Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fix to mass in convert_parmed #737

Merged
merged 3 commits into from
Jun 27, 2023
Merged

Small fix to mass in convert_parmed #737

merged 3 commits into from
Jun 27, 2023

Conversation

chrisjonesBSU
Copy link
Contributor

I ran into an error when using to_parmed and from_parmed on a typed gmso topology. I think there was just a small over-sight on preparing the site.mass value by converting it to amu units and type float which is what was already being done for sigma, charge, etc..

Here is the snippet that gives an error. It results from calling round on a unyt quantity with value and units

import forcefield_utilities as ffutils
import gmso
from gmso.external import to_parmed, from_parmed, from_mbuild
from gmso.parameterization import apply
import mbuild as mb

methane_box = mb.fill_box(compound=[mb.load("C", smiles=True)], n_compounds=5, box=[2,2,2])
gmso_top = from_mbuild(methane_box)
oplsaa = ffutils.FoyerFFs().load('oplsaa').to_gmso_ff()
apply(top=gmso_top, forcefields=oplsaa, identify_connections=True)
pmd_struc = to_parmed(gmso_top)
back_to_gmso = from_parmed(pmd_struc)

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[18], line 12
     10 apply(top=gmso_top, forcefields=oplsaa, identify_connections=True)
     11 pmd_struc = to_parmed(gmso_top)
---> 12 back_to_gmso = from_parmed(pmd_struc)

File ~/gmso/gmso/external/convert_parmed.py:60, in from_parmed(structure, refer_type)
     58 # Consolidate parmed atomtypes and relate topology atomtypes
     59 if refer_type:
---> 60     pmd_top_atomtypes = _atom_types_from_pmd(structure)
     62 ind_res = _check_independent_residues(structure)
     63 for residue in structure.residues:

File ~/gmso/gmso/external/convert_parmed.py:287, in _atom_types_from_pmd(structure)
    285 for atom in structure.atoms:
    286     if isinstance(atom.atom_type, pmd.AtomType):
--> 287         unique_atom_types.add(atom.atom_type)
    288 unique_atom_types = list(unique_atom_types)
    289 pmd_top_atomtypes = {}

File ~/mambaforge/envs/hoomd-polymers/lib/python3.9/site-packages/parmed/topologyobjects.py:5312, in AtomType.__hash__(self)
   5311 def __hash__(self):
-> 5312     return hash((self.name, self._round_trunc(self.mass), self.atomic_number, self.bond_type,
   5313                  self._round_trunc(self.charge), self._round_trunc(self.epsilon),
   5314                  self._round_trunc(self.rmin), self._round_trunc(self.epsilon_14),
   5315                  self._round_trunc(self.rmin_14), tuple(self.nbfix.items())))

File ~/mambaforge/envs/hoomd-polymers/lib/python3.9/site-packages/parmed/topologyobjects.py:5319, in AtomType._round_trunc(cls, value)
   5317 @classmethod
   5318 def _round_trunc(cls, value):
-> 5319     return round(value, _TINY_DIGITS) if value is not None else None

TypeError: __round__() takes 1 positional argument but 2 were given

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (4bac8e5) 91.99% compared to head (21c2f77) 91.99%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #737   +/-   ##
=======================================
  Coverage   91.99%   91.99%           
=======================================
  Files          67       67           
  Lines        6459     6460    +1     
=======================================
+ Hits         5942     5943    +1     
  Misses        517      517           
Impacted Files Coverage Δ
gmso/external/convert_parmed.py 95.48% <100.00%> (+0.01%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@CalCraven
Copy link
Contributor

Just as a note to this, we have added the ability to load GMSO forcefields via gmso.Forcefield.load, so you shouldn't have to use ff_utils anymore. However, we should also consider adding a gmso.Forcefield.foyer_load() method as well, so you don't have to do this conversion step every time.

Copy link
Contributor

@CalCraven CalCraven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, minus the single question about the GSD pinning. Good catch @chrisjonesBSU

@@ -15,7 +15,7 @@ dependencies:
- openbabel>=3.0.0
- foyer>=0.11.3
- forcefield-utilities>=0.2.1
- gsd>=2.0
- gsd>2.0,<3.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we pinning gsd<3? I feel like we should want the latest version to have compatibility with hoomd 4.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to make an issue about this. I changed it in this PR because tests were failing. gsd 3.0 changed the API terminology from using Snapshot to Frame which causes some breaking changes in convert_hoomd

gsd.hoomd.Snapshot would need be to be changed to gsd.hoomd.Frame I'll still make an issue so that we can discuss how to handle supporting GSD.

@chrisjonesBSU
Copy link
Contributor Author

Looks like this solves #655 as well; just noticed that.

Copy link
Member

@daico007 daico007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I will merge this once all the test pass (except for the bleeding test)

@daico007 daico007 merged commit 727d32a into mosdef-hub:main Jun 27, 2023
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants