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

[IMP-users] ConnectivityRestraint evaluation fails



Dear all,

after some time, I updated IMP. Now the way I set up ConnectivityRestraints fails. I combine several particles to a pseudo-particle and the connectivity restraint gets a list of this pseudo-particles. The problem occurs in the moment, I try to evaluate the restraint. 
Attached is an example script, based on the connectivity example. That works still fine in an older IMP version, but now it gives me an error message "_IMP_base.InternalException: Not in input list. Violating object: "Model 0". Attribute x of particle "P3" with id 3" even though P3 has a x-value. 
What is wrong in my approach? Or what did change in the implementation?
Is it related to the issue, that in my case particle.show() now only displays the name, but no attributes anymore?
Furthermore, there is a "WARNING  You should pass the model to the Restraint constructor. Constructing ConnectivityRestraint %1%", directly when I call IMP.core.ConnectivityRetraint. Is there a possibility to add the Model already at this point, which is not described in the documentation? I use set_model in the next line...

Thanks in advance!

Pia


import IMP
import IMP.core
import IMP.misc
import IMP.algebra
import IMP.atom

"""
first part modified from IMP example 'connectivity restraint'
"""
id="dummy"

m=IMP.Model()
hs=[]

# create the molecules, with 5 particles for each of 10 molecules
for i in range(1,10):
    p=IMP.Particle(m)
    d= IMP.atom.Hierarchy.setup_particle(p)
    print d.get_name()
    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)

pnodes=[]
htrs=[]
pps=m.get_particles()

#print pps
for ind in [0, 4]:
    pnode = IMP.Particle(m)
    tr = IMP.core.HierarchyTraits(id)
    htrs.append(tr)
    hnode= IMP.core.Hierarchy.setup_particle(pnode, tr)
    for ps in pps[3+ind:6+ind]:
        print "add ",ps, " to pseudo particle"
        #print ps.get_value(IMP.FloatKey(x))
        print ps.get_float_keys()
        if ps.has_attribute(IMP.FloatKey("x")):
            ds=IMP.core.XYZ.decorate_particle(ps)
            ps.show()
            print ds.get_x()
        else:
            print ps.get_name(), ps.get_type_name()
        if ( IMP.core.Hierarchy.particle_is_instance( ps, tr) ):
            # print "particle is instance of Hierarchy"
            hps = IMP.core.Hierarchy.decorate_particle(ps, tr)
        else:
            # print "particle is not instance of Hierarchy"
            hps = IMP.core.Hierarchy.setup_particle(ps, tr)
        hnode.add_child(hps)
    pnode.add_attribute(IMP.StringKey('HierarchyTrait'), id)
    print "pseudo node: pnode = ", pnode, " with type ", type(pnode)
    print "hierarchy of pseudo node = hnode: children = ", hnode.get_children(), " with type ", type(hnode)
    pnodes.append(pnode)
    

ps= IMP.core.SphereDistancePairScore(IMP.core.HarmonicUpperBound(0,1))
cps= IMP.core.ChildrenRefiner(tr)

# score based on the one closest particle from each set of balls
lrps = IMP.misc.LowestRefinedPairScore(cps, ps)
print "DEBUG: before creating connectivity restraint"
cr = IMP.core.ConnectivityRestraint(lrps)
print "DEBUG: after creating connectivity restraint"
cr.set_model(m)         
cr.set_particles(pnodes)
rs_set=IMP.RestraintSet('connectivity')
m.add_restraint(rs_set)
rs_set.add_restraint(cr)
print "show restraint: ", cr.show()
print "number of connected pairs ",len(cr.get_connected_pairs())
print "inputs ", cr.get_inputs()
print "inputs ", cr.get_model()
print "cr name: ", cr.get_name()
print "cr weight: ", cr.get_weight()
# print "number of input cotainers ", len(cr.get_input_containers())
# print "input particles ", cr.get_input_particles()
print "score: ",cr.get_score()
print "DEBUG: before evaluating model--------------"
print m.evaluate(False)
print "DEBUG: after evaluating model--------------"


print "DEBUG: before checking individual restraints "
for i in range(0,rs_set.get_number_of_restraints()):
    res=rs_set.get_restraint(i)
    # res.show()
    # re=res.evaluate(False)
    # print "----------restraint score: ", re
    r=IMP.core.ConnectivityRestraint.get_from(res)
    if r.get_is_part_of_model():
        print "is part of model"
        pairs=r.get_connected_pairs()
    print "number of pairs: ",len(pairs)
    print "connected pairs: ",pairs
print "DEBUG: after checking individual restraints"
print pairs[0]
print type(pairs[0])
pr=pairs[0][1]
print pr
print type(pr)
pr.show()
# d=IMP.core.XYZ.decorate_particle(pr)
# print d.get_x()
# print d.get_y()
# print d.get_z()

print cr.evaluate(True)
print m.evaluate(True)

Pia Unverdorben (Dipl. Math.)
Max-Planck Institut für Biochemie
Am Klopferspitz 18
D-82152 Martinsried

">