Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/mattersim/utils/supercell_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def auto_grid_detection(
== lattice_vector_lengths[1]
== lattice_vector_lengths[2]
):
number_of_replicas = int(np.round(max_atoms / (len(atom))) ** (1 / 3))
number_of_replicas = int(np.round((max_atoms / len(atom)) ** (1 / 3)))
number_of_replicas = max(number_of_replicas, 1)
max_replication = (
number_of_replicas,
Expand All @@ -62,7 +62,7 @@ def auto_grid_detection(
# Variation in cell length with in the tolerance we still consider it
# as an N-N-N replications
if ratios[0] <= ratio_tolerance and ratios[1] <= ratio_tolerance:
number_of_replicas = int(np.round(max_atoms / (len(atom))) ** (1 / 3))
number_of_replicas = int(np.round((max_atoms / len(atom)) ** (1 / 3)))
number_of_replicas = max(number_of_replicas, 1)
max_replication = (
number_of_replicas,
Expand All @@ -74,7 +74,7 @@ def auto_grid_detection(
else:
# Compute the replica along the most asymmetric direction
asymmetric_replica = int(
(max_atoms / len(atom) / np.prod(ratios)) ** (1 / 3)
np.round((max_atoms / len(atom) / np.prod(ratios)) ** (1 / 3))
)
asymmetric_replica = max(asymmetric_replica, 1)

Expand Down
Empty file added tests/utils/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions tests/utils/test_supercell_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
import unittest

from ase.build import bulk

from mattersim.utils.supercell_utils import auto_grid_detection


class SupercellUtilsTestCase(unittest.TestCase):
def test_auto_grid_detection_exact_cubes(self):
# 1-atom primitive fcc Cu
atoms = bulk("Cu", "fcc", a=3.6)
# Perfect cube roots: 64 = 4^3, 216 = 6^3
grid_64 = auto_grid_detection(
atoms, max_atoms=64, is_santity_check=False, is_verbose=False
)
self.assertEqual(grid_64, (4, 4, 4))

grid_216 = auto_grid_detection(
atoms, max_atoms=216, is_santity_check=False, is_verbose=False
)
self.assertEqual(grid_216, (6, 6, 6))

def test_auto_grid_detection_approximate_lengths(self):
# Cell lengths within ratio_tolerance
atoms = bulk("Cu", "fcc", a=3.6)
atoms.cell[0] *= 1.05
grid_64 = auto_grid_detection(
atoms,
max_atoms=64,
ratio_tolerance=1.1,
is_santity_check=False,
is_verbose=False,
)
self.assertEqual(grid_64, (4, 4, 4))


if __name__ == "__main__":
unittest.main()