-
Notifications
You must be signed in to change notification settings - Fork 824
Description
Universe pickling might be somewhat tricky (#173), and unpickling might be a relatively heavy operation if it involves reloading trajectories.
I've run into the need to pickle Universes mostly as a side effect of actually wanting to pickle AtomGroups, in my case as a return from a multiprocessing.pool.map.
My idea was to provide lightweight pickling and unpickling functions that'd do the following:
- Pickling: only atom indices are stored, together with some sort of heuristic for
Universeidentification (total number of atoms and trajectory filename, for instance). - Unpickling: run through
globals()looking for aUniversethat matches the heuristic. RecreateAtomGroupfrom the indices. (Raise an error if no suitableUniverseis found).
Search could be sped up by saving with the pickle the Universe names that have the same id as the AtomGroup's, and then looking at those names first when unpickling:
universe_names = []
key, val = None, None #Extremely unpythonic, but these can't be created on the for loop otherwise the globals() dict gets changed.
for key,val in globals().iteritems():
if val is atom_group.universe:
universe_names.append(key)The whole thing feels quite unpythonic, and granted can be easily worked around by just passing back and forth atom index lists instead of AtomGroups. But it'd make MDAnalysis work better and more natively with other code that requires pickling.
Opinions?