def projMatchRefine(self, volfile, alignstack, boxsize, numpart, pixrad, iternum):

		APSHout, projstack, numprojs = backprojectPWL.alignAPSH(volfile, alignstack, boxsize, numpart, pixrad, self.timestamp, iternum)
		### check APSH output
		if (os.path.isfile(APSHout) is False):
			apDisplay.printError("AP SH alignment did not generate a valid output file. Please check parameters and rerun!")

		apsh = open(APSHout, "r")

		neweulerdoc = os.path.join(self.params['rundir'],"newEulersdoc-%03d.spi"%(iternum))
		neweulerfile = open(neweulerdoc, "w")
		rotshiftdoc = os.path.join(self.params['rundir'],"rotShiftdoc-%03d.spi"%(iternum))
		rotshiftfile = open(rotshiftdoc, "w")

		starttime = time.time()

		count = 0
		for line in apsh.readlines():
			value = line.split()
			try:
				int(value[0])
			except:
				#apDisplay.printMsg(line)
				continue
			key = int(float(value[6]))
			rot = float(value[7])
			cumX = float(value[14]) #float(value[8])
			cumY = float(value[15]) #float(value[9])
			psi = float(value[2])
			theta = float(value[3])
			phi = float(value[4])
			mirror = int(float(value[16]))
			
			### write out new euler file
			eulerline = operations.spiderOutLine(key, [psi, theta, phi])
			neweulerfile.write(eulerline)
			
			### write out new rotate-shift-mirror file
			rotshiftline = operations.spiderOutLine(key, [key, rot, 1.00, cumX, cumY, mirror])
			rotshiftfile.write(rotshiftline)
			count+=1
			
			#if (count%20) == 0:
			#	apDisplay.printColor(str(numpart-count)+" particles left", "cyan")
			#	apDisplay.printColor("Estimated time left is "+apDisplay.timeString(((time.time()-starttime)/count)*(numpart-count)), "cyan")
		
		neweulerfile.close()
		rotshiftfile.close()

		### rotate and shift particle
		APSHstack = backprojectPWL.rotshiftParticle(alignstack, rotshiftdoc, iternum, self.timestamp)
		#APSHstack = backprojectPWL.rotshiftParticle(alignstack, key, rot, cumX, cumY, mirror, iternum, self.timestamp)
			
		apDisplay.printColor("finished rotating and shifting particles "+apDisplay.timeString(time.time()-starttime), "cyan")

		return APSHout, APSHstack, neweulerdoc, projstack, numprojs
 def appendEulerDoc(self, eulerfile, tiltpartnum, count):
         eulerf = open(eulerfile, "a")
         stackpartdata = apStack.getStackParticle(self.params['tiltstackid'], tiltpartnum)
         gamma, theta, phi, tiltangle = apTiltPair.getParticleTiltRotationAngles(stackpartdata)
         line = operations.spiderOutLine(count, [phi, tiltangle, -1.0*gamma])
         eulerf.write(line)
         eulerf.close()
 def makeEulerDoc(self, parttree):
     count = 0
     eulerfile = os.path.join(self.params['rundir'],
                              "eulersdoc" + self.timestamp + ".spi")
     eulerf = open(eulerfile, "w")
     apDisplay.printMsg("creating Euler doc file")
     starttime = time.time()
     for partdict in parttree:
         stackpartdata = apStack.getStackParticle(
             self.params['tiltstackid'], partdict['tilt'])
         count += 1
         if count % 100 == 0:
             sys.stderr.write(".")
             eulerf.flush()
         gamma, theta, phi, tiltangle = apTiltPair.getParticleTiltRotationAngles(
             stackpartdata)
         if gamma is None:
             apDisplay.printWarning("Skipping " + str(stackpartdata))
             continue
         line = operations.spiderOutLine(count, [phi, tiltangle, gamma])
         eulerf.write(line)
     eulerf.close()
     apDisplay.printColor(
         "finished Euler doc file in " +
         apDisplay.timeString(time.time() - starttime), "cyan")
     return eulerfile
        def getPartcileLists(self):
                #first query
                query1 = self.queryParticles(swap=False)
                self.cursor.execute(query1)
                results1 = self.cursor.fetchall()
                apDisplay.printMsg("Found "+str(len(results1))+" particle pairs in forward order")
                #if len(results1) < 2:
                #       apDisplay.printError("Failed to find any particles")

                #swap particle1 and particle2 in ApTiltParticlePairData
                query2 = self.queryParticles(swap=True)
                self.cursor.execute(query2)
                results2 = self.cursor.fetchall()
                apDisplay.printMsg("Found "+str(len(results2))+" particle pairs in reverse order")
                #if len(results2) < 2:
                #       apDisplay.printError("Failed to find any particles")

                parttree = self.parseResults(results1, results2)

                f = open("tiltsync-"+self.timestamp+".dat", "w")
                count = 0
                for partdict in parttree:
                        count += 1
                        emannotnum = partdict['not']-1
                        emantiltnum = partdict['tilt']-1
                        line = operations.spiderOutLine(count, (emannotnum,emantiltnum))
                        f.write(line)
                f.close()

                apDisplay.printMsg("Writing "+str(len(parttree))+" particle pairs")
                if len(parttree) < 2:
                        apDisplay.printError("Failed to find any particle pairs")

                return parttree
	def appendEulerDoc(self, eulerfile, tiltpartnum, count):
		eulerf = open(eulerfile, "a")
		stackpartdata = apStack.getStackParticle(self.params['tiltstackid'], tiltpartnum)
		gamma, theta, phi, tiltangle = apTiltPair.getParticleTiltRotationAngles(stackpartdata)
		if gamma is None:
			apDisplay.printWarning("Skipping "+str(stackpartdata))
			return			
		line = operations.spiderOutLine(count, [phi, tiltangle, -1.0*gamma])
		eulerf.write(line)
		eulerf.close()
