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

MemoryReader and MDAnalysis.analysis.distances.distance_array #1065

Closed
joaommartins opened this issue Nov 4, 2016 · 3 comments
Closed

MemoryReader and MDAnalysis.analysis.distances.distance_array #1065

joaommartins opened this issue Nov 4, 2016 · 3 comments

Comments

@joaommartins
Copy link

Expected behaviour

The previous ArrayReader AtomGroup used to return the positions as float32 when generated from a float64 numpy array.
The new MemoryReader-based AtomGroup returns positions in the same format as the input numpy array, in my case float64.

This breaks the usage of MemoryReader trajectories with MDAnalysis.analysis.distances.distance_array, which enforces a strict float32 format for both the reference and configuration arrays.

Is this enforcement needed or should it be allowed to work with float64 as well? Alternatively, should the AtomGroup.positions method always return float32?

Code to reproduce the behaviour

import MDAnalysis as mda

ref = mda.Universe(topology, coords_array, format=MemoryReader)
conf = mda.Universe(topology, coords_array, format=MemoryReader)

ref_coords = ref.select_atoms("name H").positions
conf_coords = conf.select_atoms("protein").positions
 
distance_array = mda.analysis.distances.distance_array(ref_coords, conf_coords)

  File "/Users/joaommartins/.virtualenvs/MDAnalyis_0.16dev/src/mdanalysis/package/MDAnalysis/lib/distances.py", line 179, in _check_array
    raise TypeError("{0} must be of type float32".format(desc))
TypeError: ref must be of type float32

....

Currently version of MDAnalysis:

0.16.0-dev0

@richardjgowers
Copy link
Member

Hey, thanks for the nice report.

So short term, MemoryReader should always return float32 positions to be in line with all other Readers. This should be a fairly simple fix.

Medium term, distance_array should probably learn to check arguments and convert them to float32 (possible with a warning of loss of precision).

Longer term, the forced float32 precision in distance_array and friends is annoying, (especially since they return float64). Really we should seamlessly support both (like how working with numpy feels).

@orbeckst
Copy link
Member

@wouterboomsma when you hack away at #1063 can you please also fix this issue and properly cast to float32?

@wouterboomsma
Copy link
Contributor

Sure. Will do.

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

5 participants