def test_global_min2(self):
     """Test that more involved graphs are fine"""
     m= IMP.Model()
     aps=[]
     rbs=[]
     for i in range(3):
         ps= IMP._create_particles_from_pdb(self.get_input_file_name("small_protein.pdb"), m)
         p= IMP.Particle(m)
         p.set_name("protein"+str(i))
         aps.extend(ps)
         rb=IMP.core.RigidBody.setup_particle(p, ps)
         rbs.append(rb)
     cp= IMP.container.ClosePairContainer(IMP.container.ListSingletonContainer(aps), 1, 0)
     r=IMP.container.PairsRestraint(IMP.core.DistancePairScore(IMP.core.HarmonicLowerBound(0,1)), cp)
     m.add_restraint(r)
     print "computing graph"
     pst= IMP.domino.ParticleStatesTable()
     for p in rbs:
         pst.set_particle_states(p, NullStates())
     g= IMP.domino.get_interaction_graph([m.get_root_restraint_set()],
                                          pst)
     w= IMP.display.PymolWriter(self.get_tmp_file_name("ig0.pym"))
     for gg in IMP.domino.get_interaction_graph_geometry(g):
         w.add_geometry(gg)
     del w
     print "done"
     vs= g.get_vertices()
     IMP.show_graphviz(g)
     for v in vs:
         print v
         l= g.get_vertex_name(v)
         print l.get_name()
         self.assertIn(l, rbs)
         self.assertEqual(len(g.get_out_neighbors(v)), 2)
     g.show()
Beispiel #2
0
 def setUp(self):
     """initialize IMP environment create particles"""
     IMP.test.TestCase.setUp(self)
     IMP.set_log_level(IMP.SILENT)
     IMP.set_check_level(IMP.NONE)
     # init IMP model ( the environment)
     self.imp_model = IMP.Model()
     self.particles = []
     # -  create a set of three particles in imp
     npart = 3
     self.rad_key = IMP.FloatKey("radius")
     self.weight_key = IMP.FloatKey("weight")
     for i, (x, y, z) in enumerate(((9.0, 9.0, 9.0),
                                    (12.0, 3.0, 3.0),
                                    (3.0, 12.0, 12.0))):
         p = self.create_point_particle(self.imp_model, x, y, z)
         p.add_attribute(self.rad_key, 1.0, False)
         p.add_attribute(self.weight_key, 10.0)
         p.add_attribute(IMP.IntKey("id"), i)
         p.add_attribute(IMP.IntKey("protein"), 1)
         self.particles.append(p)
     self.particle_indexes = []
     for i in range(npart):
         self.particle_indexes.append(i)
     print("initialization done ...")
Beispiel #3
0
 def test_delete_model_accessor(self):
     "Python Particles from vector accessors should survive model deletion"
     IMP.set_log_level(IMP.MEMORY)
     refcnt = IMP.test.RefCountChecker(self)
     m = IMP.Model("test model")
     IMP.Particle(m)
     # Now create new Python particle p from a C++ vector accessor
     # (front(), back(), [], etc.)
     # (not the Python IMP.Particle() constructor)
     # These accessors call specific methods in the SWIG wrapper which
     # are modified by typemaps in our interface.
     print("getting particles")
     ps = m.get_particle_indexes()
     print("getting particle")
     p = m.get_particle(ps[0])
     del ps
     # Python reference p plus C++ reference from m
     self.assertEqual(p.get_ref_count(), 2)
     print("deleting model")
     del m
     # Now only the Python reference p should survive
     self.assertEqual(p.get_ref_count(), 1)
     refcnt.assert_number(1)
     print(p)
     print("deleting p")
     print(p.thisown)
     del p
     refcnt.assert_number(0)
 def test_global_min3(self):
     """Test that showing interaction graphs is fine"""
     m= IMP.Model()
     IMP.set_log_level(IMP.SILENT)
     ps= IMP._create_particles_from_pdb(self.get_input_file_name("small_protein.pdb"), m)
     #print "radius is ", IMP.core.XYZR(IMP.atom.get_leaves(p)[0]).get_radius()
     #exit(1)
     #sp= IMP.atom.get_simplified_by_residue(p, 1)
     cpf= IMP.core.QuadraticClosePairsFinder()
     cpf.set_distance(0.0)
     print len(ps), "leaves"
     cp= cpf.get_close_pairs(ps)
     for pr in cp:
         r=IMP.core.PairRestraint(IMP.core.DistancePairScore(IMP.core.HarmonicLowerBound(0,1)), pr)
         m.add_restraint(r)
         r.set_name("pair")
     print "computing graph"
     pst= IMP.domino.ParticleStatesTable()
     for p in ps:
         pst.set_particle_states(p, NullStates())
     g= IMP.domino.get_interaction_graph([m.get_root_restraint_set()],
                                          pst)
     w= IMP.display.PymolWriter(self.get_tmp_file_name("ig-large.pym"))
     gs=IMP.domino.get_interaction_graph_geometry(g)
     print "There are ", len(gs)
     for gg in gs:
         w.add_geometry(gg)
     del w
Beispiel #5
0
 def test_set(self):
     """Testing ClassnamesConstraint"""
     # write increment an int field
     # call evaluate and check that it is incremented
     IMP.set_log_level(IMP.VERBOSE)
     print("start")
     m = IMP.Model()
     print("hi")
     c = IMP.container.ListClassnameContainer(m)
     cs = []
     for i in range(0, 30):
         t = self.create_FUNCTIONNAME(m)
         if 'FUNCTIONNAME' == 'particle':
             c.add(t.get_index())
         else:
             c.add([x.get_index() for x in t])
         cs.append(t)
     print("dl")
     k = IMP.IntKey("thevalue")
     f = ClassnameTestModifier(k)
     print("apply")
     s = IMP.container.ClassnamesConstraint(f, None, c)
     print("add")
     m.add_score_state(s)
     m.update()
     for p in cs:
         self.assertTrue(FUNCTIONNAME_has_attribute(p, k))
     print("done")
 def _test_explicit(self, nm):
     """Testing default subset states with explicit equivalencies"""
     m = IMP.Model()
     ps = []
     ns = 5
     np = 4
     for i in range(0, np):
         ps.append(IMP.Particle(m))
     pst = IMP.domino.ParticleStatesTable()
     tps = TrivialParticleStates(ns)
     pst.set_particle_states(ps[0], tps)
     pst.set_particle_states(ps[1], tps)
     for p in ps[2:]:
         pst.set_particle_states(p, TrivialParticleStates(ns))
     pft = IMP.domino.ExclusionSubsetFilterTable()
     pft.add_pair((ps[0], ps[1]))
     dsst = nm(pst, [pft])
     lsc = IMP.domino.Subset(ps)
     IMP.set_log_level(IMP.SILENT)
     pss = IMP.domino.PackedAssignmentContainer()
     dsst.load_assignments(lsc, pss)
     ss = pss.get_assignments((0, pss.get_number_of_assignments()))
     self.assertEqual(len(ss), ns ** (len(ps) - 2) * (ns) * (ns - 1))
     all_states = []
     print("testing")
     for state in ss:
         # print state
         # print all_states
         self.assertNotIn(state, all_states)
         all_states.append(state)
 def setUp(self):
     """Build test model and optimizer"""
     IMP.test.TestCase.setUp(self)
     IMP.set_log_level(IMP.SILENT)
     IMP.set_check_level(IMP.NONE)
     self.imp_model = IMP.Model()
     self.load_density_map("1z5s_10.mrc")
     self.load_proteins(["1z5s_A_fitted.pdb", "1z5s_B_fitted.pdb",
                         "1z5s_C_fitted.pdb", "1z5s_D_fitted.pdb", ])
     self.full_sampled_map = IMP.em.SampledDensityMap(
         self.scene.get_header())
     self.all_ps = []
     for mh in self.mhs:
         self.all_ps += IMP.core.get_leaves(mh)
     self.full_sampled_map.set_particles(self.all_ps)
     self.full_sampled_map.resample()
     self.scene.calcRMS()
     self.full_sampled_map.calcRMS()
     self.upper = (
         self.scene.get_number_of_voxels(
         ) * self.scene.get_header(
         ).dmean * self.full_sampled_map.get_header(
         ).dmean) / len(
         self.mhs)
     self.lower = self.scene.get_number_of_voxels(
     ) * self.scene.calcRMS(
     ) * self.full_sampled_map.calcRMS(
     )
     self.norm_factors = [self.upper, self.lower]
    def setUp(self):
        IMP.test.TestCase.setUp(self)

        # setup problem
        ndensity=4
        nmodel=10
        rs=np.random.RandomState()

        self.m = IMP.Model()
        itrans = IMP.algebra.get_identity_transformation_3d()
        self.density_ps=create_random_gaussians(self.m,rs,ndensity,spherical=False)
        self.model_ps=create_random_gaussians(self.m,rs,nmodel,spherical=False)

        psigma=IMP.Particle(self.m)
        si = IMP.isd.Scale.setup_particle(psigma,1.0)
        slope=0.0
        model_cutoff_dist=1e8
        density_cutoff_dist=1e8
        update_model=True
        self.gem=IMP.isd.GaussianEMRestraint(self.m,IMP.get_indexes(self.model_ps),
                                             IMP.get_indexes(self.density_ps),psigma.get_index(),
                                             model_cutoff_dist,density_cutoff_dist,
                                             slope,
                                             update_model,False)
        self.m.add_restraint(self.gem)
        self.orig_coords=[IMP.core.XYZ(p).get_coordinates() for p in self.model_ps]
Beispiel #9
0
 def test_set(self):
     """Testing ClassnameContainerSet"""
     IMP.set_log_level(IMP.VERBOSE)
     m = IMP.Model()
     print("hi")
     c = IMP.container.ClassnameContainerSet(m)
     ls = []
     cs = []
     for i in range(0, 3):
         l = IMP.container.ListClassnameContainer(m)
         c.add_CLASSFUNCTIONNAME_container(l)
         for j in range(0, 3):
             t = self.create_FUNCTIONNAME(m)
             l.add(t)
             cs.append(t)
     ret = c.get_contents()
     for pi in cs:
         self.assertIn(pi, ret)
     ret.sort()
     # print ret
     cs.sort()
     # rint cs
     self.assertEqual(len(ret), len(cs))
     for r, c in zip(ret, cs):
         self.assertEqual(r, c)
