Exemple #1
0
def test2():

    smiles, id = "OC1=C(Cl)C=CC=C1[N+]", 1
    mol = Smiles.smilin(smiles)
    print mol.cansmiles()
    for atom in mol.atoms:
        print atom.index
Exemple #2
0
    def cansmiles(self) :
        """
        affiche en canonical smiles une brique
        """
        # sys.stderr.write("Brique.cansmiles: will call molecule.cansmiles() ...\n")
        a = self.molecule.cansmiles()

        m = Smiles.smilin("".join(re.split("[\[\]+-]","".join(re.split("H[0-9]*",a)))))
        return m.cansmiles()
Exemple #3
0
def test():
    from frowns import Smiles
    import time
    smiles, id = "OC1=C(Cl)C=CC=C1[N+]C2CCC3CC3CCC2", 1
    mol = Smiles.smilin(smiles, transforms=[])

    t1 = time.time()
    for i in range(100):
        atoms, bonds = getAtomsBondsInRings(mol)
    print(time.time() - t1) / 100
Exemple #4
0
def test():
    from frowns import Smiles
    import time
    smiles, id = "OC1=C(Cl)C=CC=C1[N+]C2CCC3CC3CCC2", 1
    mol = Smiles.smilin(smiles, transforms=[])

    t1 = time.time()
    for i in range(100):
        atoms, bonds = getAtomsBondsInRings(mol)
    print (time.time() - t1)/100
Exemple #5
0
def checkSmiles(fname):
    from frowns import Smiles
    try:
        fSmiles = open(fname, "r")
        lines = fSmiles.readlines()
        fSmiles.close()
        asmiles = Smiles.smilin(lines[0].split()[0])
        return True
    except:
        return False
Exemple #6
0
def test():
    from frowns import Smiles
    import time
    smiles, id = "OC1=C(Cl)C=CC=C1[N+]C2CCC3CC3CCC2", 1
    mol = Smiles.smilin(smiles, transforms=[])
    assert frerejaqueNumber(mol) == 3
    t1 = time.time()
    for i in range(100):
        frerejaqueNumber(mol)
    print(time.time() - t1) / 100
Exemple #7
0
def checkSmiles(fname):
    from frowns import Smiles
    try:
        fSmiles = open(fname, "r")
        lines = fSmiles.readlines()
        fSmiles.close()
        asmiles = Smiles.smilin(lines[0].split()[0])
        return True
    except:
        return False
Exemple #8
0
def test():
    from frowns import Smiles
    import time
    smiles, id = "OC1=C(Cl)C=CC=C1[N+]C2CCC3CC3CCC2", 1
    mol = Smiles.smilin(smiles, transforms=[])
    assert frerejaqueNumber(mol) == 3
    t1 = time.time()
    for i in range(100):
        frerejaqueNumber(mol)
    print (time.time() - t1)/100    
Exemple #9
0
    def cansmiles(self):
        """
        affiche en canonical smiles une brique
        """
        # sys.stderr.write("Brique.cansmiles: will call molecule.cansmiles() ...\n")
        a = self.molecule.cansmiles()

        m = Smiles.smilin("".join(
            re.split("[\[\]+-]", "".join(re.split("H[0-9]*", a)))))
        return m.cansmiles()
Exemple #10
0
    def next(self):
        if not self.smiles:
            return None
        smile = self.smiles.pop()
        m = Smiles.smilin(smile)

        #addCoords(m)
        #toplevel = Toplevel(self.tk)
        if self.drawer:
            self.drawer.frame.pack_forget()
        drawer = self.drawer=TkMoleculeDrawer.MoleculeDrawer(self.tk, m, name=smile)
        drawer.pack(expand=1, fill=BOTH)
Exemple #11
0
def test():
    from frowns import Smiles
    strings = ["Cl/C(F)=C(Br)/I",
               #"Cl\C)(F)=C(Br)\I", <- fix parsing bug
               #"Cl\C(\F)=C(/Br)\I",
               "Cl\C(F)=C(Br)\I",
               "Cl\C(F)=C(Br)/I",
               "Cl/C(F)=C(Br)\I"
               ]
    for s in strings:
        print s
        m = Smiles.smilin(s)
        assignStereo(m)
Exemple #12
0
def testPath():
    from frowns import Smiles
    mol = Smiles.smilin("C1CCCC1CCCC2CCCC3CCC3CCC2")
    rings = {}
    spans = [Path(mol.atoms[0], rings)]
    while spans:
        new = []
        for span in spans:
            new += span.next()
            if len(rings) == 1:
                break
        if len(rings) == 1:
            break
        spans = new
    print rings
Exemple #13
0
def test():
    from frowns import Smiles
    import time
    h = BuildMatcher()
    for smi in ["C",
                "CC",
                "c",
                "C(N)O",
                "[O]",
                "c1ccccc1",
                ]:
        matcher = compile(smi)
        print matcher.dump()
        smiles = Smiles.smilin(smi)
        pathset = matcher.match(smiles)
Exemple #14
0
def testPath():
    from frowns import Smiles
    mol = Smiles.smilin("C1CCCC1CCCC2CCCC3CCC3CCC2")
    rings = {}
    spans = [Path(mol.atoms[0], rings)]
    while spans:
        new = []
        for span in spans:
            new += span.next()
            if len(rings) == 1:
                break
        if len(rings) == 1:
            break
        spans = new
    print rings
Exemple #15
0
def test():
    from frowns import Smiles
    import time
    h = BuildMatcher()
    for smi in [
            "C",
            "CC",
            "c",
            "C(N)O",
            "[O]",
            "c1ccccc1",
    ]:
        matcher = compile(smi)
        print matcher.dump()
        smiles = Smiles.smilin(smi)
        pathset = matcher.match(smiles)
Exemple #16
0
from frowns import Smiles
from frowns.perception import figueras

badsmi = "C1=CC(=C2C=CC=C(N=CC34C5=C6C7=C3[Fe]456789%10%11C%12C8=C9C%10=C%11%12)C2=C1)N=CC%13%14C%15=C%16C%17=C%13[Fe]%14%15%16%17%18%19%20%21C%22C%18=C%19C%20=C%21%22"

m1 = Smiles.smilin(badsmi, transforms=[figueras.sssr])
m2 = Smiles.smilin(badsmi)

print len(m1.cycles)
print len(m2.cycles)

            print >> ofile, "\tatom%s -- atom%s;" % (atom1.handle,
                                                     atom2.handle)

    print >> ofile, "}"

    return ofile.getvalue()


if __name__ == '__main__':
    from frowns import Smiles

    # read in a molecule
    smiles = [
        "c1ccccc1C=O",
        "c1ccc2cc1cccc2",
        "CCN",
        "CCCC(=O)NNCC",
        "CCC(CC)([CH](OC(N)=O)C1=CC=CC=C1)C2=CC=CC=C2",
        "ON=C(CC1=CC=CC=C1)[CH](C#N)C2=CC=CC=C2",
        "C1=CC=C(C=C1)C(N=C(C2=CC=CC=C2)C3=CC=CC=C3)C4=CC=CC=C4",
    ]

    mol_list = []
    for smile in smiles:
        mol = Smiles.smilin(smile)
        mol.name = smile
        mol_list.append(mol)

    f = open('frowns.dot', 'w')
    f.write(generate_dot(mol_list))
Exemple #18
0
    molecule = fixBonds(molecule, pyroleLike)
    # add implicit hydrogens
    return addHydrogens(molecule, usedPyroles)


if __name__ == "__main__":
    smiles = 'C1=CC(NC=C2)=C2C=C1'
    smiles = 'C1=CC(NC=C2)=C2C=C1'
    smiles = 'C1C=C[NH]2C=1C=CC=C2'
    smiles = 'C1[NH]C=CC=1CCC2C=CC=CC=2'
    #smiles = 'C1NC=CC=1'
    smiles = 'c1ccccc1'
    smiles = 'CC1=CC=CC2=NC=C(C)C(=C12)Cl'
    smiles = 'O=n1ccccc1'
    #smiles = 'O=N1=CC=CC=C1'
    from frowns import Smiles
    import RingDetection
    print smiles,
    mol = Smiles.smilin(smiles, transforms=[RingDetection.sssr, aromatize])

    print '->', mol.cansmiles()

    print "atoms"
    for atom in mol.atoms:
        print "\t", atom.symbol, atom.valences, atom.hcount, atom.sumBondOrders(
        ), atom.charge, atom.aromatic

    print "bonds"
    for bond in mol.bonds:
        print "\t", bond.bondtype, bond.bondorder, bond.aromatic
from frowns.perception import sssr, TrustedSmiles
from frowns import Smiles

for smiles in ["c1ccccc1", "c1cc1CCc2cc2"]:
    m = Smiles.smilin(smiles,
                      transforms=[sssr.sssr, TrustedSmiles.trusted_smiles])

    print m.cansmiles()
    print m.arbsmarts()
    for bond in m.bonds:
        print bond.fixed, bond.symbol, bond.bondorder

