Пример #1
0
 def __init__(self,
              objects,
              coordinates,
              restraints=None,
              membrane=None,
              reference_points=None,
              n_modes=None):
     self.objects = objects
     if type(coordinates) is list:
         self.coordinates = coordinates
     else:
         self.coordinates = [coordinates]
     # TODO: Calculate only one set of reference points
     if reference_points is None:
         # Reference points calculation. If single matrix error is found, calculate centroid
         try:
             ellipsoid = MinimumVolumeEllipsoid(
                 self.coordinates[0].coordinates)
             self.reference_points = np.array([ellipsoid.center.copy()])
             # Suggest the GC to free some memory
         except MinimumVolumeEllipsoidError:
             self.reference_points = np.array(
                 [np.mean(self.coordinates[0], axis=0)])
     else:
         self.reference_points = reference_points
     self.reference_points = SpacePoints(self.reference_points)
     self.n_modes = n_modes
     self.restraints = restraints
     self.membrane = membrane
Пример #2
0
    def __init__(self, chains, atoms=None, residues=None, structure_file_name='', structures=None, representative_id=0):
        """Creates a new complex that can deal with multiple coordinates for a given atom"""
        self.chains = chains
        # Set atoms at the upper level for fast indexing
        if atoms:
            self.atoms = atoms
        else:
            self.atoms = [atom for chain in self.chains
                          for residue in chain.residues for atom in residue.atoms]
        for atom_index, atom in enumerate(self.atoms):
            atom.index = atom_index

        # Same for residues
        if residues:
            self.residues = residues
        else:
            self.residues = [residue for chain in self.chains for residue in chain.residues]
        for residue_index, residue in enumerate(self.residues):
            residue.index = residue_index

        if structures:
            self.num_structures = len(structures)
            self.structure_file_names = [structure['file_name'] for structure in structures]
            self.atom_coordinates = [SpacePoints([[atom.x, atom.y, atom.z]
                                                  for atom in structure['atoms']]) for structure in structures]
        else:
            self.num_structures = 1
            self.structure_file_names = [structure_file_name]
            self.atom_coordinates = [SpacePoints([[atom.x, atom.y, atom.z] for atom in self.atoms])]

        self.num_atoms = len(self.atoms)
        self.num_residues = len(self.residues)
        self.representative_id = representative_id
Пример #3
0
 def _get_docking_model(self, molecule, restraints):
     """Builds a suitable docking model for this scoring function"""
     objects = []
     coordinates = []
     parsed_restraints = {}
     atom_index = 0
     for residue in molecule.residues:
         for rec_atom in residue.atoms:
             rec_atom_type = rec_atom.residue_name + ' ' + rec_atom.name
             if rec_atom_type in DFIRE2_ATOM_TYPES:
                 objects.append(
                     DFIRE2Object(residue.number,
                                  DFIRE2_ATOM_TYPES[rec_atom_type]))
                 coordinates.append([rec_atom.x, rec_atom.y, rec_atom.z])
                 # Restraints support
                 res_id = "%s.%s.%s" % (rec_atom.chain_id, residue.name,
                                        str(residue.number))
                 if restraints and res_id in restraints:
                     try:
                         parsed_restraints[res_id].append(atom_index)
                     except:
                         parsed_restraints[res_id] = [atom_index]
                 atom_index += 1
     try:
         return DockingModel(objects,
                             SpacePoints(coordinates),
                             parsed_restraints,
                             n_modes=molecule.n_modes.copy())
     except AttributeError:
         return DockingModel(objects, SpacePoints(coordinates),
                             parsed_restraints)
Пример #4
0
    def test_create_model(self):
        docking_model = DockingModel(objects=self.residues,
                                     coordinates=SpacePoints([[1, 1, 1], [1.1, 1.2, 1.3]]))

        expected_coordinates = SpacePoints([[1, 1, 1], [1.1, 1.2, 1.3]])

        assert len(docking_model.objects) == 2
        assert expected_coordinates == docking_model.coordinates[0]
Пример #5
0
    def test_reference_points_singular_matrix(self):
        atom1 = Atom(1, 'CA', '', 'A', 'ALA', x=2., y=2., z=2.)
        atom2 = Atom(2, 'CB', '', 'A', 'ALA', x=0., y=0., z=0.)
        atom3 = Atom(3, 'C', '', 'A', 'ALA', x=1., y=1., z=1.)
        atoms = [atom1, atom2, atom3]
        docking_model = DockingModel(atoms, SpacePoints([[2., 2., 2.], [0., 0., 0.], [1., 1., 1.]]))

        expected_coordinates = SpacePoints([[1., 1., 1.]])

        assert expected_coordinates == docking_model.reference_points
