def main(): (options, rawimage) = parse_command_line() pid = EMAN.LOGbegin(sys.argv) EMAN.LOGInfile(pid, rawimage) imagenum = EMAN.fileCount(rawimage)[0] for iter in range(options.iters): projfile = "proj.%d.hdf" % (iter+1) cmplstfile = "cmp.%d.lst" % (iter+1) ortlstfile = "ort.%d.lst" % (iter+1) mapfile = "threed.%da.mrc" % (iter) mapfile2 = "threed.%da.mrc" % (iter+1) if options.eotest: mapfile2e = "threed.%da.e.mrc" % (iter+1) mapfile2o = "threed.%da.o.mrc" % (iter+1) subsetlste = "ort.%d.e.lst" % (iter+1) subsetlsto = "ort.%d.o.lst" % (iter+1) fscfile = "fsc.%d.txt" % (iter+1) else: mapfile2e = None mapfile2o = None subsetlste = None subsetlsto = None fscfile = None if not os.path.exists(mapfile): print "ERROR: cannot find 3D map \"%s\"" % (mapfile) sys.exit() else: d = EMAN.EMData() d.readImage(rawimage,0,1) # read header rnx = d.xSize() rny = d.ySize() d.readImage(mapfile,-1,1) # read header mnx = d.xSize() mny = d.ySize() mnz = d.zSize() if rnx!=mnx or rny!=mny: print "ERROR: raw images (%s) sizes (%dx%d) are different from the 3D map (%s) sizes (%dx%dx%d)" % (rawimage, rnx, rny, mapfile, mnx, mny, mnz) sys.exit() if not os.path.exists(cmplstfile): runpar_file = "runpar.%d.ortcen.txt" % (iter+1) n = imagenum/options.batchsize if imagenum%n: n+=1 if n<options.cpus: n=options.cpus options.batchsize=imagenum/n+1 if options.batchsize==1: n = imagenum options.batchsize=1 num_tries = 0 max_tries = 3 while not os.path.exists(ortlstfile) and num_tries < max_tries: runparfp = open(runpar_file, "w") num_tries += 1 todo_num = 0 sublstfiles = [] cmpsublstfiles = [] for i in range(n): cmplstfile_tmp = "cmp.%d.%d.lst" % (iter+1, i) ortlstfile_tmp = "ort.%d.%d.lst" % (iter+1, i) startNum = i * options.batchsize endNum = (i+1) * options.batchsize if startNum>=imagenum: break if endNum>imagenum: endNum=imagenum sublstfiles.append(ortlstfile_tmp) cmpsublstfiles.append(cmplstfile_tmp) if os.path.exists(ortlstfile_tmp): continue else: todo_num += 1 cmd = "symrelax.py %s %s " % (rawimage, mapfile) if options.sffile: cmd += "--sf=%s " % ( options.sffile ) if options.phasecorrected: cmd += "--phasecorrected " cmd += "--verbose=%d " % (options.verbose ) cmd += "--mask=%d " % (options.mask) cmd += "--startSym=%s " % (options.startSym) cmd += "--endSym=%s " % (options.endSym) cmd += "--first=%d --last=%d " % (startNum, endNum) cmd += "--shrink=%d " % (options.shrink) cmd += "--ortlstfile=%s " % (ortlstfile_tmp) cmd += "--score=%s " % (options.scorefunc) if options.saveprojection: cmd += "--projection=%s " % (projfile) cmd += "--cmplstfile=%s " % (cmplstfile_tmp) if i: cmd += "--nocmdlog " if i == 0: print cmd runparfp.write("%s\n" % (cmd)) runparfp.close() if todo_num: cmd = "runpar proc=%d,%d file=%s" % (options.cpus, options.cpus, runpar_file) print cmd os.system(cmd) #now merge all sublst file # first test if all jobs are done properly done = 1 for lstfile_tmp in sublstfiles: if not os.path.exists(lstfile_tmp): done = 0 if done: EMAN.merge_lstfiles(sublstfiles, ortlstfile, delete_lstfiles = 1) # pool the cmplstfiles if options.saveprojection: EMAN.merge_lstfiles(cmpsublstfiles, cmplstfile, delete_lstfiles = 1) if not os.path.exists(ortlstfile) or (os.path.exists(ortlstfile) and os.path.getsize(ortlstfile)<=5): print "ERROR: raw image new orientation results lst file \"%s\" is not generated properly" % (ortlstfile) sys.exit() if not os.path.exists(mapfile2): reconstruction_by_make3d(ortlstfile, mapfile2, options=options, mapfile2e=mapfile2e, mapfile2o=mapfile2o, fscfile=fscfile) if not (os.path.exists(mapfile2) and os.path.getsize(mapfile2)): print "ERROR: 3D map \"%s\" is not generated properly" % (mapfile2) sys.exit() EMAN.LOGend()