Exemple #1
0
	def doRefit(self):
		parms=self.parms[self.curset]
		apix=self.sapix.getValue()
		ds=1.0/(apix*parms[0]*parms[5])

		try:
			parms[1]=e2ctf.ctf_fit(self.fft1d,parms[1].background,parms[1].background,self.fft,self.fftbg,parms[1].voltage,parms[1].cs,parms[1].ampcont,apix,bgadj=False,autohp=True,verbose=1)
			if self.cbgadj.getValue() :
				self.bgAdj()
				parms[1]=e2ctf.ctf_fit(self.fft1d,parms[1].background,parms[1].background,self.fft,self.fftbg,parms[1].voltage,parms[1].cs,parms[1].ampcont,apix,bgadj=False,autohp=True,verbose=1)
				if self.fitastig : e2ctf.ctf_fit_stig(self.fft,self.fftbg,parms[1],verbose=1)
				self.bgAdj()
			else:
				if self.fitastig : e2ctf.ctf_fit_stig(self.fft,self.fftbg,parms[1],verbose=1)

		except:
			print "CTF Autofit Failed"
			traceback.print_exc()
			parms[1].defocus=1.0

		if self.constbfactor>0 : parms[1].bfactor=self.constbfactor
		self.sdefocus.setValue(parms[1].defocus,True)
		self.sbfactor.setValue(parms[1].bfactor,True)
		self.sampcont.setValue(parms[1].ampcont,True)

		self.update_plot()
Exemple #2
0
	def doRefit(self):
		parms=self.parms[self.curset]
		apix=self.sapix.getValue()
		ds=1.0/(apix*parms[0]*parms[5])

		try:
			parms[1]=e2ctf.ctf_fit(self.fft1d,parms[1].background,parms[1].background,self.fft,self.fftbg,parms[1].voltage,parms[1].cs,parms[1].ampcont,apix,bgadj=False,autohp=True,verbose=1)
			if self.cbgadj.getValue() :
				self.bgAdj()
				parms[1]=e2ctf.ctf_fit(self.fft1d,parms[1].background,parms[1].background,self.fft,self.fftbg,parms[1].voltage,parms[1].cs,parms[1].ampcont,apix,bgadj=False,autohp=True,verbose=1)
				if self.fitastig : e2ctf.ctf_fit_stig(self.fft,self.fftbg,parms[1],verbose=1)
				self.bgAdj()
			else:
				if self.fitastig : e2ctf.ctf_fit_stig(self.fft,self.fftbg,parms[1],verbose=1)

		except:
			print "CTF Autofit Failed"
			traceback.print_exc()
			parms[1].defocus=1.0

		if self.constbfactor>0 : parms[1].bfactor=self.constbfactor
		self.sdefocus.setValue(parms[1].defocus,True)
		self.sbfactor.setValue(parms[1].bfactor,True)
		self.sampcont.setValue(parms[1].ampcont,True)

		self.update_plot()
Exemple #3
0
def importfn(i,arg,options):
	base = base_name(arg,nodir=not options.usefoldername)
	output = os.path.join(os.path.join(".","micrographs"),base+".hdf")
	cmd = "e2proc2d.py %s %s --inplace"%(arg,output)

	cmdext=[]
	if options.invert: cmdext.append(" --mult=-1")
	if options.edgenorm: cmdext.append(" --process=normalize.edgemean")
	if options.xraypixel: cmdext.append(" --process=threshold.clampminmax.nsigma:nsigma=4")
	if len(cmdext)>0 or arg!=output:
		cmd+="".join(cmdext)
		launch_childprocess(cmd)

	if options.moverawdata:
		os.rename(arg,os.path.join(originalsdir,os.path.basename(arg)))
		
	# We estimate the defocus and B-factor (no astigmatism) from the micrograph and store it in info and the header
	if options.ctfest :
		d=EMData(output,0)
		if d["nx"]<1000 or d["ny"]<1000 : 
			print("CTF estimation will only work with images at least 1000x1000 in size")
			sys.exit(1)
		if d["nx"]<2000 : box=256
		elif d["nx"]<4000 : box=512
		elif d["nx"]<6000 : box=768
		else : box=1024

		import e2ctf
		
		ds=1.0/(options.apix*box)
		ffta=None
		nbx=0
		for x in range(100,d["nx"]-box,box):
			for y in range(100,d["ny"]-box,box):
				clip=d.get_clip(Region(x,y,box,box))
				clip.process_inplace("normalize.edgemean")
				fft=clip.do_fft()
				fft.ri2inten()
				if ffta==None: ffta=fft
				else: ffta+=fft
				nbx+=1

		ffta.mult(1.0/(nbx*box**2))
		ffta.process_inplace("math.sqrt")
		ffta["is_intensity"]=0				# These 2 steps are done so the 2-D display of the FFT looks better. Things would still work properly in 1-D without it

		fftbg=ffta.process("math.nonconvex")
		fft1d=ffta.calc_radial_dist(ffta.get_ysize()/2,0.0,1.0,1)	# note that this handles the ri2inten averages properly

		# Compute 1-D curve and background
		bg_1d=e2ctf.low_bg_curve(fft1d,ds)

		#initial fit, background adjustment, refine fit, final background adjustment
		ctf=e2ctf.ctf_fit(fft1d,bg_1d,bg_1d,ffta,fftbg,options.voltage,options.cs,options.ac,options.phaseplate,options.apix,1,dfhint=(options.defocusmin,options.defocusmax))
		bgAdj(ctf,fft1d)
		ctf=e2ctf.ctf_fit(fft1d,ctf.background,ctf.background,ffta,fftbg,options.voltage,options.cs,options.ac,options.phaseplate,options.apix,1,dfhint=(options.defocusmin,options.defocusmax))
		bgAdj(ctf,fft1d)
		
		if options.astigmatism : e2ctf.ctf_fit_stig(ffta,fftbg,ctf)
		
		#ctf.background=bg_1d
		#ctf.dsbg=ds
		db=js_open_dict(info_name(arg,nodir=not options.usefoldername))
		db["ctf_frame"]=[box,ctf,(box/2,box/2),set(),5,1]
		db["quality"]=5
		db.close()
		print(info_name(arg,nodir=not options.usefoldername),ctf)
Exemple #4
0
def main():
    progname = os.path.basename(sys.argv[0])
    usage = """prog [options] <micrograph1, micrograph2....>
	Use this program to import and filter raw micrographs. If you choose to filter and/or convert format, this program will process each micrograph
	and dump them into the directory './micrographs.', otherwise the micrographs will simply be moved into './micrographs'. If you select the option
	--moverawdata AND you filter or change format, your original micrographs will be moved into the directory './raw_micrographs' and your
	filtered micrographs will be in './micrographs as usual. BDB files are not moved, but they can be processed."""

    parser = EMArgumentParser(usage=usage, version=EMANVERSION)

    parser.add_pos_argument(
        name="micrographs",
        help="List the micrographs to filter here.",
        default="",
        guitype='filebox',
        browser="EMRawDataTable(withmodal=True,multiselect=True)",
        row=0,
        col=0,
        rowspan=1,
        colspan=2,
        mode='filter')
    parser.add_pos_argument(
        name="import_files",
        help="List the files to import/filter here.",
        default="",
        guitype='filebox',
        browser="EMBrowserWidget(withmodal=True,multiselect=True)",
        row=0,
        col=0,
        rowspan=1,
        colspan=2,
        mode='import')
    parser.add_header(
        name="filterheader",
        help='Options below this label are specific to filtering',
        title="### filtering options ###",
        row=1,
        col=0,
        rowspan=1,
        colspan=2,
        mode='import,filter')
    parser.add_argument("--invert",
                        action="store_true",
                        help="Invert contrast",
                        default=False,
                        guitype='boolbox',
                        row=2,
                        col=0,
                        rowspan=1,
                        colspan=1,
                        mode='filter[True]')
    parser.add_argument("--edgenorm",
                        action="store_true",
                        help="Edge normalize",
                        default=False,
                        guitype='boolbox',
                        row=2,
                        col=1,
                        rowspan=1,
                        colspan=1,
                        mode='filter[True]')
    parser.add_argument(
        "--usefoldername",
        action="store_true",
        help=
        "If you have the same image filename in multiple folders, and need to import into the same project, this will prepend the folder name on each image name",
        default=False,
        guitype='boolbox',
        row=2,
        col=2,
        rowspan=1,
        colspan=1,
        mode="import[False]")
    parser.add_argument("--xraypixel",
                        action="store_true",
                        help="Filter X-ray pixels",
                        default=False,
                        guitype='boolbox',
                        row=3,
                        col=0,
                        rowspan=1,
                        colspan=1,
                        mode='filter[True]')
    parser.add_argument("--ctfest",
                        action="store_true",
                        help="Estimate defocus from whole micrograph",
                        default=False,
                        guitype='boolbox',
                        row=3,
                        col=1,
                        rowspan=1,
                        colspan=1,
                        mode='filter[True]')
    parser.add_argument("--astigmatism",
                        action="store_true",
                        help="Includes astigmatism in automatic fitting",
                        default=False,
                        guitype='boolbox',
                        row=3,
                        col=2,
                        rowspan=1,
                        colspan=1,
                        mode='filter[False]')
    parser.add_argument(
        "--moverawdata",
        action="store_true",
        help="Move raw data to directory ./raw_micrographs after filtration",
        default=False)
    parser.add_argument("--apix",
                        type=float,
                        help="Angstroms per pixel for all images",
                        default=None,
                        guitype='floatbox',
                        row=5,
                        col=0,
                        rowspan=1,
                        colspan=1,
                        mode="filter['self.pm().getAPIX()']")
    parser.add_argument("--voltage",
                        type=float,
                        help="Microscope voltage in KV",
                        default=None,
                        guitype='floatbox',
                        row=5,
                        col=1,
                        rowspan=1,
                        colspan=1,
                        mode="filter['self.pm().getVoltage()']")
    parser.add_argument("--cs",
                        type=float,
                        help="Microscope Cs (spherical aberation)",
                        default=None,
                        guitype='floatbox',
                        row=6,
                        col=0,
                        rowspan=1,
                        colspan=1,
                        mode="filter['self.pm().getCS()']")
    parser.add_argument("--ac",
                        type=float,
                        help="Amplitude contrast (percentage, default=10)",
                        default=10,
                        guitype='floatbox',
                        row=6,
                        col=1,
                        rowspan=1,
                        colspan=1,
                        mode="filter")
    parser.add_argument("--defocusmin",
                        type=float,
                        help="Minimum autofit defocus",
                        default=0.6,
                        guitype='floatbox',
                        row=8,
                        col=0,
                        rowspan=1,
                        colspan=1,
                        mode="filter[0.6]")
    parser.add_argument("--defocusmax",
                        type=float,
                        help="Maximum autofit defocus",
                        default=4,
                        guitype='floatbox',
                        row=8,
                        col=1,
                        rowspan=1,
                        colspan=1,
                        mode='filter[4.0]')
    parser.add_argument(
        "--ppid",
        type=int,
        help="Set the PID of the parent process, used for cross platform PPID",
        default=-1)

    (options, args) = parser.parse_args()

    microdir = os.path.join(".", "micrographs")
    if not os.access(microdir, os.R_OK):
        os.mkdir("micrographs")

    logid = E2init(sys.argv, options.ppid)

    # After filtration we move micrographs to a directory 'raw_micrographs', if desired
    if options.moverawdata:
        originalsdir = os.path.join(".", "raw_micrographs")
        if not os.access(originalsdir, os.R_OK):
            os.mkdir("raw_micrographs")

    for i, arg in enumerate(args):
        base = base_name(arg, nodir=not options.usefoldername)
        output = os.path.join(os.path.join(".", "micrographs"), base + ".hdf")
        cmd = "e2proc2d.py %s %s --inplace" % (arg, output)

        if options.invert: cmd += " --mult=-1"
        if options.edgenorm: cmd += " --process=normalize.edgemean"
        if options.xraypixel:
            cmd += " --process=threshold.clampminmax.nsigma:nsigma=4"

        launch_childprocess(cmd)
        if options.moverawdata:
            os.rename(arg, os.path.join(originalsdir, os.path.basename(arg)))

        # We estimate the defocus and B-factor (no astigmatism) from the micrograph and store it in info and the header
        if options.ctfest:
            d = EMData(output, 0)
            if d["nx"] < 1200 or d["ny"] < 1200:
                print "CTF estimation will only work with images at least 1200x1200 in size"
                sys.exit(1)
            import e2ctf

            ds = 1.0 / (options.apix * 512)
            ffta = None
            nbx = 0
            for x in range(100, d["nx"] - 512, 512):
                for y in range(100, d["ny"] - 512, 512):
                    clip = d.get_clip(Region(x, y, 512, 512))
                    clip.process_inplace("normalize.edgemean")
                    fft = clip.do_fft()
                    fft.ri2inten()
                    if ffta == None: ffta = fft
                    else: ffta += fft
                    nbx += 1

            ffta.mult(1.0 / (nbx * 512**2))
            ffta.process_inplace("math.sqrt")
            ffta[
                "is_intensity"] = 0  # These 2 steps are done so the 2-D display of the FFT looks better. Things would still work properly in 1-D without it

            fftbg = ffta.process("math.nonconvex")
            fft1d = ffta.calc_radial_dist(
                ffta.get_ysize() / 2, 0.0, 1.0,
                1)  # note that this handles the ri2inten averages properly

            # Compute 1-D curve and background
            bg_1d = e2ctf.low_bg_curve(fft1d, ds)

            #initial fit, background adjustment, refine fit, final background adjustment
            ctf = e2ctf.ctf_fit(fft1d,
                                bg_1d,
                                bg_1d,
                                ffta,
                                fftbg,
                                options.voltage,
                                options.cs,
                                options.ac,
                                options.apix,
                                1,
                                dfhint=(options.defocusmin,
                                        options.defocusmax))
            bgAdj(ctf, fft1d)
            ctf = e2ctf.ctf_fit(fft1d,
                                ctf.background,
                                ctf.background,
                                ffta,
                                fftbg,
                                options.voltage,
                                options.cs,
                                options.ac,
                                options.apix,
                                1,
                                dfhint=(options.defocusmin,
                                        options.defocusmax))
            bgAdj(ctf, fft1d)

            if options.astigmatism: e2ctf.ctf_fit_stig(ffta, fftbg, ctf)

            #ctf.background=bg_1d
            #ctf.dsbg=ds
            db = js_open_dict(info_name(arg, nodir=not options.usefoldername))
            db["ctf_frame"] = [512, ctf, (256, 256), set(), 5, 1]
            print info_name(arg, nodir=not options.usefoldername), ctf

        E2progress(logid, (float(i) / float(len(args))))

    E2end(logid)
Exemple #5
0
def main():
	progname = os.path.basename(sys.argv[0])
	usage = """prog [options] <micrograph1, micrograph2....>
	Use this program to import and filter raw micrographs. If you choose to filter and/or convert format, this program will process each micrograph
	and dump them into the directory './micrographs.', otherwise the micrographs will simply be moved into './micrographs'. If you select the option
	--moverawdata AND you filter or change format, your original micrographs will be moved into the directory './raw_micrographs' and your
	filtered micrographs will be in './micrographs as usual. BDB files are not moved, but they can be processed."""

	parser = EMArgumentParser(usage=usage,version=EMANVERSION)

	parser.add_pos_argument(name="micrographs",help="List the micrographs to filter here.", default="", guitype='filebox', browser="EMRawDataTable(withmodal=True,multiselect=True)",  row=0, col=0,rowspan=1, colspan=2, mode='filter')
	parser.add_pos_argument(name="import_files",help="List the files to import/filter here.", default="", guitype='filebox', browser="EMBrowserWidget(withmodal=True,multiselect=True)",  row=0, col=0,rowspan=1, colspan=2, mode='import')
	parser.add_header(name="filterheader", help='Options below this label are specific to filtering', title="### filtering options ###", row=1, col=0, rowspan=1, colspan=2, mode='import,filter')
	parser.add_argument("--invert",action="store_true",help="Invert contrast",default=False, guitype='boolbox', row=2, col=0, rowspan=1, colspan=1, mode='filter[True]')
	parser.add_argument("--edgenorm",action="store_true",help="Edge normalize",default=False, guitype='boolbox', row=2, col=1, rowspan=1, colspan=1, mode='filter[True]')
	parser.add_argument("--usefoldername",action="store_true",help="If you have the same image filename in multiple folders, and need to import into the same project, this will prepend the folder name on each image name",default=False,guitype='boolbox',row=2, col=2, rowspan=1, colspan=1, mode="import[False]")
	parser.add_argument("--xraypixel",action="store_true",help="Filter X-ray pixels",default=False, guitype='boolbox', row=3, col=0, rowspan=1, colspan=1, mode='filter[True]')
	parser.add_argument("--ctfest",action="store_true",help="Estimate defocus from whole micrograph",default=False, guitype='boolbox', row=3, col=1, rowspan=1, colspan=1, mode='filter[True]')
	parser.add_argument("--astigmatism",action="store_true",help="Includes astigmatism in automatic fitting",default=False, guitype='boolbox', row=3, col=2, rowspan=1, colspan=1, mode='filter[False]')
	parser.add_argument("--moverawdata",action="store_true",help="Move raw data to directory ./raw_micrographs after filtration",default=False)
	parser.add_argument("--apix",type=float,help="Angstroms per pixel for all images",default=None, guitype='floatbox', row=5, col=0, rowspan=1, colspan=1, mode="filter['self.pm().getAPIX()']")
	parser.add_argument("--voltage",type=float,help="Microscope voltage in KV",default=None, guitype='floatbox', row=5, col=1, rowspan=1, colspan=1, mode="filter['self.pm().getVoltage()']")
	parser.add_argument("--cs",type=float,help="Microscope Cs (spherical aberation)",default=None, guitype='floatbox', row=6, col=0, rowspan=1, colspan=1, mode="filter['self.pm().getCS()']")
	parser.add_argument("--ac",type=float,help="Amplitude contrast (percentage, default=10)",default=10, guitype='floatbox', row=6, col=1, rowspan=1, colspan=1, mode="filter")
	parser.add_argument("--defocusmin",type=float,help="Minimum autofit defocus",default=0.6, guitype='floatbox', row=8, col=0, rowspan=1, colspan=1, mode="filter[0.6]")
	parser.add_argument("--defocusmax",type=float,help="Maximum autofit defocus",default=4, guitype='floatbox', row=8, col=1, rowspan=1, colspan=1, mode='filter[4.0]')
	parser.add_argument("--ppid", type=int, help="Set the PID of the parent process, used for cross platform PPID",default=-1)

	(options, args) = parser.parse_args()

	microdir = os.path.join(".","micrographs")
	if not os.access(microdir, os.R_OK):
		os.mkdir("micrographs")

	logid=E2init(sys.argv,options.ppid)

	# After filtration we move micrographs to a directory 'raw_micrographs', if desired
	if options.moverawdata:
		originalsdir = os.path.join(".","raw_micrographs")
		if not os.access(originalsdir, os.R_OK):
			os.mkdir("raw_micrographs")
			
	for i,arg in enumerate(args):
		base = base_name(arg,nodir=not options.usefoldername)
		output = os.path.join(os.path.join(".","micrographs"),base+".hdf")
		cmd = "e2proc2d.py %s %s --inplace"%(arg,output)

		if options.invert: cmd += " --mult=-1"
		if options.edgenorm: cmd += " --process=normalize.edgemean"
		if options.xraypixel: cmd += " --process=threshold.clampminmax.nsigma:nsigma=4"
		
		launch_childprocess(cmd)
		if options.moverawdata:
			os.rename(arg,os.path.join(originalsdir,os.path.basename(arg)))
			
		# We estimate the defocus and B-factor (no astigmatism) from the micrograph and store it in info and the header
		if options.ctfest :
			d=EMData(output,0)
			if d["nx"]<1200 or d["ny"]<1200 : 
				print "CTF estimation will only work with images at least 1200x1200 in size"
				sys.exit(1)
			import e2ctf
			
			ds=1.0/(options.apix*512)
			ffta=None
			nbx=0
			for x in range(100,d["nx"]-512,512):
				for y in range(100,d["ny"]-512,512):
					clip=d.get_clip(Region(x,y,512,512))
					clip.process_inplace("normalize.edgemean")
					fft=clip.do_fft()
					fft.ri2inten()
					if ffta==None: ffta=fft
					else: ffta+=fft
					nbx+=1

			ffta.mult(1.0/(nbx*512**2))
			ffta.process_inplace("math.sqrt")
			ffta["is_intensity"]=0				# These 2 steps are done so the 2-D display of the FFT looks better. Things would still work properly in 1-D without it

			fftbg=ffta.process("math.nonconvex")
			fft1d=ffta.calc_radial_dist(ffta.get_ysize()/2,0.0,1.0,1)	# note that this handles the ri2inten averages properly

			# Compute 1-D curve and background
			bg_1d=e2ctf.low_bg_curve(fft1d,ds)

			#initial fit, background adjustment, refine fit, final background adjustment
			ctf=e2ctf.ctf_fit(fft1d,bg_1d,bg_1d,ffta,fftbg,options.voltage,options.cs,options.ac,options.apix,1,dfhint=(options.defocusmin,options.defocusmax))
			bgAdj(ctf,fft1d)
			ctf=e2ctf.ctf_fit(fft1d,ctf.background,ctf.background,ffta,fftbg,options.voltage,options.cs,options.ac,options.apix,1,dfhint=(options.defocusmin,options.defocusmax))
			bgAdj(ctf,fft1d)
			
			if options.astigmatism : e2ctf.ctf_fit_stig(ffta,fftbg,ctf)
			
			#ctf.background=bg_1d
			#ctf.dsbg=ds
			db=js_open_dict(info_name(arg,nodir=not options.usefoldername))
			db["ctf_frame"]=[512,ctf,(256,256),set(),5,1]
			print info_name(arg,nodir=not options.usefoldername),ctf

		E2progress(logid,(float(i)/float(len(args))))

	E2end(logid)