#!/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.io import *

from itertools import *

import os

class HasAtomicNumber:
      def __init__(self, n):
        self.n = n
      def __call__(self, a):
        return a.getElement().getAtomicNumber() == self.n 

def quantify(seq, pred=bool):
    return sum(imap(pred, seq))



mol = fromSmiles("c1c(C)c(O)c(N)cc1")

print "Number of Oxygens = ", quantify(
      CompositeIteratorFactory.create(Atom, mol), IsOxygen())
print "Number of Carbons = ", quantify(
      CompositeIteratorFactory.create(Atom, mol), HasAtomicNumber(6))


