def init_enum(self,enumdicts,systemSpecies,runGetKpoints = True): from aBuild.enumeration import Enumerate from aBuild.calculators.vasp import VASP from aBuild.database.crystal import Crystal from aBuild.jobs import Job from random import randrange from aBuild.utility import chdir from numpy import array from os import remove, path # from crystal import Crystal from os import path import os # if not path.isdir(self.root): # os.mkdir(self.root) print("Building database from enumerations") self.crystals = [] # configIndex = startPoint = self._starting_point #########################my changes#########################3 iterations = 0 ######################################################## for eDict in enumdicts: enumController = Enumerate(eDict) if enumController.nEnumStructs == 0: msg.warn('There are no enumerated structures for lattice type {}. Not building any VASP folders for them.'.format(self.enumDicts[index]["name"])) enumController.buildInputFile() enumController.enumerate()
def randomDisplace(self): from numpy.random import randn msg.warn("Warning: You are about to move basis atoms around") for ibv, bv in enumerate(self.Bv_cartesian): disp = 0.05 * randn(3) self.basis[ibv] = bv + disp self.coordsys = 'C'
def status(self): from os import path from time import time from aBuild.utility import grep import os ctime = time() with chdir(self.directory): outcar = self._check_file_exists('OUTCAR') incar = self._check_file_exists('INCAR') kpoints = self._check_file_exists('KPOINTS') potcar = self._check_file_exists('POTCAR') poscar = self._check_file_exists('POSCAR') if not (incar and kpoints and potcar and poscar): return 'not setup' if incar: relax = grep('INCAR', 'IBRION') if '-1' not in relax or relax is []: static = True else: static = False else: msg.warn("No INCAR found. That seems odd..") outcarfinishtags = self._check_tag_exists( 'OUTCAR', '------------------------ aborting loop because EDIFF is reached ----------------------------------------\n' ) or self._check_tag_exists('OUTCAR', ' writing wavefunctions') if outcar: time = path.getmtime('OUTCAR') sgrcon = grep('OUTCAR', 'SGRCON') if (ctime - time) < 60: folderstat = 'running' else: if static and self._check_tag_exists( 'OUTCAR', '------------------------ aborting loop because EDIFF is reached ----------------------------------------\n' ): print('Tripped 1') folderstat = 'done' elif self._check_tag_exists('OUTCAR', ' writing wavefunctions'): print('Tripped 2') folderstat = 'done' else: folderstat = 'running' else: folderstat = 'not started' # if outcar: #if 'OUTCAR' in files: print("Folder Stat {}".format(folderstat)) return folderstat
def _processConcRestrictions(self, concs): knarylookup = {2: "binary", 3: "ternary", 4: "quaternary"} if concs is not None: self.conc_res = True self.concRestrictions = concs if len(self.concRestrictions) > self.knary - 1: msg.warn("You have specified concentration restrictions on {} atom types.\ For a {} system, you only need to supply restrictions on {} atom types. (<order of system> - 1) "\ .format(len(self.concRestrictions),knarylookup[self.knary],self.knary - 1 ) ) else: self.conc_res = False
def init_enum(enumdicts, systemSpecies): from aBuild.enumeration import Enumerate from aBuild.calculators.vasp import VASP from aBuild.database.crystal import Crystal from aBuild.jobs import Job from random import randrange from aBuild.utility import chdir from numpy import array from os import remove, path # from crystal import Crystal from os import path import os print("Building database from enumerations") crystals = [] # configIndex = startPoint = self._starting_point for eDict in enumdicts: enumController = Enumerate(eDict) if enumController.nEnumStructs == 0: msg.warn( 'There are no enumerated structures for lattice type {}. Not building any VASP folders for them.' .format(eDict["lattice"])) enumController.buildInputFile() enumController.enumerate() # Loop to generate random structures for a given lattice type for i in range(eDict["nconfigs"]): print('Adding {} structure # {} to database'.format( eDict["lattice"], rStruct)) with open('structNums', 'a+') as f: f.write(eDict["name"] + ' ' + str(i) + '\n') enumController.generatePOSCAR(i) poscarpath = path.join( enumController.root, "poscar.{}.{}".format(eDict["name"], rStruct)) thisCrystal = Crystal.from_poscar( poscarpath, systemSpecies ) #title = ' '.join([self.enumDicts[index]["lattice"]," str #: {}"]).format(rStruct) crystals.append(thisCrystal) delpath = path.join( enumController.root, "poscar.{}.{}".format(eDict["name"], rStruct)) remove(delpath) return dataset(crystals)
def init_enum(self, enumdicts, systemSpecies, runGetKpoints=True): from aBuild.enumeration import Enumerate from aBuild.calculators.vasp import VASP from aBuild.database.crystal import Crystal from aBuild.jobs import Job from random import randrange from aBuild.utility import chdir # from crystal import Crystal from os import path import os # if not path.isdir(self.root): # os.mkdir(self.root) print("Building database from enumerations") self.crystals = [] # configIndex = startPoint = self._starting_point for eDict in enumdicts: enumController = Enumerate(eDict) if enumController.nEnumStructs == 0: msg.warn( 'There are no enumerated structures for lattice type {}. Not building any VASP folders for them.' .format(self.enumDicts[index]["lattice"])) enumController.buildInputFile() enumController.enumerate() # Loop to generate random structures for a given lattice type for i in range(eDict["nconfigs"]): rStruct = randrange(1, enumController.nEnumStructs) print('Adding {} structure # {} to database'.format( eDict["lattice"], rStruct)) with open('structNums', 'a+') as f: f.write(eDict["lattice"] + ' ' + str(rStruct) + '\n') #print("Building VASP folder for {} structure #: {}".format(eDict["lattice"],rStruct)) enumController.generatePOSCAR(rStruct) poscarpath = path.join( enumController.root, "poscar.{}.{}".format(eDict["lattice"], rStruct)) thisCrystal = Crystal( poscarpath, systemSpecies=systemSpecies ) #title = ' '.join([self.enumDicts[index]["lattice"]," str #: {}"]).format(rStruct) self.crystals.append(thisCrystal)
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')
def _init_mlp(datafile, species): from aBuild.database.crystal import Crystal import os from os import path from aBuild.calculators.vasp import VASP from aBuild.calculators.aflow import AFLOW with open(datafile, 'r') as f: lines = f.readlines() crystals = [] nCrystals = 0 # Get information for pures so I can calculate formation energies root = os.getcwd() trainingRoot = path.join(root, 'training_set') puredirs = [path.join(trainingRoot, 'pure' + x) for x in species] pures = [ AFLOW.from_path(x, species, filesuffix='.relax2.xz') for x in puredirs ] for pure in pures: pure.read_results() # End reading pures count = 0 for index, line in enumerate(lines): if 'BEGIN' in line: indexStart = index elif 'END' in line: count += 1 indexEnd = index structlines = lines[indexStart:indexEnd + 1] if count % 1000 == 0: print("Processed {} crystals".format(nCrystals)) nCrystals += 1 thisCrystal = Crystal.from_lines(structlines, species, 'mlp') # Only add the crystal if mindist is reasonable if thisCrystal.minDist > 1.5: # Only calculate formation energy if I have information about the pures if True not in [ x.crystal is None or x.crystal.results is None or thisCrystal.results["energyF"] is None for x in pures ]: 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) ]) # Otherwise, set it to a ridiculus number else: thisCrystal.results["fEnth"] = 1000 thisCrystal.results["distToHull"] = None # Save the crystal for later. crystals.append(thisCrystal) else: msg.warn( "Mindist is pretty small for this one, so I'm not gonna add it" ) return dataset(crystals)
def init_enum(self, enumdicts, systemSpecies, runGetKpoints=True): from aBuild.enumeration import Enumerate from aBuild.calculators.vasp import VASP from aBuild.database.crystal import Crystal from aBuild.jobs import Job from random import randrange from aBuild.utility import chdir from numpy import array from os import remove, path # from crystal import Crystal from os import path import os # if not path.isdir(self.root): # os.mkdir(self.root) print("Building database from enumerations") self.crystals = [] # configIndex = startPoint = self._starting_point for eDict in enumdicts: enumController = Enumerate(eDict) if enumController.nEnumStructs == 0: msg.warn( 'There are no enumerated structures for lattice type {}. Not building any VASP folders for them.' .format(self.enumDicts[index]["lattice"])) enumController.buildInputFile() enumController.enumerate() # Loop to generate random structures for a given lattice type for i in range(eDict["nconfigs"]): rStruct = 16254 #randrange(1,enumController.nEnumStructs) print('Adding {} structure # {} to database'.format( eDict["lattice"], rStruct)) with open('structNums', 'a+') as f: f.write(eDict["name"] + ' ' + str(rStruct) + '\n') #print("Building VASP folder for {} structure #: {}".format(eDict["lattice"],rStruct)) enumController.generatePOSCAR(rStruct) poscarpath = path.join( enumController.root, "poscar.{}.{}".format(eDict["name"], rStruct)) thisCrystal = Crystal( poscarpath, systemSpecies=systemSpecies ) #title = ' '.join([self.enumDicts[index]["lattice"]," str #: {}"]).format(rStruct) if self.restrictions is None: self.crystals.append(thisCrystal) elif thisCrystal.getAFMPlanes([1, 0, 0]): print('parent is AFM compatible') self.crystals.append(thisCrystal) import sys sys.exit() else: superCrystal = thisCrystal.superPeriodics(2) if superCrystal != []: print('super periodic structures is AFM compatible') print(superCrystal.minDist, 'minDist') print(superCrystal.basis, ' basis') print(array(superCrystal.Bv_direct), 'direct') print(array(superCrystal.Bv_cartesian), 'cartesian') self.crystals.append(superCrystal) import sys sys.exit() else: print("Can't find an AFM compatible structure") import sys sys.exit() # self.crystals.append(thisCrystal) delpath = path.join( enumController.root, "poscar.{}.{}".format(eDict["name"], rStruct)) remove(delpath)