Skip to content

Commit

Permalink
Merge pull request #195 from pyiron/ase_test
Browse files Browse the repository at this point in the history
Add ASE test
  • Loading branch information
jan-janssen committed Apr 23, 2024
2 parents edc6854 + 5b691fe commit b43e777
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions tests/test_ase_interface.py
@@ -0,0 +1,79 @@
import unittest

from ase.build import bulk
import numpy as np

from pylammpsmpi import LammpsASELibrary, LammpsLibrary


class TestLammpsASELibrary(unittest.TestCase):
def test_static(self):
lmp = LammpsASELibrary(
working_directory=None,
cores=1,
comm=None,
logger=None,
log_file=None,
library=LammpsLibrary(cores=2, mode='local'),
diable_log_file=True,
)
structure = bulk("Al", cubic=True).repeat([2, 2, 2])
lmp.interactive_lib_command(command="units lj")
lmp.interactive_lib_command(command="atom_style atomic")
lmp.interactive_lib_command(command="atom_modify map array")
lmp.interactive_structure_setter(
structure=structure,
units="lj",
dimension=3,
boundary=" ".join(["p" if coord else "f" for coord in structure.pbc]),
atom_style="atomic",
el_eam_lst=["Al"],
calc_md=False,
)
lmp.interactive_lib_command("pair_style lj/cut 6.0")
lmp.interactive_lib_command("pair_coeff 1 1 1.0 1.0 4.04")
lmp.interactive_lib_command("run 0")
self.assertTrue(np.all(np.isclose(lmp.interactive_cells_getter(), structure.cell.array)))
self.assertTrue(np.isclose(lmp.interactive_energy_pot_getter(), -0.04342932384411341))
self.assertTrue(np.isclose(lmp.interactive_energy_tot_getter(), -0.04342932384411341))
self.assertTrue(np.isclose(np.sum(lmp.interactive_forces_getter()), 0.0))
self.assertTrue(np.isclose(lmp.interactive_volume_getter(), 531.4409999999999))
self.assertTrue(np.all(lmp.interactive_indices_getter() == [1] * len(structure)))
self.assertEqual(lmp.interactive_steps_getter(), 0)
self.assertEqual(lmp.interactive_temperatures_getter(), 0)
lmp.close()

def test_static_with_statement(self):
structure = bulk("Al", cubic=True).repeat([2, 2, 2])
with LammpsASELibrary(
working_directory=None,
cores=1,
comm=None,
logger=None,
log_file=None,
library=LammpsLibrary(cores=2, mode='local'),
diable_log_file=True,
) as lmp:
lmp.interactive_lib_command(command="units lj")
lmp.interactive_lib_command(command="atom_style atomic")
lmp.interactive_lib_command(command="atom_modify map array")
lmp.interactive_structure_setter(
structure=structure,
units="lj",
dimension=3,
boundary=" ".join(["p" if coord else "f" for coord in structure.pbc]),
atom_style="atomic",
el_eam_lst=["Al"],
calc_md=False,
)
lmp.interactive_lib_command("pair_style lj/cut 6.0")
lmp.interactive_lib_command("pair_coeff 1 1 1.0 1.0 4.04")
lmp.interactive_lib_command("run 0")
self.assertTrue(np.all(np.isclose(lmp.interactive_cells_getter(), structure.cell.array)))
self.assertTrue(np.isclose(lmp.interactive_energy_pot_getter(), -0.04342932384411341))
self.assertTrue(np.isclose(lmp.interactive_energy_tot_getter(), -0.04342932384411341))
self.assertTrue(np.isclose(np.sum(lmp.interactive_forces_getter()), 0.0))
self.assertTrue(np.isclose(lmp.interactive_volume_getter(), 531.4409999999999))
self.assertTrue(np.all(lmp.interactive_indices_getter() == [1] * len(structure)))
self.assertEqual(lmp.interactive_steps_getter(), 0)
self.assertEqual(lmp.interactive_temperatures_getter(), 0)

0 comments on commit b43e777

Please sign in to comment.