Maybe if I provide some more information on the problem it gets clearer:
I have a
Atom, which contains the information of the atoms of my system. To simplify, let us suppose that it has 2 fields, the
name and the molecule to which it belongs, i. e.:
Now I have a vector of “atoms”, for example with 2 water molecules:
julia> atoms = [ Atom("O",1), Atom("H",1), Atom("H",1),
Atom("O",2), Atom("H",2), Atom("H",2) ]
The molecules are always consecutive (not necessarily consecutive, but the molecule numbers are unique for each molecule), and are numbered according to the
molecule field. What I want is to iterate over the molecules, with:
for molecule in eachmolecule(atoms)
So I have to implement the
eachmolecule function that generates the iterator.
One thing that I have to decide what is one molecule. It may be a vector of atoms, a view of a vector of atoms, or another struct with the range of atoms of the original vector of atoms (the option I am leaning to).
Working on it from the information provided. Thanks!