Skip to content

Inconsistent assignation behavior of the memory reader #2018

@jbarnoud

Description

@jbarnoud

Expected behavior

Any operation that modify the coordinates on a time step is permanent when using the memory reader. Switching frames do not erase the changes.

Actual behavior

Applied to u.trajectory.ts.positions, operations that modify in place the underlying array are kept permanent (e.g. +=) while operations that replaces the array are lost when switching frames.

Everything works as expected when working on an AtomGroup.

The behavior is thus not consistent. It also breaks @davidercruz's rotateby transformation when applied to the memory reader (see #2000).

Code to reproduce the behavior

Show us how to reproduce the failiure. If you can, use trajectory files from the test data.

import numpy as np
import MDAnalysis as mda

n_frames = 5
n_atoms = 4
n_dims = 3

total_coords = n_frames * n_atoms * n_dims
shape = (n_frames, n_atoms, n_dims)
coords = np.arange(total_coords, dtype=np.float32).reshape(shape)

u = mda.Universe(coords)
print(u.atoms.positions)

new_positions = u.atoms.positions + 10
print(new_positions)

## Replace the coordinates
u.trajectory.ts.positions = new_positions
#u.atoms.positions = new_positions
print(u.trajectory.ts.positions)
print(u.atoms.positions)  # these are the new coordinates

u.trajectory[0]
print(u.trajectory.ts.positions)  # the new coordinates are lost

## Modify the coordinates
u.trajectory.ts.positions *= 4
print(u.trajectory.ts.positions)  # these are the new coordinates

u.trajectory[0]
print(u.trajectory.ts.positions)  # these are still the new coordinates

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions