for cls in clslist:
            ## create SPIDER batch file and run coran
            spidercmd = emancoran.runCoranClass(params, cls)

    print "classification complete"
    print "Determining best class averages"
    #Determine best averages
    #Create list of cc values
    for cls in range(0, len(clslist)):
        clsdir = clslist[cls].split('.')[0] + '.dir'
        # if no particles in class, create empty class averages
        if not os.path.exists(
                os.path.join(clslist[cls].split('.')[0] + '.dir',
                             'aligned.spi')):
            # blank projection image
            apEMAN.writeBlankImage('goodavgs.hed', params['boxsize'], -1)
            # blank class average
            apEMAN.writeBlankImage('goodavgs.hed', params['boxsize'], -1)
            # blank "good" average
            #apEMAN.writeBlankImage('allavgs.hed',params['boxsize'],-1)
            if params['eotest'] is True:
                apEMAN.writeBlankImage('goodavgs.even.hed', params['boxsize'],
                                       -1)
                apEMAN.writeBlankImage('goodavgs.odd.hed', params['boxsize'],
                                       -1)
            continue

        avgname = os.path.join(clsdir, 'classes_avg.spi')
        averages = EMAN.readImages(avgname, -1, -1, 0)
        e = projections[cls].getEuler()
        cclist = []
예제 #2
0
def runCoranClass(params,cls):
	print "processing class",cls

	#set up cls dir
	clsdir=cls.split('.')[0]+'.dir'
	os.mkdir(clsdir)

	clscmd='clstoaligned.py -c ' + cls
	## if multiprocessor, don't run clstoaligned yet
	if params['proc'] == 1:
		#make aligned stack
		proc = subprocess.Popen(clscmd, shell=True)
		proc.wait()

	corancmd=clscmd+'\n'

	coranbatch='coranfor'+cls.split('.')[0]+'.bat'

	#make spider batch
	params['nptcls'] = apEMAN.getNPtcls(cls)

	# if no particles, create an empty class average
	if params['nptcls'] == 0:
		# don't run clscmd, just make directory and empty average
		apEMAN.writeBlankImage(os.path.join(clsdir,'classes_avg.spi'),params['boxsize'],0,'spider')
		print "WARNING!! no particles in class"
		return

	# if only 3 particles or less, turn particles into the class averages
	elif params['nptcls'] < 4:
		#this is an ugly hack, just average the particles together, no ref-free
		# don't use mpi, just make directory with clscmd and average particles
		proc = subprocess.Popen(clscmd, shell=True)
		proc.wait()
		avgcmd=("proc2d %s %s average" % (os.path.join(clsdir,'aligned.spi'),os.path.join(clsdir,'classes_avg.spi')))
		proc = subprocess.Popen(avgcmd, shell=True)
		proc.wait()
		dummyclsdir=os.path.join(clsdir,'classes')
		os.mkdir(dummyclsdir)
		dummyfilename='clhc_cls0001.spi'
		dummyfile=open(os.path.join(dummyclsdir,dummyfilename),'w')
		dummyfile.write(';bat/spi\n')
		for ptcl in range(0,params['nptcls']):
			dummyfile.write('%d 1 %d\n' % (ptcl,ptcl+1))
		dummyfile.close()
		print "WARNING!! not enough particles in class for subclassification"
		return

	# otherwise, run coran
	else:
		makeSpiderCoranBatch(params,coranbatch,clsdir)
		### this is how we should do this
		#mySpider = spyder.SpiderSession(logo=False, nproc=1)
		#mySpider.toSpiderQuiet("@%s\n" % coranbatch.split('.')[0])
		spidercmd = ("cd %s\n" % clsdir)
		
		if params['hp'] is not None:
			spidercmd+=("proc2d aligned.spi alignedhp.spi spiderswap apix=%s hp=%s\n" % (params['apix'],params['hp']))
		spidercmd+= ("spider bat/spi @%s\n" % coranbatch.split('.')[0])
		## if multiprocessor, don't run spider yet
		if params['proc'] == 1:
			proc = subprocess.Popen(spidercmd, shell=True)
			proc.wait()
		corancmd+=spidercmd
		return corancmd
                                        print "ERROR!!! "+clsdir+"/"+spijobfile+" does not exist"
	else:
		for cls in clslist:
		## create SPIDER batch file and run coran	
			spidercmd = emancoran.runCoranClass(params,cls)

	print "classification complete"
	print "Determining best class averages"
	#Determine best averages
	#Create list of cc values	
	for cls in range(0,len(clslist)):
		clsdir=clslist[cls].split('.')[0]+'.dir'
		# if no particles in class, create empty class averages
		if not os.path.exists(os.path.join(clslist[cls].split('.')[0]+'.dir','aligned.spi')):
			# blank projection image
			apEMAN.writeBlankImage('goodavgs.hed',params['boxsize'],-1)
			# blank class average
			apEMAN.writeBlankImage('goodavgs.hed',params['boxsize'],-1)
			# blank "good" average
			#apEMAN.writeBlankImage('allavgs.hed',params['boxsize'],-1)
			if params['eotest'] is True:
				apEMAN.writeBlankImage('goodavgs.even.hed',params['boxsize'],-1)
				apEMAN.writeBlankImage('goodavgs.odd.hed',params['boxsize'],-1)
			continue
			
		avgname=os.path.join(clsdir,'classes_avg.spi')
		averages=EMAN.readImages(avgname,-1,-1,0)
		e=projections[cls].getEuler()
		cclist=[]
		cutofflist=[]
		projections[cls].setNImg(-1)
