Пример #1
0
 def _make_stuff(self):
     m = IMP.Model()
     rs = IMP.RestraintSet(m, .5, "RS")
     r0 = IMP._ConstRestraint(m, [], 1)
     rs.add_restraint(r0)
     r1 = IMP._ConstRestraint(m, [], 1)
     rs.add_restraint(r1)
     r2 = IMP._ConstRestraint(m, [], 1)
     return (m, rs, r0, r1, r2)
 def _make_stuff(self):
     m= IMP.Model()
     rs= IMP.RestraintSet(.5)
     r0= IMP._ConstRestraint(1)
     rs.add_restraint(r0)
     m.add_restraint(rs)
     r1= IMP._ConstRestraint(1)
     rs.add_restraint(r1)
     r2= IMP._ConstRestraint(1)
     m.add_restraint(r2)
     return (m, rs, r0, r1, r2)
Пример #3
0
    def test_add_restraint(self):
        """Test add_restraint_to_model()"""
        m = IMP.Model()

        r1 = IMP._ConstRestraint(m, [], 1)
        IMP.pmi.tools.add_restraint_to_model(m, r1, add_to_rmf=False)
        r2 = IMP._ConstRestraint(m, [], 1)
        IMP.pmi.tools.add_restraint_to_model(m, r2, add_to_rmf=True)

        rs = IMP.pmi.tools.get_restraint_set(m, rmf=False)
        self.assertEqual(rs.get_number_of_restraints(), 2)

        rs = IMP.pmi.tools.get_restraint_set(m, rmf=True)
        self.assertEqual(rs.get_number_of_restraints(), 1)
Пример #4
0
    def test_add_restraint(self):
        """Test add_restraint_to_model()"""
        m = IMP.Model()

        r1 = IMP._ConstRestraint(m, [], 1)
        IMP.pmi.tools.add_restraint_to_model(m, r1, add_to_rmf=False)
        r2 = IMP._ConstRestraint(m, [], 1)
        IMP.pmi.tools.add_restraint_to_model(m, r2, add_to_rmf=True)

        rs = IMP.pmi.tools.get_restraint_set(m, rmf=False)
        self.assertEqual(rs.get_number_of_restraints(), 2)

        rs = IMP.pmi.tools.get_restraint_set(m, rmf=True)
        self.assertEqual(rs.get_number_of_restraints(), 1)
Пример #5
0
 def test_model_objects(self):
     """Test that model objects can get passed from python"""
     m = IMP.Model("model objets")
     r = IMP._ConstRestraint(m, [], 1)
     p = IMP.Particle(m)
     self.assertEqual([p], IMP._pass_model_objects([p]))
     self.assertEqual([r, p], IMP._pass_model_objects([r, p]))
Пример #6
0
 def test_score_state_show(self):
     """Test scoring function linkage"""
     m = IMP.Model("scoring function linkage")
     ps = [IMP.Particle(m) for i in range(0, 10)]
     r = IMP._ConstRestraint(1, ps)
     r.create_scoring_function()
     self.assertEqual(r.evaluate(False), 1)
Пример #7
0
    def test_global_min3(self):
        """Test sampling with edge scores"""
        m= IMP.Model()
        m.set_log_level(IMP.SILENT)
        ps=[]
        for i in range(0,3):
            p= IMP.Particle(m)
            d= IMP.core.XYZ.setup_particle(p)
            ps.append(p)
        pts=[IMP.algebra.Vector3D(0,0,0),
             IMP.algebra.Vector3D(1,0,0),
             IMP.algebra.Vector3D(2,0,0),
             IMP.algebra.Vector3D(3,0,0)]
        particle_state= IMP.domino.XYZStates(pts)
        pst= IMP.domino.ParticleStatesTable()
        for p in ps:
            pst.set_particle_states(p, particle_state)
            m.add_restraint(IMP._ConstRestraint(1, [p]))
        m.add_restraint(IMP.core.DistanceRestraint(IMP.core.Harmonic(1,1), ps[0], ps[1]))
        m.add_restraint(IMP.core.DistanceRestraint(IMP.core.Harmonic(1,1), ps[1], ps[2]))

        m.set_maximum_score(3.1)
        sampler= IMP.domino.DominoSampler(m, pst)
        sampler.set_log_level(IMP.VERBOSE)
        cs= sampler.get_sample()
        self.assertGreater(cs.get_number_of_configurations(), 0)
        for i in range(0, cs.get_number_of_configurations()):
            cs.load_configuration(i)
            self.assertLess((IMP.core.get_distance(IMP.core.XYZ(ps[0]),IMP.core.XYZ(ps[1]))-1)**2, .1)
            self.assertLess((IMP.core.get_distance(IMP.core.XYZ(ps[1]),IMP.core.XYZ(ps[2]))-1)**2, .1)
Пример #8
0
    def setup(self):
        """Build a set of test particles"""
        IMP.test.TestCase.setUp(self)

        model = IMP.Model("particles model")
        particles = []

        # create particles 0 - 11
        for i in range(0, 12):
            particles.append(
                self.create_point_particle(model, i * 2, i * 3, i * 4))
            p1 = particles[i]
            p1.add_attribute(radkey, 1.5 * i, False)
            p1.add_attribute(idkey, i)
            p1.add_attribute(IMP.IntKey("six"), 6)
            p1.add_attribute(IMP.StringKey("id_str"), "name_" + str(i))
            p1.add_attribute(IMP.StringKey("six"), "b:0110")

        # add additional attributes to particle 11
        for i in range(0, 6):
            p1.add_attribute(IMP.FloatKey("attr_" + str(i)), 3.5 * i, False)
        # clear derivatives
        print(model.get_ref_count())
        r = IMP._ConstRestraint(1, particles)
        r.evaluate(True)
        print(model.get_ref_count())
        return (model, particles)
Пример #9
0
 def test_model_objects(self):
     """Test that model objects can get passed from python"""
     m = IMP.Model("model objets")
     r = IMP._ConstRestraint(m, [], 1)
     p = IMP.Particle(m)
     self.assertEqual([p], IMP._pass_model_objects([p]))
     self.assertEqual([r, p], IMP._pass_model_objects([r, p]))
Пример #10
0
    def setup(self):
        """Build a set of test particles"""
        IMP.test.TestCase.setUp(self)

        model = IMP.Model("particles model")
        particles = []

        # create particles 0 - 11
        for i in range(0, 12):
            particles.append(self.create_point_particle(model,
                                                        i * 2, i * 3, i * 4))
            p1 = particles[i]
            p1.add_attribute(radkey, 1.5 * i, False)
            p1.add_attribute(idkey, i)
            p1.add_attribute(IMP.IntKey("six"), 6)
            p1.add_attribute(IMP.StringKey("id_str"), "name_" + str(i))
            p1.add_attribute(IMP.StringKey("six"), "b:0110")

        # add additional attributes to particle 11
        for i in range(0, 6):
            p1.add_attribute(IMP.FloatKey("attr_" + str(i)), 3.5 * i, False)
        # clear derivatives
        print(model.get_ref_count())
        r = IMP._ConstRestraint(1, particles)
        r.evaluate(True)
        print(model.get_ref_count())
        return (model, particles)
Пример #11
0
 def test_score_state_show(self):
     """Test scoring function linkage"""
     m = IMP.Model("scoring function linkage")
     ps = [IMP.Particle(m) for i in range(0, 10)]
     r = IMP._ConstRestraint(1, ps)
     r.create_scoring_function()
     self.assertEqual(r.evaluate(False), 1)
Пример #12
0
 def test_restraint_score(self):
     """Test restraint score log"""
     m = IMP.Model()
     r0 = IMP._ConstRestraint(m, [], 1)
     r0.set_name("r0")
     r1 = IMP._ConstRestraint(m, [], 2)
     r1.set_name("r1")
     sf = IMP.core.RestraintsScoringFunction([r0, r1])
     nm = self.get_tmp_file_name("score_log.csv")
     l = IMP.core.WriteRestraintScoresOptimizerState([r0, r1], nm)
     sf.evaluate(True)
     l.update()
     l.update()
     l.update()
     del l
     txt = open(nm, "r").read()
     print(txt)
Пример #13
0
 def test_restraint_score(self):
     """Test restraint score log"""
     m = IMP.Model()
     r0 = IMP._ConstRestraint(m, [], 1)
     r0.set_name("r0")
     r1 = IMP._ConstRestraint(m, [], 2)
     r1.set_name("r1")
     sf = IMP.core.RestraintsScoringFunction([r0, r1])
     nm = self.get_tmp_file_name("score_log.csv")
     l = IMP.core.WriteRestraintScoresOptimizerState([r0, r1], nm)
     sf.evaluate(True)
     l.update()
     l.update()
     l.update()
     del l
     txt = open(nm, "r").read()
     print(txt)
Пример #14
0
 def test_delete_model_accessor_restraint(self):
     "Python restraints from vector accessors should survive model deletion"
     IMP.set_log_level(IMP.MEMORY)
     refcnt = IMP.test.RefCountChecker(self)
     m = IMP.Model("test model")
     rs = IMP.RestraintSet(m)
     r = IMP._ConstRestraint(m, [], 1)
     print("adding")
     rs.add_restraint(r)
     print(r)
     print(r.__del__)
     # 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 restraints")
     ps = rs.get_restraints()
     print("getting restraint")
     p = ps[0]
     print(sys.getrefcount(p), len(ps))
     print(p)
     # r, m, p/ps
     self.assertEqual(p.get_ref_count(), 3)
     print("deleting ps")
     del ps
     # r, m, p
     self.assertEqual(p.get_ref_count(), 3)
     print("getting it again")
     rp = rs.get_restraint(0)
     print("check")
     # Python reference p, m, r, rp
     self.assertEqual(p.get_ref_count(), 4)
     print(p)
     print(p.thisown)
     print(dir(p))
     print(sys.getrefcount(p))
     print("deleting p")
     #del p
     # p.__del__
     print(p.__del__)
     del p
     # Python reference m, r, rp
     print("checking p")
     self.assertEqual(r.get_ref_count(), 3)
     print('deleting rp')
     del rp
     # Python reference m, r
     self.assertEqual(r.get_ref_count(), 2)
     print("deleting model")
     del m, rs
     refcnt.assert_number(1)
     # Now only the Python reference p should survive
     self.assertEqual(r.get_ref_count(), 1)
     print('deleting r')
     print(r)
     del r
     refcnt.assert_number(0)
