import IMP.example import IMP.statistics (m,c)=IMP.example.create_model_and_particles() ps= IMP.core.DistancePairScore(IMP.core.HarmonicLowerBound(1,1)) r= IMP.container.PairsRestraint(ps, IMP.container.ClosePairContainer(c, 2.0)) m.add_restraint(r) # we don't want to see lots of log messages about restraint evaluation m.set_log_level(IMP.WARNING) # the container (c) stores a list of particles, which are alse XYZR particles # we can construct a list of all the decorated particles xyzrs= IMP.core.XYZRsTemp(c.get_particles()) s= IMP.core.MCCGSampler(m) s.set_number_of_attempts(10) # but we do want something to watch s.set_log_level(IMP.TERSE) # find some configurations which move the particles far apart configs= s.get_sample(); for i in range(0, configs.get_number_of_configurations()): configs.set_configuration(i) # print out the sphere containing the point set # - Why? - Why not? sphere= IMP.core.get_enclosing_sphere(xyzrs) print sphere # cluster the solutions based on their coordinates e= IMP.statistics.ConfigurationSetXYZEmbedding(configs, c) # of course, this doesn't return anything of interest since the points are # randomly distributed, but, again, why not? clustering = IMP.statistics.get_lloyds_kmeans(e, 3, 1000) for i in range(0,clustering.get_number_of_clusters()): # load the configuration for a central point configs.set_configuration(clustering.get_cluster_representative(i)) sphere= IMP.core.get_enclosing_sphere(xyzrs) print sphere
import IMP import IMP.core m= IMP.Model() pts= IMP.core.create_xyzr_particles(m, 10, 10, 10) IMP.add_failure_handler(IMP.DumpModelOnFailure(m, "error.imp"))
import IMP import IMP.core import random import IMP.display # A trivial example that constructs a set of particles which are restrained # to form a chain via bonds between successive particles. In addition # the head and the tail of the chain are restrained to be close to one # another. IMP.set_log_level(IMP.TERSE) m= IMP.Model() # The particles in the chain chain= IMP.container.ListSingletonContainer(IMP.core.create_xyzr_particles(m, 2, 1.0)) # create a bond between successive particles IMP.atom.Bonded.setup_particle(chain.get_particle(0)) bonds= IMP.container.ListSingletonContainer("particles") for i in range(1, chain.get_number_of_particles()): bp= IMP.atom.Bonded(chain.get_particle(i-1)) bpr= IMP.atom.Bonded.setup_particle(chain.get_particle(i)) b= IMP.atom.create_custom_bond(bp, bpr, 1.5, 10) bonds.add_particle(b.get_particle()) # If you want to inspect the particles # Notice that each bond is a particle for p in m.get_particles(): p.show() # Prevent non-bonded particles from penetrating one another nbl= IMP.container.ClosePairContainer(chain, 0,2) bpc=IMP.atom.BondedPairFilter() # exclude existing bonds nbl.add_pair_filter(bpc) ps= IMP.core.SphereDistancePairScore(IMP.core.HarmonicLowerBound(0,1)) m.add_restraint(IMP.container.PairsRestraint(ps, nbl)) # penalize conformations where bond lengths aren't preserved bss= IMP.atom.BondSingletonScore(IMP.core.Harmonic(0,1)) m.add_restraint(IMP.container.SingletonsRestraint(bss, bonds)) # Tie the ends of the chain p= IMP.ParticlePair(chain.get_particle(0), chain.get_particle(chain.get_number_of_particles()-1)) pps= IMP.container.ListPairContainer() pps.add_particle_pair(p) m.add_restraint(IMP.container.PairsRestraint( IMP.core.SphereDistancePairScore(IMP.core.Harmonic(3,1)), pps)) s= IMP.core.MCCGSampler(m) # sample using MC and CG s.set_number_of_attempts(10) confs= s.get_sample() for i in range(0, confs.get_number_of_configurations()): confs.set_configuration(i) d=IMP.display.ChimeraWriter("solution"+str(i)+".py") for p in chain.get_particles(): d.add_geometry(IMP.display.XYZRGeometry(p))
import IMP.core def create_model_and_particles(): m= IMP.Model() sc= IMP.container.ListSingletonContainer() b= IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(0,0,0), IMP.algebra.Vector3D(10,10,10)) for i in range(0,100): p= IMP.Particle(m) sc.add_particle(m) d=IMP.core.XYZR.setup_particle(p, IMP.algebra.Sphere3D(IMP.algebra.get_random_vector_in(b), 1)) d.set_coordinates_are_optimized(True) return (m, sc)