示例#1
0
    def test_restraint_probability_complex(self):
        m = IMP.Model()
        rcomplex = self.init_representation_complex(m)
        xlc, cldb = self.setup_crosslinks_complex(rcomplex, "single_category")

        # check all internals didn't change since last time
        o = IMP.pmi.output.Output()
        o.write_test("expensive_test_new_cross_link_ms_restraint.dat", [xlc])

        passed = o.test(
            self.get_input_file_name(
                "expensive_test_new_cross_link_ms_restraint.dat"), [xlc])
        self.assertEqual(passed, True)
        rs = xlc.get_restraint()

        # check the probability of cross-links
        restraints = []
        for xl in xlc.xl_list:
            p0 = xl["Particle1"]
            p1 = xl["Particle2"]
            prob = xl["Restraint"].get_probability()
            resid1 = xl[cldb.residue1_key]
            chain1 = xl[cldb.protein1_key]
            resid2 = xl[cldb.residue2_key]
            chain2 = xl[cldb.protein2_key]
            d0 = IMP.core.XYZ(p0)
            d1 = IMP.core.XYZ(p1)
            sig1 = xl["Particle_sigma1"]
            sig2 = xl["Particle_sigma2"]
            psi = xl["Particle_psi"]
            d0 = IMP.core.XYZ(p0)
            d1 = IMP.core.XYZ(p1)
            dist = IMP.core.get_distance(d0, d1)

            test_prob = get_probability([d0], [d1], [sig1], [sig2], [psi],
                                        21.0, 0.0)
            restraints.append(xl["Restraint"])

            # check that the probability is the same for
            # each cross-link
            self.assertAlmostEqual(prob, test_prob, delta=0.00001)

        # check the log_wrapper
        log_wrapper_score = rs.unprotected_evaluate(None)
        test_log_wrapper_score = log_evaluate(restraints)
        self.assertAlmostEqual(log_wrapper_score,
                               test_log_wrapper_score,
                               delta=0.00001)
        for output in [
                'excluded.None.xl.db',
                'expensive_test_new_cross_link_ms_restraint.dat',
                'included.None.xl.db', 'missing.None.xl.db'
        ]:
            os.unlink(output)
示例#2
0
    def test_restraint_probability_complex(self):
        m = IMP.Model()
        rcomplex = self.init_representation_complex(m)
        xlc = setup_crosslinks_complex(rcomplex, "single_category")

        # check all internals didn't change since last time
        o = IMP.pmi.output.Output()
        o.write_test("expensive_test_cross_link_ms_restraint.dat", [xlc])

        passed = o.test(
            self.get_input_file_name(
                "expensive_test_cross_link_ms_restraint.dat"), [xlc])
        self.assertEqual(passed, True)
        rs = xlc.get_restraint()

        # check the probability of cross-links
        restraints = []
        for p in xlc.pairs:
            p0 = p[0]
            p1 = p[1]
            prob = p[2].get_probability()
            resid1 = p[3]
            chain1 = p[4]
            resid2 = p[5]
            chain2 = p[6]
            attribute = p[7]
            d0 = IMP.core.XYZ(p0)
            d1 = IMP.core.XYZ(p1)
            dist = IMP.core.get_distance(d0, d1)

            sig1 = xlc.get_sigma(p[8])[0]
            sig2 = xlc.get_sigma(p[9])[0]
            psi = xlc.get_psi(p[10])[0]
            test_prob = get_probability([d0], [d1], [sig1], [sig2], [psi],
                                        21.0, 0.0)
            restraints.append(p[2])

            # check that the probability is the same for
            # each cross-link
            self.assertAlmostEqual(prob, test_prob, delta=0.00001)

        # check the log_wrapper
        log_wrapper_score = rs.unprotected_evaluate(None)
        test_log_wrapper_score = log_evaluate(restraints)
        self.assertAlmostEqual(log_wrapper_score,
                               test_log_wrapper_score,
                               delta=0.00001)
        for output in [
                'excluded.None.xl.db',
                'expensive_test_cross_link_ms_restraint.dat',
                'included.None.xl.db', 'missing.None.xl.db'
        ]:
            os.unlink(output)
    def test_restraint_probability_complex(self):
        m = IMP.Model()
        rcomplex = self.init_representation_complex(m)
        xlc, cldb = self.setup_crosslinks_complex(rcomplex, "single_category")

        # check all internals didn't change since last time
        o = IMP.pmi.output.Output()
        o.write_test("expensive_test_new_cross_link_ms_restraint.dat", [xlc])

        passed = o.test(self.get_input_file_name("expensive_test_new_cross_link_ms_restraint.dat"), [xlc])
        self.assertEqual(passed, True)
        rs = xlc.get_restraint()

        # check the probability of cross-links
        restraints = []
        for xl in xlc.xl_list:
            p0 = xl["Particle1"]
            p1 = xl["Particle2"]
            prob = xl["Restraint"].get_probability()
            resid1 = xl[cldb.residue1_key]
            chain1 = xl[cldb.protein1_key]
            resid2 = xl[cldb.residue2_key]
            chain2 = xl[cldb.protein2_key]
            d0 = IMP.core.XYZ(p0)
            d1 = IMP.core.XYZ(p1)
            sig1 = xl["Particle_sigma1"]
            sig2 = xl["Particle_sigma2"]
            psi = xl["Particle_psi"]
            d0 = IMP.core.XYZ(p0)
            d1 = IMP.core.XYZ(p1)
            dist = IMP.core.get_distance(d0, d1)

            test_prob = get_probability([d0], [d1], [sig1], [sig2], [psi], 21.0, 0.0)
            restraints.append(xl["Restraint"])

            # check that the probability is the same for
            # each cross-link
            self.assertAlmostEqual(prob, test_prob, delta=0.00001)

        # check the log_wrapper
        log_wrapper_score = rs.unprotected_evaluate(None)
        test_log_wrapper_score = log_evaluate(restraints)
        self.assertAlmostEqual(log_wrapper_score, test_log_wrapper_score, delta=0.00001)
        for output in [
            "excluded.None.xl.db",
            "expensive_test_new_cross_link_ms_restraint.dat",
            "included.None.xl.db",
            "missing.None.xl.db",
        ]:
            os.unlink(output)
    def test_restraint_probability_complex(self):
        m = IMP.Model()
        rcomplex=self.init_representation_complex(m)
        xlc=setup_crosslinks_complex(rcomplex,"single_category")

        # check all internals didn't change since last time
        o=IMP.pmi.output.Output()
        o.write_test("expensive_test_cross_link_ms_restraint.dat", [xlc])

        passed=o.test(self.get_input_file_name("expensive_test_cross_link_ms_restraint.dat"), [xlc])
        self.assertEqual(passed, True)
        rs=xlc.get_restraint()

        # check the probability of cross-links
        restraints=[]
        for p in xlc.pairs:
            p0 = p[0]
            p1 = p[1]
            prob = p[2].get_probability()
            resid1 = p[3]
            chain1 = p[4]
            resid2 = p[5]
            chain2 = p[6]
            attribute = p[7]
            d0 = IMP.core.XYZ(p0)
            d1 = IMP.core.XYZ(p1)
            dist=IMP.core.get_distance(d0, d1)

            sig1 = xlc.get_sigma(p[8])[0]
            sig2 = xlc.get_sigma(p[9])[0]
            psi = xlc.get_psi(p[10])[0]
            test_prob=get_probability([d0],[d1],[sig1],[sig2],[psi],21.0,0.0)
            restraints.append(p[2])


            # check that the probability is the same for
            # each cross-link
            self.assertAlmostEqual(prob, test_prob, delta=0.00001)

        # check the log_wrapper
        log_wrapper_score=rs.unprotected_evaluate(None)
        test_log_wrapper_score=log_evaluate(restraints)
        self.assertAlmostEqual(log_wrapper_score, test_log_wrapper_score, delta=0.00001)
        for output in ['excluded.None.xl.db',
                       'expensive_test_cross_link_ms_restraint.dat',
                       'included.None.xl.db', 'missing.None.xl.db']:
            os.unlink(output)
