예제 #1
0
    def getParticleInPlaneRotation(self, tiltstackpartdata):
        partid = tiltstackpartdata.dbid
        if partid in self.rotmirrorcache:
            ### use cached value
            return self.rotmirrorcache[partid]

        partnum = tiltstackpartdata['particleNumber']
        notstackpartdata = apTiltPair.getStackParticleTiltPair(
            self.params['tiltstackid'], partnum, self.params['notstackid'])

        alignpartq = appiondata.ApAlignParticleData()
        alignpartq['stackpart'] = notstackpartdata
        alignpartq['alignstack'] = self.alignstackdata
        alignpartdatas = alignpartq.query()
        if not alignpartdatas or len(alignpartdatas) != 1:
            apDisplay.printError(
                "could not get inplane rotation for particle %d" %
                (tiltstackpartdata['particleNumber']))
        inplane = alignpartdatas[0]['rotation']
        mirror = alignpartdatas[0]['mirror']
        if alignpartdatas[0]['alignstack']['alignrun'][
                'maxlikerun'] is not None:
            # maxlike does mirror then rotation, and its rotation is negative relative to spider
            # April 6, 2009: rotation is negative independent of mirror
            inplane = -1.0 * inplane
        self.rotmirrorcache[partid] = (inplane, mirror)
        return inplane, mirror
예제 #2
0
	def getGoodParticles(self, classpartdatas, norefclassnum):
		includeParticle = []
		tiltParticlesData = []
		nopairParticle = 0
		excludeParticle = 0
		apDisplay.printMsg("sorting particles")
		for classpart in classpartdatas:
			#write to text file
			classnum = classpart['classNumber']-1
			if classnum == norefclassnum:
				notstackpartnum = classpart['noref_particle']['particle']['particleNumber']
				tiltstackpartdata = apTiltPair.getStackParticleTiltPair(self.params['notstackid'],
					notstackpartnum, self.params['tiltstackid'])
				if tiltstackpartdata is None:
					nopairParticle += 1
				else:
					emantiltstackpartnum = tiltstackpartdata['particleNumber']-1
					includeParticle.append(emantiltstackpartnum)
					tiltParticlesData.append(tiltstackpartdata)
			else:
				excludeParticle += 1
		includeParticle.sort()
		apDisplay.printMsg("Keeping "+str(len(includeParticle))+" and excluding \n\t"
			+str(excludeParticle)+" particles with "+str(nopairParticle)+" unpaired particles")
		if len(includeParticle) < 1:
			apDisplay.printError("No particles were kept")
		return includeParticle, tiltParticlesData
예제 #3
0
	def getParticleNoRefInPlaneRotation(self, stackpartdata):
		notstackpartdata = apTiltPair.getStackParticleTiltPair(self.params['tiltstackid'],
			stackpartdata['particleNumber'], self.params['notstackid'])
		classpartq = appiondata.ApNoRefClassParticlesData()
		classpartq['classRun'] = self.norefclassdata
		norefpartq = appiondata.ApNoRefAlignParticlesData()
		norefpartq['particle'] = notstackpartdata
		classpartq['noref_particle'] = norefpartq
		classpartdatas = classpartq.query(results=1)
		if not classpartdatas or len(classpartdatas) != 1:
			apDisplay.printError("could not get inplane rotation")
		inplane = classpartdatas[0]['noref_particle']['rotation']
		return inplane
예제 #4
0
	def getParticleInPlaneRotation(self, tiltstackpartdata):
		partid = tiltstackpartdata.dbid
		if partid in self.rotmirrorcache:
			### use cached value
			return self.rotmirrorcache[partid]

		partnum = tiltstackpartdata['particleNumber']
		notstackpartdata = apTiltPair.getStackParticleTiltPair(self.params['tiltstackid'],
			partnum, self.params['notstackid'])

		alignpartq = appiondata.ApAlignParticleData()
		alignpartq['stackpart'] = notstackpartdata
		alignpartq['alignstack'] = self.alignstackdata
		alignpartdatas = alignpartq.query()
		if not alignpartdatas or len(alignpartdatas) != 1:
			apDisplay.printError("could not get inplane rotation for particle %d"%(tiltstackpartdata['particleNumber']))
		inplane = alignpartdatas[0]['rotation']
		mirror = alignpartdatas[0]['mirror']
		self.rotmirrorcache[partid] = (inplane, mirror)
		return inplane, mirror
