def get_ligands(Protein, ligand_resnames_resnums): """ Takes a HPC_Drug.structures.protein.Protein instance and a ligand_resnames_resnums and updates Protein._ligands with the newly created HPC_Drug.structures.ligand.Ligand instances Protein :: HPC_Drug.structures.protein.Protein, Protein.file_type must be pdb !!! ligand_resnames_resnums :: nested list of type [ ['ligand_resname', ligand_resnum], [...], ... ] if == None or == [] no HPC_Drug.structures.ligand.Ligand instance will be added to Protein._ligands return Protein """ #removes old ligands if any Protein.clear_ligands() #There are no ligands to add if ligand_resnames_resnums == None or ligand_resnames_resnums == []: return Protein if Protein.file_type != 'pdb': raise TypeError( f"This function works only on PDB files, not {Protein.file_type}") #check if ligand_resnames_resnums is a nested list as it should be try: ligand_resnames_resnums[0][0] except: ligand_resnames_resnums = [ligand_resnames_resnums] Protein.update_structure(struct_type="prody") prody_select = prody.ProdySelect(structure=Protein.structure) for i, ligand_name_number in enumerate(ligand_resnames_resnums): Ligand = ligand.Ligand(resname=ligand_name_number[0], pdb_file=None, structure=None, file_type='pdb', tpg_file=None, prm_file=None, resnum=ligand_name_number[1]) Ligand.structure = prody_select.resnum(resnum=Ligand.resnum) Ligand.write(file_name=f"{os.getcwd()}/{Ligand.resname}_lgand{i}.pdb", struct_type="prody") Protein.add_ligand(Ligand=Ligand) return Protein
def separate_protein_ligand(self, Protein = None, Ligand = None): """Takes a Protein instance whose filename is the pdbfile with both the protein and the ligands together and returns the separated biopython structures""" def update_ligand_resnumbers(Protein = self.Protein, Ligand = self.Ligand): """Updates the ligand resnumbers that may be changed because of previous calculations""" if Ligand == None or len(get_iterable.get_iterable(Ligand)) == 0: print("I found no ligand, returning None") return None ligand_resnames = [] for lgand in get_iterable.get_iterable(Ligand): if lgand.resname not in ligand_resnames: ligand_resnames.append(lgand.resname) c = file_manipulation.SubstitutionParser() ligand_resnames = c.get_ligand_resnum(Protein = Protein, ligand_resnames = ligand_resnames, chain_model_selection = False) #now ligand resnames is in the form [[ligand_resname, ligand_resnumber], [..., ...], ...] #Creating a completely new Ligand list Ligand = [] for lgand in ligand_resnames: Ligand.append(ligand.Ligand(resname = lgand[0], pdb_file = None, structure = None, file_type = 'pdb', tpg_file = None, prm_file = None, resnum = lgand[1])) return Ligand if Protein == None: Protein = self.Protein if Ligand == None: Ligand = self.Ligand Ligand = update_ligand_resnumbers(Protein = Protein, Ligand = Ligand) #Extract the protein with ProDy, write a new pdb #and then get the Biopython protein structure tmp_protein = protein.Protein(protein_id= Protein.protein_id, pdb_file = Protein.pdb_file, file_type = Protein.file_type) tmp_protein.update_structure(struct_type = "prody") prody_select = prody.ProdySelect(structure = tmp_protein.structure) tmp_protein.structure = prody_select.protein_and_ions() tmp_protein.write(file_name = f"{Protein.protein_id}_protein.pdb", struct_type = 'prody') Protein.update_structure(struct_type = "biopython") #doing the same thing for every ligand ligand_structures = [] for i, lgand in enumerate(get_iterable.get_iterable(Ligand)): lgand.structure = prody_select.resnum(resnum = lgand.resnum) lgand.write(file_name = f"{Protein.protein_id}_lgand{i}.pdb", struct_type = 'prody') lgand.update_structure(struct_type = "biopython") ligand_structures.append(lgand.structure) return Protein.structure, ligand_structures
def _write_ADD_STR_COM(self): """ private Writes the informations about the bounding between the protein and the ligands """ Ligand = self.Protein.get_ligand_list() if Ligand == [] or Ligand == None: return "" #updates the Protein._ligands self.Protein = update_ligands.update_ligands(Protein=self.Protein) #get a list of ligand structures ligand_structures = [] Ligand = self.Protein.get_ligand_list() for lig in Ligand: lig.update_structure(struct_type="biopython") ligand_structures.append(lig.structure) self.Protein.update_structure(struct_type="prody") #get the only protein biopython structure prody_select_obj = prody.ProdySelect(structure=self.Protein.structure) protein_structure = prody_select_obj.protein_and_ions() prody.write_pdb(structure=protein_structure, file_name=f"{self.Protein.protein_id}_protein.pdb") protein_structure = biopython.parse_pdb( protein_id=self.Protein.protein_id, file_name=f"{self.Protein.protein_id}_protein.pdb") #Get the atom number range of each segment protein_atoms, ligand_atoms = self.orient.protein_ligand_atom_numbers() string = [] #get the distance of the centers of mass of the protein and the ligands #and create the string for i, ligand in enumerate( get_iterable.get_iterable(ligand_structures)): COM_Protein, COM_ligand, distance = self.orient.center_mass_distance( protein_structure, ligand) #These are useless COM_Protein = COM_ligand = None tmp_string = [ " ADD_STR_COM !! linker COM-COM legand protein", f" ligand {ligand_atoms[i][1]} {ligand_atoms[i][0]}", f" target {protein_atoms[1]} {protein_atoms[0]}", f" force 0.15 {distance} {distance+0.0001}", " END" ] tmp_string = '\n'.join(tmp_string) string.append(tmp_string) if len(string) > 1: string = '\n'.join(string) elif len(string) == 0: string = '' else: string = string[0] return string
def execute(self): """ A pipeline that returns a clean and repaired "protein and ions" PDB and a PDB file for any not trash organic lingand starting from both a PDB, an mmCIF file or a protein id returns a Protein instance """ #If requested in input will download pdb file #If the given local file doesn't exist raises FileNotFounfError #otherwise updates self.protein_filename with the given path #all the paths are converted to absolute paths self.get_protein_file() # creating protein instance Protein = protein.Protein(protein_id = self.protein_id, pdb_file = self.protein_filename, model = self.model, chain = self.chain, file_type = self.protein_filetype, tpg_file = self.protein_tpg_file, prm_file = self.protein_prm_file) #Get Protein.substitutions_dict Protein.sulf_bonds #repairs the Protein.pdb_file #returns a list containing the resnames and resnumbers of organic ligands # [[resname, resnum], [...], ...] #if there are none will be None item Info_rep = structural_information_and_repair.InfoRepair(Protein = Protein, repairing_method = self.repairing_method) Protein, ligand_resnames_resnums = Info_rep.get_info_and_repair() #remove still present disordered atoms (if any) Protein = remove_disordered_atoms.remove_disordered_atoms(Protein = Protein) #selects only a selected model and chain (Protein.model Protein.chain) Protein = select_model_chain.select_model_chain(Protein = Protein) #if the protein was a mmCIF I convert it to PDB Protein = mmcif2pdb.mmcif2pdb(Protein = Protein) #create the Ligand instances and add them to Protein._ligands Protein = get_ligands.get_ligands(Protein = Protein, ligand_resnames_resnums = ligand_resnames_resnums) Protein.update_structure(struct_type = "prody") prody_select = prody.ProdySelect(structure = Protein.structure) #gets the protein's structure from the pdb #The only HETATM remaining are the metal ions Protein.structure = prody_select.protein_and_ions() #Write Protein only pdb Protein.write(file_name = f"{Protein.protein_id}_protein.pdb", struct_type = 'prody') #removes the remaining trash ions Protein = remove_trash_metal_ions.remove_trash_metal_ions(Protein = Protein) #quick patch, will do it better #The structure is put in the reference system of the #inertia tensor orient_obj = orient.Orient(Protein = Protein) _, _, Rot_matrix = orient_obj.calculate_moment_of_intertia_tensor() Protein.structure = orient_obj.base_change_structure() Protein.write() Ligand = Protein.get_ligand_list() for i in range(len(Ligand)): Ligand[i].update_structure(struct_type = "biopython") Ligand[i].structure = orient_obj.base_change_structure(structure = Ligand[i].structure, rot_matrix = Rot_matrix) Ligand[i].write() return Protein
def setUpClass(cls): cls.structure = "test" cls.ProdySelect = prody.ProdySelect(cls.structure)