def generateRandomAngles(numpart, dataext=".spi"):
        i = 0
        randdocfile = "randomeulerdoc"+dataext
        f.open(randdocfile)
        while(i < numpart):
                eulerlist = randomEuler()
                spiline = operations.spiderOutLine(i+1, eulerlist)
                f.write(spiline)
                i+=1
        f.close()
        return randdocfile
Esempio n. 7
0
def generateRandomAngles(numpart, dataext=".spi"):
    i = 0
    randdocfile = "randomeulerdoc" + dataext
    f.open(randdocfile)
    while (i < numpart):
        eulerlist = randomEuler()
        spiline = operations.spiderOutLine(i + 1, eulerlist)
        f.write(spiline)
        i += 1
    f.close()
    return randdocfile
    def splitOddEven(self, classnum, select, iternum):

        if (os.path.isfile(select) is False):
            apDisplay.printError("File " + select + " does not exist!")

        selectFile = open(select, "r")
        selectFilename = os.path.splitext(os.path.basename(select))[0]

        selectOdd = os.path.join(self.params['rundir'], str(classnum),
                                 selectFilename + "Odd.spi")
        selectOddFile = open(selectOdd, "w")

        selectEven = os.path.join(self.params['rundir'], str(classnum),
                                  selectFilename + "Even.spi")
        selectEvenFile = open(selectEven, "w")

        countOdd = 1
        countEven = 1

        for line in selectFile.readlines():
            value = line.split()

            try:
                int(value[0])
            except:
                #apDisplay.printMsg(line)
                continue

            if float(value[0]) % 2.0 == 1.0:
                sline = operations.spiderOutLine(countOdd, [int(value[0])])
                selectOddFile.write(line)
                countOdd += 1
            else:
                sline = operations.spiderOutLine(countEven, [int(value[0])])
                selectEvenFile.write(line)
                countEven += 1

        selectOddFile.close()
        selectEvenFile.close()

        return selectOdd, selectEven
 def appendEulerDoc(self, eulerfile, tiltpartnum, count):
     eulerf = open(eulerfile, "a")
     stackpartdata = apStack.getStackParticle(self.params['tiltstackid'],
                                              tiltpartnum)
     gamma, theta, phi, tiltangle = apTiltPair.getParticleTiltRotationAngles(
         stackpartdata)
     if gamma is None:
         apDisplay.printWarning("Skipping " + str(stackpartdata))
         return
     line = operations.spiderOutLine(count, [phi, tiltangle, -1.0 * gamma])
     eulerf.write(line)
     eulerf.close()
	def splitOddEven(self, classnum, select, iternum):

		if (os.path.isfile(select) is False):
			apDisplay.printError("File "+ select +" does not exist!")

		selectFile = open(select, "r")
		selectFilename = os.path.splitext(os.path.basename(select))[0]

		selectOdd = os.path.join(self.params['rundir'], str(classnum), selectFilename+"Odd.spi")
		selectOddFile = open(selectOdd, "w")

		selectEven = os.path.join(self.params['rundir'], str(classnum), selectFilename+"Even.spi")
		selectEvenFile = open(selectEven, "w")

		countOdd=1
		countEven=1

		for line in selectFile.readlines():
			value = line.split()

			try:
				int(value[0])
			except:
				#apDisplay.printMsg(line)
				continue

			if float(value[0])%2.0 == 1.0:
				sline = operations.spiderOutLine(countOdd, [int(value[0])])
				selectOddFile.write(line)
				countOdd+=1
			else:
				sline = operations.spiderOutLine(countEven, [int(value[0])])
				selectEvenFile.write(line)
				countEven+=1

		selectOddFile.close()
		selectEvenFile.close()

		return selectOdd, selectEven
