Skip to content

Commit

Permalink
Populate Group information from mBuild Compounds (#683)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate (#673)

updates:
- [github.com/psf/black: 22.3.0 → 22.6.0](psf/black@22.3.0...22.6.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Revert to older versions of forcefield

* Add import for xml_representation in parameteric potential"

* Added tests for generating a forcefield object from a GMSO topology

* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci

* Remove unused import

* pin unyt to version 2.8

* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci

* Populate group names with top level compound names if hierarchy doesn't exist

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
CalCraven and pre-commit-ci[bot] committed Aug 2, 2022
1 parent cc23eb8 commit 0a11627
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gmso/external/convert_mbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def from_mbuild(
Valid functions are element_by_symbol, element_by_name,
element_by_atomic_number, and element_by_mass, which can be imported
from `gmso.core.element'
parse_label : bool, optional, default=False
parse_label : bool, optional, default=True
Option to parse hierarchy info of the compound into system of top label,
including, group, molecule and residue labels.
Expand All @@ -85,6 +85,7 @@ def from_mbuild(
for child in compound.children:
if not child.children:
site = _parse_site(site_map, child, search_method)
site.group = compound.name
top.add_site(site)
else:
for particle in child.particles():
Expand All @@ -93,6 +94,7 @@ def from_mbuild(
top.add_site(site)
else:
site = _parse_site(site_map, compound, search_method)
site.group = compound.name
top.add_site(site)

for b1, b2 in compound.bonds():
Expand Down
9 changes: 9 additions & 0 deletions gmso/tests/test_convert_mbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,12 @@ def test_hierarchical_structure(self, hierarchical_top):
assert label in hierarchical_top.unique_site_labels(
"group", name_only=True
)

@pytest.mark.skipif(not has_mbuild, reason="mBuild is not installed")
def test_group_2_level_compound(self):
mb_cpd = mb.Compound(name="_CH4", mass=12)
filled_box = mb.fill_box(mb_cpd, n_compounds=2, density=0.01)
filled_box.name = "group1"
top = from_mbuild(filled_box)
for site in top.sites:
assert site.group == filled_box.name

0 comments on commit 0a11627

Please sign in to comment.