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)
def _get_docking_model(self, molecule, restraints): """Builds a suitable docking model for this scoring function""" r3_to_numerical = {} for x in range(len(DFIREPotential.RES_3)): r3_to_numerical[DFIREPotential.RES_3[x]] = x atomnumber = {} for x in range(len(DFIREPotential.RES_3)): for y in range(len(DFIREPotential.atoms_in_residues[DFIREPotential.RES_3[x]])): name = '%s%s' % (DFIREPotential.RES_3[x], DFIREPotential.atoms_in_residues[DFIREPotential.RES_3[x]][y]) atomnumber[name] = y parsed_restraints = {} dfire_objects = [] atom_index = 0 for chain in molecule.chains: for residue in chain.residues: res_id = "%s.%s.%s" % (chain.cid, residue.name, str(residue.number)) in_restraint = False if restraints and res_id in restraints: parsed_restraints[res_id] = [] in_restraint = True for rec_atom in residue.atoms: rec_atom_type = rec_atom.residue_name + rec_atom.name rnuma = r3_to_numerical[rec_atom.residue_name] anuma = atomnumber[rec_atom_type] dfire_objects.append(DFIREObject(residue.index, rnuma, anuma)) if in_restraint: parsed_restraints[res_id].append(atom_index) atom_index += 1 try: return DockingModel(dfire_objects, molecule.copy_coordinates(), parsed_restraints, n_modes=molecule.n_modes.copy()) except AttributeError: return DockingModel(dfire_objects, molecule.copy_coordinates(), parsed_restraints)
def _get_docking_model(self, molecule, restraints): """Builds a suitable docking model for this scoring function""" pisa_objects = [] coordinates = [] parsed_restraints = {} for atom_index, atom in enumerate(molecule.atoms): atom_type = PISAPotential.get_atom_type(atom.name, atom.residue_name) if atom_type != -1: atom.pisa_type = atom_type pisa_objects.append(atom) coordinates.append([atom.x, atom.y, atom.z]) res_id = "%s.%s.%s" % (atom.chain_id, atom.residue_name, str(atom.residue_number)) if restraints and res_id in restraints: try: parsed_restraints[res_id].append(atom_index) except: parsed_restraints[res_id] = [atom_index] try: return DockingModel(pisa_objects, molecule.copy_coordinates(), parsed_restraints, n_modes=molecule.n_modes.copy()) except AttributeError: return DockingModel(pisa_objects, molecule.copy_coordinates(), parsed_restraints)
def _get_docking_model(self, molecule, restraints): """Builds a suitable docking model for this scoring function""" parsed_restraints = {} ddna_objects = [] atom_index = 0 for chain in molecule.chains: for residue in chain.residues: res_id = "%s.%s.%s" % (chain.cid, residue.name, str(residue.number)) in_restraint = False if restraints and res_id in restraints: parsed_restraints[res_id] = [] in_restraint = True for rec_atom in residue.atoms: try: ddna_atom_type = atom_types.index( atom_map[rec_atom.residue_name][rec_atom.name]) except KeyError: raise NotSupportedInScoringError( f'Atom {rec_atom.name} in residue {rec_atom.residue_name} not supported' ) ddna_objects.append(ddna_atom_type) if in_restraint: parsed_restraints[res_id].append(atom_index) atom_index += 1 try: return DockingModel(ddna_objects, molecule.copy_coordinates(), parsed_restraints, n_modes=molecule.n_modes.copy()) except AttributeError: return DockingModel(ddna_objects, molecule.copy_coordinates(), parsed_restraints)
def _get_docking_model(self, molecule, restraints): """Builds a suitable docking model for this scoring function""" r3_to_numerical = {} for x in range(len(DFIREPotential.RES_3)): r3_to_numerical[DFIREPotential.RES_3[x]] = x atomnumber = {} for x in range(len(DFIREPotential.RES_3)): for y in range( len(DFIREPotential.atoms_in_residues[ DFIREPotential.RES_3[x]])): name = '%s%s' % (DFIREPotential.RES_3[x], DFIREPotential. atoms_in_residues[DFIREPotential.RES_3[x]][y]) atomnumber[name] = y parsed_restraints = {} dfire_objects = [] atom_index = 0 membrane = {} for chain in molecule.chains: for residue in chain.residues: res_id = "%s.%s.%s" % (chain.cid, residue.name, str(residue.number)) in_restraint = False if restraints and res_id in restraints: parsed_restraints[res_id] = [] in_restraint = True for rec_atom in residue.atoms: rec_atom_type = rec_atom.residue_name + rec_atom.name if rec_atom_type == 'MMBBJ': # Membrane beads MMB.BJ try: membrane[res_id].append(atom_index) except KeyError: membrane[res_id] = [atom_index] try: rnuma = r3_to_numerical[rec_atom.residue_name] anuma = atomnumber[rec_atom_type] atoma = DFIREPotential.atom_res_trans[rnuma, anuma] dfire_objects.append(atoma) if in_restraint: parsed_restraints[res_id].append(atom_index) atom_index += 1 except KeyError: raise NotSupportedInScoringError( 'Residue {} or atom {} not supported. '.format( res_id, rec_atom.name) + 'DFIRE only supports standard aminoacids without hydrogens.' ) try: return DockingModel(dfire_objects, molecule.copy_coordinates(), parsed_restraints, membrane, n_modes=molecule.n_modes.copy()) except AttributeError: return DockingModel(dfire_objects, molecule.copy_coordinates(), parsed_restraints, membrane)
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()
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)
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)
def _get_docking_model(self, molecule, restraints): """Builds a suitable docking model for this scoring function""" # In model_objects we can store any coordinates object (atoms, beans, etc.) model_objects = [] for residue in molecule.residues: for rec_atom in residue.atoms: model_objects.append(rec_atom) try: return DockingModel(model_objects, molecule.copy_coordinates(), restraints, n_modes=molecule.n_modes.copy()) except AttributeError: return DockingModel(model_objects, molecule.copy_coordinates(), restraints)
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]
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
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)
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
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)