Skip to content

Commit b43e777

Browse files
authored
Merge pull request #195 from pyiron/ase_test
Add ASE test
2 parents edc6854 + 5b691fe commit b43e777

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

tests/test_ase_interface.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import unittest
2+
3+
from ase.build import bulk
4+
import numpy as np
5+
6+
from pylammpsmpi import LammpsASELibrary, LammpsLibrary
7+
8+
9+
class TestLammpsASELibrary(unittest.TestCase):
10+
def test_static(self):
11+
lmp = LammpsASELibrary(
12+
working_directory=None,
13+
cores=1,
14+
comm=None,
15+
logger=None,
16+
log_file=None,
17+
library=LammpsLibrary(cores=2, mode='local'),
18+
diable_log_file=True,
19+
)
20+
structure = bulk("Al", cubic=True).repeat([2, 2, 2])
21+
lmp.interactive_lib_command(command="units lj")
22+
lmp.interactive_lib_command(command="atom_style atomic")
23+
lmp.interactive_lib_command(command="atom_modify map array")
24+
lmp.interactive_structure_setter(
25+
structure=structure,
26+
units="lj",
27+
dimension=3,
28+
boundary=" ".join(["p" if coord else "f" for coord in structure.pbc]),
29+
atom_style="atomic",
30+
el_eam_lst=["Al"],
31+
calc_md=False,
32+
)
33+
lmp.interactive_lib_command("pair_style lj/cut 6.0")
34+
lmp.interactive_lib_command("pair_coeff 1 1 1.0 1.0 4.04")
35+
lmp.interactive_lib_command("run 0")
36+
self.assertTrue(np.all(np.isclose(lmp.interactive_cells_getter(), structure.cell.array)))
37+
self.assertTrue(np.isclose(lmp.interactive_energy_pot_getter(), -0.04342932384411341))
38+
self.assertTrue(np.isclose(lmp.interactive_energy_tot_getter(), -0.04342932384411341))
39+
self.assertTrue(np.isclose(np.sum(lmp.interactive_forces_getter()), 0.0))
40+
self.assertTrue(np.isclose(lmp.interactive_volume_getter(), 531.4409999999999))
41+
self.assertTrue(np.all(lmp.interactive_indices_getter() == [1] * len(structure)))
42+
self.assertEqual(lmp.interactive_steps_getter(), 0)
43+
self.assertEqual(lmp.interactive_temperatures_getter(), 0)
44+
lmp.close()
45+
46+
def test_static_with_statement(self):
47+
structure = bulk("Al", cubic=True).repeat([2, 2, 2])
48+
with LammpsASELibrary(
49+
working_directory=None,
50+
cores=1,
51+
comm=None,
52+
logger=None,
53+
log_file=None,
54+
library=LammpsLibrary(cores=2, mode='local'),
55+
diable_log_file=True,
56+
) as lmp:
57+
lmp.interactive_lib_command(command="units lj")
58+
lmp.interactive_lib_command(command="atom_style atomic")
59+
lmp.interactive_lib_command(command="atom_modify map array")
60+
lmp.interactive_structure_setter(
61+
structure=structure,
62+
units="lj",
63+
dimension=3,
64+
boundary=" ".join(["p" if coord else "f" for coord in structure.pbc]),
65+
atom_style="atomic",
66+
el_eam_lst=["Al"],
67+
calc_md=False,
68+
)
69+
lmp.interactive_lib_command("pair_style lj/cut 6.0")
70+
lmp.interactive_lib_command("pair_coeff 1 1 1.0 1.0 4.04")
71+
lmp.interactive_lib_command("run 0")
72+
self.assertTrue(np.all(np.isclose(lmp.interactive_cells_getter(), structure.cell.array)))
73+
self.assertTrue(np.isclose(lmp.interactive_energy_pot_getter(), -0.04342932384411341))
74+
self.assertTrue(np.isclose(lmp.interactive_energy_tot_getter(), -0.04342932384411341))
75+
self.assertTrue(np.isclose(np.sum(lmp.interactive_forces_getter()), 0.0))
76+
self.assertTrue(np.isclose(lmp.interactive_volume_getter(), 531.4409999999999))
77+
self.assertTrue(np.all(lmp.interactive_indices_getter() == [1] * len(structure)))
78+
self.assertEqual(lmp.interactive_steps_getter(), 0)
79+
self.assertEqual(lmp.interactive_temperatures_getter(), 0)

0 commit comments

Comments
 (0)