diff --git a/hoomd_organics/tests/base_test.py b/hoomd_organics/tests/base_test.py index 1c8c94c4..66b07d2b 100644 --- a/hoomd_organics/tests/base_test.py +++ b/hoomd_organics/tests/base_test.py @@ -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") @@ -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 diff --git a/hoomd_organics/tests/utils/test_actions.py b/hoomd_organics/tests/utils/test_actions.py index e69de29b..03f98741 100644 --- a/hoomd_organics/tests/utils/test_actions.py +++ b/hoomd_organics/tests/utils/test_actions.py @@ -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