Esempio n. 11
0
	def writePartDocFile(self, partlist):
		docfile = "finalshifts_"+self.params['timestamp']+".doc"
		f = open(docfile, "w")
		dlist = ['inplane', 'xshift', 'yshift', 'refnum', 'mirror', 'spread']
		f.write(" ; partnum ... "+str(dlist)+"\n")
		for partdict in partlist:
			floatlist = []
			for key in dlist:
				floatlist.append(partdict[key])
			line = operations.spiderOutLine(partdict['partnum'], floatlist)
			f.write(line)
		f.write(" ; partnum ... "+str(dlist)+"\n")
		f.close()
		apDisplay.printMsg("wrote rotation and shift parameters to "+docfile+" for "+str(len(partlist))+" particles")
		return
    def makeEulerDoc(self, tiltParticlesData, cnum):
        count = 0
        eulerfile = os.path.join(self.params['rundir'], str(cnum),
                                 "eulersdoc" + self.timestamp + ".spi")
        eulerf = open(eulerfile, "w")
        apDisplay.printMsg("Creating Euler angles doc file")
        starttime = time.time()
        tiltParticlesData.sort(self.sortTiltParticlesData)
        startmem = mem.active()
        for stackpartdata in tiltParticlesData:
            count += 1
            if count % 50 == 0:
                sys.stderr.write(".")
                eulerf.flush()
                memdiff = (mem.active() - startmem) / count / 1024.0
                if memdiff > 3:
                    apDisplay.printColor(
                        "Memory increase: %d MB/part" % (memdiff), "red")
            tiltrot, theta, notrot, tiltangle = apTiltPair.getParticleTiltRotationAnglesOTR(
                stackpartdata)

            ### Hack for OTR to work ( bad tilt axis angle from tilt picker )
            tiltrot = -7.0
            notrot = -7.0

            inplane, mirror = self.getParticleInPlaneRotation(stackpartdata)
            totrot = -1.0 * (notrot + inplane)
            if mirror is True:
                #theta flips to the back
                tiltangle = -1.0 * tiltangle + 180  #tiltangle = tiltangle + 180.0   #theta
                totrot = -1.0 * totrot - 180.0  #phi
                tiltrot = tiltrot + 180  #tiltrot = -1.0 * tiltrot + 180.0 #psi
            while totrot < 0:
                totrot += 360.0
            ### this is the original eman part num; count is new part num
            partnum = stackpartdata['particleNumber'] - 1
            line = operations.spiderOutLine(count,
                                            [tiltrot, tiltangle, totrot])
            eulerf.write(line)
        eulerf.close()
        apDisplay.printColor(
            "\nFinished Euler angle doc file in " +
            apDisplay.timeString(time.time() - starttime), "cyan")
        memdiff = (mem.active() - startmem) / count / 1024.0
        if memdiff > 0.1:
            apDisplay.printColor("Memory increase: %.2f MB/part" % (memdiff),
                                 "red")
        return eulerfile
