def statusReport(self): from os import path from glob import glob from aBuild.calculators.vasp import VASP trainingRoot = path.join(self.root, 'training_set') with chdir(trainingRoot): enumdirs = glob("E.*") activedirs = glob("A.*") dirs = [path.join(trainingRoot, x) for x in enumdirs + activedirs] stat = { 'done': [], 'running': [], 'not started': [], 'error': [], 'not setup': [] } for dir in dirs: thisVASP = VASP(dir, self.species) stat[thisVASP.status()].append(dir.split('/')[-1]) # msg.info("Status of directory {} is {} ".format(dir,thisVASP.status())) msg.info('Done') msg.info(' '.join(stat['done'])) msg.info('Running') msg.info(' '.join(stat['running'])) msg.info('Not Started') msg.info(' '.join(stat['not started'])) msg.info('Not Setup') msg.info(' '.join(stat['not setup'])) msg.info('Errors') msg.info(' '.join(stat['error']))
def init_paths(self, paths, systemSpecies): from aBuild.database.crystal import Crystal from aBuild.calculators.vasp import VASP self.crystals = [] for dirpath in paths: calc = VASP(dirpath, systemSpecies) calc.read_results() if calc.crystal.results is not None: self.crystals.append(calc.crystal)
def statusReport(self): from os import path from glob import glob from aBuild.calculators.vasp import VASP trainingRoot = path.join(self.root, 'training_set') with chdir(trainingRoot): enumdirs = glob("E.*") activedirs = glob("A.*") dirs = [path.join(trainingRoot, x) for x in enumdirs + activedirs] stat = { 'done': [], 'running': [], 'not started': [], 'too long': [], 'not setup': [], 'warning': [], 'idk': [], 'unconverged': [], 'sgrcon': [], 'error': [] } for dir in dirs: thisVASP = VASP(dir, systemSpecies=self.species) stat[thisVASP.status()].append(dir.split('/')[-1]) # msg.info("Status of directory {} is {} ".format(dir,thisVASP.status())) msg.info('Done (' + str(len(stat['done'])) + ')') msg.info(' '.join(stat['done'])) msg.info('Running (' + str(len(stat['running'])) + ')') msg.info(' '.join(stat['running'])) msg.info('Not Started (' + str(len(stat['not started'])) + ')') msg.info(' '.join(stat['not started'])) msg.info('Not Setup (' + str(len(stat['not setup'])) + ')') msg.info(' '.join(stat['not setup'])) msg.info('Too Long (' + str(len(stat['too long'])) + ') (last write was > 1 hr ago) ') msg.info(' '.join(stat['too long'])) msg.info('Warnings (' + str(len(stat['warning'])) + ')') msg.info(' '.join(stat['warning'])) msg.info('Not sure (' + str(len(stat['idk'])) + ') (Found finish tags but couldn' 't find final energy. It' 's probably in the process of finishing.)') msg.info(' '.join(stat['idk'])) msg.info('Unconverged (' + str(len(stat['unconverged'])) + ')') msg.info(' '.join(stat['unconverged'])) msg.info('SGRCON error (' + str(len(stat['sgrcon'])) + ')') msg.info(' '.join(stat['sgrcon'])) msg.info('Unknown error (' + str(len(stat['error'])) + ')') msg.info(' '.join(stat['error']))
def buildFolders(self,buildpath,calculator,runGetKpoints = True,foldername = 'E'): from os import path from aBuild.calculators.vasp import VASP from aBuild.calculators.lammps import LAMMPS from aBuild.calculators.espresso import ESPRESSO from aBuild.jobs import Job import os print("Building folders in {}".format(buildpath)) if not path.isdir(buildpath): os.mkdir(buildpath) print('Made path:',buildpath) configIndex = startPoint = self.starting_point(buildpath) lookupCalc = {'vasp': lambda specs: VASP(specs), 'qe': lambda specs: ESPRESSO(specs,self.species), 'lammps': lambda specs: LAMMPS(specs,self.species)} lookupSpecs = {'vasp': lambda crystal: {"incar":calculator["vasp"]["incar"],"kpoints":calculator["vasp"]["kpoints"], 'potcar':calculator["vasp"]["potcars"],"crystal":crystal}, 'qe': lambda crystal : {"crystal":crystal, "pseudopotentials":calculator["qe"]["pseudopotentials"]}, 'lammps': lambda crystal: {"crystal":crystal, "potential":calculator["lammps"]["potential"]} } lookupBuild = {'vasp': lambda obj: obj.buildFolder(runGetKPoints = runGetKpoints), 'qe': lambda obj:obj.buildFolder(), 'lammps': lambda obj: obj.buildFolder()} for crystal in self.crystals:
def buildFolders(self, buildpath, calculator, runGetKpoints=True, foldername='E'): from os import path from aBuild.calculators.vasp import VASP from aBuild.jobs import Job import os print("Building folders in {}".format(buildpath)) if not path.isdir(buildpath): os.mkdir(buildpath) print('Made path:', buildpath) configIndex = startPoint = self.starting_point(buildpath) for crystal in self.crystals: vaspspecs = { "incar": calculator["incar"], "kpoints": calculator["kpoints"], 'potcar': calculator["potcars"], "crystal": crystal } thisVASP = VASP(vaspspecs, self.species) runpath = path.join(buildpath, foldername + ".{}".format(configIndex)) if not path.isdir(runpath): os.mkdir(runpath) else: msg.fatal( "I'm gonna write over top of a current directory. ({}) I think I'll stop instead." .format(runpath)) print("Building folder for structure: {}".format(crystal.title)) with chdir(runpath): thisVASP.buildFolder(runGetKPoints=runGetKpoints) configIndex += 1 exdir = path.join(buildpath, 'E.') mljob = Job(calculator["execution"], exdir, calculator["execution"]["exec_path"], arrayStart=startPoint, arrayEnd=configIndex - 1) with chdir(buildpath): print('Building job file') mljob.write_jobfile()
def _init_mlp(self, datafile): from aBuild.database.crystal import Crystal import os from os import path from aBuild.calculators.vasp import VASP with open(datafile, 'r') as f: lines = f.readlines() self.crystals = [] nCrystals = 0 # Get information for pures so I can calculate formation energies root = os.getcwd() pures = [ VASP(path.join(root, 'training_set', 'pure' + x), systemSpecies=self.species) for x in self.species ] puresDict = {} for ispec, spec in enumerate(self.species): pures[ispec].read_results() # puresDict[spec] = pures[ispec].crystal.results["energypatom"] print(pures, 'pures') for index, line in enumerate(lines): if 'BEGIN' in line: indexStart = index elif 'END' in line: indexEnd = index structlines = lines[indexStart:indexEnd + 1] print("Processed {} crystals".format(nCrystals)) nCrystals += 1 thisCrystal = Crystal(structlines, self.species, lFormat='mlp') if thisCrystal.results == None: if thisCrystal.minDist > 1.5: self.crystals.append(thisCrystal) else: thisCrystal.results["fEnth"] = thisCrystal.results[ "energyF"] / thisCrystal.nAtoms - sum([ pures[i].crystal.results["energyF"] / pures[i].crystal.nAtoms * thisCrystal.concentrations[i] for i in range(thisCrystal.nTypes) ]) if thisCrystal.results[ "energyF"] < 100 and thisCrystal.minDist > 1.5: self.crystals.append(thisCrystal) else: print( "Not adding structure {}. Seems like an extreme one." .format(thisCrystal.title)) print("Energy: {}".format( thisCrystal.results["energyF"])) print("MinDist: {}".format(thisCrystal.minDist))
def from_paths(paths, systemSpecies, calculator='VASP'): from aBuild.database.crystal import Crystal from aBuild.calculators.vasp import VASP from aBuild.calculators.aflow import AFLOW from aBuild.calculators.lammps import LAMMPS from os import path # Get pures information puredirs = [ path.join(path.split(paths[0])[0], 'pure' + x) for x in systemSpecies ] pures = [ AFLOW.from_path(x, systemSpecies, filesuffix='.relax2.xz') for x in puredirs ] for pure in pures: pure.read_results() crystals = [] for dirpath in paths: if calculator == 'VASP' or calculator == 'AFLOW': if path.isfile(path.join(dirpath, 'aflow.in')): print("Initializing AFLOW object from path: {}".format( dirpath)) calc = AFLOW.from_path(dirpath, systemSpecies) calc.read_results(pures=pures) if calc.crystal.results is not None: print("Formation energy is {}.".format( calc.crystal.results["fEnth"])) else: calc = VASP.from_path(dirpath, systemSpecies) calc.read_results(pures=pures) if calc.crystal is not None and calc.crystal.results is not None: print("Adding Crystal") crystals.append(calc.crystal) species = crystals[0].systemSpecies return dataset(crystals)
def init_paths(self, paths, systemSpecies): from aBuild.database.crystal import Crystal from aBuild.calculators.vasp import VASP from aBuild.calculators.lammps import LAMMPS from os import path self.crystals = [] for dirpath in paths: print("Initializing from path: {}".format(dirpath)) if self.calculator == 'VASP': calc = VASP(dirpath, systemSpecies=systemSpecies) calc.read_results() #Added for LAMMPS compatibility if self.calculator == 'LAMMPS': calc = LAMMPS(dirpath, systemSpecies) calc.read_results() if calc.crystal.results is not None: self.crystals.append(calc.crystal)
def statusReport(self): from os import path, listdir, remove from glob import glob from aBuild.calculators.vasp import VASP from aBuild.calculators.aflow import AFLOW from numpy import argsort trainingRoot = path.join(self.root, 'validation_set') with chdir(trainingRoot): enumdirs = glob("E.*") activedirs = glob("A.*") delFiles = glob("status.*") for i in delFiles: remove(i) dirs = [path.join(trainingRoot, x) for x in enumdirs + activedirs] nDirs = len(dirs) numdirs = [int(y.split('.')[-1]) for y in dirs] count = 0 for idx, directory in enumerate([dirs[x] for x in argsort(numdirs)]): if count % 100 == 0: print("checking directories {} - {}".format( dirs[argsort(numdirs)[count + 1]], dirs[argsort(numdirs)[count + 100 if count + 100 < nDirs else nDirs - 1]])) count += 1 if 'aflow.in' in listdir(directory): thisAFLOW = AFLOW.from_path(directory, self.species) thisStat = thisAFLOW.status() else: thisVASP = VASP.from_path(directory, self.species) thisStat = thisVASP.status() if thisStat == 'errors' or thisStat == 'running': msg.info("Directory {} is {} ".format(directory, thisStat)) with open('status.' + thisStat, 'a') as f: f.write(directory.split('/')[-1] + ' ')
def buildFolders(self, buildpath, calculator, runGetKpoints=True, foldername='A', onlyCloseToHull=False, distToHull=5e-3): from os import path from aBuild.calculators.vasp import VASP from aBuild.calculators.aflow import AFLOW from aBuild.calculators.lammps import LAMMPS from aBuild.calculators.espresso import ESPRESSO from aBuild.jobs import Job from math import floor import os print("Building folders in {}".format(buildpath)) if not path.isdir(buildpath): os.mkdir(buildpath) print('Made path:', buildpath) configIndex = startPoint = self.starting_point(buildpath) lookupCalc = { 'aflow': lambda specs: AFLOW.from_dictionary(specs), 'vasp': lambda specs: VASP.from_dictionary(specs), 'qe': lambda specs: ESPRESSO(specs, self.species), 'lammps': lambda specs: LAMMPS(specs, self.species) } lookupBuild = { 'aflow': lambda obj: obj.buildFolder(), 'vasp': lambda obj: obj.buildFolder(runGetKPoints=runGetKpoints), 'qe': lambda obj: obj.buildFolder(), 'lammps': lambda obj: obj.buildFolder() } for crystal in self.crystals: if onlyCloseToHull: if crystal.results["distToHull"] is None: msg.fatal( "You asked only for cystals that are close to the hull, but I don't have a value for that distance." ) elif crystal.results["distToHull"] > distToHull: continue print("Building crystal {}".format(crystal.title)) runpath = path.join(buildpath, foldername + ".{}".format(configIndex)) #Augment the existing dictionary in preparation for sending it in calculator[calculator["active"]]["crystal"] = crystal calculator[calculator["active"]]["directory"] = runpath # Initialize the calculation object print('initializing VASP object') thisCalc = lookupCalc[calculator["active"]]( calculator[calculator["active"]]) # Build the path if not path.isdir(runpath): os.mkdir(runpath) else: msg.fatal( "I'm gonna write over top of a current directory. ({}) I think I'll stop instead." .format(runpath)) # Change the directory and build the folder print("Building folder for structure: {}".format(crystal.title)) with chdir(runpath): success = lookupBuild[calculator["active"]](thisCalc) if not success: if calculator["active"] == 'aflow': retryCalc = lookupCalc["vasp"](calculator['vasp']) with chdir(runpath): success = lookupBuild["vasp"](retryCalc) if not success: msg.fatal( "I tried building an aflow dir and it failed, then I tried building a VASP dir and it failed too. I give up" ) else: msg.warn( "VASP(??) directory build failed, and I'm not sure why" ) configIndex += 1 # Build the submission script exdir = path.join(buildpath, 'A.') if calculator['active'] == 'aflow': calculator["execution"]["exec_path"] = "aflow --run" elif calculator["active"] == 'vasp': calculator["execution"]["exec_path"] = "vasp6_serial" startAdder = int(floor(startPoint / 1000)) * 1000 endAdder = int(floor((configIndex - 1) / 1000)) * 1000 if startAdder == endAdder: # Don't need to submit two jobs in this case. Just one, but we might have to add an offset if the numbers are too high. msg.info("Building one job submission file") calculator["execution"]["offset"] = startAdder mljob = Job(calculator["execution"], exdir, calculator["execution"]["exec_path"], arrayStart=startPoint - startAdder, arrayEnd=configIndex - 1 - endAdder) with chdir(buildpath): print('Building job file') mljob.write_jobfile('jobscript_vasp.sh') else: # We're going to have to submit two jobs to span the whole job array. msg.info("Building two job submission files") #First job.. calculator["execution"]["offset"] = startAdder mljob = Job(calculator["execution"], exdir, calculator["execution"]["exec_path"], arrayStart=startPoint - startAdder, arrayEnd=999) with chdir(buildpath): print('Building job file') mljob.write_jobfile('jobscript_vasp_1.sh') calculator["execution"]["offset"] = endAdder - 1 mljob = Job(calculator["execution"], exdir, calculator["execution"]["exec_path"], arrayStart=1, arrayEnd=configIndex - endAdder) with chdir(buildpath): print('Building job file') mljob.write_jobfile('jobscript_vasp_2.sh')
from os import path from glob import glob from aBuild.calculators.vasp import VASP trainingRoot = path.join(self.root, 'training_set') with chdir(trainingRoot): enumdirs = glob("E.*") activedirs = glob("A.*") dirs = [path.join(trainingRoot,x) for x in enumdirs + activedirs] <<<<<<< HEAD stat = {'done':[],'running':[], 'not started': [], 'too long':[], 'not setup':[],'warning':[],'idk':[],'unconverged':[],'sgrcon':[],'error':[]} ======= stat = {'done':[],'running':[], 'not started': [], 'too long':[], 'not setup':[],'warning':[],'idk':[],'unconverged':[]} >>>>>>> 03893ba98eddd6991de841e54e88613fa8b4165d for dir in dirs: thisVASP = VASP(dir,systemSpecies = self.species) stat[thisVASP.status()].append(dir.split('/')[-1]) # msg.info("Status of directory {} is {} ".format(dir,thisVASP.status())) msg.info('Done (' + str(len(stat['done'])) + ')') msg.info(' '.join(stat['done'])) msg.info('Running (' + str(len(stat['running'])) + ')') msg.info(' '.join(stat['running'])) msg.info('Not Started (' + str(len(stat['not started'])) + ')') msg.info(' '.join(stat['not started'])) msg.info('Not Setup (' + str(len(stat['not setup'])) + ')') msg.info(' '.join(stat['not setup'])) msg.info('Too Long (' + str(len(stat['too long'])) + ') (last write was > 1 hr ago) ') msg.info(' '.join(stat['too long'])) msg.info('Warnings (' + str(len(stat['warning'])) + ')') msg.info(' '.join(stat['warning'])) msg.info('Not sure (' + str(len(stat['idk'])) + ') (Found finish tags but couldn''t find final energy. It''s probably in the process of finishing.)')
def buildFolders(self, buildpath, calculator, runGetKpoints=True, foldername='E'): from os import path from aBuild.calculators.vasp import VASP from aBuild.calculators.lammps import LAMMPS from aBuild.calculators.espresso import ESPRESSO from aBuild.jobs import Job import os print("Building folders in {}".format(buildpath)) if not path.isdir(buildpath): os.mkdir(buildpath) print('Made path:', buildpath) configIndex = startPoint = self.starting_point(buildpath) lookupCalc = { 'vasp': lambda specs: VASP(specs), 'qe': lambda specs: ESPRESSO(specs, self.species), 'lammps': lambda specs: LAMMPS(specs, self.species) } lookupSpecs = { 'vasp': lambda crystal: { "incar": calculator["vasp"]["incar"], "kpoints": calculator["vasp"]["kpoints"], 'potcar': calculator["vasp"]["potcars"], "crystal": crystal }, 'qe': lambda crystal: { "crystal": crystal, "pseudopotentials": calculator["qe"]["pseudopotentials"] }, 'lammps': lambda crystal: { "crystal": crystal, "potential": calculator["lammps"]["potential"] } } lookupBuild = { 'vasp': lambda obj: obj.buildFolder(runGetKPoints=runGetKpoints), 'qe': lambda obj: obj.buildFolder(), 'lammps': lambda obj: obj.buildFolder() } for crystal in self.crystals: print("Building crystal {}".format(crystal.title)) #Augment the existing dictionary in preparation for sending it in calculator[calculator["active"]]["crystal"] = crystal calculator[calculator["active"]]["species"] = self.species # Initialize the calculation object print(calculator[calculator["active"]], 'check here') thisCalc = lookupCalc[calculator["active"]]( calculator[calculator["active"]]) # thisCalc = lookupCalc[calculator["active"]](lookupSpecs[calculator["active"]](crystal)) if 'AFM' in calculator[calculator[ "active"]] and thisCalc.crystal.AFMPlanes == None: msg.info( "Skipping this structure because I can't find the AFM planes" ) continue # Build the path runpath = path.join(buildpath, foldername + ".{}".format(configIndex)) if not path.isdir(runpath): os.mkdir(runpath) else: msg.fatal( "I'm gonna write over top of a current directory. ({}) I think I'll stop instead." .format(runpath)) # Change the directory and build the folder print("Building folder for structure: {}".format(crystal.title)) with chdir(runpath): lookupBuild[calculator["active"]](thisCalc) configIndex += 1 # Build the submission script exdir = path.join(buildpath, 'A.') mljob = Job(calculator["execution"], exdir, calculator["execution"]["exec_path"], arrayStart=startPoint, arrayEnd=configIndex - 1) with chdir(buildpath): print('Building job file') mljob.write_jobfile('jobscript_vasp.sh')