fusedrings = "c12c3c(cc(c(Cl)c3oc2c(Cl)ccc1Cl)Cl)Cl"
for smiles in [fusedrings, 'c12[nH]c(c3ccc(CC)cc3)[nH0]c2[nH0]ccc1']:
    print "*" * 44
    m = Smiles.smilin(smiles,
                      transforms=[sssr.sssr, TrustedSmiles.trusted_smiles])

    print m.cansmiles()
    print m.arbsmarts()

    m = Smiles.smilin(smiles)
    print m.cansmiles()
    print m.arbsmarts()
Exemple #20
0
from frowns import Smiles

mol = Smiles.smilin("c1ccccc1")

print mol.cansmiles()

print "atoms"
for atom in mol.atoms:
    print atom.symbol, atom.hcount, atom.aromatic

print "bonds"
for bond in mol.bonds:
    print bond.bondorder, bond.bondtype

Exemple #21
0
from bsddb3 import dbshelve
from frowns import Smiles, Smarts, Fingerprint

# ################################################################
# load database (this only needs to be done once
# you can comment this out at a later data
# ################################################################
# this is a persistent disk cache
cache = dbshelve.open("FOO.shelve")
molecules = ["CCCN", "c1ccccc1CCN", "C#C(N)CCc1ccccc1CCc1ccccc1"]

for m in molecules:
    mol = Smiles.smilin(m)
    fp = Fingerprint.generateFingerprint(mol)
    # cache the fingerprint using the canonical smiles
    # as the key and the fingerprint object as the value
    # shelves can store any picklable object!
    cache[mol.cansmiles()] = fp

cache.close()

# ##################################################################
# Iterate through database to see which molecules we need to
# do a full substructure search on
# ##################################################################
cache = dbshelve.open("FOO.shelve", 'r')

query = "CCCN"  # this should reject molecule #2 above

testFP = Fingerprint.generateFingerprint(Smiles.smilin(query))
    molecule = fixBonds(molecule, pyroleLike)
    # add implicit hydrogens
    return addHydrogens(molecule, usedPyroles)
        

if __name__ == "__main__":
    smiles = 'C1=CC(NC=C2)=C2C=C1'
    smiles = 'C1=CC(NC=C2)=C2C=C1'
    smiles = 'C1C=C[NH]2C=1C=CC=C2'
    smiles = 'C1[NH]C=CC=1CCC2C=CC=CC=2'
    #smiles = 'C1NC=CC=1'
    smiles = 'c1ccccc1'
    smiles = 'CC1=CC=CC2=NC=C(C)C(=C12)Cl'
    smiles = 'O=n1ccccc1'
    #smiles = 'O=N1=CC=CC=C1'
    from frowns import Smiles
    import RingDetection
    print smiles,
    mol = Smiles.smilin(smiles, transforms=[RingDetection.sssr,
                                            aromatize])
    
    print '->', mol.cansmiles()

    print "atoms"
    for atom in mol.atoms:
        print "\t", atom.symbol, atom.valences, atom.hcount, atom.sumBondOrders(), atom.charge, atom.aromatic

    print "bonds"
    for bond in mol.bonds:
        print "\t", bond.bondtype, bond.bondorder, bond.aromatic
Exemple #23
0
from frowns import Smiles

mol = Smiles.smilin("c1ccccc1CCC1CC1")

index = 0
for cycle in mol.cycles:
    print "cycle", index
    print "\t", cycle.atoms
    print "\t", cycle.bonds
    index = index + 1
Exemple #24
0
        atoms, bonds = toposort(atoms)        
        rings.append((atoms, bonds))
        cycles.append(Cycle(atoms, bonds))

    molecule.rings = rings
    molecule.cycles = cycles
    return molecule

    
if __name__ == "__main__":
    from frowns import Smiles
    import time
    
    data = open("../Working/frowns/test/data/NCI_small").read()
    count = 0
    i = 0
    for line in data.split("\n"):
        i += 1
        smiles = line.split()[0]
        m = Smiles.smilin(smiles)
        t1 = time.time()
        m = sssr(m)
        t2 = time.time()
        count += (t2-t1)
        
        assert len(m.cycles) == len(m.rings), "failed %s in %f average"%(float(count)/i)

    print "average sssr", float(count)/i


Exemple #25
0
import Components

def computeMW(mol):
    """mol -> mw of largest fragment, mw of total molecule"""
    fragments = []
    total = 0.0
    if not mol.atoms: return 0.0, 0.0
    for atoms, bonds in Components.components(mol):
        mw = 0.0
        for atom in atoms:
            mw += atom.mass + atom.hcount
            fragments.append(mw)
        total += mw

    largest = max(fragments)
    return largest, total

