Ejemplo n.º 1
0
    def test_xlinks(self):
        """
        Test the Xlinks class
        """
        for p in self.pairs:
            xlist = self.xlinks.get_xlinks_for_pair(p)
            # build manually the list that xlist should build
            manual_xlist = []
            xl = None
            for c in self.crosslinks:
                if p == (c[0], c[3]) or p == (c[3], c[0]):
                    xl = bx.Xlink(*c)
                    if p == (c[3], c[0]):
                        xl.swap()
                    manual_xlist.append(xl)
            # check the number of crosslinks for the pair
            self.assertEqual(len(manual_xlist), len(xlist))
            # check amino acids and distances
            aa = [(xl.first_residue, xl.second_residue, xl.distance)
                  for xl in xlist]
            ll = [(xl.first_residue, xl.second_residue, xl.distance)
                  for xl in manual_xlist]
            for x in ll:
                self.assertTrue(x in aa)

        xlistDE = self.xlinks.get_xlinks_for_pair(("subunitD", "subunitE"))
        xlistED = self.xlinks.get_xlinks_for_pair(("subunitE", "subunitD"))
        self.assertEqual(len(xlistDE), 4)
        self.assertEqual(len(xlistED), 4)
        for y, x in zip(xlistDE, xlistED):
            self.assertEqual(x.first_residue, y.second_residue)
            self.assertEqual(y.first_residue, x.second_residue)
            self.assertEqual(x.distance, y.distance)
Ejemplo n.º 2
0
    def setUp(self):
        IMP.test.TestCase.setUp(self)
        if bx is None:
            self.skipTest(bxerr)
        self.crosslinks = [
            ("subunitA", "A", 1, "subunitB", "B", 1, 10),
            ("subunitA", "A", 2, "subunitB", "B", 2, 20),
            ("subunitB", "B", 3, "subunitA", "A", 3, 30),
            ("subunitB", "B", 4, "subunitC", "C", 1, 40),
            ("subunitB", "B", 5, "subunitC", "C", 2, 20),
            ("subunitD", "D", 6, "subunitC", "C", 1, 10),
            ("subunitC", "C", 3, "subunitD", "D", 2, 70),
            ("subunitC", "C", 4, "subunitD", "D", 3, 80),
            ("subunitD", "D", 4, "subunitE", "E", 1, 10),
            ("subunitE", "E", 5, "subunitD", "D", 2, 30),
            ("subunitD", "D", 6, "subunitE", "E", 3, 40),
            ("subunitD", "D", 7, "subunitE", "E", 4, 50),
        ]

        # get different pairs of subunits
        self.xlinks = bx.XlinksDict()
        for c in self.crosslinks:
            x = bx.Xlink(*c)
            self.xlinks.add(x)
        self.pairs = set()
        for c in self.crosslinks:
            self.pairs.add((c[0], c[3]))
Ejemplo n.º 3
0
 def set_xlink_restraint(self, id1, chain1, residue1, id2, chain2, residue2,
                         distance, weight, stddev, max_score=False):
     """
         Set a restraint on the maximum distance between 2 residues
         @param id1 Name of the first component
         @param chain1
         @param residue1 Residue number for the aminoacid in the first
             component.The number is the number in the PDB file, not the
             number relative to the beginning of the chain
         @param id2 Name of the second component
         @param chain2
         @param residue2 Residue number for the aminoacid in the second
           component.
         @param distance Maximum distance tolerated
         @param weight Weight of the restraint
         @param stddev Standard deviation used to approximate the
             HarmonicUpperBound function to a Gaussian
         @param max_score See help for add_restraint(). If none is given,
         the maximum score is set to allow a maximum distance of 10 Angstrom
         greater than the parameter "distance".
     """
     xlink = buildxlinks.Xlink(
         id1,
         chain1,
         residue1,
         id2,
         chain2,
         residue2,
         distance)
     log.info("Setting cross-linking restraint ")
     log.info("%s", xlink.show())
     self.xlinks_dict.add(xlink)
     # setup restraint
     A = representation.get_component(self.assembly, xlink.first_id)
     s1 = IMP.atom.Selection(A, chain=xlink.first_chain,
                             residue_index=xlink.first_residue)
     p1 = s1.get_selected_particles()[0]
     B = representation.get_component(self.assembly, xlink.second_id)
     s2 = IMP.atom.Selection(B, chain=xlink.second_chain,
                             residue_index=xlink.second_residue)
     p2 = s2.get_selected_particles()[0]
     k = core.Harmonic.get_k_from_standard_deviation(stddev)
     score = core.HarmonicUpperBound(xlink.distance, k)
     pair_score = IMP.core.DistancePairScore(score)
     r = IMP.core.PairRestraint(pair_score, IMP.ParticlePair(p1, p2))
     if not max_score:
         error_distance_allowed = 100
         max_score = weight * \
             score.evaluate(distance + error_distance_allowed)
     log.info("%s, max_score %s", xlink.show(), max_score)
     self.add_restraint(r, xlink.get_name(), weight, max_score)
Ejemplo n.º 4
0
    def test_filter_transformations(self):
        """
            Check if the filtered conformation are the conformations that I
            computed before
        """
        try:
            import subprocess
            import IMP.EMageFit.buildxlinks as bx
        except ImportError as e:
            self.skipTest(str(e))

        dock = self.import_python_application('emagefit_dock')
        sel = atom.NonWaterNonHydrogenPDBSelector()
        ligand = IMP.kernel.Model()
        fn_ligand = self.get_input_file_name("3sfdB-3sfdA_initial_docking.pdb")
        h_ligand = atom.read_pdb(fn_ligand, ligand, sel)
        rb_ligand = atom.create_rigid_body(h_ligand)
        receptor = IMP.kernel.Model()
        fn_receptor = self.get_input_file_name("3sfdB.pdb")
        h_receptor = atom.read_pdb(fn_receptor, receptor, sel)
        # read_hex_transformations
        fn = self.get_input_file_name("hex_solutions_3sfdB-3sfdA.txt")
        residue_receptor = 23
        residue_ligand = 456
        distance = 30
        xl = bx.Xlink("3sfdB", "B", residue_receptor, "3sfdA", "A",
                      residue_ligand, distance)

        xlinks_list = [xl]
        fn_filtered = "filtered_transforms.txt"
        dock.filter_docking_results(h_receptor, h_ligand, xlinks_list, fn,
                                    fn_filtered)
        fn_stored = self.get_input_file_name(
            "hex_solutions_3sfdB-3sfdA_filtered.txt")
        filtered = dock.read_hex_transforms(fn_filtered)
        stored = dock.read_hex_transforms(fn_stored)
        # check that the filtered transforms match the stored ones
        self.assertEqual(len(filtered), len(stored))
        for Tf, Ts in zip(filtered, stored):
            tf = Tf.get_translation()
            ts = Ts.get_translation()
            qf = Tf.get_rotation().get_quaternion()
            qs = Ts.get_rotation().get_quaternion()
            for k in range(3):
                self.assertAlmostEqual(tf[k], ts[k])
            for k in range(4):
                self.assertAlmostEqual(qf[k], qs[k])
        os.remove(fn_filtered)
Ejemplo n.º 5
0
    def setUp(self):

        IMP.test.TestCase.setUp(self)
        if bx is None:
            self.skipTest(bxerr)
        self.max_distance = 30
        self.crosslinks = [
            ("3sfdB", "B", 23, "3sfdA", "A", 456, self.max_distance),
            ("3sfdB", "B", 241, "3sfdC", "C", 112, self.max_distance),
            ("3sfdB", "B", 205, "3sfdD", "D", 37, self.max_distance),
            ("3sfdB", "B", 177, "3sfdD", "D", 99, self.max_distance),
            ("3sfdC", "C", 9, "3sfdD", "D", 37, self.max_distance),
            ("3sfdC", "C", 78, "3sfdD", "D", 128, self.max_distance),
        ]
        self.xlinks = bx.XlinksDict()
        for c in self.crosslinks:
            self.xlinks.add(bx.Xlink(*c))
Ejemplo n.º 6
0
    def test_build_order(self):
        """
            Test the order recommendation for the xlinks
        """
        # Note that we don't use the same crosslinks here as the other tests,
        # because the order recommendation doesn't take account of multiple
        # crosslinks between a given pair of subunits.
        crosslinks = [
            ("subunitA", "A", 1, "subunitB", "B", 1, 10),
            ("subunitA", "A", 1, "subunitC", "B", 1, 10),
            ("subunitA", "A", 1, "subunitD", "B", 1, 10),
            ("subunitA", "A", 1, "subunitE", "B", 1, 10),
            ("subunitA", "A", 1, "subunitF", "B", 1, 10),
            ("subunitC", "A", 1, "subunitE", "B", 1, 10),
            ("subunitC", "A", 1, "subunitD", "B", 1, 10),
            ("subunitB", "A", 1, "subunitF", "B", 1, 10),
        ]
        xlinks = bx.XlinksDict()
        for c in crosslinks:
            xlinks.add(bx.Xlink(*c))

        dock_order = bx.DockOrder()
        dock_order.set_xlinks(xlinks)
        docking_pairs = dock_order.get_docking_order()
        # Optimal order should be:
        # - First, pick the most linked subunit (A) and dock everything
        #   that's linked to it (in any order)
        # - Repeat with the remaining subunits in order of most links (C, B)
        optimal_order = [('subunitA', 'subunitB'), ('subunitA', 'subunitC'),
                         ('subunitA', 'subunitD'), ('subunitA', 'subunitE'),
                         ('subunitA', 'subunitF'), ('subunitC', 'subunitD'),
                         ('subunitC', 'subunitE'), ('subunitF', 'subunitB')]
        docking_pairs = sorted(docking_pairs[:5]) + sorted(docking_pairs[5:7]) \
                        + [docking_pairs[7]]
        for p, q in zip(docking_pairs, optimal_order):
            self.assertEqual(p, q)