Esempio n. 13
0
	def makecccAPSHselectFile(self, APSHout, classnum, iternum, factor):

		if (os.path.isfile(APSHout) is False):
			apDisplay.printError("File "+ APSHout +" does not exist!")

		apshFile = open(APSHout, "r")
		corrValues = []

		for line in apshFile.readlines():
			value = line.split()

			try:
				int(value[0])
			except:
				#apDisplay.printMsg(line)
				continue

			corrValues.append(float(value[12]))

		apshFile.close()

		corrmean = (numpy.array(corrValues)).mean()
		corrvar = (numpy.array(corrValues)).var()
		corrstd = (numpy.array(corrValues)).std()

		threshold = corrmean + (factor*corrstd)

		count = 1
		part = 1

		corrSelect = os.path.join(self.params['rundir'], str(classnum), "apshCorrSelect-%03d.spi"%(iternum))
		corrSelectFile = open(corrSelect, "w")


		for i,corrValue in enumerate(corrValues):

			if corrValue >= threshold:
				line = operations.spiderOutLine(count, [i+1])
				corrSelectFile.write(line)
				count+=1

		corrSelectFile.close()

		if count == 0:
			apDisplay.printError("no correlation value is above threshold!")

		return corrSelect
 def makeEulerDoc(self, parttree):
         count = 0
         eulerfile = os.path.join(self.params['rundir'], "eulersdoc"+self.timestamp+".spi")
         eulerf = open(eulerfile, "w")
         apDisplay.printMsg("creating Euler doc file")
         starttime = time.time()
         for partdict in parttree:
                 stackpartdata = apStack.getStackParticle(self.params['tiltstackid'], partdict['tilt'])
                 count += 1
                 if count%100 == 0:
                         sys.stderr.write(".")
                         eulerf.flush()
                 gamma, theta, phi, tiltangle = apTiltPair.getParticleTiltRotationAngles(stackpartdata)
                 line = operations.spiderOutLine(count, [phi, tiltangle, gamma])
                 eulerf.write(line)
         eulerf.close()
         apDisplay.printColor("finished Euler doc file in "+apDisplay.timeString(time.time()-starttime), "cyan")
         return eulerfile
    def makeEulerDoc(self, tiltParticlesData, cnum):
        count = 0
        eulerfile = os.path.join(self.params["rundir"], str(cnum), "eulersdoc" + self.timestamp + ".spi")
        eulerf = open(eulerfile, "w")
        apDisplay.printMsg("Creating Euler angles doc file")
        starttime = time.time()
        tiltParticlesData.sort(self.sortTiltParticlesData)
        startmem = mem.active()
        for stackpartdata in tiltParticlesData:
            count += 1
            if count % 50 == 0:
                sys.stderr.write(".")
                eulerf.flush()
                memdiff = (mem.active() - startmem) / count / 1024.0
                if memdiff > 3:
                    apDisplay.printColor("Memory increase: %d MB/part" % (memdiff), "red")
            tiltrot, theta, notrot, tiltangle = apTiltPair.getParticleTiltRotationAnglesOTR(stackpartdata)

            ### Hack for OTR to work ( bad tilt axis angle from tilt picker )
            tiltrot = -7.0
            notrot = -7.0

            inplane, mirror = self.getParticleInPlaneRotation(stackpartdata)
            totrot = -1.0 * (notrot + inplane)
            if mirror is True:
                # theta flips to the back
                tiltangle = -1.0 * tiltangle + 180  # tiltangle = tiltangle + 180.0   #theta
                totrot = -1.0 * totrot - 180.0  # phi
                tiltrot = tiltrot + 180  # tiltrot = -1.0 * tiltrot + 180.0 #psi
            while totrot < 0:
                totrot += 360.0
            ### this is the original eman part num; count is new part num
            partnum = stackpartdata["particleNumber"] - 1
            line = operations.spiderOutLine(count, [tiltrot, tiltangle, totrot])
            eulerf.write(line)
        eulerf.close()
        apDisplay.printColor(
            "\nFinished Euler angle doc file in " + apDisplay.timeString(time.time() - starttime), "cyan"
        )
        memdiff = (mem.active() - startmem) / count / 1024.0
        if memdiff > 0.1:
            apDisplay.printColor("Memory increase: %.2f MB/part" % (memdiff), "red")
        return eulerfile
