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)
- Support writing to file-like objects
- `ligand_in_water/ligand_in_water.ipynb` example is failing on openff-docs HOT 2
- JSON roundtrip doesn't work with `from_openmm` generated system HOT 3
- `from_openmm` doesn't take `System` masses HOT 3
- Bond information is silently lost in openmm roundtrip for constrained systems HOT 5
- Document known limitations of `Interchange.from_openmm`
- ENH and/or DOC: Better handling of atoms with resindex 0 in GROMACSAtom HOT 6
- Improve GROMACS export speed HOT 18
- Unique atom types in LAMMPS. HOT 6
- Improve handling of residue IDs/numbers in GROMACS files HOT 8
- Add basic performance tests
- GROMACS export crashes due to non-bonded lookup failures when virtual sites are present in some topologies HOT 2
- GROMACS Residue IDs not incremented when writing multiple copies of a unique molecule
- Status of vacuum simulations in GROMACS HOT 5
- Loosing Gromacs atom name details when using an OpenMM topology 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 6
- Make `Interchange.topology` required? HOT 2
- LAMMPS atom writer makes assigning unique IDs to chemically-identical molecules impossible HOT 3
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.