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 Bond Order information to Topology #1308
Conversation
cc @andrrizzi @jchodera as this is a feature related to our projects. |
The Travis failures appear to be OSX image problems with Ruby version on Brew, I think the fix is just |
Also re-triggers builds, hopefully AppVeyor is fixed Taken from a Travis CI official here Homebrew/brew#3299 (comment)
""" | ||
Creates a subclass for all classes intended to be a singleton. This | ||
maintains the correctness of instance is instance even following | ||
pickling/unpickling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a test to ensure that the topology is unchanged by a pickle cycle?
Fix fork's conflicts with upstream
Bond order info is not checked when comparing bond objects in topology, may be missing information
I modified the With respect to the original post, any feed back on the two outstanding points I asked about? |
For 1. it seems to me that either it should be illegal to define two bonds between the same pair of atoms, or the comparison operators ought to check the type and order. For 2, I think the (admittedly) slightly-breaking way you did the dataframe is the best way. |
Can confirm that type and order information is preserved on conversion
mdtraj/core/topology.py
Outdated
if other.type != self.type: | ||
return False | ||
if other.order != self.order: | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this is a bit pedantic, but I don't think you have a total ordering now since you changed eq w/o changing gt and lt. two bonds that share the same atoms but have different type or order are neither greater than, less than, nor equal to one another under the current code.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under that condition (same atom indices, but different type/order), that should probably throw an error somewhere since that means there are two Bonds
between the same pair of atoms (as you mentioned before). I can't think of a use case where that may be helpful, unless you are defining a type of additional restraint through the "bond" framework of whatever simulation package you are using.
I'm not sure where there would be a good time to check for multiple bonds on the same atoms. The add_bond
method could check to see if there is already a bond between atom1 and atom2 in the Topology._bonds list, but will that add too much overhead? The only way you could have 2 bonds on the same pair of atoms is if you manually call add_bond
right now; I don't think any of the programatic ways (e.g. from_openmm
, join
) can cause this case.
If you don't mind the overhead of doing a for a,b in self._bonds
each time add_bond
is called, I can add this in and then not have to worry about the inequality. Alternately, I can add an absolute order to order
and type
properties for Bond.__lt__
and Bond.__gt__
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said before, I'm really fine with either it being illegal to have multiple bonds between the same pair of atoms or comparison operators that properly handle multiple bonds between the same pair of atoms. I wouldn't worry about the overhead of checking -- it's easy to optimize if slow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you ought not to have to write all of the comparators either -- @functools.total_ordering can fill in most of them
I've added in the full inequality check. It should catch all the corner cases. Although come to think of it, I could probably do it simpler by just making a tuple of The test which keeps failing looks like something to do with one of the notebooks accessing a remote file, I don't think thats something I broke. |
Yeah, that test is something I was trying to fix in #1315, so don't worry about that. |
+1 for the tuple idea too. much easier. |
I think there might be more tests failing, e.g. starting on line 2928 of https://travis-ci.org/mdtraj/mdtraj/jobs/309785921#L2928. |
So it did, that is something I broken then. I'll figure that out and make a new push once my local tests pass |
Make the Singleton objects public if we want people to use them as part of `Topology.add_bonds`
A couple things:
|
The pickle round trip for the Bond object does not preserve the `type` and `order` parameters in Python 2.7. Near as I can tell, its because the parent `namedtuple` already has a __getstate__ method, so the default of returning the `__dict__` is never given, so `__setstate__` is not called (as default). This leads to pickle restoring the state, but never invoking the `__new__` statement, resulting in `type` and `order` being lost. This PR fixes this problem in python 2.7, without breaking python 3.x versions. Related mdtraj/mdtraj#1308
Grain of salt on the tests passing, only the AppVeyor tests ran, travis never hooked into the commit (f8624c4) |
The topology tests run on windows, so I'm sure it's fine. |
v1.9.2 (July 30, 2018) --------------------- We're pleased to announce the release of MDTraj 1.9.2. This version has a number of bug fixes and improvements for trajectory parsing and conversion. - Fix bug in TINKER ARC reader (#1371) - Improved mdconvert error message (#1368) - Striding relative to current position in XTC and TRR (#1364) - Return last successful read frame for DCD (#1358) - Handle stride like numpy for DCDs (#1352) - Fix pickling of virtual site's element field (#1350) - Compile geometry extension with OpenMP (#1349) - Ensure correct dtype in neighborlist box vectors (#1344) - Added support for prm7 topology file extension (#1334) - Added efficient stride handling fo TRR (#1332) - Use byte offsets between frames for stride of XTCs (#1331) - Updated the calculation of chi5 (#1322, #1323) - Added testing against conda-forge channel (#1310) - Port [OpenMM bond order](openmm/openmm#1668) representation into MDTraj. Implements the `Bond` class to Topology and updates the Mol2 reader to use bond_order field (#1308)
This PR ports the OpenMM bond order representation into MDTraj. Implements the
Bond
class to Topology and updates the Mol2 reader to use bond_order field.This does change the API a bit since bonds are now represented by a class instead of just two atoms. However, most backwards compatibility should be preserved as each
Bond
is subclass of thenamedtuple
so you can iterate byfor a,b in top.bonds
and still get aAtom
class fora
andb
. This behavior is only different in theto_dataframe
output (see below).There are a couple of points which I implemented which I would like some additional feedback on.
Topology
equality checks.to_/from_dataframe
representation ofBond
. I changed the output of this to float to represent theBond.type
as fractional for things like Aromatic and Amide, without having to have a numpy array of mixed type or structured arrays. Since this is the main API breaking component, it would be good to get some feedback on this implementation and if others have a better way of making this conversion.Fixes #1307