if __name__ == "__main__":
    from frowns import Smiles
    mol = Smiles.smilin("CCC.NNN.Br")
        
    print computeMW(mol)
                #is the coordinates of hydrogen stored somewhere in the
                #atom the hydrogen is attached to?
##                hatom.x = 
##                hatom.y = 
##                hatom.z =

                #does the hcount need to be changed?
##                atom.hcount -= 1 
                
                mol.add_atom(hatom)
                bond = Bond()
                mol.add_bond(bond, atom, hatom)

        #reset atom indices
        index = 0
        for atom in mol.atoms:
            atom.index = index
            index += 1

        mol.explicitHydrogens = 1 #change flag to let know that hydrogens are explicit in this mol 
    return mol


from frowns import Smiles
m = Smiles.smilin("CCCCc1ccccc1")
m.explicitHydrogens = 0

addHydrogens(m)

print m.cansmiles()
Exemple #27
0
        assert maxdepth - 1 == len(integersPerAtoms)

    def createFP(self, molecule):
        p = SplitFingerprint(self.maxdepth, self.integersPerAtoms)

        paths = generatePaths(molecule, maxdepth=self.maxdepth)
        paths.sort()
        for length, s in paths:
            p.addPath(length, s)

        return p


if __name__ == "__main__":
    from frowns import Smiles
    mol = Smiles.smilin("CCCc1cc[nH]c1")
    mol2 = Smiles.smilin("c1cc[nH]c1")

    paths = generatePaths(mol)
    pathLengths = {}
    for p in paths:
        l, s = p
        pathLengths[l] = pathLengths.get(l, []) + [s]

    generator = SplitFingerprintGenerator()
    sp = generator.createFP(mol)
    sp2 = generator.createFP(mol2)

    assert sp in sp
    assert sp2 in sp
Exemple #28
0
from frowns import Smarts, Smiles

mol = Smiles.smilin('O=[N+]([O-])c1ccc(NC(C(C)(C)O)=O)cc1')
pattern = Smarts.compile('[cH0]-[!C;!N]')
match = pattern.match(mol)
if match:
    for path in match:
        a1, a2 = path.atoms
        b1 = path.bonds[0]
        print a1, a1.index, a1.aromatic, b1.aromatic, b1.bondtype, b1.bondorder, a2, a2.index, a2.aromatic


Exemple #29
0
from frowns import Smiles
from frowns.perception import figueras

badsmi = "C1=CC(=C2C=CC=C(N=CC34C5=C6C7=C3[Fe]456789%10%11C%12C8=C9C%10=C%11%12)C2=C1)N=CC%13%14C%15=C%16C%17=C%13[Fe]%14%15%16%17%18%19%20%21C%22C%18=C%19C%20=C%21%22"

m1 = Smiles.smilin(badsmi, transforms=[figueras.sssr])
m2 = Smiles.smilin(badsmi)

print len(m1.cycles)
print len(m2.cycles)
Exemple #30
0
from frowns import Smiles

mol = Smiles.smilin("C1CC=1")
print mol.arbsmiles()
            
        
def generatePaths(molecule, maxdepth=5,
                  name_atom=name_atom, name_bond=name_bond,
                  name_ring_atom=name_ring_atom, name_ring_bond=name_ring_bond,
                  make_rpath=0):
    """(molecule, maxdepth, *name_atom, *name_bond) -> linear paths
    Generate all linear paths through a molecule up to maxdepth
    change name_atom and name_bond to name the atoms and bonds
    in the molecule

    name_atom and name_bond must return a stringable value"""
    paths = {}
    for atom in molecule.atoms:
        _bfswalk(atom, {atom:1}, [name_atom(atom)], [name_ring_atom(atom)], paths, 1, maxdepth,
                 name_atom, name_bond, name_ring_atom, name_ring_bond, make_rpath)
    return paths.keys()

if __name__ == "__main__":
    from frowns import Smiles
    mol = Smiles.smilin("CCNc1cccc1")
    paths = generatePaths(mol)
    print len(paths)
    print paths
    
    ONE_STRING_PER_PATH = 1
    paths = generatePaths(mol)
    print len(paths)
    print paths
            
                  name_atom=name_atom,
                  name_bond=name_bond,
                  name_ring_atom=name_ring_atom,
                  name_ring_bond=name_ring_bond,
                  make_rpath=0):
    """(molecule, maxdepth, *name_atom, *name_bond) -> linear paths
    Generate all linear paths through a molecule up to maxdepth
    change name_atom and name_bond to name the atoms and bonds
    in the molecule

    name_atom and name_bond must return a stringable value"""
    paths = {}
    for atom in molecule.atoms:
        _bfswalk(atom, {atom: 1}, [name_atom(atom)], [name_ring_atom(atom)],
                 paths, 1, maxdepth, name_atom, name_bond, name_ring_atom,
                 name_ring_bond, make_rpath)
    return paths.keys()


