MDAnalysis / mdanalysis

MDAnalysis is a Python library to analyze molecular dynamics simulations.
https://mdanalysis.org
Other
1.29k stars 646 forks source link

Remove use of `trajectory.timeseries` from `ENCORE` #3761

Closed hmacdope closed 1 year ago

hmacdope commented 2 years ago

Expected behavior

The ENCORE module should work with all kinds of readers. As revealed by the use of the DUMPReader in this mailing list question this is not the case.

Actual behavior

The use of trajectory.timestep in ENCORE in many places means it cannot use readers that do not have the timeseries attribute. Currently only DCDReader and MemoryReader expose the timeseries attribute in the correct way to allow ENCORE to work.

Code to reproduce the behavior

import MDAnalysis as mda
from MDAnalysis.analysis import encore
from MDAnalysisTests.datafiles import LAMMPSDUMP
u = mda.Universe(LAMMPSDUMP, format='LAMMPSDUMP',atom_style="id type x y z")

es_conv = encore.ces_convergence(u,  50,  select='index 1') 

The current workaround is to load your trajectory into the MemoryReader using AnalysisFromFunction

import MDAnalysis as mda
from MDAnalysis.coordinates.memory import MemoryReader
from MDAnalysis.analysis.base import AnalysisFromFunction
from MDAnalysisTests.datafiles import PDB, XTC
from MDAnalysis.analysis import encore

u = mda.Universe(PDB, XTC)
coordinates = AnalysisFromFunction(lambda ag: ag.positions.copy(), u.atoms).run().results
u2 = mda.Universe(PDB, coordinates['timeseries'], format=MemoryReader)
es_conv = encore.ces_convergence(u2,  50, select='index 1')

Solution

We should change to using AtomGroup.positions.

IAlibay commented 2 years ago

related MDAnalysis/mdaencore#30 MDAnalysis/mdanalysis#2948

hmacdope commented 1 year ago

Instead we have implemented timeseries in ReaderBase in MDAnalysis/mdanalysis#3890 so all readers will now have access to it which should solve this issue the reverse way.