Exemplo n.º 1
0
def get_reference_frames_from_chain_alignment(reference_rbs, reference_index,
                                              rbs_to_align, index_to_align):
    """
        Align the rigid bodies rbs_to_align to the the reference frames of
        reference_rbs. The rb with index_to_align is aligned to the reference rb
        with reference_index. The function returns the reference frames to
        apply to the rbs_to_align.
    """
    ref_coords = \
        [m.get_coordinates()
         for m in reference_rbs[reference_index].get_members()]
    coords = [m.get_coordinates()
              for m in rbs_to_align[index_to_align].get_members()]
    if(len(coords) != len(ref_coords)):
        raise ValueError(
            "Mismatch in the number of members. Reference %d Aligned %d " % (
                len(ref_coords), len(coords)))
    T = alg.get_transformation_aligning_first_to_second(coords, ref_coords)
    new_refs = []
    for rb in rbs_to_align:
#        log.debug("aligning ... %s",rb)
        t = rb.get_reference_frame().get_transformation_to()
        new_t = alg.compose(T, t)
        new_refs.append(alg.ReferenceFrame3D(new_t))
    return new_refs
Exemplo n.º 2
0
def align_centroids_using_pca(ref_frames, ref_frames_reference):
    """
        Align the centroids of 2 sets of rigid bodyes using PCA using their
        reference frames. returns the best rmsd and the ref_frames to get it.
    """
    if(len(ref_frames) != len(ref_frames_reference)):
        raise ValueError("The number of reference frames must be the same")
    Ts1 = [r.get_transformation_to() for r in ref_frames]
    vs1 = [T.get_translation() for T in Ts1]
    Ts2 = [r.get_transformation_to() for r in ref_frames_reference]
    vs2 = [T.get_translation() for T in Ts2]

    # align with PCA
    pc1 = alg.get_principal_components(vs1)
    pc2 = alg.get_principal_components(vs2)
    pcTs = alg.get_alignments_from_first_to_second(pc1, pc2)
    best_refs = []
    best_rmsd = 1e5
    for j, pcT in enumerate(pcTs):
        new_Ts1 = [alg.compose(pcT, T) for T in Ts1]
        new_vs1 = [T.get_translation() for T in new_Ts1]
        r = atom.get_rmsd(new_vs1, vs2)
        if(r < best_rmsd):
            best_rmsd = r
            best_refs = [alg.ReferenceFrame3D(T) for T in new_Ts1]
    return best_rmsd, best_refs
Exemplo n.º 3
0
    def move_xlinks(self, ):
        """
            Function equivalent to move_one_xlink() for the case where there
            are more than one cross-link restraints available.
            Puts the ligand residues as close as possible to the receptor
            residues
        """
        rec_coords = []
        lig_coords = []
        for xl in self.xlinks_list:
            c = self.get_residue_coordinates(self.h_receptor, xl.first_chain,
                                             xl.first_residue)
            rec_coords.append(c)
            c = self.get_residue_coordinates(self.h_ligand, xl.second_chain,
                                             xl.second_residue)
            lig_coords.append(c)
        log.debug("Receptor residues before moving %s", rec_coords)
        log.debug("Ligand residues before moving %s", lig_coords)
        ref = self.rb_ligand.get_reference_frame()
        Tr = alg.get_transformation_aligning_first_to_second(
            lig_coords, rec_coords)
        T = ref.get_transformation_to()
        newT = alg.compose(Tr, T)
        self.rb_ligand.set_reference_frame(alg.ReferenceFrame3D(newT))

        moved_lig_coords = []
        for xl in self.xlinks_list:
            c = self.get_residue_coordinates(self.h_ligand, xl.second_chain,
                                             xl.second_residue)
            moved_lig_coords.append(c)
        log.debug("Ligand residues after moving %s", moved_lig_coords)
Exemplo n.º 4
0
    def get_restraints_for_native(self, restraints_names):
        """
            Get values of the restraints for the native structure
            @param restraints_names Names of the restraints requested
            @return a list with the values of all scores, and the total score
        """
        saved = [rb.get_reference_frame() for rb in self.components_rbs]
        # Set the state of the model to native
        for rb, rn in zip(self.components_rbs, self.native_rbs):
            # remove sub-rigid bodies
            rb_members = [m for m in rb.get_members()
                          if not core.RigidBody.get_is_setup(m.get_particle())]
            rn_members = [m for m in rn.get_members()
                          if not core.RigidBody.get_is_setup(m.get_particle())]
            rb_coords = [m.get_coordinates() for m in rb_members]
            rn_coords = [m.get_coordinates() for m in rn_members]

            # align and put rb in the position of rn
            if len(rn_coords) != len(rb_coords):
                raise ValueError("Mismatch in the number of members. "
                                 "Reference %d Aligned %d " % (len(rn_coords), len(rb_coords)))
            T = alg.get_transformation_aligning_first_to_second(rb_coords,
                                                                rn_coords)
            t = rb.get_reference_frame().get_transformation_to()
            new_t = alg.compose(T, t)
            rb.set_reference_frame(alg.ReferenceFrame3D(new_t))
        scores = []
        for name in restraints_names:
            scores.append(self.restraints[name].evaluate(False))
        total_score = sum(scores)
        representation.set_reference_frames(self.components_rbs, saved)
        return scores, total_score
