Smiles parser Smarts substructure searching SD file parser with SD field manipulations Depiction for SD files with coordinates Molecule Fingerprint generation Several forms of Ring Detection available Simple aromaticity perception Full source code Really bad depiction of arbitray molecules! (requires AT&T's GraphViz) |
Recursive Smarts searches (coming
soon!) Stereochemistry (this actually exists but Frowns’ can’t canonicalize stereochemistry yet) |
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 |
c1ccccc1 atoms C 1 1 C 1 1 C 1 1 C 1 1 C 1 1 C 1 1 bonds 2 4 1 4 2 4 1 4 2 4 1 4 |
Name |
Property |
---|---|
cansmiles() |
Canonical string representation of the molecule |
arbsmiles() |
Arbitrary string representation of the molecule |
atoms |
List of atoms in the molecule |
bonds |
List of bonds in the molecule |
handle |
Unique integer ID for each object created. Used
for consistency with PyDaylight |
Name |
Property |
---|---|
bonds |
list bonds to which this atom is connected |
oatoms |
list of atoms to which this atom is connected |
hcount |
number of hydrogens attached to the atom |
implicit_hcount |
number of implicitly placed hydrogens to balance
valence |
mass |
mass of atom |
charge |
charge of atom |
symbol |
atomic symbol of atom |
equiv_class |
Equivalence class of atom (See canonicalization
section) |
symclass |
Symmetry class of atom (See canonicalization
section) |
symorder |
Symmetry order of atom (See canonicalization
section) |
xatom(bond) |
Return the atom on the other end of bond or None
if one doesn't exist. |
handle |
Unique integer ID for each object created. Used
for consistency with PyDaylight |
Name |
Property |
---|---|
bondorder |
Bond order 1,2,3 (single, double, triple) |
bondtype |
Bond type 1,2,3,4 (single, double, triple, aromatic) |
symbol |
symbol of the bond |
xatom(atom1) |
Return the atom on the other end of this bond and
atom1 or None if one doesn't exist. |
handle |
Unique integer ID for each object created. Used
for consistency with PyDaylight |
from frowns import Smiles listOfSmiles = ["CCN", "NCC", "CCC"] duplicates = {} for smile in listOfSmiles: mol = Smiles.smilin(smile) canonicalString = mol.cansmiles() if duplicates.has_key(canonicalString): print "found duplicate molecule", smile else: duplicates[canonicalString] = 1 print len(duplicates), "unique molecules found" |
molecule = transform(molecule) |
from frowns import Smiles mol = Smiles.smilin("c1ccccc1") print mol.cansmiles() mol = Smiles.smilin("c1ccccc1", transforms=[]) print mol.cansmiles() |
c1ccccc1 [c]1[c][c][c][c][c]1 |
Perception Routine |
Description |
---|---|
frowns.perception.sssr.sssr |
Fast ring detection code using Figueras' algorithsm |
frowns.perception.RingDetection.sssr |
Slower ring detection code using spans, similar
to Babel's ring detection code. Much slower than Figueras but overcomes
some limitations of Figueras algorithm for complex molecules. |
frowns.perception.BasicAromaticity.aromatize |
Aromatize molecules using simple rules. |
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) |
benzene with no transforms [c]1[c][c][c][c][c]1 atoms symbol C hcount 0 aromatic 1 symbol C hcount 0 aromatic 1 symbol C hcount 0 aromatic 1 symbol C hcount 0 aromatic 1 symbol C hcount 0 aromatic 1 symbol C hcount 0 aromatic 1 bonds bondorder 1, bondtype 1 fixed 0 bondorder 1, bondtype 1 fixed 0 bondorder 1, bondtype 1 fixed 0 bondorder 1, bondtype 1 fixed 0 bondorder 1, bondtype 1 fixed 0 bondorder 1, bondtype 1 fixed 0 |
mol = Smiles.smilin("c1-c=c-c=c-c=1",
transforms=[]) ... |
benzene with no transforms but
bonds fully specified [c]1[c]=[c][c]=[c][c]=1 atoms symbol C hcount 0 aromatic 1 symbol C hcount 0 aromatic 1 symbol C hcount 0 aromatic 1 symbol C hcount 0 aromatic 1 symbol C hcount 0 aromatic 1 symbol C hcount 0 aromatic 1 bonds bondorder 1, bondtype 1 fixed 1 bondorder 2, bondtype 2 fixed 1 bondorder 1, bondtype 1 fixed 1 bondorder 2, bondtype 2 fixed 1 bondorder 1, bondtype 1 fixed 1 bondorder 2, bondtype 2 fixed 1 |
from frowns import MDL reader = MDL.mdlin(open("../test/data/bad.sdf")) while 1: mol = reader.next() if not mol: break print mol.cansmiles() |
for key, value
in mol.fields.items(): print "%s: %s"%(key, value) |
for atom in
mol.atoms: print atom.x, atom.y, atom.z |
for atom in
mol.atoms: print atom._line for bond in mol.bonds: print bond._line |
from Tkinter import * from frowns.Depict.MoleculeDock import MoleculeDock from frowns import MDL # read in a molecule reader = MDL.mdlin(open("../test/data/bad.sdf")) mol = reader.next() # create the moleculedock widget and place it # into a tk window tk = top = Tk() m = MoleculeDock(top) m.pack(fill=BOTH, expand=1) # add some molecules m.addMolecule(mol) m.addMolecule(mol) m.addMolecule(mol) m.addMolecule(mol) mainloop() |
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() |
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 |
match 1 atoms (Atom(0), Atom(1), Atom(2)) bond (Bond(3), Bond(5)) |
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 |
match 1 atoms (Atom(0), Atom(1)) bond (Bond(3),) match 2 atoms (Atom(1), Atom(0)) bond (Bond(3),) match 3 atoms (Atom(1), Atom(2)) bond (Bond(5),) |
pattern = Smarts.compile("[!N]-[!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 |
match 1 atoms (Atom(1), Atom(2)) bond (Bond(5),) |
import frowns.Fingerprint from frowns import Smiles pattern = "CCN" targets = ["CCN", "CCNCC", "c1cccc1CCN", "CC"] 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 if pfp in molfp: print "%s hits target %s"%(pattern, target) else: print "%s does not hit target %s"%(pattern, target) |
CCN hits target CCN CCN hits target CCNCC CCN hits target c1cccc1CCN CCN does not hit target CC |
from frowns import Smiles mol = Smiles.smilin("c1ccccc1CCC2CC2") index = 0 for cycle in mol.cycles: print "cycle", index print "\t", cycle.atoms print "\t", cycle.bonds index = index + 1 |
cycle 0 [Atom(5), Atom(4), Atom(3), Atom(2), Atom(1), Atom(0)] [Bond(11), Bond(9), Bond(7), Bond(5), Bond(3), Bond(12)] cycle 1 [Atom(10), Atom(9), Atom(8)] [Bond(22), Bond(20), Bond(23)] |