def main(): usage = " " parser = EMArgumentParser(usage=usage, version=EMANVERSION) #parser.add_argument("--path", type=str,help="path", default="") parser.add_header(name="orblock1", help='', title="Click launch to evaluate subtomogram averages", row=1, col=0, rowspan=1, colspan=2) parser.add_argument( "--ppid", type=int, help="Set the PID of the parent process, used for cross platform PPID", default=-2) (options, args) = parser.parse_args() logid = E2init(sys.argv) app = EMApp() gui = SptEvalGUI(options) gui.show() gui.raise_() app.exec_() E2end(logid)
def main(): usage = "This is a GUI program that allows users inspect tomograms easily. Simply run without argument in a tomogram project directory." parser = EMArgumentParser(usage=usage, version=EMANVERSION) parser.add_argument("--ppid", type=int, help="", default=None) parser.add_header(name="orblock1", help='', title="Click launch to evaluate reconstructed tomograms", row=1, col=0, rowspan=1, colspan=2, mode="") (options, args) = parser.parse_args() logid = E2init(sys.argv) if not os.path.isdir("tomograms"): os.mkdir("tomograms") #print("No tomograms found. You must perform at least one reconstruction or manually populate the 'tomograms' directory with at least one reconstruction.") #sys.exit() app = EMApp() gui = TomoEvalGUI(options) gui.show() gui.raise_() app.exec_() E2end(logid)
def main(): global debug, logid progname = os.path.basename(sys.argv[0]) usage = """%prog [options] This program allows the user to play around with Fourier synthesis graphically """ parser = OptionParser(usage=usage, version=EMANVERSION) # parser.add_option("--gui",action="store_true",help="Start the GUI for interactive fitting",default=False) parser.add_option( "--verbose", "-v", dest="verbose", action="store", metavar="n", type="int", default=0, help= "verbose level [0-9], higher number means higher level of verboseness") (options, args) = parser.parse_args() app = EMApp() win = GUIFourierSynth(app) win.show() try: win.raise_() win.synthplot.raise_() except: pass app.exec_()
def main(): progname = os.path.basename(sys.argv[0]) usage = """prog [options] A simple CTF simulation program. """ parser = EMArgumentParser(usage=usage,version=EMANVERSION) parser.add_argument("--apix",type=float,help="Angstroms per pixel for all images",default=1.0, guitype='floatbox', row=4, col=0, rowspan=1, colspan=1, mode="autofit['self.pm().getAPIX()']") parser.add_argument("--voltage",type=float,help="Microscope voltage in KV",default=300.0, guitype='floatbox', row=4, col=1, rowspan=1, colspan=1, mode="autofit['self.pm().getVoltage()']") parser.add_argument("--cs",type=float,help="Microscope Cs (spherical aberation)",default=4.1, guitype='floatbox', row=5, col=0, rowspan=1, colspan=1, mode="autofit['self.pm().getCS()']") parser.add_argument("--ac",type=float,help="Amplitude contrast (percentage, default=10)",default=10, guitype='floatbox', row=5, col=1, rowspan=1, colspan=1, mode='autofit') parser.add_argument("--samples",type=int,help="Number of samples in the plotted curve",default=256) parser.add_argument("--apply",type=str,default=None,help="A 2-D image file which the CTF will be applied to in real-time") parser.add_argument("--verbose", "-v", dest="verbose", action="store", metavar="n", type=int, default=0, help="verbose level [0-9], higher number means higher level of verboseness") (options, args) = parser.parse_args() from eman2_gui.emapplication import EMApp app=EMApp() gui=GUIctfsim(app,options.apix,options.voltage,options.cs,options.ac,options.samples,options.apply) gui.show_guis() gui.raise_() app.exec_()
def main(): usage="[prog] <2D image file> " parser = EMArgumentParser(usage=usage,version=EMANVERSION) (options, args) = parser.parse_args() logid=E2init(sys.argv) filename=args[0] app = EMApp() img=EMData(filename) #print img[0]["mean"] w=EMBreakBrick(img,app) #w.set_data(img,filename) app.show_specific(w) app.exec_() E2end(logid)
def main(): usage = " " parser = EMArgumentParser(usage=usage, version=EMANVERSION) #parser.add_argument("--path", type=str,help="path", default="") (options, args) = parser.parse_args() logid = E2init(sys.argv) app = EMApp() gui = TomoEvalGUI(options) gui.show() gui.raise_() app.exec_() E2end(logid)
def display_validation_plots(path, radcut, planethres, plotdatalabels=False, color='#00ff00', plotzaxiscolor=False): from eman2_gui.emimage2d import EMImage2DWidget from eman2_gui.emapplication import EMApp r = [] theta = [] datap = [] zaxis = [] try: tpdb = js_open_dict("%s/perparticletilts.json" % path) tplist = tpdb["particletilt_list"] maxcolorval = max(tplist, key=lambda x: x[3])[3] for tp in tplist: if tp[3] > planethres: # if the out of plane threshold is too much continue if plotdatalabels: datap.append(tp[0]) r.append(tp[1]) theta.append(math.radians(tp[2])) # Color the Z axis out of planeness zaxis.append(computeRGBcolor(tp[3], 0, maxcolorval)) tpdb.close() except: print("Couldn't load tp from DB, not showing polar plot") data = None try: data = EMData("%s/contour.hdf" % path) except: print("Couldn't open contour plot") if not data and not (theta and r): return app = EMApp() if theta and r: plot = EMValidationPlot() plot.set_data((theta, r), 50, radcut, datap) # Color by Z axis if desired if plotzaxiscolor: plot.set_scattercolor([zaxis]) plot.set_datalabelscolor(color) plot.show() if data: image = EMImage2DWidget(data) image.show() app.exec_()
def main(): progname = os.path.basename(sys.argv[0]) usage = """e2simmxptclcmp.py [options] <simmx file> ... Plots the set of similarity quality values for a single particle from a set of simmx files. """ parser = EMArgumentParser(usage=usage, version=EMANVERSION) parser.add_argument("--ptcl", type=int, help="particle number", default=0) # parser.add_argument("--refine",type=str,default=None,help="Automatically get parameters for a refine directory") #parser.add_argument("--output",type=str,help="Output text file",default="zvssim.txt") #parser.add_argument("--refs",type=str,help="Reference images from the similarity matrix (projections)",default=None) #parser.add_argument("--inimgs",type=str,help="Input image file",default=None) #parser.add_argument("--outimgs",type=str,help="Output image file",default="imgs.hdf") #parser.add_argument("--filtimgs",type=str,help="A python expression using Z[n], Q[n] and N[n] for selecting specific particles to output. n is the 0 indexed number of the input file",default=None) #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() app = EMApp() from eman2_gui.emplot2d import EMPlot2DWidget plotw = EMPlot2DWidget(application=app) plts = [] for simmx in args: mx = EMData(simmx, 0) plts.append(mx.get_clip(Region(0, options.ptcl, mx["nx"], 1))) plts[-1].process_inplace("normalize") plotw.set_data(plts[-1], simmx) plotw.setWindowTitle("ptcl vs similarity") plotw.show() try: plotw.raise_() except: pass app.exec_()
def main(): progname = os.path.basename(sys.argv[0]) usage = """prog Refinement directory [options] Plot Euler angle distributions for refinement results. Poiont size is proportional to Euler bin count. >""" parser = EMArgumentParser(usage=usage, version=EMANVERSION) #parser.add_pos_argument(name="plot_files",help="List the directories to plot here.", default="", guitype='filebox', browser="EMBrowserWidget(withmodal=True,multiselect=True)", row=0, col=0,rowspan=1, colspan=2) parser.add_pos_argument( name="refinedir", help="The refinement directory to use for FSC plotting.", default="", guitype='dirbox', dirbasename='refine|TiltValidate', row=0, col=0, rowspan=1, colspan=2) parser.add_header( name="eulerheader", help='Options below this label are specific to e2plotEuler', title="### e2plotEuler options ###", row=1, col=0, rowspan=1, colspan=1) parser.add_argument("--iteration", type=int, help="Refinement iteration to plot", default=0, guitype='intbox', row=2, col=0, rowspan=1, colspan=1) parser.add_argument( "--pointwidth", type=float, help= "The relative scale of the points plotted. The absoule size is dpenedent on particle count", default=1.0, guitype='floatbox', row=2, col=1, rowspan=1, colspan=1) parser.add_argument( "--sym", dest="sym", default="c1", help= "Set the symmetry; if no value is given then the model is assumed to have no symmetry.\nChoices are: i, c, d, tet, icos, or oct.", guitype='symbox', row=3, col=0, rowspan=1, colspan=2) parser.add_argument("--norticklabels", action="store_true", help="Disable radius tick labels", guitype='boolbox', row=4, col=0, rowspan=1, colspan=1, default=False) parser.add_argument("--nothetaticklabels", action="store_true", help="Disable Theta tick labels", guitype='boolbox', row=4, col=1, rowspan=1, colspan=1, default=False) 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() # Grab the data iteration = 0 data = EMData.read_images("bdb:%s#classify_%02d" % (args[0], iteration)) projections = EMData.read_images("bdb:%s#projections_%02d" % (args[0], iteration)) # We use a hash data structure to count same Eulers(could also use an array an sort it) eulerhash = {} for i in range(data[0].get_ysize()): # Get Eulers projnum = int(data[0][i]) euler = projections[projnum].get_attr('xform.projection') #Loop over all syms for sym in Symmetries.get(options.sym).get_syms(): eulerangles = (sym * euler).get_rotation('eman') # Use has to count unique eulers hashkey = "%3.2f %3.2f" % (eulerangles['az'], eulerangles['alt']) if hashkey in eulerhash: eulerhash[hashkey] += 1 else: eulerhash[hashkey] = 1 # Now plot these eulers theta = [] r = [] size = [] for euler, count in list(eulerhash.items()): eulers = euler.split() theta.append(float(eulers[0])) r.append(float(eulers[1])) size.append(count * options.pointwidth) # Make the QT app and plot app = EMApp() plot = EMPolarPlot2DWidget() plot.set_yticklabels(not options.norticklabels) plot.set_xticklabels(not options.nothetaticklabels) plot.setAxisParms(False, False) plot.set_data((theta, r), linewidth=50, radcut=180) plot.setPointSizes(size) plot.show() app.exec_()
def main(): progname = os.path.basename(sys.argv[0]) usage = """prog Refinement directory [options] Plot FSC curvers produced by e2refine, eotest, etc. >""" parser = EMArgumentParser(usage=usage, version=EMANVERSION) #dirbasename='refine|frealign', #parser.add_pos_argument(name="plot_files",help="List the directories to plot here.", default="", guitype='filebox', browser="EMBrowserWidget(withmodal=True,multiselect=True)", row=0, col=0,rowspan=1, colspan=2) parser.add_header( name="filterheader", help='There is no help', title= "This program is currently not functional. The table below is still useful,\n but for actual plots, suggest using e2evalrefine.py for now.", row=0, col=0, rowspan=1, colspan=2) parser.add_pos_argument( name="fscdir", help="The refinement directory to use for FSC plotting.", default="", guitype='fsctable', row=1, col=0, rowspan=1, colspan=2) parser.add_header( name="filterheader", help='Options below this label are specific to e2plotFSC', title="### e2plotFSC options ###", row=2, col=0, rowspan=1, colspan=2) parser.add_argument("--plote2res", action="store_false", help="Plot curves from e2resoltion", default=True, guitype='boolbox', row=3, col=0, rowspan=1, colspan=1) parser.add_argument("--plote2eotest", action="store_false", help="Plot curves from e2eotest", default=True, guitype='boolbox', row=3, col=1, rowspan=1, colspan=1) parser.add_argument("--plotconvergence", action="store_false", help="Plot curves from refinement convergence", default=True, guitype='boolbox', row=4, col=0, rowspan=1, colspan=1) parser.add_argument("--ploteoconvergence", action="store_false", help="Plot curves from refine_even_odd convergence", default=True, guitype='boolbox', row=4, col=1, rowspan=1, colspan=1) 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() # Make the QT app app = EMApp() # display table if len(args) == 0: fsctable = PMFSCTableWidget("fsc", "", None, resize=True) fsctable.show() # or let user choose FSC plotting pars else: module = EMPlot2DWidget() # Get data from data base db_name = "bdb:" + args[0] + "#convergence.results" if not db_check_dict(db_name): print("Rubbish!!!, no FSC curves found!!!") return db = db_open_dict(db_name, ro=True) keys = db.keys() # Load desired FSC curves res = [] eo = [] conv = [] eoconv = [] # Method to the maddness, I use not here because I need to only plot when open is not presented AND I need to keep presentation on in the GUI if not options.plote2res: res = get_e2resolution_results_list(keys) if not options.plote2eotest: eo = get_e2eotest_results_list(keys) if not options.plotconvergence: conv = get_convergence_results_list(keys) if not options.ploteoconvergence: eoconv = get_e2refine_even_odd_results_list(keys) # Plot FSC curves i = 0 max = len(colortypes) for k in conv: module.set_data( db[k], k, color=(i % max), linewidth=1) # there are only a ceratin number of colors i += 1 # plot e2refine_even_odd curves for k in eoconv: module.set_data( db[k], k, color=(i % max), linewidth=2) # there are only a ceratin number of colors i += 1 #plot eo test and res for plot in [eo, res]: for k in plot: module.set_data( db[k], k, color=(i % max), linewidth=3) # there are only a ceratin number of colors i += 1 module.show() app.exec_()
def main(): global debug, logid progname = os.path.basename(sys.argv[0]) usage = """%prog [options] <input stack/image> ... Various CTF-related operations on images, including automatic fitting. Note that automatic fitting is limited to 5 microns underfocus at most. Input particles should be unmasked and unfiltered. A minimum of ~20% padding around the particles is required for background extraction, even if this brings the edge of another particle into the box in some cases. Particles should be reasonably well centered. Can also optionally phase flip and Wiener filter particles. Wiener filtration comes after phase-flipping, so if phase flipping is performed Wiener filtered particles will also be phase-flipped. Note that both operations are performed on oversampled images if specified (though final real-space images are clipped back to their original size. Increasing padding during the particle picking process will improve the accuracy of phase-flipping, particularly for images far from focus.""" parser = OptionParser(usage=usage, version=EMANVERSION) parser.add_option("--gui", action="store_true", help="Start the GUI for interactive fitting", default=False) parser.add_option("--auto_fit", action="store_true", help="Runs automated CTF fitting on the input images", default=False) parser.add_option( "--bgmask", type="int", help= "Compute the background power spectrum from the edge of the image, specify a mask radius in pixels which would largely mask out the particles. Default is boxsize/2.", default=0) parser.add_option("--apix", type="float", help="Angstroms per pixel for all images", default=0) parser.add_option("--voltage", type="float", help="Microscope voltage in KV", default=0) parser.add_option("--cs", type="float", help="Microscope Cs (spherical aberation)", default=0) parser.add_option("--ac", type="float", help="Amplitude contrast (percentage, default=10)", default=10) parser.add_option( "--autohp", action="store_true", help= "Automatic high pass filter of the SNR only to remove initial sharp peak, phase-flipped data is not directly affected (default false)", default=False) #parser.add_option("--invert",action="store_true",help="Invert the contrast of the particles in output files (default false)",default=False) parser.add_option("--nonorm", action="store_true", help="Suppress per image real-space normalization", default=False) parser.add_option( "--nosmooth", action="store_true", help= "Disable smoothing of the background (running-average of the log with adjustment at the zeroes of the CTF)", default=False) #parser.add_option("--phaseflip",action="store_true",help="Perform phase flipping after CTF determination and writes to specified file.",default=False) #parser.add_option("--wiener",action="store_true",help="Wiener filter (optionally phaseflipped) particles.",default=False) parser.add_option("--oversamp", type="int", help="Oversampling factor", default=1) parser.add_option( "--sf", type="string", help= "The name of a file containing a structure factor curve. Can improve B-factor determination.", default=None) parser.add_option("--debug", action="store_true", default=False) (options, args) = parser.parse_args() if len(args) < 1: parser.error("Input image required") if sp_global_def.CACHE_DISABLE: from sp_utilities import disable_bdb_cache disable_bdb_cache() if options.auto_fit: if options.voltage == 0: parser.error("Please specify voltage") if options.cs == 0: parser.error("Please specify Cs") if options.apix == 0: sxprint("Using A/pix from header") debug = options.debug global sfcurve if options.sf: sfcurve = XYData() sfcurve.read_file(options.sf) logid = E2init(sys.argv) # if options.oversamp>1 : options.apix/=float(options.oversamp) db_project = db_open_dict("bdb:project") db_parms = db_open_dict("bdb:e2ctf.parms") db_misc = db_open_dict("bdb:e2ctf.misc") options.filenames = args ### Power spectrum and CTF fitting if options.auto_fit: img_sets = pspec_and_ctf_fit( options, debug) # converted to a function so to work with the workflow ### This computes the intensity of the background subtracted power spectrum at each CTF maximum for all sets global envelopes # needs to be a global for the Simplex minimizer # envelopes is essentially a cache of information that could be useful at later stages of refinement # as according to Steven Ludtke for i in img_sets: envelopes.append(ctf_env_points(i[2], i[3], i[1])) # we use a simplex minimizer to try to rescale the individual sets to match as best they can scales = [1.0] * len(img_sets) if (len(img_sets) > 3): incr = [0.2] * len(img_sets) simp = Simplex(env_cmp, scales, incr) scales = simp.minimize(maxiters=1000)[0] # sxprint scales sxprint(" ") # apply the final rescaling envelope = [] for i in range(len(scales)): cur = envelopes[i] for j in range(len(cur)): envelope.append((cur[j][0], cur[j][1] * scales[i])) envelope.sort() envelope = [i for i in envelope if i[1] > 0] # filter out all negative peak values db_misc = db_open_dict("bdb:e2ctf.misc") db_misc["envelope"] = envelope #db_close_dict("bdb:e2ctf.misc") #out=file("envelope.txt","w") #for i in envelope: out.write("%f\t%f\n"%(i[0],i[1])) #out.close() ### GUI - user can update CTF parameters interactively if options.gui: img_sets = get_gui_arg_img_sets(options.filenames) if len(img_sets) == 0: E2end(logid) ERROR("img_sets == 0") return app = EMApp() gui = GUIctf(app, img_sets) gui.show_guis() app.exec_() sxprint("done execution") ### Process input files #if debug : print "Phase flipping / Wiener filtration" # write wiener filtered and/or phase flipped particle data to the local database #if options.phaseflip or options.wiener: # only put this if statement here to make the program flow obvious # write_e2ctf_output(options) # converted to a function so to work with the workflow E2end(logid)
def display_validation_plots(path, radcut, planethres, plotdatalabels=False, color='#00ff00', plotzaxiscolor=False): # In some cases it is impossible to import PyQT4, particularly on clusters try: from PyQt5 import QtCore, QtGui, QtWidgets, QtOpenGL # from eman2_gui.emshape import * from eman2_gui.valslider import ValSlider from eman2_gui.emplot2d import EMPolarPlot2DWidget except: class dummy(object): pass class QWidget(object): "A dummy class for use when Qt not installed" def __init__(self, parent): print("Qt4 has not been loaded") QtGui = dummy() QtWidgets.QWidget = QWidget from eman2_gui.emimage2d import EMImage2DWidget from eman2_gui.emapplication import EMApp r = [] theta = [] datap = [] zaxis = [] try: tpdb = js_open_dict("%s/perparticletilts.json" % path) tplist = tpdb["particletilt_list"] maxcolorval = max(tplist, key=lambda x: x[3])[3] for tp in tplist: if tp[3] > planethres: # if the out of plane threshold is too much continue if plotdatalabels: datap.append(tp[0]) r.append(tp[1]) theta.append(math.radians(tp[2])) # Color the Z axis out of planeness zaxis.append(computeRGBcolor(tp[3], 0, maxcolorval)) tpdb.close() except: print("Couldn't load tp from DB, not showing polar plot") data = None try: data = EMData("%s/contour.hdf" % path) except: print("Couldn't open contour plot") if not data and not (theta and r): return app = EMApp() if theta and r: plot = EMValidationPlot() plot.set_data((theta, r), 50, radcut, datap) # Color by Z axis if desired if plotzaxiscolor: plot.set_scattercolor([zaxis]) plot.set_datalabelscolor(color) plot.show() if data: image = EMImage2DWidget(data) image.show() app.exec_() # Compute a RGB value to represent a data range. Basically convert Hue to GSB with I=0.33 and S=1.0 def computeRGBcolor(value, minval, maxval): # Normalize from 0 to 1 normval = old_div((value - minval), (maxval - minval)) radval = normval * 2 * math.pi if radval < 2 * math.pi / 3: B = 0.0 R = 0.33 * (1 + old_div(math.cos(radval), math.cos(old_div(math.pi, 3) - radval))) G = 1.0 - R return "#%02x%02x%02x" % (255 * R, 255 * G, 255 * B) if radval > 2 * math.pi / 3 and radval < 4 * math.pi / 3: hue = radval - 2 * math.pi / 3 R = 0.0 G = 0.33 * (1 + old_div(math.cos(hue), math.cos(old_div(math.pi, 3) - hue))) B = 1.0 - G return "#%02x%02x%02x" % (255 * R, 255 * G, 255 * B) if radval > 4 * math.pi / 3: hue = radval - 4 * math.pi / 3 G = 0 B = 0.33 * (1 + old_div(math.cos(hue), math.cos(old_div(math.pi, 3) - hue))) R = 1.0 - B return "#%02x%02x%02x" % (255 * R, 255 * G, 255 * B) class EMValidationPlot(QtWidgets.QWidget): """Make a plot to display validation info""" def __init__(self): QtWidgets.QWidget.__init__(self) box = QtWidgets.QVBoxLayout() self.polarplot = EMPolarPlot2DWidget() self.polarplot.setMinimumHeight(50) self.polarplot.setMinimumWidth(50) self.resize(480, 580) meanAngLabel = QtWidgets.QLabel("Mean Tilt Angle") self.meanAngle = QtWidgets.QLineEdit("") meanAxisLabel = QtWidgets.QLabel("Mean Tilt Axis") self.meanAxis = QtWidgets.QLineEdit("") rmsdAngLabel = QtWidgets.QLabel("RMSD Tilt Angle") self.rmsdAngle = QtWidgets.QLineEdit("") rmsdAxisLabel = QtWidgets.QLabel("RMSD Tilt Axis") self.rmsdAxis = QtWidgets.QLineEdit("") pointsLabel = QtWidgets.QLabel("Num points") self.points = QtWidgets.QLineEdit("") self.pointlabel = QtWidgets.QLabel( "Right click to pick the nearest point") frame = QtWidgets.QFrame() frame.setFrameShape(QtWidgets.QFrame.StyledPanel) frame.setMaximumHeight(100) grid = QtWidgets.QGridLayout() grid.addWidget(meanAngLabel, 0, 0) grid.addWidget(self.meanAngle, 0, 1) grid.addWidget(meanAxisLabel, 0, 2) grid.addWidget(self.meanAxis, 0, 3) grid.addWidget(rmsdAngLabel, 1, 0) grid.addWidget(self.rmsdAngle, 1, 1) grid.addWidget(rmsdAxisLabel, 1, 2) grid.addWidget(self.rmsdAxis, 1, 3) grid.addWidget(self.pointlabel, 2, 0, 1, 2) grid.addWidget(pointsLabel, 2, 2) grid.addWidget(self.points, 2, 3) frame.setLayout(grid) box.addWidget(self.polarplot) box.addWidget(frame) self.setLayout(box) self.polarplot.clusterStats.connect(self._on_stats) def _on_stats(self, stats): """ Set the selected stats """ self.meanAngle.setText(str(round(stats[1], 2))) self.meanAxis.setText(str(round(stats[0], 2))) self.rmsdAngle.setText(str(round(stats[3], 2))) self.rmsdAxis.setText(str(round(stats[2], 2))) self.points.setText(str(stats[4])) def _on_point(self, point): """ Set the selected point""" self.pointlabel.setText("You selected the point: %s" % str(point)) def set_data(self, data, linewidth, radcut, datapoints): self.polarplot.set_data(data, linewidth=linewidth, radcut=radcut, datapoints=datapoints) def set_datalabelscolor(self, color): self.polarplot.setDataLabelsColor(color) def set_scattercolor(self, color): self.polarplot.setScatterColor(color)
def main(): progname = os.path.basename(sys.argv[0]) usage = """prog 3Dstack [options] Visulaizse and compute the mean amplitude and sigma in the missing wedge region. After you are sasified that the missing wedge looks sane, compute missing wedge stats on all volumes. These stats are used by the aligner tomo.fsc, for subtomogram alignment and averaging. """ parser = EMArgumentParser(usage=usage, version=EMANVERSION) parser.add_pos_argument(name="tdstack", help="The 3D stack to examine.", default="", guitype='filebox', row=0, col=0, rowspan=1, colspan=2) parser.add_header(name="wedgeheader", help='Options below this label are specific to e2wedge', title="### e2wedge options ###", row=1, col=0, rowspan=1, colspan=2) parser.add_argument("--wedgeangle", type=float, help="Missing wedge angle", default=60.0, guitype='floatbox', row=2, col=0, rowspan=1, colspan=1) parser.add_argument("--wedgei", type=float, help="Missingwedge begining", default=0.05) parser.add_argument("--wedgef", type=float, help="Missingwedge ending", default=0.5) parser.add_argument( "--ppid", type=int, help="Set the PID of the parent process, used for cross platform PPID", default=-1) parser.add_argument( "--nogui", action="store_true", default=False, help= "Do not launch the GUI and set the average of the missing wedge statistics on all the volumes." ) parser.add_argument( "--averagestats", action="store_true", default=False, help= "Do not launch the GUI and set the average of the missing wedge statistics on all the volumes." ) (options, args) = parser.parse_args() logger = E2init(sys.argv, options.ppid) stack = args[0] if not options.nogui: em_app = EMApp() wedgeviewer = MissingWedgeViewer(stack, options.wedgeangle, wedgei=options.wedgei, wedgef=options.wedgef) wedgeviewer.show() ret = em_app.exec_() sys.exit(ret) else: means = [] sigmas = [] n = EMUtil.get_image_count(stack) for i in range(n): a = EMData(stack, i) retr = wedgestats(a, options.wedgeangle, options.wedgei, options.wedgef) mean = retr[0] sigma = retr[1] if options.averagestats: means.append(mean) sigmas.append(sigma) else: a['spt_wedge_mean'] = mean a['spt_wedge_sigma'] = sigma print( "The mean and sigma for subvolume %d are: mean=%f, sigma=%f" % (i, mean, sigma)) a.write_image(stack, i) if options.averagestats: meanavg = old_div(sum(means), len(means)) sigmaavg = old_div(sum(sigmas), len(sigmas)) print("The average mean and sigma for the wedges in the stack are", meanavg, sigmaavg) for i in range(n): a = EMData(stack, i) a['spt_wedge_mean'] = meanavg a['spt_wedge_sigma'] = sigmaavg a.write_image(stack, i) E2end(logger) return
def main(): progname = os.path.basename(sys.argv[0]) usage = """prog [options] This is a program to compute the resolution of a n averaged subtomogram. Right now it is very simple simple divide the aligned subtomos into even/odd classes, average and then compute the FSC. In the future this program will be extended to compute resolution of an averged subtomo vs a reference and hopefuly of a single sub/tomogram. """ parser = EMArgumentParser(usage=usage, version=EMANVERSION) parser.add_pos_argument( name="tomodir", help="The refinement directory to use for tomoresolution.", default="", guitype='dirbox', dirbasename='spt_', row=0, col=0, rowspan=1, colspan=2) parser.add_header( name="tomoresoheader", help='Options below this label are specific to e2tomoresolution', title="### e2tomoresolution options ###", row=1, col=0, rowspan=1, colspan=2) parser.add_argument( "--averager", type=str, help="The averager used to generate the averages. Default is \'mean\'.", default="mean", guitype='combobox', choicelist='dump_averagers_list()', row=2, col=0, rowspan=1, colspan=2) parser.add_argument("--sym", type=str, help="The recon symmetry", default="c1", guitype='symbox', row=3, col=0, rowspan=1, colspan=2) parser.add_argument( "--mask", type=str, help="The mask to apply before FSC calculation", default=None, guitype='comboparambox', choicelist='re_filter_list(dump_processors_list(),\'mask\')', row=4, col=0, rowspan=1, colspan=2) 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() if options.mask: options.mask = parsemodopt(options.mask) logid = E2init(sys.argv, options.ppid) fscstrategy = EvenOddReso(args[0], options) fscstrategy.execute() results_db = db_open_dict("bdb:%s#convergence.results" % args[0]) results_db["tomo_fsc"] = [ fscstrategy.getFreq(), fscstrategy.getFSC(), fscstrategy.getError() ] results_db.close() E2end(logid) # Plot FSC app = EMApp() plot = EMPlot2DWidget() plot.set_data((fscstrategy.getFreq(), fscstrategy.getFSC())) plot.show() app.exec_()
def main(): progname = os.path.basename(sys.argv[0]) helpstring = """Help is available on the following topics: boxsizes, processors, cmps, aligners, averagers, projectors, reconstructors, analyzers, symmetries, orientgens, rotationtypes, imagetypes""" usage = """prog <topic> [contains] Interactive help on a variety of the eman2 library's modular functions. The optional 'contains' argument will act as a filter on the names of the algorithms.""" usage += " " + helpstring parser = EMArgumentParser(usage=usage, version=EMANVERSION) #parser.add_argument("--res", "-R", type=float, help="Resolution in A, equivalent to Gaussian lowpass with 1/e width at 1/res",default=2.8) #parser.add_argument("--box", "-B", type=str, help="Box size in pixels, <xyz> or <x>,<y>,<z>") parser.add_argument("--gui", action="store_true", help="Use the GUI for display help", default=False) parser.add_argument( "--ppid", type=int, help="Set the PID of the parent process, used for cross platform PPID", default=-2) parser.add_argument( "--verbose", "-v", dest="verbose", action="store", metavar="n", type=int, default=0, help= "verbose level [0-9], higher number means higher level of verboseness") (options, args) = parser.parse_args() if options.gui: from e2projectmanager import TheHelp from eman2_gui.emapplication import EMApp app = EMApp() thehelp = TheHelp() thehelp.show() if args: print(args[0]) if args[0] in ("aligner", "aligners"): thehelp._helpchange(0) elif args[0] in ("analyzer", "analyzers"): thehelp._helpchange(1) elif args[0] in ("averager", "averagers"): thehelp._helpchange(2) elif args[0] in ("cmp", "cmps"): thehelp._helpchange(3) elif args[0] in ("orientgen", "orientationgen", "orientgens", "orientationgens", "orientationgenerators"): thehelp._helpchange(4) elif args[0] in ("processor", "processors"): thehelp._helpchange(5) elif args[0] in ("projector", "projectors"): thehelp._helpchange(6) elif args[0] in ("reconstructor", "reconstructors"): thehelp._helpchange(7) elif args[0] in ("sym", "symmetry", "symmetries"): thehelp._helpchange(8) app.exec_() exit(0) if len(args) < 1: print(helpstring) exit(0) l = None if args[0] in ("cmp", "cmps"): print("Available comparators:") l = dump_cmps_list() elif args[0] in ("analyzer", "analyzers"): print("Available analysers:") l = dump_analyzers_list() elif args[0] in ("averager", "averagers"): print("Available averagers:") l = dump_averagers_list() elif args[0] in ("processor", "processors"): print("Available processors:") l = dump_processors_list() elif args[0] in ("projector", "projectors"): print("Available projectors:") l = dump_projectors_list() elif args[0] in ("reconstructor", "reconstructors"): print("Available reconstructors:") l = dump_reconstructors_list() elif args[0] in ("aligner", "aligners"): print("Available aligners:") l = dump_aligners_list() elif args[0] in ("sym", "symmetry", "symmetries"): print("Available symmetries:") l = dump_symmetries_list() elif args[0] in ("orientgen", "orientationgen", "orientgens", "orientationgens", "orientationgenerators"): print("Available orientation generators:") l = dump_orientgens_list() elif args[0][:3] == "box": if len(args) > 1: print(good_size(int(args[1]))) else: print(good_box_sizes) exit(0) elif args[0][:8] == "rotation": print("Available rotation conventions:") l = { "eman": [ "EMAN convention, az(Z),alt(X),phi(Z') Eulers", "alt", "FLOAT", "Altitude, X-axis", "az", "FLOAT", "Azimuth, Z-axis", "phi", "FLOAT", "Z' Axis. in-plane rotation in 2-D" ], "imagic": [ "IMAGIC convention", "alpha", "FLOAT", "alpha", "beta", "FLOAT", "beta", "gamma", "FLOAT", "gamma" ], "spider": [ "SPIDER convention", "phi", "FLOAT", "phi", "theta", "FLOAT", "theta", "psi", "FLOAT", "psi" ], "mrc": [ "MRC/CCP4 convention", "omega", "FLOAT", "omega", "theta", "FLOAT", "theta", "psi", "FLOAT", "psi" ], "xyz": [ "XYZ convention (Chimera)", "x", "FLOAT", "X-axis", "y", "FLOAT", "Y-axis", "z", "FLOAT", "Z-axis" ], "spin": [ "Spin-Axis (n1,n2,n3) vector with angle omega", "n1", "FLOAT", "X vector component", "n2", "FLOAT", "Y vector component", "n3", "FLOAT", "Z vector component", "omega", "FLOAT", "Angle of rotation in degrees" ], "sgirot": [ "SGI Spin-Axis (n1,n2,n3) vector with angle q", "n1", "FLOAT", "X vector component", "n2", "FLOAT", "Y vector component", "n3", "FLOAT", "Z vector component", "q", "FLOAT", "Angle of rotation in degrees" ], "quaternion": [ "Standard 4 component quaternion (e0,e1,e2,e3)", "e0", "FLOAT", "e0", "e1", "FLOAT", "e1", "e2", "FLOAT", "e2", "e3", "FLOAT", "e3" ] } elif args[0] in ("imagetypes", "imagetype", "image", "images", "imageformats", "imageformat"): print("Available image types:") header_line = [ "Type", "Extension", "Read", "Write", "3D", "ImgStack", "VolStack", "RgnI/O" ] img_types = [["HDF5", "hdf", "Y", "Y", "Y", "Y", "Y", "Y"], ["DM2 (Gatan)", "dm2", "Y", "N", "N", "N", "N", "N"], ["DM3 (Gatan)", "dm3", "Y", "N", "N", "N", "", "N"], ["DM4 (Gatan)", "dm4", "Y", "N", "Y", "Y", "", "N"], ["SER (FEI)", "ser", "Y", "N", "N", "Y", "", "N"], ["EER (TF)", "eer", "Y", "N", "N", "Y", "N", "N "], ["EM", "em", "Y", "Y", "Y", "N", "", "Y"], ["ICOS", "icos", "Y", "Y", "Y", "N", "", "Y"], ["Imagic", "img/hed", "Y", "Y", "Y", "Y", "Y", "Y"], ["MRC", "mrc", "Y", "Y", "N", "Y", "", "Y"], ["MRCS", "mrcs", "Y", "Y", "N", "Y", "soon?", "Y"], ["Spider Stack", "spi", "Y", "Y", "Y", "Y", "", "Y"], ["Spider Single", "spi", "Y", "Y", "Y", "N", "", "Y"], ["SER", "ser", "Y", "N", "N", "Y", "", "N"], ["BDB", "N/A", "Y", "Y", "Y", "Y", "", "Y"], ["Amira", "am", "Y", "Y", "Y", "N", "", "N"], ["DF3", "df3", "Y", "Y", "Y", "N", "", "N"], ["FITS", "fts", "Y", "N", "Y", "N", "", "N"], ["JPEG", "jpg/jpeg", "N", "Y", "N", "N", "", "N"], ["LST", "lst", "Y", "Y", "Y", "Y", "", "N"], ["LSTFAST", "lsx/lst", "Y", "Y", "Y", "Y", "", "N"], ["OMAP", "omap", "Y", "N", "Y", "N", "", "N"], ["PGM", "pgm", "Y", "Y", "N", "N", "", "N"], ["PIF", "pif", "Y", "Y", "Y", "Y", "", "N"], ["PNG", "png", "Y", "Y", "N", "N", "", "N"], ["SAL", "hdr/img", "Y", "N", "N", "N", "", "N"], ["SITUS", "situs", "Y", "Y", "Y", "N", "", "N"], ["TIFF", "tiff/tif", "Y", "Y", "N", "N", "", "N"], ["V4L", "v4l", "Y", "N", "N", "N", "", "N"], ["VTK", "vtk", "Y", "Y", "Y", "N", "", "N"], ["XPLOR", "xplor", "Y", "Y", "Y", "N", "", "N"]] type_len_max = max([len(img[0]) for img in img_types]) print(f"{header_line[0]:>{type_len_max}}: " + " ".join(header_line[1:])) for img in img_types: print(f"{img[0]:<{type_len_max}}: " + f"{img[1]:{len(header_line[1])}}" + f" {img[2]:^{len(header_line[2])}}" + f" {img[3]:^{len(header_line[3])}}" + f" {img[4]:^{len(header_line[4])}}" + f" {img[5]:^{len(header_line[5])}}" + f" {img[6]:^{len(header_line[6])}}" + f" {img[7]:^{len(header_line[7])}}") elif args[0] in ("version"): print(FULLVERSIONSTRING) elif args[0] in ("tophat"): print( "There are multiple ways to filter the 3D maps in SPA or SPT refinements:" ) print( " wiener: wiener filter based on FSC curve. default mode in most programs." ) print( " global: tophat filter across the map at the resolution cutoff 0.143 from fsc_masked_xx.txt." ) print( " localwiener: wiener filter based on the fsc curve of local regions from the even/odd maps. see e2fsc_real_local.py" ) print( " local: tophat filter based on local resolution calculated from the even/odd maps at 0.143 cutoff. see e2fsc_real_local.py" ) print( " localold: an old version of local resolution based filter. see e2fsc_local.py" ) else: print(helpstring) print("unknown option:", args[0]) if l: if options.verbose > 0: if len(args) > 1: k = [i for i in list(l.keys()) if args[1] in i] else: k = list(l.keys()) k.sort() for i in k: print("%s : %s" % (i, l[i][0])) for j in range(1, len(l[i]), 3): print("\t%s(%s) - %s" % (l[i][j], l[i][j + 1], l[i][j + 2])) else: if len(args) > 1: k = [i for i in list(l.keys()) if args[1] in i] else: k = list(l.keys()) if len(k) == 0: print("Empty list - no items met search criteria") sys.exit(0) maxk = max([len(ii) for ii in k]) fmt = "%%-%0ds : " % maxk k.sort() for i in k: print(fmt % i, end=' ') for j in range(1, len(l[i]), 3): print("%s(%s) " % (l[i][j], l[i][j + 1]), end=' ') if len(k) > 1: print("")
def main(): usage = "Generate training set for tomogram segmentation. Please run this program from the GUI in e2projectmanager.py." #print usage parser = EMArgumentParser(usage=usage, version=EMANVERSION) #parser.add_header(name="tmpheader", help='temp label', title="### This program is NOT avaliable yet... ###", row=0, col=0, rowspan=1, colspan=2, mode="box,seg,set") #### boxing #### parser.add_argument("--boxing", action="store_true", help="Boxing particles.", default=False, guitype='boolbox', row=4, col=0, rowspan=1, colspan=1, mode='box[True]') parser.add_pos_argument( name="micrographs", help="List the file to process with e2boxer here.", default="", guitype='filebox', browser="EMRawDataTable(withmodal=True,startpath=\"rawtomograms\")", row=1, col=0, rowspan=1, colspan=3, mode="box") parser.add_argument("--boxsize", "-B", type=int, help="Box size in pixels", default=-1, guitype='intbox', row=3, col=0, rowspan=1, colspan=3, mode="box") #### segment #### #parser.add_header(name="instruction", help='instruction', title="### Mark the target features white ###", row=0, col=0, rowspan=1, colspan=2, mode="seg") parser.add_argument("--segment", action="store_true", help="Segment particles.", default=False, guitype='boolbox', row=4, col=0, rowspan=1, colspan=1, mode='seg[True]') parser.add_pos_argument(name="particles", help="Particle file.", default="", guitype='filebox', browser="EMParticlesTable(withmodal=True)", row=1, col=0, rowspan=1, colspan=3, mode="seg") parser.add_argument( "--output", type=str, help= "output file name. Default is the input particle file name plus _seg.hdf", default=None, guitype='strbox', row=3, col=0, rowspan=1, colspan=3, mode="seg") #### build set #### parser.add_argument("--buildset", action="store_true", help="Segment particles.", default=False, guitype='boolbox', row=7, col=0, rowspan=1, colspan=1, mode='set[True]') parser.add_argument("--particles_raw", type=str, help="Input raw particle file", default=None, guitype='filebox', browser="EMParticlesTable(withmodal=True)", row=1, col=0, rowspan=1, colspan=3, mode="set") parser.add_argument("--particles_label", type=str, help="Input labels for particle file", default=None, guitype='filebox', browser="EMParticlesTable(withmodal=True)", row=2, col=0, rowspan=1, colspan=3, mode="set") parser.add_argument("--boxes_negative", type=str, help="Input boxes of negative samples", default=None, guitype='filebox', browser="EMParticlesTable(withmodal=True)", row=3, col=0, rowspan=1, colspan=3, mode="set") parser.add_argument( "--ncopy", type=int, help= "Number of copies for NEGATIVE samples. (number of copies of particles is calculated accordingly) ", default=10, guitype='intbox', row=5, col=0, rowspan=1, colspan=1, mode="set") parser.add_argument( "--trainset_output", type=str, help= "output file name of the training set.Default is the input particle file name plus _trainset.hdf", default=None, guitype='strbox', row=4, col=0, rowspan=1, colspan=3, mode="set") parser.add_argument("--zthick", type=int, help="Thickness in z ", default=0, guitype='intbox', row=5, col=1, rowspan=1, colspan=1, mode="set") parser.add_argument( "--validset", type=float, help="Propotion of particles in validation set. Default is 0.2 ", default=0.0, guitype='floatbox', row=7, col=1, rowspan=1, colspan=1, mode="set") ################## 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() logid = E2init(sys.argv) #### boxing ### if options.boxing: db = js_open_dict(EMBOXERBASE_DB) cache_box_size = True if options.boxsize == -1: cache_box_size = False options.boxsize = db.setdefault("box_size", 64) application = EMApp() module = EMBoxerModule(args, options.boxsize) module.show_interfaces() application.execute(logid) #### segment ### if options.segment: filename = args[0] if options.output == None: options.output = filename[:-4] + "_seg.hdf" app = EMApp() img = EMData.read_images(filename) #print img[0]["mean"] w = EMImageWidget(data=img, old=None, app=app, force_2d=True) #w = EMWidgetFromFile(filename,application=app,force_2d=True) w.setWindowTitle(base_name(filename)) w.show_inspector(1) ins = w.get_inspector() ins.mmtab.setCurrentIndex(5) ins.dtpenv.setText('100') w.set_mouse_mode(5) app.show_specific(w) app.exec_() try: os.remove(options.output) except: pass for e in img: e.process_inplace("threshold.belowtozero", {"minval": 99}) e.process_inplace("threshold.binary", {"value": 1}) e.write_image(options.output, -1) #### build set ### if options.buildset: tomo_in = options.particles_raw seg_in = options.particles_label neg_in = options.boxes_negative if tomo_in and neg_in and seg_in: n_ptcl = EMUtil.get_image_count(tomo_in) n_neg = EMUtil.get_image_count(neg_in) if options.trainset_output == None: options.trainset_output = tomo_in[:-4] + "_trainset.hdf" p_copy = options.ncopy * n_neg / n_ptcl else: p_copy = options.ncopy try: os.remove(options.trainset_output) except: pass print( "making {} copies for particles, and {} copies for negative samples" .format(p_copy, options.ncopy)) imgs = [] if tomo_in and seg_in: n_ptcl = EMUtil.get_image_count(tomo_in) for i in range(n_ptcl): #t=EMData(tomo_in,i) t = get_box(tomo_in, i, options.zthick) if t == None: continue s = EMData(seg_in, i) for c in range(p_copy): tr = Transform() rd = random.random() * 360 tr.set_rotation({"type": "2d", "alpha": rd}) e = t.process("xform", {"transform": tr}) #e.process_inplace("normalize") imgs.append(e) #e.write_image(options.trainset_output,-1) e = s.process("xform", {"transform": tr}) #e.write_image(options.trainset_output,-1) imgs.append(e) ngood = len(imgs) if neg_in: s = EMData(neg_in, 0) s.to_zero() n_neg = EMUtil.get_image_count(neg_in) for i in range(n_neg): t = get_box(neg_in, i, options.zthick) if t == None: continue for c in range(options.ncopy): tr = Transform() rd = random.random() * 360 tr.set_rotation({"type": "2d", "alpha": rd}) e = t.process("xform", {"transform": tr}) #e.process_inplace("normalize") #e.write_image(options.trainset_output,-1) imgs.append(e) e = s.process("xform", {"transform": tr}) #e.write_image(options.trainset_output,-1) imgs.append(e) print("Shuffling particles...") ### randomize n = len(imgs) #n=EMUtil.get_image_count(options.trainset_output) idx = range(int((ngood / 2) * (1 - options.validset))) + range( (ngood / 2), int(n / 2 * (1 - options.validset))) random.shuffle(idx) for i in idx: imgs[i * 2]["valid_set"] = 0 imgs[i * 2].write_image(options.trainset_output, -1) imgs[i * 2 + 1]["valid_set"] = 0 imgs[i * 2 + 1].write_image(options.trainset_output, -1) idx = range(int( (ngood / 2) * (1 - options.validset)), ngood / 2) + range( int(n / 2 * (1 - options.validset)), n / 2) random.shuffle(idx) for i in idx: imgs[i * 2]["valid_set"] = 1 imgs[i * 2].write_image(options.trainset_output, -1) imgs[i * 2 + 1]["valid_set"] = 1 imgs[i * 2 + 1].write_image(options.trainset_output, -1) #e=EMData(options.trainset_output,i*2) #e.process_inplace("normalize") #e.write_image(tmpfile,-1) #e=EMData(options.trainset_output,i*2+1) #e.write_image(tmpfile,-1) #shutil.move(tmpfile,options.trainset_output) print("Generate a training set of {:d} samples.".format(n / 2)) print("Done") E2end(logid)
def main(): progname = os.path.basename(sys.argv[0]) usage = """prog [options] <image file> ... This program can be used to visualize most files used in EMAN2. Running it without arguments will open a browser window with more flexible functionality than the command-line. """ global app, win, options parser = EMArgumentParser(usage=usage, version=EMANVERSION) parser.add_argument( "--classmx", type=str, help= "<classmx>,<#> Show particles in one class from a classification matrix. Pass raw particle file as first argument to command." ) parser.add_argument( "--classes", type=str, help="<rawptcl>,<classmx> Show particles associated class-averages") parser.add_argument("--pdb", type=str, help="<pdb file> Show PDB structure.") parser.add_argument("--singleimage", action="store_true", default=False, help="Display a stack in a single image view") parser.add_argument( "--plot", action="store_true", default=False, help="Data file(s) should be plotted rather than displayed in 2-D") parser.add_argument( "--hist", action="store_true", default=False, help= "Data file(s) should be plotted as a histogram rather than displayed in 2-D." ) parser.add_argument( "--plot3d", action="store_true", default=False, help="Data file(s) should be plotted rather than displayed in 3-D") parser.add_argument( "--fullrange", action="store_true", default=False, help= "A specialized flag that disables auto contrast for the display of particles stacks and 2D images only." ) parser.add_argument("--newwidget", action="store_true", default=False, help="Use the new 3D widgetD. Highly recommended!!!!") parser.add_argument( "--ppid", type=int, help="Set the PID of the parent process, used for cross platform PPID", default=-2) parser.add_argument( "--verbose", "-v", dest="verbose", action="store", metavar="n", type=int, default=0, help= "verbose level [0-9], higher number means higher level of verboseness") (options, args) = parser.parse_args() # logid=E2init(sys.argv) app = EMApp() #gapp = app #QtWidgets.QApplication(sys.argv) win = [] if options.fullrange: print( """The --fullrange option has been removed, and replaced with an option in user preferences. To set your preferences for full-range 2-D display, please run: e2procjson.py --setoption display2d.autocontrast:true """) sys.exit(0) if len(args) < 1: global dialog file_list = [] dialog = embrowser.EMBrowserWidget(withmodal=False, multiselect=False) dialog.show() try: dialog.raise_() # QtCore.QObject.connect(dialog,QtCore.SIGNAL("ok"),on_browser_done) # QtCore.QObject.connect(dialog,QtCore.SIGNAL("cancel"),on_browser_cancel) except: pass elif options.pdb: load_pdb(args, app) elif options.plot: plot(args, app) elif options.hist: hist(args, app) elif options.plot3d: plot_3d(args, app) elif options.classes: options.classes = options.classes.split(",") imgs = EMData.read_images(args[0]) display(imgs, app, args[0]) win[0].child.mousedown.connect(lambda a, b: selectclass( options.classes[0], options.classes[1], a, b)) try: out = open("selected.lst", "w") out.write("#LST\n") out.close() except: pass elif options.classmx: options.classmx = options.classmx.split(",") clsnum = int(options.classmx[1]) imgs = getmxim(args[0], options.classmx[0], clsnum) display(imgs, app, args[0]) else: for i in args: if not file_exists(i): print("%s doesn't exist" % i) sys.exit(1) display_file(i, app, options.singleimage, usescenegraph=options.newwidget) app.exec_()
def main(): progname = os.path.basename(sys.argv[0]) usage = """e2findlines sets/img.lst ** EXPERIMENTAL ** this program looks for ~ straight line segments in images, such as wrinkles in graphene oxide films or possible C-film edges """ parser = EMArgumentParser(usage=usage, version=EMANVERSION) parser.add_argument("--threshold", type=float, help="Threshold for separating particles, default=3", default=3.0) parser.add_argument("--newsets", default=False, action="store_true", help="Split lines/nolines into 2 new sets") #parser.add_argument("--output",type=str,help="Output filename (text file)", default="ptclplot.txt") parser.add_argument("--gui", default=False, action="store_true", help="show histogram of values") parser.add_argument( "--threads", default=4, type=int, help="Number of threads to run in parallel on the local computer") parser.add_argument( "--verbose", "-v", dest="verbose", action="store", metavar="n", type=int, default=0, help= "verbose level [0-9], higher number means higher level of verboseness") parser.add_argument( "--ppid", type=int, help="Set the PID of the parent process, used for cross platform PPID", default=-1) parser.add_argument( "--invar", default=False, action="store_true", help= "create the invar file for the newsets. The newsets option must be used." ) parser.add_argument("--zscore", default=True, action="store_true", help="run Z-score-based line finding.") parser.add_argument("--rdnxform", default=False, action="store_true", help="detect lines via radon transform") parser.add_argument( "--rthreshold", default=25, help="see scikit-image.transform.radon() parameter documentation.") parser.add_argument( "--rsigma", default=3, help="see scikit-image.transform.radon() parameter documentation.") (options, args) = parser.parse_args() if (len(args) < 1): parser.error("Please specify an input stack/set to operate on") E2n = E2init(sys.argv, options.ppid) options.threads += 1 # one extra thread for storing results if options.rdnxform: options.zscore = False print("running e2findlines.py with Radon transform method.") n = EMUtil.get_image_count(args[0]) lines = [] if options.threads - 1 == 0: t1 = time.time() for i in range(n): im = EMData(args[0], i) radon_im = radon(im.numpy(), preserve_range=True) laplacian = blob_log(radon_im, threshold=options.rthreshold, min_sigma=options.rsigma) if len(laplacian) == 0: lines.append(0) else: lines.append(1) print(f"{i} out of {n} images analyzed" + ' ' * 20, end='\b' * (len(str(f"{i} out of {n} images analyzed")) + 20), flush=True) t2 = time.time() print(f"Total time for rdnxform (nonthreaded): {t2-t1}s") if options.threads - 1 > 0 and options.threads <= n: t1 = time.time() print("running threaded rdnxform") threaded_indices = [[] for x in range(options.threads - 1)] for i in range(n): threaded_indices[i % (options.threads - 1)].append(i) #completed = 0 class ImageBatch(threading.Thread): def __init__(self, threadId, name, data_indices): threading.Thread.__init__(self) self.threadId = threadId self.name = name self.data_indices = data_indices def run(self): for i in self.data_indices: im = EMData(args[0], i) radon_im = radon(im.numpy(), preserve_range=True) laplacian = blob_log(radon_im, threshold=options.rthreshold, min_sigma=options.rsigma) if len(laplacian) == 0: lines.append(0) else: lines.append(1) print( f"{i} out of {n} images analyzed" + ' ' * 20, end='\b' * (len(str(f"{i} out of {n} images analyzed")) + 20), flush=True) threads = [ ImageBatch(x, "thread_%s" % x, threaded_indices[x]) for x in range(options.threads - 1) ] for thread in threads: thread.start() for thread in threads: thread.join() t2 = time.time() print(f"Total time rdnxform (threaded): {t2-t1}s") """for i in range(n): im=EMData(args[0],i) radon_im=radon(im.numpy(), preserve_range=True) laplacian=blob_log(radon_im, threshold=options.rthreshold, min_sigma=options.rsigma) if len(laplacian)==0: lines.append(0) else: lines.append(1) print(f"{i} out of {n} images analyzed"+' '*20, end ='\b'*(len(str(f"{i} out of {n} images analyzed"))+20), flush=True)""" if options.zscore: print("running e2findlines.py with Z-score method.") im0 = EMData(args[0], 0) # first image r2 = im0["ny"] / 4 # outer radius # we build up a list of 'Z scores' which should be larger for images containing one or more parallel lines. # if 2 lines aren't parallel the number may be lower, even if the lines are strong, but should still be higher # than images without lines in most cases n = EMUtil.get_image_count(args[0]) step = max(n // 500, 1) Z = [] im2d = [] for i in range(n): im = EMData(args[0], i) a = im.do_fft().calc_az_dist(60, -88.5, 3, 4, r2) d = np.array(a) Z.append((d.max() - d.mean()) / d.std()) if i % step == 0: im["zscore"] = (d.max() - d.mean()) / d.std() im2d.append(im) if options.gui: # GUI display of a histogram of the Z scores from eman2_gui.emhist import EMHistogramWidget from eman2_gui.emimagemx import EMImageMXWidget from eman2_gui.emapplication import EMApp app = EMApp() histw = EMHistogramWidget(application=app) histw.set_data(Z) app.show_specific(histw) imd = EMImageMXWidget(application=app) im2d.sort(key=lambda x: x["zscore"]) imd.set_data(im2d) app.show_specific(imd) app.exec_() """ if options.newsets: lstin=LSXFile(args[0]) # output containing images with lines linesfsp=args[0].rsplit(".",1)[0]+"_lines.lst" try: os.unlink(linesfsp) except: pass lstlines=LSXFile(linesfsp) # output containin images without lines nolinesfsp=args[0].rsplit(".",1)[0]+"_nolines.lst" try: os.unlink(nolinesfsp) except: pass lstnolines=LSXFile(nolinesfsp) for i,z in enumerate(Z): if z>options.threshold: lstlines[-1]=lstin[i] else: lstnolines[-1]=lstin[i] """ if options.newsets and not options.invar: lstin = LSXFile(args[0]) # output containing images with lines linesfsp = args[0].split("__", 1)[0] + "_lines__" + args[0].split( "__", 1)[1] try: os.unlink(linesfsp) except: pass lstlines = LSXFile(linesfsp) # output containin images without lines nolinesfsp = args[0].split("__", 1)[0] + "_nolines__" + args[0].split( "__", 1)[1] try: os.unlink(nolinesfsp) except: pass lstnolines = LSXFile(nolinesfsp) if options.zscore: for i, z in enumerate(Z): if z > options.threshold: lstlines[-1] = lstin[i] else: lstnolines[-1] = lstin[i] if options.rdnxform: for i, r in enumerate(lines): if r != 0: lstlines[-1] = lstin[i] else: lstnolines[-1] = lstin[i] if options.newsets and options.invar: lstin = LSXFile(args[0]) # output containing images with lines fnamemod = input("Type the filename modifier: ") linesfsp = args[0].split( "__", 1)[0] + f"_lines_{fnamemod}__" + args[0].split("__", 1)[1] try: os.unlink(linesfsp) except: pass lstlines = LSXFile(linesfsp) # output containing images without lines nolinesfsp = args[0].split( "__", 1)[0] + f"_nolines_{fnamemod}__" + args[0].split("__", 1)[1] try: os.unlink(nolinesfsp) except: pass lstnolines = LSXFile(nolinesfsp) # output copy of nolines folder invarfsp = nolinesfsp.rsplit("_", 1)[0] + "_invar.lst" try: os.unlink(invarfsp) except: pass lstinvar = LSXFile(invarfsp) if options.zscore: for i, z in enumerate(Z): if z > options.threshold: lstlines[-1] = lstin[i] else: lstnolines[-1] = lstin[i] lstinvar[-1] = lstin[i] if options.rdnxform: for i, r in enumerate(lines): if r != 0: lstlines[-1] = lstin[i] else: lstnolines[-1] = lstin[i] lstinvar[-1] = lstin[i] print(f"running: e2proclst.py {invarfsp} --retype ctf_flip_invar") os.system(f"e2proclst.py {invarfsp} --retype ctf_flip_invar") print("invar file created.") E2end(E2n)
def maskparmgui(classes): try: from eman2_gui.emapplication import EMApp from PyQt5 import QtCore, QtGui, QtWidgets, QtOpenGL import OpenGL OpenGL.ERROR_CHECKING = False from OpenGL import GL,GLUT from eman2_gui.valslider import ValSlider,CheckBox from eman2_gui.emimagemx import EMImageMXWidget except: print("Error: PyQt5 must be usable to use the --gui option") sys.exit(1) class GUImask(QtWidgets.QWidget): def __init__(self,app,classes): """Effectively a modal dialog for selecting masking parameters interactively """ self.app=app QtWidgets.QWidget.__init__(self,None) nx=classes[0]["nx"] self.classes=classes self.classview=EMImageMXWidget(self,classes) self.vbl = QtWidgets.QVBoxLayout(self) self.vbl.addWidget(self.classview) self.hbl = QtWidgets.QHBoxLayout() self.cmode=CheckBox(self,"orig",value=1) self.hbl.addWidget(self.cmode) self.slpres=ValSlider(self,(0.001,0.2),"Low-pass Filter:",0.03,90) self.hbl.addWidget(self.slpres) self.snmax=ValSlider(self,(0,20),"NMax:",5,90) self.snmax.intonly=1 self.hbl.addWidget(self.snmax) self.sshells=ValSlider(self,(0,40),"NShells:",nx//8,90) self.sshells.intonly=1 self.hbl.addWidget(self.sshells) self.ssigma=ValSlider(self,(0,2),"Sigma:",0.333,90) self.hbl.addWidget(self.ssigma) self.bok=QtWidgets.QPushButton("OK") self.hbl.addWidget(self.bok) self.vbl.addLayout(self.hbl) self.cmode.valueChanged.connect(self.newParm) self.slpres.valueChanged.connect(self.newParm) self.snmax.valueChanged.connect(self.newParm) self.sshells.valueChanged.connect(self.newParm) self.ssigma.valueChanged.connect(self.newParm) self.bok.clicked[bool].connect(self.close) self.newParm() def quit(self): self.app.close_specific(self) def newParm(self): if self.cmode.getValue(): self.classview.set_data(self.classes) return self.masked=[i.process("filter.lowpass.gauss",{"cutoff_freq":self.slpres.value}) for i in self.classes] nx=self.masked[0]["nx"] for i,im in enumerate(self.masked): im.process_inplace("mask.auto2d",{"nmaxseed":int(self.snmax.value),"nshells":int(self.sshells.value),"radius":old_div(nx,10),"return_mask":1,"sigma":self.ssigma.value}) im.process_inplace("filter.lowpass.gauss",{"cutoff_freq":0.03}) im.mult(self.classes[i]) self.classview.set_data(self.masked) app=EMApp() gui=GUImask(app,classes) gui.show() gui.raise_() app.exec_() return((gui.slpres.value,gui.snmax.value,gui.sshells.value,gui.ssigma.value))
ttx=False def IPY(): global ttx launch_new_instance() #app = TerminalIPythonApp.instance() #app.initialize() #app.start() print("Exiting e22.py") ttx=True def on_timer(): global ttx if ttx : QtGui.qApp.quit() ipythr=threading.Thread(target=IPY) ipythr.run() app = EMApp() EMAN2.GUIMode=True EMAN2.app=app mytimer = QtCore.QTimer() mytimer.timeout.connect(on_timer) mytimer.start(500) app.exec_()
def main(): progname = os.path.basename(sys.argv[0]) helpstring = """Help is available on the following topics: boxsizes,processors, cmps, aligners, averagers, projectors, reconstructors, analyzers, symmetries, orientgens, rotationtypes""" usage = """prog <topic> [contains] Interactive help on a variety of the eman2 library's modular functions. The optional 'contains' argument will act as a filter on the names of the algorithms.""" usage += " " + helpstring parser = EMArgumentParser(usage=usage, version=EMANVERSION) #parser.add_argument("--res", "-R", type=float, help="Resolution in A, equivalent to Gaussian lowpass with 1/e width at 1/res",default=2.8) #parser.add_argument("--box", "-B", type=str, help="Box size in pixels, <xyz> or <x>,<y>,<z>") parser.add_argument("--gui", action="store_true", help="Use the GUI for display help", default=False) parser.add_argument( "--ppid", type=int, help="Set the PID of the parent process, used for cross platform PPID", default=-2) parser.add_argument( "--verbose", "-v", dest="verbose", action="store", metavar="n", type=int, default=0, help= "verbose level [0-9], higher number means higher level of verboseness") (options, args) = parser.parse_args() if options.gui: from e2projectmanager import TheHelp from eman2_gui.emapplication import EMApp app = EMApp() thehelp = TheHelp() thehelp.show() if args: print(args[0]) if args[0] in ("aligner", "aligners"): thehelp._helpchange(0) elif args[0] in ("analyzer", "analyzers"): thehelp._helpchange(1) elif args[0] in ("averager", "averagers"): thehelp._helpchange(2) elif args[0] in ("cmp", "cmps"): thehelp._helpchange(3) elif args[0] in ("orientgen", "orientationgen", "orientgens", "orientationgens", "orientationgenerators"): thehelp._helpchange(4) elif args[0] in ("processor", "processors"): thehelp._helpchange(5) elif args[0] in ("projector", "projectors"): thehelp._helpchange(6) elif args[0] in ("reconstructor", "reconstructors"): thehelp._helpchange(7) elif args[0] in ("sym", "symmetry", "symmetries"): thehelp._helpchange(8) app.exec_() exit(0) if len(args) < 1: print(helpstring) exit(0) l = None if args[0] in ("cmp", "cmps"): print("Available comparators:") l = dump_cmps_list() elif args[0] in ("analyzer", "analyzers"): print("Available analysers:") l = dump_analyzers_list() elif args[0] in ("averager", "averagers"): print("Available averagers:") l = dump_averagers_list() elif args[0] in ("processor", "processors"): print("Available processors:") l = dump_processors_list() elif args[0] in ("projector", "projectors"): print("Available projectors:") l = dump_projectors_list() elif args[0] in ("reconstructor", "reconstructors"): print("Available reconstructors:") l = dump_reconstructors_list() elif args[0] in ("aligner", "aligners"): print("Available aligners:") l = dump_aligners_list() elif args[0] in ("sym", "symmetry", "symmetries"): print("Available symmetries:") l = dump_symmetries_list() elif args[0] in ("orientgen", "orientationgen", "orientgens", "orientationgens", "orientationgenerators"): print("Available orientation generators:") l = dump_orientgens_list() elif args[0][:3] == "box": if len(args) > 1: print(good_size(int(args[1]))) else: print(good_box_sizes) exit(0) elif args[0][:8] == "rotation": print("Available rotation conventions:") l = { "eman": [ "EMAN convention, az(Z),alt(X),phi(Z') Eulers", "alt", "FLOAT", "Altitude, X-axis", "az", "FLOAT", "Azimuth, Z-axis", "phi", "FLOAT", "Z' Axis. in-plane rotation in 2-D" ], "imagic": [ "IMAGIC convention", "alpha", "FLOAT", "alpha", "beta", "FLOAT", "beta", "gamma", "FLOAT", "gamma" ], "spider": [ "SPIDER convention", "phi", "FLOAT", "phi", "theta", "FLOAT", "theta", "psi", "FLOAT", "psi" ], "mrc": [ "MRC/CCP4 convention", "omega", "FLOAT", "omega", "theta", "FLOAT", "theta", "psi", "FLOAT", "psi" ], "xyz": [ "XYZ convention (Chimera)", "x", "FLOAT", "X-axis", "y", "FLOAT", "Y-axis", "z", "FLOAT", "Z-axis" ], "spin": [ "Spin-Axis (n1,n2,n3) vector with angle omega", "n1", "FLOAT", "X vector component", "n2", "FLOAT", "Y vector component", "n3", "FLOAT", "Z vector component", "omega", "FLOAT", "Angle of rotation in degrees" ], "sgirot": [ "SGI Spin-Axis (n1,n2,n3) vector with angle q", "n1", "FLOAT", "X vector component", "n2", "FLOAT", "Y vector component", "n3", "FLOAT", "Z vector component", "q", "FLOAT", "Angle of rotation in degrees" ], "quaternion": [ "Standard 4 component quaternion (e0,e1,e2,e3)", "e0", "FLOAT", "e0", "e1", "FLOAT", "e1", "e2", "FLOAT", "e2", "e3", "FLOAT", "e3" ] } elif args[0] in ("version"): print(FULLVERSIONSTRING) else: print(helpstring) print("unknown option:", args[0]) if l: if options.verbose > 0: if len(args) > 1: k = [i for i in list(l.keys()) if args[1] in i] else: k = list(l.keys()) k.sort() for i in k: print("%s : %s" % (i, l[i][0])) for j in range(1, len(l[i]), 3): print("\t%s(%s) - %s" % (l[i][j], l[i][j + 1], l[i][j + 2])) else: if len(args) > 1: k = [i for i in list(l.keys()) if args[1] in i] else: k = list(l.keys()) if len(k) == 0: print("Empty list - no items met search criteria") sys.exit(0) maxk = max([len(ii) for ii in k]) fmt = "%%-%0ds : " % maxk k.sort() for i in k: print(fmt % i, end=' ') for j in range(1, len(l[i]), 3): print("%s(%s) " % (l[i][j], l[i][j + 1]), end=' ') if len(k) > 1: print("")
def main(): progname = os.path.basename(sys.argv[0]) usage = """e2findlines sets/img.lst ** EXPERIMENTAL ** this program looks for ~ straight line segments in images, such as wrinkles in graphene oxide films or possible C-film edges """ parser = EMArgumentParser(usage=usage, version=EMANVERSION) parser.add_argument("--threshold", type=float, help="Threshold for separating particles, default=3", default=3.0) parser.add_argument("--newsets", default=False, action="store_true", help="Split lines/nolines into 2 new sets") #parser.add_argument("--output",type=str,help="Output filename (text file)", default="ptclplot.txt") parser.add_argument("--gui", default=False, action="store_true", help="show histogram of values") parser.add_argument( "--threads", default=4, type=int, help="Number of threads to run in parallel on the local computer") parser.add_argument( "--verbose", "-v", dest="verbose", action="store", metavar="n", type=int, default=0, help= "verbose level [0-9], higher number means higher level of verboseness") 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() if (len(args) < 1): parser.error("Please specify an input stack/set to operate on") E2n = E2init(sys.argv, options.ppid) options.threads += 1 # one extra thread for storing results im0 = EMData(args[0], 0) # first image r2 = im0["ny"] / 4 # outer radius # we build up a list of 'Z scores' which should be larger for images containing one or more parallel lines. # if 2 lines aren't parallel the number may be lower, even if the lines are strong, but should still be higher # than images without lines in most cases n = EMUtil.get_image_count(args[0]) step = max(n // 500, 1) Z = [] im2d = [] for i in range(n): im = EMData(args[0], i) a = im.do_fft().calc_az_dist(60, -88.5, 3, 4, r2) d = np.array(a) Z.append((d.max() - d.mean()) / d.std()) if i % step == 0: im["zscore"] = (d.max() - d.mean()) / d.std() im2d.append(im) if options.gui: # GUI display of a histogram of the Z scores from eman2_gui.emhist import EMHistogramWidget from eman2_gui.emimagemx import EMImageMXWidget from eman2_gui.emapplication import EMApp app = EMApp() histw = EMHistogramWidget(application=app) histw.set_data(Z) app.show_specific(histw) imd = EMImageMXWidget(application=app) im2d.sort(key=lambda x: x["zscore"]) imd.set_data(im2d) app.show_specific(imd) app.exec_() if options.newsets: lstin = LSXFile(args[0]) # output containing images with lines linesfsp = args[0].rsplit(".", 1)[0] + "_lines.lst" try: os.unlink(linesfsp) except: pass lstlines = LSXFile(linesfsp) # output containin images without lines nolinesfsp = args[0].rsplit(".", 1)[0] + "_nolines.lst" try: os.unlink(nolinesfsp) except: pass lstnolines = LSXFile(nolinesfsp) for i, z in enumerate(Z): if z > options.threshold: lstlines[-1] = lstin[i] else: lstnolines[-1] = lstin[i] E2end(E2n)