
Hey there, I am trying to write an mrc file using the write_mrc2000_grid_data module. My function is below. My array of data is a <scitbx_array_family_flex_ext.double object at 0x58b9502c>. Which is a basically a matrix with dimensions: (243, 243, 243). When trying to write an mrc file using this array I get the following error: ************************* File "/home/eshacham/cctbx/mrc_functions.py", line 20, in write_mrc write_mrc2000_grid_data(g, path) File "CHIMERA/share/VolumeData/mrc/writemrc.py", line 44, in write_mrc2000_grid_data File "CHIMERA/share/VolumeData/arraygrid.py", line 48, in submatrix ValueError: need more than 1 value to unpack Code used *********************** def write_mrc(data): print data origin = (1.54, 2.45, 3.45) # XYZ coordinates of array index (0,0,0) step = (.25, .25, .25) # Spacing between grid points import Numeric a = Numeric.array(data, Numeric.Float32) arrays = [a] import VolumeData g = VolumeData.Array_Grid_Data(arrays, origin, step) path = '/home/eshacham/structures/result.mrc' from VolumeData.mrc import write_mrc2000_grid_data write_mrc2000_grid_data(g, path) I am assuming that it has to do with my array dimensions. Any help would be greatly appreciated. Cheers, Eran.

Hi Eran, The problem is the argument "data" being passed to your routine is 1-dimensional, it needs to be 3-dimensional. For instance you are passing an array to your write_mrc() routine that looks like data = (1,2,3,4,5,6,7,8) instead of data = (((1,2),(3,4)),((5,6), (7,8))) # Dimensions 2 by 2 by 2 There are two solutions. Either you pass in the 3-dimensional array to your routine, or you pass in 1-dimensional array and a second argument which gives the grid size. This second option would look like: def write_mrc(data, zyx_grid_size): print data origin = (1.54, 2.45, 3.45) # XYZ coordinates of array index (0,0,0) step = (.25, .25, .25) # Spacing between grid points import Numeric a = Numeric.array(data, Numeric.Float32) a = a.resize(zyx_grid_size) arrays = [a] import VolumeData g = VolumeData.Array_Grid_Data(arrays, origin, step) path = '/home/eshacham/structures/result.mrc' from VolumeData.mrc import write_mrc2000_grid_data write_mrc2000_grid_data(g, path) Example call: data = (1,2,3,4,5,6,7,8) zyx_grid_size = (2,2,2) write_mrc(data, zyx_grid_size) Notice that the grid size is 3 numbers (zs,ys,xs) the first being the z-axis size. Also the data values in the 1-D array have to be ordered such that x varies fastest, y second fastest, and z slowest. In other words the first xs*ys numbers are the first z plane of data. Tom

Hi Eran, Oops! My suggested code was wrong. a = a.resize(grid_size) gives an error because Numeric tries copy values of a into a instead of just rebinding variable a. The corrected version is below. Tom def write_mrc(data, zyx_grid_size): print data origin = (1.54, 2.45, 3.45) # XYZ coordinates of array index (0,0,0) step = (.25, .25, .25) # Spacing between grid points import Numeric a = Numeric.array(data, Numeric.Float32) a_3d = a.resize(zyx_grid_size) arrays = [a_3d] import VolumeData g = VolumeData.Array_Grid_Data(arrays, origin, step) path = '/home/eshacham/structures/result.mrc' from VolumeData.mrc import write_mrc2000_grid_data write_mrc2000_grid_data(g, path)
participants (2)
-
Eran Shacham
-
Thomas Goddard