예제 #1
0
	def run_task(self,fw_spec): 
		job,params,optAtoms = initialize(fw_spec)
		optCell   		= optAtoms.get_cell()
		strains   		= np.linspace(1-job.strain(),1+job.strain(),9)		
		vol,eng 		= [],[]
		
		for i, strain in enumerate(strains):
			atoms = optAtoms.copy()
			atoms.set_cell(optCell*strain,scale_atoms=True)
			optimizePos(atoms,job.calc(),job.fmax())
			volume,energy = atoms.get_volume(),atoms.get_potential_energy()
			vol.append(c.deepcopy(volume));eng.append(c.deepcopy(energy))
		aHat,quadR2 = quadFit(np.array(c.deepcopy(vol)),np.array(c.deepcopy(eng)))

		try:		
			eos = aseeos.EquationOfState(vol,eng)
			v0, e0, b = eos.fit()
			eos.plot(filename='bulk-eos.png',show=False)
			b0= b/ase.units.kJ*1e24 									#GPa: use this value if EOS doesn't fail
			with open('bulk-eos.png', 'rb') as f: img = base64.b64encode(f.read())

		except ValueError:  								# too bad of a fit for ASE to handle
			b0 = aHat*2*vol[4]*160.2						# units: eV/A^6 * A^3 * 1, where 1 === 160.2 GPa*A^3/eV
			img = None


		resultDict 	= misc.mergeDicts([params,trajDetails(optAtoms)
									,{'bulkmod':b0,'bfit':quadR2,'bulkmodimg_base64':img,'voleng_json':json.dumps(zip(vol,eng))}])

		with open('result.json', 'w') as outfile:   json.dumps(resultDict, outfile)
		return fireworks.core.firework.FWAction( stored_data=resultDict)
예제 #2
0
	def run_task(self,fw_spec): 
		job,params,initatoms = initialize(fw_spec)
		print 'initialized'
		if os.path.exists('qn.traj'): 
			if os.stat('qn.traj').st_size > 100: 	
				initatoms = ase.io.read('qn.traj')
				print 'reading from qn.traj'
			else: 									
				os.remove('qn.traj')
				print 'removing empty qn.traj'
		if os.path.exists('qn.log') and os.stat('qn.log').st_size < 100: 
			os.remove('qn.log')
			print 'removing empty qn.log'

		optimizePos(initatoms,job.calc(),job.fmax())
		print 'optimized positions'
		ase.io.write('final.traj',initatoms)
		
		niter = getRelaxIter(job.dftcode())
		print 'got nIter'
		resultDict 	= misc.mergeDicts([params,trajDetails(ase.io.read('final.traj'))
									,{'raw_energy':initatoms.get_potential_energy()
									,'forces_pckl':pickle.dumps(initatoms.get_forces())
									,'niter':niter} ])
		print 'made result dict'
		with open('result.json', 'w') as outfile:   json.dumps(resultDict, outfile)
		return fireworks.core.firework.FWAction(stored_data=resultDict)
예제 #3
0
	def run_task(self,fw_spec):
		job,params,atoms = initialize(fw_spec)
		neb = None
		raise NotImplementedError
		resultDict 	= misc.mergeDicts([params,	{}])
		with open('result.json', 'w') as outfile:   json.dumps(resultDict, outfile)
		return fireworks.core.firework.FWAction(stored_data=resultDict)
