Skip to content

Commit

Permalink
Added new tests for ASE and Pymatgen
Browse files Browse the repository at this point in the history
  • Loading branch information
jd15489 committed Jan 7, 2024
1 parent f03fa16 commit c984d78
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 2 deletions.
Binary file added kinisi/tests/inputs/example_ase_center.traj
Binary file not shown.
Binary file added kinisi/tests/inputs/example_ase_drift.traj
Binary file not shown.
23 changes: 23 additions & 0 deletions kinisi/tests/inputs/example_center.XDATCAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
H He H
1
5.000000 0.000000 0.000000
0.000000 5.000000 0.000000
0.000000 0.000000 5.000000
H He H
1 1 1
Direct configuration= 1
0.20000000 0.20000000 0.20000000
0.40000000 0.20000000 0.20000000
0.22000000 0.40000000 0.20000000
Direct configuration= 2
0.40000000 0.20000000 0.20000000
0.40000000 0.20000000 0.20000000
0.20000000 0.40000000 0.20000000
Direct configuration= 3
0.40000000 0.20000000 0.20000000
0.40000000 0.20000000 0.20000000
0.20000000 0.40000000 0.20000000
Direct configuration= 4
0.40000000 0.20000000 0.20000000
0.40000000 0.40000000 0.20000000
0.20000000 0.40000000 0.20000000
47 changes: 47 additions & 0 deletions kinisi/tests/inputs/example_drift.XDATCAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
H He
1
10.000000 0.000000 0.000000
0.000000 10.000000 0.000000
0.000000 0.000000 10.000000
H He
1 8
Direct configuration= 1
0.50000000 0.50000000 0.50000000
0.25000000 0.25000000 0.25000000
0.75000000 0.25000000 0.25000000
0.25000000 0.75000000 0.25000000
0.25000000 0.25000000 0.75000000
0.75000000 0.75000000 0.25000000
0.75000000 0.25000000 0.75000000
0.25000000 0.75000000 0.75000000
0.75000000 0.75000000 0.75000000
Direct configuration= 2
0.50000000 0.50000000 0.50000000
0.23000000 0.23000000 0.23000000
0.73000000 0.23000000 0.23000000
0.23000000 0.73000000 0.23000000
0.23000000 0.23000000 0.73000000
0.73000000 0.73000000 0.23000000
0.73000000 0.23000000 0.73000000
0.23000000 0.73000000 0.73000000
0.73000000 0.73000000 0.73000000
Direct configuration= 3
0.50000000 0.50000000 0.50000000
0.21000000 0.21000000 0.21000000
0.71000000 0.21000000 0.21000000
0.21000000 0.71000000 0.21000000
0.21000000 0.21000000 0.71000000
0.71000000 0.71000000 0.21000000
0.71000000 0.21000000 0.71000000
0.21000000 0.71000000 0.71000000
0.71000000 0.71000000 0.71000000
Direct configuration= 4
0.50000000 0.50000000 0.50000000
0.15000000 0.15000000 0.15000000
0.65000000 0.15000000 0.15000000
0.15000000 0.65000000 0.15000000
0.15000000 0.15000000 0.65000000
0.65000000 0.65000000 0.15000000
0.65000000 0.15000000 0.65000000
0.15000000 0.65000000 0.65000000
0.65000000 0.65000000 0.65000000
94 changes: 92 additions & 2 deletions kinisi/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def test_get_disps(self):
assert_equal(disp_3d[0].shape[1], 81)
assert_equal(disp_3d[0].shape[2], 3)

#Pymatgen tests with VASP XDATCAR files
def test_pymatgen_init(self):
xd = Xdatcar(os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_XDATCAR.gz'))
da_params = {'specie': 'Li', 'time_step': 2.0, 'step_skip': 50}
Expand Down Expand Up @@ -122,7 +123,51 @@ def test_pymatgen_big_timestep(self):
assert_almost_equal(data.time_step, 20.0)
assert_almost_equal(data.step_skip, 100)
assert_equal(data.indices, list(range(xd.natoms[0])))

def test_pymatgen_init_with_COG(self):
xd = Xdatcar(os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_center.XDATCAR'))
da_params = {'specie': None, 'time_step': 1.0, 'step_skip': 1, 'specie_indices': [[1, 2, 3]]}
data = parser.PymatgenParser(xd.structures, **da_params)
assert_almost_equal(data.time_step, 1)
assert_almost_equal(data.step_skip, 1)
assert_equal(data.indices, [0])
assert_almost_equal(data.coords_check, [[[0.269634905, 0.262183827, 0.2]]])

def test_pymatgen_init_with_COM(self):
xd = Xdatcar(os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_center.XDATCAR'))
da_params = {
'specie': None,
'time_step': 1.0,
'step_skip': 1,
'specie_indices': [[1, 2, 3]],
'masses': [1, 16, 1]
}
data = parser.PymatgenParser(xd.structures, **da_params)
assert_almost_equal(data.time_step, 1)
assert_almost_equal(data.step_skip, 1)
assert_equal(data.indices, [0])
assert_almost_equal(data.coords_check, [[[0.382421597, 0.2087361, 0.2]]])

def test_pymatgen_init_with_framwork_indices(self):
xd = Xdatcar(os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_drift.XDATCAR'))
da_1_params = {'specie': 'H', 'time_step': 1.0, 'step_skip': 1, 'framework_indices': []}
data_1 = parser.PymatgenParser(xd.structures, **da_1_params)
assert_almost_equal(data_1.time_step, 1)
assert_almost_equal(data_1.step_skip, 1)
assert_equal(data_1.indices, [0])
assert_equal(data_1.drift_indices, [])
assert_equal(data_1.dc[0], np.zeros((4, 3)))
da_2_params = {'specie': 'H', 'time_step': 1.0, 'step_skip': 1}
data_2 = parser.PymatgenParser(xd.structures, **da_2_params)
assert_almost_equal(data_2.time_step, 1)
assert_almost_equal(data_2.step_skip, 1)
assert_equal(data_2.indices, [0])
assert_equal(data_2.drift_indices, list(range(1, 9)))
print(data_2.dc[0])
disp_array = [[0.0, 0.0, 0.0], [0.2, 0.2, 0.2], [0.4, 0.4, 0.4], [1, 1, 1]]
assert_almost_equal(data_2.dc[0], disp_array)

#ASE tests with ASE traj files
def test_ase_init(self):
traj = Trajectory(os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_ase.traj'))
da_params = {'specie': 'Li', 'time_step': 1e-3, 'step_skip': 1}
Expand All @@ -148,6 +193,50 @@ def test_ase_init_with_molecules(self):
assert_almost_equal(data.step_skip, 1)
assert_equal(data.indices, list(range(len(molecules))))

def test_ase_init_with_COG(self):
traj = Trajectory(os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_ase_center.traj'))
da_params = {'specie': None, 'time_step': 1, 'step_skip': 1, 'specie_indices': [[1, 2, 3]]}
data = parser.ASEParser(traj, **da_params)
assert_almost_equal(data.time_step, 1)
assert_almost_equal(data.step_skip, 1)
assert_equal(data.indices, [0])
assert_almost_equal(data.coords_check, [[[0.269634905, 0.262183827, 0.2]]])

def test_ase_init_with_COM(self):
traj = Trajectory(os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_ase_center.traj'))
da_params = {
'specie': None,
'time_step': 1,
'step_skip': 1,
'specie_indices': [[1, 2, 3]],
'masses': [1, 16, 1]
}
data = parser.ASEParser(traj, **da_params)
assert_almost_equal(data.time_step, 1)
assert_almost_equal(data.step_skip, 1)
assert_equal(data.indices, [0])
assert_almost_equal(data.coords_check, [[[0.382421597, 0.2087361, 0.2]]])

def test_ase_init_with_framwork_indices(self):
traj = Trajectory(os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_ase_drift.traj'))
da_1_params = {'specie': 'H', 'time_step': 1, 'step_skip': 1, 'framework_indices': []}
data_1 = parser.ASEParser(traj, **da_1_params)
assert_almost_equal(data_1.time_step, 1)
assert_almost_equal(data_1.step_skip, 1)
assert_equal(data_1.indices, [0])
assert_equal(data_1.drift_indices, [])
assert_equal(data_1.dc[0], np.zeros((4, 3)))
da_2_params = {'specie': 'H', 'time_step': 1, 'step_skip': 1}
data_2 = parser.ASEParser(traj, **da_2_params)
assert_almost_equal(data_2.time_step, 1)
assert_almost_equal(data_2.step_skip, 1)
assert_equal(data_2.indices, [0])
assert_equal(data_2.drift_indices, list(range(1, 9)))
print(data_2.dc[0])
disp_array = [[0.0, 0.0, 0.0], [0.2, 0.2, 0.2], [0.4, 0.4, 0.4], [1, 1, 1]]
assert_almost_equal(data_2.dc[0], disp_array)

#MDAnalysis tests with LAMMPS data and dump files
def test_mda_init(self):
xd = mda.Universe(os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_LAMMPS.data'),
os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_LAMMPS.dcd'),
Expand Down Expand Up @@ -210,7 +299,7 @@ def test_mda_init_with_COM(self):
assert_equal(data.indices, [0])
assert_almost_equal(data.coords_check, [[[0.382421597, 0.2087361, 0.2]]])

def test_mda_inti_with_framwork_indices(self):
def test_mda_init_with_framwork_indices(self):
xd = mda.Universe(os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_LAMMPS_drift.data'),
os.path.join(os.path.dirname(kinisi.__file__), 'tests/inputs/example_LAMMPS_drift.traj'),
topology_format='DATA',
Expand All @@ -231,7 +320,8 @@ def test_mda_inti_with_framwork_indices(self):
print(data_2.dc[0])
disp_array = [[0.0, 0.0, 0.0], [0.2, 0.2, 0.2], [0.4, 0.4, 0.4], [1, 1, 1]]
assert_almost_equal(data_2.dc[0], disp_array)


#Matrix test
def test_get_matrix(self):
matrix = parser._get_matrix([10, 10, 10, 90, 90, 90])
assert_almost_equal(matrix, np.diag((10, 10, 10)))

0 comments on commit c984d78

Please sign in to comment.