Exemplo n.º 5
0
def anchor_assembly(components_rbs, anchored):
    """
        "Anchor" a set of rigid bodies, by setting the position of one of them
        at the origin (0,0,0).
        @param components_rbs Rigid bodies of the components
        @param anchored - List of True/False values indicating if the components
      of the assembly are anchored. The function sets the FIRST anchored
      component in the (0,0,0) coordinate and moves the other
      components with the same translation. If all the values are False, the
      function does not do anything
    """
    if True in anchored:
        anchored_rb = None
        for a, rb in zip(anchored, components_rbs):
            if a:
                anchored_rb = rb
                break
        center = anchored_rb.get_coordinates()
        log.info("Anchoring assembly at (0,0,0)")
        for rb in components_rbs:
            T = rb.get_reference_frame().get_transformation_to()
            t = T.get_translation()
            R = T.get_rotation()
            log.debug("%s: Rerefence frame BEFORE %s",
                      rb.get_name(), rb.get_reference_frame())
            T2 = alg.Transformation3D(R, t - center)
            rb.set_reference_frame(alg.ReferenceFrame3D(T2))
            log.debug("%s Rerefence frame AFTER %s",
                      rb.get_name(), rb.get_reference_frame())
Exemplo n.º 6
0
def get_docked_reference_frames(relative_transforms, rb_lig):
    Tinitial = rb_lig.get_reference_frame().get_transformation_to()
    docked_ref_frames = []
    for Trelative in relative_transforms:
        Tdock = alg.compose(Trelative, Tinitial)
        docked_rf = alg.ReferenceFrame3D(Tdock)
        docked_ref_frames.append(docked_rf)
    return docked_ref_frames
Exemplo n.º 7
0
def apply_rotation_around_centroid(rb, rot):
    """
        Rotates the reference frame of a rigid body around the centroid
    """
    c = rb.get_coordinates()
    ref = rb.get_reference_frame()
    R = ref.get_transformation_to().get_rotation()
    R2 = alg.compose(rot, R)
    T = alg.Transformation3D(R2, c)
    ref = alg.ReferenceFrame3D(T)
    rb.set_reference_frame(ref)
Exemplo n.º 8
0
def apply_random_transform(rb, max_trans=100):
    """
        Apply a random transformation to the rigid body and change the reference
        frame
    """
    bb = alg.BoundingBox3D(alg.Vector3D(-max_trans, -max_trans, -max_trans),
                           alg.Vector3D(max_trans, max_trans, max_trans))
    Trand = alg.Transformation3D(alg.get_random_rotation_3d(),
                                 alg.get_random_vector_in(bb))
    ref = rb.get_reference_frame()
    Tr = ref.get_transformation_to()
    T = alg.compose(Trand, Tr)
    rb.set_reference_frame(alg.ReferenceFrame3D(T))
Exemplo n.º 9
0
 def set_rb_states(self, rb, transformations):
     """
         Add a set of reference frames as possible states for a rigid body
         @param rb The rigid body
         @param transformations Transformations are used to build the
                                   reference frames for the rigid body.
     """
     log.info("Set rigid body states for %s", rb.get_name())
     RFs = [alg.ReferenceFrame3D(T) for T in transformations]
     for st in RFs:
         log.debug("%s", st)
     rb_states = domino.RigidBodyStates(RFs)
     self.rb_states_table.set_particle_states(rb, rb_states)
     st = self.rb_states_table.get_particle_states(rb)
     log.info("RigidBodyStates created %s",
              st.get_number_of_particle_states())
Exemplo n.º 10
0
    def __init__(self, model, rigid_bodies, anchored):
        log.info("Setting MonteCarloRelativeMoves")
        self.model = model
        self.rbs = rigid_bodies
        self.components = []
        self.best_models = []
        self.anchored = anchored
        self.parent_rbs = []
        # triplets with the information to build a relative mover using the
        # results from docking with HEX
        self.dock_transforms = None
        self.non_relative_move_prob = 0.1

        log.debug("Anchored components %s", self.anchored)
        T = alg.Transformation3D(alg.get_identity_rotation_3d(),
                                 alg.Vector3D(0., 0., 0.))
        origin = alg.ReferenceFrame3D(T)
        for rb in self.rbs:
            rb.set_reference_frame(origin)
Exemplo n.º 11
0
 def move_one_xlink(self):
     """
         Put the residues in a random distance between 0 and the maximum
         cross-linkin distance
     """
     xl = self.xlinks_list[0]
     center = self.get_residue_coordinates(self.h_receptor, xl.first_chain,
                                           xl.first_residue)
     sph = alg.Sphere3D(center, xl.distance)
     v = alg.get_random_vector_in(sph)
     ref = self.rb_ligand.get_reference_frame()
     coords = ref.get_transformation_to().get_translation()
     R = ref.get_transformation_to().get_rotation()
     lig = self.get_residue_coordinates(self.h_ligand, xl.second_chain,
                                        xl.second_residue)
     log.debug("Ligand residue before moving %s", lig)
     displacement = v - lig
     T = alg.Transformation3D(R, coords + displacement)
     self.rb_ligand.set_reference_frame(alg.ReferenceFrame3D(T))
     new_coords = self.get_residue_coordinates(self.h_ligand,
                                               xl.second_chain,
                                               xl.second_residue)
     log.debug("ligand after moving %s", new_coords)
Exemplo n.º 12
0
Arquivo: io.py Projeto: sirusb/imp
 def __init__(self, text, delimiter="|"):
     TextToTransformation3D.__init__(self, text, delimiter)
     self.ref = alg.ReferenceFrame3D(self.get_transformation())