Exemplo n.º 1
0
 def menu_add_3dwin(self):
     if self.viewer == None: return
     self.viewer.append(EMScene3D())
     self.sgdata = EMDataItem3D(test_image_3d(3), transform=Transform())
     self.viewer[-1].insertNewNode('Data',
                                   self.sgdata,
                                   parentnode=self.viewer[-1])
     isosurface = EMIsosurface(self.sgdata, transform=Transform())
     self.viewer[-1].insertNewNode("Iso",
                                   isosurface,
                                   parentnode=self.sgdata)
     volslice = EMSliceItem3D(self.sgdata, transform=Transform())
     self.viewer[-1].insertNewNode("Slice",
                                   volslice,
                                   parentnode=self.sgdata)
     self.viewer[-1].show()
     self.needupdate = 1
Exemplo n.º 2
0
    def setData(self, data):
        if data == None:
            self.data = None
            return

        elif isinstance(data, str):
            self.datafile = data
            self.nimg = EMUtil.get_image_count(data)

            if self.dataidx >= 0 and self.dataidx < self.nimg:
                ii = self.dataidx
                self.nimg = 1
            else:
                ii = 0

            hdr = EMData(data, 0, 1)

            self.origdata = EMData(data, ii)

            if self.origdata["nz"] == 1:
                if self.nimg > 20 and hdr["ny"] > 512:
                    self.origdata = EMData.read_images(
                        data, list(range(0, self.nimg, self.nimg // 20))
                    )  # read regularly separated images from the file totalling ~20
                elif self.nimg > 100:
                    self.origdata = EMData.read_images(
                        data,
                        list(range(0, 72)) +
                        list(range(72, self.nimg, self.nimg // 100))
                    )  # read the first 36 then regularly separated images from the file
                elif self.nimg > 1:
                    self.origdata = EMData.read_images(data,
                                                       list(range(self.nimg)))
                else:
                    self.origdata = [self.origdata]
            else:
                self.origdata = [self.origdata]

        else:
            self.datafile = None
            if isinstance(data, EMData): self.origdata = [data]
            else: self.origdata = data

        self.nx = self.origdata[0]["nx"]
        self.ny = self.origdata[0]["ny"]
        self.nz = self.origdata[0]["nz"]
        if self.apix <= 0.0: self.apix = self.origdata[0]["apix_x"]
        EMProcessorWidget.parmdefault["apix"] = (0, (0.2, 10.0), self.apix,
                                                 None)

        origfft = self.origdata[0].do_fft()
        self.pspecorig = origfft.calc_radial_dist(old_div(self.ny, 2), 0.0,
                                                  1.0, 1)
        ds = old_div(1.0, (self.apix * self.ny))
        self.pspecs = [ds * i for i in range(len(self.pspecorig))]

        if self.viewer != None:
            for v in self.viewer:
                v.close()

        if self.nz == 1 or self.force2d or (self.nx > 320
                                            and self.safemode == False):
            if len(self.origdata) > 1:
                self.viewer = [EMImageMXWidget()]
                self.mfile_save_stack.setEnabled(True)
            else:
                self.viewer = [EMImage2DWidget()]
                self.mfile_save_stack.setEnabled(False)
        else:
            self.mfile_save_stack.setEnabled(False)
            self.viewer = [EMScene3D()]
            self.sgdata = EMDataItem3D(test_image_3d(3), transform=Transform())
            self.viewer[0].insertNewNode('Data',
                                         self.sgdata,
                                         parentnode=self.viewer[0])
            isosurface = EMIsosurface(self.sgdata, transform=Transform())
            self.viewer[0].insertNewNode("Iso",
                                         isosurface,
                                         parentnode=self.sgdata)
            volslice = EMSliceItem3D(self.sgdata, transform=Transform())
            self.viewer[0].insertNewNode("Slice",
                                         volslice,
                                         parentnode=self.sgdata)

        if self.nz > 1: self.mfile_save_map.setEnabled(True)
        else: self.mfile_save_map.setEnabled(False)

        E2loadappwin("e2filtertool", "image", self.viewer[0].qt_parent)
        if self.origdata[0].has_attr("source_path"):
            winname = str(self.origdata[0]["source_path"])
        else:
            winname = "FilterTool"
        self.viewer[0].setWindowTitle(winname)

        self.procChange(-1)
Exemplo n.º 3
0
def main():

    usage = """prog --path <spt_xx> --iter <X> --tomo <tomogram>
	map aligned particles back to tomograms """
    parser = EMArgumentParser(usage=usage, version=EMANVERSION)
    parser.add_argument("--path",
                        type=str,
                        help="spt_xx path",
                        default="",
                        guitype='strbox',
                        row=0,
                        col=0,
                        rowspan=1,
                        colspan=1)
    parser.add_argument("--iter",
                        type=int,
                        help="iteration number",
                        default=1,
                        guitype='intbox',
                        row=0,
                        col=1,
                        rowspan=1,
                        colspan=1)
    parser.add_argument(
        "--tomo",
        type=str,
        help="tomogram file name",
        default="",
        guitype='filebox',
        browser="EMBrowserWidget(withmodal=True, startpath='tomograms')",
        row=2,
        col=0,
        rowspan=1,
        colspan=2,
    )
    parser.add_argument(
        "--avg",
        type=str,
        help="3D volume to insert. spt_xx/threed_xx if unspecified",
        default="",
        guitype='filebox',
        browser="EMBrowserWidget(withmodal=True, startpath='.')",
        row=3,
        col=0,
        rowspan=1,
        colspan=2)
    parser.add_argument("--postxf",
                        type=str,
                        help="extra shift after alignment",
                        default="")
    parser.add_argument(
        "--keep",
        type=float,
        help=
        "propotion to keep. will exclude bad particles if this is smaller than 1.0",
        default=1.0)
    parser.add_argument(
        "--gui",
        action="store_true",
        help="open the resulting map and tomogram in a GUI display",
        default=False,
        guitype="boolbox",
        row=4,
        col=0,
        rowspan=1,
        colspan=1)
    parser.add_argument("--ppid", type=int, help="ppid...", default=-1)
    (options, args) = parser.parse_args()
    logid = E2init(sys.argv)

    path = options.path
    itr = options.iter
    try:
        postxf = options.postxf.split(',')
        postxf = [float(i) for i in postxf]
        print("post shift : ", postxf)
    except:
        postxf = [0, 0, 0]

    js = js_open_dict("{}/particle_parms_{:02d}.json".format(path, itr))

    tomo = EMData(options.tomo)
    if options.gui: tomo_orig = tomo.copy()

    if len(options.avg) == 0:
        options.avg = "{}/threed_{:02d}.hdf".format(path, itr)
    avg = EMData(options.avg, 0)
    print("Using averaged map {}".format(options.avg))

    apix_tomo = tomo["apix_x"]
    apix_ptcl = avg["apix_x"]
    shrink = apix_tomo / apix_ptcl

    print(
        "Apix from tomogram {:.2f}, apix from average {:.2f}. Shrinking factor {:.1f}"
        .format(apix_tomo, apix_ptcl, shrink))

    avg.process_inplace("math.fft.resample", {"n": shrink})
    avg.process_inplace("normalize.edgemean")

    tomo.to_zero()

    ptcl = []
    scr = []
    llfile = ""
    bname = base_name(options.tomo)
    for k in js.keys():
        fsp, i = eval(k)
        if fsp[-4:] == ".lst":
            if llfile != fsp:
                llfile = fsp
                lsx = LSXFile(fsp, True)
            i, fsp, x = lsx.read(i)
        if base_name(fsp) == bname:
            ptcl.append((js[k]["score"], fsp, i, js[k]["xform.align3d"]))

    ptcl.sort()
    print(ptcl)

    nptcl = int(len(ptcl) * options.keep)
    if options.keep < 1.0:
        sthr = ptcl[nptcl][0]
    else:
        sthr = 100

    pts = []
    print("{:d} particles total.".format(int(nptcl)))
    if nptcl == 0:
        print("No particles. Exiting")
        sys.exit(0)

    for s, fsp, i, xf in ptcl:
        if s > sthr:
            continue
        a = EMData(fsp, i, True)

        if tomo.has_attr("zshift"):
            zs = tomo["zshift"]
        else:
            zs = 0
        crd = np.array(a["ptcl_source_coord"]) / shrink + [
            tomo["nx"] // 2, tomo["ny"] // 2, tomo["nz"] // 2 + zs / shrink
        ]
        ts = np.array(xf.get_trans())
        ts += postxf
        xf.set_trans((ts / shrink).tolist())
        xf = xf.inverse()
        t = avg.process("xform", {"transform": xf})
        pts.append(crd - ts / 4)
        tomo.insert_scaled_sum(t, crd.tolist())
        print("\t{}/{} finished.".format(len(pts), nptcl), end='\r')
        sys.stdout.flush()

    pts = np.array(pts)
    pfile = "{}/ptcls_pos_{:02d}.pdb".format(path, itr)
    tfile = "{}/ptcls_in_tomo_{}_{:02d}.hdf".format(path, bname, itr)
    tomo.write_compressed(tfile, 0, 8)
    numpy2pdb(fname=pfile, data=pts)
    print("Map {} particles to the tomogram".format(len(pts)))
    print("Particle coordinates written to {}".format(pfile))
    print("Map with particles written to {}".format(tfile))
    js = None
    E2end(logid)

    if options.gui:
        print("opening GUI")
        from eman2_gui.emapplication import get_application, EMApp
        from eman2_gui.emscene3d import EMScene3D
        from eman2_gui.emdataitem3d import EMDataItem3D, EMIsosurface, EMSliceItem3D
        from eman2_gui.emshape import EMShape

        app = EMApp()
        view = EMScene3D()

        # slice through the original tomogram
        tomo_orig_di = EMDataItem3D(tomo_orig, transform=Transform())
        view.insertNewNode('Data', tomo_orig_di, parentnode=view)
        volslice = EMSliceItem3D(tomo_orig_di, transform=Transform())
        view.insertNewNode("Slice", volslice, parentnode=tomo_orig_di)

        # isosurface of reconstituted particles
        tomo_di = EMDataItem3D(tomo, transform=Transform())
        view.insertNewNode('Data', tomo_di, parentnode=view)
        isosurface = EMIsosurface(tomo_di, transform=Transform())
        view.insertNewNode("Iso", isosurface, parentnode=tomo_di)

        view.show()
        try:
            view.raise_()
        except:
            pass

        app.execute()

    print("Done.")
Exemplo n.º 4
0
    def setData(self, data):
        if data == None:
            self.data = None
            return

        elif isinstance(data, str):
            self.datafile = data
            self.nimg = EMUtil.get_image_count(data)

            self.origdata = EMData(data, 0)

            if self.origdata["nz"] == 1:
                if self.nimg > 20:
                    self.origdata = EMData.read_images(
                        data, list(range(0, self.nimg, old_div(self.nimg, 20)))
                    )  # read regularly separated images from the file totalling ~20
                elif self.nimg > 1:
                    self.origdata = EMData.read_images(data,
                                                       list(range(self.nimg)))
                else:
                    self.origdata = [self.origdata]
            else:
                self.origdata = [self.origdata]

        else:
            self.datafile = None
            if isinstance(data, EMData): self.origdata = [data]
            else: self.origdata = data

        self.nx = self.origdata[0]["nx"]
        self.ny = self.origdata[0]["ny"]
        self.nz = self.origdata[0]["nz"]
        if self.apix <= 0.0: self.apix = self.origdata[0]["apix_x"]
        EMProcessorWidget.parmdefault["apix"] = (0, (0.2, 10.0), self.apix,
                                                 None)

        origfft = self.origdata[0].do_fft()
        self.pspecorig = origfft.calc_radial_dist(old_div(self.ny, 2), 0.0,
                                                  1.0, 1)
        ds = old_div(1.0, (self.apix * self.ny))
        self.pspecs = [ds * i for i in range(len(self.pspecorig))]

        if self.viewer != None:
            for v in self.viewer:
                v.close()

        if self.nz == 1 or self.force2d:
            if len(self.origdata) > 1:
                self.viewer = [EMImageMXWidget()]
                self.mfile_save_stack.setEnabled(True)
                self.mfile_save_map.setEnabled(False)
            else:
                self.viewer = [EMImage2DWidget()]
                self.mfile_save_stack.setEnabled(False)
                self.mfile_save_map.setEnabled(True)
        else:
            self.mfile_save_stack.setEnabled(False)
            self.mfile_save_map.setEnabled(True)
            self.viewer = [EMScene3D()]
            self.sgdata = EMDataItem3D(test_image_3d(3), transform=Transform())
            self.viewer[0].insertNewNode('Data',
                                         self.sgdata,
                                         parentnode=self.viewer[0])
            isosurface = EMIsosurface(self.sgdata, transform=Transform())
            self.viewer[0].insertNewNode("Iso",
                                         isosurface,
                                         parentnode=self.sgdata)
            volslice = EMSliceItem3D(self.sgdata, transform=Transform())
            self.viewer[0].insertNewNode("Slice",
                                         volslice,
                                         parentnode=self.sgdata)

        E2loadappwin("e2filtertool", "image", self.viewer[0].qt_parent)

        self.procChange(-1)