def main(argv=[__name__]):

    itf = oechem.OEInterface(InterfaceData)

    if not oechem.OEParseCommandLine(itf, argv):
        oechem.OEThrow.Fatal("Unable to interpret command line!")

    # @ <SNIPPET-ALTLOCFACT-FLAVOR>
    ims = oechem.oemolistream()
    ims.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_ALTLOC)
    # @ </SNIPPET-ALTLOCFACT-FLAVOR>

    inputFile = itf.GetString("-in")
    if not ims.open(inputFile):
        oechem.OEThrow.Fatal("Unable to open %s for reading." % inputFile)

    if not oechem.OEIs3DFormat(ims.GetFormat()):
        oechem.OEThrow.Fatal("%s is not in a 3D format." % inputFile)

    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ims, mol):
        oechem.OEThrow.Fatal("Unable to read %s." % inputFile)

    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)

    # @ <SNIPPET-ALTLOCFACT-PRIMARY>
    alf = oechem.OEAltLocationFactory(mol)
    if alf.GetGroupCount() != 0:
        alf.MakePrimaryAltMol(mol)
    # @ </SNIPPET-ALTLOCFACT-PRIMARY>

    # @ <SNIPPET-PLACE-HYDROGENS-BASIC>
    if oechem.OEPlaceHydrogens(mol):
        # ...
        # @ </SNIPPET-PLACE-HYDROGENS-BASIC>
        print("success")

    # @ <SNIPPET-PLACE-HYDROGENS-OPTIONS>
    opt = oechem.OEPlaceHydrogensOptions()
    opt.SetStandardizeBondLen(False)
    # @ </SNIPPET-PLACE-HYDROGENS-OPTIONS>

    # @ <SNIPPET-PLACE-HYDROGENS-DETAILS>
    # given molecule mol and OEPlaceHydrogensOptions opt...
    details = oechem.OEPlaceHydrogensDetails()
    if oechem.OEPlaceHydrogens(mol, details, opt):
        print(details.Describe())
    # @ </SNIPPET-PLACE-HYDROGENS-DETAILS>

    ims.close()
Beispiel #2
0
    def addh(self, altProcess='occupancy', processName='fullsearch', \
            ihopt=T, standardize=T, badclash=0.4, flipbias=1.0, maxStates=20):#7):

        imol = self.mol.CreateCopy()

        wp = oechem.OEPlaceHydrogensWaterProcessing_Ignore
        if processName == 'fullsearch':
            wp = oechem.OEPlaceHydrogensWaterProcessing_FullSearch
        elif processName == 'focused':
            wp = oechem.OEPlaceHydrogensWaterProcessing_Focused

        keepAlts = (altProcess != "a")
        highestOcc = (altProcess == "occupancy")
        compareAlts = (altProcess == "compare")
        print('#1')
        if highestOcc or compareAlts:
            alf = oechem.OEAltLocationFactory(imol)
            if alf.GetGroupCount() != 0:
                if highestOcc:
                    oechem.OEThrow.Verbose(
                        "Dropping alternate locations from input.")
                    alf.MakePrimaryAltMol(imol)
                elif compareAlts:
                    oechem.OEThrow.Verbose("Fixing alternate location issues.")
                    imol = alf.GetSourceMol()
        omol = imol
        print('#2')
        oechem.OEThrow.Verbose("Adding hydrogens to complex.")

        hopt = oechem.OEPlaceHydrogensOptions()
        if ihopt:
            hopt.SetAltsMustBeCompatible(compareAlts)
            hopt.SetStandardizeBondLen(standardize)
            hopt.SetWaterProcessing(wp)
            hopt.SetBadClashOverlapDistance(badclash)
            hopt.SetFlipBiasScale(flipbias)
            hopt.SetMaxSubstateCutoff(maxStates)

        if self.verbose:
            print('#3')
            details = oechem.OEPlaceHydrogensDetails()
            if not oechem.OEPlaceHydrogens(omol, details, hopt):
                oechem.OEThrow.Fatal(
                    "Unable to place hydrogens and get details on %s." %
                    self.inmol.GetTitle())
            oechem.OEThrow.Verbose(details.Describe())
        else:
            if not oechem.OEPlaceHydrogens(omol, hopt):
                oechem.OEThrow.Fatal("Unable to place hydrogens on %s." %
                                     self.inmol.GetTitle())
        self.mol = omol
