def screen_molecules(screener, mols_to_screen, activity, conformers_dir, output_name): """Run the ligand screener and write out the screened conformations. Return sorted list of ranked scores. :param screener: :param mols_to_screen: Screening set :param activity: 1 if the molecule is active, 0 if it's a decoy :param nconformers: Number of conformers to screen for each molecule in screening set :param nthreads: Number of threads on which to run the conformer generation :param output_name: File name for the result molecules :return: sorted list of ranked scores """ screen_set = [m for m in MoleculeReader(mols_to_screen) ] ### Read the molecules to screen scores = [] molwriter = MoleculeWriter(output_name) for mol in screen_set: mol_id = mol.identifier list_of_conformers_files = read_mol2_file(conformers_dir) for conformers_file in list_of_conformers_files: if conformers_file.startswith(mol_id): print(conformers_file) conformers_file_path = os.path.join(conformers_dir, conformers_file) print(conformers_file_path) conformers = [[ x for x in MoleculeReader(conformers_file_path) ]] print(type(conformers)) print("yeah!!!!!! start screening") res = screener.screen(conformers) # Screening step scores.extend([(r.score, activity, r.identifier) for r in res]) # Write results for r in res: molwriter.write(r.molecule) molwriter.close() return sorted(scores)
def prepare_ligand_for_dock(self): """ :return: """ # TODO: behaviour in case there's several ligands in the file? lig = MoleculeReader(self.input_ligand_path)[0] # Apply to our supplied ligand the same functions that ligand_prep would to a CSD entry. lig.identifier = self.lig_name # Note -> self.lig_name should be the name of the query ligand, not the reference (unless they are same) lig.remove_unknown_atoms() lig.assign_bond_types() # Standrdises to CSD conventions - not entirely sure if this is necessary. lig.standardise_aromatic_bonds() lig.standardise_delocalised_bonds() # Does it matter what oder you protonate and assign hydrogens in? Docker.LigandPreparation()._protonation_rules.apply_rules( lig._molecule) lig.add_hydrogens() if self.minimise_ligand: # If the ligand has no 3D coordinates, the minimisation won't work. So let's generate some: if not lig.is_3d: print( f'Input ligand {lig.identifier} has no 3D coords. Generating 3D coords' ) lig = ccdc_mol_from_smiles(smiles=lig.smiles, identifier=lig.identifier) # Minimise the ligand conformation molminimiser = MoleculeMinimiser() lig = molminimiser.minimise(lig) print('Checking if ligand sucessfully minimised', type(lig)) # Save the prepped ligand: ligwr = MoleculeWriter(self.prepared_ligand_path) ligwr.write(lig)
def prepare_protein_for_dock(self): """ :return: """ prot = Protein.from_file(self.input_protein_path) prot.identifier = self.prot_name prot.remove_all_waters() prot.remove_all_metals() prot.add_hydrogens() prot.detect_ligand_bonds() for l in prot.ligands: print(l.identifier) prot.remove_ligand(l.identifier) print('Ligands reminaing {}'.format(len(prot.ligands))) # Save the protein protwr = MoleculeWriter(self.prepared_protein_path) protwr.write(prot)
def screen_molecules(screener, mols_to_screen, activity, nconformers, output_name): """Run the ligand screener and write out the screened conformations. Return sorted list of ranked scores. :param screener: :param mols_to_screen: Screening set :param activity: 1 if the molecule is active, 0 if it's a decoy :param nconformers: Number of conformers to screen for each molecule in screening set :param nthreads: Number of threads on which to run the conformer generation :param output_name: File name for the result molecules :return: sorted list of ranked scores """ screen_set = [m for m in MoleculeReader(mols_to_screen) ] ### Read the molecules to screen scores = [] molwriter = MoleculeWriter(output_name) for mol in screen_set: # If nconformers=0 the input conformation is used, otherwise the CSD-driven conformer # generator is called and a number of conformations equal to nconformers is generated. if nconformers == 0: confs = [[standardise(mol)]] else: try: confs = generate_confs(mol, nconformers, nthreads) except: confs = [[standardise(mol)]] res = screener.screen(confs) # Screening step scores.extend([(r.score, activity, r.identifier) for r in res]) # Write results for r in res: molwriter.write(r.molecule) molwriter.close() return sorted(scores)