Пример #15
0
 def test_delete_model_accessor_restraint(self):
     "Python restraints from vector accessors should survive model deletion"
     IMP.set_log_level(IMP.MEMORY)
     refcnt = IMP.test.RefCountChecker(self)
     m = IMP.Model("test model")
     rs = IMP.RestraintSet(m)
     r = IMP._ConstRestraint(m, [], 1)
     print("adding")
     rs.add_restraint(r)
     print(r)
     print(r.__del__)
     # 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 restraints")
     ps = rs.get_restraints()
     print("getting restraint")
     p = ps[0]
     print(sys.getrefcount(p), len(ps))
     print(p)
     # r, m, p/ps
     self.assertEqual(p.get_ref_count(), 3)
     print("deleting ps")
     del ps
     # r, m, p
     self.assertEqual(p.get_ref_count(), 3)
     print("getting it again")
     rp = rs.get_restraint(0)
     print("check")
     # Python reference p, m, r, rp
     self.assertEqual(p.get_ref_count(), 4)
     print(p)
     print(p.thisown)
     print(dir(p))
     print(sys.getrefcount(p))
     print("deleting p")
     #del p
     # p.__del__
     print(p.__del__)
     del p
     # Python reference m, r, rp
     print("checking p")
     self.assertEqual(r.get_ref_count(), 3)
     print('deleting rp')
     del rp
     # Python reference m, r
     self.assertEqual(r.get_ref_count(), 2)
     print("deleting model")
     del m, rs
     refcnt.assert_number(1)
     # Now only the Python reference p should survive
     self.assertEqual(r.get_ref_count(), 1)
     print('deleting r')
     print(r)
     del r
     refcnt.assert_number(0)
Пример #16
0
 def test_restraint_score(self):
     """Test restraint score log"""
     m = IMP.Model()
     r0 = IMP._ConstRestraint(1)
     r0.set_name("r0")
     r1 = IMP._ConstRestraint(2)
     r1.set_name("r1")
     m.add_restraint(r0)
     m.add_restraint(r1)
     nm = self.get_tmp_file_name("score_log.csv")
     l = IMP.core.WriteRestraintScoresOptimizerState([r0, r1], nm)
     m.evaluate(True)
     l.update()
     l.update()
     l.update()
     del l
     txt = open(nm, "r").read()
     print txt
Пример #17
0
 def test_cast(self):
     """Test that casting objects works"""
     m = IMP.Model("object cast")
     r = IMP._ConstRestraint(1)
     m.add_restraint(r)
     rb = m.get_restraints()[0]
     # print rb.get_value()
     rc = IMP._ConstRestraint.get_from(rb)
     print rc.get_value()
Пример #18
0
 def test_overload(self):
     """Checking that overloading works"""
     m = IMP.Model("overloading")
     p = IMP.Particle(m)
     r = IMP._ConstRestraint(m, [], 1)
     pi = IMP._test_overload([p])
     ri = IMP._test_overload([r])
     self.assertEqual(pi, 0)
     self.assertEqual(ri, 1)
Пример #19
0
 def test_printing(self):
     """Test ref counting works with restraints and scoring functions"""
     m = IMP.Model()
     # make sure that sf keeps the restraint alive
     sf = IMP._ConstRestraint(m, [], 1).create_scoring_function()
     IMP.set_log_level(IMP.MEMORY)
     # trigger cleanup
     m.update()
     sf.evaluate(False)
Пример #20
0
 def test_overload(self):
     """Checking that overloading works"""
     m = IMP.Model("overloading")
     p = IMP.Particle(m)
     r = IMP._ConstRestraint(m, [], 1)
     pi = IMP._test_overload([p])
     ri = IMP._test_overload([r])
     self.assertEqual(pi, 0)
     self.assertEqual(ri, 1)
Пример #21
0
 def test_restraint_cast(self):
     """Test that restraints can be cast"""
     m = IMP.Model("model objets")
     rs = IMP.RestraintSet(m)
     r = IMP._ConstRestraint(m, [], 1)
     rs.add_restraint(r)
     rb = rs.get_restraint(0)
     rbc = IMP._ConstRestraint.get_from(rb)
     self.assertEqual(rbc, rb)
Пример #22
0
 def test_restraint_cast(self):
     """Test that restraints can be cast"""
     m = IMP.Model("model objets")
     rs = IMP.RestraintSet(m)
     r = IMP._ConstRestraint(m, [], 1)
     rs.add_restraint(r)
     rb = rs.get_restraint(0)
     rbc = IMP._ConstRestraint.get_from(rb)
     self.assertEqual(rbc, rb)
Пример #23
0
 def test_printing(self):
     """Test ref counting works with restraints and scoring functions"""
     m = IMP.Model()
     # make sure that sf keeps the restraint alive
     sf = IMP._ConstRestraint(m, [], 1).create_scoring_function()
     IMP.set_log_level(IMP.MEMORY)
     # trigger cleanup
     m.update()
     sf.evaluate(False)
Пример #24
0
 def test_cast(self):
     """Test that casting objects works"""
     m = IMP.Model("object cast")
     rs = IMP.RestraintSet(m)
     r = IMP._ConstRestraint(m, [], 1)
     rs.add_restraint(r)
     rb = rs.get_restraint(0)
     # print rb.get_value()
     rc = IMP._ConstRestraint.get_from(rb)
     print(rc.get_value())
Пример #25
0
 def test_cast(self):
     """Test that casting objects works"""
     m = IMP.Model("object cast")
     rs = IMP.RestraintSet(m)
     r = IMP._ConstRestraint(m, [], 1)
     rs.add_restraint(r)
     rb = rs.get_restraint(0)
     # print rb.get_value()
     rc = IMP._ConstRestraint.get_from(rb)
     print(rc.get_value())