Beispiel #3
0
    def _prepare_ligand_template(
        self, ligand_template: pd.Series, kinase_domain: oechem.OEGraphMol
    ) -> oechem.OEGraphMol:
        """
        Prepare a PDB structure containing the ligand template of interest.
        Parameters
        ----------
        ligand_template: pd.Series
            A data series containing entries 'pdb', 'chain', 'ligand' and 'alt'.
        kinase_domain: oechem.OEGraphMol
            An OpenEye molecule holding the kinase domain the ligand template structure should be superposed to.
        Returns
        -------
        : oechem.OEGraphMol
            An OpenEye molecule holding the prepared ligand structure.
        """
        from openeye import oechem
        from ..modeling.OEModeling import (
            read_molecules,
            select_chain,
            select_altloc,
            remove_non_protein,
            superpose_proteins,
        )
        from ..utils import FileDownloader

        logging.debug("Interpreting structure ...")
        ligand_template_structure = PDBProtein(ligand_template.pdb)
        if not ligand_template_structure.path.is_file():
            logging.debug(f"Downloading PDB entry {ligand_template.pdb} ...")
            FileDownloader.rcsb_structure_pdb(ligand_template.pdb)
        logging.debug("Reading structure ...")
        ligand_template_structure = read_molecules(ligand_template_structure.path)[0]

        logging.debug("Selecting chain ...")
        ligand_template_structure = select_chain(ligand_template_structure, ligand_template.chain)

        logging.debug("Selecting alternate location ...")
        ligand_template_structure = select_altloc(ligand_template_structure, ligand_template.alt)

        logging.debug("Removing everything but protein, water and ligand of interest ...")
        ligand_template_structure = remove_non_protein(
            ligand_template_structure, exceptions=[ligand_template.ligand], remove_water=False
        )

        logging.debug("Superposing structure on kinase domain ...")
        ligand_template_structure = superpose_proteins(kinase_domain, ligand_template_structure)

        logging.debug("Adding hydrogens ...")
        oechem.OEPlaceHydrogens(ligand_template_structure)
        split_options = oechem.OESplitMolComplexOptions()

        logging.debug("Extracting ligand ...")
        ligand_template_structure = list(
            oechem.OEGetMolComplexComponents(
                ligand_template_structure, split_options, split_options.GetLigandFilter()
            )
        )[0]

        return ligand_template_structure
def read_graph_mol(fname):
    ifs = oechem.oemolistream(fname)
    mol = oechem.OEGraphMol()
    with oechem.oemolistream(fname) as ifs:
        oechem.OEReadMolecule(ifs, mol)
    oechem.OEPlaceHydrogens(mol)
    return mol
Beispiel #5
0
    def _assemble_complex(protein: oechem.OEGraphMol,
                          solvent: oechem.OEGraphMol,
                          ligand: oechem.OEGraphMol) -> oechem.OEGraphMol:
        """
        Assemble components of a solvated protein-ligand complex into a single
        OpenEye molecule. Water molecules will be checked for clashes with the ligand.

        Parameters
        ----------
        protein: oechem.OEGraphMol
            An OpenEye molecule holding the protein of interest.
        solvent: oechem.OEGraphMol
            An OpenEye molecule holding the solvent of interest.
        ligand: oechem.OEGraphMol
            An OpenEye molecule holding the ligand of interest.

        Returns
        -------
        protein_ligand_complex: oechem.OEGraphMol
            An OpenEye molecule holding protein, ligand and solvent.
        """
        from openeye import oechem

        from ..modeling.OEModeling import (
            clashing_atoms,
            update_residue_identifiers,
            split_molecule_components,
        )

        protein_ligand_complex = oechem.OEGraphMol()

        logging.debug("Adding protein ...")
        oechem.OEAddMols(protein_ligand_complex, protein)

        logging.debug("Adding ligand ...")
        oechem.OEAddMols(protein_ligand_complex, ligand)

        logging.debug("Adding water molecules ...")
        # converts solvent molecule into a list of water molecules
        water_molecules = split_molecule_components(solvent)
        for water_molecule in water_molecules:  # TODO: slow, move to cKDtrees
            if not clashing_atoms(ligand, water_molecule):
                oechem.OEAddMols(protein_ligand_complex, water_molecule)

        logging.debug("Updating hydrogen positions ...")
        oechem.OEPlaceHydrogens(protein_ligand_complex)

        logging.debug("Updating residue identifiers ...")
        protein_ligand_complex = update_residue_identifiers(
            protein_ligand_complex)

        return protein_ligand_complex
