Skip to content

Commit

Permalink
Updated freehand scripts May 2012
Browse files Browse the repository at this point in the history
  • Loading branch information
mcianfrocco committed May 7, 2012
1 parent 1483120 commit c40ea11
Show file tree
Hide file tree
Showing 40 changed files with 3,676 additions and 34 deletions.
23 changes: 23 additions & 0 deletions 3D_spi_to_3D_mrc.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/csh -f

set file = $1

setenv IMAGIC_BATCH 1
echo "! "
echo "! "
echo "! ====================== "
echo "! IMAGIC ACCUMULATE FILE "
echo "! ====================== "
echo "! "
echo "! "
echo "! IMAGIC program: em2em ------------------------------------------------"
echo "! "
/opt/qb3/imagic-070813/stand/em2em.e <<EOF
SPI
SINGLE_FILE
MRC
3
$file
${file:r}.mrc
NO
EOF
86 changes: 86 additions & 0 deletions EMAN_to_FREALIGN_fromParam_freeHand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env python

from sys import *
import os
from optparse import OptionParser
import glob
import subprocess
from os import system
import sys
import optparse
from EMAN2 import *

def setupParserOptions():
parser = optparse.OptionParser()
parser.set_usage("%prog -p <parameter filek>")
parser.add_option("-p",dest="param",type="string",metavar="FILE",
help="EMAN2 parameter file")

options,args = parser.parse_args()

if len(args) > 1:
parser.error("Unknown commandline options: " +str(args))

if len(sys.argv) < 2:
parser.print_help()
sys.exit()

params={}
for i in parser.option_list:
if isinstance(i.dest,str):
params[i.dest] = getattr(options,i.dest)
return params

def Eman2Freali(az,alt,phi):

t1 = Transform({"type":"eman","az":az,"alt":alt,"phi":phi,"mirror":False})

#t_conv = Transform({"type":"eman","alt":31.717474411458415,"az":90,"phi":-90,"mirror":False})

#t2 = t1*t_conv.inverse()

d = t1.get_params("eman")

psi = d["phi"]+90

if psi >360:

psi = psi-360

theta= d["alt"]

phi = d["az"]-90

return psi,theta,phi

def main(params):
parm=params['param']

f=open(parm,'r')
out = open("%s_freeHand"%(parm),'w')
count=1
count2=1
count=1
for line in f:

l = line.split()

parmPSI = float(l[0])
parmTHETA = float(l[1])
parmPHI = float(l[2])
sx =(float(l[3]))
sy =(float(l[4]))
model = float(l[5])

psi,theta,phi = Eman2Freali(parmPSI,parmTHETA,parmPHI)

out.write("%s %s %s %s %s %s\n"%(psi,theta,phi,sx,sy,model))


f.close()
out.close()

#Need this at the end for the parse commands
if __name__ == "__main__":
params=setupParserOptions()
main(params)
34 changes: 21 additions & 13 deletions ctftilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
stack2 = 'stack01' #stack name for tilted particles

#Inputs
shrink = 4 #Binning factor for final particle stack
new = 64 #Box size for binned particles
shrink = 2 #Binning factor for final particle stack
new = 128 #Box size for binned particles
scale = 4 #Binning factor used for micrograph from which the particles were picked

#CTFTILT inputs
parm3 = "2.2,120.0,0.2,99993,15,2\n" # !CS[mm],HT[kV],AmpCnst,XMAG,DStep[um]
parm4 = "128,400.0,8.0,2000.0,30000.0,500.0,30,5\n" #!Box,ResMin[A],ResMax[A],dFMin[A],dFMax[A],FStep
parm3 = "2.2,120.0,0.07,80000,12.03141,2\n" # !CS[mm],HT[kV],AmpCnst,XMAG,DStep[um]
parm4 = "128,400.0,8.0,2000.0,35000.0,500.0,30,5\n" #!Box,ResMin[A],ResMax[A],dFMin[A],dFMax[A],FStep

############# Script ###############

Expand All @@ -25,7 +25,7 @@

p1 = open(paramOUT1,'wa')
p2 = open(paramOUT2,'wa')
cmd = "/opt/qb3/frealign-9.02/bin/ctftilt.exe"
cmd = "/users/glander/myami_latest/appion/bin/ctftilt64.exe"

#syntax: grep(regexp_string,list_of_strings_to_search)
def grep(string,list):
Expand All @@ -34,9 +34,13 @@ def grep(string,list):

list = glob.glob('*en_00.mrc')

micro = 1
particle1 = 1
particle2 = 1

