def main(argv):
    if len(argv) != 2:
        oechem.OEThrow.Usage("%s <receptor>" % argv[0])

    receptor = oechem.OEGraphMol()
    oedocking.OEReadReceptorFile(receptor, argv[1])

    # @ <SNIPPET-RECEPTOR-PROTEIN-CONSTRAINT-EDITING-1>
    for constraint in oedocking.OEReceptorGetProteinConstraints(receptor):
        print("Atom %i has a constraint" % constraint.GetAtom().GetIdx())
    # @ </SNIPPET-RECEPTOR-PROTEIN-CONSTRAINT-EDITING-1>

    # @ <SNIPPET-RECEPTOR-PROTEIN-CONSTRAINT-EDITING-2>
    for constraint in oedocking.OEReceptorGetProteinConstraints(receptor):
        print("Protein constraint on atom  %d" % constraint.GetAtom().GetIdx())
        print("  Type :  %s" % oedocking.OEProteinConstraintTypeGetName(constraint.GetType()))
        print("  Name :  %s" % constraint.GetName())
    # @ </SNIPPET-RECEPTOR-PROTEIN-CONSTRAINT-EDITING-2>

    for heavyAtom in receptor.GetAtoms(oechem.OENotAtom(oechem.OEIsHydrogen())):
        # @ <SNIPPET-RECEPTOR-PROTEIN-CONSTRAINT-EDITING-3>
        proteinConstraint = oedocking.OEProteinConstraint()
        proteinConstraint.SetAtom(heavyAtom)
        proteinConstraint.SetType(oedocking.OEProteinConstraintType_Contact)
        proteinConstraint.SetName("Example constraint")
        oedocking.OEReceptorSetProteinConstraint(receptor, proteinConstraint)
        # @ </SNIPPET-RECEPTOR-PROTEIN-CONSTRAINT-EDITING-3>
        break

    # @ <SNIPPET-RECEPTOR-PROTEIN-CONSTRAINT-EDITING-4>
    oedocking.OEReceptorClearProteinConstraints(receptor)
def GetFragmentScore(mol):

    score = 0.0
    score += 2.0 * oechem.OECount(mol, oechem.OEAtomIsInRing())
    score += 1.0 * oechem.OECount(mol, oechem.OENotAtom(oechem.OEAtomIsInRing()))

    return score
Ejemplo n.º 3
0
    def AddRelevantRingAtoms(mol, torsion, torsionSet):
        atom1or2 = oechem.OEOrAtom(oechem.OEHasMapIdx(1),
                                   oechem.OEHasMapIdx(2))
        ringNbrs = []
        for atom in mol.GetAtoms(
                oechem.OEAndAtom(oechem.OEAtomIsInRing(), atom1or2)):
            for nbr in atom.GetAtoms(
                    oechem.OEAndAtom(oechem.OENotAtom(atom1or2),
                                     oechem.OENotAtom(
                                         oechem.OEAtomIsInRing()))):
                if nbr.IsHydrogen():
                    ringNbrs.append(nbr)
                    continue

                if nbr.IsOxygen() and mol.GetBond(atom, nbr).GetOrder() == 2:
                    ringNbrs.append(nbr)
                    continue

                if TorsionGenerator.IsOrtho(nbr, torsion):
                    ringNbrs.append(nbr)
        for nbr in ringNbrs:
            if not torsionSet.HasAtom(nbr):
                nbr.SetMapIdx(2)
                torsionSet.AddAtom(nbr)
