Skip to content

Commit

Permalink
fix a bug in lattice.from_1D_representation
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed May 4, 2024
1 parent 15ea976 commit c385b35
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
7 changes: 4 additions & 3 deletions pyxtal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,14 +1341,14 @@ def get_std_representation(self, trans):
"""
pass

def get_1D_representation(self):
def get_1D_representation(self, standard=False):
"""
Get the 1D representation class for molecular crystals
"""
if self.molecular:
rep = representation.from_pyxtal(self)
else:
rep = representation_atom.from_pyxtal(self)
rep = representation_atom.from_pyxtal(self, standard=standard)
return rep

def transform(self, trans, lattice=None):
Expand Down Expand Up @@ -3148,6 +3148,7 @@ def update_from_1d_rep(self, x):
# update cell
l_type = self.lattice.ltype
self.lattice = Lattice.from_1d_representation(cell, l_type)
#print("lattice dof", N, cell, l_type, self.lattice)

# update position
start = 0
Expand All @@ -3169,7 +3170,7 @@ def get_1d_rep_x(self):
The above rep is [2.5019, 8.7514, 0.4614]
"""

rep = self.get_1D_representation()
rep = self.get_1D_representation(standard=True)
cell, xyzs = rep.x[0][1:], rep.x[1:]
x = cell
for xyz in xyzs:
Expand Down
2 changes: 1 addition & 1 deletion pyxtal/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def from_1d_representation(self, v, ltype):
a, b, c, alpha, beta, gamma = v[0], v[1], v[2], 90, 90, 90
elif ltype == 'tetragonal':
a, b, c, alpha, beta, gamma = v[0], v[0], v[1], 90, 90, 90
elif ltype == 'hexagonal':
elif ltype in ['trigonal', 'hexagonal']:
a, b, c, alpha, beta, gamma = v[0], v[0], v[1], 90, 90, 120
else:
a, b, c, alpha, beta, gamma = v[0], v[0], v[0], 90, 90, 90
Expand Down
2 changes: 1 addition & 1 deletion pyxtal/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __str__(self):
return self.to_string()

@classmethod
def from_pyxtal(cls, struc, standard=False):
def from_pyxtal(cls, struc, standard=True):
"""
Initialize 1D rep. from the pyxtal object
Expand Down
6 changes: 6 additions & 0 deletions pyxtal/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,12 @@ def test_is_valid_lattice(self):
self.assertTrue(l9.is_valid_lattice())
self.assertTrue(not l10.is_valid_lattice())

def test_from_1d_representation(self):
lat = Lattice.from_1d_representation([5.09, 6.11], 'trigonal')
self.assertTrue(abs(lat.a-5.09)<1e-3)
self.assertTrue(abs(lat.c-6.11)<1e-3)
self.assertTrue(abs(lat.gamma-2/3*np.pi)<1e-3)


class TestSymmetry(unittest.TestCase):
def test_from_symops_wo_grou(self):
Expand Down

0 comments on commit c385b35

Please sign in to comment.