[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [IMP-dev] Iterating over all restraints



Keren Lasker wrote:
I would like to iterate over all restraints.
To my understating the way to do that today is using model.get_restraints(), although the restraints I get might also be of type RestraintSet. It seems that today one basically needs to know which restraint sets the model contains. I suggest to add a function Flat() in class Restraint that returns a flat list of all restraint in that instance ( will be called recursively with RestraintSet).
I think we need to keep the number of virtual methods in Restraint to a 
minimum. As Daniel points out, you can certainly try to dynamic cast 
each restraint to a RestraintSet if you want to enumerate them in C++. I 
don't know of any way to do this at the Python level, so I asked on the 
SWIG mailing list for suggestions. I'll report back what I hear from 
those guys. (It would be straightforward to write a SWIG helper function 
that did the dynamic cast though, if there's no way of doing it 
automatically.)
Your other option is to do what Frido is currently doing - keep a 
reference in Python to the RestraintSets you're interested in looking at 
later. Since everything is dynamic typed at the Python level, it's very 
easy to build all sorts of useful hierarchies there at runtime.
	Ben
--
ben@salilab.org                      http://salilab.org/~ben/
"It is a capital mistake to theorize before one has data."
	- Sir Arthur Conan Doyle