Skip to content

Commit

Permalink
add is_valid_lattice func
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed May 4, 2024
1 parent 254c3c0 commit 15ea976
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
30 changes: 28 additions & 2 deletions pyxtal/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ def _get_dof(self):
self.dof = 1

@classmethod
def get_dofs(self, ltype=None):
def get_dofs(self, ltype):
"""
get the number of degree of freedom
"""
if ltype is None: ltype = self.ltype
#if ltype is None: ltype = self.ltype

if ltype in ["triclinic"]:
dofs = [3, 3]
elif ltype in ["monoclinic"]:
Expand Down Expand Up @@ -467,6 +468,7 @@ def encode(self):

@classmethod
def from_1d_representation(self, v, ltype):
#print('test', v, type(v), len(v), v[0])
if ltype == 'triclinic':
a, b, c, alpha, beta, gamma = v[0], v[1], v[2], v[3], v[4], v[5]
elif ltype == 'monoclinic':
Expand Down Expand Up @@ -913,6 +915,30 @@ def is_valid_matrix(self):
except:
return False

def is_valid_lattice(self, tol=1e-3):
if self.ltype in ['cubic', 'Cubic']:
if (self.a-self.b) > tol or (self.a-self.c) > tol or \
(self.alpha-np.pi/2) > tol or (self.beta-np.pi/2) > tol \
or (self.gamma-np.pi/2) > tol:
return False
if self.ltype in ['hexagonal', 'trigonal', 'Hexagonal', 'Trigonal']:
if (self.a-self.b) > tol or (self.alpha-np.pi/2) > tol \
or (self.beta-np.pi/2) > tol or (self.gamma-2/3*np.pi) > tol:
return False
elif self.ltype in ['tetragonal', 'Tetragonal']:
if (self.a-self.b) > tol or (self.alpha-np.pi/2) > tol \
or (self.beta-np.pi/2) > tol or (self.gamma-np.pi/2) > tol:
return False
elif self.ltype in ['orthorhombic', 'Orthorhombic']:
if (self.alpha-np.pi/2) > tol or (self.beta-np.pi/2) > tol \
or (self.gamma-np.pi/2) > tol:
return False
elif self.ltype in ['monoclinic', 'Monoclinic']:
if (self.alpha-np.pi/2) > tol or (self.gamma-np.pi/2) > tol:
return False

return True

def check_mismatch(self, trans, l_type, tol=1.0, a_tol=10):
"""
check if the lattice mismatch is big after a transformation
Expand Down
9 changes: 9 additions & 0 deletions pyxtal/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,15 @@ def test_search_transformation(self):
l7 = l7.transform_multi(trans)
self.assertTrue(np.abs(l7.matrix-l6.matrix).sum() < 0.25)

def test_is_valid_lattice(self):
l8 = Lattice.from_para(3.454, 3.401, 5.908, 90.00, 105.80, 91.00, ltype='monoclinic')
l9 = Lattice.from_para(3.454, 3.401, 5.908, 90.00, 105.80, 90.00, ltype='monoclinic')
l10 = Lattice.from_para(3.454, 3.401, 5.908, 90.00, 90.00, 90.00, ltype='cubic')
self.assertTrue(not l8.is_valid_lattice())
self.assertTrue(l9.is_valid_lattice())
self.assertTrue(not l10.is_valid_lattice())


class TestSymmetry(unittest.TestCase):
def test_from_symops_wo_grou(self):
data = [
Expand Down
2 changes: 1 addition & 1 deletion pyxtal/wyckoff_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class wyckoff_split:
def __init__(self, G=197, idx=None, wp1=[0, 1], group_type='t', elements=None):
self.error = False
self.elements = elements
if type(G) is int:
if type(G) in [int, np.int64]:
self.G = sym.Group(G) # Group object
else:
self.G = G
Expand Down

0 comments on commit 15ea976

Please sign in to comment.