def saveResults(jobID, cell, pos, magmom, e0, b, bFit, xc, t, nIter): result = BulkResult( jobID, cell, pos, magmom, e0, b, bFit, xc, t, nIter ) #lattice constants determined downstream, depending on structure' if rank() == 0: insertObject(result) with open("result.json", "w") as f: print >> f, result.toJSON() updateStatus(jobID, 'running', 'completed')
def run_task(self,fw_spec): jobID = fw_spec['jobID'] job = db2SurfaceJob(jobID) resultNames = ['pos','magmom','e0','f0','xcContribs','avgtime','niter'] results = [fw_spec[x][0] for x in resultNames] resultDict = {n:fw_spec[n] for n in resultNames} result = SurfaceResult(*([jobID]+results)) result.addToASEdb(job) insertObject(result) # add result to surface result table updateDB('surfacejob','status','id',jobID,'complete') return FWAction(stored_data= resultDict)
def increaseConvergence(): kohnsham = [x[0] for x in plotQuery(['jobid'], [KOHNSHAM])] new = 0 for k in kohnsham: jobj = db2object(k) jobj.convid += 1 jobj.status = 'initialized' jobj.error, jobj.comments = None, None id, status = insertObject(jobj) if status == 'inserted': new += 1 print 'added %d new jobs' % new
def main(): try: deleteTable('tentative') #WHAT IS GOING ON HERE? except: pass try: createTentativeBulkTable() except: pass domains = [ filteredTrajDomain, filteredXCDomain, filteredPSPDomain, filteredPWDomain, filteredKPTDomain, filteredPreCalcXCDomain, filteredDFTDomain ] combos = product(*domains) ncombo = reduce(mul, [len(x) for x in domains]) for i, c in enumerate(combos): print '%f%' % (i / float(ncombo) * 100) tentativeInput = c[:5] + tuple(defaults) + c[5:] tentativeBulkjob = BulkJob(*tentativeInput) if tentativeBulkjob.xc == 'mBEEF': #defaults slightly different for mBEEF tentativeBulkjob.sigma += 0.1 tentativeBulkjob.sigma -= 0.05 ID, status = insertObject(tentativeBulkjob, tentative=True) print "%d tentative jobs" % countDB('tentative') valid = [ db2BulkJob(x[0], tentative=True) for x in plotQuery('tentative', ['tentative.id'], constraints) ] new = 0 for z in range(len(valid)): ID, status = insertObject(valid[z]) if status == 'inserted': new += 1 print "%d valid jobs, %d are new" % (len(valid), new) deleteTable('tentative')
def main(): dropTable('tentativejob') dropTable('tentativedetails') sqlexecute(jobTable('tentativejob')) sqlexecute('INSERT INTO tentativejob SELECT * FROM job') sqlexecute(tentativedetailstable) for i,sID in enumerate(surfs): p = asedb.get(sID).get('parent') cols = ['xc','pw','kptden','psp','convid','precalc','dftcode'] allInfo = queryManyFromOne(cols,'aseid',p) xc,pw,kptden,psp,convid,precalc,dftcode = allInfo tentativeInput = [None,'surfrelax',sID,None,None,xc,pw,kptden,psp,None,None,convid,precalc,dftcode,None,None,'initialized'] tentativeSurfjob = Job(*tentativeInput) insertObject(tentativeSurfjob,tentative=True) applyDetails(tentative=True) #populate details table so that plotQuery works valid = [db2object(x[0],'tentativejob','job') for x in plotQuery(['jobid'],constraints,tentativetable)] new = 0 print "%d valid jobs, %d are new"%(len(valid),new) question = "Do you want to insert %d new surface jobs?"%new if raw_input(question) in ['y','yes']: for z in range(len(valid)): ID,status = insertObject(valid[z]) if status == 'inserted': new +=1 print "%d jobs are new"%new applyDetails() dropTable('tentativejob') dropTable('tentativedetails')
def main(): try: dropTable('tentativejob') # uncomment if script fails in the middle except: pass sqlexecute(jobTable('tentativejob')) copyTable('job','tentativejob') combos = product(*domains) nTot = reduce(mul,[len(x) for x in [trajDomain,xcDomain,pspDomain,pwDomain,kptDomain,preXcDomain,dftDomain]]) ncombo = reduce(mul,[len(x) for x in domains]) for i,c in enumerate(combos): print '%f %%'%(i/float(ncombo)*100) # jobid jobkind aseid vib neb xc pw kpt psp xtol strain convergence ID precalc dft comm err stat tentativeInput = [None,'bulkrelax',c[0],None,None,c[1],c[2],c[3],c[4],0.005,0.03, 2 if c[1]=='mBEEF' else 1,c[5],c[6],None,None,'initialized'] tentativejob = Job(*tentativeInput) insertObject(tentativejob,tentative=True) nJobsInit,nJobsTent = countDB('job'),countDB('tentativejob') print "%d tentative jobs after filtering %d jobs"%(ncombo,nTot) applyDetails(tentative=True) #populate details table so that plotQuery works valid = [db2object(x[0],'tentativejob') for x in plotQuery(['jobid'],CONSTRAINTS,tentativetable)] new = 0 question = "Do you want to insert %d valid bulk jobs?\n(y/n)--> "%len(valid) if raw_input(question) in ['y','yes']: for z in range(len(valid)): ID,status = insertObject(valid[z]) if status == 'inserted': new +=1 print "%d jobs are new"%new applyDetails() dropTable('tentativejob')
def main(): deleteTable('tentativesurf') for i, sID in enumerate(surfs): p = asedb.get(sID).get('parent') table = ' bulkjob INNER JOIN bulkresult ON bulkresult.jobid=bulkjob.id ' cols = [ 'xc', 'psp', 'pw', 'kptden', 'kpt', 'econv', 'mixing', 'nmix', 'maxstep', 'nbands', 'sigma', 'fmax', 'precalcxc', 'dftcode' ] allInfo = queryManyFromOne(table, cols, 'aseid', p) xc, psp, pw, kptden, kpt, econv, mixing, nmix, maxstep, nbands, sigma, fmax, precalcxc, dftcode = allInfo tentativeInput = [ sID, xc, psp, pw, 10, kptden, None, econv, mixing, nmix, maxstep, nbands, sigma, fmax, precalcxc, dftcode ] tentativeSurfjob = SurfaceJob(*tentativeInput) ID, status = insertObject(tentativeSurfjob, tentative=True) valid = [ db2SurfaceJob(x[0], tentative=True) for x in plotQuery('tentativesurf', ['tentativesurf.id'], constraints) ] # SurfaceJob objects that satisfy constraints tot, new = len(valid), 0 question = '%d job(s) meet these criteria. Do you want to add them to surfacejobs in data.db?\n(y/n)--->' % tot if raw_input(question).lower() in ['y', 'yes']: for z in range(len(valid)): ID, status = insertObject(valid[z]) if status == 'inserted': new += 1 deleteTable('tentativesurf') print '%d jobs considered, %d are new' % (tot, new)
import os import sqlite3 as sqlite from db import insertObject from itertools import product commands = [] sherlockDB = '/scratch/users/ksb/db/data.db' ########################### # Add PSP Paths to Database ########################### # Define domain of psp's to consider for p in pspDomain: insertObject(p) ################################ # Add XC Functionals to Database ################################ # Define domain of XC's to consider PBE = XC('PBE', [[]]) BEEF = XC('BEEF', [[]]) mBEEF = XC('mBEEF',[[]]) xcDomain = [PBE,BEEF,mBEEF] for x in xcDomain: insertObject(x) ################################ # Add Calculators to Database
def run_task(self,fw_spec): jobID = fw_spec['jobID'] job = db2object(jobID) if 'relax' in job.jobkind: pos = fw_spec['pos'][0] cell = fw_spec['cell'][0] if job.jobkind == 'bulkrelax' else job.cellinit() magmom = fw_spec['magmom'][0] db = connect('/scratch/users/ksb/db/ase.db') info = {'name': job.name() ,'emt': 0 # EMT for relaxed structures useless, only relevant for deciding when to relax something ,'relaxed': True # Could always doing this be a problem? ,'comments': 'Generated from #%d'%(job.aseidinitial) ,'parent': job.aseidinitial ,'jobid': job.jobid # Int ###Unchanged Things### ,'kind': job.kind()} # String if job.structure() is not None: info['structure'] = job.structure() if job.vacancies() is not None: info['vacancies'] = job.vacancies() if job.sites() is not None: info['sites'] = job.sites() if job.facet() is not None: info['facet'] = job.facet() if job.xy() is not None: info['xy'] = job.xy() if job.layers() is not None: info['layers'] = job.layers() if job.constrained() is not None: info['constrained'] = job.constrained() if job.symmetric() is not None: info['symmetric'] = job.symmetric() if job.vacuum() is not None: info['vacuum'] = job.vacuum() if job.adsorbates() is not None: info['adsorbates'] = job.adsorbates() optAtoms = Atoms(symbols = job.symbols() ,scaled_positions = pos ,cell = cell ,magmoms = magmom ,constraint = job.constraints() ,tags = job.tags()) aseid = db.write(optAtoms,key_value_pairs=info) else: aseid = None launchdir = fw_spec['_launch_dir'] energy = fw_spec['e0'][0] if 'relax' in job.jobkind else None forces = fw_spec['f0'][0] if 'relax' in job.jobkind else None bulkmodulus = fw_spec['b0'][0] if job.jobkind == 'bulkrelax' else None bfit = fw_spec['quadR2'][0] if job.jobkind == 'bulkrelax' else None xccoeffs = fw_spec['xcContribs'][0] if 'relax' in job.jobkind else None viblist = fw_spec['vibs'][0] if job.jobkind == 'vib' else None dos = fw_spec['dos'][0] if job.jobkind == 'dos' else None barrier = fw_spec['barrier'][0] if job.jobkind == 'neb' else None time = fw_spec['avgtime'][0] niter = fw_spec['niter'][0] if 'relax' in job.jobkind else None result = Result(jobID,launchdir,aseid=aseid,energy=energy,forces=forces ,bulkmodulus=bulkmodulus,bfit=bfit,xccoeffs=xccoeffs,viblist=viblist ,dos=dos,barrier=barrier,time=time,niter=niter) resultDict = {'_launch_dir':launchdir,'aseid':aseid,'energy':energy ,'forces':str(forces),'bulkmodulus':bulkmodulus ,'bfit':bfit,'xccoeffs':xccoeffs,'time':time ,'niter':niter,'viblist':viblist,'barrier':barrier} insertObject(result) # add result to bulkresult table updateDB('status','jobid',jobID,'complete') return FWAction(stored_data= resultDict)
def main(): for conv in convs: insertObject(conv)
def main(): jIDs = [x[0] for x in plotQuery(['jobid'], CONSTRAINTS)] question = "Going to add an %s interstitial to %d bulk objects.\n(y/n)--> " % ( inter, len(jIDs)) if raw_input(question).lower() in ['y', 'yes']: for j in jIDs: aseinitID = query1('aseid', 'jobid', j) aseinit = asedb.get_atoms(id=aseinitID) # Access information about previous Job / Atoms object jobinit = db2object(j) xc, pw, kptden = jobinit.xc, jobinit.pw, jobinit.kptden psp, xtol, strain = jobinit.psp, jobinit.xtol, jobinit.strain precalc, dftcode = jobinit.precalc, jobinit.dftcode nameinit = jobinit.name() structure = jobinit.structure() vacancies = jobinit.vacancies() # Create conventional PyMatGen Object pmg_init = AseAtomsAdaptor.get_structure(aseinit) pmg_init2 = SpacegroupAnalyzer( pmg_init).get_conventional_standard_structure() interstitial = Interstitial( pmg_init2, None, covalent_radii) #accuracy=high breaks... os.system('cls' if os.name == 'nt' else 'clear') for i, site in enumerate(interstitial.enumerate_defectsites()): coordination = int( round(interstitial.get_defectsite_coordination_number(i))) mult = 0 # interstitial.get_defectsite_multiplicity(i) -- broken ??? insert = InsertSitesTransformation([inter], [site.coords], coords_are_cartesian=True) pmg_new = insert.apply_transformation(pmg_init2.copy()) ase_new = AseAtomsAdaptor.get_atoms(pmg_new) ase_new.set_calculator(EMT()) emt = ase_new.get_potential_energy() if coordination == 4: siteName = 'T' elif coordination == 6: siteName = 'O' else: siteName = '%d-fold' % coordination question = ('site: %s\ncoordination: %s\nmultiplicity: %s' % (site.coords, coordination, mult) + '\ninitial ase id: %d \nxc: %s \npw: %d ' % (aseinitID, xc, pw) + '\nkptden: %f \npsp: %s\nxtol: %f\nstrain: %f' % (kptden, psp, xtol, strain) + '\nprecalc: %s \ndftcode: %s' % (precalc, dftcode) + '\n\nDoes this structure look good?\n(y/n)--> ') view(ase_new) if raw_input(question).lower() in ['y', 'yes']: if checkForDuplicates(ase_new, structure, emt): newquestion = 'What structure does this have?\n(leave blank for general triclinic case)\n--> ' structure = raw_input(newquestion) if structure is '': structure = 'triclinic' info = { 'name': nameinit + '_%s-%s' % (inter, siteName), 'emt': emt # EMT for relaxed structures useless, only relevant for deciding when to relax something , 'relaxed': False # Could always doing this be a problem? , 'comments': 'Generated from initializeHydride.py', 'parent': aseinitID, 'kind': 'bulk', 'structure': structure, 'interstitial': siteName } if vacancies is not None: info['vacancies'] = vacancies newaseid = asedb.write(ase_new, key_value_pairs=info) newjob = Job(None, 'bulkrelax', newaseid, None, None, xc, pw, kptden, psp, xtol, strain, 2 if xc == 'mBEEF' else 1, precalc, dftcode, None, None, 'initialized') insertObject(newjob)
0, 0, 0, 0, 0, 0, 12, 13, 11, 15, 16, 15, 16, 11, 12, 13, 14, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8 ]) sgs15 = PSP( 'sgs_15', '/scratch/users/ksb/gpaw/gpaw_sg15/norm_conserving_setups', [ 1, 0, 3, 4, 3, 4, 5, 6, 7, 0, 9, 10, 3, 4, 5, 6, 7, 0, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 12, 5, 6, 7, 0, 9, 10, 11, 12, 13, 14, 15, 16, 15, 16, 19, 12, 13, 14, 15, 6, 7, 0, 9, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 11, 15, 16, 15, 16, 11, 12, 13, 14, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8 ]) pspDomain = [gbrv15pbe, sgs15] for p in pspDomain: insertObject(p) ################################ # Add XC Functionals to Database ################################ # Define domain of XC's to consider PBE = XC('PBE', [[]]) BEEF = XC('BEEF', [[]]) mBEEF = XC('mBEEF', [[]]) xcDomain = [PBE, BEEF, mBEEF] for x in xcDomain: insertObject(x) ################################