project-gemmi / gemmi

macromolecular crystallography library and utilities
https://project-gemmi.github.io/
Mozilla Public License 2.0
231 stars 46 forks source link

Gemmi setup MapReorderOnly never sets AxisOrder for a grid #322

Open gabriellareggiano opened 4 months ago

gabriellareggiano commented 4 months ago

Hello,

I've been using gemmi for a bit and I wanted to check that this was the intended behavior. I load in a X-ray map which has a map extent that is not equal to the unit cell. When I attempt to do setup with the MapReorderOnly, the axis order of the grid stays as unknown. Here's my ipython session (just removed some typo lines), gemmi version 0.6.4:

In [17]: m8jsd = gemmi.read_ccp4_map("8jsd-createmap-out-0.ccp4")

In [21]: m8jsd.setup(float('nan'), mode=gemmi.MapSetup.ReorderOnly)

In [22]: m8jsd.grid.axis_order
Out[22]: <AxisOrder.Unknown: 0>

In [24]: m8jsd.full_cell()
Out[24]: False

In [26]: m8jsd.setup(float('nan'))

In [28]: m8jsd.grid.axis_order
Out[28]: <AxisOrder.XYZ: 1>

I believe this happens because it's not in the full cell. Is this the intended usage? It's confusing to me that the axis_order is not updated unless the grid is in the full cell, since we already have the full cell function. Is it to prevent other functions from running on a non-full cell grid?

For context, I just wanted to use set_subarray for this non-full cell grid, which understandably asks for XYZ axis order.

Thank you for your help!

wojdyr commented 4 months ago

Yes, it's confusing. axis_order ended up being primarily used to check if a grid corresponds to the unit cell.

Almost all grid functions work only in full-cell mode, with periodic boundary conditions (grid coordinates modulo grid size) always applied. I know it sometimes gets in the way. On the other hand, having a grid from (0,0,0) to (1,1,1) simplifies things.

We could have a separate class for 3D array data that would allow offset and wouldn't have translation symmetry. I've had it in mind for a long time, but I'm not sure if it's a good idea and what such class would be useful for.

As an alternative to set_subarray, you could modify grid.array which is a NumPy array interface to the grid.