Hi,
I'd like to propose some fairly severe changes to AtomGroup and are asking for a discussion amongst developers and then later (if the proposal survives the developer list) on the user list.
PROPOSAL
1) AtomGroup methods/properties should return NumPy arrays when these can be of simple numeric or string types.
E.g. ag.resids() would return an array([1,2,3], dtype="int") and ag.resnames() would return something like array(['MET ,'ARG', 'THR'], dtype="|S3").
This would make it easier to use numpy-style slicing and generally fits the theme of integrating MD trajectories tightly with numpy.
Groups of specific objects such as a bunch of residues are returned as a ResidueGroup or segments as a SegmentGroup (I added a patch to that effect the other day.)
It is unlikely to break code because arrays pretty much behave like lists.
2) Turn methods that mainly report on topology properties into managed attributes.
For example:
ag.resids() ---> ag.resids
In code:
@property
def resids(self):
....
I suggest the following methods to be converted to managed attributes:
bfactors (already attribute but scheduled to be a method in 0.8)
charges
indices
masses
names
radii
resids
resnames
resnums
segids
velocities
coordinates # could leave as a method because we already have ag.positions — or make a clean break and also change
Turning the above methods into (managed) attributes would have the following
Advantages:
1) Make the interface more consistent and probably easier to learn for new comers.
2) Easier to write concise code, especially once these attributes return numpy arrays: instead of ugly ag.resids()[2:10:2] you write straightforward ag.resids[2:10:2].
We could later add the ability to set these managed attributes via property.setter and then we could phase out set_xxxx() methods, thus decreasing the amount of methods/attributes exposed by AtomGroup and so tighten the API.
Disadvantage:
1) Will break existing scripts. Pretty much all of them, at least looking at mine, which use ag.resids() and friends liberally.
(Could be mitigated by a simple script that changes occurences of method calls to attribute access.)
I think we can implement (1) without problems.
- What do you think of these changes?
- Would you modify these changes? Add other methods, remove some?
- What would "your users" think of these changes?
Thanks for your time!
Oliver