Beispiel #10
0
 def test_dependencies(self):
     """Check dependencies with restraints and score states"""
     m= IMP.Model("dependencies")
     ps=[IMP.Particle(m) for i in range(0,20)]
     cs=[DummyScoreState(ips=self._select(ps[:5], 2),
                         ops= self._select(ps[5:], 2))
         for i in range(5)]
     for c in cs:
         m.add_score_state(c)
     rs=[DummyRestraint(ps=self._select(ps, 4))
         for i in range(5)]
     for r in rs:
         m.add_restraint(r)
     dg= IMP.get_dependency_graph(m)
     #IMP.show_graphviz(dg)
     for r in rs:
         print "now restraint",r
         rcsl=IMP.get_required_score_states([r], dg,
                                            IMP.get_vertex_index(dg))
         rdg= IMP.get_dependency_graph(m)
         #IMP.show_graphviz(rdg)
         ccsl=[]
         for n in rdg.get_vertices():
             nn= rdg.get_vertex_name(n)
             print nn.get_name()
             try:
                 IMP.ScoreState.get_from(nn)
             except:
                 print "not", nn.get_name()
                 pass
             else:
                 print "found", nn.get_name()
                 ccsl.append(nn)
 def test_set(self):
     """Testing PairContainerSet"""
     IMP.set_log_level(IMP.VERBOSE)
     m= IMP.Model()
     print "hi"
     c= IMP.container.PairContainerSet(m)
     ls=[]
     cs=[]
     for i in range(0,3):
         l= IMP.container.ListPairContainer(m)
         c.add_pair_container(l)
         for j in range(0,3):
             t=self.create_particle_pair(m)
             l.add_particle_pair(t)
             cs.append(t)
     for p in cs:
         self.assertTrue(c.get_contains_particle_pair(p))
     ret=[]
     for i in range(0, len(cs)):
         ret.append(c.get_particle_pair(i))
     ret.sort(cmp)
     #print ret
     cs.sort(cmp)
     #rint cs
     for i in range(0, len(ret)):
         self.assertEqual(cmp(ret[i], cs[i]), 0)
     self.assertEqual(c.get_number_of_particle_pairs(), len(cs))
Beispiel #12
0
    def run_from_config(self, config, output):
        """
        Run using work-unit 0 using specified config file,
        dumping output to specified output file

        return - the resulting simulation data object
        """
        IMP.set_log_level( IMP.SILENT );
        print "assigning parameter ranges from config"
        num=assign_ranges( config, output,
                          0, True, 10 );
        sd= IMP.npctransport.SimulationData(output, False,
                                            self.get_tmp_file_name("out0.rmf"));
        print "BEFORE INIT", time.ctime()
        IMP.npctransport.initialize_positions(sd, [], False)
        print "AFTER INIT", time.ctime()
        obd= sd.get_bd()
        obd.optimize(2)
        print "AFTER OPTIMIZE", time.ctime()
        timer= IMP.npctransport.timer();
        # # lame test
        # rt= sd.get_root()
        # rtt= IMP.npctransport.Transporting.setup_particle(rt, True)
        # rtf= rt.get_child(0)
        # rttf= IMP.npctransport.Transporting.setup_particle(rtf, False)
        print "updating stats"
        sd.update_statistics(timer, 0);
        return sd
 def test_set(self):
     """Testing PairsConstraint"""
     # write increment an int field
     # call evaluate and check that it is incremented
     IMP.set_log_level(IMP.VERBOSE)
     print "start"
     m= IMP.Model()
     print "hi"
     c= IMP.container.ListPairContainer(m)
     cs=[]
     for i in range(0,30):
         t=self.create_particle_pair(m)
         c.add_particle_pair(t)
         cs.append(t)
     print "dl"
     k= IMP.IntKey("thevalue")
     f= PairTestModifier(k)
     print "apply"
     s= IMP.container.PairsConstraint(f, None, c)
     print "add"
     m.add_score_state(s)
     m.update()
     for p in cs:
         self.assertTrue(particle_pair_has_attribute(p, k))
     print "done"
Beispiel #14
0
 def test_global_min3(self):
     """Test capped caching of restraint scores"""
     m = IMP.Model()
     p = IMP.Particle(m)
     IMP.core.XYZ.setup_particle(p)
     lr = LogRestraint(m, [p])
     lr.set_maximum_score(0)
     pst = IMP.domino.ParticleStatesTable()
     s = IMP.domino.XYZStates([IMP.algebra.Vector3D(0, 0, 0),
                              IMP.algebra.Vector3D(0, 0, 1)])
     pst.set_particle_states(p, s)
     rc = IMP.domino.RestraintCache(pst, 1)
     rc.add_restraints([lr])
     rft = IMP.domino.RestraintScoreSubsetFilterTable(rc)
     f = rft.get_subset_filter(IMP.domino.Subset([p]), [])
     f.set_log_level(IMP.VERBOSE)
     IMP.set_log_level(IMP.VERBOSE)
     # turn off checks to avoid restraint re-evals
     IMP.set_check_level(IMP.NONE)
     lr.reset()
     f.get_is_ok(IMP.domino.Assignment([0]))
     f.get_is_ok(IMP.domino.Assignment([0]))
     f.get_is_ok(IMP.domino.Assignment([1]))
     f.get_is_ok(IMP.domino.Assignment([1]))
     f.get_is_ok(IMP.domino.Assignment([0]))
     self.assertEqual(lr.count, 3)
Beispiel #15
0
    def filterAssignments(self, assignments, subset, nodeIndex, rssft):

        filteredSubsets = []
        restraintList = []

        # make dependency graph for stats
        for r in IMP.get_restraints([self.model.get_root_restraint_set()]):
            restraintList.append(r)
        dg = IMP.get_dependency_graph(restraintList)

        stateCounter = 0
        passedCounter = 0

        # create hdf5AssignmentContainer

        sFilter = rssft.get_subset_filter(subset, filteredSubsets)
        # check each unique state to see if passes filter
        filteredAssignments = []
        for assignment in assignments:

            if (sFilter is None or sFilter.get_is_ok(assignment)):
                # add to assignment container if it passes
                passedCounter += 1
                filteredAssignments.append(assignment)

            stateCounter += 1
        fraction = (passedCounter * 1.0) / (stateCounter * 1.0)
        print("%s states passed out of %s total for this subset (fraction %s)" % (passedCounter, stateCounter, fraction))
        if (passedCounter == 0):
            print("subset %s had 0 assignments (out of %s) pass. Exiting..." % (subset, stateCounter))
            sys.exit()

        return filteredAssignments
Beispiel #16
0
 def test_global_min1(self):
     """Test close pairs list generation"""
     m = IMP.Model()
     ps = [IMP.Particle(m) for i in range(0, 10)]
     psi = IMP.get_indexes(ps)
     ds = [IMP.core.XYZR.setup_particle(p) for p in ps]
     for d in ds:
         d.set_radius(6)
     bb = IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(0, 0, 0),
                                    IMP.algebra.Vector3D(50, 50, 50))
     bbs = IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(0, 0, 0),
                                     IMP.algebra.Vector3D(4, 4, 4))
     pst = IMP.domino.ParticleStatesTable()
     for p in ps:
         v0 = IMP.algebra.get_random_vector_in(bb)
         vs = [v0 + IMP.algebra.get_random_vector_in(bbs)
               for i in range(0, ns)]
         yxz = IMP.domino.XYZStates(vs)
         pst.set_particle_states(p, yxz)
     allp = IMP.domino.get_possible_interactions(ps, 2, pst)
     cpf = IMP.core.GridClosePairsFinder()
     cpf.set_distance(1.8)
     pst.set_was_used(True)
     for rep in range(0, 1000):
         for p in ps:
             st = pst.get_particle_states(p)
             st.load_particle_state(random.sample(range(0, ns), 1)[0], p)
         curp = cpf.get_close_pairs(m, psi)
         print(len(curp))
         for pi in curp:
             p = tuple(IMP.get_particles(m, pi))
             self.assertTrue(p in allp or (p[1], p[0]) in allp)
 def setUp(self):
     IMP.test.TestCase.setUp(self)
     #IMP.set_log_level(IMP.TERSE)
     IMP.set_log_level(0)
     self.m = IMP.Model()
     data=open(self.get_input_file_name('lyzexp_gpir.dat')).readlines()
     data=[map(float,d.split()) for d in data]
     self.q=[[i[0]] for i in data]
     self.I=[i[1] for i in data]
     self.err=[i[2] for i in data]
     self.N=10
     self.G = Scale.setup_particle(IMP.Particle(self.m), 3.0)
     self.G.set_nuisance_is_optimized(False)
     self.Rg = Scale.setup_particle(IMP.Particle(self.m),  10.0)
     self.Rg.set_nuisance_is_optimized(False)
     #put d=15 so we don't use the porod region
     self.d = Scale.setup_particle(IMP.Particle(self.m),  15.0)
     self.d.set_nuisance_is_optimized(False)
     self.s = Scale.setup_particle(IMP.Particle(self.m),  0.0)
     self.s.set_nuisance_is_optimized(False)
     self.A = Scale.setup_particle(IMP.Particle(self.m),  0.0)
     self.A.set_nuisance_is_optimized(False)
     self.mean = GeneralizedGuinierPorodFunction(
             self.G,self.Rg,self.d,self.s, self.A)
     self.tau = Switching.setup_particle(IMP.Particle(self.m), 1.0)
     self.tau.set_nuisance_is_optimized(True)
     self.lam = Scale.setup_particle(IMP.Particle(self.m), 1.)
     self.lam.set_nuisance_is_optimized(True)
     self.sig = Scale.setup_particle(IMP.Particle(self.m), 1.0)
     self.sig.set_nuisance_is_optimized(True)
     self.cov = Covariance1DFunction(self.tau, self.lam, 2.0)
     self.gpi = IMP.isd.GaussianProcessInterpolation(self.q, self.I,
             self.err, self.N, self.mean, self.cov, self.sig)
     self.particles=[self.G,self.Rg,self.d,self.s,self.sig,self.tau,self.lam]
Beispiel #18
0
 def test_filters(self):
     """Test filters on excluded volume"""
     m = IMP.kernel.Model()
     m.set_log_level(IMP.base.SILENT)
     print "pdb"
     h0s=IMP.kernel._create_particles_from_pdb(self.get_input_file_name("1z5s_A.pdb"),
                                        m)
     l0= h0s[0:10]
     rm= h0s[10:]
     for r in rm:
         m.remove_particle(r)
     del h0s
     del rm
     print "ev"
     #set the restraint
     r=IMP.core.ExcludedVolumeRestraint(l0, 1, 0)
     print "cpc"
     cpc= IMP.container.ClosePairContainer(l0, 0, 0)
     cr= IMP.container.PairsRestraint(IMP.core.SoftSpherePairScore(1), cpc)
     dg= IMP.get_dependency_graph(m)
     #IMP.base.show_graphviz(dg)
     idx= IMP.get_vertex_index(dg)
     ss= IMP.get_required_score_states(cr, [], dg, idx)
     print "ss", ss
     self.assert_(len(ss) > 0)
     crsf= IMP.core.RestraintsScoringFunction([cr])
     crsf.set_has_required_score_states(True)
     print crsf.get_required_score_states()
     print r.evaluate(False)
     m.set_log_level(IMP.base.VERBOSE)
     print cr.evaluate(False)
     pp= cpc.get_particle_pairs()
     print  "pairs are", pp
     self.assertAlmostEqual(r.evaluate(False), cr.evaluate(False),
                            delta=.1)
 def setUp(self):
     """Build test model and optimizer"""
     IMP.test.TestCase.setUp(self)
     IMP.set_log_level(IMP.SILENT)
     self.imp_model = IMP.Model()
     self.load_density_map()
     self.load_protein("1z5s_A.pdb")
Beispiel #20
0
    def test_ms_connectivity_graph_2(self):
        """Test for the correctness of the graph 2."""
        IMP.set_log_level(IMP.SILENT)

        self.ds2[0].set_coordinates(IMP.algebra.Vector3D(1.0, 6.0, 0.0))  # A
        self.ds2[1].set_coordinates(IMP.algebra.Vector3D(3.0, 5.0, 0.0))  # A
        self.ds2[2].set_coordinates(IMP.algebra.Vector3D(0.0, 4.0, 0.0))  # A
        self.ds2[3].set_coordinates(IMP.algebra.Vector3D(1.0, 5.0, 0.0))  # B
        self.ds2[4].set_coordinates(IMP.algebra.Vector3D(1.0, 3.0, 0.0))  # B
        self.ds2[5].set_coordinates(IMP.algebra.Vector3D(0.0, 2.0, 0.0))  # C
        self.ds2[6].set_coordinates(IMP.algebra.Vector3D(0.0, 0.0, 0.0))  # C
        self.ds2[7].set_coordinates(IMP.algebra.Vector3D(1.0, 1.0, 0.0))  # D

        idk = IMP.StringKey("id")
        connections = list()
        pps = self.r2.get_connected_pairs()
        for p in pps:
            conn = sorted([p[0].get_value(idk), p[1].get_value(idk)])
            connections.append("%s <-> %s" % (conn[0], conn[1]))
        connections.sort()
        connections = ", ".join(connections)
        self.assertEqual(
            connections,
            "A <-> A, A <-> B, A <-> B, A <-> B, A <-> B, A <-> C, B <-> B, B <-> C, C <-> C, C <-> D, C <-> D",
        )
Beispiel #21
0
 def _do_test_rot(self, dt):
     """Check rigid body brownian dynamics correlation time"""
     print("Testing for dt=", dt)
     m = IMP.Model()
     p = IMP.Particle(m)
     d = IMP.core.XYZR.setup_particle(p)
     d.set_radius(10)
     rb = IMP.core.RigidBody.setup_particle(
         p, IMP.algebra.ReferenceFrame3D())
     rb.set_coordinates_are_optimized(True)
     dd = IMP.atom.RigidBodyDiffusion.setup_particle(p)
     nD = dd.get_rotational_diffusion_coefficient()
     dd.set_rotational_diffusion_coefficient(nD)
     # print dd.get_rotational_diffusion_coefficient(),
     # dd.get_diffusion_coefficient()
     bd = IMP.atom.BrownianDynamics(m)
     bd.set_scoring_function([])
     bd.set_maximum_time_step(dt)
     angles = []
     rots = []
     for i in range(0, 3000):
         bd.optimize(1)
         rots.append(
             rb.get_rotation())
         angle = IMP.algebra.get_axis_and_angle(rots[-1])
         angles.append(angle[1])
     # print angles
     real_D= dd.get_rotational_diffusion_coefficient()
     IMP.set_log_level(IMP.PROGRESS)
     estimate_D= IMP.atom.get_rotational_diffusion_coefficient(rots, dt)
     print("Mean rot angle per dt/real rotD/estimated rotD: ",
           IMP.atom.get_diffusion_angle(real_D, dt),
           real_D, estimate_D)
     self.assertAlmostEqual(real_D, estimate_D, delta= .05*(real_D+estimate_D))
     return estimate_D
Beispiel #22
0
    def _testit(self, writer, nm):
        m= IMP.Model()
        o= IMP.core.SteepestDescent()
        o.set_model(m)
        p0= IMP.Particle(m)
        d0= IMP.core.XYZR.setup_particle(p0)
        d0.set_radius(1.5)
        d0.set_x(0)
        d0.set_y(0)
        d0.set_z(0)

        p1= IMP.Particle(m)
        d1= IMP.core.XYZR.setup_particle(p1)
        d1.set_x(1)
        d1.set_y(1)
        d1.set_z(1)
        d1.set_radius(1)
        IMP.set_log_level(IMP.VERBOSE)
        a= IMP.display.WriteOptimizerState(writer)
        g= IMP.core.XYZRGeometry(d0)
        #ge= IMP.core.XYZRGeometryExtractor(rk)
        ps= IMP.container.ListSingletonContainer(m)
        ps.add_particle(p1)
        #a.add_geometry(ge, ps)
        a.add_geometry(g)
        o.add_optimizer_state(a)
        a.update()
        a.update()
        a.update()
        open(nm.replace("%1%", "2"), "r").read()
        self.assertRaises(IOError, self._testopen, nm)
Beispiel #23
0
 def test_it(self):
     """Test cover refined"""
     m= IMP.Model()
     IMP.set_log_level(IMP.MEMORY)
     n= random.randrange(1,10)
     ps=[]
     ds=IMP.core.XYZRs()
     pp= IMP.Particle(m)
     hd= IMP.core.Hierarchy.setup_particle(pp)
     dd= IMP.core.XYZR.setup_particle(pp)
     for i in range(0,n):
         p= IMP.Particle(m)
         d=IMP.core.XYZR.setup_particle(p)
         ps.append(p)
         ds.append(d)
         d.set_coordinates(IMP.algebra.get_random_vector_in(IMP.algebra.get_unit_bounding_box_3d()))
         d.set_radius(random.uniform(0,1))
         hd.add_child(IMP.core.Hierarchy.setup_particle(p))
     r= IMP.core.ChildrenRefiner(IMP.core.Hierarchy.get_default_traits())
     c= IMP.core.CentroidOfRefined(r)
     c.apply(pp)
     bb= IMP.algebra.BoundingBox3D()
     cd= IMP.core.XYZ(pp)
     for i in range(0,n):
         d= IMP.core.XYZ(hd.get_child(i).get_particle())
         bb+=IMP.algebra.BoundingBox3D(d.get_coordinates())
     self.assertTrue(bb.get_contains(cd.get_coordinates()))
    def _test_score(self):
        """Test protein ligand restraint 1"""
        m = IMP.Model()
        IMP.set_log_level(IMP.SILENT)
        p = IMP.atom.read_pdb(self.get_input_file_name("1d3d-protein.pdb"),
                              m)
        l = IMP.atom.read_mol2(self.get_input_file_name("1d3d-ligands.mol2"),
                               m)
        # print "protein"
        # IMP.atom.show_molecular_hierarchy(p)
        # print "ligand"
        # IMP.atom.show_molecular_hierarchy(l)
        print("rigid bodies")
        rbp = IMP.atom.create_rigid_body(p)
        rbl = IMP.atom.create_rigid_body(l)
        it = IMP.algebra.Transformation3D(
            IMP.algebra.get_identity_rotation_3d(),
            IMP.algebra.Vector3D(0, 0, 0))
        rbp.set_transformation(it)
        rbl.set_transformation(it)
        IMP.atom.write_mol2(
            l,
            self.get_tmp_file_name(
                "transformed_ligand.mol2"))
        IMP.atom.write_pdb(
            p,
            self.get_tmp_file_name(
                "transformed_protein.pdb"))

        print("evaluate")
        # IMP.set_log_level(IMP.VERBOSE)
        r = IMP.atom.ProteinLigandRestraint(p, l, 15.0)
        raw = r.evaluate(False)
        deriv = r.evaluate(True)
        self.assertAlmostEqual(raw, deriv, delta=.1 * (raw + deriv))
 def test_score_2(self):
     """Test protein ligand restraint 2"""
     m = IMP.Model()
     IMP.set_log_level(IMP.SILENT)
     p = IMP.atom.read_pdb(self.get_input_file_name("1d3d-protein.pdb"),
                           m, IMP.atom.NonWaterNonHydrogenPDBSelector())
     l = IMP.atom.read_mol2(self.get_input_file_name("1d3d-ligands.mol2"),
                            m, IMP.atom.NonHydrogenMol2Selector())
     #patms= IMP.atom.get_by_type(p, IMP.atom.ATOM_TYPE)
     # for cp in patms:
     #    print "Read patom "+str(IMP.core.XYZ(cp.get_particle()).get_coordinates())+":Type: \""+str(IMP.atom.Atom(cp.get_particle()).get_atom_type())+"\" atom number: "+str(IMP.atom.Atom(cp.get_particle()).get_input_index())
     #latms= IMP.atom.get_by_type(l, IMP.atom.ATOM_TYPE)
     # for cp in latms:
     # print "Read latom
     # "+str(IMP.core.XYZ(cp.get_particle()).get_coordinates())+":Type:
     # \""+str(IMP.atom.Atom(cp.get_particle()).get_atom_type())+"\" atom
     # number: "+str(IMP.atom.Atom(cp.get_particle()).get_input_index())
     print("evaluate")
     ls = IMP.atom.get_by_type(l, IMP.atom.RESIDUE_TYPE)
     self.assertEqual(len(ls), 2)
     IMP.set_log_level(IMP.SILENT)
     r0 = IMP.atom.ProteinLigandRestraint(p, ls[0], 6.0)
     r1 = IMP.atom.ProteinLigandRestraint(p, ls[1], 6.0)
     print(r0.evaluate(False))
     print(r1.evaluate(False))
     self.assertAlmostEqual(r0.evaluate(False), 8.3, delta=1)
     self.assertAlmostEqual(r1.evaluate(False), 6.5, delta=1)
    def setUp(self):
        IMP.test.TestCase.setUp(self)
        IMP.set_log_level(IMP.SILENT)
        # Initial values and names of files
        self.fn_in = self.get_input_file_name('1tdx_sampled.mrc')
        self.resolution=6.0
        self.fn_coords = self.get_input_file_name('1tdx.pdb')
        self.pixel_size=1.0

        self.mrc_rw = IMP.em.MRCReaderWriter()
        self.EM_map = IMP.em.read_map(self.fn_in,self.mrc_rw)
        self.EM_map.std_normalize()
        self.EM_map.get_header_writable().compute_xyz_top()
        self.mdl=IMP.Model()
        mh=IMP.atom.read_pdb(self.fn_coords,self.mdl,IMP.atom.CAlphaPDBSelector())
        IMP.atom.add_radii(mh)
        self.atoms=IMP.core.get_leaves(mh)
        self.model_map = IMP.em.SampledDensityMap(self.atoms, self.resolution,
                                                  self.pixel_size)
        self.xo=self.model_map.get_header().get_xorigin()
        self.yo=self.model_map.get_header().get_yorigin()
        self.zo=self.model_map.get_header().get_zorigin()

        self.EM_map = IMP.em.SampledDensityMap(self.atoms, self.resolution,                                                                                                 self.pixel_size)
        self.EM_map.std_normalize()
        self.EM_map.get_header_writable().compute_xyz_top()

        self.ccc = IMP.em.CoarseCC()
        self.ccc_intervals = IMP.em.CoarseCCatIntervals()
Beispiel #27
0
 def test_stats(self):
     """Test MonteCarlo stats"""
     m = IMP.Model()
     IMP.set_log_level(IMP.WARNING)
     mc = IMP.core.MonteCarlo(m)
     mc.set_log_level(IMP.WARNING)
     ps = []
     bb = IMP.algebra.get_unit_bounding_box_3d()
     for i in range(0, 10):
         p = IMP.Particle(m)
         d = IMP.core.XYZR.setup_particle(p)
         ps.append(d)
         d.set_coordinates(IMP.algebra.get_random_vector_in(bb))
         d.set_radius(.1)
         d.set_coordinates_are_optimized(True)
     cpc = IMP.container.ConsecutivePairContainer(m, ps)
     hps = IMP.core.HarmonicDistancePairScore(1, 100)
     r = IMP.container.PairsRestraint(hps, cpc)
     mc.set_scoring_function([r])
     ms = [IMP.core.BallMover([x], .1) for x in ps]
     mv = IMP.core.SerialMover(ms)
     mc.add_mover(mv)
     self.assertEqual(mc.get_number_of_accepted_steps(), 0)
     self.assertEqual(mc.get_number_of_upward_steps(), 0)
     self.assertEqual(mc.get_number_of_downward_steps(), 0)
     self.assertEqual(mc.get_number_of_proposed_steps(), 0)
     for i in range(0, 10):
         mc.optimize(100)
         self.assertEqual(mc.get_number_of_accepted_steps(),
                          mc.get_number_of_upward_steps() +
                          mc.get_number_of_downward_steps())
         self.assertEqual(mc.get_number_of_proposed_steps(), 100)
Beispiel #28
0
 def test_rops(self):
     """Check that LowestRefinedPairScore returns the lowest"""
     IMP.set_log_level(IMP.VERBOSE)
     m = IMP.Model()
     pp0 = m.add_particle("pp0")
     pp1 = m.add_particle("pp1")
     hpp = [IMP.core.Hierarchy.setup_particle(m, pp0),
            IMP.core.Hierarchy.setup_particle(m, pp1)]
     ds = [[], []]
     for i in range(0, 10):
         p = IMP.Particle(m)
         d = IMP.core.XYZ.setup_particle(p)
         d.set_coordinates(IMP.algebra.get_random_vector_in(
             IMP.algebra.get_unit_bounding_box_3d()))
         ds[i % 2].append(d)
         hp = IMP.core.Hierarchy.setup_particle(p)
         hpp[i % 2].add_child(hp)
     # could be more clever
     md = 1000000
     for p0 in ds[0]:
         for p1 in ds[1]:
             d = IMP.core.get_distance(p0, p1)
             if d < md:
                 md = d
     pr = IMP.core.ChildrenRefiner(IMP.core.Hierarchy.get_default_traits())
     cps = IMP.core.Linear(0, 1)
     dps = IMP.core.DistancePairScore(cps)
     rps = IMP.misc.LowestRefinedPairScore(pr, dps)
     self.assertAlmostEqual(rps.evaluate_index(m, (pp0, pp1),
                                         None), .9 * md, delta=1.1 * md)
 def setUp(self):
     IMP.test.TestCase.setUp(self)
     # IMP.set_log_level(IMP.MEMORY)
     IMP.set_log_level(0)
     self.m = IMP.Model()
     self.kappa = Scale.setup_particle(IMP.Particle(self.m), 1.0)
     self.DA = IMP.DerivativeAccumulator()
 def test_create_one(self):
     """Testing create_rigid_body"""
     count=1
     success=0
     for i in range(0, count):
         m= IMP.Model()
         IMP.set_log_level(IMP.SILENT)
         print "creating"
         p= self._create_hierarchy(m)
         print "created", p
         print "wrapping"
         h=IMP.core.Hierarchy(p)
         print "getting children"
         children=h.get_children()
         print "wrapping children"
         cs=IMP.core.XYZs(children)
         print "setting up"
         rbd=IMP.core.RigidBody.setup_particle(p, cs)
         print "set up"
         p.show()
         rbd.set_coordinates_are_optimized(True)
         self. _add_rb_restraints(rbd)
         cg= IMP.core.ConjugateGradients()
         cg.set_model(m)
         print "Initial score is " + str(m.evaluate(False))
         cg.optimize(1000)
         if m.evaluate(False) < .1:
             success=success+1
     self.assertGreater(success, count/2)
Beispiel #31
0
 def get_version_info(self):
     return IMP.VersionInfo("Daniel Russel", "0.5")
Beispiel #32
0
import IMP
import RMF
import IMP.atom
import IMP.algebra
import IMP.rmf
import IMP.pmi
import IMP.pmi.topology
import IMP.pmi.dof
import IMP.pmi.macros
import IMP.pmi.restraints.em
import tempfile
import os
###################### SYSTEM SETUP #####################
# Preliminaries
mdl = IMP.Model()
seqs = IMP.pmi.topology.Sequences(IMP.pmi.get_example_path('data/1WCM.fasta'))

# Setup just one molecule
s = IMP.pmi.topology.System(mdl)
st = s.create_state()
mol = st.create_molecule("Rpn4",sequence=seqs["1WCM:D"],chain_id="D")
atomic_res = mol.add_structure(IMP.pmi.get_example_path('data/1WCM_fitted.pdb'),
                           chain_id="D",
                           offset=0)

# Below we create a GMM approximation for this moleucle
# This "DENSITY" representation is used in the GaussianEMRestraint (and others in the future)
# For structure regions we "fit" GMM components to all atom centers
mol.add_representation(atomic_res,
                       resolutions=[1,10],
Beispiel #33
0
    def __init__(self,
                 representation=None,
                 images=None,
                 pixel_size=None,
                 image_resolution=None,
                 projection_number=None,
                 micrographs_number=None,
                 resolution=None,
                 n_components=1,
                 hier=None):
        """Constructor.
        @param representation DEPRECATED, pass 'hier' instead
        @param images 2D class average filenames in PGM text format
        @param pixel_size Pixel size in angstroms
        @param image_resolution Estimated resolution of the images
               in angstroms
        @param projection_number Number of projections of the model
               to generate and fit to images. The lower the number, the
               faster the evaluation, but the lower the accuracy
        @param micrographs_number Number of micrograph particles that
               were used to generate the class averages, if known
        @param resolution Which level of
               [model representation](@ref pmi_resolution) to use in the fit
        @param n_components Number of the largest components to be
               considered for the EM image
        @param hier The root hierarchy for applying the restraint
        """

        import IMP.em2d

        # check input
        if images is None:
            raise Exception("Must pass images")
        if pixel_size is None:
            raise Exception("Must pass pixel size")
        if image_resolution is None:
            raise Exception("must pass image resolution")

        self.datasets = []
        for image in images:
            l = ihm.location.InputFileLocation(
                image, details="Electron microscopy class average")
            d = ihm.dataset.EM2DClassDataset(l)
            self.datasets.append(d)

        if representation:
            for p, state in representation._protocol_output:
                for i in range(len(self.datasets)):
                    p.add_em2d_restraint(state, self, i, resolution,
                                         pixel_size, image_resolution,
                                         projection_number, micrographs_number)

        # PMI1/2 selection
        if representation is None and hier is not None:
            self.m = hier.get_model()
            particles = IMP.atom.Selection(
                hier, resolution=resolution).get_selected_particles()
        elif hier is None and representation is not None:
            self.m = representation.prot.get_model()
            particles = IMP.pmi.tools.select(representation,
                                             resolution=resolution)
        else:
            raise Exception("EM2D: must pass hier or representation")
        self.weight = 1.0
        self.rs = IMP.RestraintSet(self.m, 'em2d')
        self.label = "None"

        # read PGM FORMAT images
        # format conversion recommendataion - first run "e2proc2d.py $FILE ${NEW_FILE}.pgm"
        # then, run "convert ${NEW_FILE}.pgm -compress none ${NEW_FILE2}.pgm"
        if (
                n_components >= 2
        ):  # Number of the largest components to be considered for the EM image
            em2d = IMP.em2d.PCAFitRestraint(particles, images, pixel_size,
                                            image_resolution,
                                            projection_number, True,
                                            n_components)
        else:
            em2d = IMP.em2d.PCAFitRestraint(particles, images, pixel_size,
                                            image_resolution,
                                            projection_number, True)
        self._em2d_restraint = em2d
        self._num_images = len(images)
        self.rs.add_restraint(em2d)
Beispiel #34
0
    def __init__(self,
                 representation=None,
                 images=None,
                 pixel_size=None,
                 image_resolution=None,
                 projection_number=None,
                 resolution=None,
                 hier=None):
        """Constructor.
        @param representation DEPRECATED, pass 'hier' instead
        @param images SPIDER FORMAT images (format conversion should be done through EM2EM)
        @param pixel_size sampling rate of the available EM images (angstroms)
        @param image_resolution resolution at which you want to generate the projections of the model
               In principle you want "perfect" projections, so use the highest resolution
        @param projection_number Number of projections of the model (coarse registration) to
               estimate the registration parameters
        @param resolution Which level of
               [model representation](@ref pmi_resolution) to use in the fit
        @param n_components Number of the largest components to be
               considered for the EM image
        @param hier The root hierarchy for applying the restraint
        """

        import IMP.em2d

        # check input
        if images is None:
            raise Exception("EM2D_FFT: must pass images")
        if pixel_size is None:
            raise Exception("EM2D_FFT: must pass pixel size")
        if image_resolution is None:
            raise Exception("EM2D_FFT: must pass image resolution")
        if projection_number is None:
            raise Exception("EM2D_FFT: must pass projection_number")

        # PMI1/2 selection
        if representation is None and hier is not None:
            self.m = hier.get_model()
            particles = IMP.atom.Selection(
                hier, resolution=resolution).get_selected_particles()
        elif hier is None and representation is not None:
            self.m = representation.prot.get_model()
            particles = IMP.pmi.tools.select(representation,
                                             resolution=resolution)
        else:
            raise Exception("EM2D: must pass hier or representation")

        self.weight = 1.0
        self.rs = IMP.RestraintSet(self.m, 'em2d_FFT')
        self.label = "None"

        # read
        srw = IMP.em2d.SpiderImageReaderWriter()
        imgs = IMP.em2d.read_images(images, srw)
        rows = imgs[0].get_header().get_number_of_rows()
        cols = imgs[0].get_header().get_number_of_columns()

        params = IMP.em2d.Em2DRestraintParameters(pixel_size, image_resolution,
                                                  projection_number)

        # This method (recommended) uses preprocessing of the images and projections to speed-up the registration
        params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
        params.optimization_steps = 50
        params.simplex_initial_length = 0.1
        params.simplex_minimum_size = 0.02

        # use true if you want to save the projections from the model that best match the EM images
        params.save_match_images = False

        ######################
        # set up the em2D restraint
        ######################
        score_function = IMP.em2d.EM2DScore()
        em2d_restraint = IMP.em2d.Em2DRestraint(self.m)
        em2d_restraint.setup(score_function, params)
        em2d_restraint.set_images(imgs)
        em2d_restraint.set_fast_mode(5)
        em2d_restraint.set_name("em2d_restraint")

        print("len(particles) = ", len(particles))
        container = IMP.container.ListSingletonContainer(self.m, particles)
        em2d_restraint.set_particles(container)

        self.rs.add_restraint(em2d_restraint)
Beispiel #35
0
def fit_dirichlet_gmm_to_points(points,
                      n_components,
                      mdl,
                      ps=[],
                      num_iter=100,
                      covariance_type='full',
                      mass_multiplier=1.0):
    """fit a GMM to some points. Will return core::Gaussians.
    if no particles are provided, they will be created

    points:            list of coordinates (python)
    n_components:      number of gaussians to create
    mdl:               IMP Model
    ps:                list of particles to be decorated. if empty, will add
    num_iter:          number of EM iterations
    covariance_type:   covar type for the gaussians. options: 'full', 'diagonal', 'spherical'
    init_centers:      initial coordinates of the GMM
    force_radii:       fix the radii (spheres only)
    force_weight:      fix the weights
    mass_multiplier:   multiply the weights of all the gaussians by this value
    """


    new_sklearn = True
    try:
        from sklearn.mixture import BayesianGaussianMixture
    except ImportError:
        from sklearn.mixture import DPGMM
        new_sklearn = False

    ### create and fit GMM
    print('using dirichlet prior')
    if new_sklearn:
        gmm = BayesianGaussianMixture(
                weight_concentration_prior_type='dirichlet_process',
                n_components=n_components, max_iter=num_iter,
                covariance_type=covariance_type)
    else:
        gmm = DPGMM(n_components=n_components, n_iter=num_iter,
                    covariance_type=covariance_type)

    gmm.fit(points)

    #print('>>> GMM score',gmm.score(points))

    #print gmm.covars_
    #print gmm.weights_
    #print gmm.means_
    ### convert format to core::Gaussian
    if not new_sklearn:
        gmm.precisions_ = gmm.precs_
    for ng in range(n_components):
        invcovar=gmm.precisions_[ng]
        covar=np.linalg.inv(invcovar)
        if covar.size==3:
            covar=np.diag(covar).tolist()
        else:
            covar=covar.tolist()
        center=list(gmm.means_[ng])
        weight=mass_multiplier*gmm.weights_[ng]
        if ng>=len(ps):
            ps.append(IMP.Particle(mdl))
        shape=IMP.algebra.get_gaussian_from_covariance(covar,IMP.algebra.Vector3D(center))
        g=IMP.core.Gaussian.setup_particle(ps[ng],shape)
        IMP.atom.Mass.setup_particle(ps[ng],weight)
        IMP.core.XYZR.setup_particle(ps[ng],sqrt(max(g.get_variances())))
Beispiel #36
0
def fit_gmm_to_points(points,
                      n_components,
                      mdl,
                      ps=[],
                      num_iter=100,
                      covariance_type='full',
                      min_covar=0.001,
                      init_centers=[],
                      force_radii=-1.0,
                      force_weight=-1.0,
                      mass_multiplier=1.0):
    """fit a GMM to some points. Will return the score and the Akaike score.
    Akaike information criterion for the current model fit. It is a measure
    of the relative quality of the GMM that takes into account the
    parsimony and the goodness of the fit.
    if no particles are provided, they will be created

    points:            list of coordinates (python)
    n_components:      number of gaussians to create
    mdl:               IMP Model
    ps:                list of particles to be decorated. if empty, will add
    num_iter:          number of EM iterations
    covariance_type:   covar type for the gaussians. options: 'full', 'diagonal', 'spherical'
    min_covar:         assign a minimum value to covariance term. That is used to have more spherical
                       shaped gaussians
    init_centers:      initial coordinates of the GMM
    force_radii:       fix the radii (spheres only)
    force_weight:      fix the weights
    mass_multiplier:   multiply the weights of all the gaussians by this value
    dirichlet:         use the DGMM fitting (can reduce number of components, takes longer)
    """


    new_sklearn = False
    try:
        from sklearn.mixture import GMM
    except ImportError:
        from sklearn.mixture import GaussianMixture
        new_sklearn = True

    print('creating GMM with n_components',n_components,'n_iter',num_iter,'covar type',covariance_type)
    if new_sklearn:
        # aic() calls size() on points, so it needs to be
        # a numpy array, not a list
        points = np.array(points)
        weights_init = precisions_init = None
        if force_radii != -1.0:
            print('warning: radii can no longer be forced, but setting '
                  'initial values to ', force_radii)
            precisions_init = np.array([[1./force_radii]*3
                                       for i in range(n_components)])
        if force_weight != -1.0:
            print('warning: weights can no longer be forced, but setting '
                  'initial values to ', force_weight)
            weights_init = np.array([force_weight]*n_components)

        gmm = GaussianMixture(n_components=n_components,
                              max_iter=num_iter,
                              covariance_type=covariance_type,
                              weights_init=weights_init,
                              precisions_init=precisions_init,
                              means_init=None if init_centers==[]
                                              else init_centers)
    else:
        params='m'
        init_params='m'
        if force_radii==-1.0:
            params+='c'
            init_params+='c'
        else:
            covariance_type='spherical'
            print('forcing spherical with radii',force_radii)

        if force_weight==-1.0:
            params+='w'
            init_params+='w'
        else:
            print('forcing weights to be',force_weight)

        gmm = GMM(n_components=n_components, n_iter=num_iter,
                  covariance_type=covariance_type, min_covar=min_covar,
                  params=params, init_params=init_params)
        if force_weight!=-1.0:
            gmm.weights_=np.array([force_weight]*n_components)
        if force_radii!=-1.0:
            gmm.covars_=np.array([[force_radii]*3 for i in range(n_components)])
        if init_centers!=[]:
            gmm.means_=init_centers
    print('fitting')
    model=gmm.fit(points)
    score=gmm.score(points)
    akaikescore=model.aic(points)
    #print('>>> GMM score',gmm.score(points))

    ### convert format to core::Gaussian
    if new_sklearn:
        covars = gmm.covariances_
    else:
        covars = gmm.covars_
    for ng in range(n_components):
        covar=covars[ng]
        if covar.size==3:
            covar=np.diag(covar).tolist()
        else:
            covar=covar.tolist()
        center=list(gmm.means_[ng])
        weight=mass_multiplier*gmm.weights_[ng]
        if ng>=len(ps):
            ps.append(IMP.Particle(mdl))
        shape=IMP.algebra.get_gaussian_from_covariance(covar,IMP.algebra.Vector3D(center))
        g=IMP.core.Gaussian.setup_particle(ps[ng],shape)
        IMP.atom.Mass.setup_particle(ps[ng],weight)
        IMP.core.XYZR.setup_particle(ps[ng],sqrt(max(g.get_variances())))

    return (score,akaikescore)
Beispiel #37
0
 def get_version_info(self):
     return IMP.get_module_version_info()
Beispiel #38
0
    def test_bonded(self):
        """Check brownian dynamics with rigid bodies"""
        self.skipTest("TAMD is temporarily disabled")
        # Disable internal checks, since they make the test take way too long
        IMP.set_check_level(IMP.USAGE)
        m = IMP.Model()
        m.set_log_level(IMP.SILENT)
        cores=[]
        for i in range(10):
            cores.append( self._create_tamd_centroid(m) )
#        p2, fparticles2, p2S = self._create_tamd_centroid(m)
#        p3, fparticles3, p3S = self._create_tamd_centroid(m)

        for p in ([cores[0][0]] + cores[0][1]+ [cores[0][2]] ):
            IMP.display.Colored.setup_particle( p, IMP.display.Color(1, 0, 0) )
        for p in ([cores[1][0]] + cores[1][1]+ [cores[1][2]] ):
            IMP.display.Colored.setup_particle( p, IMP.display.Color(0, 1, 0) )
        for p in ([cores[2][0]] + cores[2][1]+ [cores[2][2]] ):
            IMP.display.Colored.setup_particle( p, IMP.display.Color(0, 0, 1) )
        for p in ([cores[3][0]] + cores[3][1]+ [cores[3][2]] ):
            IMP.display.Colored.setup_particle( p, IMP.display.Color(1, 1, 0) )

        # Add Restraints:
        spring = IMP.core.HarmonicDistancePairScore(0, 0.00000001)
        excluded_vol = IMP.core.SoftSpherePairScore(100)
        attraction = IMP.core.HarmonicSphereDistancePairScore(5, 5)
        R=[] # restraints
        # TAMD:
        for core in cores:
            r=IMP.core.PairRestraint(m, spring, (core[0], core[2]))
            R.append(r)
        # Repulsion between fine particles
        for core1 in cores:
            for p1 in core1[1]:
                for core2 in cores:
                    for p2 in core2[1]:
                        if(p1 == p2): continue
                        r = IMP.core.PairRestraint(m, excluded_vol,
                                                   (p1, p2), "Excluded_vol")
                        R.append(r)
        # Attraction between consecutive particles (within or between cores)
        for core in cores:
            for p1,p2 in zip(core[1][0:-1],core[1][1:]):
                r = IMP.core.PairRestraint(m, attraction, (p1, p2), "Chain")
                R.append(r)
        for core1,core2 in zip(cores[0:-1],cores[1:]):
            r = IMP.core.PairRestraint(m, attraction,
                                   (core1[1][-1], core2[1][0]), "Interchain")
            R.append(r)
        print(R)

        # Define BD
        bd = IMP.atom.BrownianDynamicsTAMD(m)
        sf = IMP.core.RestraintsScoringFunction(R)
        bd.set_maximum_time_step(5)


        # Attach RMF
#        RMF.set_log_level("Off")
        rmf_fname = self.get_tmp_file_name("bd_rb_NOtamd.rmf")
        rmf = RMF.create_rmf_file(rmf_fname)
        print("RMF: ", rmf_fname)
        all_particles=[]
        for core in cores:
            for p in [core[0]] + core[1] + [core[2]]:
                IMP.rmf.add_hierarchy(rmf, p)
        IMP.rmf.add_restraints(rmf, R)
        sf.set_log_level(IMP.SILENT)
        os = IMP.rmf.SaveOptimizerState(m, rmf)
        os.set_log_level(IMP.SILENT)
        os.set_period(10)
        bd.set_scoring_function(sf)
        bd.add_optimizer_state(os)

        IMP.set_log_level(IMP.VERBOSE)
        os.update_always("Init position")
        IMP.set_log_level(IMP.SILENT)

        for i in range(100):
            bd.optimize(5)
            m.update()
            os.update_always("Init opt %d" % i)
            for core in cores:
                centroid =  IMP.core.XYZ(core[0]).get_coordinates()
                IMP.core.XYZ(core[2]).set_coordinates( centroid )

        max_cycles = 50
        round_cycles = 25
        total_cycles = 0
        e_threshold = 2
        for i in range(max_cycles // round_cycles):
            bd.optimize(round_cycles)
            energy = sf.evaluate(False)
            total_cycles += round_cycles
            print("energy after %d cycles = %.2f"
                  % (total_cycles, energy))
Beispiel #39
0
r = IMP.container.PairsRestraint(s, lpc)
r.set_maximum_score(.1)

space = IMP.domino.XYZStates(
    [IMP.algebra.Vector3D(i, 0, 0) for i in range(0, 6)])

pst = IMP.domino.ParticleStatesTable()
for p in ps:
    pst.set_particle_states(p, space)

m.set_log_level(IMP.base.SILENT)

# make sure to break up the
mt = IMP.domino.get_merge_tree([r], pst)
try:
    IMP.show_graphviz(mt)
except:
    print("Unable to display graph using 'dot'")
rc = IMP.domino.RestraintCache(pst)
rc.add_restraints([r])
filters = [
    IMP.domino.RestraintScoreSubsetFilterTable(rc),
    IMP.domino.ExclusionSubsetFilterTable(pst)
]
leaf_table = IMP.domino.BranchAndBoundAssignmentsTable(pst, filters)

# create a database to store the results
name = IMP.create_temporary_file_name("assignments", ".hdf5")
root = RMF.HDF5.create_file(name)

# recurse down the tree getting the assignments and printing them
Beispiel #40
0
 def __init__(self, model, particles):
     IMP.kernel.Restraint.__init__(self, model, "WoodsFunc %1%")
     self.particles = particles
     self.index = IMP.FloatKey("x")
Beispiel #41
0
#--------------------------
# Create movers
#--------------------------

# rigid body movement params
rb_max_trans = 1.00
rb_max_rot = 0.01
# flexible bead movement
bead_max_trans = 2.00

#--------------------------------
# Build the Model Representation
#--------------------------------

# Initialize model
m = IMP.Model()

# Create list of components from topology file
topology = IMP.pmi.topology.TopologyReader(topology_file,
                                           pdb_dir=datadirectory,
                                           fasta_dir=datadirectory)
domains = topology.get_components()

bs = IMP.pmi.macros.BuildSystem(m)
bs.add_state(topology)
representation, dof = bs.execute_macro(max_rb_trans=rb_max_trans,
                                       max_rb_rot=rb_max_rot,
                                       max_bead_trans=bead_max_trans)

# representation.shuffle_configuration(50)
Beispiel #42
0
 def create_singleton_score(self):
     uf = IMP.core.Linear(0, 1)
     return IMP.core.AttributeSingletonScore(uf, IMP.FloatKey("thekey"))
import IMP.pmi.macros
import sys, os

# most common settings
num_top_models = 500
run_number = 1

merge_directories = ["../run" + str(run_number) + "/"]
prefiltervalue = 2000
out_dir = "kmeans_r%i_m%i/" % (run_number, num_top_models)

#################################
# should not have to change below
##################################

model = IMP.Model()

# initialize the macro
mc = IMP.pmi.macros.AnalysisReplicaExchange0(
    model, merge_directories=merge_directories)

# fields that have to be extracted for the stat file
feature_list = [
    "ISDCrossLinkMS_Distance_intrarb", "ISDCrossLinkMS_Distance_interrb",
    "ISDCrossLinkMS_Data_Score", "GaussianEMRestraint_None",
    "SimplifiedModel_Linker_Score_None", "ISDCrossLinkMS_Psi",
    "ISDCrossLinkMS_Sigma"
]

# Dictionary of densities to be calculated
# the key is the name of the file and the value is the selection
Beispiel #44
0
 def test_get_set_source(self):
     mdl = IMP.Model()
     p = IMP.Particle(mdl)
     s = IMP.atom.StructureSource.setup_particle(p, '1ABC', 'G')
     self.assertEqual(s.get_source_id(), '1ABC')
     self.assertEqual(s.get_source_chain_id(), 'G')
Beispiel #45
0
 def test_process_output_v1(self):
     """Test reading stat file (v1)"""
     with IMP.allow_deprecated():
         self._check_stat_file(self.get_input_file_name(
                                               "./output1/statv1.out"))
Beispiel #46
0
## \example core/rigid_bodies.py
# This example shows how to set up rigid bodies, one per residue in a protein. A score
# state is then used to ensure that the bodies remain rigid during the optimization process.
#

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

IMP.setup_from_argv(sys.argv, "rigid bodies")

m = IMP.Model()
# create a new IMP.atom.Hierarchy for the pdb file
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])
# Create a rigid body from the first chain
# note that rbs != chains[0] as the bounding volume for rbs needs to include all of the
# chain, but chains[0] might have a smaller sphere associated with it.
rbs = IMP.atom.create_rigid_body(chains[0])
print("all done")
Beispiel #47
0
## \example kernel/graph.py
# A simple example showing how to use the graph interface for in python.

from __future__ import print_function
import IMP
import sys

IMP.setup_from_argv(sys.argv, "Graph interface")

m = IMP.Model()
# An undirected graph with an IMP::Object for each node
g = IMP.DependencyGraph()
vs = []
ps = []
for i in range(0, 10):
    ps.append(IMP.Particle(m))
    vs.append(g.add_vertex(ps[-1]))
g.add_edge(vs[0], vs[1])
g.add_edge(vs[1], vs[2])

# try to use the altgraph package to visualize
IMP.show_graphviz(g)
try:
    IMP.show_graphviz(g)
except:
    print("Oh well, no altgraph")

try:
    import matplotlib
    # the engine to be used must be selected before pyplot is imported
    matplotlib.use("macosx")
Beispiel #48
0
 def setUp(self):
     IMP.test.TestCase.setUp(self)
     # IMP.set_log_level(IMP.MEMORY)
     IMP.set_log_level(0)
     self.m = IMP.kernel.Model()
     self.w = Weight.setup_particle(IMP.kernel.Particle(self.m))
Beispiel #49
0
    def test_shuffle_deep(self):
        """Test moving rbs, fbs"""
        mdl = IMP.Model()
        s = IMP.pmi.topology.System(mdl)
        seqs = IMP.pmi.topology.Sequences(
            self.get_input_file_name('chainA.fasta'))
        st1 = s.create_state()
        mol = st1.create_molecule("GCP2_YEAST",
                                  sequence=seqs["GCP2_YEAST"][:100],
                                  chain_id='A')
        atomic_res = mol.add_structure(self.get_input_file_name('chainA.pdb'),
                                       chain_id='A',
                                       res_range=(1, 100))
        mol.add_representation(mol.get_atomic_residues(), resolutions=[10])
        mol.add_representation(mol.get_non_atomic_residues(), resolutions=[10])

        mol2 = mol.create_clone('B')

        mol3 = st1.create_molecule("GCP2_YEAST_BEADS",
                                   sequence=seqs["GCP2_YEAST"][:100],
                                   chain_id='C')
        mol3.add_representation(mol3.get_non_atomic_residues(),
                                resolutions=[10])

        hier = s.build()

        dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
        dof.create_rigid_body(mol,
                              nonrigid_parts=mol.get_non_atomic_residues())
        dof.create_rigid_body(mol2,
                              nonrigid_parts=mol2.get_non_atomic_residues())
        dof.create_flexible_beads(mol3.get_non_atomic_residues(),
                                  max_trans=1.0)

        rbs, fbs = IMP.pmi.tools.get_rbs_and_beads([hier])

        rbs_trans_before = {}
        fbs_position_before = {}

        rbs_trans_after = {}
        fbs_position_after = {}

        for rb in rbs:
            rbs_trans_before[rb] = rb.get_reference_frame(
            ).get_transformation_to()

        for fb in fbs:
            if IMP.core.NonRigidMember.get_is_setup(fb):
                fbs_position_before[fb] = \
                        IMP.core.NonRigidMember(fb).get_internal_coordinates()
            else:
                fbs_position_before[fb] = IMP.core.XYZ(fb).get_coordinates()

        IMP.pmi.tools.shuffle_configuration(hier)

        for rb in rbs:
            rbs_trans_after[rb] = rb.get_reference_frame(
            ).get_transformation_to()

        for fb in fbs:
            if IMP.core.NonRigidMember.get_is_setup(fb):
                fbs_position_after[fb] = \
                        IMP.core.NonRigidMember(fb).get_internal_coordinates()
            else:
                fbs_position_after[fb] = IMP.core.XYZ(fb).get_coordinates()

        for fb in fbs:
            position_after = fbs_position_after[fb]
            position_before = fbs_position_before[fb]
            for i in [0, 1, 2]:
                self.assertNotEqual(position_after[i], position_before[i])

        for rb in rbs:
            position_after = rbs_trans_after[rb].get_translation()
            position_before = rbs_trans_before[rb].get_translation()
            rotation_after = rbs_trans_after[rb].get_rotation(
            ) * IMP.algebra.Vector3D(1, 1, 1)
            rotation_before = rbs_trans_before[rb].get_rotation(
            ) * IMP.algebra.Vector3D(1, 1, 1)
            for i in [0, 1, 2]:
                self.assertNotEqual(position_after[i], position_before[i])
                self.assertNotEqual(rotation_after[i], rotation_before[i])
