Comments (5)
Thanks for finding this - I can reproduce it and it's totally valid
That part of the JSON blob is parsed here, where something is going awry when re-instantiating the object.
It's not the raw JSON parsing, which finds the right value, but something in .parse_raw
is not iterating over the keys and mapping them onto fields like I'd expect
In [17]: json.loads(i["Electrostatics"].json())["scale_14"]
Out[17]: 0.8333333333
In [18]: SMIRNOFFElectrostaticsCollection.parse_raw(i["Electrostatics"].json())
Out[18]: Handler 'Electrostatics' with expression 'coul', 11 mapping keys, and 11 potentials
In [19]: SMIRNOFFElectrostaticsCollection.parse_raw(i["Electrostatics"].json()).scale_14
Out[19]: 0.5
Interchange
has a custom loader, but this particular collection does not. It falls back to this function, which ... maybe isn't parsing numbers at all? I think this line is indented over one too far
The quickest fix for this behavior would be to set the default value to the traditional value of round(5 / 6, 10)
- notice how the class definition doesn't override the default provided by its base class(es).
In [25]: SMIRNOFFElectrostaticsCollection().scale_14
Out[25]: 0.5
Obviously a more robust fix would go onto the base class's JSON parsing function. To be honest, the JSON roundtripping of Interchange
s (and their constituent components) is neither well-tested nor broadly-used yet, so there are probably more than a few of these bugs out there. One day I'll add a bunch of tests that just round-trip everything with JSON from a variety of different states ....
Anyway, happy to review PRs for any combination of these ideas if you wanted to take a stab at them and if my suggestions are coherent. You're under no obligation to, of course, as this is all behavior that a user should expect to work.
from openff-interchange.
Here's the sort of test I would like added en masse one day1: using only slight extensions of your snippet:
from openff.toolkit import Molecule, ForceField, Quantity
from openff.interchange import Interchange
from openff.interchange.drivers import get_gromacs_energies
def test_issue_908():
m = Molecule.from_smiles("CCC")
m.generate_conformers()
t = m.to_topology()
t.box_vectors = Quantity([4, 4, 4], "nanometer")
ff = ForceField("openff-2.1.0.offxml")
i = ff.create_interchange(t)
with open("test.json", "w") as f:
f.write(i.json())
j = Interchange.parse_file("test.json")
get_gromacs_energies(i).compare(get_gromacs_energies(j))
# FAILED test.py::test_issue_908 - openff.interchange.exceptions.EnergyError: {'Electrostatics': <Quantity(-0.29432869, 'kilojoule / mole')>}
I think there are some basic tests for JSON round-tripping, just not one that looks at this particular comparison
Footnotes
-
Just with a lot of different chemistries, force fields, engines, serialization formats, periodicity on or off, virtual sites included or excluded, the list goes on ... ↩
from openff-interchange.
@pbuslaev try the main
branch now - not sure when the next release will be
from openff-interchange.
@mattwthompson Thanks a lot! Looks super cool.
Related question, I would like to use Interchange
combination functionality. Do you want me to add test cases for it?
from openff-interchange.
Absolutely!
The only detail you should be aware of is that I'm planning on Interchange.__add__
going away and it being replaced by some sort of Interchange.combine
. The business logic should be similar, but having it be a concrete method allows for arguments to be passed in and for the possibility that something could be returned (i.e. some sort of atom mapping between input and final states).
from openff-interchange.
Related Issues (20)
- Electrostatics key mismatch after combination HOT 3
- Positions of `MonovalentLonePair` virtual sites is incorrect (does not affect simulations) HOT 1
- Virtual site parameters can clash if looked up using only SMIRKS HOT 4
- `experimental/openmmforcefields/gaff.ipynb` and `ligand_in_water.ipynb` notebooks broken on OpenFF Docs HOT 1
- units for `Interchange.collection['Bonds'].get_system_parameters()` HOT 2
- Support GROMACS's `3fad` virtual sites
- `get_positions_with_virtual_sites` does not collate virtual sites with molecules HOT 1
- Some combinations of Interchanges do not commute HOT 2
- Improved LAMMPS support. HOT 1
- LAMMPS versions prior to 2023.08.02 are incompatible with Interchange, but may be installed with it HOT 2
- Interchange.to_gromacs() creates a topology with far too many atomtypes, which influences GROMACS performance HOT 4
- Syncing topology and `Interchange` attributes
- Easier indexing into collections
- Look into ordering of charge dictionary
- Combining a Sage interchange with one loaded from OpenMM fails because the electrostatics cutoff is not set by the OpenMM importer, but is checked by the `combine` method HOT 1
- GROMACS writer chokes without unique molecule names HOT 5
- `experimental/openmmforcefields/gaff.ipynb` is failing on openff-docs HOT 3
- Dihedrals lost in `Interchange.from_gromacs` HOT 1
- PACKMOL wrapper with >100,000 atoms HOT 5
- Make `Interchange.topology` required? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openff-interchange.