On 4/27/11 6:31 PM, Javier Velazquez wrote: > Recovering restraints (after optimization) from a model in python has > an unexpected behaviour. This code fails: > > for i in range(model.get_number_of_restraints()): > r = model.get_restraint(i) > print "checking restraint ...",r.get_name() > pairs = r.get_connected_pairs()
Actually, that is expected behavior, in both Python and C++. Model contains a list of Restraints, not ConnectivityRestraints or any other type.
> Is there another way to access the restraints when the optimization has > finished?
Any class that derives from IMP::Object has a 'get_from' class method. This will cast a given object to that type, if possible - otherwise it'll raise a ValueException. (The C++ equivalent is dynamic_cast.)
e.g.
for i in range(model.get_number_of_restraints()): r = model.get_restraint(i) print "checking restraint ...",r.get_name() cr = IMP.core.ConnectivityRestraint.get_from(r) pairs = cr.get_connected_pairs()
Ben