-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreconstruct-all-frame-groups.py
executable file
·79 lines (71 loc) · 2.54 KB
/
reconstruct-all-frame-groups.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
import shutil
import os
import subprocess
import linecache
refine3d='Refine3D/job039/run_data.star'
outdir='recon20190424'
postprocess_mask='MaskCreate/job024/mask.mrc'
angpix=0.885
sym='D2'
mtf='mtf_k2_300kV.star'
maxframes=24
if os.path.exists(outdir):
shutil.rmtree(outdir)
os.makedirs(outdir)
#==============
def updateStarFile(instar,outstar1,outstar2,oldsuffix,newsuffix):
instaropen=open(instar,'r')
o1=open(outstar1,'w')
o2=open(outstar2,'w')
for line in instaropen:
if len(line)<40:
o1.write(line)
o2.write(line)
if len(line)>40:
groupnum=line.split()[-1]
if groupnum == '1':
newline=line.replace(oldsuffix,newsuffix)
o1.write(newline)
if groupnum == '2':
newline=line.replace(oldsuffix,newsuffix)
o2.write(newline)
o1.close()
o2.close()
instaropen.close()
#Go through refine3D to re-generate half STAR file sets
currframe=2
while currframe<=maxframes:
updateStarFile(refine3d,'%s/run_half1_class001_unfil_1_%i.star' %(outdir,currframe),'%s/run_half2_class001_unfil_1_%i.star' %(outdir,currframe),"1_%i"%(maxframes),"1_%i" %(currframe))
#reconstruct
submitfile='%s/run_half1_class001_unfil_1_%i_3D_submit.run' %(outdir,currframe)
o1=open(submitfile,'w')
o1.write('''#!/bin/bash
###Inherit all current environment variables
#PBS -V
### Job name
#PBS -N reconstruct
### Keep Output and Error
#PBS -k eo
### Queue name
#PBS -q batch
### Specify the number of nodes and thread (ppn) for your job.
#PBS -l nodes=1:ppn=1,pmem=12gb
### Tell PBS the anticipated run-time for your job, where walltime=HH:MM:SS
#PBS -l walltime=72:00:00
#################################
NSLOTS=$(wc -l $PBS_NODEFILE|awk {'print $1'})
# Ensure the necessary modules are loaded
module load gcc/4.9.4
module load openmpi/3.1.2/gcc/4.9.4
module load relion/3.0_beta-cluster/openmpi/3.1.2
module load imod
# Switch to the working directory
cd $PBS_O_WORKDIR
relion_reconstruct --o %s/run_half1_class001_unfil_1_%i_3D.mrc --i %s/run_half1_class001_unfil_1_%i.star --ctf --sym %s
relion_reconstruct --o %s/run_half2_class001_unfil_1_%i_3D.mrc --i %s/run_half2_class001_unfil_1_%i.star --ctf --sym %s
relion_postprocess --mask %s --i %s/run_half1_class001_unfil_1_%i_3D.mrc --o %s/run_class001_1_%i_3D_postprocess --angpix %f --mtf %s --auto_bfac --autob_lowres 10\n''' %(outdir,currframe,outdir,currframe,sym,outdir,currframe,outdir,currframe,sym,postprocess_mask,outdir,currframe,outdir,currframe,angpix,mtf))
o1.close()
cmd='qsub %s' %(submitfile)
subprocess.Popen(cmd,shell=True).wait()
currframe=currframe+1