Ejemplo n.º 4
0
def has_undesirable_elements(mol):
    '''
    returns True if molecule contains any element other than
    H, C, N, O, F, S, Cl, or P
    @param mol:
    @type mol: OEGraphMol
    @return: bool
    '''
    atomsHC = oechem.OEOrAtom(oechem.OEIsHydrogen(), oechem.OEIsCarbon())
    atomsNO = oechem.OEOrAtom(oechem.OEIsNitrogen(), oechem.OEIsOxygen())
    atomsFS = oechem.OEOrAtom(oechem.OEHasAtomicNum(9), oechem.OEIsSulfur())
    atomsHCNO = oechem.OEOrAtom(atomsHC, atomsNO)
    atomsHCNOFS = oechem.OEOrAtom(atomsHCNO, atomsFS)
    atomsHCNOFSCl = oechem.OEOrAtom(atomsHCNOFS, oechem.OEHasAtomicNum(17))
    atomsHCNOFSClP = oechem.OEOrAtom(atomsHCNOFSCl, oechem.OEIsPhosphorus())

    undesirable_atom = mol.GetAtom(oechem.OENotAtom(atomsHCNOFSClP))
    if undesirable_atom is not None:
        return True

    return False
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be
# liable for any damages or liability in connection with the Sample Code
# or its use.

# @ <SNIPPET>
from __future__ import print_function
from openeye import oechem

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cnc(O)cc1CCCBr")

print("Number of chain atoms =", end=" ")
print(oechem.OECount(mol, oechem.OENotAtom(oechem.OEAtomIsInRing())))

print("Number of aromatic nitrogens =", end=" ")
print(
    oechem.OECount(
        mol, oechem.OEAndAtom(oechem.OEIsNitrogen(),
                              oechem.OEIsAromaticAtom())))

print("Number of non-carbons =", end=" ")
print(
    oechem.OECount(mol,
                   oechem.OENotAtom(oechem.OEHasAtomicNum(oechem.OEElemNo_C))))

