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

Add utilities for parsing gmso forcefields XML. Closes #4 #5

Merged
merged 38 commits into from
Aug 19, 2022

Conversation

umesh-timalsina
Copy link
Member

No description provided.

@codecov
Copy link

codecov bot commented Jun 17, 2022

Codecov Report

Merging #5 (135bf73) into main (096c1e8) will increase coverage by 4.23%.
The diff coverage is 95.61%.

@@            Coverage Diff             @@
##             main       #5      +/-   ##
==========================================
+ Coverage   86.60%   90.84%   +4.23%     
==========================================
  Files           9       12       +3     
  Lines         702     1322     +620     
==========================================
+ Hits          608     1201     +593     
- Misses         94      121      +27     
Impacted Files Coverage Δ
forcefield_utilities/tests/utils.py 83.33% <83.33%> (ø)
forcefield_utilities/utils.py 92.68% <92.85%> (+0.09%) ⬆️
forcefield_utilities/gmso_xml.py 94.28% <94.28%> (ø)
forcefield_utilities/xml_loader.py 95.06% <94.87%> (+0.14%) ⬆️
forcefield_utilities/__init__.py 100.00% <100.00%> (ø)
forcefield_utilities/tests/test_gmso_xml.py 100.00% <100.00%> (ø)
forcefield_utilities/tests/test_xml_loader.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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.

I think this looks good! Have a few questions, but nothing major. I think this is ready to be merged (or after you add the remaining test @umesh-timalsina)

forcefield_utilities/gmso_xml.py Show resolved Hide resolved
forcefield_utilities/gmso_xml.py Outdated Show resolved Hide resolved
@umesh-timalsina
Copy link
Member Author

Depends on mosdef-hub/gmso#681

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.

Going to push a few tests here and in GMSO for handling the reading for these functions. We should wait on this until those are all implemented. I think we're going to transition in the next week to a full dependency on forcefield-utilities for GMSO.


if (
torsion_type.type1
and torsion_type.type2
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't work if the type or class is only partially defined e.g.

<DihedralType name="DihedralType1" type1="" type2="C" type3="C" type4="">

We need to switch the and's for or's here to check if any one is defined.

Copy link
Member Author

Choose a reason for hiding this comment

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

@CalCraven Good catch. I think we need an alternative approach where in the default value is populated as a * and this check should stay as is.

@daico007
Copy link
Member

mosdef-hub/gmso#681 is merged.

@CalCraven
Copy link
Contributor

I'm having an issue with the defaults unyts K*kb for energy when loading these forcefields. The GMSO inhouse reader can do it fine, so I think it's something we need to fix here before merging.

@CalCraven
Copy link
Contributor

CalCraven commented Aug 12, 2022

 def test_ffutils_backend(self):
        ff = ForceField()
>       ff.load_backend_forcefield_utilities(get_path("ff-example0.xml"))

self = FFMetaData(children=[Units(energy='K*kb', distance='nm', mass='amu', charge='coulomb', temperature=None, angle=None, time=None)], electrostatics14Scale=0.5, nonBonded14Scale=0.67, combining_rule='lorentz')

    def get_default_units(self):
        units_dict = {}
        units = self.children[0].dict(by_alias=True, exclude_none=True)
        for name, unit in units.items():
            try:
                units_dict[name] = u.Unit(unit)
            except u.exceptions.UnitParseError:
>               units_dict[name] = getattr(u.physical_constants, unit)
E               AttributeError: module 'unyt.physical_constants' has no attribute 'K*kb'

def load_backend_forcefield_utilities(self, filename, backend="forcefield-utilities"):
     from forcefield_utilities.xml_loader import GMSOFFs
     loader = GMSOFFs()
     self = loader.load(filename).to_gmso_ff()

@CalCraven
Copy link
Contributor

CalCraven commented Aug 12, 2022

For now, I will test forcefields in GMSO that don't have the K*kb unit styles. Once this PR is merged, we should fix that functionality.

@umesh-timalsina
Copy link
Member Author

umesh-timalsina commented Aug 17, 2022

@CalCraven I think this is fine to do as long as we define a new unit called _kb and similar units that would be good. Then we would either extend the existing unyt registry or define our own for find and replace. Since kb is already defined and is a physical_quantity in unyt. Similar utilities were developed in the inhouse reader which can be added here but we need a listing of relevant physical quantities that are used interchangeably as units.

>>> import unyt as U
>>>  U.define_unit('_kb', 1.0 * U.kb)

@umesh-timalsina
Copy link
Member Author

This is still incomplete with duplicates trimming. Because of multiple sections allowed. An alternate strategy is necessary to weedout duplicates.

@CalCraven
Copy link
Contributor

To be clear, duplicates means duplicate section headers in the XML. I would expect duplicated sections to just append to that object in the GMSO ForceField class, but if it's going to take a bit more time to implement, I would suggest merging this as is and document that we only support a single section for now, pending a new PR for it.

@daico007
Copy link
Member

Agree with @CalCraven that we should merge this PR in the interest of time, and we can list the remaining to do as issue to be deal with in near future.

@umesh-timalsina
Copy link
Member Author

umesh-timalsina commented Aug 18, 2022

I am working on an async coroutine to make sure we error out on any duplicates encountered. Should be complete soon.

@umesh-timalsina umesh-timalsina merged commit 7284f24 into main Aug 19, 2022
@umesh-timalsina umesh-timalsina deleted the 4-gmso-xml-parsing branch August 19, 2022 00:11
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