Beispiel #50
0
    def create_rigid_body(self,
                          rigid_parts,
                          nonrigid_parts=None,
                          max_trans=1.0,
                          max_rot=0.1,
                          nonrigid_max_trans=0.1,
                          resolution='all',
                          name=None):
        """Create rigid body constraint and mover
        @param rigid_parts Can be one of the following inputs:
           IMP Hierarchy, PMI System/State/Molecule/TempResidue, a list/set (of list/set) of them
           or a RigidBody object.
           Must be uniform input, however. No mixing object types.
        @param nonrigid_parts Same input format as rigid_parts.
               Must be a subset of rigid_parts particles.
        @param max_trans Maximum rigid body translation
        @param max_rot Maximum rigid body rotation
        @param nonrigid_max_trans Maximum step for the nonrigid (bead) particles
        @param resolution Only used if you pass PMI objects. Probably you want 'all'.
        @param name Rigid body name (if None, use IMP default)
        \note If you want all resolutions, pass PMI objects because this function will get them all.
        Alternatively you can do your selection elsewhere and just pass hierarchies.
        Returns tuple (rb_movers,rb_object)
        """

        rb_movers = []

        # ADD CHECK: these particles are not already part of some RB or SRB

        # First, is this already a rigid body?
        if type(rigid_parts) is IMP.core.RigidBody:
            rb = rigid_parts
            if name is not None:
                name = rb.get_name()
        else:
            ### Otherwise, setup RB
            hiers = IMP.pmi.tools.input_adaptor(rigid_parts,
                                                resolution,
                                                flatten=True)
            if not hiers:
                print(
                    "WARNING: No hierarchies were passed to create_rigid_body()"
                )
                return []
            rb = IMP.atom.create_rigid_body(hiers)
        self.rigid_bodies.append(rb)
        rb.set_coordinates_are_optimized(True)
        rb_mover = IMP.core.RigidBodyMover(rb, max_trans, max_rot)
        if name is not None:
            rb.set_name(name)
            rb_mover.set_name(name)
        rb_movers.append(rb_mover)

        ### setup nonrigid parts
        if nonrigid_parts:
            nr_hiers = IMP.pmi.tools.input_adaptor(nonrigid_parts,
                                                   resolution,
                                                   flatten=True)
            if nr_hiers:
                floatkeys = [IMP.FloatKey(4), IMP.FloatKey(5), IMP.FloatKey(6)]
                rb_idxs = set(rb.get_member_indexes())
                for h in nr_hiers:
                    self.flexible_beads.append(h)
                    p = h.get_particle()
                    if not p.get_index() in rb_idxs:
                        raise Exception(
                            "You tried to create nonrigid members from "
                            "particles that aren't in the RigidBody!")

                    rb.set_is_rigid_member(p.get_index(), False)
                    for fk in floatkeys:
                        p.set_is_optimized(fk, True)
                    rb_movers.append(
                        IMP.core.BallMover([p], IMP.FloatKeys(floatkeys),
                                           nonrigid_max_trans))
        self.movers += rb_movers  # probably need to store more info
        return rb_movers, rb
Beispiel #51
0
 def test_import_module(self):
     """Test CommandDispatcher.import_module()"""
     c = IMP.CommandDispatcher("short", "long", "TestModule")
     self.assertEqual(id(c.import_module()), id(TestModule))
     self.assertEqual(id(c.import_module('submodule')),
                      id(TestModule.submodule))
Beispiel #52
0
    def test_input_adaptor_pmi(self):
        """Test that input adaptor correctly performs selection"""
        mdl = IMP.Model()
        s = IMP.pmi.topology.System(mdl)
        seqs = IMP.pmi.topology.Sequences(
            self.get_input_file_name('seqs.fasta'))
        st1 = s.create_state()

        m1 = st1.create_molecule("Prot1", sequence=seqs["Protein_1"])
        m2 = st1.create_molecule("Prot2", sequence=seqs["Protein_2"])
        m3 = st1.create_molecule("Prot3", sequence=seqs["Protein_3"])
        a1 = m1.add_structure(self.get_input_file_name('prot.pdb'),
                              chain_id='A',
                              res_range=(55, 63),
                              offset=-54)
        a2 = m2.add_structure(self.get_input_file_name('prot.pdb'),
                              chain_id='B',
                              res_range=(180, 192),
                              offset=-179)
        a3 = m3.add_structure(self.get_input_file_name('prot.pdb'),
                              chain_id='G',
                              res_range=(55, 63),
                              offset=-54)
        m1.add_representation(a1, resolutions=[0, 1])
        m1.add_representation(m1.get_non_atomic_residues(), resolutions=[1])
        m2.add_representation(a2, resolutions=[0, 1])  # m2 only has atoms
        m3.add_representation(a3, resolutions=[1, 10])
        m3.add_representation(m3.get_non_atomic_residues(),
                              resolutions=[1],
                              setup_particles_as_densities=True)
        hier = s.build()

        densities = [r.get_hierarchy() for r in m3.get_non_atomic_residues()]

        #set up GMM particles
        gemt = IMP.pmi.restraints.em.GaussianEMRestraint(
            densities,
            self.get_input_file_name('prot_gmm.txt'),
            target_is_rigid_body=True)

        gmm_hier = gemt.get_density_as_hierarchy()
        test0 = IMP.pmi.tools.input_adaptor(gmm_hier)
        self.assertEqual(test0, [IMP.atom.get_leaves(gmm_hier)])

        # get one resolution
        test1 = IMP.pmi.tools.input_adaptor(m1, pmi_resolution=0)
        self.assertEqual(test1, [
            IMP.atom.Selection(m1.get_hierarchy(),
                               resolution=0).get_selected_particles()
        ])

        # get all resolutions
        test1all = IMP.pmi.tools.input_adaptor(m1, pmi_resolution='all')
        compare1all = set(
            IMP.atom.Selection(m1.get_hierarchy(),
                               resolution=0).get_selected_particles() +
            IMP.atom.Selection(m1.get_hierarchy(),
                               resolution=1).get_selected_particles())
        self.assertEqual(set(test1all[0]), compare1all)

        # list of set of TempResidue
        test3 = IMP.pmi.tools.input_adaptor([m1[0:3], m2[:], m3[0:1]],
                                            pmi_resolution=1)
        compare3 = [
            IMP.atom.Selection(m1.get_hierarchy(),
                               residue_indexes=[1, 2, 3],
                               resolution=1).get_selected_particles(),
            IMP.atom.Selection(m2.get_hierarchy(),
                               resolution=1).get_selected_particles(),
            IMP.atom.Selection(m3.get_hierarchy(),
                               residue_index=1,
                               resolution=1).get_selected_particles()
        ]
        self.assertEqual([set(l) for l in test3], [set(l) for l in compare3])

        # check robustness and consistency TempResidue + Hierarchy
        test4 = IMP.pmi.tools.input_adaptor([m1[0:3], m2[:], m3[0:1]],
                                            flatten=True,
                                            pmi_resolution=1)

        compare4 = IMP.pmi.tools.input_adaptor(compare3,
                                               pmi_resolution=1,
                                               flatten=True)
        compare5 = IMP.pmi.tools.input_adaptor(compare3, flatten=True)
        compare6 = IMP.pmi.tools.input_adaptor(compare3,
                                               pmi_resolution='all',
                                               flatten=True)

        self.assertEqual(test4, compare4)
        self.assertEqual(test4, compare5)
        self.assertEqual(test4, compare6)

        # check input is list or list of lists
        test5 = IMP.pmi.tools.input_adaptor([m1, m2, m3], pmi_resolution=1)
        test6 = IMP.pmi.tools.input_adaptor([[m1, m2], [m3]], pmi_resolution=1)
        self.assertEqual(test5, test6)

        # test input particles and input hierarchies

        compare7 = [
            IMP.atom.Hierarchy(p) for sublist in compare3 for p in sublist
        ]
        test7 = IMP.pmi.tools.input_adaptor(compare7,
                                            flatten=True,
                                            pmi_resolution=1)
        compare8 = [p for sublist in compare3 for p in sublist]
        test8 = IMP.pmi.tools.input_adaptor(compare8,
                                            flatten=True,
                                            pmi_resolution=1)
        self.assertEqual(test7, test8)

        # raises if passing an uneven list
        with self.assertRaises(Exception):
            IMP.pmi.tools.input_adaptor([[m1, m2], m3], pmi_resolution=1)

        #raises if passing mixed lists
        with self.assertRaises(Exception):
            IMP.pmi.tools.input_adaptor([m1, s, m3], pmi_resolution=1)

        # compare hierarchies and pmi molecules:
        m1s_pmi = IMP.pmi.tools.input_adaptor(m1, pmi_resolution=1)
        m1s_hiers = IMP.pmi.tools.input_adaptor(m1.hier, pmi_resolution=1)
        self.assertEqual([set(l) for l in m1s_pmi],
                         [set(l) for l in m1s_hiers])

        m1s_pmi = IMP.pmi.tools.input_adaptor(m1, pmi_resolution=10)
        m1s_hiers = IMP.pmi.tools.input_adaptor(m1.hier, pmi_resolution=10)
        self.assertEqual([set(l) for l in m1s_pmi],
                         [set(l) for l in m1s_hiers])

        m1s_pmi = IMP.pmi.tools.input_adaptor(m1, pmi_resolution='all')
        m1s_hiers = IMP.pmi.tools.input_adaptor(m1.hier, pmi_resolution='all')
        self.assertEqual([set(l) for l in m1s_pmi],
                         [set(l) for l in m1s_hiers])

        # compare hierarchies and pmi states:
        st1s_pmi = IMP.pmi.tools.input_adaptor(st1,
                                               pmi_resolution=1,
                                               flatten=True)
        st1s_hiers = IMP.pmi.tools.input_adaptor(st1.hier,
                                                 pmi_resolution=1,
                                                 flatten=True)
        self.assertEqual(st1s_pmi, st1s_hiers)

        st1s_pmi = IMP.pmi.tools.input_adaptor(st1,
                                               pmi_resolution=10,
                                               flatten=True)
        st1s_hiers = IMP.pmi.tools.input_adaptor(st1.hier,
                                                 pmi_resolution=10,
                                                 flatten=True)
        self.assertEqual(st1s_pmi, st1s_hiers)

        st1s_pmi = IMP.pmi.tools.input_adaptor(st1,
                                               pmi_resolution='all',
                                               flatten=True)
        st1s_hiers = IMP.pmi.tools.input_adaptor(st1.hier,
                                                 pmi_resolution='all',
                                                 flatten=True)
        self.assertEqual(st1s_pmi, st1s_hiers)

        # compare hierarchies and pmi system:
        sys_pmi = IMP.pmi.tools.input_adaptor(s,
                                              pmi_resolution=1,
                                              flatten=True)
        sys_hiers = IMP.pmi.tools.input_adaptor(s.hier,
                                                pmi_resolution=1,
                                                flatten=True)
        self.assertEqual(sys_pmi, sys_hiers)

        sys_pmi = IMP.pmi.tools.input_adaptor(s,
                                              pmi_resolution=10,
                                              flatten=True)
        sys_hiers = IMP.pmi.tools.input_adaptor(s.hier,
                                                pmi_resolution=10,
                                                flatten=True)
        self.assertEqual(sys_pmi, sys_hiers)

        sys_pmi = IMP.pmi.tools.input_adaptor(s,
                                              pmi_resolution='all',
                                              flatten=True)
        sys_hiers = IMP.pmi.tools.input_adaptor(s.hier,
                                                pmi_resolution='all',
                                                flatten=True)
        self.assertEqual(sys_pmi, sys_hiers)

        # nothing changes to hierarchy
        p = IMP.Particle(mdl)
        h = IMP.atom.Hierarchy.setup_particle(p)
        IMP.atom.Mass.setup_particle(p, 1.0)
        xyzr = IMP.core.XYZR.setup_particle(p)
        xyzr.set_coordinates((0, 0, 0))
        xyzr.set_radius(1.0)
        tH = [h]

        testH = IMP.pmi.tools.input_adaptor(tH)
        self.assertEqual(testH, [tH])

        # check passing system,state
        testSystem = [
            set(l) for l in IMP.pmi.tools.input_adaptor(s, pmi_resolution=0)
        ]
        testState = [
            set(l) for l in IMP.pmi.tools.input_adaptor(st1, pmi_resolution=0)
        ]
        compareAll = [
            set(
                IMP.atom.Selection(m.get_hierarchy(),
                                   resolution=0).get_selected_particles())
            for m in [m1, m2, m3]
        ]

        # get_molecules() returns a dict, so the order of testSystem
        # and testState is not guaranteed
        self.assertEqualUnordered(testSystem, compareAll)
        self.assertEqualUnordered(testState, compareAll)
Beispiel #53
0
 def test_show_command_help_help(self):
     """Test CommandDispatcher show help command help"""
     sys.argv = ['testprog', 'help', 'help']
     c = IMP.CommandDispatcher("short", "long", "TestModule")
     c.main()
     self.assert_help_out_ok()
Beispiel #54
0
# addition, show how to visualize restraints and visualize the
# rejected conformations. Both are useful things to do when trying to
# figure out why optimization is not converging.

from __future__ import print_function
import IMP
import IMP.atom
import IMP.container
import IMP.display
import IMP.statistics
import IMP.example
import os
import sys

# not finished
IMP.add_bool_flag("run", "Whether to run the program")

# parse command line arguments so, eg profiling can be used
IMP.setup_from_argv(sys.argv, "Nup84 example")

if IMP.get_bool_flag("run") != "yes":
    exit(0)

# First we define some basic parameters for the modeling effort

# the spring constant to use, it doesn't really matter
k = 10
# the target resolution for the representation
resolution = 100
# the box to perform everything in, make it flat as it is a 2D structure
bb = IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(-300, -300, -50),
Beispiel #55
0
    def unprotected_evaluate(self, da):
        score = 0
        for i in range(1, len(self.ps)):
            p0 = self.ps[i - 1]
            p1 = self.ps[i]
            if p0.get_value(k) > p1.get_value(k):
                diff = (p0.get_value(k) - p1.get_value(k))
                score = score + diff
                p0.add_to_derivative(k, -1, da)
                p1.add_to_derivative(k, 1, da)
            else:
                if IMP.get_log_level() >= IMP.base.TERSE:
                    print p0.get_name(), "and", p1.get_name(), " are ok"
        return score

    def do_get_inputs(self):
        return self.ps


# some code to create and evaluate it
k = IMP.FloatKey("a key")
m = IMP.kernel.Model()
ps = []
for i in range(0, 10):
    p = IMP.kernel.Particle(m)
    p.add_attribute(k, i)
    ps.append(p)
r = MyRestraint(m, ps, k)
# IMP.base.set_log_level(IMP.base.TERSE)
print r.evaluate(True)
Beispiel #56
0
 def test_init(self):
     """Test CommandDispatcher init"""
     sys.argv = ['/foo/bar/testprogname', 'arg1']
     c = IMP.CommandDispatcher("short", "long", "TestModule")
     self.assertEqual(c._progname, 'testprogname')
Beispiel #57
0
 def tearDown(self):
     # Restore original check level
     IMP.set_check_level(self.__check_level)
     # Clean up any temporary files
     if hasattr(self, '_tmpdir'):
         del self._tmpdir
Beispiel #58
0
    def test_relative_position_mover(self, ):
        """ Test the RelativePositionMover """
        log.info("test RelativePositionMover")
        fn_rec1 = self.get_input_file_name("1suvA_xlinked.pdb")
        fn_rec2 = self.get_input_file_name("1suvC_xlinked.pdb")
        fn_lig = self.get_input_file_name("1suvE_xlinked.pdb")
        fn_tr1  = \
            self.get_input_file_name("transforms-1suvA-1suvE_reduced.txt")
        fn_tr2  = \
            self.get_input_file_name("transforms-1suvC-1suvE_filtered.txt")
        m = IMP.Model()
        sel = atom.ATOMPDBSelector()
        h_rec1 = atom.read_pdb(fn_rec1, m, sel)
        rb_rec1 = atom.create_rigid_body(h_rec1)
        rec1_coords = [
            core.XYZ(l).get_coordinates() for l in atom.get_leaves(h_rec1)
        ]
        h_rec2 = atom.read_pdb(fn_rec2, m, sel)
        rb_rec2 = atom.create_rigid_body(h_rec2)
        rec2_coords = [
            core.XYZ(l).get_coordinates() for l in atom.get_leaves(h_rec2)
        ]
        h_ligand = atom.read_pdb(fn_lig, m, sel)
        rb_lig = atom.create_rigid_body(h_ligand)

        Ts = get_relative_transforms(fn_tr1)
        Tis1 = []
        for i, T in enumerate(Ts):
            V = get_internal_transform3(T, rb_rec1, rb_lig)
            Tis1.append(V)
        docked_refs1 = get_docked_reference_frames(Ts, rb_lig)

        Ts = get_relative_transforms(fn_tr2)
        Tis2 = []
        for i, T in enumerate(Ts):
            V = get_internal_transform3(T, rb_rec2, rb_lig)
            Tis2.append(V)
        docked_refs2 = get_docked_reference_frames(Ts, rb_lig)

        mv = em2d.RelativePositionMover(rb_lig, 10, 20)
        mv.add_internal_transformations(rb_rec1, Tis1)
        mv.add_internal_transformations(rb_rec2, Tis2)

        for i in range(2):
            #            prob_random = 0
            ref_before = rb_lig.get_reference_frame()
            ps = mv.propose()  # _move(prob_random)
            ref_after = rb_lig.get_reference_frame()
            found = False
            current_coords = [
                core.XYZ(l).get_coordinates()
                for l in atom.get_leaves(h_ligand)
            ]
            # check all possible reference frames where the ligand could be
            for r in itertools.chain(docked_refs1, docked_refs2):
                rb_lig.set_reference_frame(r)
                docked_coords = [
                    core.XYZ(l).get_coordinates()
                    for l in atom.get_leaves(h_ligand)
                ]
                rmsd = alg.get_rmsd(current_coords, docked_coords)
                if rmsd < 0.1:
                    found = True
            self.assertTrue(found,
                            msg="the proposed move is not "
                            "in the relative solutions")
            mv.accept()
Beispiel #59
0
 def create_particle(self, m):
     p = IMP.kernel.Particle(m)
     p.add_attribute(IMP.FloatKey("thekey"), float(1))
     return p
Beispiel #60
0
 def assertRaisesInternalException(self, c, *args, **keys):
     """Assert that the given callable object raises InternalException.
        This differs from unittest's assertRaises in that the test
        is skipped in fast mode (where internal checks are turned off)."""
     if IMP.get_check_level() >= IMP.USAGE_AND_INTERNAL:
         return self.assertRaises(IMP.InternalException, c, *args, **keys)