#!/usr/bin/env python

from nanotechsoftware.base import *
from nanotechsoftware.chemistry import *
from nanotechsoftware.chemistry.framework import *
from nanotechsoftware.chemistry.core import *
from nanotechsoftware.chemistry.processor import *
from nanotechsoftware.chemistry.io import *

from itertools import *

import os

def quantify(seq, pred = bool):
    "Count how many times the predicate is True in the sequence"
    return sum(imap(pred, seq))



mol = fromSmiles("c1ccccc1c2ccccc2")

AssignIndexProcessor()(mol)

for atom in CompositeIteratorFactory.create(Atom, mol):
    print "atom ", atom.getIndex(), atom.getInRing(),
    quantify(AtomIterator(atom), IsInRing())
    print

rings = BuildRingsProcessor()(mol)
print "Number of rings : ", \
      quantify(ComponentIteratorFactory.create(Composite, rings))
for ring in ComponentIteratorFactory.create(Composite, rings) :
    print "Ring size = ", \
          quantify(ComponentIteratorFactory.create(Atom, ring))
    for atom in ComponentIteratorFactory.create(Atom, ring) :
        print "Atom ", atom.getIndex()


