Exemplo n.º 1
0
def rdkit_to_ccdc(mol):
    """
    Convert RDKit mol to CCDC mol
    :param mol:
    :return:
    """
    ccdc_mol = Molecule.from_string(Chem.MolToMolBlock(mol), format='mol')
    ccdc_mol.identifier = mol.GetProp("_Name")
    return ccdc_mol
    def dock(self, number_poses=100):
        """

        :return:
        """
        # Set up protein and ligand, in case they need to be

        if self.prepare_protein:
            self.prepare_protein_for_dock()

        if self.prepare_ligand:
            self.prepare_ligand_for_dock()

        reference_ligand = MoleculeReader(self.reference_ligand_path)[0]
        prepared_protein = Protein.from_file(self.prepared_protein_path)
        prepared_ligand = MoleculeReader(self.prepared_ligand_path)[0]

        if self.substructure:
            substr_string = make_substructure_molecule(
                template_mol_path=self.reference_ligand_path,
                query_mol_path=self.prepared_ligand_path)
            substructure = Molecule.from_string(substr_string, format='sdf')
            with MoleculeWriter(
                    str(
                        Path(self.gold_results_directory,
                             f"{self.lig_name}_substructure.sdf"))) as sdfwr:
                sdfwr.write(substructure)

        # Set up the docking run
        docker = Docker()
        docker._conf_file_name = self.conf_file_location
        docker_settings = docker.settings
        # Prevent it from generating a ton of output ligand files - the ranked docks are in 'concat_ranked_docked_ligands.mol2'
        docker_settings._settings.set_delete_rank_files(True)
        docker_settings._settings.set_delete_empty_directories(True)
        docker_settings._settings.set_delete_all_initialised_ligands(True)
        docker_settings._settings.set_delete_all_solutions(True)
        docker_settings._settings.set_delete_redundant_log_files(True)
        docker_settings._settings.set_save_lone_pairs(False)

        # Set up the binding site. Since the sites are based on ragment hits, generate a binding site around the starting hit.
        docker_settings.reference_ligand_file = self.reference_ligand_path
        docker_settings.binding_site = docker_settings.BindingSiteFromLigand(
            prepared_protein, reference_ligand, 6.0)
        # Default distance around ligand is 6 A. Should be ok for small fragments.

        docker_settings.add_protein_file(self.prepared_protein_path)
        docker_settings.diverse_solutions = self.diverse_solutions
        # Try a template similarity restraint:
        #
        if self.substructure:
            try:
                docker_settings.add_constraint(
                    docker_settings.ScaffoldMatchConstraint(substructure))
            except Exception as e:
                docker_settings.add_constraint(
                    docker_settings.TemplateSimilarityConstraint(
                        'all', reference_ligand, weight=75.0))
                txtstr = 'Substructure search failed. Using template similarity'
                log_file = Path(self.results_directory, 'pipeline_error.log')
                log_file.write_text(txtstr)

        else:
            docker_settings.add_constraint(
                docker_settings.TemplateSimilarityConstraint('all',
                                                             reference_ligand,
                                                             weight=150.0))

        # Choose the fitness function: options: ['goldscore', 'chemscore', 'asp', 'plp']. plp is the default.
        docker_settings.fitness_function = 'plp'
        docker_settings.autoscale = self.autoscale
        docker_settings.early_termination = False
        docker_settings.output_directory = self.gold_results_directory
        docker_settings.output_file = str(
            Path(self.results_directory, 'concat_ranked_docked_ligands.mol2'))

        # Add the ligand
        docker_settings.add_ligand_file(
            self.prepared_ligand_path, number_poses
        )  # Second argument determines how many poses are saved

        # Perform the docking:
        gold_result = docker.dock(file_name=self.conf_file_location)
        # pickle.dump(obj=gold_result,file=Path(self.results_directory, 'gold_result').open())
        self.docking_result = gold_result

        return gold_result