def set_relative_movers(self, max_translation, max_rotation):
     """
         Generate the relative models form the transfors. The transforms
         is a list with triplets [id1, id2, transform_file]
         @param max_translation Maximum translation distance allowed for
             the moves
         @param nax_rotation Maximum rotation angle allowed for the moves
     """
     log.info("Setting relative movers")
     self.movers = []
     relative_movers = []
     relative_names = []
     for d in self.dock_transforms:
         rb_id = representation.get_rb_name(d[1])
         if rb_id not in relative_names:
             log.debug("Checking for %s", rb_id)
             rb_lig = representation.get_rigid_body(self.rbs, rb_id)
             mv = em2d.RelativePositionMover(rb_lig, max_translation,
                                                          max_rotation)
             relative_movers.append(mv)
             relative_names.append(rb_id)
             log.debug("added a RelativePositionMover for %s",rb_id)
         i = relative_names.index(rb_id)
         relative_movers[i].set_random_move_probability(
                                               self.non_relative_move_prob)
         rb_rec = representation.get_rigid_body(self.rbs,
                                      representation.get_rb_name(d[0]))
         log.debug("Reference added for %s: %s. ref. frame %s ",
                     rb_id, rb_rec.get_name(), rb_rec)
         Tis = io.read_transforms(d[2])
         relative_movers[i].add_internal_transformations(rb_rec, Tis)
     # add regular movers for the rigid bodies that are neither moved
     # anchored nor moved relative to others
     regular_movers = []
     for is_anchored, rb in zip(self.anchored, self.rbs):
         if(not is_anchored):
             name =rb.get_name()
             if(not name in relative_names):
                 log.debug("adding a RigidBodyMover for %s",name)
                 mv = core.RigidBodyMover(rb, max_translation, max_rotation)
                 regular_movers.append(mv)
     self.movers = regular_movers
     self.movers += relative_movers
Beispiel #2
0
 def set_not_optimized(self, name):
     """
         Set a part of the model as not optimized (it does not move during
         the model optimization)
         @param name of the component to optimized
     """
     if name not in self.names:
         raise ValueError("DominoModel: There is not component " \
                         "in the assembly with this name")
     rb_name = representation.get_rb_name(name)
     self.not_optimized_rbs.append(rb_name)
def create_dockings_from_xlinks(exp):
    """
        Perform dockings that satisfy the cross-linking restraints.
        1) Based on the number of restraints, creates an order for the
           docking between pairs of subunits, favouring the subunits with
           more crosslinks to be the "receptors"
        2) Moves the subunits that are going to be docked to a position that
           satisfies the x-linking restraints. There is no guarantee that this
           position is correct. Its purpose is to help the docking
           algorithm with a clue of the proximity/orientation between subunits
        3) Performs docking between the subunits
        4) Filters the results of the docking that are not consistent with
           the cross-linking restraints
        5) Computes the relative transformations between the rigid bodies
           of the subunits that have been docked
        @param exp Class with the parameters for the experiment
    """
    log.info("Creating initial assembly from xlinks and docking")
    import docking_related as dock
    import buildxlinks as bx
    m = DominoModel.DominoModel()
    m.set_assembly_components(exp.fn_pdbs, exp.names)
    set_xlink_restraints(exp, m)
    order = bx.DockOrder()
    order.set_xlinks(m.xlinks)
    docking_pairs = order.get_docking_order()

    if hasattr(exp, "have_hexdock"):
        if not exp.have_hexdock:
            return

    for rec, lig in docking_pairs:
        pair_xlinks = m.xlinks.get_xlinks_for_pair((rec,lig))
        log.debug("Xlinks for the pair %s %s %s",rec, lig, pair_xlinks)
        h_receptor = representation.get_component(m.assembly, rec)
        h_ligand = representation.get_component(m.assembly, lig)
        rb_receptor = representation.get_rigid_body(m.components_rbs,
                                         representation.get_rb_name(rec))
        rb_ligand = representation.get_rigid_body(m.components_rbs,
                                         representation.get_rb_name(lig))
        initial_ref = rb_ligand.get_reference_frame()
        # move to the initial docking position
        mv = bx.InitialDockingFromXlinks()
        mv.set_xlinks(pair_xlinks)
        mv.set_hierarchies(h_receptor, h_ligand)
        mv.set_rigid_bodies(rb_receptor, rb_ligand)
        mv.move_ligand()
        fn_initial_docking = "%s-%s_initial_docking.pdb" % (rec,lig)
        mv.write_ligand(fn_initial_docking)
        # dock
        hex_docking = dock.HexDocking()
        receptor_index = exp.names.index(rec)
        fn_transforms = "hex_solutions_%s-%s.txt" % (rec, lig)
        fn_docked = "%s-%s_hexdock.pdb" % (rec, lig)
        hex_docking.dock(exp.fn_pdbs[receptor_index],
                         fn_initial_docking, fn_transforms, fn_docked, False)

        sel = atom.ATOMPDBSelector()
        new_m = IMP.Model()
        # After reading the file with the initial solution, the reference frame
        # for the rigid body of the ligand is not necessarily the  same one
        # that it had when saved.
        # Thus reading the file again ensures  consisten results when
        # using the HEXDOCK transforms
        new_h_ligand =  atom.read_pdb(fn_initial_docking, new_m, sel)
        new_rb_ligand = atom.create_rigid_body(new_h_ligand)
        Tlig = new_rb_ligand.get_reference_frame().get_transformation_to()
        fn_filtered = "hex_solutions_%s-%s_filtered.txt" % (rec, lig)
        # h_ligand contains the coordinates of the ligand after moving it
        # to the initial position for the docking
        dock.filter_docking_results(h_receptor, new_h_ligand, pair_xlinks,
                                            fn_transforms, fn_filtered)
        # transforms to apply to the ligand as it is in the file
        # fn_initial_docking
        Thex = dock.read_hex_transforms(fn_filtered)
        Trec = rb_receptor.get_reference_frame().get_transformation_to()
        Tinternal = []
        for i,T in enumerate(Thex):
            Tdock = alg.compose(T, Tlig)
            ref = alg.ReferenceFrame3D(Tdock)
            new_rb_ligand.set_reference_frame(ref)
            # internal transformation. The relationship is Tdock = Trec * Ti
            Ti = alg.compose(Trec.get_inverse(), Tdock)
            Tinternal.append(Ti)
        fn_relative = "relative_positions_%s-%s.txt" % (rec, lig)
        io.write_transforms(Tinternal, fn_relative)
        rb_ligand.set_reference_frame(initial_ref)