if __name__ == "__main__":
    from frowns import Smiles
    mol = Smiles.smilin("CCNc1cccc1")
    paths = generatePaths(mol)
    print len(paths)
    print paths

    ONE_STRING_PER_PATH = 1
    paths = generatePaths(mol)
    print len(paths)
    print paths
Exemple #33
0
import sys
sys.path.append("/Users/stockwel/Working")
from frowns import Smiles
import time
from frowns.perception import RingDetection, BasicAromaticity, figueras, pysssr

transforms = [figueras.sssr,
              BasicAromaticity.aromatize]

tests = [x.split()[0] for x in open("data/NCI_small")][0:100]

t1 = time.time()

for smiles in tests:
    m = Smiles.smilin(smiles, transforms)

t2 = time.time()

time1 = (t2-t1)/len(tests)
print "start", t1
print "end", t2
print "elapsed", t2-t1
print "number of smiles", len(tests)
print "average molecule generation", time1


transforms = [pysssr.sssr,
              BasicAromaticity.aromatize]

t1 = time.time()
for smiles in tests:
Exemple #34
0
from Tkinter import *
from frowns.Depict.MoleculeDock import MoleculeDock
from frowns import Smiles

# read in a molecule
smiles = ["c1ccccc1C=O", "c1ccc2cc1cccc2",
          "CCN", "CCCC(=O)NNCC"]


# create the moleculedock widget and place it
# into a tk window
tk = top = Tk()
m = MoleculeDock(top)
m.pack(fill=BOTH, expand=1)

for smile in smiles:
    mol = Smiles.smilin(smile)
    m.addMolecule(mol)


mainloop()
Exemple #35
0
from frowns import Smiles

m = Smiles.smilin("N[C@](C)(F)C(=O)O")
print "initial smiles:", m.arbsmiles(isomeric=1)
print "canonical smiles:", m.cansmiles(isomeric=1)

print
m = Smiles.smilin("[C@H](C)(F)(O)")
print "initial smiles:", m.arbsmiles(isomeric=1)
print "canonical smiles:", m.cansmiles(isomeric=1)
Exemple #36
0
    while 1:
        to_remove = []
        for atom in m.atoms:
            if atom.symbol == "C" and len(atom.bonds) == 1:
                to_remove.append(atom)

        if not to_remove:
            break

        for atom in to_remove:
            m.remove_atom(atom)

    return m


m = Smiles.smilin("c1ccccc1CCNc1cccc1CCC")

print m.cansmiles()
removeTerminalAtoms(m)
smarts = m.arbsmarts()
print smarts

pat = Smarts.compile(smarts)
assert pat.match(m)

smiles = []

file = open("F:\\Chemical Libraries\\Libraries to Purchase\\Nat_425.sdf")

reader = MDL.mdlin(file)
mol = reader.next()
Exemple #37
0
        if atom.aromatic:
            # assume the combined bondorder is 3
            atom.hybrid = SP2
            continue
        symbol = atom.symbol
        hcount = atom.valences[0] - atom.sumBondOrders()
        connections = len(atom.bonds) + hcount
        charge = atom.charge
        if atom.symbol in ["C", "N"] and connections == 2:
            charge = ANY

        atom.hybrid = _hybrid.get((symbol, connections, charge), "")
        #print atom, `atom`, hcount, atom.hybrid


if __name__ == "__main__":
    from frowns import Smiles
    from frowns.perception import TrustedSmiles, sssr

    smiles = "CC(=O)OC1C(N(c2c(CC1c1ccc(OC)cc1)cc(cc2)Oc1ccccc1)CCN(C)C)=O"
    smiles = "O=C1NC(N)=NC2=C1N=CNC2"
    #smiles = "O=C1C=CC(=O)C=C1"

    print smiles
    mol = Smiles.smilin(smiles, [sssr.sssr])

    getHybridAtoms(mol)
    for cycle in mol.cycles:
        print[(atom, atom.symbol, atom.hybrid) for atom in cycle.atoms]
Exemple #38
0
                #atom the hydrogen is attached to?
                ##                hatom.x =
                ##                hatom.y =
                ##                hatom.z =

                #does the hcount need to be changed?
                ##                atom.hcount -= 1

                mol.add_atom(hatom)
                bond = Bond()
                mol.add_bond(bond, atom, hatom)

        #reset atom indices
        index = 0
        for atom in mol.atoms:
            atom.index = index
            index += 1

        mol.explicitHydrogens = 1  #change flag to let know that hydrogens are explicit in this mol
    return mol


from frowns import Smiles

m = Smiles.smilin("CCCCc1ccccc1")
m.explicitHydrogens = 0

addHydrogens(m)

print m.cansmiles()
Exemple #39
0
def test():
    from frowns import Smiles
    import RingDetection
    import sssr as sssr2
    import time
    from frowns.Canonicalization import Disambiguate, Traverse
    
    ##mol = Smiles.smilin("C12C3C4C1C5C4C3C25CCCCCC12C3C4C1C5C4C3C25")
    ##mol1 = Smiles.smilin("C1O[CH]1C2=CC=CC=C2",
    ##                    transforms = [])
    ##print mol1.cansmiles()
    smiles = "COC(=O)[CH]1C2CCC(CC2)[CH]1C(=O)OCC"
    smiles = "CC1(C)[CH]2CC[CH](CC(O)=O)[CH]1C2"
    smiles = "C[CH]1C(=O)O[CH]2CCN3CC=C(COC(=O)[C](C)(O)[C]1(C)O)[CH]23"
    #smiles = "CC1=CC(=O)C=CC1=O"
    smiles = "NC1=CC2=C(C=C1)C(=O)C3=C(C=CC=C3)C2=O"
    smiles = "COC1=CC2=C(C=C1OC)[C]34CCN5CC6=CCO[CH]7CC(=O)N2[CH]3[CH]7[CH]6C[CH]45.OS(O)(=O)=O"

    mol1 = Smiles.smilin(smiles,
                         transforms = [])
    
    print mol1.cansmiles()
    NUM = 1
    
    t1 = time.time()
    for i in range(NUM):
        sssr(mol1)
    t2 = time.time()
    print (t2-t1)/NUM
    symbols = []
    for atom in mol1.atoms:
        symbols.append(atom.symbol)

    for atom in mol1.atoms:
        atom.symbol += ".%s."%atom.index
        atom.symorder = mol1.atoms.index(atom)
        
    index = 0
    for cycle in mol1.cycles:
        print cycle.atoms
        print cycle.bonds
        for atom in cycle.atoms:
            atom.symbol += "<%s>"%index
        index += 1

    print Traverse.draw(mol1)[0]

    for atom, symbol in zip(mol1.atoms, symbols):
        atom.symbol = symbol

    for atom in mol1.atoms:
        atom.symbol += ".%s."%atom.index
        atom.symorder = mol1.atoms.index(atom)
        
    t1 = time.time()
    for i in range(NUM):
        RingDetection.sssr(mol1)
    t2 = time.time()
    print (t2-t1)/NUM
    index = 0
    for cycle in mol1.cycles:
        print cycle.atoms
        print cycle.bonds
        for atom in cycle.atoms:
            atom.symbol += "<%s>"%index
        index += 1

    print Traverse.draw(mol1)[0]
Exemple #40
0
    def createFP(self, molecule):
        p = SplitFingerprint(self.maxdepth, self.integersPerAtoms)

        paths = generatePaths(molecule, maxdepth=self.maxdepth)
        paths.sort()
        for length, s in paths:
            p.addPath(length, s)

        return p


if __name__ == "__main__":
    from frowns import Smiles

    mol = Smiles.smilin("CCCc1cc[nH]c1")
    mol2 = Smiles.smilin("c1cc[nH]c1")

    paths = generatePaths(mol)
    pathLengths = {}
    for p in paths:
        l, s = p
        pathLengths[l] = pathLengths.get(l, []) + [s]

    generator = SplitFingerprintGenerator()
    sp = generator.createFP(mol)
    sp2 = generator.createFP(mol2)

    assert sp in sp
    assert sp2 in sp
import time
from frowns import Smiles
from frowns import Smarts
mol = Smiles.smilin("CCCCC(C)CCCC(C)CCCCCC(C)C(C)CCCCCC(C)CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCN")
pat = Smarts.compile("C*")
print len(pat.match(mol))

pat2 = Smarts.compile("[#6]")
t1 = time.time()
print len(pat2.match(mol))
t2 = time.time()
print t2-t1
t1 = time.time()
print len(pat2.match(mol))
t2 = time.time()
print t2-t1

print mol.vfgraph
Exemple #42
0
from frowns import Smiles
m = Smiles.smilin("[CH0]")
assert m.cansmiles() == "[C]"
m = Smiles.smilin("C")
assert m.cansmiles() == "C"
Exemple #43
0
        if atom.symbol == "C" and (
            (len(atom.bonds) == 4 and atom.hcount == 0) or \
            (len(atom.bonds) == 3 and atom.hcount == 1) ):
            atomsToCheck.append(atom)

    chiralAtoms = []
    for atom in atomsToCheck:
        types = {}
        for attachedAtom in atom.oatoms:
            symbol = attachedAtom.symbol

            if symbol in types:
                if bfsCheckAtoms(atom):
                    chiralAtoms.append(atom)
                break

            types[symbol] = 1

        else:
            chiralAtoms.append(atom)

    return chiralAtoms


if __name__ == "__main__":
    from frowns import Smiles
    for smiles in ["C(N)(O)(S)", "C(N)(O)(S)(C)", "C(N)(C)(O)[Fe]"]:

        m = Smiles.smilin(smiles)
        print getStereoCenters(m)
from frowns.perception import sssr, TrustedSmiles
from frowns import Smiles

s = "c12[nH]c(c3ccc(CC)cc3)[nH0]c2[nH0]ccc1"
m = Smiles.smilin(s, transforms=[sssr.sssr, TrustedSmiles.trusted_smiles])

print m.arbsmarts()
for atom in m.atoms:
    print atom.symbol, atom.hcount, atom.explicit_hcount
Exemple #45
0
from frowns import Smiles

print "*"*33
print "benzene with default transforms"
mol = Smiles.smilin("c1ccccc1")
print mol.cansmiles()

print "atoms"
for atom in mol.atoms:
    print "\tsymbol %s hcount %s aromatic %s"%(
        atom.symbol, atom.hcount, atom.aromatic)

print "bonds"
for bond in mol.bonds:
    print "\tbondorder %s, bondtype %s fixed %s"%(
        bond.bondorder, bond.bondtype, bond.fixed)

print "*"*33
print "benzene with no transforms"
mol = Smiles.smilin("c1ccccc1", transforms=[])
print mol.cansmiles()

print "atoms"
for atom in mol.atoms:
    print "\tsymbol %s hcount %s aromatic %s"%(
        atom.symbol, atom.hcount, atom.aromatic)

print "bonds"
for bond in mol.bonds:
    print "\tbondorder %s, bondtype %s fixed %s"%(
        bond.bondorder, bond.bondtype, bond.fixed)
Exemple #46
0
from frowns import Smiles, Smarts
for smiles in ['OC1C=CC(=O)C=C1', 'c1ccccc1']:
    mol = Smiles.smilin(smiles)
    print mol.cansmiles()

    print "with square brackets"    
    pattern = Smarts.compile('OC(C)[A]')
    match = pattern.match(mol)
    if match:
        for path in match:
            print path.atoms

    print
    print "without square brackets" 
    pattern2 = Smarts.compile('O=C(C)A')
    match2 = pattern2.match(mol)
    if match2:
        for path2 in match2:
            print path2.atoms

m = Smiles.smilin("c1ccccc1")
p = Smarts.compile("c1ccccc1")
assert p.match(m)


Exemple #47
0
from frowns import Smiles
from frowns import Smarts

mol = Smiles.smilin("CCN")
pattern = Smarts.compile("CCN")

# simple match
match = pattern.match(mol)
assert match
index = 1
for path in match:
    print "match", index
    print "\tatoms", path.atoms
    print "\tbond", path.bonds
    index = index + 1

print "*" * 33
# more complicated match
pattern = Smarts.compile("C*")
match = pattern.match(mol)
assert match
index = 1
for path in match:
    print "match", index
    print "\tatoms", path.atoms
    print "\tbond", path.bonds
    index = index + 1

