Exemple #1
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)
Exemple #2
0
def get_components_placement_scores(assembly, native_assembly, align=False):
    """
        Compute the placement score of each of the children of an assembly.
        The function does not do any time of alignment of the coordinates
        @param assembly An atom.Molecule object
        @param native_assembly An atom.Molecule object with the native conformation
                                Obviously the atoms in assembly and native assembly
                                must be the same
        @param align If True, assembly is aligned to native_assembly before
                    calculating the placement score
        @return The function returns 2 lists. The first list contains the
                placement distances of the children. The second list contains the
                placnement angles
    """
    model_coords_per_child = [get_coordinates(c)
                              for c in assembly.get_children()]
    native_coords_per_child = [get_coordinates(c)
                               for c in native_assembly.get_children()]
    if align:
        model_coords = []
        nil = [model_coords.extend(x) for x in model_coords_per_child]
        native_coords = []
        nil = [native_coords.extend(x) for x in native_coords_per_child]
        T = alg.get_transformation_aligning_first_to_second(model_coords,
                                                            native_coords)
        # get aligned coordinates
        new_model_coords_per_child = []
        for c in model_coords_per_child:
            coords = [T.get_transformed(x) for x in c]
            new_model_coords_per_child.append(coords)
        model_coords_per_child = new_model_coords_per_child
    distances, angles = get_placement_scores_from_coordinates(
        native_coords_per_child, model_coords_per_child)
    return distances, angles
Exemple #3
0
def get_components_placement_scores(assembly, native_assembly, align=False):
    """
        Compute the placement score of each of the children of an assembly.
        The function does not do any time of alignment of the coordinates
        @param assembly An atom.Molecule object
        @param native_assembly An atom.Molecule object with the native conformation
                                Obviously the atoms in assembly and native assembly
                                must be the same
        @return The function returns 2 lists. The first list contains the
                placement distances of the children. The second list contains the
                placnement angles
    """
    model_coords_per_child = [get_coordinates(c)
                              for c in assembly.get_children()]
    native_coords_per_child = [get_coordinates(c)
                               for c in native_assembly.get_children()]
    if align:
        model_coords = []
        nil = [model_coords.extend(x) for x in model_coords_per_child]
        native_coords = []
        nil = [native_coords.extend(x) for x in native_coords_per_child]
        T = alg.get_transformation_aligning_first_to_second(model_coords,
                                                            native_coords)
        # get aligned coordinates
        new_model_coords_per_child = []
        for c in model_coords_per_child:
            coords = [T.get_transformed(x) for x in c]
            new_model_coords_per_child.append(coords)
        model_coords_per_child = new_model_coords_per_child
    distances, angles = get_placement_scores_from_coordinates(
        native_coords_per_child, model_coords_per_child)
    return distances, angles
Exemple #4
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)
Exemple #5
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
Exemple #6
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
Exemple #7
0
 def align_rigid_bodies_states(self):
     """
         Aligns the set of structures considered for DOMINO sampling.
         The function:
             1) reads the possible reference frames that the
                 rb_states_table stores for each rigid body. This table
                 must be filled before using this function. Usually it is
                 filled with the results from a previous Monte Carlo sampling.
                 If the solutions from Monte Carlo seem to have the same structure
                 but they are not aligned to each other, this function can
                 help setting better starting positions to use with DOMINO.
             2) Gets the first state for each of the rigid bodies and sets
                a reference structure using such states.
             3) Aligns all the rest of the structures respect to the reference
             4) Replaces the values of the reference frames stored in the
                rb_states_table with the new values obtained from the alignments.
                It does it for all states of a rigid body.
         @note: If this function is applied, the parameters "anchor" and "fixed"
            are ignored, as they are superseded by the use of the alignments
            calculated here.
     """
     log.debug("Align the configurations read from the database before "
               "running DOMINO")
     rb_states = []
     n_states = []
     for rb in self.components_rbs:
         ps = self.rb_states_table.get_particle_states(rb)
         n = ps.get_number_of_particle_states()
         if n == 0:
             raise ValueError(
                 "There are no particle states for %s" %
                 rb.get_name())
         n_states.append(n)
         rb_states.append(ps)
     # coordinates of the first configuration (there is at least one for all
     # the rbs)
     for rb, states in zip(self.components_rbs, rb_states):
         states.load_particle_state(0, rb)
     reference_coords = get_coordinates(self.components_rbs)
     aligned_transformations = [[] for rb in self.components_rbs]
     for i in range(1, max(n_states)):
         log.debug("Aligning rigid bodies configuration %s" % i)
         # load the configuration
         for j in range(len(self.components_rbs)):
             # if there are no more particle states for this rigid body, use
             # the last
             state_index = min(i, n_states[j] - 1)
             rb_states[j].load_particle_state(
                 state_index,
                 self.components_rbs[j])
         coords = get_coordinates(self.components_rbs)
         T = alg.get_transformation_aligning_first_to_second(
             coords, reference_coords)
         for j, rb in enumerate(self.components_rbs):
             t = rb.get_reference_frame().get_transformation_to()
             new_t = alg.compose(T, t)
             aligned_transformations[j].append(new_t)
     # set the new possible transformations
     for i, rb in enumerate(self.components_rbs):
         self.set_rb_states(rb, aligned_transformations[i])
 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_residues = [x[0] for x in self.xlinks]
     lig_residues = [x[1] for x in self.xlinks]
     rec_coords = [self.get_residue_coordinates(self.h_receptor, x)
                                                     for x in rec_residues]
     lig_coords = [self.get_residue_coordinates(self.h_ligand, x)
                                                     for x in lig_residues]
     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()
     # new coords for the ligand aminoacids
     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 = [self.get_residue_coordinates(self.h_ligand, x)
                                                     for x in lig_residues]
     log.debug( "Ligand residues after moving %s", moved_lig_coords)
