Skip to content

Commit

Permalink
add check for periodic bond axis param
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjonesBSU committed Jul 8, 2024
1 parent 42449f2 commit f0b7668
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion flowermd/base/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ class Polymer(Molecule):
bond_orientation: list, default None
The orientation of the bond between connected atoms.
periodic_bond_axis : str, default None
Axis along which to orient the polymer backbone along.
Axis which to orient the polymer backbone along.
Once the chain is aligned, a periodic bond between
head and tail atoms is formed.
Options are "x", "y", or "z"
Expand Down Expand Up @@ -521,6 +521,13 @@ def monomer(self):

def _build(self, length):
if self.periodic_bond_axis:
if not isinstance(
self.periodic_bond_axis, str
) or self.periodic_bond_axis.lower() not in ["x", "y", "z"]:
raise ValueError(
"Valid choices for a `periodic_bond_axis` are "
"'x', 'y', 'z'"
)
add_hydrogens = False
else:
add_hydrogens = True
Expand Down
6 changes: 6 additions & 0 deletions flowermd/tests/base/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,9 @@ def test_periodic_bond(self, polyethylene, axis):
n_particles_with = pe_with_bond.molecules[0].n_particles
assert n_bonds - n_bonds_with == 1
assert n_particles - n_particles_with == 2

def test_periodic_bond_bad_axis(self, polyethylene):
with pytest.raises(ValueError):
polyethylene(num_mols=1, lengths=20, periodic_bond_axis=1)
with pytest.raises(ValueError):
polyethylene(num_mols=1, lengths=20, periodic_bond_axis="a")

0 comments on commit f0b7668

Please sign in to comment.