Skip to content

Commit

Permalink
updated allclose to deal with zeros and update all traj conversion files
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiCheng45 committed Mar 3, 2025
1 parent 17c6560 commit 6ea49cd
Show file tree
Hide file tree
Showing 40 changed files with 58 additions and 48 deletions.
10 changes: 5 additions & 5 deletions MDANSE/Tests/UnitTests/Analysis/test_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def test_vacf(interp_order, normalise):
if normalise:
np.testing.assert_allclose(
actual[f"/{key}"] * actual[f"/{key}"].attrs["scaling_factor"],
desired[f"/{key}"],
desired[f"/{key}"], atol=1e-8
)
else:
np.testing.assert_allclose(
actual[f"/{key}"], desired[f"/{key}"],
actual[f"/{key}"], desired[f"/{key}"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down Expand Up @@ -111,7 +111,7 @@ def test_pps():
]:
np.testing.assert_allclose(
actual[f"/{key}"] * actual[f"/{key}"].attrs["scaling_factor"],
desired[f"/{key}"],
desired[f"/{key}"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down Expand Up @@ -201,11 +201,11 @@ def test_dynamics_analysis(
if job_info[2]:
np.testing.assert_allclose(
actual[f"/{key}"] * actual[f"/{key}"].attrs["scaling_factor"],
desired[f"/{key}"],
desired[f"/{key}"], atol=1e-8
)
else:
np.testing.assert_allclose(
actual[f"/{key}"], desired[f"/{key}"],
actual[f"/{key}"], desired[f"/{key}"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down
8 changes: 5 additions & 3 deletions MDANSE/Tests/UnitTests/Analysis/test_infrared.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def test_dacf_analysis():

with h5py.File(temp_name + ".mda") as actual, h5py.File(result_file) as desired:
np.testing.assert_allclose(
actual["/dacf"] * actual["/dacf"].attrs["scaling_factor"], desired["/dacf"]
actual["/dacf"] * actual["/dacf"].attrs["scaling_factor"],
desired["/dacf"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down Expand Up @@ -94,10 +95,11 @@ def test_ir_analysis():
with h5py.File(temp_name + ".mda") as actual, h5py.File(result_file) as desired:
np.testing.assert_allclose(
actual["/ddacf"] * actual["/ddacf"].attrs["scaling_factor"],
desired["/ddacf"],
desired["/ddacf"], atol=1e-8
)
np.testing.assert_allclose(
actual["/ir"] * actual["/ir"].attrs["scaling_factor"], desired["/ir"]
actual["/ir"] * actual["/ir"].attrs["scaling_factor"],
desired["/ir"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down
8 changes: 4 additions & 4 deletions MDANSE/Tests/UnitTests/Analysis/test_mdmc_h5md.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ def test_h5md_temperature(trajectory, interp_order):

with h5py.File(temp_name + ".mda") as actual, h5py.File(result_file) as desired:
np.testing.assert_allclose(
actual["/kinetic_energy"], desired["/kinetic_energy"]
actual["/kinetic_energy"], desired["/kinetic_energy"], atol=1e-8
)
np.testing.assert_allclose(
actual["/temperature"], desired["/temperature"]
actual["/temperature"], desired["/temperature"], atol=1e-8
)
np.testing.assert_allclose(
actual["/avg_kinetic_energy"], desired["/avg_kinetic_energy"]
actual["/avg_kinetic_energy"], desired["/avg_kinetic_energy"], atol=1e-8
)
np.testing.assert_allclose(
actual["/avg_temperature"], desired["/avg_temperature"]
actual["/avg_temperature"], desired["/avg_temperature"], atol=1e-8
)

os.remove(temp_name + ".mda")
10 changes: 5 additions & 5 deletions MDANSE/Tests/UnitTests/Analysis/test_meansquare.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def test_basic_meansquare():
result_file = os.path.join(result_dir, "basic_meansquare.mda")

with h5py.File(temp_name + ".mda") as actual, h5py.File(result_file) as desired:
np.testing.assert_allclose(actual["/msd_Cu"], desired["/msd_Cu"])
np.testing.assert_allclose(actual["/msd_S"], desired["/msd_S"])
np.testing.assert_allclose(actual["/msd_Sb"], desired["/msd_Sb"])
np.testing.assert_allclose(actual["/msd_Cu"], desired["/msd_Cu"], atol=1e-8)
np.testing.assert_allclose(actual["/msd_S"], desired["/msd_S"], atol=1e-8)
np.testing.assert_allclose(actual["/msd_Sb"], desired["/msd_Sb"], atol=1e-8)
np.testing.assert_allclose(
actual["/msd_total"], desired["/msd_total"]
actual["/msd_total"], desired["/msd_total"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_parallel_meansquare():
for kk in single.keys():
if not "metadata" in kk:
np.testing.assert_allclose(
np.array(single[kk]), np.array(parallel[kk])
np.array(single[kk]), np.array(parallel[kk]), atol=1e-8
)
os.remove(temp_name + ".mda")
os.remove(temp_name2 + ".mda")
4 changes: 2 additions & 2 deletions MDANSE/Tests/UnitTests/Analysis/test_mock_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def test_vacf(interp_order, normalise):
if normalise:
np.testing.assert_allclose(
actual[f"/{key}"] * actual[f"/{key}"].attrs["scaling_factor"],
desired[f"/{key}"],
desired[f"/{key}"], atol=1e-8
)
else:
np.testing.assert_allclose(
actual[f"/{key}"], desired[f"/{key}"],
actual[f"/{key}"], desired[f"/{key}"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down
2 changes: 1 addition & 1 deletion MDANSE/Tests/UnitTests/Analysis/test_molecule_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_structure_analysis(parameters, job_info):

with h5py.File(temp_name + ".mda") as actual, h5py.File(result_file) as desired:
for key in job_info[1]:
np.testing.assert_allclose(actual[f"/{key}"], desired[f"/{key}"])
np.testing.assert_allclose(actual[f"/{key}"], desired[f"/{key}"], atol=1e-8)

os.remove(temp_name + ".mda")
assert path.exists(temp_name + ".log")
Expand Down
2 changes: 1 addition & 1 deletion MDANSE/Tests/UnitTests/Analysis/test_resolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_dos(trajectory, resolution_generator):
]:
np.testing.assert_allclose(
actual[f"/{key}"] * actual[f"/{key}"].attrs["scaling_factor"],
desired[f"/{key}"],
desired[f"/{key}"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down
9 changes: 6 additions & 3 deletions MDANSE/Tests/UnitTests/Analysis/test_scattering.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_dcsf(traj_info, qvector_grid):
np.testing.assert_allclose(
actual[f"/{key}"] * actual[f"/{key}"].attrs["scaling_factor"],
desired[f"/{key}"] * desired[f"/{key}"].attrs["scaling_factor"],
atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down Expand Up @@ -157,7 +158,7 @@ def test_ccf(traj_info, qvector_grid):
for key in keys:
# reference results were not rescaled
np.testing.assert_allclose(
actual[f"/{key}"], desired[f"/{key}"],
actual[f"/{key}"], desired[f"/{key}"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down Expand Up @@ -218,6 +219,7 @@ def test_disf(traj_info, qvector_grid):
np.testing.assert_allclose(
actual[f"/{key}"] * actual[f"/{key}"].attrs["scaling_factor"],
desired[f"/{key}"] * desired[f"/{key}"].attrs["scaling_factor"],
atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down Expand Up @@ -255,7 +257,7 @@ def test_eisf(traj_info, qvector_grid):
for key in keys:
np.testing.assert_allclose(
actual[f"/{key}"] * actual[f"/{key}"].attrs["scaling_factor"],
desired[f"/{key}"],
desired[f"/{key}"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down Expand Up @@ -297,6 +299,7 @@ def test_gdisf(traj_info):
np.testing.assert_allclose(
actual[f"/{key}"] * actual[f"/{key}"].attrs["scaling_factor"],
desired[f"/{key}"] * desired[f"/{key}"].attrs["scaling_factor"],
atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down Expand Up @@ -330,7 +333,7 @@ def test_ndtsf(disf, dcsf, qvector_grid):
]
for key in keys:
np.testing.assert_allclose(
actual[f"/{key}"], desired[f"/{key}"],
actual[f"/{key}"], desired[f"/{key}"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down
2 changes: 1 addition & 1 deletion MDANSE/Tests/UnitTests/Analysis/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_structure_analysis(
keys = [i for i in desired.keys() if any([j in i for j in job_info[1]])]
for key in keys:
np.testing.assert_allclose(
actual[f"/{key}"], desired[f"/{key}"]
actual[f"/{key}"], desired[f"/{key}"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down
16 changes: 8 additions & 8 deletions MDANSE/Tests/UnitTests/Analysis/test_thermodynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ def test_temperature(traj_info, interp_order):

with h5py.File(temp_name + ".mda") as actual, h5py.File(result_file) as desired:
np.testing.assert_allclose(
actual["/kinetic_energy"], desired["/kinetic_energy"]
actual["/kinetic_energy"], desired["/kinetic_energy"], atol=1e-8
)
np.testing.assert_allclose(
actual["/temperature"], desired["/temperature"]
actual["/temperature"], desired["/temperature"], atol=1e-8
)
np.testing.assert_allclose(
actual["/avg_kinetic_energy"], desired["/avg_kinetic_energy"]
actual["/avg_kinetic_energy"], desired["/avg_kinetic_energy"], atol=1e-8
)
np.testing.assert_allclose(
actual["/avg_temperature"], desired["/avg_temperature"]
actual["/avg_temperature"], desired["/avg_temperature"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down Expand Up @@ -110,16 +110,16 @@ def test_density(traj_info, output_format):

with h5py.File(temp_name + ".mda") as actual, h5py.File(result_file) as desired:
np.testing.assert_allclose(
actual["/atomic_density"], desired["/atomic_density"]
actual["/atomic_density"], desired["/atomic_density"], atol=1e-8
)
np.testing.assert_allclose(
actual["/mass_density"], desired["/mass_density"]
actual["/mass_density"], desired["/mass_density"], atol=1e-8
)
np.testing.assert_allclose(
actual["/avg_atomic_density"], desired["/avg_atomic_density"]
actual["/avg_atomic_density"], desired["/avg_atomic_density"], atol=1e-8
)
np.testing.assert_allclose(
actual["/avg_mass_density"], desired["/avg_mass_density"]
actual["/avg_mass_density"], desired["/avg_mass_density"], atol=1e-8
)

os.remove(temp_name + ".mda")
Expand Down
Binary file modified MDANSE/Tests/UnitTests/Converted/ase.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/ase_xyz.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/castep.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/cp2k.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/cp2k_srtio3.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/cp2k_velocity.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/dftb.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/discover.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/dlp_v2.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/dlp_v4.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/dlp_with_grad.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/forcite.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/gromacs-nvt.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/hem_cam.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/lammps.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/lammps_cgs.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/lammps_electron.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/lammps_metal.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/lammps_micro.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/lammps_moly_custom.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/lammps_moly_h5md.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/lammps_moly_xyz.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/lammps_nano.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/lammps_real.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/lammps_si.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/md.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/namd.mdt
Binary file not shown.
Binary file modified MDANSE/Tests/UnitTests/Converted/vasp.mdt
Binary file not shown.
33 changes: 19 additions & 14 deletions MDANSE/Tests/UnitTests/TrajectoryEditor/test_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ def test_editor_null():

with h5py.File(temp_name + ".mdt") as actual, h5py.File(short_traj) as desired:
np.testing.assert_allclose(
actual["/configuration/coordinates"], desired["/configuration/coordinates"]
actual["/configuration/coordinates"], desired["/configuration/coordinates"],
atol=1e-8
)
np.testing.assert_allclose(actual["/time"], desired["/time"])
np.testing.assert_allclose(actual["/time"], desired["/time"], atol=1e-8)

os.remove(temp_name + ".mdt")
os.remove(temp_name + ".log")
Expand Down Expand Up @@ -103,10 +104,10 @@ def test_editor_frames():
with h5py.File(temp_name + ".mdt") as actual, h5py.File(short_traj) as desired:
np.testing.assert_allclose(
actual["/configuration/coordinates"],
desired["/configuration/coordinates"][0:501:10],
desired["/configuration/coordinates"][0:501:10], atol=1e-8
)
np.testing.assert_allclose(
actual["/time"], desired["/time"][0:501:10]
actual["/time"], desired["/time"][0:501:10], atol=1e-8
)

os.remove(temp_name + ".mdt")
Expand Down Expand Up @@ -141,9 +142,9 @@ def test_editor_atoms():
with h5py.File(temp_name + ".mdt") as actual, h5py.File(short_traj) as desired:
np.testing.assert_allclose(
actual["/configuration/coordinates"],
desired["/configuration/coordinates"][:, 6:20, :],
desired["/configuration/coordinates"][:, 6:20, :], atol=1e-8
)
np.testing.assert_allclose(actual["/time"], desired["/time"])
np.testing.assert_allclose(actual["/time"], desired["/time"], atol=1e-8)

os.remove(temp_name + ".mdt")
os.remove(temp_name + ".log")
Expand Down Expand Up @@ -178,9 +179,10 @@ def test_editor_unit_cell():

with h5py.File(temp_name + ".mdt") as actual, h5py.File(short_traj) as desired:
np.testing.assert_allclose(
actual["/configuration/coordinates"], desired["/configuration/coordinates"]
actual["/configuration/coordinates"],
desired["/configuration/coordinates"], atol=1e-8
)
np.testing.assert_allclose(actual["/time"], desired["/time"])
np.testing.assert_allclose(actual["/time"], desired["/time"], atol=1e-8)

os.remove(temp_name + ".mdt")
os.remove(temp_name + ".log")
Expand Down Expand Up @@ -219,9 +221,10 @@ def test_editor_transmute():

with h5py.File(temp_name + ".mdt") as actual, h5py.File(short_traj) as desired:
np.testing.assert_allclose(
actual["/configuration/coordinates"], desired["/configuration/coordinates"]
actual["/configuration/coordinates"],
desired["/configuration/coordinates"], atol=1e-8
)
np.testing.assert_allclose(actual["/time"], desired["/time"])
np.testing.assert_allclose(actual["/time"], desired["/time"], atol=1e-8)

os.remove(temp_name + ".mdt")
os.remove(temp_name + ".log")
Expand Down Expand Up @@ -253,9 +256,10 @@ def test_editor_set_charges():

with h5py.File(temp_name + ".mdt") as actual, h5py.File(short_traj) as desired:
np.testing.assert_allclose(
actual["/configuration/coordinates"], desired["/configuration/coordinates"]
actual["/configuration/coordinates"],
desired["/configuration/coordinates"], atol=1e-8
)
np.testing.assert_allclose(actual["/time"], desired["/time"])
np.testing.assert_allclose(actual["/time"], desired["/time"], atol=1e-8)

os.remove(temp_name + ".mdt")
os.remove(temp_name + ".log")
Expand Down Expand Up @@ -284,9 +288,10 @@ def test_editor_find_molecules():

with h5py.File(temp_name + ".mdt") as actual, h5py.File(short_traj) as desired:
np.testing.assert_allclose(
actual["/configuration/coordinates"], desired["/configuration/coordinates"]
actual["/configuration/coordinates"],
desired["/configuration/coordinates"], atol=1e-8
)
np.testing.assert_allclose(actual["/time"], desired["/time"])
np.testing.assert_allclose(actual["/time"], desired["/time"], atol=1e-8)

os.remove(temp_name + ".mdt")
os.remove(temp_name + ".log")
2 changes: 1 addition & 1 deletion MDANSE/Tests/UnitTests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _converter_test(tmp_path, converter_type, result, compare, parameters, compr

with h5py.File(out_name) as actual, h5py.File(result_name) as desired:
for prop in compare:
np.testing.assert_allclose(actual[prop], desired[prop])
np.testing.assert_allclose(actual[prop], desired[prop], atol=1e-8)

assert out_name.is_file()
assert log_name.is_file()
Expand Down

0 comments on commit 6ea49cd

Please sign in to comment.