Skip to content

Commit

Permalink
add unit test for _scale_charges, remove import from init func in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjonesBSU committed Aug 29, 2023
1 parent 0f9b87a commit 1cd61eb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
22 changes: 22 additions & 0 deletions hoomd_organics/tests/base/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,25 @@ def test_lattice_molecule(self, benzene_molecule):
assert len(system.hoomd_forcefield) > 0
assert system.n_particles == system.hoomd_snapshot.particles.N
assert system.reference_values.keys() == {"energy", "length", "mass"}

def test_scale_charges(self, pps):
pps_mol = pps(num_mols=5, lengths=5)
no_scale = Pack(
molecules=pps_mol,
density=0.5,
r_cut=2.4,
force_field=OPLS_AA_PPS(),
auto_scale=True,
scale_charges=False,
)

with_scale = Pack(
molecules=pps_mol,
density=0.5,
r_cut=2.4,
force_field=OPLS_AA_PPS(),
auto_scale=True,
scale_charges=True,
)
assert abs(no_scale.net_charge.value) > abs(with_scale.net_charge.value)
assert np.allclose(0, with_scale.net_charge.value, atol=1e-30)
31 changes: 20 additions & 11 deletions hoomd_organics/tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ def __init__(self, lengths, num_mols, **kwargs):

return _PolyEthylene

@pytest.fixture()
def pps(self, pps_smiles):
class _PPS(Polymer):
def __init__(self, lengths, num_mols, **kwargs):
smiles = pps_smiles
bond_indices = [7, 10]
bond_length = 0.176
bond_orientation = [[0, 0, 1], [0, 0, -1]]
super().__init__(
lengths=lengths,
num_mols=num_mols,
smiles=smiles,
bond_indices=bond_indices,
bond_length=bond_length,
bond_orientation=bond_orientation,
**kwargs
)

return _PPS

@pytest.fixture()
def polyDME(self, dimethylether_smiles):
class _PolyDME(Polymer):
Expand Down Expand Up @@ -219,14 +239,3 @@ def polyethylene_system(self, polyethylene):
remove_hydrogens=True,
)
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
2 changes: 1 addition & 1 deletion hoomd_organics/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .actions import *
from .base_types import FF_Types
from .ff_utils import xml_to_gmso_ff
from .utils import check_return_iterable, scale_charges
from .utils import check_return_iterable

0 comments on commit 1cd61eb

Please sign in to comment.