예제 #4
0
def readJobs():
	"""Looks for jobs, adds new ones to job table"""
	fwpathsher,fwpathsunc = '/scratch/users/ksb/fireworks/jobs/','/nfs/slac/g/suncatfs/ksb/fireworks/jobs/'
	existingJobs = [str(x[0]) for x in dbase.sqlexecute('SELECT launchdir from job')]
	ls = subprocess.Popen(['ssh','*****@*****.**', 'cd %s;ls'%fwpathsunc], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	suncout, err 	=  ls.communicate()

	suncatJobs 		= [fwpathsunc + d for d in suncout.split('\n') 		if fwpathsunc+d not in existingJobs and len(d)>1]
	sherlockJobs 	= [fwpathsher + x for x in os.listdir(fwpathsher) 	if fwpathsher+x not in existingJobs]
	tot = len(suncatJobs + sherlockJobs)
	for i,d in enumerate(suncatJobs + sherlockJobs):
		print d
		print '%d/%d'%(i+1,tot) ; sys.stdout.write("\033[F") # Cursor up one line
		fwid = getFWID(d)
		deleted = int(os.path.exists(d+'/deleted'))
		inputDict = misc.mergeDicts([{'fwid':fwid,'launchdir':d,'deleted':deleted},getInitData(fwid)])

		command = "INSERT into job ({0}) values ({1})".format(	','.join(inputDict.keys())
															,','.join(['?']*len(inputDict)))
		try: dbase.sqlexecute(command,inputDict.values())
		except: #remove 'bad keys'
			for k in ['relax','vacancies_json']:
				try: del inputDict[k]
				except KeyError: pass
			command = "INSERT into job ({0}) values ({1})".format(	','.join(inputDict.keys()),','.join(['?']*len(inputDict)))
			dbase.sqlexecute(command,inputDict.values())
예제 #5
0
 def generalSummary(self):
     """summarize some of the invariant methods of jobs in a dictionary"""
     general = {
         'params_json': json.dumps(self.params),
         'natoms': self.natoms(),
         'symbols_pckl': self.symbols_pckl(),
         'symbols_str': self.symbols_str(),
         'comp_pckl': self.comp_pckl(),
         'comp_str': self.comp_str(),
         'species_pckl': self.species_pckl(),
         'species_str': self.species_str(),
         'numbers_pckl': self.numbers_pckl(),
         'numbers_str': self.numbers_str(),
         'metalstoich_pckl': self.metalstoich_pckl(),
         'metalstoich_str': self.metalstoich_str(),
         'metalspecies_pckl': self.metalspecies_pckl(),
         'metalspecies_str': self.metalspecies_str(),
         'metalcomp_pckl': self.metalcomp_pckl(),
         'metalcomp_str': self.metalcomp_str()
         #,'cellinit_pckl':	self.cellinit_pckl()
         #,'cellinit_str':	self.cellinit_str()
         #,'posinit_pckl':	self.posinit_pckl()
         #,'posinit_str':		self.posinit_str()
         #,'magmomsinitpckl':	self.magmomsinit_pckl()
         #,'magmomsinitstr':	self.magmomsinit_str()
         #,'tags_pckl':		self.tags_pckl()
         #,'tags_str':		self.tags_str()
         #,'constraints_pckl':self.constraints_pckl()
         #,'constraints_str':	self.constraints_str()
         ,
         'paramsinit_pckl': self.paramsinit_pckl()
         #,'paramsinit_str':	self.paramsinit_str()
         ,
         'kpt_pckl': self.kpt_pckl(),
         'kpt_str': self.kpt_str(),
         'emt': self.emt(),
         'emtsym': self.emtsym(),
         'spinpol': self.spinpol(),
         'dipole': self.dipole(),
         'calclabel': self.calcLabel(),
         'strjob': str(self)
     }
     return misc.mergeDicts(
         [self.params, general,
          self.jobSummary(),
          self.kindSummary()])
예제 #6
0
	def run_task(self,fw_spec): 
		from gpaw        import restart
		from gpaw.xc.bee import BEEFEnsemble
		job,params,atoms = initialize(fw_spec)
		atoms.set_calculator(job.PBEcalc())
		atoms.get_potential_energy()
		atoms.calc.write('inp.gpw', mode='all') 

		atoms,calc = restart('inp.gpw', setups='sg15', xc='mBEEF', convergence={'energy': 5e-4}, txt='mbeef.txt')
		atoms.get_potential_energy()
		beef 		= BEEFEnsemble(calc)
		xcContribs 	= beef.mbeef_exchange_energy_contribs()
		ase.io.write('final.traj',atoms)
		resultDict 	= misc.mergeDicts([params,trajDetails(ase.io.read('final.traj'))
									,{'xcContribs': pickle.dumps(xcContribs)}])

		with open('result.json', 'w') as outfile:   json.dumps(resultDict, outfile)
		return fireworks.core.firework.FWAction( stored_data=resultDict)
예제 #7
0
	def run_task(self,fw_spec):
		global nIter
		job,params,initatoms = initialize(fw_spec)
		nIter,energies,lparams = 0,[],[]
		print 'initialized'
		if os.path.exists('lastguess.log'):
			with open('lastguess.log','r') as f: iGuess = pickle.loads(f.read())
			print 'read lastguess ',iGuess
		else: 
			iGuess = job.iGuess()
			print 'using initial guess ',iGuess
		
		for d in ['qn.traj','qn.log']:
			if os.path.exists(d): 
				os.remove(d)
				print 'removed existing file ',d
		
		def getBulkEnergy(latticeParams):
			"""For a given set of bravais lattice parameters, optimize atomic coordinates and return minimum energy"""
			global nIter
			nIter += 1
			with open('lastguess.log','w') as f: f.write(pickle.dumps(latticeParams))
			atoms = job.fromParams(latticeParams)
			optimizePos(atoms,job.calc(),job.fmax())
			energy = atoms.get_potential_energy()
			energies.append(energy);lparams.append(latticeParams)
			ase.io.write('out.traj',atoms)
			return energy
		
		optimizedLatticeParams 	= opt.fmin(getBulkEnergy,iGuess,ftol=1,xtol=job.xtol())
		print 'optimized lattice params',optimizedLatticeParams
		optAtoms 				= ase.io.read('out.traj')
		
		resultDict 	= misc.mergeDicts([params,trajDetails(optAtoms)
									,{'raw_energy': 		optAtoms.get_potential_energy()
										,'forces_pckl':		pickle.dumps(optAtoms.get_forces())
										,'niter': 			nIter
										,'latticeopt_pckl':	pickle.dumps(zip(energies,lparams))}])	
		
		with open('result.json', 'w') as outfile: json.dumps(resultDict, outfile)
		return fireworks.core.firework.FWAction(stored_data=resultDict)
예제 #8
0
def molecule(molname=None):
    readJobs.readJobs()
    for name, m in gas.aseMolDict.items():
        if molname is None or name == molname:
            mol = pickle.dumps(m)
            variableParams = {
                'pw': 500,
                'xc': 'RPBE',
                'psp': 'gbrv15pbe',
                'fmax': 0.05,
                'dftcode': 'quantumespresso'
            }

            defaultParams = {
                'jobkind': 'relax',
                'inittraj_pckl': mol,
                'comments': 'created by gendata.molecule()',
                'trajcomments': '',
                'name': name,
                'relaxed': 0,
                'kind': 'molecule',
                'kptden':
                1  #doesn't matter, will be ignored. Use 1 to be safe.
                ,
                'dwrat': 10,
                'econv': 5e-4,
                'mixing': 0.1,
                'nmix': 10,
                'maxstep': 500,
                'nbands': -12,
                'sigma': 0.1
            }
            p = misc.mergeDicts([variableParams, defaultParams])
            if molname is None or ask(
                    'Do you want to run a gas phase calculation with these params?\n%s'
                    % (abbreviateDict(p))):
                j = jobs.assignJob(p)
                if j.new():
                    j.check()
                    j.submit()
    misc.launch()
예제 #9
0
	def run_task(self,fw_spec):

		job,params,atoms = initialize(fw_spec)
		
		if not os.path.exists('intermediate.traj'):
			atoms.set_calculator(job.vccalc())
			energy = atoms.get_potential_energy() #trigger espresso to be launched
			ase.io.write('intermediate.traj',atoms.calc.get_final_structure())

		atoms = ase.io.read('intermediate.traj')
		atoms.set_calculator(job.vccalc())
		energy = atoms.get_potential_energy() #trigger espresso to be launched
		ase.io.write('final.traj',atoms.calc.get_final_structure())
		e0,f0 	= atoms.get_potential_energy(),atoms.get_forces()
		atoms 	= ase.io.read('final.traj')

		resultDict 	= misc.mergeDicts([params,trajDetails(atoms),
									{'raw_energy': 	e0
									,'forces_pckl': pickle.dumps(f0)}])

		with open('result.json', 'w') as outfile:   json.dumps(resultDict, outfile)

		return fireworks.core.firework.FWAction(stored_data=resultDict)
예제 #10
0
	def run_task(self,fw_spec): 
		"""ONLY WORKS FOR QUANTUM ESPRESSO"""
		from ase.vibrations       import Vibrations
		job,params,atoms = initialize(fw_spec)
		
		prev = g.glob('*.pckl') #delete incomplete pckls - facilitating restarted jobs
		for p in prev:
			if os.stat(p).st_size < 100: os.remove(p)
		
		atoms.set_calculator(job.vibCalc())
		vib = Vibrations(atoms,delta=job.delta(),indices=job.vibids())


		vib.run(); vib.write_jmol()
		vib.summary(log='vibrations.txt')
		with open('vibrations.txt','r') as f: vibsummary = f.read()

		vib_energies,vib_frequencies = vib.get_energies(),vib.get_frequencies()
		resultDict 	= misc.mergeDicts([params,	{'vibfreqs_pckl': pickle.dumps(vib_frequencies)
												,'vibsummary':vibsummary
												,'vibengs_pckl':pickle.dumps(vib_energies)}])

		with open('result.json', 'w') as outfile: json.dumps(resultDict, outfile)
		return fireworks.core.firework.FWAction(stored_data=resultDict)