Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjonesBSU committed Jul 7, 2024
1 parent f6ad467 commit 5431166
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions flowermd/tests/base/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,43 @@ def test_initialize_from_state(self, benzene_system):
reference_values=benzene_system.reference_values,
)

def test_initialize_from_simulation_pickle(self, benzene_system):
sim = Simulation.from_snapshot_forces(
initial_state=benzene_system.hoomd_snapshot,
forcefield=benzene_system.hoomd_forcefield,
reference_values=benzene_system.reference_values,
)
sim.save_simulation("simulation.pickle")
new_sim = Simulation.from_simulation_pickle("simulation.pickle")
assert new_sim.dt == sim.dt
assert new_sim.gsd_write_freq == sim.gsd_write_freq
assert new_sim.log_write_freq == sim.log_write_freq
assert new_sim.seed == sim.seed
assert (
new_sim.maximum_write_buffer_size == sim.maximum_write_buffer_size
)
assert new_sim.volume_reduced == sim.volume_reduced
assert new_sim.mass_reduced == sim.mass_reduced
assert new_sim.reference_mass == sim.reference_mass
assert new_sim.reference_energy == sim.reference_energy
assert new_sim.reference_length == sim.reference_length
snap = sim.state.get_snapshot()
new_snap = new_sim.state.get_snapshot()
assert np.array_equal(
snap.particles.position, new_snap.particles.position
)
new_sim.run_NVT(n_steps=2, kT=1.0, tau_kt=0.001)

def test_initialize_from_bad_pickle(self, benzene_system):
sim = Simulation.from_snapshot_forces(
initial_state=benzene_system.hoomd_snapshot,
forcefield=benzene_system.hoomd_forcefield,
reference_values=benzene_system.reference_values,
)
sim.pickle_forcefield("forces.pickle")
with pytest.raises(ValueError):
Simulation.from_simulation_pickle("forces.pickle")

def test_no_reference_values(self, benzene_system):
sim = Simulation.from_snapshot_forces(
initial_state=benzene_system.hoomd_snapshot,
Expand Down

0 comments on commit 5431166

Please sign in to comment.