import IMP import IMP.core import IMP.container # This example restraints the diameter of a set of particles to be smaller than 10 diameter=10 m= IMP.Model() lc= IMP.container.ListSingletonContainer(IMP.core.create_xyzr_particles(m, 50, 1.0)) h=IMP.core.HarmonicUpperBound(0,1) r=IMP.core.DiameterRestraint(h, lc, diameter) m.add_restraint(r) # Set up optimizer o= IMP.core.ConjugateGradients() o.set_model(m) max=0 for p0 in lc.get_particles(): for p1 in lc.get_particles(): d=IMP.core.get_distance(IMP.core.XYZ(p0), IMP.core.XYZ(p1)) if d > max: max=d print "The maximim distance is "+str(max) IMP.set_log_level(IMP.SILENT) o.optimize(100) max=0 for p0 in lc.get_particles(): for p1 in lc.get_particles(): d=IMP.core.get_distance(IMP.core.XYZ(p0), IMP.core.XYZ(p1)) if d > max: max=d print "Afterwards, the maximim distance is "+str(max)
import IMP import IMP.core import IMP.atom import IMP.helper m= IMP.Model() mp0= IMP.atom.read_pdb(IMP.core.get_example_path('example_protein.pdb'), m) residues= IMP.atom.get_by_type(mp0, IMP.atom.RESIDUE_TYPE) rbs=IMP.container.ListSingletonContainer(residues) for r in residues: IMP.core.RigidBody.setup_particle(r.get_particle(), IMP.core.XYZs(IMP.atom.get_leaves(r))) mp1= IMP.atom.read_pdb(IMP.core.get_example_path('example_protein.pdb'), m) chains= IMP.atom.get_by_type(mp1, IMP.atom.CHAIN_TYPE) rd= IMP.atom.Hierarchy(chains[0]) rbs=IMP.atom.setup_as_rigid_body(chains[0]) print "all done"
import IMP.example (m,c)=IMP.example.create_model_and_particles() # this container lists all pairs that are close at the time of evaluation nbl= IMP.container.ClosePairContainer(c, 0,2) h= IMP.core.HarmonicLowerBound(0,1) sd= IMP.core.SphereDistancePairScore(h) # use the lower bound on the inter-sphere distance to push the spheres apart nbr= IMP.container.PairsRestraint(sd, nbl) m.add_restraint(nbr) # alternatively, one could just do r = IMP.core.ExcludedVolumeRestraint(c) m.add_restraint(r) # get the current score print m.evaluate(False)
import IMP.example (m,c)=IMP.example.create_model_and_particles() uf= IMP.core.Harmonic(0,1) df= IMP.core.DistancePairScore(uf) r= IMP.core.PairRestraint(df, IMP.ParticlePair(c.get_particle(0), c.get_particle(1))) m.add_restraint(r)
import IMP import IMP.core import IMP.misc import IMP.algebra import IMP.atom m= IMP.Model() # Put the parent particles for each molecule hs=IMP.Particles() # create the 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()) lrps = IMP.misc.LowestRefinedPairScore(cps,ps) cr = IMP.core.ConnectivityRestraint(lrps) cr.set_particles(hs) m.add_restraint(cr) m.evaluate(False)
import IMP import IMP.core import IMP.atom import IMP.helper import IMP.container # This example addes a restraint on nonbonded interactions # Since it is between two rigid bodies, internal interactions are ignored m= IMP.Model() # The particles in the rigid bodies rbps0= IMP.core.create_xyzr_particles(m, 3, 1) rbps1= IMP.core.create_xyzr_particles(m, 3, 1) rbp0= IMP.Particle(m) rbp1= IMP.Particle(m) rbss0 = IMP.core.RigidBody.setup_particle(rbp0, IMP.core.XYZs(rbps0)) rbss1 = IMP.core.RigidBody.setup_particle(rbp1, IMP.core.XYZs(rbps1)) lsc= IMP.container.ListSingletonContainer() lsc.add_particle(rbp0) lsc.add_particle(rbp1) tr= IMP.core.TableRefiner() tr.add_particle(rbp0, rbps0) tr.add_particle(rbp1, rbps1) # Set up the nonbonded list nbl= IMP.container.ClosePairContainer(lsc, 0, IMP.core.RigidClosePairsFinder(tr), 2.0) # Set up excluded volume ps= IMP.core.SphereDistancePairScore(IMP.core.HarmonicLowerBound(0,1)) evr= IMP.container.PairsRestraint(ps, nbl) evri= m.add_restraint(evr) # Set up optimizer o= IMP.core.ConjugateGradients() o.set_model(m) done=False while not done: try: o.optimize(1000) except IMP.ModelException: for d in [rbss0, rbss1]: d.set_transformation(IMP.algebra.Transformation3D(IMP.algebra.get_random_rotation_3d(), IMP.algebra.get_random_vector_in(IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(0,0,0), IMP.algebra.Vector3D(10,10,10))))) else: done=True
import IMP import IMP.core import IMP.algebra m= IMP.Model() p0= IMP.Particle(m) d0= IMP.core.XYZR.setup_particle(p0, IMP.algebra.Sphere3D(IMP.algebra.Vector3D(0,1,2), 1.0)) p1= IMP.Particle(m) d1= IMP.core.XYZR.setup_particle(p1) d1.set_coordinates(IMP.algebra.Vector3D(3,4,5)) d1.set_radius(2.0) print IMP.core.get_distance(d0, d1) # use them as XYZ particles xd0= IMP.core.XYZ.decorate_particle(p0) xd1= IMP.core.XYZ.decorate_particle(p1) # distance without radii print IMP.core.get_distance(xd0, xd1)
import IMP import IMP.core import IMP.atom import IMP.atom import IMP.helper m= IMP.Model() prot= IMP.atom.read_pdb(IMP.core.get_example_path('example_protein.pdb'), m) res= IMP.atom.get_by_type(prot, IMP.atom.RESIDUE_TYPE) for p in res: IMP.core.XYZR.setup_particle(p.get_particle()) mtr=IMP.atom.Hierarchy.get_traits() pr= IMP.core.ChildrenRefiner(mtr) for r in res: IMP.core.Cover.setup_particle(r.get_particle(), pr) m.evaluate(False)
import IMP import IMP.core import IMP.algebra m= IMP.Model() p0= IMP.Particle(m) d0= IMP.core.XYZ.setup_particle(p0, IMP.algebra.Vector3D(0,1,2)) p1= IMP.Particle(m) d1= IMP.core.XYZ.setup_particle(p1) d1.set_coordinates(IMP.algebra.Vector3D(3,4,5)) print IMP.core.get_distance(d0, d1)
# Assume p is a RigidBody Particle rbd= IMP.core.RigidBody(p) translation=IMP.algebra.get_random_vector_in(IMP.algebra.Vector3D(0,0,0), 10.0) # we don't yet have python code to generate a nearby rotation rotation= IMP.algebra.random_rotation() transformation= IMP.algebra.Transformation3D(rotation, translation) # note, this overwrites the existing position # The True is to transform the members now rather than wait for a # score state rbd.set_transformation(transformation, True) # to instead perturb the existing transformation instead do rbd.set_transformation(IMP.algebra.compose(rbd.get_transformation(), transformation))
tr= IMP.core.HierarchyTraits("my hierarchy") pd= IMP.core.Hierarchy.setup_particle(parent_particle, tr) for p in children_particles: cd= IMP.core.Hierarchy.setup_particle(p, tr) pd.add_child(cd) pd.show()