[Chimera-users] writing mrc files

Thomas Goddard goddard at cgl.ucsf.edu
Fri Apr 21 13:46:56 PDT 2006

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.


More information about the Chimera-users mailing list