Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
377 changes: 358 additions & 19 deletions MolAdsPy/__adsorption__.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion MolAdsPy/__atom__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from MolAdsPy.__exception__ import BasicException
from __exception__ import BasicException
from numpy import array,ndarray

class AtomError(BasicException):
Expand Down
46 changes: 31 additions & 15 deletions MolAdsPy/__atomcollection__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from MolAdsPy.__atom__ import Atom,Species
from MolAdsPy.__exception__ import BasicException
from __atom__ import Atom,Species
from __exception__ import BasicException
from multipledispatch import dispatch
from numpy import array,ndarray,dot,sqrt
from copy import copy
Expand All @@ -14,8 +14,9 @@ class AtomCollection(ABC):
_instances=None # List of atom collection objects created so far
__slots__=["_ucell","_atoms","_loc","_species","_a0","_latvec","_n","_m","_l",
"_maxn","_maxm","_maxl","_id","_origin","_belongs_to","_label"]

def __init__(self):
_verbose = 1 # Level of verbose during usage of the lib

def __init__(self,**kwargs):
'''
Object initialization.
'''
Expand All @@ -33,6 +34,7 @@ def __init__(self):
self._maxn=self._maxm=self._maxl=0 # Maximum number of translations for resizing purposes
self._origin=array([0.0,0.0,0.0]) # Position with minimum values of X, Y, and Z coordinates of the structure.

self._verbose = kwargs.get("verbose",False)
type(self)._append(self)

@dispatch(int,loc=(tuple,list),update=bool)
Expand Down Expand Up @@ -260,7 +262,7 @@ def write_xyz(self,file_name="coords.xyz",ucell=False):
n=self._n+1 if not ucell else 1
m=self._m+1 if not ucell else 1
l=self._l+1 if not ucell else 1

for atom in self._atoms:
i,j,k=self._loc[atom._id]

Expand Down Expand Up @@ -558,8 +560,14 @@ def write_pw_input(self,file_name="pw.in",ucell=False,pseudopotentials={},

with open(file_name,"w") as f:
f.write(inpstr)


# TODO: Rename to replicate.
def resize(self,n,m,l):
#print("max")
#print(self._maxn, self._maxm,self._maxl)
#print("input")
#print(n,m,l)
print(n,m,l)
'''
Resizes the atom collection structure.

Expand All @@ -579,9 +587,12 @@ def resize(self,n,m,l):
and n>=0 and m>=0 and l>=0):
raise AtomCollectionError("'n', 'm' and 'l' values must be integers greater than or equal to zero!")
elif n==self._n and m==self._m and l==self._l:
raise AtomCollectionError("The current structure size was not changed!")
elif n>self._maxn or m>self._maxm and l>self._maxl:
print("WARNING: Atoms newly created will not be removed if the supercell is subsequently reduced!")
if(self._verbose):
print("The current structure size was not changed!")
return
elif n>self._maxn or m>self._maxm or l>self._maxl:
if(self._verbose):
print("WARNING: Atoms newly created will not be removed if the supercell is subsequently reduced!")

for i in range(n+1):
for j in range(m+1):
Expand All @@ -602,11 +613,12 @@ def resize(self,n,m,l):
self._maxn=max([self._maxn,n])
self._maxm=max([self._maxm,m])
self._maxl=max([self._maxl,l])

self._n=n
self._m=m
self._l=l

print()
print(self._n)
self._update()

def copy(self):
Expand Down Expand Up @@ -698,6 +710,7 @@ def _read_xyz(self,file_name):
% (len(self._atoms),file_name))

self._update()
f.close()

def __getitem__(self,idx):
'''
Expand All @@ -716,11 +729,13 @@ def __getitem__(self,idx):
atom list.
'''
maxidx=len(self._atoms)
if not isinstance(idx,int):
raise AtomCollectionError("Index is not int!")

if isinstance(idx,int) and idx>=-maxidx and idx<maxidx:
if idx>=-maxidx and idx<maxidx:
return self._atoms[idx]
else:
raise AtomCollectionError("Invalid index!")
raise AtomCollectionError("Invalid index in get item!")

@dispatch(int,int)
def __setitem__(self,idx,atomid):
Expand Down Expand Up @@ -766,7 +781,7 @@ def __setitem__(self,idx,atomid):
else:
raise AtomCollectionError("'atomid' must be an integer greater than or equal to zero!")
else:
raise AtomCollectionError("Invalid index!")
raise AtomCollectionError("Invalid index in set item!")

@dispatch(int,Atom)
def __setitem__(self,idx,atom):
Expand Down Expand Up @@ -804,7 +819,7 @@ def __setitem__(self,idx,atom):
else:
raise AtomCollectionError("Atom already belongs to another structure!")
else:
raise AtomCollectionError("Invalid index!")
raise AtomCollectionError("Invalid index in set item Atom dispatch!")

def __len__(self):
'''
Expand Down Expand Up @@ -949,6 +964,7 @@ def lattice_vectors(self,val):
else:
raise AtomCollectionError("Lattice vectors must be a Numpy array with three vectors!")


@property
def origin(self):
return self._origin
Expand Down
24 changes: 21 additions & 3 deletions MolAdsPy/__hybrid__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import print_function
from MolAdsPy.__atomcollection__ import AtomCollection
from MolAdsPy.__exception__ import BasicException
from __atomcollection__ import AtomCollection
from __exception__ import BasicException
from abc import ABC,abstractmethod
from numpy import array

Expand All @@ -11,10 +11,11 @@ class Hybrid(AtomCollection,ABC):
__slots__=["_components","_a0","_latvec","_n","_m","_l","_maxn","_maxm",
"_maxl","_origin"]

def __init__(self):
def __init__(self,**kwargs):
'''
Object initialization.
'''

self._components={} # Dictionary of objects that are put together to form the hybrid system
self._a0=1.0 # Lattice constant
self._latvec=array([[1.0,0.0,0.0],
Expand All @@ -24,6 +25,7 @@ def __init__(self):
self._maxn=self._maxm=self._maxl=0 # Maximum number of translations for resizing purposes
self._origin=array([0.0,0.0,0.0]) # Position with minimum values of X, Y, and Z coordinates of the structure.

self._verbose = kwargs.get("verbose",False)
type(self)._append(self)

@abstractmethod
Expand All @@ -42,6 +44,22 @@ def remove_component(self,*args):
'''
pass

@abstractmethod
def beginHandler(self,obj,method,**kwargs):
'''
To be implemented in a derived hybrid structure, this method is expected
to make the hybrid structure reconsntruct itself when an object is realigned inside it.
'''
pass

@abstractmethod
def endHandler(self,obj,method,**kwargs):
'''
To be implemented in a derived hybrid structure, this method is expected
to make the hybrid structure reconsntruct itself when an object is realigned inside it.
'''
pass

def force_update(self):
'''
Forces the hybrid system's attributes to be updated if there is a change
Expand Down
2 changes: 1 addition & 1 deletion MolAdsPy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .core import Atom,Molecule,Slab,Adsorption
from .core import Atom,Molecule,Slab,Adsorption,Polymer

__version__="1.0.0"
13 changes: 7 additions & 6 deletions MolAdsPy/__molecule__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import print_function
from MolAdsPy.__atom__ import Atom
from MolAdsPy.__atomcollection__ import AtomCollection
from MolAdsPy.__exception__ import BasicException
from __atom__ import Atom
from __atomcollection__ import AtomCollection
from __exception__ import BasicException
from numpy import array,ndarray,min,max,sum,cos,sin,radians,dot
from copy import deepcopy
from multipledispatch import dispatch
Expand All @@ -13,7 +13,7 @@ class Molecule(AtomCollection):
__slots__=["_vaccuum","_maxx","_maxy","_maxz","_minx","_miny","_minz","_anchors"]

@dispatch(str,vaccuum=(int,float))
def __init__(self,label,vaccuum=10.0):
def __init__(self,label,vaccuum=10.0,**kwargs):
'''
Object initialization.

Expand All @@ -27,7 +27,7 @@ def __init__(self,label,vaccuum=10.0):
boundary conditions scheme. The default is 10.0 Angstroms.

'''
super().__init__()
super().__init__(**kwargs)

if len(label)>0:
self._label=label
Expand Down Expand Up @@ -122,7 +122,8 @@ def __init__(self,label,atom_list,vaccuum=10.0):
if isinstance(atom,(Atom,int)):
self.add_atom(atom,loc=(0,0,0),update=False)
else:
print("WARNING! An element in the atom list must be either an Atom object or an atom ID!")
if(self.verbose):
print("WARNING! An element in the atom list must be either an Atom object or an atom ID!")
else:
raise MoleculeError("'atom_list' must be a non-empyt list!")

Expand Down
Loading