Skip to content

Commit

Permalink
raise error for bad connection types, add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjonesBSU committed Sep 8, 2023
1 parent 7e0f10c commit 7a8272a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gmso/core/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,12 @@ def iter_connections_by_site(self, site, connections=None):
connections = ["bonds", "angles", "dihedrals", "impropers"]
else:
connections = set([option.lower() for option in connections])
for option in connections:
if option not in ["bonds", "angles", "dihedrals", "impropers"]:
raise ValueError(
"Valid connection types are limited to: "
'"bonds", "angles", "dihedrals", "impropers"'
)
for conn_str in connections:
for conn in getattr(self, conn_str):
if site in conn.connection_members:
Expand Down
9 changes: 9 additions & 0 deletions gmso/tests/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,15 @@ def test_iter_connections_by_site_none(self, ethane):
):
assert site in conn.connection_members

def test_iter_connections_by_site_bad_param(self, ethane):
ethane.identify_connections()
site = ethane.sites[0]
with pytest.raises(ValueError):
for conn in ethane.iter_connections_by_site(
site=site, connections=["bond"]
):
pass

def test_write_forcefield(self, typed_water_system):
forcefield = typed_water_system.get_forcefield()
assert "opls_111" in forcefield.atom_types
Expand Down

0 comments on commit 7a8272a

Please sign in to comment.