Skip to content

Commit

Permalink
add tests for actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
marjanalbooyeh committed Aug 29, 2023
1 parent 18339b6 commit 0532585
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
19 changes: 8 additions & 11 deletions hoomd_organics/tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from gmso.external.convert_mbuild import from_mbuild

from hoomd_organics import Molecule, Pack, Polymer
from hoomd_organics import Molecule, Pack, Polymer, Simulation
from hoomd_organics.library import OPLS_AA

ASSETS_DIR = os.path.join(os.path.dirname(__file__), "assets")
Expand Down Expand Up @@ -204,13 +204,10 @@ def polyethylene_system(self, polyethylene):
)
return system

# @pytest.fixture()
# def ua_polyethylene_system(self):
# system = Pack(
# molecule=PolyEthylene,
# n_mols=5,
# mol_kwargs={"length": 5},
# density=0.5
# )
# system.apply_forcefield(forcefield=GAFF(), remove_hydrogens=True)
# return system
@pytest.fixture()
def benzene_simulation(self, benzene_system):
sim = Simulation(
initial_state=benzene_system.hoomd_snapshot,
forcefield=benzene_system.hoomd_forcefield,
)
return sim
36 changes: 36 additions & 0 deletions hoomd_organics/tests/utils/test_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import copy

import hoomd

from hoomd_organics.tests import BaseTest
from hoomd_organics.utils import ScaleEpsilon, ScaleSigma


class TestActions(BaseTest):
def test_scale_epsilon(self, benzene_simulation):
sim = benzene_simulation
epsilon_scale = ScaleEpsilon(sim=sim, scale_factor=0.5)
energy_operation = hoomd.update.CustomUpdater(
action=epsilon_scale, trigger=10
)
sim.operations.updaters.append(energy_operation)
old_lj_force = copy.deepcopy(sim._lj_force().params)
sim.run_NVT(n_steps=10, kT=1.0, tau_kt=1.0)
new_lj_force = sim._lj_force().params
for k in old_lj_force.keys():
assert (
new_lj_force[k]["epsilon"] == old_lj_force[k]["epsilon"] + 0.5
)

def test_scale_sigma(self, benzene_simulation):
sim = benzene_simulation
sigma_scale = ScaleSigma(sim=sim, scale_factor=0.5)
energy_operation = hoomd.update.CustomUpdater(
action=sigma_scale, trigger=10
)
sim.operations.updaters.append(energy_operation)
old_lj_force = copy.deepcopy(sim._lj_force().params)
sim.run_NVT(n_steps=10, kT=1.0, tau_kt=1.0)
new_lj_force = sim._lj_force().params
for k in old_lj_force.keys():
assert new_lj_force[k]["sigma"] == old_lj_force[k]["sigma"] + 0.5

0 comments on commit 0532585

Please sign in to comment.