Пример #6
0
 def test_reference_points_minimum_volume_ellipsoid(self):
     atom1 = Atom(1, 'CA', '', 'A', 'ALA', x=1.2, y=-1., z=2.)
     atom2 = Atom(2, 'CB', '', 'A', 'ALA', x=0., y=0., z=0.)
     atom3 = Atom(3, 'C', '', 'A', 'ALA', x=0.5, y=3., z=0.5)
     atom4 = Atom(4, 'N', '', 'A', 'ALA', x=0.85, y=-2.5, z=0.4)
     atoms = [atom1, atom2, atom3, atom4]
     docking_model = DockingModel(atoms, SpacePoints([[1.2, -1., 2.], [0., 0., 0.],
                                                      [0.5, 3., 0.5], [0.85, -2.5, 0.4]]))
     # Only center is used now
     expected_coordinates = SpacePoints([[0.6375, -0.125, 0.725]])
     assert expected_coordinates == docking_model.reference_points
Пример #7
0
    def test_translate(self):
        atom1 = Atom(1, 'CA', '', 'A', 'ALA', x=2., y=2., z=2.)
        atom2 = Atom(2, 'CB', '', 'A', 'ALA', x=0., y=0., z=0.)
        residues = [Residue('ALA', 1, [atom1, atom2])]
        docking_model = DockingModel(residues, SpacePoints([[2., 2., 2.], [0, 0, 0]]))

        docking_model.translate([-2, -2, -2])

        expected_coordinates = SpacePoints([[0, 0, 0], [-2, -2, -2]])
        assert expected_coordinates == docking_model.coordinates[0]

        expected_coordinates = SpacePoints([[-1, -1, -1]])
        assert np.allclose(expected_coordinates, docking_model.reference_points)
Пример #8
0
    def test_null_rotation(self):
        atom1 = Atom(1, 'CA', '', 'A', 'ALA', x=2., y=2., z=2.)
        atom2 = Atom(2, 'CB', '', 'A', 'ALA', x=0., y=0., z=0.)
        atom3 = Atom(3, 'C', '', 'A', 'ALA', x=0.5, y=0.5, z=0.5)
        atoms = [atom1, atom2, atom3]
        docking_model = DockingModel(atoms, SpacePoints([[2., 2., 2.], [0., 0., 0.], [0.5, 0.5, 0.5]]))
        q = Quaternion()
        docking_model.rotate(q)

        expected_coordinates = SpacePoints([[2., 2., 2.], [0., 0., 0.], [0.5, 0.5, 0.5]])
        assert expected_coordinates == docking_model.coordinates[0]

        expected_coordinates = SpacePoints([[0.833333333333, 0.833333333333, 0.833333333333]])
        assert np.allclose(expected_coordinates, docking_model.reference_points)
Пример #9
0
class DockingModel(object):
    """Represents a docking model of a protein molecule"""
    def __init__(self,
                 objects,
                 coordinates,
                 restraints=None,
                 membrane=None,
                 reference_points=None,
                 n_modes=None):
        self.objects = objects
        if type(coordinates) is list:
            self.coordinates = coordinates
        else:
            self.coordinates = [coordinates]
        # TODO: Calculate only one set of reference points
        if reference_points is None:
            # Reference points calculation. If single matrix error is found, calculate centroid
            try:
                ellipsoid = MinimumVolumeEllipsoid(
                    self.coordinates[0].coordinates)
                self.reference_points = np.array([ellipsoid.center.copy()])
                # Suggest the GC to free some memory
            except MinimumVolumeEllipsoidError:
                self.reference_points = np.array(
                    [np.mean(self.coordinates[0], axis=0)])
        else:
            self.reference_points = reference_points
        self.reference_points = SpacePoints(self.reference_points)
        self.n_modes = n_modes
        self.restraints = restraints
        self.membrane = membrane

    def translate(self, vector):
        """Translates coordinates based on vector"""
        for coordinates in self.coordinates:
            coordinates.translate(vector)
        self.reference_points.translate(vector)

    def rotate(self, q):
        """Rotates coordinates using a quaternion q"""
        for coordinates in self.coordinates:
            coordinates.rotate(q)
        self.reference_points.rotate(q)

    def __len__(self):
        return len(self.coordinates)
Пример #10
0
    def test_null_rotation_one_atom(self):
        atom1 = Atom(1, 'CA', '', 'A', 'ALA', x=2., y=2., z=2.)
        atoms = [atom1]
        docking_model = DockingModel(atoms, SpacePoints([[2., 2., 2.]]))
        q = Quaternion()
        docking_model.rotate(q)

        expected_coordinates = np.array([[2., 2., 2.]])
        assert (expected_coordinates == docking_model.coordinates).all()
