Skip to content

Commit

Permalink
starting unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StephMcCallum committed Mar 3, 2025
1 parent e68e4a9 commit c7cd328
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
7 changes: 4 additions & 3 deletions flowermd/library/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@


class SingleChainSystem(System):
"""Builds a box around a single chain.
"""Builds a vacuum box around a single chain.
Calculates the maximum distance of the chain using scipy.spatial.distance.pdist().
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
----------
See System class.
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.
"""

Expand Down
70 changes: 70 additions & 0 deletions flowermd/tests/library/test_systems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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
'''

0 comments on commit c7cd328

Please sign in to comment.