Skip to content

Commit

Permalink
add the cut_lattice function
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Oct 31, 2024
1 parent 5f62e1e commit c71338e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
23 changes: 15 additions & 8 deletions pyxtal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3282,14 +3282,21 @@ def get_separations(self, hkls=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]):

return np.array(separations)

#def cut_cell(self, cutoff=5.0):
# """
# An utility to reduce the empty spacing
# """
# seps = self.get_separations()
# id = seps.argmax()
# if seps[id] >= cutoff:
# pass
def cut_lattice(self, max_separation=3.0, verbose=False):
"""
An utility to reduce the empty spacing
"""
seps = self.get_separations()
ax = seps.argmax()
if seps[ax] >= max_separation:
cut = seps[ax] - max_separation
# update coordinates
for mol_site in self.mol_sites:
mol_site.cut_lattice(ax, cut)
self.lattice.update_para(ax, -cut)
if verbose:
print(f"Found large separation {ax} {seps[ax]:.2f}")
print("Update lattice", self.lattice)


def get_structure_factor(self, hkl, coeffs=None):
Expand Down
5 changes: 5 additions & 0 deletions pyxtal/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,11 @@ def set_para(self, para=None, radians=False):
else:
self.set_matrix()

def update_para(self, id, change):
para = [self.a, self.b, self.c, self.alpha, self.beta, self.gamma]
para[id] += change
self.set_matrix(para2matrix(para))

def reset_matrix(self, shape="upper"):
if self.random:
success = False
Expand Down
22 changes: 19 additions & 3 deletions pyxtal/wyckoff_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,25 @@ def optimize_orientation_by_energy(self, max_ax=20, max_ori=5, early_quit=3.0, v
if fun <= early_quit:
break

def update_lattice(self, lattice):
# QZ: Symmetrize the angle to the compatible orientation first
self.lattice = lattice
def cut_lattice(self, ax, cut):
"""
Cut lattice length on the given direction
Args:
ax (int): 0, 1, 2
cut (float): the cut
"""
paras = self.lattice.get_para()
x0 = self.position[ax]
x0 -= np.floor(x0)

if x0 < 0.25:
self.position[ax] = paras[ax] * x0 / (paras[ax]-cut)
elif 0.25 <= x0 <= 0.75:
self.position[ax] = (paras[ax] * x0 - 0.5 * cut) / (paras[ax]-cut)
else:
self.position[ax] = (paras[ax] * x0 - cut) / (paras[ax]-cut)
#self.lattice.update_para(ax, -cut)

def __str__(self):
if not hasattr(self.wp, "site_symm"):
Expand Down

0 comments on commit c71338e

Please sign in to comment.