#!/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
import textwrap

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



mol = XYZ(os.environ['EXAMPLESPATH'] + os.sep + 'mols.xyz')

AssignIndexProcessor()(mol)
BuildBondsProcessor()(mol)

parts = BuildCompositesProcessor()(mol)

print "The molecule has %d components\n" % \
      quantify(ComponentIteratorFactory.create(Composite, parts))

for part in ComponentIteratorFactory.create(Composite, parts) :
    print "Molecule with Atoms :"
    s = ""
    for atom in ComponentIteratorFactory.create(Atom, part) :
        s = s + str(atom.getIndex()) + " "
    print textwrap.fill(s, width=40)
    


