Skip to content

Commit

Permalink
fix a lattice bug in lego_optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Oct 9, 2024
1 parent 0242b4d commit f05fdad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 6 additions & 2 deletions pyxtal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3426,8 +3426,12 @@ def update_from_1d_rep(self, x):
N = self.lattice.dof
cell, pos = x[:N], x[N:]

# update cell
self.lattice.update_from_1d_representation(cell)
try:
# update cell
self.lattice.update_from_1d_representation(cell)
except:
self.lattice = None
return
#l_type = self.lattice.ltype
#self.lattice = Lattice.from_1d_representation(cell, l_type)
# print("lattice dof", N, cell, l_type, self.lattice)
Expand Down
16 changes: 13 additions & 3 deletions pyxtal/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,12 @@ def update_from_1d_representation(self, v):
self.a, self.b, self.c = v[0], v[0], v[0]

para = (self.a, self.b, self.c, self.alpha, self.beta, self.gamma)
self.set_matrix(para2matrix(para))

matrix = para2matrix(para)
if matrix is not None:
self.set_matrix(matrix)
else:
msg = f'error input {v} in update_from_1d_representation {self.ltype}'
raise ValueError(msg)

def mutate(self, degree=0.10, frozen=False):
"""
Expand Down Expand Up @@ -639,7 +643,13 @@ def set_matrix(self, matrix=None):
m = np.array(matrix)
if np.shape(m) == (3, 3):
self.matrix = m
self.inv_matrix = np.linalg.inv(m)
try:
self.inv_matrix = np.linalg.inv(m)
except:
print(self.para)
print(matrix)
msg = "Error in getting the inv_matrix"
raise ValueError(msg)
else:
print(matrix)
msg = "Error: matrix must be a 3x3 numpy array or list"
Expand Down

0 comments on commit f05fdad

Please sign in to comment.