IMP logo

container examples

bipartite nonbonded interactions

This example shows how set up excluded volume interactions between two sets of particles.

import IMP
import IMP.core
import IMP.container

# This example addes a restraint on bipartite nonbonded interactions
# after excluding a set of bonded interactions.

m= IMP.Model()
# The set of particles
ps0 = IMP.container.ListSingletonContainer(IMP.core.create_xyzr_particles(m, 20, 1.0))
ps1 = IMP.container.ListSingletonContainer(IMP.core.create_xyzr_particles(m, 20, 2.0))

# Set up the nonbonded list
nbl= IMP.container.CloseBipartitePairContainer(ps0, ps1,0,1)

# Set up excluded volume
ps= IMP.core.SphereDistancePairScore(IMP.core.HarmonicLowerBound(0,1))
evr= IMP.container.PairsRestraint(ps, nbl)
m.add_restraint(evr)

# Set up optimizer
o= IMP.core.ConjugateGradients()
o.set_model(m)

o.optimize(1000)

connectivity

Shows how to use and visualize the IMP::misc::ConnectingPairContainer.

import IMP.container
import IMP.display

m= IMP.Model()
ds=IMP.core.create_xyzr_particles(m, 20, .1)
sc= IMP.container.ListSingletonContainer(ds)
cpc= IMP.container.ConnectingPairContainer(sc, .1, True)
m.evaluate(False)
pg= IMP.display.EdgePairsGeometry(cpc)
w= IMP.display.ChimeraWriter("pairs.py")
w.add_geometry(pg)
print pg.get_name()
del w

filter close pairs

This example shows how to filter the list of close pairs generated in the IMP.container.ClosePairContainer (or IMP.container.CloseBipartitePairContainer). Eventually the filter should probably be implemented in C++, for speed but implementing the filter in python is good for prototyping.

import IMP
import IMP.container
import IMP.core
import IMP.algebra

np=10
bb= IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(0,0,0),
                              IMP.algebra.Vector3D(5,5,5))
ik= IMP.IntKey("num")
IMP.set_log_level(IMP.SILENT)
m= IMP.Model()
l= []
for i in range(0, np):
    p= IMP.Particle(m)
    p.add_attribute(ik, i)
    IMP.core.XYZR.setup_particle(p, IMP.algebra.Sphere3D(IMP.algebra.get_random_vector_in(bb), 1))
    l.append(p)
lsc= IMP.container.ListSingletonContainer(l)
cpc= IMP.container.ClosePairContainer(lsc, 0.0)

m.update()
print "without",[(x[0].get_name(), x[1].get_name()) for x in cpc.get_particle_pairs()]

class ConsecutiveFilter(IMP.PairFilter):
    def __init__(self):
        IMP.PairFilter.__init__(self)
    def get_contains_particle_pair(self, pp):
        diff= pp[0].get_value(ik)-pp[1].get_value(ik)
        if diff==-1 or diff ==1:
            return True
        return False
    def get_input_particles(self, p):
        return [p]
    def get_input_containers(self, p):
        return []
    def do_show(self, out):
        pass
f= ConsecutiveFilter()
cpc.add_pair_filter(f)
m.update()
print "with",[(x[0].get_name(), x[1].get_name()) for x in cpc.get_particle_pairs()]

nonbonded interactions

This example shows how to set up an excluded volume restraint for a set of XYZRDecorator-style particles.

import IMP
import IMP.core
import IMP.atom
import IMP.container

# This example addes a restraint on nonbonded interactions
# after excluding a set of bonded interactions.

m= IMP.Model()
# The set of particles
ps = IMP.container.ListSingletonContainer(IMP.core.create_xyzr_particles(m, 20, 1.0))

# create a bond between two particles
bd0= IMP.atom.Bonded.setup_particle(ps.get_particle(0))
bd1= IMP.atom.Bonded.setup_particle(ps.get_particle(1))
IMP.atom.create_custom_bond(bd0, bd1, 2.0)

# Set up the nonbonded list for all pairs at are touching
# and let things move 3 before updating the list
nbl= IMP.container.ClosePairContainer(ps, 0.0, 3.0)
nbl.add_pair_filter(IMP.atom.BondedPairFilter())

# Set up excluded volume
sdps= IMP.core.SphereDistancePairScore(IMP.core.HarmonicLowerBound(0,1))
evr= IMP.container.PairsRestraint(sdps, nbl)
m.add_restraint(evr)

# Set up optimizer
o= IMP.core.ConjugateGradients()
o.set_model(m)

o.optimize(1000)

restrain in sphere

This fragment shows how to restrain a set of points stored in a SingletonContainer in a sphere of radius 'radius' centered around 'center'.

import IMP.example
radius=10
stiffness=2
center= IMP.algebra.Vector3D(1,2,3)
(m,c)=IMP.example.create_model_and_particles()
ub= IMP.core.HarmonicUpperBound(radius, stiffness)
ss= IMP.core.DistanceToSingletonScore(ub, center)

r= IMP.container.SingletonsRestraint(ss, c)
m.add_restraint(r)
m.evaluate(False)


Generated on Thu Mar 24 2011 02:01:40 for IMP by doxygen 1.7.3