def converge(calc): presults = getResults(calc['parent']) if 'settingsmod' not in presults.keys(): presults['settingsmod'] = {} for propset in presults['convergence']: total = len(propset) prop = propset[0] for i in range(1,total): (crit,cond,current,converged) = propset[i] if converged == 1: continue; elif crit == 'K': if 'KPOINTS' not in presults['settingsmod'].keys(): presults['settingsmod']['KPOINTS'] = {} if 'K' not in presults['settingsmod']['KPOINTS'].keys(): presults['settingsmod']['KPOINTS']['K'] = '2 2 2' else: presults['settingsmod']['KPOINTS']['K'] = ' '.join([str(int(x) + 2) for x in presults['settingsmod']['KPOINTS']['K'].split(' ')]) #curkp = [int(x) for x in calc['settings']['KPOINTS']['K'].split(' ')] #curmod = [int(x) for x in presults['settingsmod']['KPOINTS']['K'].split(' ')] # calc['settings']['KPOINTS']['K'] = ' '.join([str(curkp[x] + curmod[x]) for x in range(3)]) break; elif crit == 'ENCUT': if 'INCAR' not in presults['settingsmod'].keys(): presults['settingsmod']['INCAR'] = {} if 'ENCUT' not in presults['settingsmod']['INCAR']: presults['settingsmod']['INCAR']['ENCUT'] = 100 else: presults['settingsmod']['INCAR']['ENCUT'] += 100 # calc['settings']['INCAR']['ENCUT'] = int(calc['settings']['INCAR']['ENCUT']) + presults['settingsmod']['INCAR']['ENCUT'] break; updateResults(presults,calc['parent']) return True
def halveSigmaInherit(calc): presults = getResults(calc['parent']) if 'settingsmod' not in presults.keys(): presults['settingsmod'] = {"INCAR": {}} if 'INCAR' not in presults['settingsmod'].keys(): presults['settingsmod']['INCAR'] = {} elif presults['settingsmod'].get('INCAR').get('SIGMA') != None: presults['settingsmod']['INCAR']['SIGMA'] = float( presults['settingsmod']['INCAR']['SIGMA']) / 2 else: presults['settingsmod']['INCAR']['SIGMA'] = float( calc['settings']['INCAR']['SIGMA']) / 2 updateResults(presults, calc['parent']) return True
def cont(calc): import HighThroughput.manage.calculation as manage baks = 0 bako = 0 bakx = 0 bakt = 0 for file in os.listdir(os.curdir): if os.path.isfile(file) and file[0:10] == 'POSCAR.bak': baks += 1 if os.path.isfile(file) and file[0:10] == 'OUTCAR.bak': bako += 1 if os.path.isfile(file) and file[0:11] == 'XDATCAR.bak': bakx += 1 if os.path.isfile(file) and file[0:11] == 'tempout.bak': bakt += 1 if os.path.isfile('CONTCAR') and os.stat('CONTCAR').st_size > 0: os.rename('POSCAR','POSCAR.bak' + str(baks)) os.rename('CONTCAR','POSCAR') if os.path.isfile('OUTCAR') and os.stat('OUTCAR').st_size > 0: os.rename('OUTCAR','OUTCAR.bak' + str(bako)) if os.path.isfile('XDATCAR') and os.stat('XDATCAR').st_size > 0: os.rename('XDATCAR','XDATCAR.bak' + str(bakx)) if os.path.isfile('tempout') and os.stat('tempout').st_size > 0: os.rename('tempout','tempout.bak' + str(bakt)) psettings = manage.getSettings(calc['parent']) presults = manage.getResults(calc['parent']) if 'continued' not in psettings.keys(): psettings['continued'] = 1 else: psettings['continued'] += 1 if presults.get('settingsmod') != None: if presults['settingsmod'].get('KPOINTS').get('K') != None and calc['settings']['KPOINTS'].get('K') != None: curkp = [int(x) for x in calc['settings']['KPOINTS']['K'].split(' ')] curmod = [int(x) for x in presults['settingsmod']['KPOINTS']['K'].split(' ')] calc['settings']['KPOINTS']['K'] = ' '.join([str(curkp[x] + curmod[x]) for x in range(3)]) if 'ENCUT' in presults['settingsmod'].keys(): calc['settings']['INCAR']['ENCUT'] = int(calc['settings']['INCAR']['ENCUT']) + presults['settingsmod']['INCAR']['ENCUT'] manage.updateSettings(psettings, calc['parent']) manage.updateResults(presults, calc['parent']) return calc
def changeSpinInherit(calc): presults = getResults(calc['parent']) if 'settingsmod' not in presults.keys(): presults['settingsmod'] = {"INCAR": {}} if 'INCAR' not in presults['settingsmod'].keys(): presults['settingsmod']['INCAR'] = {} if presults['settingsmod'].get('INCAR').get('ISPIN') != None: presults['settingsmod']['INCAR']['ISPIN'] = ( int(presults['settingsmod']['INCAR']['ISPIN']) - 2) % 2 + 1 else: presults['settingsmod']['INCAR']['ISPIN'] = ( int(calc['settings']['INCAR']['ISPIN']) - 2) % 2 + 1 print('Setting spin to ' + str(presults['settingsmod']['INCAR']['ISPIN'])) updateResults(presults, calc['parent']) return True
def notConverged(calc): presults = getResults(calc['parent']) error = False if 'convergence' not in presults.keys(): return False else: #"convergence": [["Ehull", ["K", 0.01, [], 0]]] format, could add more than two els to each tuple to determine how to increase the settings and so on new = [] for propset in presults['convergence']: total = len(propset) prop = propset[0] pnew = (prop,) for i in range(1,total): (crit,cond,current,converged) = propset[i] if converged == 1: propset[i][-1] = 1 pnew += (tuple(propset[i]),) continue; print('Checking ' + prop + ' convergence ' + ' with respect to ' + crit + '.') newval = gather({ prop : ''})[prop] current.append(newval) if len(current) == 1: error = True else: delta = np.abs(current[-1] - current[-2]) if delta > cond: print('Not converged. Remaining error of ' + str(delta) + ' on ' + prop + '.') error = True else: print('Property ' + prop + ' is converged up to ' + str(delta) + '.') if crit == 'K': presults['settingsmod']['KPOINTS']['K'] = ' '.join([str(int(x) - 2) for x in presults['settingsmod']['KPOINTS']['K'].split(' ')]) elif crit == 'ENCUT': presults['settingsmod']['INCAR']['ENCUT'] -= 100 converged = 1 pnew += ((crit,cond,current,converged),) new.append(pnew) # presults['convergence'] = json.dumps(new).translate(str.maketrans({"'": r"\'"})) updateResults(presults,calc['parent']) return error
def changeSmearInherit(calc): presults = getResults(calc['parent']) if 'settingsmod' not in presults.keys(): presults['settingsmod'] = {"INCAR": {}} if 'INCAR' not in presults['settingsmod'].keys(): presults['settingsmod']['INCAR'] = {} if presults['settingsmod'].get('INCAR').get('ISMEAR') != None: if presults['settingsmod'].get('INCAR').get('ISMEAR') == 0: presults['settingsmod']['INCAR']['ISMEAR'] = 1 presults['settingsmod']['INCAR']['SIGMA'] = 0.2 elif presults['settingsmod'].get('INCAR').get('ISMEAR') == 1: presults['settingsmod']['INCAR']['ISMEAR'] = 0 presults['settingsmod']['INCAR']['SIGMA'] = 0.05 else: if calc['settings']['INCAR']['ISMEAR'] == 0: presults['settingsmod']['INCAR']['ISMEAR'] = 1 presults['settingsmod']['INCAR']['SIGMA'] = 0.2 elif calc['settings']['INCAR']['ISMEAR'] == 1: presults['settingsmod']['INCAR']['ISMEAR'] = 0 presults['settingsmod']['INCAR']['SIGMA'] = 0.05 updateResults(presults, calc['parent']) return True
# Checkpoint abortion if os.path.isfile('aborted'): print('Calculation aborted') resubmit() sys.exit() # Post-processing (run hooks? or extra functions in VASP module) # Gather results and settings and end calculation # Nowadays I take the energy with sigma -> 0, while in theory without entropy should be nearly the same, # this seems more robust and is also used by the VASP group # Store detected errors if 'error' in locals(): HT.updateResults({'error': error}, cinfo['id']) else: print('Gathering results') results = gather(cinfo['results']) print('Updating results.') # updateresults could be assumed from dictionary keys and automated. HT.updateResults(results, cinfo['id']) print( 'Energy OK. Ending calculation, deleting junk files and fetching results.' ) HT.end(cinfo['id']) #cleanup function # Can change this to a step dictionary os.remove('CHG')
def inherit(calc, path, contcar=True, chgcar=True, wavecar=True, settingsmod=None, grid=False, rescale=1.0): #pstep = int(math.ceil(float(stat)/2.)) -1 if path is None: return True #inputfile = os.path.join(qdir, 'import', str(cfile) + '.vasp') #qdir, 'CALCULATIONS/' + cfile + '/STEP' + str(pstep) if contcar: contcarnames = [ 'CONTCAR', 'POSCAR' + calc['file'] + '.vasp', 'POSCAR' + calc['file'], calc['file'], calc['file'] + '.vasp' ] for name in contcarnames: temp = os.path.join(path, name) if os.path.isfile(temp): inputfile = temp print('Inheriting geometry from ' + inputfile + '.') shutil.copy(inputfile, './POSCAR') rescalePOSCAR('POSCAR', rescale) break if chgcar: chgcarnames = [ 'CHGCAR.gz', 'CHGCAR', 'CHGCAR' + calc['file'] + '.gz', 'CHGCAR' + calc['file'] ] for name in chgcarnames: temp = os.path.join(path, name) if os.path.isfile(temp): density = temp out = 'CHGCAR' if density[-3:] == '.gz': out += '.gz' print('Inheriting charge density from ' + density + '.') shutil.copy(density, out) if calc['settings']['INCAR'].get('ICHARG') is None: calc['settings']['INCAR']['ICHARG'] = 1 break if wavecar: wavecarnames = [ 'WAVECAR.gz', 'WAVECAR', 'WAVECAR' + calc['file'] + '.gz', 'WAVECAR' + calc['file'] ] for name in wavecarnames: temp = os.path.join(path, name) if os.path.isfile(temp): wavecar = temp out = 'WAVECAR' if wavecar[-3:] == '.gz': out += '.gz' print('Inheriting wave functions from ' + wavecar + '.') shutil.copy(wavecar, out) break if grid: outcar = os.path.join(path, 'OUTCAR') ng = execute('grep "dimension x,y,z NGX" ' + outcar + ' | head -n 1').strip().split() calc['settings']['INCAR']['NGX'] = int(ng[4]) calc['settings']['INCAR']['NGY'] = int(ng[7]) calc['settings']['INCAR']['NGZ'] = int(ng[10]) if settingsmod: presults = manage.getResults(calc['parent']) presults['settingsmod'] = settingsmod manage.updateResults(presults, calc['parent']) print('These setting mods are inherited:') print(presults['settingsmod']) if settingsmod.get('KPOINTS') is not None and calc['settings'].get( 'KPOINTS').get('K') is not None: curkp = [ int(x) for x in calc['settings']['KPOINTS']['K'].split(' ') ] curmod = [int(x) for x in settingsmod['KPOINTS']['K'].split(' ')] calc['settings']['KPOINTS']['K'] = ' '.join( [str(curkp[x] + curmod[x]) for x in range(3)]) print(curkp, curmod) print('Calibration update to kpoints executed.') if settingsmod.get('INCAR') is not None: if settingsmod.get('INCAR').get('ENCUT') is not None: calc['settings']['INCAR']['ENCUT'] = int( calc['settings']['INCAR'] ['ENCUT']) + settingsmod['INCAR']['ENCUT'] if settingsmod.get('INCAR').get('SIGMA') is not None: calc['settings']['INCAR']['SIGMA'] = settingsmod['INCAR'][ 'SIGMA'] if settingsmod.get('INCAR').get('ISMEAR') is not None: if int(calc['settings']['INCAR']['ISMEAR']) != -5: calc['settings']['INCAR']['ISMEAR'] = settingsmod['INCAR'][ 'ISMEAR'] if settingsmod.get('INCAR').get('ISPIN') is not None: calc['settings']['INCAR']['ISPIN'] = settingsmod['INCAR'][ 'ISPIN'] #if os.path.isfile('CHGCAR'): # os.rename('CHGCAR','CHGCAR.prec') return calc
def cont(calc): print('DEBUG: continue') baks = 0 bako = 0 bakx = 0 bakt = 0 bakv = 0 for file in os.listdir(os.curdir): if os.path.isfile(file) and file[0:10] == 'POSCAR.bak': baks += 1 if os.path.isfile(file) and file[0:10] == 'OUTCAR.bak': bako += 1 if os.path.isfile(file) and file[0:11] == 'XDATCAR.bak': bakx += 1 if os.path.isfile(file) and file[0:11] == 'tempout.bak': bakt += 1 if os.path.isfile(file) and file[0:11] == 'vasprun.bak': bakv += 1 if os.path.isfile('CONTCAR') and os.stat('CONTCAR').st_size > 0: os.rename('POSCAR', 'POSCAR.bak' + str(baks)) os.rename('CONTCAR', 'POSCAR') if os.path.isfile('OUTCAR') and os.stat('OUTCAR').st_size > 0: os.rename('OUTCAR', 'OUTCAR.bak' + str(bako)) if os.path.isfile('XDATCAR') and os.stat('XDATCAR').st_size > 0: os.rename('XDATCAR', 'XDATCAR.bak' + str(bakx)) if os.path.isfile('tempout') and os.stat('tempout').st_size > 0: os.rename('tempout', 'tempout.bak' + str(bakt)) if os.path.isfile('vasprun.xml') and os.stat('vasprun.xml').st_size > 0: os.rename('vasprun.xml', 'vasprun.bak' + str(bakv)) psettings = manage.getSettings(calc['parent']) presults = manage.getResults(calc['parent']) if 'continued' not in psettings.keys(): psettings['continued'] = 1 else: psettings['continued'] += 1 if presults.get('settingsmod') is not None: if presults['settingsmod'].get('KPOINTS') is not None and calc[ 'settings'].get('KPOINTS') is not None: if presults['settingsmod'].get('KPOINTS').get( 'K') is not None and calc['settings']['KPOINTS'].get( 'K') is not None: curkp = [ int(x) for x in calc['settings']['KPOINTS']['K'].split(' ') ] curmod = [ int(x) for x in presults['settingsmod']['KPOINTS']['K'].split(' ') ] calc['settings']['KPOINTS']['K'] = ' '.join( [str(curkp[x] + curmod[x]) for x in range(3)]) if presults.get('settingsmod').get('INCAR') is not None: if presults.get('settingsmod').get('INCAR').get( 'ENCUT') is not None: calc['settings']['INCAR']['ENCUT'] = int(calc['settings']['INCAR']['ENCUT']) + \ presults['settingsmod']['INCAR']['ENCUT'] if presults.get('settingsmod').get('INCAR').get( 'SIGMA') is not None: calc['settings']['INCAR']['SIGMA'] = presults['settingsmod'][ 'INCAR']['SIGMA'] if presults.get('settingsmod').get('INCAR').get( 'ISMEAR') is not None: if int(calc['settings']['INCAR']['ISMEAR']) != -5: calc['settings']['INCAR']['ISMEAR'] = presults[ 'settingsmod']['INCAR']['ISMEAR'] if presults.get('settingsmod').get('INCAR').get( 'ISPIN') is not None: calc['settings']['INCAR']['ISPIN'] = presults['settingsmod'][ 'INCAR']['ISPIN'] manage.updateSettings(psettings, calc['parent']) manage.updateResults(presults, calc['parent']) return calc
' is not a valid status. Calculation terminated.') sys.exit() #UPDATE POTCAR INFO POTCAR_version = execute('grep -a \'TITEL\' POTCAR | awk \'{ print $4 }\'') settings['POTCAR'] = POTCAR_version.strip().replace('\n', ', ') #END CALCULATION AND FETCH RESULTS energy = execute( 'grep \'energy without entropy\' OUTCAR | tail -1 | awk \'{ print $7 }\'' ) if 'error' in locals(): HT.updateResults({'error': error}, cid) elif energy == '' or not 'energy' in locals(): HT.updateResults({'error': 'Energy missing'}, cid) print('Energy missing! Error...') elif not os.path.isfile('CHGCAR') and not os.path.isfile('CHG'): HT.updateResults({'error': 'CHGCAR and CHG missing. VASP Error?'}, cid) print('CHGCAR/CHG missing. VASP Error?') else: print( 'Energy OK. Ending calculation, deleting junk files and fetching results.' ) print('This is the HT.end cid: ' + str(cid)) ended = 0 tries = 0 while (ended == 0 and tries < 10):
else: print('Not a valid status. Calculation terminated.') sys.exit() #UPDATE POTCAR INFO POTCAR_version = execute('grep -a \'TITEL\' POTCAR | awk \'{ print $4 }\'') settings['POTCAR'] = POTCAR_version.strip().replace('\n',', ') #END CALCULATION AND FETCH RESULTS energy = execute('grep \'energy without entropy\' OUTCAR | tail -1 | awk \'{ print $4 }\'') if 'error' in locals(): HT.updateResults({'error':error}, cid) elif energy=='' or not 'energy' in locals(): HT.updateResults({'error':'Energy missing'}, cid) print('Energy missing! Error...') elif not os.path.isfile('CHGCAR') and not os.path.isfile('CHG'): HT.updateResults({'error':'CHGCAR and CHG missing. VASP Error?'}, cid) print('CHGCAR/CHG missing. VASP Error?') else: print('Energy OK. Ending calculation, deleting junk files and fetching results.') HT.end(cid) if status<19: os.remove('CHG') results = HT.getResults(cid)
#HTML.setMLPriority(newq, 2, ['mass','Ecoh','EN','IP'], N_init) # #for i in range(N_init): # calc = HTc.fetchgetstart(newq) # HTc.updateResults({target: rdict[calc['file']]}) # # if rdict[calc['file']] < limit: # stable += 1 # print('Found ' + str(stable) + ' stable materials (' + str(int(round(100*stable/tstable,0))) + ' %) in ' + str(i+1) + ' samples.') # HTc.end() for i in range(nsample): if i % batch_size == 0: HTML.updateMLPriority( newq, stat=2, modelClass='sklearn.gaussian_process.GaussianProcessRegressor', target='Ehull', features=['mass', 'Ecoh', 'EN', 'IP'], maxParallel=1) calc = HTc.fetchgetstart(newq) print(calc) HTc.updateResults({target: rdict[calc['file']]}) if rdict[calc['file']] < limit: stable += 1 print('Found ' + str(stable) + ' stable materials (' + str(int(round(100 * stable / tstable, 0))) + ' %) in ' + str(i + 1) + ' samples.') HTc.end()