def test(rdata):
        radialsize = rdata.shape[0]
        envshape = (4096, 4096)
        ### write data out
        f = open('radial-envelope.dat', 'w')
        spi = open('radial-envelope.spi', 'w')
        for i in range(radialsize):
                f.write('%d\t%.8f\n'%(i, rdata[i]))
                spi.write(operations.spiderOutLine(i, [i, rdata[i]]))
        f.close()
        spi.close()

        ### create new mrc
        xdata = numpy.arange(0, radialsize, 1.0, dtype=numpy.float64)
        ### fixed end values
        #print 0, rdata[0], "-->", 265.20575
        #print 2896, rdata[2896], "-->", 185.45721
        rdata[0] = 265.20575
        rdata[2896] = 185.45721
        envcalc = fromRadialFunc(funcrad, envshape, xdata=xdata, rdata=rdata)
        mrc.write(envcalc, 'calcualted-envelope.mrc')
Esempio n. 17
0
def test(rdata):
    radialsize = rdata.shape[0]
    envshape = (4096, 4096)
    ### write data out
    f = open('radial-envelope.dat', 'w')
    spi = open('radial-envelope.spi', 'w')
    for i in range(radialsize):
        f.write('%d\t%.8f\n' % (i, rdata[i]))
        spi.write(operations.spiderOutLine(i, [i, rdata[i]]))
    f.close()
    spi.close()

    ### create new mrc
    xdata = numpy.arange(0, radialsize, 1.0, dtype=numpy.float64)
    ### fixed end values
    #print 0, rdata[0], "-->", 265.20575
    #print 2896, rdata[2896], "-->", 185.45721
    rdata[0] = 265.20575
    rdata[2896] = 185.45721
    envcalc = fromRadialFunc(funcrad, envshape, xdata=xdata, rdata=rdata)
    mrc.write(envcalc, 'calcualted-envelope.mrc')
