From f0b76682c1b8711c44e5076be1fcd72598cc89cb Mon Sep 17 00:00:00 2001 From: chrisjonesBSU Date: Mon, 8 Jul 2024 08:29:27 -0600 Subject: [PATCH] add check for periodic bond axis param --- flowermd/base/molecule.py | 9 ++++++++- flowermd/tests/base/test_molecule.py | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/flowermd/base/molecule.py b/flowermd/base/molecule.py index d6ab70fd..c517f57b 100644 --- a/flowermd/base/molecule.py +++ b/flowermd/base/molecule.py @@ -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" @@ -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 diff --git a/flowermd/tests/base/test_molecule.py b/flowermd/tests/base/test_molecule.py index 27939479..b6ad615c 100644 --- a/flowermd/tests/base/test_molecule.py +++ b/flowermd/tests/base/test_molecule.py @@ -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")