freud
freud copied to clipboard
NeighborQuery.box can't be edited
Describe the bug Trying to edit properties of an AABBQuery's box fails silently.
To Reproduce
system = freud.locality.NeighborQuery.from_system(freud.data.make_random_system(10, 2000))
print(system.box.L)
system.box.Lx = 500
print(system.box.L)
The box length does not change, and issues no warnings or errors.
Additional context This code returns a value instead of a reference: https://github.com/glotzerlab/freud/blob/d96a8ee3365acf647df96c5138129d02a2aeb02d/freud/locality.pyx#L369-L373 https://github.com/glotzerlab/freud/blob/d96a8ee3365acf647df96c5138129d02a2aeb02d/freud/box.pyx#L855-L862
Fixing this requires some nontrivial internal changes. We need to be much more consistent internally about when objects own their own boxes, and we'd probably need to create a new method to generate a Cython box that points to but does not own a C++ box. The former is somewhat related to #616 .
Changing the box's properties would need to trigger a re-computation of the spatial data structure, and it would be complicated to implement "hooks" for the box property setters. Unless I'm overlooking some cleaner implementation, I think this should probably fail.
You would also need to validate that the original positions are still valid in the new box, etc. So yes, I think failing is probably the safest approach.
We probably also need to verify that the NeighborQuery.points
array is returned as read-only...