Пример #26
0
    def test_symmetry(self):
        """Test the transform pair score basics"""
        IMP.set_log_level(IMP.VERBOSE)
        m = IMP.Model()
        p0 = m.add_particle("p0")
        d0 = IMP.core.XYZ.setup_particle(m, p0)
        p1 = m.add_particle("p1")
        d1 = IMP.core.XYZ.setup_particle(m, p1)
        t = IMP.algebra.Vector3D(0, 1, 0)
        tr = IMP.algebra.Transformation3D(
            IMP.algebra.get_identity_rotation_3d(),
            t)
        tps = IMP.core.TransformedDistancePairScore(
            IMP.core.Harmonic(0, 1), tr)
        tps.set_was_used(True)
        d0.set_coordinates(IMP.algebra.Vector3D(2, 3, 4))
        d1.set_coordinates(IMP.algebra.Vector3D(2, 2, 4))
        self.assertEqual(tps.evaluate_index(m, (p0, p1), None), 0)
        self.assertNotEqual(tps.evaluate_index(m, (p1, p0), None), 0)

        print("test rotation")
        rot = IMP.algebra.get_rotation_from_matrix(0, 0, -1,
                                                   0, 1, 0,
                                                   1, 0, 0)
        tr = IMP.algebra.Transformation3D(rot, t)
        tps.set_transformation(tr)
        d1.set_coordinates(IMP.algebra.Vector3D(4, 2, -2))
        self.assertAlmostEqual(tps.evaluate_index(m, (p0, p1), None),
                               0, delta=.01)
        self.assertNotEqual(tps.evaluate_index(m, (p1, p0), None), 0)
        t = IMP.algebra.Vector3D(0, 0, 0)
        rot = IMP.algebra.get_rotation_from_matrix(0, -1, 0,
                                                   1, 0, 0,
                                                   0, 0, 1)
        tps.set_transformation(IMP.algebra.Transformation3D(rot, t))
        d0.set_coordinates(IMP.algebra.Vector3D(0, 1, 0))
        d1.set_coordinates(IMP.algebra.Vector3D(1, 1, 0))
        # clear derivs
        print("test derivs")
        const_restraint = IMP._ConstRestraint(m, [p0, p1], 0)
        const_restraint.evaluate(True)
        tps.evaluate_index(m, (p0, p1), IMP.DerivativeAccumulator(1))
        print(d0.get_derivative(0))
        print(d0.get_derivative(1))
        print(d0.get_derivative(2))
        print(d1.get_derivative(0))
        print(d1.get_derivative(1))
        print(d1.get_derivative(2))
        self.assertGreater(d0.get_derivative(0), 0)
        self.assertAlmostEqual(d0.get_derivative(1), 0, delta=.1)
        self.assertAlmostEqual(d0.get_derivative(2), 0, delta=.1)
        self.assertGreater(d1.get_derivative(1), 0)
        self.assertAlmostEqual(d1.get_derivative(0), 0, delta=.1)
        self.assertAlmostEqual(d1.get_derivative(2), 0, delta=.1)
Пример #27
0
 def test_weights(self):
     """Test that restraints decompose ok"""
     m = IMP.Model()
     p = IMP.Particle(m)
     r = IMP._ConstRestraint(1, [p])
     rd = r.create_decomposition()
     self.assertEqual(r.evaluate(False), rd.evaluate(False))
     ra = IMP.get_restraints([r])
     rda = IMP.get_restraints([rd])
     sf = IMP.core.RestraintsScoringFunction(ra)
     sfda = IMP.core.RestraintsScoringFunction(rda)
     self.assertEqual(sf.evaluate(False), sfda.evaluate(False))
Пример #28
0
 def _create_stuff(self):
     m = IMP.Model()
     ps = [IMP.Particle(m) for i in range(0, 10)]
     r = IMP._ConstRestraint(1, ps)
     r.set_name("const restraint")
     pst = IMP.domino.ParticleStatesTable()
     ik = IMP.IntKey("key")
     for p in ps:
         p.add_attribute(ik, 0)
         pst.set_particle_states(p, IMP.domino.IndexStates(4, ik))
     cache = IMP.domino.RestraintCache(pst, 4)
     return (m, ps, r, pst, ik, cache)
Пример #29
0
 def _create_stuff(self):
     m = IMP.Model()
     ps = [IMP.Particle(m) for i in range(0, 10)]
     r = IMP._ConstRestraint(1, ps)
     r.set_name("const restraint")
     pst = IMP.domino.ParticleStatesTable()
     ik = IMP.IntKey("key")
     for p in ps:
         p.add_attribute(ik, 0)
         pst.set_particle_states(p, IMP.domino.IndexStates(4, ik))
     cache = IMP.domino.RestraintCache(pst, 4)
     return (m, ps, r, pst, ik, cache)
Пример #30
0
    def test_symmetry(self):
        """Test the transform pair score basics"""
        IMP.set_log_level(IMP.VERBOSE)
        m = IMP.Model()
        p0 = m.add_particle("p0")
        d0 = IMP.core.XYZ.setup_particle(m, p0)
        p1 = m.add_particle("p1")
        d1 = IMP.core.XYZ.setup_particle(m, p1)
        t = IMP.algebra.Vector3D(0, 1, 0)
        tr = IMP.algebra.Transformation3D(
            IMP.algebra.get_identity_rotation_3d(), t)
        tps = IMP.core.TransformedDistancePairScore(IMP.core.Harmonic(0, 1),
                                                    tr)
        tps.set_was_used(True)
        d0.set_coordinates(IMP.algebra.Vector3D(2, 3, 4))
        d1.set_coordinates(IMP.algebra.Vector3D(2, 2, 4))
        self.assertEqual(tps.evaluate_index(m, (p0, p1), None), 0)
        self.assertNotEqual(tps.evaluate_index(m, (p1, p0), None), 0)

        print("test rotation")
        rot = IMP.algebra.get_rotation_from_matrix(0, 0, -1, 0, 1, 0, 1, 0, 0)
        tr = IMP.algebra.Transformation3D(rot, t)
        tps.set_transformation(tr)
        d1.set_coordinates(IMP.algebra.Vector3D(4, 2, -2))
        self.assertAlmostEqual(tps.evaluate_index(m, (p0, p1), None),
                               0,
                               delta=.01)
        self.assertNotEqual(tps.evaluate_index(m, (p1, p0), None), 0)
        t = IMP.algebra.Vector3D(0, 0, 0)
        rot = IMP.algebra.get_rotation_from_matrix(0, -1, 0, 1, 0, 0, 0, 0, 1)
        tps.set_transformation(IMP.algebra.Transformation3D(rot, t))
        d0.set_coordinates(IMP.algebra.Vector3D(0, 1, 0))
        d1.set_coordinates(IMP.algebra.Vector3D(1, 1, 0))
        # clear derivs
        print("test derivs")
        const_restraint = IMP._ConstRestraint(m, [p0, p1], 0)
        const_restraint.evaluate(True)
        tps.evaluate_index(m, (p0, p1), IMP.DerivativeAccumulator(1))
        print(d0.get_derivative(0))
        print(d0.get_derivative(1))
        print(d0.get_derivative(2))
        print(d1.get_derivative(0))
        print(d1.get_derivative(1))
        print(d1.get_derivative(2))
        self.assertGreater(d0.get_derivative(0), 0)
        self.assertAlmostEqual(d0.get_derivative(1), 0, delta=.1)
        self.assertAlmostEqual(d0.get_derivative(2), 0, delta=.1)
        self.assertGreater(d1.get_derivative(1), 0)
        self.assertAlmostEqual(d1.get_derivative(0), 0, delta=.1)
        self.assertAlmostEqual(d1.get_derivative(2), 0, delta=.1)
Пример #31
0
 def test_reweighting(self):
     """Test scoring function reweighting"""
     m = IMP.Model("scoring function linkage")
     ps = [IMP.Particle(m) for i in range(0, 10)]
     r = IMP._ConstRestraint(1, ps)
     rs = IMP.RestraintSet(m, 1.0, "rs")
     rs.add_restraint(r)
     rsf = rs.create_scoring_function()
     self.assertEqual(rsf.evaluate(False), 1)
     r.set_weight(0)
     self.assertEqual(rsf.evaluate(False), 0)
     r.set_weight(1)
     rs.set_weight(0)
     self.assertEqual(rsf.evaluate(False), 0)
Пример #32
0
 def test_reweighting(self):
     """Test scoring function reweighting"""
     m = IMP.Model("scoring function linkage")
     ps = [IMP.Particle(m) for i in range(0, 10)]
     r = IMP._ConstRestraint(1, ps)
     rs = IMP.RestraintSet(m, 1.0, "rs")
     rs.add_restraint(r)
     rsf = rs.create_scoring_function()
     self.assertEqual(rsf.evaluate(False), 1)
     r.set_weight(0)
     self.assertEqual(rsf.evaluate(False), 0)
     r.set_weight(1)
     rs.set_weight(0)
     self.assertEqual(rsf.evaluate(False), 0)
Пример #33
0
 def test_global_min3(self):
     """Test caching sampling with edge scores"""
     m = IMP.Model()
     m.set_log_level(IMP.SILENT)
     ps = []
     ds = []
     for i in range(0, 3):
         p = IMP.Particle(m)
         d = IMP.core.XYZ.setup_particle(p)
         print(d)
         ds.append(d)
         ps.append(p)
     pts = [
         IMP.algebra.Vector3D(0, 0, 0),
         IMP.algebra.Vector3D(1, 0, 0),
         IMP.algebra.Vector3D(2, 0, 0),
         IMP.algebra.Vector3D(3, 0, 0)
     ]
     particle_state = IMP.domino.XYZStates(pts)
     pst = IMP.domino.ParticleStatesTable()
     r = IMP.RestraintSet(m)
     for p in ps:
         pst.set_particle_states(p, particle_state)
         r.add_restraint(IMP._ConstRestraint(1, [p]))
     sst = IMP.domino.BranchAndBoundAssignmentsTable(pst, [])
     r.add_restraint(
         IMP.core.DistanceRestraint(m, IMP.core.Harmonic(1, 1), ps[0],
                                    ps[1]))
     r.add_restraint(
         IMP.core.DistanceRestraint(m, IMP.core.Harmonic(1, 1), ps[1],
                                    ps[2]))
     #sevt= IMP.domino.ModelSubsetEvaluatorTable(m, pst)
     sampler = IMP.domino.DominoSampler(m, pst)
     sampler.set_restraints(r)
     # sampler.set_subset_evaluator_table(sevt);
     sampler.set_log_level(IMP.VERBOSE)
     # sampler.set_assignments_table(sst)
     r.set_maximum_score(3.1)
     print("getting sample")
     cs = sampler.create_sample()
     print("done")
     self.assertGreater(cs.get_number_of_configurations(), 0)
     for i in range(0, cs.get_number_of_configurations()):
         print("loading ", i)
         cs.load_configuration(i)
         print("testing")
         dist = IMP.core.get_distance(ds[0], ds[1])
         print(dist)
         self.assertLess((dist - 1)**2, .1)
         self.assertLess((IMP.core.get_distance(ds[1], ds[2]) - 1)**2, .1)