示例#5
0
    def test_restraint_probability_complex(self):
        """Test restraint gets correct probabilities"""
        m = IMP.Model()
        rcomplex, dof = self.init_representation_complex_pmi2(m)
        xlc, cldb = self.setup_crosslinks_complex(root_hier=rcomplex,
                                                  mode="single_category")
        self.assertEqual(len(dof.get_movers()), 42)
        dof.get_nuisances_from_restraint(xlc)
        self.assertEqual(len(dof.get_movers()), 44)
        # check all internals didn't change since last time
        o = IMP.pmi.output.Output()
        o.write_test("expensive_test_new_cross_link_ms_restraint.dat", [xlc])

        passed = o.test(
            self.get_input_file_name(
                "expensive_test_new_cross_link_ms_restraint.dat"), [xlc])
        self.assertEqual(passed, True)
        rs = xlc.get_restraint()

        # check the probability of cross-links
        restraints = []
        for xl in xlc.xl_list:
            p0 = xl["Particle1"]
            p1 = xl["Particle2"]
            prob = xl["Restraint"].get_probability()
            resid1 = xl[cldb.residue1_key]
            chain1 = xl[cldb.protein1_key]
            resid2 = xl[cldb.residue2_key]
            chain2 = xl[cldb.protein2_key]
            d0 = IMP.core.XYZ(p0)
            d1 = IMP.core.XYZ(p1)
            sig1 = xl["Particle_sigma1"]
            sig2 = xl["Particle_sigma2"]
            psi = xl["Particle_psi"]
            d0 = IMP.core.XYZ(p0)
            d1 = IMP.core.XYZ(p1)
            dist = IMP.core.get_distance(d0, d1)

            test_prob = get_probability([d0], [d1], [sig1], [sig2], [psi],
                                        21.0, 0.0)
            restraints.append(xl["Restraint"])

            # check that the probability is the same for
            # each cross-link
            self.assertAlmostEqual(prob, test_prob, delta=0.00001)

        # check the log_wrapper
        log_wrapper_score = rs.unprotected_evaluate(None)
        test_log_wrapper_score = log_evaluate(restraints)
        self.assertAlmostEqual(log_wrapper_score,
                               test_log_wrapper_score,
                               delta=0.00001)
        rex = IMP.pmi.macros.ReplicaExchange0(
            m,
            root_hier=rcomplex,
            monte_carlo_sample_objects=dof.get_movers(),
            number_of_frames=2,
            test_mode=True,
            replica_exchange_object=rem)
        rex.execute_macro()
        for output in [
                'excluded.None.xl.db',
                'expensive_test_new_cross_link_ms_restraint.dat',
                'included.None.xl.db', 'missing.None.xl.db'
        ]:
            os.unlink(output)
    def test_restraint_probability_complex(self):
        """Test restraint gets correct probabilities"""
        for i in range(2):
            m = IMP.Model()
            print("Testing PMI version",i+1)
            if i==0:
                rcomplex = self.init_representation_complex(m)
                xlc,cldb = self.setup_crosslinks_complex(rcomplex,"single_category")
            else:
                rcomplex,dof=self.init_representation_complex_pmi2(m)
                xlc,cldb = self.setup_crosslinks_complex(root_hier=rcomplex,
                                                         mode="single_category")
                self.assertEqual(len(dof.get_movers()),42)
                dof.get_nuisances_from_restraint(xlc)
                self.assertEqual(len(dof.get_movers()),44)
            # check all internals didn't change since last time
            o=IMP.pmi.output.Output()
            o.write_test("expensive_test_new_cross_link_ms_restraint.dat", [xlc])

            passed=o.test(self.get_input_file_name("expensive_test_new_cross_link_ms_restraint.dat"),
                          [xlc])
            self.assertEqual(passed, True)
            rs = xlc.get_restraint()

            # check the probability of cross-links
            restraints=[]
            for xl in xlc.xl_list:
                p0 = xl["Particle1"]
                p1 = xl["Particle2"]
                prob = xl["Restraint"].get_probability()
                resid1 = xl[cldb.residue1_key]
                chain1 = xl[cldb.protein1_key]
                resid2 = xl[cldb.residue2_key]
                chain2 = xl[cldb.protein2_key]
                d0 = IMP.core.XYZ(p0)
                d1 = IMP.core.XYZ(p1)
                sig1 = xl["Particle_sigma1"]
                sig2 = xl["Particle_sigma2"]
                psi =  xl["Particle_psi"]
                d0 = IMP.core.XYZ(p0)
                d1 = IMP.core.XYZ(p1)
                dist=IMP.core.get_distance(d0, d1)

                test_prob=get_probability([d0],[d1],[sig1],[sig2],[psi],21.0,0.0)
                restraints.append(xl["Restraint"])

                # check that the probability is the same for
                # each cross-link
                self.assertAlmostEqual(prob, test_prob, delta=0.00001)

            # check the log_wrapper
            log_wrapper_score=rs.unprotected_evaluate(None)
            test_log_wrapper_score=log_evaluate(restraints)
            self.assertAlmostEqual(log_wrapper_score, test_log_wrapper_score, delta=0.00001)
            if i==0:
                rex0 = IMP.pmi.macros.ReplicaExchange0(m,
                                                       rcomplex,
                                                       monte_carlo_sample_objects=[rcomplex],
                                                       number_of_frames=2,
                                                       test_mode=True,
                                                       replica_exchange_object = rem)
                rex0.execute_macro()
            else:
                rex = IMP.pmi.macros.ReplicaExchange0(m,
                                                      root_hier=rcomplex,
                                                      monte_carlo_sample_objects=dof.get_movers(),
                                                      number_of_frames=2,
                                                      test_mode=True,
                                                      replica_exchange_object = rem)
                rex.execute_macro()
            for output in ['excluded.None.xl.db',
                           'expensive_test_new_cross_link_ms_restraint.dat',
                           'included.None.xl.db', 'missing.None.xl.db']:
                os.unlink(output)