Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
atoms.positions returns a copy of the underlying array #2069
Code to reproduce the behavior
import MDAnalysis as mda import numpy as np u = mda.fetch_mmtf('1UBQ') u.atoms[:5].positions[:] = np.ones((5, 3)) print(np.allclose(np.ones((5,3)), u.atoms[:5].positions))
I know this a limitation of numpy when indexing. I'm also aware that my code example is not how one would ideally write the code. However, this is still potentially confusing behavior and I think we get questions about this on the mailing list once in a while.
I also do not know a good solution to this problem. Or even if there is one using numpy. It would still be nice to have this in a
It is definitely possible to write our own array structure in C that supports to create views to individual atoms. I don't think the effort this would involve is worth it though.
Currently version of MDAnalysis