Skip to content

Comments

Identifier key as part of potential type#64

Merged
CalCraven merged 4 commits intomosdef-hub:mainfrom
CalCraven:main
Feb 10, 2026
Merged

Identifier key as part of potential type#64
CalCraven merged 4 commits intomosdef-hub:mainfrom
CalCraven:main

Conversation

@CalCraven
Copy link
Contributor

Adding the string class "identifier" to potential objects, such as angletypes, bondtypes, etc, so these can be stored such that rewriting a forcefield using "classes" or "types" is possible.

Use Case

import gmso
ff = gmso.ForceField()
bondtype = gmso.core.bond_type.BondType(name="b1", identifier="CT-CT", member_classes=("CT", "CT"))
ff.bond_types["CT-CT"] = bondtype # this key and the identifier string should match
# TODO: probably would be nice to set it up in gmso so you can only specify `member_classes`, and `identifier` will be populated from there.
ff.to_xml("tmp.xml")
load_ff = ForceField("tmp.xml", strict=False)
print(load_ff.bond_types.keys())
print(hasattr(list(load_ff.values())[0], "identifier"))

With PR, output is

"CT-CT"
True

Without PR, output is

"CT~CT" # Note this is changed from - to ~ as the bondtype, since the ffkey is generated from member_classes, which loses info on the bondtype.
False

**Note this requires a different version of gmso to run. Will need mosdef-hub/gmso#958

@CalCraven
Copy link
Contributor Author

Wait to merge until mosdef-hub/gmso#958 is ready to go.

@CalCraven
Copy link
Contributor Author

Probably need to hard and fast map the identifier to a tuple of values instead of the string. I.e. it should be ("CT", "~", "CT") instead of "CT~CT". This would help us handle the case with bond symbols in the atomclass names, since then they could be specified as type1 = "C=", and type2="C=", which maps to ("C=", "=", "C=")

@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 8.47458% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.69%. Comparing base (529839d) to head (c067615).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
forcefield_utilities/gmso_xml.py 8.47% 54 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (529839d) and HEAD (c067615). Click for more details.

HEAD has 160 uploads less than BASE
Flag BASE (529839d) HEAD (c067615)
168 8
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #64       +/-   ##
===========================================
- Coverage   93.29%   76.69%   -16.61%     
===========================================
  Files          12       12               
  Lines        1641     1665       +24     
===========================================
- Hits         1531     1277      -254     
- Misses        110      388      +278     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@CalCraven CalCraven merged commit 9b4ba19 into mosdef-hub:main Feb 10, 2026
9 of 21 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.

2 participants