uibcdf / MolSysMT

Open source library to work with molecular systems
https://www.uibcdf.org/MolSysMT/
Other
12 stars 3 forks source link

New class iterator in the module `structure` to work with trajectories. #76

Closed dprada closed 2 years ago

dprada commented 2 years ago

In my opinion, the only important functionality left to implement before publishing this is something to work with trajectories. We could probably discuss here how this tool could be shaped.

I would like to avoid additional auxiliary classes as most of the libraries have (mdtraj or MDAnalysis). In my opinion the power of the tool should be in a unique place, a iterator.

¿What do we need? We need a tool to extract frames (step, time, coordinates, and boxes) in a smart and simple way when these structures are stored in a trajectory file. However, their use should not be restricted to trajectory files.

As user, I would like to do something like this:

import molsysmt as msm

iterator = msm.structure.iterator('traj.h5', start=100, interval=10, stop=200, selection='atom_name=="CA"')

for step, time, coordinates, box in iterator:
     print(step, time, coordinates, box)

iterator.close()

or

import molsysmt as msm

iterator = msm.structure.iterator(['traj.gro', 'traj.xtc'], indices=[10, 22, 30, 78, 145], selection=[10, 11, 12])

for step, time, coordinates, box in iterator:
     print(step, time, coordinates, box)

iterator.close()

or

import molsysmt as msm

iterator = msm.structure.iterator('traj.dcd', start=1, interval=10, stop=1000, chunk_size=20)

for _, chunk_times, chunk_coordinates, _ in iterator:
     print(chunk_times, chunk_coordinates)

iterator.close()

This iterator could have the following instatation arguments:

I am not sure if to do this iterator method, we need to define a specific structures_iterator in the module item for each form (trajectory file or form with structures in general).

@Daniel-Ibarrola: What do you think? Do you have an alternative proposal?

dprada commented 2 years ago

This issue was fixed with #86 by @Daniel-Ibarrola.