コード例 #1
0
 def test_ring_substituents(self):
     """Test finding ring substituents"""
     tagged_rings, tagged_funcgroup = fragment.tag_molecule(charged)
     bond = charged.GetBond(oechem.OEHasBondIdx(8))
     next_bond = charged.GetBond(oechem.OEHasBondIdx(10))
     ring_idx = next_bond.GetData('ringsystem')
     rs_atoms, rs_bonds = fragment._ring_substiuents(
         charged, next_bond, bond, tagged_rings, ring_idx, tagged_funcgroup)
     self.assertEquals(rs_atoms, {5, 6, 7, 8, 10, 28, 29, 46, 47, 48})
     self.assertEquals(rs_bonds, {5, 6, 7, 8, 30, 31, 49, 50, 51})
コード例 #2
0
 def test_is_ortho(self):
     """Test if substituent is ortho to rotatable bond"""
     rot_bond = charged.GetBond(oechem.OEHasBondIdx(8))
     next_bond = charged.GetBond(oechem.OEHasBondIdx(10))
     ortho_bond = charged.GetBond(oechem.OEHasBondIdx(30))
     self.assertTrue(
         fragment._is_ortho(bond=ortho_bond,
                            rot_bond=rot_bond,
                            next_bond=next_bond))
     other_bond = charged.GetBond(oechem.OEHasBondIdx(31))
     self.assertFalse(
         fragment._is_ortho(bond=other_bond,
                            rot_bond=rot_bond,
                            next_bond=next_bond))
コード例 #3
0
 def test_is_fgroup(self):
     """Test is functional group """
     tagged_rings, taggged_funcgroup = fragment.tag_molecule(charged)
     atom_idx = taggged_funcgroup['amide_0'][0].pop()
     bond_idx = taggged_funcgroup['amide_0'][-1].pop()
     atom = charged.GetAtom(oechem.OEHasAtomIdx(atom_idx))
     bond = charged.GetBond(oechem.OEHasBondIdx(bond_idx))
     self.assertTrue(fragment._is_fgroup(taggged_funcgroup, atom))
     self.assertTrue(fragment._is_fgroup(taggged_funcgroup, bond))
コード例 #4
0
    def test_build_frag(self):
        """ Test build fragment """
        bond = charged.GetBond(oechem.OEHasBondIdx(2))
        tagged_rings, tagged_funcgroup = fragment.tag_molecule(charged)
        atoms, bonds = fragment._build_frag(bond, charged, tagged_funcgroup,
                                            tagged_rings)

        self.assertEquals(atoms, {0, 1, 2, 3, 4, 5, 6, 41, 42, 44})
        self.assertEquals(bonds, {0, 1, 2, 3, 4})
コード例 #5
0
 def test_iterate_nbratoms(self):
     """Test iterate neighboring atoms"""
     rotor_bond = charged.GetBond(oechem.OEHasBondIdx(2))
     beg = rotor_bond.GetBgn()
     end = rotor_bond.GetEnd()
     tagged_rings, tagged_funcgroup = fragment.tag_molecule(charged)
     atoms, bonds = fragment.iterate_nbratoms(charged, rotor_bond, beg, end,
                                              tagged_funcgroup,
                                              tagged_rings)
     self.assertEquals(atoms, {0, 2})
     self.assertEquals(bonds, {0, 1})
コード例 #6
0
ファイル: cp_openeye.py プロジェクト: AspirinCode/chemper
    def get_molecule(self):
        """
        Extracts the parent molecule this bond is in

        Returns
        -------
        mol: chemper Mol
            molecule this bond is stored in
        """
        mol = oechem.OEMol(self.bond.GetParent())
        self.bond = mol.GetBond(oechem.OEHasBondIdx(self._idx))
        return Mol(mol)
コード例 #7
0
ファイル: cp_openeye.py プロジェクト: AspirinCode/chemper
    def get_bond_by_index(self, idx):
        """
        Parameters
        ----------
        idx: ing
            bond index

        Returns
        -------
        bond: chemper Bond object
            bond with index idx
        """
        return Bond(self.mol.GetBond(oechem.OEHasBondIdx(idx)))
コード例 #8
0
def _to_AtomBondSet(mol, atoms, bonds):
    """
    Builds OpeneyeAtomBondet from atoms and bonds set of indices
    Parameters
    ----------
    mol: Openeye OEMolGraph
    atoms: Set of atom indices
    bonds: Set of bond indices

    Returns
    -------
    AtomBondSet: Openeye AtomBondSet of fragment
    """

    AtomBondSet = oechem.OEAtomBondSet()
    for a_idx in atoms:
        AtomBondSet.AddAtom(mol.GetAtom(oechem.OEHasAtomIdx(a_idx)))
    for b_idx in bonds:
        AtomBondSet.AddBond(mol.GetBond(oechem.OEHasBondIdx(b_idx)))
    return AtomBondSet
