-
Notifications
You must be signed in to change notification settings - Fork 658
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
Persistent topologies in JSON #643
Comments
what is your motivation to write to JSON format? |
@hainm ease of mapping python objects to and from JSON, futureproof, lightweight (no dependency added) |
Yeah I had this idea before in #253, but it didn't make sense before as data was scattered everywhere. I think you're right that each |
I'm going to try and prototype this fairly soon. I think this could inform a nicer resolution for some related issues, namely #292 and datreant/MDSynthesis#25. |
We've also got #618 which needs the spider scheme or pickling the topology and making a new Reader |
Yeah, we can set |
Completely off topic, but while I've got you here, we really need to merge develop into 363 soonish. So maybe that before you hack too much? |
@richardjgowers will do. I'll happily do this since you've been hard at work on other things. |
`basestring` got removed from Python 3. This commit replaces all its occurrences by `six.string_types`. See MDAnalysis#643 and MDAnalysis#260
`basestring` got removed from Python 3. This commit replaces all its occurrences by `six.string_types`. See MDAnalysis#643 and MDAnalysis#260
We now register TopologyAttrs using the same metaclassing mechanism as used for Parsers, Readers, and Writers. This is necessary in order to deserialize Topology objects that have been serialized to JSON. An existing Topology can now be serialized to JSON with: ```python top.to_json('topology.json') ``` and a Topology can be generated from its JSON form with: ```python top = Topology.from_json('topology.json') ``` Individual TopologyAttrs must define how to serialize themselves and to deserialize their data to make an instance of themselves for this to work. Addresses #643.
Aaron Virshup pointed this out to me. It seems like the time is right to (a) do this, and (b) make sure it can support everything we need for the long haul. Do you have somewhere where you're laying out specs for this? (For example, on this end we have a particular interest in being able to carry along bond types and bond orders along with the types of information one would normally have in a topology file for simulation, partly because this information becomes increasingly important for small molecules). Also, as @jchodera noted it will probably also be useful to talk with the mdtraj folks about this. |
@rmcgibbo noted in mdtraj/mdtraj#1144 that |
@davidlmobley we have not laid out a formal spec for this yet, and at the moment this serialization scheme is meant to make it possible to fully serialize our I'm hesitant to propose a standard too quickly, since at the moment our needs are local to MDAnalysis. We are in the midst of finishing up and merging the new topology system, and this is one component serving that end. For us it would be best to wait until after we've cleared that milestone before committing to anything new. We'll see how the chips fall for this issue (and the corresponding WIP PR #831). |
@jchodera I've had a look at the |
Since the
Topology
object is now well defined and independent of the limitations of any particular file format, it should be possible to design a scheme for serializing its information to a file, perhaps JSON. The core translation tables would simply be converted into JSON arrays, and any addtionalTopologyAttrs
theTopology
has could have their ownserialize
methods that would be called in sequence to produce a serializable data structure. The dict-like object schema of JSON would basically map directly to theTopology
object it is a serialized form of.An example could look like.
Likewise, the machinery would be there for complete deserialization. This gets trickier, though, since the appropriate
TopologyAttrs
would need to be determined from the JSON structure. Failure to find aTopologyAttr
for a particular key in the schema wouldn't be a huge problem since they function independently anyhow.The consequence of this is that any changes made to a
Topology
object can be preserved for later use, without having to rely on the limitations of any particular file format.The text was updated successfully, but these errors were encountered: