Project

General

Profile

Feature #2766 ยป repairEPUmrc.py

Ryan Hoffman, 05/12/2014 07:32 AM

 
#!/usr/bin/env python

#rmbh14
#thanks to Anchi Cheng, Scott Stagg, Chris Arthur

#USAGE: ./repairEPUmrc.py FEI-format.mrc MRC-format.mrc angstroms-per-pixel

import pyami.mrc
import sys,numpy

f = sys.argv[1] #input file (EPU-generated MRC)
outf = sys.argv[2] #output file (unbroken MRC)
apix = sys.argv[3] #angstroms-per-pixel

oldHeader = pyami.mrc.readHeaderFromFile( f )

newHeader= pyami.mrc.newHeader()
newHeader['shape'] = oldHeader['shape']
newHeader['mode'] = 1
newHeader['dtype'] = oldHeader['dtype']
newHeader['nx'] = oldHeader['nx']
newHeader['mx'] = newHeader['nx']
newHeader['ny'] = oldHeader['ny']
newHeader['my'] = newHeader['ny']
newHeader['nz'] = oldHeader['nz']
newHeader['mz'] = newHeader['nz']
#print float(newHeader['nx'])*float(apix)
boxLength = "%.2f" % float(float(newHeader['nx'])*float(apix))
newHeader['cella'] = ( boxLength, boxLength, 1.0 )
newHeader['cellb'] = ( 90.0, 90.0, 90.0 )
newHeader['nsymb'] = 0
newHeader['machst'] = pyami.mrc.fix_file_machine_stamp( f )

#print oldHeader
#print newHeader

dataOnly = numpy.asarray( pyami.mrc.read( f ), 'int16' )

pyami.mrc.write( dataOnly, outf , newHeader)
    (1-1/1)