print "*" * 33
pattern = Smarts.compile("[!N]-[!C]")
match = pattern.match(mol)
Exemple #48
0
def test():
    from frowns import Smiles
    import RingDetection
    import sssr as sssr2
    import time
    from frowns.Canonicalization import Disambiguate, Traverse

    ##mol = Smiles.smilin("C12C3C4C1C5C4C3C25CCCCCC12C3C4C1C5C4C3C25")
    ##mol1 = Smiles.smilin("C1O[CH]1C2=CC=CC=C2",
    ##                    transforms = [])
    ##print mol1.cansmiles()
    smiles = "COC(=O)[CH]1C2CCC(CC2)[CH]1C(=O)OCC"
    smiles = "CC1(C)[CH]2CC[CH](CC(O)=O)[CH]1C2"
    smiles = "C[CH]1C(=O)O[CH]2CCN3CC=C(COC(=O)[C](C)(O)[C]1(C)O)[CH]23"
    #smiles = "CC1=CC(=O)C=CC1=O"
    smiles = "NC1=CC2=C(C=C1)C(=O)C3=C(C=CC=C3)C2=O"
    smiles = "COC1=CC2=C(C=C1OC)[C]34CCN5CC6=CCO[CH]7CC(=O)N2[CH]3[CH]7[CH]6C[CH]45.OS(O)(=O)=O"

    mol1 = Smiles.smilin(smiles, transforms=[])

    print mol1.cansmiles()
    NUM = 1

    t1 = time.time()
    for i in range(NUM):
        sssr(mol1)
    t2 = time.time()
    print(t2 - t1) / NUM
    symbols = []
    for atom in mol1.atoms:
        symbols.append(atom.symbol)

    for atom in mol1.atoms:
        atom.symbol += ".%s." % atom.index
        atom.symorder = mol1.atoms.index(atom)

    index = 0
    for cycle in mol1.cycles:
        print cycle.atoms
        print cycle.bonds
        for atom in cycle.atoms:
            atom.symbol += "<%s>" % index
        index += 1

    print Traverse.draw(mol1)[0]

    for atom, symbol in zip(mol1.atoms, symbols):
        atom.symbol = symbol

    for atom in mol1.atoms:
        atom.symbol += ".%s." % atom.index
        atom.symorder = mol1.atoms.index(atom)

    t1 = time.time()
    for i in range(NUM):
        RingDetection.sssr(mol1)
    t2 = time.time()
    print(t2 - t1) / NUM
    index = 0
    for cycle in mol1.cycles:
        print cycle.atoms
        print cycle.bonds
        for atom in cycle.atoms:
            atom.symbol += "<%s>" % index
        index += 1

    print Traverse.draw(mol1)[0]
from frowns import Smiles
from frowns import Smarts
from frowns.perception import sssr
from frowns.perception import RingDetection

## '*' is ok
mol=Smiles.smilin("SCCCCSCCCC",transforms=[RingDetection.sssr])
#pattern=Smarts.compile("S*CC")

##!! '~' has problem
pattern=Smarts.compile("S~C~C")

##!! pattern can't match itself
mol=Smiles.smilin("C[CH](C1=CC=CC=C1)[C](C)(C#N)C2=CC=CC=C2")
pattern = Smarts.compile(mol.arbsmarts())
print mol.arbsmarts()
pattern=Smarts.compile("CC(C1=CC=CC=C1)C(C)(C#N)C2=CC=CC=C2")

match=pattern.match(mol)
assert match
index=1
for path in match:
    print "match",index
    print "\tatoms",path.atoms
    print "\tbond",path.bonds
    index=index+1
Exemple #50
0
import frowns.Fingerprint
from frowns import Smiles

patterns_and_targets = (
    ("CCN",
     ("CCN", "CCNCC", "c1cccc1CCN")),
    )

for pattern, targets in patterns_and_targets:
    pattern_molecule = Smiles.smilin(pattern)
    pfp = frowns.Fingerprint.generateFingerprint(pattern_molecule)

    for target in targets:
        mol = Smiles.smilin(target)
        molfp = \
              frowns.Fingerprint.generateFingerprint(mol)
        # pfp must be "in" molfp for test to pass
        assert pfp in molfp, "match %s is not in target %s!"%(pattern, target)

Exemple #51
0
            atom.hybrid = SP2
            continue
        symbol = atom.symbol
        hcount = atom.valences[0] - atom.sumBondOrders()
        connections = len(atom.bonds) + hcount
        charge = atom.charge
        if atom.symbol in ["C", "N"] and connections == 2:
            charge = ANY

        atom.hybrid =  _hybrid.get((symbol, connections, charge), "")
        #print atom, `atom`, hcount, atom.hybrid

        
        
            
if __name__ == "__main__":
    from frowns import Smiles
    from frowns.perception import TrustedSmiles, sssr
    
    smiles = "CC(=O)OC1C(N(c2c(CC1c1ccc(OC)cc1)cc(cc2)Oc1ccccc1)CCN(C)C)=O"
    smiles = "O=C1NC(N)=NC2=C1N=CNC2"
    #smiles = "O=C1C=CC(=O)C=C1"

    print smiles
    mol = Smiles.smilin(smiles, [sssr.sssr])
            
    getHybridAtoms(mol)
    for cycle in mol.cycles:
        print [(atom, atom.symbol, atom.hybrid) for atom in cycle.atoms]