Modified. Bug on chainIter().
The selection should be done on the lists of positions not on the basis of the number of atoms (upbound to be sobstituted!).