From c71338e5c83487b132fee4177e88c876e10a9300 Mon Sep 17 00:00:00 2001 From: qzhu2017 Date: Wed, 30 Oct 2024 20:50:43 -0400 Subject: [PATCH] add the cut_lattice function --- pyxtal/__init__.py | 23 +++++++++++++++-------- pyxtal/lattice.py | 5 +++++ pyxtal/wyckoff_site.py | 22 +++++++++++++++++++--- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/pyxtal/__init__.py b/pyxtal/__init__.py index 775709e0..a35a2146 100644 --- a/pyxtal/__init__.py +++ b/pyxtal/__init__.py @@ -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): diff --git a/pyxtal/lattice.py b/pyxtal/lattice.py index 1f341523..253f3580 100644 --- a/pyxtal/lattice.py +++ b/pyxtal/lattice.py @@ -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 diff --git a/pyxtal/wyckoff_site.py b/pyxtal/wyckoff_site.py index 04e15bb8..d55ffe18 100644 --- a/pyxtal/wyckoff_site.py +++ b/pyxtal/wyckoff_site.py @@ -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"):