-
Notifications
You must be signed in to change notification settings - Fork 1
ConvertNewCTFModelOldCTF
Adrian Quintana edited this page Dec 11, 2017
·
1 revision
#!/usr/bin/env xmipp_python
"""/***************************************************************************
*
* Authors: Roberto Marabini (roberto@cnb.csic.es)
* Josue Gomez
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*
* All comments concerning this program package may be sent to the
* e-mail address 'xmipp@cnb.csic.es'
***************************************************************************/
"""
#!/usr/bin/env xmipp_python
import os
from protlib_xmipp import XmippScript, RowMetaData
from xmipp import *
#old=_old
#for i in */xmipp_ctf.ctfparam
#do
# echo $i
# ./toOldCTF.py -i $i -o $i$old
#done
class ScriptImportCtfparam(XmippScript):
def __init__(self):
XmippScript.__init__(self)
def defineParams(self):
self.addUsageLine('Import a ctfparam file from Xmipp3.0 version')
self.addUsageLine('The new style ctfparam file is converted to a old')
self.addUsageLine('ctfparam file')
## params
self.addParamsLine(' -i <xmd> : micrographs.xmd')
# self.addParamsLine(' -o <old_ctfparam> : Old Xmipp2.4 CTF definition file (.ctfparam)')
## examples
# self.addExampleLine(' xmipp_import_ctfparam -i new.ctfparam -o old.ctfparam')
def run(self):
micsMd = self.getParam('-i')
# oldCtf = self.getParam('-o')
CTF_BASIC_LABELS = [
MDL_CTF_DEFOCUSU,
MDL_CTF_DEFOCUSV,
MDL_CTF_DEFOCUS_ANGLE,
MDL_CTF_SAMPLING_RATE,
MDL_CTF_VOLTAGE,
MDL_CTF_CS,
MDL_CTF_Q0,
MDL_CTF_K]
oldLabelsName = [
'defocusU',
'defocusV',
'azimuthal_angle',
'sampling_rate',
'voltage',
'spherical_aberration',
'Q0',
'K']
conversionDict = dict(zip(CTF_BASIC_LABELS, oldLabelsName))
mdMics = MetaData(micsMd)
for objId in mdMics:
newCtf = mdMics.getValue(MDL_CTF_MODEL, objId)
micFn = os.path.basename(mdMics.getValue(MDL_MICROGRAPH, objId)).split('.')[0]
md = MetaData(newCtf)
oldCtfDir = os.path.join('Preprocessing_down1', micFn)
os.makedirs(oldCtfDir)
oldCtf = os.path.join(oldCtfDir, 'down1_' + micFn + '_Periodogramavg.ctfparam')
f = open(oldCtf,'w')
for label in CTF_BASIC_LABELS:
value = md.getValue(label,1L)
if(label==MDL_CTF_DEFOCUSU):
value = -value
elif(label==MDL_CTF_DEFOCUSV):
value = -value
elif(label==MDL_CTF_Q0):
value = -value
elif(label==MDL_CTF_K):
value = 1.
elif(label==MDL_CTF_SAMPLING_RATE):
value=value
elif(label==MDL_CTF_VOLTAGE):
value= int(value)
#print conversionDict[label]+'='+str(value)
f.write(conversionDict[label]+'= '+str(value)+'\n')
f.close()
if __name__ == '__main__':
ScriptImportCtfparam().tryRun()
-- Main.RobertoMarabini - 2014-08-01