for file in list:
tmp1 = re.sub("_00_","_01_",file)
tiltname = re.sub("en_00","en_01",tmp1)
tmp1 = re.sub("_00_","_01_",file)
tiltname = re.sub("en_00","en_01",tmp1)
#Check if both files exist
if os.path.isfile(file) & os.path.isfile(tiltname):
a = subprocess.Popen(cmd, -1, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand All @@ -52,7 +56,8 @@ def grep(string,list):

while i <= tot:

p1.write('%s %s %s %s\n' %(out3[0],out3[1],out3[2],out3[4]))
p1.write('%s %s %s %s %s %s\n' %(out3[0],out3[1],out3[2],out3[4],str(particle1),str(micro)))
particle1 = particle1 + 1
i = i + 1

cmd2 = 'batchboxer input=%s.mrc dbbox=%s.box scale=%s output=%s.img' %(fname,fname,scale,stack1)
Expand All @@ -71,20 +76,23 @@ def grep(string,list):

while i <= tot:

p2.write('%s %s %s %s\n' %(out3[0],out3[1],out3[2],out3[4]))
p2.write('%s %s %s %s %s %s\n' %(out3[0],out3[1],out3[2],out3[4],str(particle2),str(micro)))
particle2 = particle2 + 1
i = i + 1

cmd2 = 'batchboxer input=%s.mrc dbbox=%s.box scale=%s output=%s.img' %(fname,fname,scale,stack2)
subprocess.Popen(cmd2,shell=True).wait()

cmd3 = 'proc2d %s.img %s_dc4.img meanshrink=%s' %(stack1,stack1,shrink)
micro = micro + 1

cmd3 = 'proc2d %s.img %s_dc%01d.img meanshrink=%s' %(stack1,stack1,float(shrink),shrink)
subprocess.Popen(cmd3,shell=True).wait()

cmd4 = 'proc2d %s_dc4.img %s_dc4_%03d.img clip=%s edgenorm=0,1' %(stack1,stack1,float(new),new)
cmd4 = 'proc2d %s_dc%01d.img %s_dc%01d_%03d.img clip=%s edgenorm=0,1' %(stack1,float(shrink),stack1,float(shrink),float(new),new)
subprocess.Popen(cmd4,shell=True).wait()

cmd3 = 'proc2d %s.img %s_dc4.img meanshrink=%s' %(stack2,stack2,shrink)
cmd3 = 'proc2d %s.img %s_dc%01d.img meanshrink=%s' %(stack2,stack2,float(shrink),shrink)
subprocess.Popen(cmd3,shell=True).wait()

cmd4 = 'proc2d %s_dc4.img %s_dc4_%03d.img clip=%s edgenorm=0,1' %(stack2,stack2,float(new),new)
cmd4 = 'proc2d %s_dc%01d.img %s_dc%01d_%03d.img clip=%s edgenorm=0,1' %(stack2,float(shrink),stack2,float(shrink),float(new),new)
subprocess.Popen(cmd4,shell=True).wait()
110 changes: 110 additions & 0 deletions ctftilt_ace2_weiner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env python

#Output filenames
paramOUT1 = 'parameter_00.par' #param filename for untilted particles
paramOUT2 = 'parameter_01.par' #param filename for tilted particles
stack1 = 'stack00' #stack name for untilted particles
stack2 = 'stack01' #stack name for tilted particles

#Inputs
shrink = 2 #Binning factor for final particle stack
new = 256 #Box size for binned particles
scale = 4 #Binning factor used for micrograph from which the particles were picked

#CTFTILT inputs
parm3 = "2.2,120.0,0.07,80000,12.03141,2\n" # !CS[mm],HT[kV],AmpCnst,XMAG,DStep[um]
parm4 = "128,400.0,8.0,20000,30000,1000.0,30,5\n" #!Box,ResMin[A],ResMax[A],dFMin[A],dFMax[A],FStep

############# Script ###############

from decimal import *
import subprocess
import sys
import re
import os
import glob

p1 = open(paramOUT1,'wa')
p2 = open(paramOUT2,'wa')
cmd = "/users/glander/myami_latest/appion/bin/ctftilt64.exe"

#syntax: grep(regexp_string,list_of_strings_to_search)
def grep(string,list):
expr = re.compile(string)
return filter(expr.search,list)

list = glob.glob('*en_00.mrc')

l = parm3.split(',')
ang = Decimal(str(10**10))
apix = str(((Decimal(l[4])*(Decimal(str(10**-6))))/Decimal(l[3]))*ang)
cs = Decimal(l[0])/1000
kv = l[1]

for file in list:
tmp1 = re.sub("_00_","_01_",file)
tiltname = re.sub("en_00","en_01",tmp1)
#Check if both files exist
if os.path.isfile(file) & os.path.isfile(tiltname):
a = subprocess.Popen(cmd, -1, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
[o,e] = a.communicate('%s\n'%(file) + '%s.diag\n'%(file) + parm3 + parm4)
out = grep("Final Values", o.split("\n"))
out2 = out[0]
out3 = out2.split()

fname = file.strip('.mrc')
b = open('%s.box'%(fname))
tot = len(b.readlines())
i = 1

while i <= tot:

p1.write('%s %s %s %s\n' %(out3[0],out3[1],out3[2],out3[4]))
i = i + 1

#Weiner filter (with Ace2) micrograph before boxing

ang = Decimal(str(10**10))

df1 = -1*(Decimal(out3[0])/ang)
df2 = -1*(Decimal(out3[1])/ang)
astig = (out3[2])

df = '%s,%s,%s' %(df1,df2,astig)

cmd3 = '/users/glander/myami_latest/appion/bin/ace2correct.exe -img %s -kv %s -cs %s -apix %s -df %s -wiener 0.1' %(file,kv,cs,apix,df)
subprocess.Popen(cmd3,shell=True).wait()

cmd2 = 'batchboxer input=%s.mrc.corrected.mrc dbbox=%s.box scale=%s output=%s.img' %(fname,fname,scale,stack1)
subprocess.Popen(cmd2,shell=True).wait()

a = subprocess.Popen(cmd, -1, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
[o,e] = a.communicate('%s\n'%(tiltname) + '%s.diag\n'%(tiltname) + parm3 + parm4)
out = grep("Final Values", o.split("\n"))
out2 = out[0]
out3 = out2.split()

fname = tiltname.strip('.mrc')
b = open('%s.box'%(fname))
tot = len(b.readlines())
i = 1

while i <= tot:

p2.write('%s %s %s %s\n' %(out3[0],out3[1],out3[2],out3[4]))
i = i + 1

cmd2 = 'batchboxer input=%s.mrc dbbox=%s.box scale=%s output=%s.img' %(fname,fname,scale,stack2)
subprocess.Popen(cmd2,shell=True).wait()

cmd3 = 'proc2d %s.img %s_dc%01d.img meanshrink=%s' %(stack1,stack1,float(shrink),shrink)
subprocess.Popen(cmd3,shell=True).wait()

cmd4 = 'proc2d %s_dc%01d.img %s_dc%01d_%03d.img clip=%s edgenorm=0,1' %(stack1,float(shrink),stack1,float(shrink),float(new),new)
subprocess.Popen(cmd4,shell=True).wait()

cmd3 = 'proc2d %s.img %s_dc%01d.img meanshrink=%s' %(stack2,stack2,float(shrink),shrink)
subprocess.Popen(cmd3,shell=True).wait()

cmd4 = 'proc2d %s_dc%01d.img %s_dc%01d_%03d.img clip=%s edgenorm=0,1' %(stack2,float(shrink),stack2,float(shrink),float(new),new)
subprocess.Popen(cmd4,shell=True).wait()
24 changes: 24 additions & 0 deletions e2proc3d.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/csh -f

set file = $1

setenv IMAGIC_BATCH 1
echo "! "
echo "! "
echo "! ====================== "
echo "! IMAGIC ACCUMULATE FILE "
echo "! ====================== "
echo "! "
echo "! "
echo "! IMAGIC program: em2em ------------------------------------------------"
echo "! "
/opt/qb3/imagic-070813/stand/em2em.e <<EOF
IMAGIC
SPI
SINGLE_FILE
3
${file:r}
${file:r}.spi
LINUX
NO
EOF
24 changes: 24 additions & 0 deletions e2proc3d_all.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/csh -f

set file=$1

setenv IMAGIC_BATCH 1
echo "! "
echo "! "
echo "! ====================== "
echo "! IMAGIC ACCUMULATE FILE "
echo "! ====================== "
echo "! "
echo "! "
echo "! IMAGIC program: em2em ------------------------------------------------"
echo "! "
/opt/qb3/imagic-110326/stand/em2em.e <<EOF
IMAGIC
SPI
SIN
3
${file}
${file}.spi
LINUX
YES
EOF
36 changes: 36 additions & 0 deletions e2proc3d_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python

#This will convert all volumes within an HDF file into separate SPIDER volumes

#To run:

#./e2proc3d_all.py volume_file.hdf [volume number wanted]

import glob
import subprocess
import sys

f = sys.argv[1]
num=float(sys.argv[2])

new=f.strip('.hdf')

cmd="e2proc3d.py --first=%01d --last=%01d %s %s_%03d.hdf" %(num,num,f,new,num)
subprocess.Popen(cmd,shell=True).wait()

cmd="proc3d %s_%03d.hdf %s_%03d.img imagic" %(new,num,new,num)
subprocess.Popen(cmd,shell=True).wait()

cmd="/home/michael/BATCHLIB/freeHand/e2proc3d.b %s_%03d.img" %(new,num)
subprocess.Popen(cmd,shell=True).wait()

cmd="rm %s_%03d.hdf" %(new,num)
subprocess.Popen(cmd,shell=True).wait()

cmd="rm %s_%03d.hed %s_%03d.img" %(new,num,new,num)
subprocess.Popen(cmd,shell=True).wait()

cmd="~michael/BATCHLIB/freeHand/mirror_vols_spi.py %s_%03d.spi" %(new,num)
subprocess.Popen(cmd,shell=True).wait()


Loading

0 comments on commit c40ea11

Please sign in to comment.