コード例 #9
0
def subgraphToAtomBondSet(graph, subgraph, oemol):
    """
    Build Openeye AtomBondSet from subrgaphs for enumerating fragments recipe

    Parameters
    ----------
    graph: NetworkX graph
    subgraph: NetworkX subgraph
    oemol: Openeye OEMolGraph

    Returns
    ------
    atomBondSet: Openeye oechem atomBondSet
    """
    # Build openeye atombondset from subgraphs
    atomBondSet = oechem.OEAtomBondSet()
    for node in subgraph.node:
        atomBondSet.AddAtom(oemol.GetAtom(oechem.OEHasAtomIdx(node)))
    for node1, node2 in subgraph.edges():
        index = graph.edge[node1][node2]['index']
        atomBondSet.AddBond(oemol.GetBond(oechem.OEHasBondIdx(index)))
    return atomBondSet
コード例 #10
0
ファイル: chemi.py プロジェクト: dgasmith/fragmenter
def tag_conjugated_bond(mol, tautomers=None, tag=None, threshold=1.05):
    """
    Add conjugated bond data tag. If the bond order is above the threshold, this tag will be True, otherwise it will be
    False
    Parameters
    ----------
    mol: OEMol
    tautomers: list of OEMols, optional, Default None
        If a list is provided, the conjugation tag will be true if the bond in any of the set of molecules is double.
        The list should consist of resonance structures of the molecules. You can get that from oequacpac.EnumerateTautomres
    tag: str, optional, Default None
        If provided, will use that bond order. Options are WibergBondOrder, Wiberg_psi4, Mayer_psi4
    threshold: int, optional, Default is 1.05
        The fractional bond order threshold above which the bond will be considered conjugated.

    Returns
    -------
    atom_indices: list of atom indices in conjugated bonds.

    """
    atom_indices = []
    for bond in mol.GetBonds():
        resonance = False
        if tautomers is not None:
            for tmol in tautomers:
                t_bond = tmol.GetBond(oechem.OEHasBondIdx(bond.GetIdx()))
                if t_bond.GetOrder() > 1:
                    resonance = True
                    break
        elif bond.GetData()[tag] >= threshold:
            resonance = True
        # Add tag to bond
        conj_tag = oechem.OEGetTag("conjugated")
        bond.SetData(conj_tag, resonance)
        if resonance:
            a1 = bond.GetBgnIdx()
            a2 = bond.GetEndIdx()
            atom_indices.extend([a1, a2])
    return atom_indices
コード例 #11
0
# 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 openeye import oechem

# @ <SNIPPET-OEADDMOLS>
dstmol = oechem.OEGraphMol()
oechem.OESmilesToMol(dstmol, 'c1ccccc1 benzene')
srcmol = oechem.OEGraphMol()
oechem.OESmilesToMol(srcmol, 'c1cnccc1 pyridine')

amap, bmap = oechem.OEAddMols(dstmol, srcmol, "+")
print("%s %s" % (oechem.OEMolToSmiles(dstmol), dstmol.GetTitle()))
print(" ".join(str(a) for a in amap))
print(" ".join(str(b) for b in bmap))
# @ </SNIPPET-OEADDMOLS>

# @ <SNIPPET-OEADDMOL-ATOMMAP>
srcatom = srcmol.GetAtom(oechem.OEHasAtomicNum(oechem.OEElemNo_N))
dstatom = amap[srcatom.GetIdx()]
# @ </SNIPPET-OEADDMOL-ATOMMAP>

# @ <SNIPPET-OEADDMOL-BONDMAP>
srcbond = srcmol.GetBond(oechem.OEHasBondIdx(0))
dstbond = bmap[srcbond.GetIdx()]
# @ </SNIPPET-OEADDMOL-BONDMAP>
# @ </SNIPPET>
コード例 #12
0
 def get_bond_by_index(self, idx):
     return Bond(self.mol.GetBond(oechem.OEHasBondIdx(idx)))
コード例 #13
0
 def get_molecule(self):
     mol = oechem.OEMol(self.bond.GetParent())
     self.bond = mol.GetBond(oechem.OEHasBondIdx(self._idx))
     return Mol(mol)
コード例 #14
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)