Пример #34
0
 def test_rot_nrb(self):
     """Check hidden rigid body correlation time"""
     print("TEST_ROT_NRB")
     m= IMP.Model()
     p= IMP.Particle(m, "rb")
     d=IMP.core.XYZR.setup_particle(p)
     d.set_radius(10)
     d.set_coordinates_are_optimized(True)
     rb= IMP.core.RigidBody.setup_particle(p, IMP.algebra.ReferenceFrame3D())
     for i in range(3):
         pc= IMP.Particle(m, str(i))
         d=IMP.core.XYZR.setup_particle(pc)
         d.set_radius(2)
         v= IMP.algebra.Vector3D(0,0,0)
         v[i]=5
         d.set_coordinates(v)
         rb.add_member(pc)
     # to make sure coordinates get updated
     cr= IMP._ConstRestraint(0, rb.get_rigid_members())
     sf = IMP.core.RestraintsScoringFunction([cr])
     dd= IMP.atom.RigidBodyDiffusion.setup_particle(p)
     nD=10.0*dd.get_rotational_diffusion_coefficient()
     dd.set_rotational_diffusion_coefficient(nD)
     dt=10000
     bd= IMP.atom.BrownianDynamics(m)
     bd.set_scoring_function(sf)
     bd.set_maximum_time_step(dt)
     os= IMP.npctransport.ChainStatisticsOptimizerState(rb.get_rigid_members())
     os.set_period(10)
     bd.add_optimizer_state(os)
     os2= IMP.npctransport.BodyStatisticsOptimizerState(p)
     os2.set_period(10)
     bd.add_optimizer_state(os2)
     IMP.set_log_level(IMP.SILENT)
     bd.set_log_level(IMP.SILENT)
     bd.optimize(5000)
     Dout= os.get_correlation_time()
     Dout2= os2.get_correlation_time()
     Din= dd.get_rotational_diffusion_coefficient()
     v=1.0/(2.0*Dout)
     print("Corr1, Corr2, rot_dif_coeff, v",  Dout, Dout2, Din, v)
     self.assertAlmostEqual(Dout, Dout2, delta=.1*Dout)
     dfs= os.get_local_diffusion_coefficients()
     print(dfs)
     for d in dfs:
         self.assertAlmostEqual(0, d, delta=.1)
Пример #35
0
 def test_global_min3(self):
     """Test caching sampling with edge scores"""
     m = IMP.Model()
     m.set_log_level(IMP.SILENT)
     ps = []
     ds = []
     for i in range(0, 3):
         p = IMP.Particle(m)
         d = IMP.core.XYZ.setup_particle(p)
         print(d)
         ds.append(d)
         ps.append(p)
     pts = [IMP.algebra.Vector3D(0, 0, 0),
            IMP.algebra.Vector3D(1, 0, 0),
            IMP.algebra.Vector3D(2, 0, 0),
            IMP.algebra.Vector3D(3, 0, 0)]
     particle_state = IMP.domino.XYZStates(pts)
     pst = IMP.domino.ParticleStatesTable()
     r = IMP.RestraintSet(m)
     for p in ps:
         pst.set_particle_states(p, particle_state)
         r.add_restraint(IMP._ConstRestraint(1, [p]))
     sst = IMP.domino.BranchAndBoundAssignmentsTable(pst, [])
     r.add_restraint(IMP.core.DistanceRestraint(m,
         IMP.core.Harmonic(1, 1), ps[0], ps[1]))
     r.add_restraint(IMP.core.DistanceRestraint(m,
         IMP.core.Harmonic(1, 1), ps[1], ps[2]))
     #sevt= IMP.domino.ModelSubsetEvaluatorTable(m, pst)
     sampler = IMP.domino.DominoSampler(m, pst)
     sampler.set_restraints(r)
     # sampler.set_subset_evaluator_table(sevt);
     sampler.set_log_level(IMP.VERBOSE)
     # sampler.set_assignments_table(sst)
     r.set_maximum_score(3.1)
     print("getting sample")
     cs = sampler.create_sample()
     print("done")
     self.assertGreater(cs.get_number_of_configurations(), 0)
     for i in range(0, cs.get_number_of_configurations()):
         print("loading ", i)
         cs.load_configuration(i)
         print("testing")
         dist = IMP.core.get_distance(ds[0], ds[1])
         print(dist)
         self.assertLess((dist - 1) ** 2, .1)
         self.assertLess((IMP.core.get_distance(ds[1], ds[2]) - 1) ** 2, .1)
Пример #36
0
 def test_simple_rest(self):
     """Check reference counting of restraints"""
     refcnt = IMP.test.RefCountChecker(self)
     m= IMP.Model("ref counted restraints")
     r= IMP._ConstRestraint(1)
     s= IMP.RestraintSet()
     m.add_restraint(s)
     m.add_restraint(r)
     s.add_restraint(r)
     m.evaluate(False)
     refcnt.assert_number(3)
     # Model should hold a ref to restraints, so nothing should be freed
     # until it is
     del r
     refcnt.assert_number(3)
     del s
     refcnt.assert_number(3)
     del m
     refcnt.assert_number(0)
Пример #37
0
 def test_delete_model_iterator(self):
     """Python Restraints from iterators should survive model deletion"""
     refcnt = IMP.test.RefCountChecker(self)
     m = IMP.Model("python restraint survival")
     rs = IMP.RestraintSet(m)
     r = IMP._ConstRestraint(m, [], 1)
     rs.add_restraint(r)
     del r
     # Now create new Python Restraint r from C++ iterator
     # This calls swig::from() internally, which is modified by template
     # specialization in our SWIG interface.
     r = rs.get_restraints()[0]
     # Python reference r plus C++ reference from m
     self.assertEqual(r.get_ref_count(), 2)
     del m, rs
     # Now only the Python reference r should survive
     self.assertEqual(r.get_ref_count(), 1)
     refcnt.assert_number(1)
     del r
     refcnt.assert_number(0)