def runCoranClass(params, cls):
    print "processing class", cls

    #set up cls dir
    clsdir = cls.split('.')[0] + '.dir'
    os.mkdir(clsdir)

    clscmd = 'clstoaligned.py -c ' + cls
    ## if multiprocessor, don't run clstoaligned yet
    if params['proc'] == 1:
        #make aligned stack
        proc = subprocess.Popen(clscmd, shell=True)
        proc.wait()

    corancmd = clscmd + '\n'

    coranbatch = 'coranfor' + cls.split('.')[0] + '.bat'

    #make spider batch
    params['nptcls'] = apEMAN.getNPtcls(cls)

    # if no particles, create an empty class average
    if params['nptcls'] == 0:
        # don't run clscmd, just make directory and empty average
        apEMAN.writeBlankImage(os.path.join(clsdir, 'classes_avg.spi'),
                               params['boxsize'], 0, 'spider')
        print "WARNING!! no particles in class"
        return

    # if only 3 particles or less, turn particles into the class averages
    elif params['nptcls'] < 4:
        #this is an ugly hack, just average the particles together, no ref-free
        # don't use mpi, just make directory with clscmd and average particles
        proc = subprocess.Popen(clscmd, shell=True)
        proc.wait()
        avgcmd = ("proc2d %s %s average" % (os.path.join(
            clsdir, 'aligned.spi'), os.path.join(clsdir, 'classes_avg.spi')))
        proc = subprocess.Popen(avgcmd, shell=True)
        proc.wait()
        dummyclsdir = os.path.join(clsdir, 'classes')
        os.mkdir(dummyclsdir)
        dummyfilename = 'clhc_cls0001.spi'
        dummyfile = open(os.path.join(dummyclsdir, dummyfilename), 'w')
        dummyfile.write(';bat/spi\n')
        for ptcl in range(0, params['nptcls']):
            dummyfile.write('%d 1 %d\n' % (ptcl, ptcl + 1))
        dummyfile.close()
        print "WARNING!! not enough particles in class for subclassification"
        return

    # otherwise, run coran
    else:
        makeSpiderCoranBatch(params, coranbatch, clsdir)
        ### this is how we should do this
        #mySpider = spyder.SpiderSession(logo=False, nproc=1)
        #mySpider.toSpiderQuiet("@%s\n" % coranbatch.split('.')[0])
        spidercmd = ("cd %s\n" % clsdir)

        if params['hp'] is not None:
            spidercmd += (
                "proc2d aligned.spi alignedhp.spi spiderswap apix=%s hp=%s\n" %
                (params['apix'], params['hp']))
        spidercmd += ("spider bat/spi @%s\n" % coranbatch.split('.')[0])
        ## if multiprocessor, don't run spider yet
        if params['proc'] == 1:
            proc = subprocess.Popen(spidercmd, shell=True)
            proc.wait()
        corancmd += spidercmd
        return corancmd