예제 #5
0
	def getParticleInPlaneRotation(self, tiltstackpartdata):
		partid = tiltstackpartdata.dbid
		if partid in self.rotmirrorcache:
			### use cached value
			return self.rotmirrorcache[partid]

		partnum = tiltstackpartdata['particleNumber']
		notstackpartdata = apTiltPair.getStackParticleTiltPair(self.params['tiltstackid'],
			partnum, self.params['notstackid'])

		alignpartq = appiondata.ApAlignParticleData()
		alignpartq['stackpart'] = notstackpartdata
		alignpartq['alignstack'] = self.alignstackdata
		alignpartdatas = alignpartq.query()
		if not alignpartdatas or len(alignpartdatas) != 1:
			apDisplay.printError("could not get inplane rotation for particle %d"%(tiltstackpartdata['particleNumber']))
		inplane = alignpartdatas[0]['rotation']
		mirror = alignpartdatas[0]['mirror']
		if alignpartdatas[0]['alignstack']['alignrun']['maxlikerun'] is not None:
			# maxlike does mirror then rotation, and its rotation is negative relative to spider
			# April 6, 2009: rotation is negative independent of mirror
			inplane = -1.0*inplane
		self.rotmirrorcache[partid] = (inplane, mirror)
		return inplane, mirror