Beispiel #6
0
def main(argv=[__name__]):

    itf = oechem.OEInterface(InterfaceData)

    if not oechem.OEParseCommandLine(itf, argv):
        oechem.OEThrow.Fatal("Unable to interpret command line!")

    ims = oechem.oemolistream()
    ims.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_ALTLOC)

    inputFile = itf.GetString("-in")
    if not ims.open(inputFile):
        oechem.OEThrow.Fatal("Unable to open %s for reading." % inputFile)

    if not oechem.OEIs3DFormat(ims.GetFormat()):
        oechem.OEThrow.Fatal("%s is not in a 3D format." % inputFile)

    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ims, mol):
        oechem.OEThrow.Fatal("Unable to read %s." % inputFile)

    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)

    alf = oechem.OEAltLocationFactory(mol)
    if alf.GetGroupCount() != 0:
        alf.MakePrimaryAltMol(mol)

    # in our example, we will select the first histidine
    selectedResidue = oechem.OEResidue()
    for atom in mol.GetAtoms():
        res = oechem.OEAtomGetResidue(atom)
        if oechem.OEGetResidueIndex(res) == oechem.OEResidueIndex_HIS:
            selectedResidue = res
            break

    # @ <SNIPPET-PLACE-HYDROGENS-PRED>
    # given predicate IsSameResidue, residue selectedResidue and molecule mol...
    opt = oechem.OEPlaceHydrogensOptions()
    opt.SetNoFlipPredicate(IsSameResidue(selectedResidue))

    if oechem.OEPlaceHydrogens(mol, opt):
        # selectedResidue will not be flipped...
        # @ </SNIPPET-PLACE-HYDROGENS-PRED>
        print("success")

    ims.close()
Beispiel #7
0
def mutate_structure(target_structure: oechem.OEGraphMol,
                     template_sequence: str) -> oechem.OEGraphMol:
    """
    Mutate a protein structure according to an amino acid sequence.
    Parameters
    ----------
    target_structure: oechem.OEGraphMol
        An OpenEye molecule holding a protein structure to mutate.
    template_sequence: str
        A template one letter amino acid sequence, which defines the sequence the target structure should be mutated
        to. Protein residues not matching a template sequence will be either mutated or deleted.
    Returns
    -------
    mutated_structure: oechem.OEGraphMol
        An OpenEye molecule holding the mutated protein structure.
    """
    from Bio import pairwise2

    # the hierarchy view is more stable if reinitialized after each change
    # https://docs.eyesopen.com/toolkits/python/oechemtk/biopolymers.html#a-hierarchy-view
    finished = False
    while not finished:
        altered = False
        # align template and target sequences
        target_sequence = get_sequence(target_structure)
        template_sequence_aligned, target_sequence_aligned = pairwise2.align.globalxs(
            template_sequence, target_sequence, -10, 0)[0][:2]
        logging.debug(f"Template sequence:\n{template_sequence}")
        logging.debug(f"Target sequence:\n{target_sequence}")
        hierview = oechem.OEHierView(target_structure)
        structure_residues = hierview.GetResidues()
        # adjust target structure to match template sequence
        for template_sequence_residue, target_sequence_residue in zip(
                template_sequence_aligned, target_sequence_aligned):
            if template_sequence_residue == "-":
                # delete any non protein residue from target structure
                structure_residue = structure_residues.next()
                if target_sequence_residue != "X":
                    # delete
                    for atom in structure_residue.GetAtoms():
                        target_structure.DeleteAtom(atom)
                    # break loop and reinitialize
                    altered = True
                    break
            else:
                # compare amino acids
                if target_sequence_residue != "-":
                    structure_residue = structure_residues.next()
                    if target_sequence_residue not in [
                            "X", template_sequence_residue
                    ]:
                        # mutate
                        structure_residue = structure_residue.GetOEResidue()
                        three_letter_code = oechem.OEGetResidueName(
                            oechem.OEGetResidueIndexFromCode(
                                template_sequence_residue))
                        oespruce.OEMutateResidue(target_structure,
                                                 structure_residue,
                                                 three_letter_code)
                        # break loop and reinitialize
                        altered = True
                        break
        # leave while loop if no changes were introduced
        if not altered:
            finished = True
    # OEMutateResidue doesn't build sidechains and doesn't add hydrogens automatically
    oespruce.OEBuildSidechains(target_structure)
    oechem.OEPlaceHydrogens(target_structure)
    # update residue information
    oechem.OEPerceiveResidues(target_structure, oechem.OEPreserveResInfo_All)

    return target_structure