-
Notifications
You must be signed in to change notification settings - Fork 652
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
All deprecations on AtomGroup and friends getters and setters. #698
Conversation
The new topology system for #363 will arrive in 0.15.0, and this removes redundant getters and setters of various `Atom`, `Residue`, and `Segment` properties. These methods predated the properties that replace them, and this commit features deprecation warnings for each with instructions on what to use instead. Some `Atom` properties, such as `number`, `pos`, `serials`, have themselves been replaced in the new scheme (`index`, `position`, `id`, respectively). The centroid method has also been removed. The methods `AtomGroup.translate` and `AtomGroup.rotateby` no longer take tuples of `AtomGroup` objects as optional arguments, but only take explicit vectors. Because `Residue`, `ResidueGroup`, `Segment`, and `SegmentGroup` are no longer `AtomGroup`s themselves, leaving this in creates a minor convenience at the cost of method complexity. The documentation is correspondingly complex, and in the course of updating the docstrings to numpy-style for #363, simplifying the method also simplified the documenation. Also deprecated `as_Universe` function. This has yet to be discussed on the `issue-363` branch, but discussion should happen on what its purpose is. Not addressed in this commit: 1) In #363, `__getattr__` behavior for the Groups have changed to a slightly different scheme. No warnings have been added for this change to the `__getattr__` methods yet. The new scheme goes as:: SegmentGroups __getattr__ can select by segment name Segment __getattr__ can select by residue name ResidueGroup __getattr__ can select by residue name Residue __getattr__ can select by atom name AtomGroup __getattr__ can select by atom name Should only require the following in `AtomGroup.__getattr__`, or pehaps override in `ResidueGroup` and add after a `super`: ```python if isinstance(self, ResidueGroup): warnings.warn("In version 0.15.0 this will select " "residue names, not atom names ", DeprecationWarning) ``` 2) I left bonds things alone as it's not my area of expertise. Any deprecations on that front should be placed by @richardjgowers. 3) Because `Residue`, `ResidueGroup`, `Segment`, and `SegmentGroup` are no longer `AtomGroup`s themselves, there are methods such as `Segment.names` that now longer exist (one would use `Segment.atoms.names` instead). Something like: ```python if isinstance(self, Segment): warnings.warn("In version 0.15.0, use `segment.atoms.names " "instead.", DeprecationWarning) ``` will be needed.
The methods `phi_selection`, `psi_selection`, `omega_selection`, and `chi1_selection` rely on particular atom names and the contiguity of resids to work properly. Although these are not bad assumptions for most topologies with a protein, they are inherently fragile. They have not been included in the new topology system addressing #363.
Quick comment: I would want to keep the "slot in groups of atoms for |
@orbeckst I will reinstate the conveniences built into these transformation methods. |
@@ -3336,6 +3378,7 @@ def __init__(self, name, id, atoms, resnum=None): | |||
##if not Residue._cache.has_key(name): | |||
## Residue._cache[name] = dict([(a.name, i) for i, a in enumerate(self._atoms)]) | |||
|
|||
@deprecate(message=_FIFTEEN_DEPRECATION) |
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.
Can these not get moved across?
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 think these things are really fragile. They depend on particular atom names (however customary), and the implementation also seems a bit frail, depending on residue id being in order for the chain. I'd rather mark them as deprecated and then reverse the decision later if we think they can be included with confidence.
They've been included for now among the Atomnames
TopologyAttr in the 363 branch (dbe6d06), but they don't work at the moment since they depend on Residue __getitem__
working with atom names in a funny way. This isn't implemented yet, and I'm not sure it should be, but it is possible. See __getattr__
for Residues for an example of how.
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.
"Fragile" is a very relative term. They work for pretty much anyone who cares about them, i.e. if you have protein simulations then there's a very good chance that this works because the naming is de-facto standard for the backbone atoms (termini is more varied but not as varied between the force fields and PDB that it wouldn't make sense to catch them). It's easy to take the developer's high-road and only provide functionality that "never ever will break" (haha) but that misses the point that most users are quite happy to get the work done in 90% of cases and would simply appreciate a good error message in the remaining 10%.
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.
... so, I don't want to deprecate them.
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.
Yeah rather leave a note in the doc string so people can look into it if it fails.
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.
Alright, I'll remove these from deprecation. @richardjgowers we'll probably need to redo the implementation of these under the new scheme.
I found a potential use for
And then
Then both Correct me if there is a better way of manually adding an attribute to the topology that gets propagated down to the individual atoms. |
@khuston hmm, adding the attribute should propogate it without your hack... I'll have a poke around |
I'm sorry -- I'm mistaken, and the |
@dotsdl what is still needed to get the deprecations merged? |
@kain88-de I'll be addressing the comments made here and elsewhere (#599) and have this PR ready for merge by the end of the week. I've got this whole week for development, and this is among the things at the top of my list. |
Also added warning that getattr on ResidueGroups will work only for residue names, not atom names.
Added more deprecations; see top comment for updates. Ready for review again and hopeful for merge. |
@@ -457,8 +457,84 @@ | |||
# And the return route | |||
_SINGULAR_PROPERTIES = {v: k for k, v in _PLURAL_PROPERTIES.items()} | |||
|
|||
_FIFTEEN_DEPRECATION = "This will be removed in version 0.15.0" | |||
_FIFTEEN_DEPRECATION = "This will be removed in version 0.16.0" |
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.
Can you run a global replace to _SIXTEEN_DEPRECATION
? In case you are using emacs and projectile the short cut it C-p r
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.
Or just in this file since all changes are in one file.
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.
Yeah, I'll make the change.
self.name = x | ||
|
||
@property | ||
@deprecate(message="{}; use `segid` property instead".format(_SIXTEEN_DEPRECATION)) |
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.
Is git messing up or are you really adding deprecated features here?
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 think git's messing up. I only added the segid
property, which for the moment refers to segment name
internally.
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.
Since id
also uses name (see left of screen), it would be really bad if name
wasn't already there.
So bonds won't work any differently in the future, apart from the fact they're now only accessible from Atom/AtomGroup. I've added deprecations for this |
Okay, so I hope nobody uses I'm shoring up the suggestion to use |
In the new topology scheme, atomid is just a label present defined by the topology format (gro and PDB files have them) that don't need to start from 0 or be unique. Atoms are uniquely identified by atom *index* instead, which is mostly internal to the topology system but is unique between atoms and starts from 0. Given this, we make atom id in the old system roughly behave as it will for the new scheme. Strangely, atom ids up until this point were defined by residues. I have no idea why, or what a good reason might have been for this.
…ysis into issue-599-deprecations
Alright, we should be set, then. Ready to merge if there is nothing further. |
Looks good to me. I've you add it to the CHANGELOG I think we are good to go. Since all deprecations already have a replacement I think @tylerjereddy could make changes for a |
Hold up...I missed some things. For one thing, Adding properties for these things, and the appropriate deprecation for the alternative that should be used. |
… respectively Since Residues are an AtomGroup subclass here, a Residue has e.g. `resids`, which gives per-atom resids (all the same, *hopefully*). This doesn't exist in #363, so added proper deprecations. Ditto for segment properties that spit out per-residue results. Also, since we don't want our own recommendations for setters using the deprecated setters internally, did simple copy-paste of setter code to appropriate property. Also deprecated Residue.id, Residue.name, and added Residue.resid and Residue.resname as the proper alternatives. Still getting deprecation warnings on loading a PSF+DCD Universe. Next up is checking all the readers for internal use of deprecated properties/methods.
So, did a lot in the last commit (b399e18). See log for details. What needs doing: we get deprecation warnings on load of a tldr: our own code shouldn't throw deprecation warnings. Only user code should. |
Ok I'm reviewing this |
So, we want a separate |
@dotsdl loading PSF/DCD universe doesn't throw warnings now, except..... The anchoring stuff. I read through it all, and there's no reason why it won't work in the new scheme. I'm not sure how useful it is to pickle AtomGroups? but it should still work as best I can tell. Maybe remove these deprecations and raise an Issue if we want to axe this feature? |
@richardjgowers I don't think it makes any sense to pickle AtomGroups in the new scheme, since they are useless without a But that's another discussion. Let's de-deprecate the anchoring machinery so it stops throwing warnings from internal use. I doubt users are using this stuff directly, though I could be surprised. We should put a deprecation warning on AtomGroup's |
@tylerjereddy we started making a list here but it needs expanding a lot. I'll try and fill it out today |
The anchor mechanisms of a Universe deserve further discussion. They are used for AtomGroup pickling/unpickling, which may or may not make sense under the new system. De-deprecating for now, though.
…ysis into issue-599-deprecations
Also, moved warning decorator outside of cached decorator if present so it displays every time. We should now be good to go here.
Okay, after some last fixes on some omissions, I think we're finally ready. CHANGELOG updated, too. These deprecation warnings should help us out when adapting the existing tests to the new API conventions, since currently the test suite throws them everywhere. |
On 2 Apr, 2016, at 09:46, Tyler Reddy wrote:
Assuming that there's no harm in running "ten2sixteen" on >0.11 code, I'd say make a new ten2sixteen and remove ten2eleven ... we just mustn't forget to update wiki etc. |
Anything else to address here? Otherwise can we merge? |
This results in a lot of warning messages now about deprecations. It should be easy enough to grep for the words and replace them but I lost track what they all were. @dotsdl can you make a list of the deprecated methods and their preferred alternative, then I can change them across the whole codebase (emacs has a function for that 😉) |
Plus I get deprecation warning when I use the preferred methods |
@kain88-de I'm working on this a little. positions is because it goes through get_positions, so it needs to get redone so that get_positions goes via positions. Ideally we should be able to run the tests with no deprecation warnings |
@@ -1143,6 +1234,7 @@ def n_segments(self): | |||
return len(self.segments) | |||
|
|||
@property | |||
@warn_atom_property |
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.
which one should be used instead in the future?
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.
*Group.atoms.indices
Indices always refer to atom indices (zero-based, and always unique among atoms), no matter what level called from. In order to get back indices as they currently work from all levels (except AtomGroup) in the new system, one must prefix with .atoms
.
The new topology system for #363 will arrive in 0.16.0, and this removes
redundant getters and setters of various
Atom
,Residue
, andSegment
properties. These methods predated the properties that replacethem, and this commit features deprecation warnings for each with
instructions on what to use instead.
Some
Atom
properties, such asnumber
,pos
,serials
, have themselves beenreplaced in the new scheme (
index
,position
,id
, respectively).The centroid method has also been removed.
The methods
AtomGroup.translate
andAtomGroup.rotateby
no longertake tuples of
AtomGroup
objects as optional arguments, but only takeexplicit vectors. Because
Residue
,ResidueGroup
,Segment
, andSegmentGroup
are no longerAtomGroup
s themselves, leaving this increates a minor convenience at the cost of method complexity. The
documentation is correspondingly complex, and in the course of updating
the docstrings to numpy-style for #363, simplifying the method also
simplified the documenation.
Also deprecated
as_Universe
function. This has yet to be discussed onthe
issue-363
branch, but discussion should happen on what its purposeis.
Also addressed in this commit:
In Move from Atom based topology to array based #363,
__getattr__
behavior for the Groupshave changed to a slightly different scheme. No warnings have been added
for this change to the
__getattr__
methods yet. The new scheme goesas::
SegmentGroups getattr can select by segment name
Segment getattr can select by residue name
ResidueGroup getattr can select by residue name
Residue getattr can select by atom name
AtomGroup getattr can select by atom name
Should only require the following in
AtomGroup.__getattr__
, orpehaps override in
ResidueGroup
and add after asuper
:Residue
,ResidueGroup
,Segment
, andSegmentGroup
are no longerAtomGroup
s themselves, there are methodssuch as
Segment.names
that now longer exist (one would useSegment.atoms.names
instead). Something like:will be needed. And since calling
SegmentGroup.names
no longer gives a singlenumpy
array of all atom names in each segment shoved together, but instead a list of arrays, one for each segment, this will need to be noted. A decorator will be best.