Пример #38
0
 def test_delete_model_accessor_2(self):
     "Python Restraints from vector accessors should survive model deletion"
     refcnt = IMP.test.RefCountChecker(self)
     m = IMP.Model("restraint survival")
     rs = IMP.RestraintSet(m)
     r = IMP._ConstRestraint(m, [], 1)
     rs.add_restraint(r)
     del r
     # Now create new Python Restraint r from a C++ vector accessor
     # These accessors call specific methods in the SWIG wrapper which
     # are modified by typemaps in our interface.
     r = rs.get_restraints()[0]
     # Python reference r plus C++ reference from m
     self.assertEqual(r.get_ref_count(), 2)
     del m, rs
     # Now only the Python reference r should survive
     self.assertEqual(r.get_ref_count(), 1)
     refcnt.assert_number(1)
     del r
     refcnt.assert_number(0)
Пример #39
0
 def test_delete_model_iterator(self):
     """Python Restraints from iterators should survive model deletion"""
     refcnt = IMP.test.RefCountChecker(self)
     m = IMP.Model("python restraint survival")
     rs = IMP.RestraintSet(m)
     r = IMP._ConstRestraint(m, [], 1)
     rs.add_restraint(r)
     del r
     # Now create new Python Restraint r from C++ iterator
     # This calls swig::from() internally, which is modified by template
     # specialization in our SWIG interface.
     r = rs.get_restraints()[0]
     # Python reference r plus C++ reference from m
     self.assertEqual(r.get_ref_count(), 2)
     del m, rs
     # Now only the Python reference r should survive
     self.assertEqual(r.get_ref_count(), 1)
     refcnt.assert_number(1)
     del r
     refcnt.assert_number(0)
Пример #40
0
 def test_delete_model_accessor_2(self):
     "Python Restraints from vector accessors should survive model deletion"
     refcnt = IMP.test.RefCountChecker(self)
     m = IMP.Model("restraint survival")
     rs = IMP.RestraintSet(m)
     r = IMP._ConstRestraint(m, [], 1)
     rs.add_restraint(r)
     del r
     # Now create new Python Restraint r from a C++ vector accessor
     # These accessors call specific methods in the SWIG wrapper which
     # are modified by typemaps in our interface.
     r = rs.get_restraints()[0]
     # Python reference r plus C++ reference from m
     self.assertEqual(r.get_ref_count(), 2)
     del m, rs
     # Now only the Python reference r should survive
     self.assertEqual(r.get_ref_count(), 1)
     refcnt.assert_number(1)
     del r
     refcnt.assert_number(0)
Пример #41
0
 def test_decomposition_5(self):
     """Test cache with simple restraint"""
     (m, ps, r, pst, ik, cache) = self._create_stuff()
     rs = IMP.RestraintSet(m, 1.0, "outer")
     r = IMP._ConstRestraint(1, [ps[0]])
     r.set_name("const 2")
     rs.add_restraint(r)
     r.set_maximum_score(.5)
     cache.add_restraints([rs])
     print("info:")
     cache.show_restraint_information()
     subset = IMP.domino.Subset([ps[0]])
     rsb = cache.get_restraints(subset, [])
     self.assertEqual(len(rsb), 1)
     slc = cache.get_slice(rsb[0], subset)
     self.assertEqual(len(slc), 1)
     aslc = slc.get_sliced(IMP.domino.Assignment(range(len(ps))))
     self.assertEqual(len(aslc), 1)
     score = cache.get_score(rsb[0], aslc)
     print(score)
     self.assert_(score > 1000)
Пример #42
0
 def test_decomposition_5(self):
     """Test cache with simple restraint"""
     (m, ps, r, pst, ik, cache) = self._create_stuff()
     rs = IMP.RestraintSet(m, 1.0, "outer")
     r = IMP._ConstRestraint(1, [ps[0]])
     r.set_name("const 2")
     rs.add_restraint(r)
     r.set_maximum_score(.5)
     cache.add_restraints([rs])
     print("info:")
     cache.show_restraint_information()
     subset = IMP.domino.Subset([ps[0]])
     rsb = cache.get_restraints(subset, [])
     self.assertEqual(len(rsb), 1)
     slc = cache.get_slice(rsb[0], subset)
     self.assertEqual(len(slc), 1)
     aslc = slc.get_sliced(IMP.domino.Assignment(range(len(ps))))
     self.assertEqual(len(aslc), 1)
     score = cache.get_score(rsb[0], aslc)
     print(score)
     self.assert_(score > 1000)
Пример #43
0
    def test_global_min3(self):
        """Test sampling with edge scores"""
        m = IMP.Model()
        m.set_log_level(IMP.SILENT)
        ps = []
        for i in range(0, 3):
            p = IMP.Particle(m)
            d = IMP.core.XYZ.setup_particle(p)
            ps.append(p)
        pts = [
            IMP.algebra.Vector3D(0, 0, 0),
            IMP.algebra.Vector3D(1, 0, 0),
            IMP.algebra.Vector3D(2, 0, 0),
            IMP.algebra.Vector3D(3, 0, 0)
        ]
        particle_state = IMP.domino.XYZStates(pts)
        pst = IMP.domino.ParticleStatesTable()
        r = IMP.RestraintSet(m)
        for p in ps:
            pst.set_particle_states(p, particle_state)
            r.add_restraint(IMP._ConstRestraint(1, [p]))
        r.add_restraint(
            IMP.core.DistanceRestraint(m, IMP.core.Harmonic(1, 1), ps[0],
                                       ps[1]))
        r.add_restraint(
            IMP.core.DistanceRestraint(m, IMP.core.Harmonic(1, 1), ps[1],
                                       ps[2]))

        r.set_maximum_score(3.1)
        sampler = IMP.domino.DominoSampler(m, pst)
        sampler.set_restraints([r])
        sampler.set_log_level(IMP.VERBOSE)
        cs = sampler.create_sample()
        self.assertGreater(cs.get_number_of_configurations(), 0)
        for i in range(0, cs.get_number_of_configurations()):
            cs.load_configuration(i)
            self.assertLess((IMP.core.get_distance(IMP.core.XYZ(
                ps[0]), IMP.core.XYZ(ps[1])) - 1)**2, .1)
            self.assertLess((IMP.core.get_distance(IMP.core.XYZ(
                ps[1]), IMP.core.XYZ(ps[2])) - 1)**2, .1)
