Exemplo n.º 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
Exemplo n.º 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()
Exemplo n.º 3
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
Exemplo n.º 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
Exemplo n.º 5
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    
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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
Exemplo n.º 9
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)
Exemplo n.º 10
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]

Exemplo n.º 11
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


Exemplo n.º 12
0
        print len(molecule.atoms)
        print connections
        raise

    rings = potentialCycles  #checkRings(potentialCycles)
    molecule.rings = rings
    molecule.cycles = [Cycle(atoms, bonds) for atoms, bonds in rings]
    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
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
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
Exemplo n.º 16
0
                #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()
Exemplo n.º 17
0
def nanotube(width, height):
    N = width * 2
    first, middle, last = make_lines(width * 2)
    lines = [first]
    for i in range(height - 1):
        lines.append(middle)
    lines.append(last)
    return ".".join(lines)


tube = nanotube(4, 100)
print tube

from frowns import Smiles
import time
#try:
#    import psyco
#    psyco.full()
#except:
#    print "nope"
#    pass

Smiles.smilin("c1cccc1")
t1 = time.time()
mol = Smiles.smilin(tube)
t2 = time.time()

print mol.cansmiles()

print t2 - t1
Exemplo n.º 18
0
from frowns import Smiles

mol = Smiles.smilin("C(\C)(C)=C(/C)(C)")
print mol.cansmiles()

mol = Smiles.smilin("F/C=C/F")
print mol.cansmiles()

for bond in mol.bonds:
    print bond.symbol
    print bond.equiv_class
Exemplo n.º 19
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",
    "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",
]

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

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

mainloop()
Exemplo n.º 20
0
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
Exemplo n.º 21
0
                _recurse(next, visited)
    
                
def components(molecule):
    atoms = {}
    for atom in molecule.atoms:
        atoms[atom] = 1

    components = []

    while atoms:
        start = atoms.keys()[0]
        visited = {start:1}
        _recurse(start, visited)
        bonds = {}
        for atom in visited.keys():
            del atoms[atom]
            for bond in atom.bonds:
                bonds[bond] = 1
                
        components.append((visited.keys(), bonds.keys()))

    return components

if __name__ == "__main__":
    from frowns import Smiles
    mol = Smiles.smilin("CCC.NNN")
    print components(mol)
        
    print mol.cansmiles()
Exemplo n.º 22
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)
Exemplo n.º 23
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()
Exemplo n.º 24
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)
Exemplo n.º 25
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
Exemplo n.º 26
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
Exemplo n.º 27
0
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
Exemplo n.º 28
0
            
        
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
            
Exemplo n.º 29
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)
Exemplo n.º 30
0
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
Exemplo n.º 31
0

            _dfswalk(oatom, visitedAtoms, visitedBonds, nonPathBonds, path, paths, depth+1, mindepth, maxdepth)

            while len(path) != mark:
                path.pop()

            while len(nonPathBonds) != markNonPathBonds:
                nonPathBonds.pop()

            del visitedAtoms[oatom]
            del visitedBonds[bond]

def generatePaths(molecule, mindepth=6,  maxdepth=7):
    """(molecule, mindepth maxdepth) -> linear paths
    Generate all linear paths through a molecule from mindepth atoms
    to maxdepth atoms
    """
    paths = {}
    for atom in molecule.atoms:
        _dfswalk(atom, {atom:1}, {}, [], [atom], paths, 1, mindepth, maxdepth)

    return paths.keys()


if __name__ == "__main__":
    from frowns import Smiles
    m = Smiles.smilin("CCCNc1ccccc1")
    for paths in generatePaths(m):
        print paths
Exemplo n.º 32
0
from frowns import Smiles

mol = Smiles.smilin("C1CC=1")
print mol.arbsmiles()
Exemplo n.º 33
0
# Just some simple postive testing for smarts
# negative testing is a little harder to come by

from frowns import Smiles
from frowns import Smarts

mol = Smiles.smilin("C1CCCCC1CCN(=O)OCCN=C")

# search for ring atoms
matcher = Smarts.compile("[R1]")
print matcher.dump()
pathset = matcher.match(mol)
assert pathset
print pathset.atoms
print pathset.bonds

# search for CCN=O or CCN=C
matcher = Smarts.compile("CCN=[O,C]")
print matcher.dump()
pathset = matcher.match(mol)
assert pathset
for path in pathset:
    print path.atoms, path.bonds


# search for a wildcard
matcher = Smarts.compile("*=O")
print matcher.dump()
pathset = matcher.match(mol)
assert pathset
for path in pathset:
Exemplo n.º 34
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
Exemplo n.º 35
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]
Exemplo n.º 36
0
from frowns import Smiles
m = Smiles.smilin("[CH0]")
assert m.cansmiles() == "[C]"
m = Smiles.smilin("C")
assert m.cansmiles() == "C"
Exemplo n.º 37
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
Exemplo n.º 38
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)


Exemplo n.º 39
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:
Exemplo n.º 40
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)

Exemplo n.º 41
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