Esempio n. 18
0
    def runEoTest(self, alignstack, eulerfile):
        evenvolfile = os.path.join(self.params['rundir'],
                                   "evenvolume%s.spi" % (self.timestamp))
        oddvolfile = os.path.join(self.params['rundir'],
                                  "oddvolume%s.spi" % (self.timestamp))
        eveneulerfile = os.path.join(self.params['rundir'],
                                     "eveneulers%s.spi" % (self.timestamp))
        oddeulerfile = os.path.join(self.params['rundir'],
                                    "oddeulers%s.spi" % (self.timestamp))
        evenpartlist = os.path.join(self.params['rundir'],
                                    "evenparts%s.lst" % (self.timestamp))
        oddpartlist = os.path.join(self.params['rundir'],
                                   "oddparts%s.lst" % (self.timestamp))

        ### Create New Doc Files
        of = open(oddeulerfile, "w")
        ef = open(eveneulerfile, "w")
        op = open(oddpartlist, "w")
        ep = open(evenpartlist, "w")
        inf = open(eulerfile, "r")
        evenpart = 0
        oddpart = 0
        for line in inf:
            spidict = operations.spiderInLine(line)
            if spidict:
                partnum = spidict['row']
                if partnum % 2 == 0:
                    ep.write("%d\n" % (partnum - 1))
                    evenpart += 1
                    outline = operations.spiderOutLine(evenpart,
                                                       spidict['floatlist'])
                    ef.write(outline)
                elif partnum % 2 == 1:
                    op.write("%d\n" % (partnum - 1))
                    oddpart += 1
                    outline = operations.spiderOutLine(oddpart,
                                                       spidict['floatlist'])
                    of.write(outline)
        inf.close()
        of.close()
        ef.close()
        op.close()
        ep.close()

        ### Create stacks
        evenstack = os.path.join(self.params['rundir'],
                                 "evenstack%s.spi" % (self.timestamp))
        emancmd = "proc2d %s %s list=%s spiderswap" % (alignstack, evenstack,
                                                       evenpartlist)
        apEMAN.executeEmanCmd(emancmd, verbose=True, showcmd=True)
        oddstack = os.path.join(self.params['rundir'],
                                "oddstack%s.spi" % (self.timestamp))
        emancmd = "proc2d %s %s list=%s spiderswap" % (alignstack, oddstack,
                                                       oddpartlist)
        apEMAN.executeEmanCmd(emancmd, verbose=True, showcmd=True)

        ### Create Volumes
        backproject.backproject3F(evenstack, eveneulerfile, evenvolfile,
                                  evenpart)
        backproject.backproject3F(oddstack, oddeulerfile, oddvolfile, oddpart)
        if not os.path.isfile(evenvolfile) or not os.path.isfile(oddvolfile):
            apDisplay.printError("Even-Odd volume creation failed")

        ### Calculate FSC
        apix = apStack.getStackPixelSizeFromStackId(
            self.params['tiltstackid']) * self.params['tiltbin']
        emancmd = "proc3d %s %s" % (evenvolfile, evenvolfile + ".mrc")
        apEMAN.executeEmanCmd(emancmd, verbose=True, showcmd=True)
        emancmd = "proc3d %s %s" % (oddvolfile, oddvolfile + ".mrc")
        apEMAN.executeEmanCmd(emancmd, verbose=True, showcmd=True)
        fscfile = os.path.join(self.params['rundir'],
                               "fscdata%s.fsc" % (self.timestamp))
        emancmd = "proc3d %s %s fsc=%s" % (evenvolfile + ".mrc",
                                           oddvolfile + ".mrc", fscfile)
        apEMAN.executeEmanCmd(emancmd, verbose=True, showcmd=True)

        if not os.path.isfile(fscfile):
            apDisplay.printError("Even-Odd fsc calculation failed")
        boxsize = self.getBoxSize()
        self.fscresolution = apRecon.getResolutionFromFSCFile(fscfile,
                                                              boxsize,
                                                              apix,
                                                              msg=True)
        apDisplay.printColor(
            ("Final FSC resolution: %.5f" % (self.fscresolution)), "cyan")

        for fname in (evenvolfile, oddvolfile, evenstack, oddstack,
                      eveneulerfile, oddeulerfile, evenpartlist, oddpartlist):
            apFile.removeFile(fname)
	def runEoTest(self, alignstack, eulerfile):
		evenvolfile = os.path.join(self.params['rundir'], "evenvolume%s.spi"%(self.timestamp))
		oddvolfile = os.path.join(self.params['rundir'], "oddvolume%s.spi"%(self.timestamp))
		eveneulerfile = os.path.join(self.params['rundir'], "eveneulers%s.spi"%(self.timestamp))
		oddeulerfile = os.path.join(self.params['rundir'], "oddeulers%s.spi"%(self.timestamp))
		evenpartlist = os.path.join(self.params['rundir'], "evenparts%s.lst"%(self.timestamp))
		oddpartlist = os.path.join(self.params['rundir'], "oddparts%s.lst"%(self.timestamp))

		### Create New Doc Files
		of = open(oddeulerfile, "w")
		ef = open(eveneulerfile, "w")
		op = open(oddpartlist, "w")
		ep = open(evenpartlist, "w")
		inf = open(eulerfile, "r")
		evenpart = 0
		oddpart = 0
		for line in inf:
			spidict = operations.spiderInLine(line)
			if spidict:
				partnum = spidict['row']
				if partnum % 2 == 0:
					ep.write("%d\n"%(partnum-1))
					evenpart += 1
					outline = operations.spiderOutLine(evenpart, spidict['floatlist'])
					ef.write(outline)
				elif partnum % 2 == 1:
					op.write("%d\n"%(partnum-1))
					oddpart += 1
					outline = operations.spiderOutLine(oddpart, spidict['floatlist'])
					of.write(outline)
		inf.close()
		of.close()
		ef.close()
		op.close()
		ep.close()

		### Create stacks
		evenstack = os.path.join(self.params['rundir'], "evenstack%s.spi"%(self.timestamp))
		emancmd = "proc2d %s %s list=%s spiderswap"%(alignstack,evenstack,evenpartlist)
		apEMAN.executeEmanCmd(emancmd, verbose=True, showcmd=True)
		oddstack = os.path.join(self.params['rundir'], "oddstack%s.spi"%(self.timestamp))
		emancmd = "proc2d %s %s list=%s spiderswap"%(alignstack,oddstack,oddpartlist)
		apEMAN.executeEmanCmd(emancmd, verbose=True, showcmd=True)

		### Create Volumes
		backproject.backproject3F(evenstack, eveneulerfile, evenvolfile, evenpart)
		backproject.backproject3F(oddstack, oddeulerfile, oddvolfile, oddpart)
		if not os.path.isfile(evenvolfile) or  not os.path.isfile(oddvolfile):
			apDisplay.printError("Even-Odd volume creation failed")

		### Calculate FSC
		apix = apStack.getStackPixelSizeFromStackId(self.params['tiltstackid'])*self.params['tiltbin']
		emancmd = "proc3d %s %s"%(evenvolfile, evenvolfile+".mrc")
		apEMAN.executeEmanCmd(emancmd, verbose=True, showcmd=True)
		emancmd = "proc3d %s %s"%(oddvolfile, oddvolfile+".mrc")
		apEMAN.executeEmanCmd(emancmd, verbose=True, showcmd=True)
		fscfile = os.path.join(self.params['rundir'], "fscdata%s.fsc"%(self.timestamp))
		emancmd = "proc3d %s %s fsc=%s"%(evenvolfile+".mrc", oddvolfile+".mrc", fscfile)
		apEMAN.executeEmanCmd(emancmd, verbose=True, showcmd=True)

		if not os.path.isfile(fscfile):
			apDisplay.printError("Even-Odd fsc calculation failed")
		boxsize = self.getBoxSize()
		self.fscresolution = apRecon.getResolutionFromFSCFile(fscfile, boxsize, apix, msg=True)
		apDisplay.printColor( ("Final FSC resolution: %.5f" % (self.fscresolution)), "cyan")

		for fname in (evenvolfile, oddvolfile, evenstack, oddstack, eveneulerfile, oddeulerfile, evenpartlist, oddpartlist):
			apFile.removeFile(fname)
