diff --git a/flowermd/library/systems.py b/flowermd/library/systems.py index 4668484e..354e0f9f 100644 --- a/flowermd/library/systems.py +++ b/flowermd/library/systems.py @@ -1,3 +1,37 @@ """Examples for the Systems class.""" -# This is a placeholder for any class that inherits from base.system +import numpy as np +from scipy.spatial.distance import pdist + +from flowermd.base.system import System + + +class SingleChainSystem(System): + """Builds a vacuum box around a single chain. + + The box lengths are chosen so they are at least as long as the largest particle distance. The maximum distance of the chain is calculated using scipy.spatial.distance.pdist(). This distance multiplied by a buffer defines the box dimensions. The chain is centered in the box. + + Parameters + ---------- + buffer : float, default 1.05 + A factor of the length of the chain to define the box dimensions. Needs to be greater than 1 so that the end particles are not on the boundaries. + + """ + + def __init__(self, molecules, base_units=dict(),buffer=1.05): + self.buffer = buffer + super(SingleChainSystem, self).__init__( + molecules=molecules, + base_units=base_units + ) + + def _build_system(self): + chain = self.all_molecules[0] + eucl_dist = pdist(self.all_molecules[0].xyz) + chain_length = np.max(eucl_dist) + box = mb.Box(lengths=np.array([chain_length] * 3) * self.buffer) + comp = mb.Compound() + comp.add(chain) + comp.box = box + chain.translate_to((box.Lx / 2, box.Ly / 2, box.Lz / 2)) + return comp diff --git a/flowermd/tests/library/test_systems.py b/flowermd/tests/library/test_systems.py new file mode 100644 index 00000000..cba0048b --- /dev/null +++ b/flowermd/tests/library/test_systems.py @@ -0,0 +1,69 @@ +import os + +import gmso +import hoomd +import numpy as np +import pytest + +from flowermd import SingleChainSystem +from flowermd.internal.exceptions import ForceFieldError, ReferenceUnitError +from flowermd.library import ( + OPLS_AA, + LJChain, +) +from flowermd.tests import BaseTest + +Class TestSystems(BaseTest): +''' +#test long chain,short chain,AA + def test_single_chain(self, polyethylene): + polyethylene_short = polyethylene(lengths=3, num_mols=1) + short_system = SingleChainSystem( + molecules=[polyethylene] + ) + short_system.apply_forcefield( + r_cut=2.5, force_field=[OPLS_AA()], auto_scale=True + ) + + + polyethylene_long = polyethylene(lengths=150, num_mols=1) + long_system = SingleChainSystem( + molecules=[polyethylene] + ) + long_system.apply_forcefield( + r_cut=2.5, force_field=[OPLS_AA()], auto_scale=True + ) + + #add assert for success in system being built + +#test CG chain + def test_single_chain_cg(self, polyethylene): + cg_chain = LJChain(lengths=15, num_mols=1) + system = SingleChainSystem( + molecules=[cg_chain] + ) + system.apply_forcefield( + r_cut=2.5, force_field=[OPLS_AA()], auto_scale=True + ) + + assert system.n_mol_types == 1 + assert len(system.all_molecules) == len(polyethylene.molecules) + assert len(system.hoomd_forcefield) > 0 + assert system.n_particles == system.hoomd_snapshot.particles.N + +#test buffer <= 1.0 breaks + def test_single_chain_buffer(self): + cg_chain = LJChain(lengths=15, num_mols=1) + system = SingleChainSystem( + molecules=[cg_chain], buffer=0.8 + ) + #add assert for break + +#test num_mols > 1 breaks + def test_single_chain_mols(self): + cg_chain = LJChain(lengths=15, num_mols=3) + system = SingleChainSystem( + molecules=[cg_chain] + ) + #add assert for break +'''