Пример #11
0
    def _get_docking_model(self, molecule, restraints):
        """Builds a suitable docking model for this scoring function"""
        residues = [residue for chain in molecule.chains for residue in chain.residues]
        tobi_residues = []
        list_of_coordinates = []
        parsed_restraints = {}
        for structure in range(molecule.num_structures):
            coordinates = []
            for residue in residues:
                try:
                    residue_index = TOBIPotential.recognized_residues.index(residue.name)

                    cx = 0.0
                    cy = 0.0
                    cz = 0.0
                    count = 0
                    chain_id = ''
                    for atom in residue.atoms:
                        if not atom.is_hydrogen():
                            current_atom = "%s%s" % (residue.name, atom.name)
                            ax = molecule.atom_coordinates[structure][atom.index][0]
                            ay = molecule.atom_coordinates[structure][atom.index][1]
                            az = molecule.atom_coordinates[structure][atom.index][2]

                            for atom_type in range(len(TOBIPotential.atom_types)):
                                if current_atom in TOBIPotential.atom_types[atom_type]:
                                    cx += ax
                                    cy += ay
                                    cz += az
                                    count += 1
                            if atom.name == 'N':
                                coordinates.append([ax, ay, az])
                                tobi_residues.append(20)
                            if atom.name == 'O':
                                coordinates.append([ax, ay, az])
                                tobi_residues.append(21)
                            chain_id = atom.chain_id
                    cx /= float(count)
                    cy /= float(count)
                    cz /= float(count)

                    coordinates.append([cx, cy, cz])
                    tobi_residues.append(residue_index)

                    res_id = "%s.%s.%s" % (chain_id, residue.name, str(residue.number))
                    if restraints and res_id in restraints:
                        parsed_restraints[res_id] = []

                except ValueError:
                    pass
                except ZeroDivisionError:
                    continue
            list_of_coordinates.append(SpacePoints(coordinates))

        return DockingModel(tobi_residues, list_of_coordinates, parsed_restraints)
Пример #12
0
class DockingModel(object):
    """Represents a docking model of a protein molecule"""
    def __init__(self, objects, coordinates, restraints=None, reference_points=None, n_modes=None):
        self.objects = objects
        if type(coordinates) is list:
            self.coordinates = coordinates
        else:
            self.coordinates = [coordinates]
        # TODO: Calculate only one set of reference points
        if reference_points is None:
            # Reference points calculation. If single matrix error is found, calculate centroid
            try:
                ellipsoid = MinimumVolumeEllipsoid(self.coordinates[0].coordinates)
                self.reference_points = np.array([ellipsoid.center.copy()])
                # Suggest the GC to free some memory
            except MinimumVolumeEllipsoidError:
                self.reference_points = np.array([np.mean(self.coordinates[0], axis=0)])
        else:
            self.reference_points = reference_points
        self.reference_points = SpacePoints(self.reference_points)
        self.n_modes = n_modes
        self.restraints = restraints

    def translate(self, vector):
        """Translates coordinates based on vector"""
        for coordinates in self.coordinates:
            coordinates.translate(vector)
        self.reference_points.translate(vector)

    def rotate(self, q):
        """Rotates coordinates using a quaternion q"""
        for coordinates in self.coordinates:
            coordinates.rotate(q)
        self.reference_points.rotate(q)

    def clone(self):
        """Creates a copy of the current model"""
        return DockingModel(self.objects, self.coordinates.clone(), self.reference_points.clone(), self.n_modes)

    def __len__(self):
        return len(self.coordinates)
Пример #13
0
    def _get_docking_model(self, molecule, restraints):
        """Builds a suitable docking model for this scoring function"""
        list_of_coordinates = []
        not_considered_atoms = ['O', 'C', 'N', 'H']
        residues_to_remove = []
        residues = [
            residue for chain in molecule.chains for residue in chain.residues
        ]
        parsed_restraints = {}
        for structure in range(molecule.num_structures):
            coordinates = []
            for res_index, residue in enumerate(residues):
                c_x = 0.0
                c_y = 0.0
                c_z = 0.0
                count = 0
                chain_id = ''
                for atom in residue.atoms:
                    if atom.name not in not_considered_atoms:
                        c_x += molecule.atom_coordinates[structure][
                            atom.index][0]
                        c_y += molecule.atom_coordinates[structure][
                            atom.index][1]
                        c_z += molecule.atom_coordinates[structure][
                            atom.index][2]
                        count += 1
                        chain_id = atom.chain_id
                if count:
                    count = float(count)
                    coordinates.append([c_x / count, c_y / count, c_z / count])
                    res_id = "%s.%s.%s" % (chain_id, residue.name,
                                           str(residue.number))
                    if restraints and res_id in restraints:
                        parsed_restraints[res_id] = []
                else:
                    residues_to_remove.append(res_index)

            if len(residues_to_remove):
                residues = [
                    residue for res_index, residue in enumerate(residues)
                    if res_index not in residues_to_remove
                ]

            list_of_coordinates.append(SpacePoints(coordinates))

        return DockingModel(residues, list_of_coordinates, parsed_restraints)
Пример #14
0
 def __init__(self, objects, coordinates, restraints=None, reference_points=None, n_modes=None):
     self.objects = objects
     if type(coordinates) is list:
         self.coordinates = coordinates
     else:
         self.coordinates = [coordinates]
     # TODO: Calculate only one set of reference points
     if reference_points is None:
         # Reference points calculation. If single matrix error is found, calculate centroid
         try:
             ellipsoid = MinimumVolumeEllipsoid(self.coordinates[0].coordinates)
             self.reference_points = np.array([ellipsoid.center.copy()])
             # Suggest the GC to free some memory
         except MinimumVolumeEllipsoidError:
             self.reference_points = np.array([np.mean(self.coordinates[0], axis=0)])
     else:
         self.reference_points = reference_points
     self.reference_points = SpacePoints(self.reference_points)
     self.n_modes = n_modes
     self.restraints = restraints