So in C++ you can just do something like
template <class C> void visit_restraints(C *m) for (typename C::RestraintIterator rit= m->restraints_begin(); rit != m->restraints_end(); ++rit) { RestraintSet *rs= dynamic_cast<RestraintSet>(*rit); if (rs) { visit_restraints(rs); } else { do something to the restraint } } }
In python I would imagine you can do something similar, but I don't really know how. Ben?
I don't like the idea of a Flat method (first, because the name is all wrong). More importantly, in most cases, whether a restraint contains others (like Bret's do) is really just an implementation detail and is something that should not be exposed.
What are you trying to accomplish? If it is getting a dependency graph, you will have all sorts of problems with nonbonded lists and other sorts of indirect relationships.
How about requiring that Restraint::get_particles() always returns all the particles that affect the Restraint? It would be horribly expensive in the worst case, but....
We may need to introduce some lower level mechanism. For example, a method on Object which returns a list of all pointers contained to other objects. I may be able to implement that in a clean way with only the overhead of one extra int per pointer.
On Feb 23, 2008, at 5:19 PM, Keren Lasker wrote:
> hi, > > 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). > > thoughts? > > Keren. > _______________________________________________ > IMP-dev mailing list > IMP-dev@salilab.org > https://salilab.org/mailman/listinfo/imp-dev