def testResidueCopying(self): smi = "C[C@@H](C(=O)N[C@@H](CS)C(=O)O)N" # H-Ala-Cys-OH mol = pybel.readstring("smi", smi).OBMol ob.cvar.chainsparser.PerceiveChains(mol) mol.SetChainsPerceived() residues = list(ob.OBResidueIter(mol)) self.assertEqual(len(residues), 2) # Copy just the Cys N bv = self.createBitVec(mol.NumAtoms() + 1, (5, )) nmol = ob.OBMol() mol.CopySubstructure(nmol, bv) self.assertEqual(len(list(ob.OBResidueIter(nmol))), 1) pdb = pybel.Molecule(nmol).write("pdb") atoms = [line for line in pdb.split("\n") if line.startswith("ATOM")] self.assertEqual(len(atoms), 1) cysN = "ATOM 1 N CYS A 2" self.assertTrue(atoms[0].startswith(cysN)) # Copy the Cys N and Ca bv = self.createBitVec(mol.NumAtoms() + 1, (5, 6)) nmol.Clear() mol.CopySubstructure(nmol, bv) self.assertEqual(len(list(ob.OBResidueIter(nmol))), 1) pdb = pybel.Molecule(nmol).write("pdb") atoms = [line for line in pdb.split("\n") if line.startswith("ATOM")] self.assertEqual(len(atoms), 2) self.assertTrue(atoms[0].startswith(cysN)) cysCa = "ATOM 2 CA CYS A 2" self.assertTrue(atoms[1].startswith(cysCa)) # Copy the Ala C and Cys N bv = self.createBitVec(mol.NumAtoms() + 1, (3, 5)) nmol.Clear() mol.CopySubstructure(nmol, bv) self.assertEqual(len(list(ob.OBResidueIter(nmol))), 2) pdb = pybel.Molecule(nmol).write("pdb") atoms = [line for line in pdb.split("\n") if line.startswith("ATOM")] self.assertEqual(len(atoms), 2) alaC = "ATOM 1 C ALA A 1" self.assertTrue(atoms[0].startswith(alaC)) cysN = "ATOM 2 N CYS A 2" self.assertTrue(atoms[1].startswith(cysN))
def GetAtomByID(protein, residueNumber, name): """ Returns the OBAtom object given the AtomID (PDB Columns 13-16), the protein name (ace2 or spike), and the residue number """ for res in ob.OBResidueIter(protein): if res.GetNum() == residueNumber: for atom in ob.OBResidueAtomIter(res): if res.GetAtomID(atom) == name: return atom
def GetResidueMolecule(protein, residueNumber): """ Gets the OBMol object corresponding to a residue number on ACE2 protein or Spike protein protein: 'ace2' or 'spike' residueNumber: The residue Number returns: The OBMol object representing the molecule """ resMol = ob.OBMol() for res in ob.OBResidueIter(protein): if res.GetNum() == residueNumber: for atom in ob.OBResidueAtomIter(res): resMol.AddAtom(atom) break return resMol
def rna_coords_atom_index_dict(structure): """For the debug/detail mode only; creates a dictionary or nucleic acid's atoms' coords with their atom ids as values :param structure: nucleic acid structure object :type structure: pybel.Molecule :return: dictionary indexed by nucleic acid's atoms' coords, with their atom ids as values :rtype: dict """ dictionary = {} for residue in openbabel.OBResidueIter(structure.OBMol): if residue.GetNumAtoms() > 3: for atom in openbabel.OBResidueAtomIter(residue): dictionary[( atom.GetX(), atom.GetY(), atom.GetZ())] = atom.GetResidue().GetAtomID(atom).strip() return dictionary
def printAtomNames(mol): for res in openbabel.OBResidueIter(mol): for atom in openbabel.OBResidueAtomIter(res): name = res.GetAtomID(atom) print(name)
def calculateIFPPlants(self, ligands, flex_proteins, ligand_atom_group): pose_num = len(ligands) self.flex_residues = [residue.GetName() for residue in ob.OBResidueIter(flex_proteins[0])] self.full_bits_list = [self.full_bitstring.copy() for i in range(pose_num)] self.simp_bits_list = [self.simp_bitstring.copy() for i in range(pose_num)] self.full_nobb_list = [self.full_nobb_bitstring.copy() for i in range(pose_num)] possible_interactions = [] for x, y in zip(self.interactions, ligand_atom_group['interactions']): possible_interactions.append(1) if x & y else possible_interactions.append(0) for ligand, flex, full, full_nobb, simp in \ zip(ligands, flex_proteins, self.full_bits_list, self.full_nobb_list, self.simp_bits_list): interaction_flags = [0, 0, 0, 0, 0, 0, 0] if possible_interactions[0]: for ligand_id in ligand_atom_group['hydrophobic']: ligand_atom = ligand.GetAtomById(ligand_id) for atom in self.atomGroup['hydrophobic']: distance = ligand_atom.GetDistance(atom) if distance <= HYDROPHOBIC: if self.simplified: simp |= self.hydrophobic[self.AA_name]['bitarray'] if self.full: full |= bitarray('1000000') if self.full_nobb: full_nobb |= bitarray('1000000') interaction_flags[0] = 1 break if interaction_flags[0]: break if possible_interactions[1]: for path in ligand_atom_group['rings']: path3 = path[:3] path3atoms = [] for i in path3: path3atoms.append(ligand.GetAtom(i)) for ligand_id in path: for atom in self.atomGroup['aromatic']: distance = ligand.GetAtom(ligand_id).GetDistance(atom) if distance <= AROMATIC: ligCross, ligModulus = getCrossModulus(path3atoms) dot = np.dot(self.cross, ligCross) cos_angle = dot / self.modulus / ligModulus ring_angle = np.arccos(cos_angle) * 180 / np.pi if (AROMATIC_ANGLE_LOW >= ring_angle) or (AROMATIC_ANGLE_HIGH <= ring_angle): if self.simplified: simp |= self.aromatic[self.AA_name]['bitarrayF2F'] if self.full: full |= bitarray('0100000') if self.full_nobb: full_nobb |= bitarray('0100000') interaction_flags[1] = 1 else: if self.simplified: simp |= self.aromatic[self.AA_name]['bitarrayE2F'] if self.full: full |= bitarray('0010000') if self.full_nobb: full_nobb |= bitarray('0010000') interaction_flags[2] = 1 break if interaction_flags[1] | interaction_flags[2]: break if interaction_flags[1] & interaction_flags[2]: break if possible_interactions[2]: for ligand_id in ligand_atom_group['h_accept']: ligand_atom = ligand.GetAtomById(ligand_id) for atom, h_list in zip(self.atomGroup['h_donor'], self.atomGroup['h_donorh']): distance = ligand_atom.GetDistance(atom) if distance <= HBOND: angle_flag = 0 if self.res_name in self.flex_residues: for flex_atom in ob.OBMolAtomIter(flex): if (flex_atom.GetAtomicNum() == 1) & (flex_atom.GetResidue().GetName() == self.res_name): angle = atom.GetAngle(flex_atom, ligand_atom) if angle > HBOND_ANGLE: angle_flag = 1 break else: for hydrogen in h_list: angle = atom.GetAngle(hydrogen, ligand_atom) if angle > HBOND_ANGLE: angle_flag = 1 break if angle_flag: if self.simplified: simp |= self.h_donor[self.AA_name]['bitarray'] if self.full: full |= bitarray('0001000') if self.full_nobb: full_nobb |= bitarray('0001000') interaction_flags[3] = 1 break if interaction_flags[3]: break if possible_interactions[3]: for ligand_id, h_list in zip(ligand_atom_group['h_donor'], ligand_atom_group['h_donorh']): ligand_atom = ligand.GetAtomById(ligand_id) for atom in self.atomGroup['h_accept']: distance = ligand_atom.GetDistance(atom) if distance <= HBOND: angle_flag = 0 for h in h_list: hydrogen = ligand.GetAtomById(h) angle = ligand_atom.GetAngle(hydrogen, atom) if angle > HBOND_ANGLE: angle_flag = 1 break if angle_flag: if self.simplified: simp |= self.h_accept[self.AA_name]['bitarray'] if self.full: full |= bitarray('0000100') if self.full_nobb: full_nobb |= bitarray('0000100') interaction_flags[4] = 1 if interaction_flags[4]: break if possible_interactions[4]: for ligand_id in ligand_atom_group['negative']: ligand_atom = ligand.GetAtomById(ligand_id) for atom in self.atomGroup['positive']: distance = ligand_atom.GetDistance(atom) if distance <= ELECTROSTATIC: if self.simplified: simp |= self.positive[self.AA_name]['bitarray'] if self.full: full |= bitarray('0000010') if self.full_nobb: full_nobb |= bitarray('0000010') interaction_flags[5] = 1 break if interaction_flags[5]: break if possible_interactions[5]: for ligand_id in ligand_atom_group['positive']: ligand_atom = ligand.GetAtomById(ligand_id) for atom in self.atomGroup['negative']: distance = ligand_atom.GetDistance(atom) if distance <= ELECTROSTATIC: if self.simplified: simp |= self.negative[self.AA_name]['bitarray'] if self.full: full |= bitarray('0000001') if self.full_nobb: full_nobb |= bitarray('0000001') interaction_flags[6] = 1 break if interaction_flags[6]: break if self.full: if ligand_atom_group['interactions'][0]: for ligand_id in ligand_atom_group['hydrophobic']: ligand_atom = ligand.GetAtomById(ligand_id) bb_atom = self.heavyatoms[1] distance = ligand_atom.GetDistance(bb_atom) if distance <= HYDROPHOBIC: full |= bitarray('1000000') break notPRO = False if self.AA_name == 'PRO' else True if ligand_atom_group['interactions'][3] & notPRO: for ligand_id in ligand_atom_group['h_accept']: bb_atom = self.heavyatoms[0] ligand_atom = ligand.GetAtomById(ligand_id) distance = ligand_atom.GetDistance(bb_atom) if distance <= HBOND: hydrogen = self.hydrogens[0] angle = bb_atom.GetAngle(hydrogen, ligand_atom) if angle > HBOND_ANGLE: full |= bitarray('0001000') break if ligand_atom_group['interactions'][2]: for ligand_id, h_list in zip(ligand_atom_group['h_donor'], ligand_atom_group['h_donorh']): ligand_atom = ligand.GetAtomById(ligand_id) bb_atom = self.heavyatoms[3] distance = ligand_atom.GetDistance(bb_atom) if distance <= HBOND: angle_flag = 0 for h in h_list: hydrogen = ligand.GetAtomById(h) angle = ligand_atom.GetAngle(hydrogen, bb_atom) if angle > HBOND_ANGLE: angle_flag = 1 break if angle_flag: full |= bitarray('0000100') break
print(mssg) print('#' * len(mssg)) if fingerprint == 'SIMPLE' or fingerprint == 'PBS': # Read all ligands ligands_mols = list(pybel.readfile(extension_ligand, filename_ligand)) # Create ligands all atoms (except hydrogens) dictionary ligands_all_atoms = find_ligands_all_atoms(ligands_mols) # Fill the RESULTS dictionary of keys - ligand ids and values - lists of 0 for ligand_name in ligands_all_atoms.keys(): RESULTS[ligand_name] = [0] * RNA_LENGTH * FUNCTIONS[fingerprint] for residue in openbabel.OBResidueIter( structure.OBMol): # Loop over all RNA residues RNA_residues.append( str(residue.GetNum()) + ':' + str(residue.GetChain())) RNA_nucleotides.append(str(residue.GetName())) for ligand_name, ligand_atoms in ligands_all_atoms.items(): centroid_ligand = centroid(ligand_atoms) if fingerprint == 'SIMPLE': result = calculate_SIMPLE(residue, ligand_name, ligand_atoms, centroid_ligand) if result[-1] != 0: assign_interactions_results(result, RESULTS, RNA_LENGTH, len(RNA_residues) - 1,
newfile = open(F'{pdb_code}_{chain_letter}.pdb', 'w+') for i in range(len(lines)): line = lines[i] if line[0:6] == "ATOM " and line[16:17] != 'B': if line[21:22] == chain_letter: newfile.write(line) newfile.close() obconv.ReadFile(protein, F'{pdb_code}_{chain_letter}.pdb') os.chdir('/Users/andyjiang/Documents/sherrill/CCProtein/') for res in ob.OBResidueIter(protein): mol = Cap(protein, res.GetNum()) print(res.GetNum(), GetCharge(mol), mol.NumAtoms()) obconv.WriteFile( mol, F"{pdb_code}/{pdb_code}_{chain_letter}_{res.GetNum()}_capped.xyz") resFile = open( F"{pdb_code}/{pdb_code}_{chain_letter}_{res.GetNum()}_capped.xyz", "r") resLines = resFile.readlines() resFile.close() newResFile = open( F"{pdb_code}/{pdb_code}_{chain_letter}_{res.GetNum()}_capped.xyz", "w") newResFile.write(resLines[0]) newResFile.write(F'{GetCharge(mol)} 1\n')