Exemple #9
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
Exemple #10
0
 def align_rigid_bodies_states(self):
     """
         Aligns the set of structures considered for DOMINO sampling.
         The function:
             1) reads the possible reference frames that the
                 rb_states_table stores for each rigid body. This table
                 must be filled before using this function. Usually it is
                 filled with the results from a previous Monte Carlo sampling.
                 If the solutions from Monte Carlo seem to have the same structure
                 but they are not aligned to each other, this function can
                 help setting better starting positions to use with DOMINO.
             2) Gets the first state for each of the rigid bodies and sets
                a reference structure using such states.
             3) Aligns all the rest of the structures respect to the reference
             4) Replaces the values of the reference frames stored in the
                rb_states_table with the new values obtained from the alignments.
                It does it for all states of a rigid body.
         @note: If this function is applied, the parameters "anchor" and "fixed"
            are ignored, as they are superseded by the use of the alignments
            calculated here.
     """
     log.debug("Align the configurations read from the database before "
               "running DOMINO")
     rb_states = []
     n_states = []
     for rb in self.components_rbs:
         ps = self.rb_states_table.get_particle_states(rb)
         n = ps.get_number_of_particle_states()
         if n == 0:
             raise ValueError(
                 "There are no particle states for %s" %
                 rb.get_name())
         n_states.append(n)
         rb_states.append(ps)
     # coordinates of the first configuration (there is at least one for all
     # the rbs)
     for rb, states in zip(self.components_rbs, rb_states):
         states.load_particle_state(0, rb)
     reference_coords = get_coordinates(self.components_rbs)
     aligned_transformations = [[] for rb in self.components_rbs]
     for i in range(1, max(n_states)):
         log.debug("Aligning rigid bodies configuration %s" % i)
         # load the configuration
         for j in range(len(self.components_rbs)):
             # if there are no more particle states for this rigid body, use
             # the last
             state_index = min(i, n_states[j] - 1)
             rb_states[j].load_particle_state(
                 state_index,
                 self.components_rbs[j])
         coords = get_coordinates(self.components_rbs)
         T = alg.get_transformation_aligning_first_to_second(
             coords, reference_coords)
         for j, rb in enumerate(self.components_rbs):
             t = rb.get_reference_frame().get_transformation_to()
             new_t = alg.compose(T, t)
             aligned_transformations[j].append(new_t)
     # set the new possible transformations
     for i, rb in enumerate(self.components_rbs):
         self.set_rb_states(rb, aligned_transformations[i])
def get_placement_score(reference_rb, rb):
    reference_centroid = reference_rb.get_coordinates()
    centroid = rb.get_coordinates()
    translation_vector = reference_centroid - centroid
    distance = translation_vector.get_magnitude()
    ref_coords =  [m.get_coordinates() for m in reference_rb.get_members()]
    coords = [m.get_coordinates() for m in rb.get_members()]
    if(len(ref_coords) != len(coords) ):
        raise ValueError(
          "Mismatch in the number of members: reference model %d, " \
                "model to measure %d " % (len(ref_coords), len(coords)) )
    TT = alg.get_transformation_aligning_first_to_second(coords, ref_coords)
    P = alg.get_axis_and_angle( TT.get_rotation() )
    angle = P.second
    return distance, angle
Exemple #12
0
def get_placement_score_from_coordinates(model_coords, native_coords):
    """
        Computes the position error (placement distance) and the orientation
        error (placement angle) of the coordinates in model_coords respect to
        the coordinates in native_coords.
        placement distance - translation between the centroids of the
                            coordinates
        placement angle - Angle in the axis-angle formulation of the rotation
        aligning the two rigid bodies.
    """
    native_centroid = alg.get_centroid(native_coords)
    model_centroid = alg.get_centroid(model_coords)
    translation_vector = native_centroid - model_centroid
    distance = translation_vector.get_magnitude()
    if (len(model_coords) != len(native_coords)):
        raise ValueError("Mismatch in the number of members %d %d " %
                         (len(model_coords), len(native_coords)))
    TT = alg.get_transformation_aligning_first_to_second(
        model_coords, native_coords)
    P = alg.get_axis_and_angle(TT.get_rotation())
    angle = P.second
    return distance, angle
Exemple #13
0
def get_placement_score_from_coordinates(model_coords, native_coords):
    """
        Computes the position error (placement distance) and the orientation
        error (placement angle) of the coordinates in model_coords respect to
        the coordinates in native_coords.
        placement distance - translation between the centroids of the
                            coordinates
        placement angle - Angle in the axis-angle formulation of the rotation
        aligning the two rigid bodies.
    """
    native_centroid = alg.get_centroid(native_coords)
    model_centroid = alg.get_centroid(model_coords)
    translation_vector = native_centroid - model_centroid
    distance = translation_vector.get_magnitude()
    if(len(model_coords) != len(native_coords)):
        raise ValueError(
            "Mismatch in the number of members %d %d " % (
                len(model_coords),
                len(native_coords)))
    TT = alg.get_transformation_aligning_first_to_second(model_coords,
                                                         native_coords)
    P = alg.get_axis_and_angle(TT.get_rotation())
    angle = P.second
    return distance, angle