Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

density_from_Universe does not work with the MemoryReader #1248

Closed
jbarnoud opened this issue Mar 19, 2017 · 4 comments
Closed

density_from_Universe does not work with the MemoryReader #1248

jbarnoud opened this issue Mar 19, 2017 · 4 comments

Comments

@jbarnoud
Copy link
Contributor

Expected behaviour

density_from_Universe creates a Density object from an Universe that use the MemoryReader.

Actual behaviour

density_from_Universe calculate the density, but fails to create the resulting object as it is missing a filename to write as metadata.

Code to reproduce the behaviour

import MDAnalysis as mda
from MDAnalysisTests.datafiles import TPR, XTC
import MDAnalysis.analysis.density as mad

u = mda.Universe(TPR, XTC)
u.transfer_to_memory()
mad.density_from_Universe(u, atomselection='protein')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-6400dc1944f6> in <module>()
      5 u = mda.Universe(TPR, XTC)
      6 u.transfer_to_memory()
----> 7 mad.density_from_Universe(u, atomselection='protein')

/home/jon/dev/mdanalysis/package/MDAnalysis/analysis/density.pyc in density_from_Universe(universe, delta, atomselection, start, stop, step, metadata, padding, cutoff, soluteselection, use_kdtree, update_selection, verbose, interval, quiet, parameters)
    636     metadata = metadata if metadata is not None else {}
    637     metadata['psf'] = u.filename
--> 638     metadata['dcd'] = u.trajectory.filename
    639     metadata['atomselection'] = atomselection
    640     metadata['n_frames'] = n_frames

AttributeError: 'MemoryReader' object has no attribute 'filename'

Currently version of MDAnalysis:

(run python -c "import MDAnalysis as mda; print(mda.__version__)")
'0.16.0-dev0'

@richardjgowers
Copy link
Member

I think MemoryReader.filename came up before, because things like this might happen. Not sure what our Reader API states exactly, but maybe MemoryReader should have a default value of something like MEMORY

@kain88-de
Copy link
Member

See #1027

@orbeckst
Copy link
Member

The quick fix, however, is to make the metadata creation more fault tolerant (or decide to scrap its autogeneration and leave it to usercode to provide the metadata dict). The reason why it's there in the first place was because it can be rather difficult to track provenance of densities; metadata was a simple way to maintain context.

p.s.: bonus points to @jbarnoud for the acronym for importing MDAnalysis.analysis.density ;-)

@jbarnoud
Copy link
Contributor Author

Fixed by #1252.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants