<- Back | Index | Forward ->

Example 1 -- atom data from SMILES
from daylight import Smiles
mol = Smiles.smilin("COO")
for atom in mol.atoms:
   print "  symbol=", atom.symbol, "hcount=", atom.hcount
Example 2 -- cansmiles
from daylight import Smiles, BadFormat
import fileinput, string

count = bad = 0
for line in fileinput.input():
  count = count + 1
  smi = line[:-1]
  try:
    mol = Smiles.smilin(smi)
    cansmi = mol.cansmiles()
  except BadFormat, msg:
    print "Could not parse", smi, "because:", msg
    bad = bad + 1
  print smi, "=>", cansmi
print "%d total, %d bad." % (count, bad)
Example 3 -- SMARTS query
from daylight import Smiles, Smarts

pat = Smarts.compile("[O,C]")
for smi in ("COO", "NO"):
    pathset = pat.match(Smiles.smilin(smi))
    print ">>>", smi
    for path in pathset:
    print "Found a", path.atoms[0].symbol