def getBestCtfValue(self, imgdata, msg=False): if self.params['ctfrunid'] is not None: return ctfdb.getCtfValueForCtfRunId(imgdata, self.params['ctfrunid'], msg=msg) return ctfdb.getBestCtfValue(imgdata, sortType=self.params['ctfsorttype'], method=self.params['ctfmethod'], msg=msg)
def start(self): ### default parameters starfile = self.params['starfile'] images = self.params['images'] dbnum = self.params['dbnum'] ctfrunid = self.params['ctfrunid'] stackid = self.params['stackid'] voltage = self.params['voltage'] cs = self.params['cs'] wgh = self.params['wgh'] ### particles, angles appiondata.sinedon.setConfig('appiondata', db="ap%d" % dbnum) particledata = apStack.getStackParticlesFromId(stackid) ### write Relion starfile header sf = open(starfile, "w") sf.write("data_images\n") sf.write("loop_\n") sf.write("_rlnImageName\n") sf.write("_rlnMicrographName\n") sf.write("_rlnDefocusU\n") sf.write("_rlnDefocusV\n") sf.write("_rlnDefocusAngle\n") sf.write("_rlnVoltage\n") sf.write("_rlnSphericalAberration\n") sf.write("_rlnAmplitudeContrast\n") ### write info to starfile olddx = 0 micn = 0 oldimgid = None for i in range(len(particledata)): if i % 1000 == 0: print "done with %d particles" % i ### CTF info image = particledata[i]['particle']['image'] imgid = image.dbid try: ctf = ctfdb.getCtfValueForCtfRunId(image, ctfrunid, msg=False) dx = ctf['defocus1'] * 10e9 dy = ctf['defocus2'] * 10e9 astig = ctf['angle_astigmatism'] except: ctf = None # print "didn't find CTF values for image ", image.dbid if ctf is None: if oldimgid != imgid: print "particle %d: " % i, "getting best value for image: %d" % imgid ctf = ctfdb.getBestCtfValueForImage(image, msg=False, method='ctffind') dx = ctf[0]['defocus1'] * 10e9 dy = ctf[0]['defocus2'] * 10e9 astig = ctf[0]['angle_astigmatism'] oldctf = ctf oldimgid = imgid else: try: ctf = oldctf dx = oldctf[0]['defocus1'] * 10e9 dy = oldctf[0]['defocus2'] * 10e9 astig = oldctf[0]['angle_astigmatism'] except: apDisplay.printError("no CTF information for image") if dx != olddx: micn += 1 olddx = dx ### write input Relion parameters sf.write("%06d@%s%10d%12.3f%12.3f%12.3f%8.3f%8.3f%8.3f\n" % (i + 1, images, micn, dx, dy, astig, voltage, cs, wgh)) sf.close()
def start(self): ### default parameters starfile = self.params['starfile'] images = self.params['images'] dbnum = self.params['dbnum'] ctfrunid = self.params['ctfrunid'] stackid = self.params['stackid'] voltage = self.params['voltage'] cs = self.params['cs'] wgh = self.params['wgh'] ### particles, angles appiondata.sinedon.setConfig('appiondata', db="ap%d" % dbnum) particledata = apStack.getStackParticlesFromId(stackid) ### write Relion starfile header sf = open(starfile, "w") sf.write("data_images\n") sf.write("loop_\n") sf.write("_rlnImageName\n") sf.write("_rlnMicrographName\n") sf.write("_rlnDefocusU\n") sf.write("_rlnDefocusV\n") sf.write("_rlnDefocusAngle\n") sf.write("_rlnVoltage\n") sf.write("_rlnSphericalAberration\n") sf.write("_rlnAmplitudeContrast\n") ### write info to starfile olddx = 0 micn = 0 oldimgid = None for i in range(len(particledata)): if i % 1000 == 0: print "done with %d particles" % i ### CTF info image = particledata[i]['particle']['image'] imgid = image.dbid try: ctf = ctfdb.getCtfValueForCtfRunId(image, ctfrunid, msg=False) dx = ctf['defocus1'] * 10e9 dy = ctf['defocus2'] * 10e9 astig = ctf['angle_astigmatism'] except: ctf = None # print "didn't find CTF values for image ", image.dbid if ctf is None: if oldimgid != imgid: print "particle %d: " % i, "getting best value for image: %d" % imgid ctf = ctfdb.getBestCtfValueForImage(image, msg=False, method='ctffind') dx = ctf[0]['defocus1'] * 10e9 dy = ctf[0]['defocus2'] * 10e9 astig = ctf[0]['angle_astigmatism'] oldctf = ctf oldimgid = imgid else: try: ctf = oldctf dx = oldctf[0]['defocus1'] * 10e9 dy = oldctf[0]['defocus2'] * 10e9 astig = oldctf[0]['angle_astigmatism'] except: apDisplay.printError("no CTF information for image") if dx != olddx: micn += 1 olddx = dx ### write input Relion parameters sf.write("%06d@%s%10d%12.3f%12.3f%12.3f%8.3f%8.3f%8.3f\n" % (i+1, images, micn, dx, dy, astig, voltage, cs, wgh) ) sf.close()