예제 #6
0
    def getGoodAlignParticles(self):
        includeParticle = []
        tiltParticlesData = []
        nopairParticle = 0
        excludeParticle = 0
        badmirror = 0
        badscore = 0
        apDisplay.printMsg("Sorting particles from classes at " +
                           time.asctime())
        count = 0
        startmem = mem.active()
        t0 = time.time()
        if self.params['clusterid'] is not None:
            ### method 1: get particles from clustering data
            clusterpartq = appiondata.ApClusteringParticleData()
            clusterpartq[
                'clusterstack'] = appiondata.ApClusteringStackData.direct_query(
                    self.params['clusterid'])
            clusterpartdatas = clusterpartq.query()
            apDisplay.printMsg("Sorting " + str(len(clusterpartdatas)) +
                               " clustered particles")

            for clustpart in clusterpartdatas:
                count += 1
                if count % 50 == 0:
                    sys.stderr.write(".")
                    memdiff = (mem.active() - startmem) / count / 1024.0
                    if memdiff > 3:
                        apDisplay.printColor(
                            "Memory increase: %d MB/part" % (memdiff), "red")
                #write to text file
                clustnum = clustpart['refnum'] - 1
                if self.params['minscore'] is not None:
                    if (clustpart['alignparticle']['score'] is not None
                            and clustpart['alignparticle']['score'] <
                            self.params['minscore']):
                        badscore += 1
                        continue
                    elif (clustpart['alignparticle']['spread'] is not None
                          and clustpart['alignparticle']['spread'] <
                          self.params['minscore']):
                        badscore += 1
                        continue
                if clustnum in self.classlist:
                    notstackpartnum = clustpart['alignparticle']['stackpart'][
                        'particleNumber']
                    tiltstackpartdata = apTiltPair.getStackParticleTiltPair(
                        self.params['notstackid'], notstackpartnum,
                        self.params['tiltstackid'])

                    if tiltstackpartdata is None:
                        nopairParticle += 1
                        continue
                    tiltrot, theta, notrot, tiltangle = apTiltPair.getParticleTiltRotationAngles(
                        tiltstackpartdata)
                    if tiltrot is None:
                        apDisplay.printWarning("BAD particle  " +
                                               str(tiltstackpartdata))
                        nopairParticle += 1
                        continue
                    else:
                        inplane, mirror = self.getParticleInPlaneRotation(
                            tiltstackpartdata)
                        if (self.params['mirror'] == "all" or
                            (self.params['mirror'] == "no" and mirror is False)
                                or (self.params['mirror'] == "yes"
                                    and mirror is True)):
                            emantiltstackpartnum = tiltstackpartdata[
                                'particleNumber'] - 1
                            includeParticle.append(emantiltstackpartnum)
                            tiltParticlesData.append(tiltstackpartdata)
                            if self.params['numpart'] is not None and len(
                                    includeParticle) > self.params['numpart']:
                                break
                        else:
                            badmirror += 1
                else:
                    excludeParticle += 1
        else:
            ### method 2: get particles from alignment data
            alignpartq = appiondata.ApAlignParticleData()
            alignpartq['alignstack'] = self.alignstackdata
            alignpartdatas = alignpartq.query()
            apDisplay.printMsg("Sorting " + str(len(alignpartdatas)) +
                               " aligned particles")

            for alignpart in alignpartdatas:
                count += 1
                if count % 50 == 0:
                    sys.stderr.write(".")
                    memdiff = (mem.active() - startmem) / count / 1024.0
                    if memdiff > 3:
                        apDisplay.printColor(
                            "Memory increase: %d MB/part" % (memdiff), "red")
                #write to text file
                alignnum = alignpart['ref']['refnum'] - 1
                if (self.params['minscore'] is not None
                        and alignpart['score'] is not None
                        and alignpart['score'] < self.params['minscore']):
                    badscore += 1
                    continue
                if alignnum in self.classlist:
                    notstackpartnum = alignpart['stackpart']['particleNumber']
                    tiltstackpartdata = apTiltPair.getStackParticleTiltPair(
                        self.params['notstackid'], notstackpartnum,
                        self.params['tiltstackid'])
                    if tiltstackpartdata is None:
                        nopairParticle += 1
                    else:
                        inplane, mirror = self.getParticleInPlaneRotation(
                            tiltstackpartdata)
                        if (self.params['mirror'] == "all" or
                            (self.params['mirror'] == "no" and mirror is False)
                                or (self.params['mirror'] == "yes"
                                    and mirror is True)):
                            emantiltstackpartnum = tiltstackpartdata[
                                'particleNumber'] - 1
                            includeParticle.append(emantiltstackpartnum)
                            tiltParticlesData.append(tiltstackpartdata)
                            if self.params['numpart'] is not None and len(
                                    includeParticle) > self.params['numpart']:
                                break
                        else:
                            badmirror += 1
                else:
                    excludeParticle += 1
        ### end methods

        includeParticle.sort()
        ### messages
        if time.time() - t0 > 1.0:
            apDisplay.printMsg("\nSorting time: " +
                               apDisplay.timeString(time.time() - t0))
        apDisplay.printMsg("Keeping " + str(len(includeParticle)) +
                           " and excluding \n\t" + str(excludeParticle) +
                           " particles with " + str(nopairParticle) +
                           " unpaired particles")
        if badmirror > 0:
            apDisplay.printMsg("Particles with bad mirrors: %d" % (badmirror))
        if badscore > 0:
            apDisplay.printColor("Particles with bad scores: %d" % (badscore),
                                 "cyan")
        if len(includeParticle) < 1:
            apDisplay.printError("No particles were kept")
        memdiff = (mem.active() - startmem) / count / 1024.0
        if memdiff > 0.1:
            apDisplay.printColor("Memory increase: %.2f MB/part" % (memdiff),
                                 "red")

        return includeParticle, tiltParticlesData
