get_connected_pairs
Dear all,
I try to access the connected pairs of a connectivity restraint via get_connected_pairs(). Directly after defining the restraint, everything works fine. Now my problem is, that after adding it to a RestraintSet and retrieving it, the same function always gives an attribute error. Show() tells me in both cases that it is a connectivity restraint, so get_connected_pairs should work the same way? My test case is below (modified from the connectivity restraint example). What is wrong? Is there any possibility to get this connected pairs out of the restraint set? Any help is greatly appreciated!
Thanks, Pia
import IMP import IMP.core import IMP.misc import IMP.algebra import IMP.atom
m=IMP.Model() hs=[] # create the molecules, with 5 particles for each of 10 molecules for i in range(0,10): p=IMP.Particle(m) d= IMP.atom.Hierarchy.setup_particle(p) for j in range(0,5): p=IMP.Particle(m) cd= IMP.atom.Fragment.setup_particle(p) d.add_child(cd) xd= IMP.core.XYZR.setup_particle(p, IMP.algebra.Sphere3D(IMP.algebra.Vector3D(3*i,j,0), 1)) hs.append(p)
ps= IMP.core.SphereDistancePairScore(IMP.core.HarmonicUpperBound(0,1)) cps= IMP.core.ChildrenRefiner(IMP.atom.Hierarchy.get_traits())
# score based on the one closest particle from each set of balls lrps = IMP.misc.LowestRefinedPairScore(cps, ps) #lrps = IMP.core.KClosePairsPairScore(ps, cps, 1) # connect all 10 molecules together cr = IMP.core.ConnectivityRestraint(lrps) cr.set_particles(hs) rs_set=IMP.RestraintSet('connectivity') m.add_restraint(rs_set) rs_set.add_restraint(cr) cr.show() print len(cr.get_connected_pairs()) print m.evaluate(False)
for i in range(0,rs_set.get_number_of_restraints()): res=rs_set.get_restraint(i) res.show() if res.get_is_part_of_model(): print "is part of model" pairs=res.get_connected_pairs() print len(pairs)
When you get a Restraint back from a RestraintSet, python doesn't know that the thing returned is a ConnectivityRestraint and so the only methods available are those for a generic Restraint. You can cast the resulting object to, eg, a ConnectivityRestraint by doing IMP.core.ConnectivityRestraint.get_as(the_restraint). This will throw an exception if the cast does not succeeed.
On Sep 15, 2011, at 8:32 AM, Pia Unverdorben wrote:
> Dear all, > > I try to access the connected pairs of a connectivity restraint via get_connected_pairs(). Directly after defining the restraint, everything works fine. Now my problem is, that after adding it to a RestraintSet and retrieving it, the same function always gives an attribute error. Show() tells me in both cases that it is a connectivity restraint, so get_connected_pairs should work the same way? > My test case is below (modified from the connectivity restraint example). What is wrong? Is there any possibility to get this connected pairs out of the restraint set? > Any help is greatly appreciated! > > Thanks, > Pia > > > import IMP > import IMP.core > import IMP.misc > import IMP.algebra > import IMP.atom > > m=IMP.Model() > hs=[] > # create the molecules, with 5 particles for each of 10 molecules > for i in range(0,10): > p=IMP.Particle(m) > d= IMP.atom.Hierarchy.setup_particle(p) > for j in range(0,5): > p=IMP.Particle(m) > cd= IMP.atom.Fragment.setup_particle(p) > d.add_child(cd) > xd= IMP.core.XYZR.setup_particle(p, IMP.algebra.Sphere3D(IMP.algebra.Vector3D(3*i,j,0), 1)) > hs.append(p) > > ps= IMP.core.SphereDistancePairScore(IMP.core.HarmonicUpperBound(0,1)) > cps= IMP.core.ChildrenRefiner(IMP.atom.Hierarchy.get_traits()) > > # score based on the one closest particle from each set of balls > lrps = IMP.misc.LowestRefinedPairScore(cps, ps) > #lrps = IMP.core.KClosePairsPairScore(ps, cps, 1) > # connect all 10 molecules together > cr = IMP.core.ConnectivityRestraint(lrps) > cr.set_particles(hs) > rs_set=IMP.RestraintSet('connectivity') > m.add_restraint(rs_set) > rs_set.add_restraint(cr) > cr.show() > print len(cr.get_connected_pairs()) > print m.evaluate(False) > > > for i in range(0,rs_set.get_number_of_restraints()): > res=rs_set.get_restraint(i) > res.show() > if res.get_is_part_of_model(): > print "is part of model" > pairs=res.get_connected_pairs() > print len(pairs) > _______________________________________________ > IMP-users mailing list > IMP-users@salilab.org > https://salilab.org/mailman/listinfo/imp-users
participants (2)
-
Daniel Russel
-
Pia Unverdorben