Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Single Chain system class #192

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion flowermd/library/systems.py
Original file line number Diff line number Diff line change
@@ -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
69 changes: 69 additions & 0 deletions flowermd/tests/library/test_systems.py
Original file line number Diff line number Diff line change
@@ -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
'''
Loading