Пример #44
0
    def test_simple_rest(self):
        """Check reference counting of restraints"""
        refcnt = IMP.test.RefCountChecker(self)
        IMP.set_log_level(IMP.MEMORY)
        m = IMP.Model("M")
        r = IMP._ConstRestraint(m, [], 1)
        r.set_name("R")
        s = IMP.RestraintSet(m, 1.0, "S")
        s.add_restraint(r)
        """m.evaluate(False)
        refcnt.assert_number(3)
        # Model should hold a ref to restraints, so nothing should be freed
        # until it is
"""
        print(r.get_ref_count(), s.get_ref_count(), m.get_ref_count())
        del r
        refcnt.assert_number(4)
        print(s.get_ref_count(), m.get_ref_count())
        del s
        refcnt.assert_number(2)
        print(m.get_ref_count())
        del m
        print("check")
        refcnt.assert_number(0)
Пример #45
0
    def test_simple_rest(self):
        """Check reference counting of restraints"""
        refcnt = IMP.test.RefCountChecker(self)
        IMP.set_log_level(IMP.MEMORY)
        m = IMP.Model("M")
        r = IMP._ConstRestraint(m, [], 1)
        r.set_name("R")
        s = IMP.RestraintSet(m, 1.0, "S")
        s.add_restraint(r)
        """m.evaluate(False)
        refcnt.assert_number(3)
        # Model should hold a ref to restraints, so nothing should be freed
        # until it is
"""
        print(r.get_ref_count(), s.get_ref_count(), m.get_ref_count())
        del r
        refcnt.assert_number(3)
        print(s.get_ref_count(), m.get_ref_count())
        del s
        refcnt.assert_number(1)
        print(m.get_ref_count())
        del m
        print("check")
        refcnt.assert_number(0)
Пример #46
0
    """An optimizer state which prints out the last scores of some restraints"""

    def __init__(self, rs):
        IMP.OptimizerState.__init__(self, rs[0].get_model(),
                                    "MyOptimizerState%1%")
        self.rs = rs

    def update(self):
        for r in self.rs:
            print(r.get_name(), r.get_last_score())

# some code to create and evaluate it
k = IMP.FloatKey("a key")
m = IMP.Model()
# we don't have any real restraints in the kernel
r0 = IMP._ConstRestraint(m, [], 1)
r0.set_name("restraint 0")

r1 = IMP._ConstRestraint(m, [], 2)
r1.set_name("restraint 1")

rs = IMP.RestraintSet([r0, r1], 1.0)
sf = rs.create_scoring_function()

os = MyOptimizerState([r0, r1])
os.set_name("python optimizer state")
# we don't have any optimizers either
co = IMP._ConstOptimizer(m)
co.set_scoring_function(sf)
co.add_optimizer_state(os)
print(co.optimize(100))
Пример #47
0
class MyOptimizerState(IMP.OptimizerState):

    def __init__(self, rs):
        IMP.OptimizerState.__init__(self, rs[0].get_model(),
                                    "MyOptimizerState%1%")
        self.rs = rs

    def update(self):
        for r in self.rs:
            print(r.get_name(), r.get_last_score())

# some code to create and evaluate it
k = IMP.FloatKey("a key")
m = IMP.Model()
# we don't have any real restraints in the kernel
r0 = IMP._ConstRestraint(m, [], 1)
r0.set_name("restraint 0")

r1 = IMP._ConstRestraint(m, [], 2)
r1.set_name("restraint 1")

rs = IMP.RestraintSet([r0, r1], 1.0)
sf = rs.create_scoring_function()

os = MyOptimizerState([r0, r1])
os.set_name("python optimizer state")
# we don't have any optimizers either
co = IMP._ConstOptimizer(m)
co.set_scoring_function(sf)
co.add_optimizer_state(os)
print(co.optimize(100))
import IMP

# an optimizer state which prints out model statistics.
class MyOptimizerState(IMP.OptimizerState):
    def __init__(self):
        IMP.OptimizerState.__init__(self)
    def update(self):
        self.get_optimizer().get_model().show_restraint_score_statistics()

# some code to create and evaluate it
k= IMP.FloatKey("a key")
m= IMP.Model()
# we don't have any real restraints in the kernel
r0=IMP._ConstRestraint(1)
r0.set_name("restraint 0")
m.add_restraint(r0)
r1=IMP._ConstRestraint(2)
r1.set_name("restraint 1")
m.add_restraint(r1)

os= MyOptimizerState()
os.set_name("python optimizer state")
# we don't have any optimizers either
co= IMP._ConstOptimizer(m)
co.add_optimizer_state(os)
m.set_gather_statistics(True)
# so we only see the statistics
IMP.set_log_level(IMP.SILENT)
print co.optimize(100)

# this is needed to clean up memory properly for some reason