print("Number of nitrogen and oxygen atoms =", end=" ")
print(
    oechem.OECount(
Ejemplo n.º 6
0
def _oe_render_fragment(
    parent: Molecule,
    fragment: Molecule,
    bond_indices: BondTuple,
    image_width: int = 283,
    image_height: int = 169,
) -> str:

    from openeye import oechem, oedepict

    # Map the OpenFF molecules into OE ones, making sure to explicitly set the atom
    # map on the OE object as this is not handled by the OpenFF toolkit.
    oe_parent = parent.to_openeye()

    for atom in oe_parent.GetAtoms():
        atom.SetMapIdx(get_map_index(parent, atom.GetIdx(), False))

    oedepict.OEPrepareDepiction(oe_parent)

    oe_fragment = fragment.to_openeye()

    for atom in oe_fragment.GetAtoms():
        atom.SetMapIdx(get_map_index(fragment, atom.GetIdx(), False))

    oe_parent_bond = oe_parent.GetBond(
        oe_parent.GetAtom(oechem.OEHasMapIdx(bond_indices[0])),
        oe_parent.GetAtom(oechem.OEHasMapIdx(bond_indices[1])),
    )

    # Set-up common display options.
    image = oedepict.OEImage(image_width, image_height)

    display_options = oedepict.OE2DMolDisplayOptions(
        image_width, image_height, oedepict.OEScale_AutoScale)

    display_options.SetTitleLocation(oedepict.OETitleLocation_Hidden)
    display_options.SetAtomColorStyle(
        oedepict.OEAtomColorStyle_WhiteMonochrome)
    display_options.SetAtomLabelFontScale(1.2)

    # display_options.SetBondPropertyFunctor(_oe_wbo_label_display({bond_indices}))

    display = oedepict.OE2DMolDisplay(oe_parent, display_options)

    fragment_atom_predicate, fragment_bond_predicate = _oe_fragment_predicates(
        {atom.GetMapIdx()
         for atom in oe_fragment.GetAtoms()})

    not_fragment_atoms = oechem.OENotAtom(fragment_atom_predicate)
    not_fragment_bonds = oechem.OENotBond(fragment_bond_predicate)

    oedepict.OEAddHighlighting(
        display,
        oedepict.OEHighlightByColor(oechem.OEGrey, 0.75),
        not_fragment_atoms,
        not_fragment_bonds,
    )

    rotatable_bond = oechem.OEAtomBondSet()

    rotatable_bond.AddBond(oe_parent_bond)
    rotatable_bond.AddAtom(oe_parent_bond.GetBgn())
    rotatable_bond.AddAtom(oe_parent_bond.GetEnd())

    oedepict.OEAddHighlighting(
        display,
        oechem.OEColor(oechem.OELimeGreen),
        oedepict.OEHighlightStyle_BallAndStick,
        rotatable_bond,
    )

    oedepict.OERenderMolecule(image, display)

    svg_contents = oedepict.OEWriteImageToString("svg", image)
    return svg_contents.decode()
Ejemplo n.º 7
0
def DepictMoleculeWithFragmentCombinations(report, mol, frags, opts): #fragcombs, opts):
    """ This function was taken from https://docs.eyesopen.com/toolkits/cookbook/python/depiction/enumfrags.html with some modification
    """
    stag = "fragment idx"
    itag = oechem.OEGetTag(stag)
    for fidx, frag in enumerate(frags):
        for bond in frags[frag].GetBonds():
            bond.SetData(itag, fidx)

    # setup depiction styles

    nrfrags = len(frags)
    colors = [c for c in oechem.OEGetLightColors()]
    if len(colors) < nrfrags:
        colors = [c for c in oechem.OEGetColors(oechem.OEYellowTint, oechem.OEDarkOrange, nrfrags)]

    bondglyph = ColorBondByFragmentIndex(colors, itag)

    lineWidthScale = 0.75
    fadehighlight = oedepict.OEHighlightByColor(oechem.OEGrey, lineWidthScale)

    # depict each fragment combinations

    for frag in frags:

        cell = report.NewCell()
        disp = oedepict.OE2DMolDisplay(mol, opts)

        fragatoms = oechem.OEIsAtomMember(frags[frag].GetAtoms())
        fragbonds = oechem.OEIsBondMember(frags[frag].GetBonds())

        notfragatoms = oechem.OENotAtom(fragatoms)
        notfragbonds = oechem.OENotBond(fragbonds)

        oedepict.OEAddHighlighting(disp, fadehighlight, notfragatoms, notfragbonds)

        bond = mol.GetBond(oechem.OEHasBondIdx(frag))

        atomBondSet = oechem.OEAtomBondSet()
        atomBondSet.AddBond(bond)
        atomBondSet.AddAtom(bond.GetBgn())
        atomBondSet.AddAtom(bond.GetEnd())

        hstyle = oedepict.OEHighlightStyle_BallAndStick
        hcolor = oechem.OEColor(oechem.OELightBlue)
        oedepict.OEAddHighlighting(disp, hcolor, hstyle, atomBondSet)

        #oegrapheme.OEAddGlyph(disp, bondglyph, fragbonds)

        oedepict.OERenderMolecule(cell, disp)

    # depict original fragmentation in each header

    cellwidth, cellheight = report.GetHeaderWidth(), report.GetHeaderHeight()
    opts.SetDimensions(cellwidth, cellheight, oedepict.OEScale_AutoScale)
    opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome)

    bondlabel = LabelBondOrder()
    opts.SetBondPropertyFunctor(bondlabel)
    disp = oedepict.OE2DMolDisplay(mol, opts)
    #oegrapheme.OEAddGlyph(disp, bondglyph, oechem.IsTrueBond())

    headerpen = oedepict.OEPen(oechem.OEWhite, oechem.OELightGrey, oedepict.OEFill_Off, 2.0)
    for header in report.GetHeaders():
        oedepict.OERenderMolecule(header, disp)
        oedepict.OEDrawBorder(header, headerpen)
Ejemplo n.º 8
0
    def process(self, record, port):

        try:
            opt = dict(self.opt)

            if not record.has_value(Fields.md_components):
                raise ValueError("Missing the MD Components Field")

            md_components = record.get_value(Fields.md_components)

            solute, map_comp = md_components.create_flask

            if not record.has_value(Fields.title):
                self.log.warn("Missing Title field")
                solute_title = solute.GetTitle()[0:12]
            else:
                solute_title = record.get_value(Fields.title)

            self.log.info("[{}] solvating flask {}".format(
                self.title, solute_title))

            # Update cube simulation parameters
            for field in record.get_fields(include_meta=True):
                field_name = field.get_name()
                if field_name in ['molar_fractions', 'density', 'solvents']:
                    rec_value = record.get_value(field)
                    if field_name == 'molar_fractions':
                        opt[field_name] = str(rec_value)
                    else:
                        opt[field_name] = rec_value
                    opt['Logger'].info(
                        "{} Updating parameters for molecule: {} {} = {}".
                        format(self.title, solute.GetTitle(), field_name,
                               rec_value))
            # Set the flag to return the solvent molecule components
            opt['return_components'] = True

            # Solvate the system
            sol_system, solvent, salt, counter_ions = packmol.oesolvate(
                solute, **opt)

            # Separate the Water from the solvent
            pred_water = oechem.OEIsWater(checkHydrogens=True)
            water = oechem.OEMol()
            oechem.OESubsetMol(water, solvent, pred_water)

            if water.NumAtoms():
                if md_components.has_water:

                    water_comp = md_components.get_water

                    if not oechem.OEAddMols(water_comp, water):
                        raise ValueError(
                            "Cannot add the MD Component Water and the Packmol Water"
                        )

                    md_components.set_water(water_comp)

                else:
                    md_components.set_water(water)

                pred_not_water = oechem.OENotAtom(
                    oechem.OEIsWater(checkHydrogens=True))
                solvent_not_water = oechem.OEMol()
                oechem.OESubsetMol(solvent_not_water, solvent, pred_not_water)

                if solvent_not_water.NumAtoms():
                    solvent = solvent_not_water
                else:
                    solvent = oechem.OEMol()

            self.log.info(
                "[{}] Solvated simulation flask {} yielding {} atoms overall".
                format(self.title, solute_title, sol_system.NumAtoms()))
            sol_system.SetTitle(solute.GetTitle())

            if salt is not None and counter_ions is not None:
                if not oechem.OEAddMols(counter_ions, salt):
                    raise ValueError(
                        "Cannot add the salt component and the counter ion component"
                    )
            elif salt is not None:
                counter_ions = salt
            else:
                pass

            if md_components.has_solvent:
                solvent_comp = md_components.get_solvent
                if not oechem.OEAddMols(solvent_comp, solvent):
                    raise ValueError(
                        "Cannot add the MD Component solvent and the Packmol Solvent"
                    )
            else:
                solvent_comp = solvent

            if solvent_comp.NumAtoms():
                md_components.set_solvent(solvent_comp)

            if counter_ions is not None:
                if md_components.has_counter_ions:
                    counter_ions_comp = md_components.get_counter_ions
                    if not oechem.OEAddMols(counter_ions_comp, counter_ions):
                        raise ValueError(
                            "Cannot add the MD Component counter ions and the Packmol counter ions"
                        )
                else:
                    counter_ions_comp = counter_ions

                md_components.set_counter_ions(counter_ions_comp)

            # Set Box Vectors
            vec_data = pack_utils.getData(sol_system, tag='box_vectors')
            box_vec = pack_utils.decodePyObj(vec_data)
            md_components.set_box_vectors(box_vec)

            flask, map_comp = md_components.create_flask
            record.set_value(Fields.md_components, md_components)
            record.set_value(Fields.flask, flask)
            record.set_value(Fields.title, solute_title)

            self.success.emit(record)

        except Exception as e:

            print("Failed to complete", str(e), flush=True)
            self.opt['Logger'].info('Exception {} {}'.format(
                str(e), self.title))
            self.log.error(traceback.format_exc())
            self.failure.emit(record)

        return