Esempio n. 20
0
	def cccAPSH(self, APSHout, classnum, iternum):
		### Calculate absolute shifts
		absshifts=[]

		if not os.path.isfile(APSHout):
			apDisplay.printError("APSH output file not found: "+APSHout)

		apsh = open(APSHout, "r")

		for line in apsh.readlines():
			value = line.split()
			try:
				int(value[0])
			except:
				#apDisplay.printMsg(line)
				continue

			### absshift = sqrt(x^2 + y^2)
			absshift = math.sqrt((float(value[8])*float(value[8]))+(float(value[9])*float(value[9])))
			absshifts.append(absshift)

		apsh.close()

		### calculate the mean, variance and stdev of the absolute shift of the dataset
		APSHmean = (numpy.array(absshifts)).mean()
		APSHvar = (numpy.array(absshifts)).var()
		APSHstd = (numpy.array(absshifts)).std()

		### calculate the weighted cross correlation values

		####################################################################
		##
		##								1
		## prob(shift) = ------------------ * e^[-1/2*(shift-mean)/stdev]**2
		##						stdev*sqrt(2*pi)
		##
		####################################################################
		const = APSHstd*math.sqrt(2*math.pi)
		probs=[]

		for absshift in absshifts:

			### probability for each particle
			prob = (1/const)*math.exp((-1/2)*((absshift-APSHmean)/APSHstd)*((absshift-APSHmean)/APSHstd))
			probs.append(prob)

		### output file for APSH with weighted CC values
		APSHout_weighted = os.path.join(self.params['rundir'], str(classnum), "apshOut_weighted-%03d.spi"%(iternum))

		apsh = open(APSHout, "r")
		apshCCC = open(APSHout_weighted, "w")

		notline=0

		for i,line in enumerate(apsh.readlines()):
			value = line.split()
			try:
				int(value[0])
			except:
				#apDisplay.printMsg(line)
				notline+=1
				continue

			key = int(float(value[6]))
			weightedCCvalue = float(value[12])*probs[i-notline]

			psi = float(value[2])
			theta = float(value[3])
			phi = float(value[4])
			ref = float(value[5])
			partnum =  float(value[6])
			rot = float(value[7])
			cumX = float(value[8])
			cumY = float(value[9])
			proj = float(value[10])
			diff = float(value[11])
			inplane = float(value[13])
			sx = float(value[14])
			sy = float(value[15])
			mirror = float(value[16])


			### write out new APSH file
			APSHline = operations.spiderOutLine(key, [psi, theta, phi, ref, partnum, rot, cumX, cumY, proj, diff, weightedCCvalue, inplane, sx, sy, mirror])
			apshCCC.write(APSHline)

		apshCCC.close()
		apsh.close()

		return APSHout_weighted