예제 #7
0
	def getGoodAlignParticles(self):
		includeParticle = []
		tiltParticlesData = []
		nopairParticle = 0
		excludeParticle = 0
		badmirror = 0
		badscore = 0
		apDisplay.printMsg("Sorting particles from classes at "+time.asctime())
		count = 0
		startmem = mem.active()
		t0 = time.time()
		if self.params['clusterid'] is not None:
			### method 1: get particles from clustering data
			clusterpartq = appiondata.ApClusteringParticleData()
			clusterpartq['clusterstack'] = appiondata.ApClusteringStackData.direct_query(self.params['clusterid'])
			clusterpartdatas = clusterpartq.query()
			apDisplay.printMsg("Sorting "+str(len(clusterpartdatas))+" clustered particles")

			for clustpart in clusterpartdatas:
				count += 1
				if count%50 == 0:
					sys.stderr.write(".")
					memdiff = (mem.active()-startmem)/count/1024.0
					if memdiff > 3:
						apDisplay.printColor("Memory increase: %d MB/part"%(memdiff), "red")
				#write to text file
				clustnum = clustpart['refnum']-1
				if self.params['minscore'] is not None:
					if ( clustpart['alignparticle']['score'] is not None
					 and clustpart['alignparticle']['score'] < self.params['minscore'] ):
						badscore += 1
						continue
					elif ( clustpart['alignparticle']['spread'] is not None
					 and clustpart['alignparticle']['spread'] < self.params['minscore'] ):
						badscore += 1
						continue
				if clustnum in self.classlist:
					notstackpartnum = clustpart['alignparticle']['stackpart']['particleNumber']
					tiltstackpartdata = apTiltPair.getStackParticleTiltPair(self.params['notstackid'],
						notstackpartnum, self.params['tiltstackid'])
						
				
					if tiltstackpartdata is None:
						nopairParticle += 1
						continue
					tiltrot, theta, notrot, tiltangle = apTiltPair.getParticleTiltRotationAngles(tiltstackpartdata)
					if tiltrot is None:
						apDisplay.printWarning("BAD particle  "+str(tiltstackpartdata))
						nopairParticle += 1
						continue
					else:
						inplane, mirror = self.getParticleInPlaneRotation(tiltstackpartdata)
						if ( self.params['mirror'] == "all"
						 or (self.params['mirror'] == "no" and mirror is False)
						 or (self.params['mirror'] == "yes" and mirror is True) ):
							emantiltstackpartnum = tiltstackpartdata['particleNumber']-1
							includeParticle.append(emantiltstackpartnum)
							tiltParticlesData.append(tiltstackpartdata)
							if self.params['numpart'] is not None and len(includeParticle) > self.params['numpart']:
								break
						else:
							badmirror += 1
				else:
					excludeParticle += 1
		else:
			### method 2: get particles from alignment data
			alignpartq = appiondata.ApAlignParticleData()
			alignpartq['alignstack'] = self.alignstackdata
			alignpartdatas = alignpartq.query()
			apDisplay.printMsg("Sorting "+str(len(alignpartdatas))+" aligned particles")

			for alignpart in alignpartdatas:
				count += 1
				if count%50 == 0:
					sys.stderr.write(".")
					memdiff = (mem.active()-startmem)/count/1024.0
					if memdiff > 3:
						apDisplay.printColor("Memory increase: %d MB/part"%(memdiff), "red")
				#write to text file
				alignnum = alignpart['ref']['refnum']-1
				if ( self.params['minscore'] is not None
				 and alignpart['score'] is not None
				 and alignpart['score'] < self.params['minscore'] ):
					badscore += 1
					continue
				if alignnum in self.classlist:
					notstackpartnum = alignpart['stackpart']['particleNumber']
					tiltstackpartdata = apTiltPair.getStackParticleTiltPair(self.params['notstackid'],
						notstackpartnum, self.params['tiltstackid'])
					if tiltstackpartdata is None:
						nopairParticle += 1
					else:
						inplane, mirror = self.getParticleInPlaneRotation(tiltstackpartdata)
						if ( self.params['mirror'] == "all"
						 or (self.params['mirror'] == "no" and mirror is False)
						 or (self.params['mirror'] == "yes" and mirror is True) ):
							emantiltstackpartnum = tiltstackpartdata['particleNumber']-1
							includeParticle.append(emantiltstackpartnum)
							tiltParticlesData.append(tiltstackpartdata)
							if self.params['numpart'] is not None and len(includeParticle) > self.params['numpart']:
								break
						else:
							badmirror += 1
				else:
					excludeParticle += 1
		### end methods

		includeParticle.sort()
		### messages
		if time.time()-t0 > 1.0:
			apDisplay.printMsg("\nSorting time: "+apDisplay.timeString(time.time()-t0))
		apDisplay.printMsg("Keeping "+str(len(includeParticle))+" and excluding \n\t"
			+str(excludeParticle)+" particles with "+str(nopairParticle)+" unpaired particles")
		if badmirror > 0:
			apDisplay.printMsg("Particles with bad mirrors: %d"%(badmirror))
		if badscore > 0:
			apDisplay.printColor("Particles with bad scores: %d"%(badscore), "cyan")
		if len(includeParticle) < 1:
			apDisplay.printError("No particles were kept")
		memdiff = (mem.active()-startmem)/count/1024.0
		if memdiff > 0.1:
			apDisplay.printColor("Memory increase: %.2f MB/part"%(memdiff), "red")

		return includeParticle, tiltParticlesData