From f1028e5eee8cc19edfc1d44f3c468c1206192daa Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Wed, 5 Feb 2025 13:13:09 +0800 Subject: [PATCH] Fix: make box smaller for no pbc structure (#84) * fix: make box smaller for no pbc structure * Update src/mattersim/datasets/utils/convertor.py Co-authored-by: Han Yang * chore: remove redundant --------- Co-authored-by: Han Yang --- src/mattersim/datasets/utils/convertor.py | 28 +++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/mattersim/datasets/utils/convertor.py b/src/mattersim/datasets/utils/convertor.py index 186b61d..59a42a9 100644 --- a/src/mattersim/datasets/utils/convertor.py +++ b/src/mattersim/datasets/utils/convertor.py @@ -193,16 +193,26 @@ def convert( min_z = np.min(atoms.positions[:, 2]) max_x = np.max(atoms.positions[:, 0]) max_y = np.max(atoms.positions[:, 1]) - max_z = np.max(atoms.positions[:, 2]) - x_len = max((max_x - min_x) * 10, 1000) - y_len = max((max_y - min_y) * 10, 1000) - z_len = max((max_z - min_z) * 10, 1000) - lattice_matrix = np.array( - [[x_len, 0.0, 0.0], [0.0, y_len, 0.0], [0.0, 0.0, z_len]], - dtype=float, - ) + max_z = np.max(atoms.positions[:, 2]) + x_len = (max_x - min_x) + max( + self.twobody_cutoff, self.threebody_cutoff + ) * 5 + y_len = (max_y - min_y) + max( + self.twobody_cutoff, self.threebody_cutoff + ) * 5 + z_len = (max_z - min_z) + max( + self.twobody_cutoff, self.threebody_cutoff + ) * 5 + max_len = max(x_len, y_len, z_len) + x_len = y_len = z_len = max_len + lattice_matrix = np.eye(3) * max_len pbc_ = np.array([1, 1, 1], dtype=int) - warnings.warn("No PBC detected, using a large supercell", UserWarning) + warnings.warn( + "No PBC detected, using a large supercell with " + f"size {x_len}x{y_len}x{z_len} Angstrom**3", + UserWarning, + ) + atoms.set_cell(lattice_matrix) atoms.set_pbc(pbc_) else: