Skip to content

Commit

Permalink
Fix: make box smaller for no pbc structure (#84)
Browse files Browse the repository at this point in the history
* fix: make box smaller for no pbc structure

* Update src/mattersim/datasets/utils/convertor.py

Co-authored-by: Han Yang <[email protected]>

* chore: remove redundant

---------

Co-authored-by: Han Yang <[email protected]>
  • Loading branch information
anyangml and yanghan234 authored Feb 5, 2025
1 parent 4a07e10 commit f1028e5
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/mattersim/datasets/utils/convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f1028e5

Please sign in to comment.