def select_add( self, executeParams, jobfile='jobscript_select.sh', exeCommand='mlp_release_version select-add pot.mtp train.cfg candidate.cfg new_training.cfg', buildJob=True): from subprocess import Popen from os import waitpid, rename, path from aBuild.jobs import Job # baseCommand = 'mlp select-add pot.mtp train.cfg candidate.cfg new_training.cfg' if buildJob: # Select does not yet run in parallel. mlpCommand = exeCommand executeParams["ntasks"] = 1 executeParams["time"] = 12 executeParams["job_name"] mljob = Job(executeParams, self.root, mlpCommand) with chdir(self.root): print('Building job file') mljob.write_jobfile(jobfile) else: with chdir(self.root): child = Popen(mlpCommand, shell=True, executable="/bin/bash") waitpid(child.pid, 0)
def setup_training_input(self): from os import path from glob import glob from aBuild.calculators.vasp import VASP #from aBuild.database.crystal import CrystalsList from aBuild.fitting.mtp import MTP from aBuild.jobs import Job from aBuild.database.dataset import dataset 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] # dirs = enumdirs + activedirs print('Building dataset') trainingSet = dataset(dirs, self.species) fittingRoot = path.join(self.root, 'fitting', 'mtp') thisMTP = MTP(fittingRoot, settings=self.fitting) thisMTP.write_blank_pot(self.knary) with open(path.join(fittingRoot, 'train.cfg'), 'a+') as f: for crystal in trainingSet.crystals: f.writelines('\n'.join(crystal.lines('mtptrain'))) mlpCommand = 'mlp train pot.mtp train.cfg\n' mljob = Job(self.calculator["execution"], path.join(self.root, "fitting", "mtp"), mlpCommand) with chdir(path.join(self.root, "fitting/mtp")): print('Building job file') mljob.write_jobfile()
def train(self,executeParams, potential="pot.mtp", tSet="train.cfg",buildJob = True): from aBuild.jobs import Job from os import path if buildJob: if executeParams["ntasks"] > 1: mlpCommand = 'mpirun -n ' + str(executeParams["ntasks"]) + ' mlp train {} {}'.format(potential,tSet) else: mlpCommand = 'mlp train {} {}'.format(potential,tSet) mljob = Job(executeParams,self.root,mlpCommand) with chdir(self.root): print('Building job file') mljob.write_jobfile('jobscript_train.sh') else: with chdir(self.root): child=Popen(mlpCommand, shell=True, executable="/bin/bash") waitpid(child.pid, 0)
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 select_add(self,executeParams,buildJob = True): from subprocess import Popen from os import waitpid, rename,path from aBuild.jobs import Job baseCommand = 'mlp select-add pot.mtp train.cfg candidate.cfg new_training.cfg' if buildJob: if executeParams["ntasks"] > 1: mlpCommand = 'mpirun -n ' + str(executeParams["ntasks"]) + ' ' + baseCommand else: mlpCommand = baseCommand mljob = Job(executeParams,self.root,mlpCommand) with chdir(self.root): print('Building job file') mljob.write_jobfile('jobscript_select.sh') else: with chdir(self.root): child=Popen(mlpCommand, shell=True, executable="/bin/bash") waitpid(child.pid, 0)
def relax(self,executeParams,buildJob = True): from aBuild.jobs import Job from subprocess import Popen from os import waitpid, rename,path baseCommand = 'mlp relax relax.ini --cfg-filename=to_relax.cfg --save-relaxed=relaxed.cfg --save-unrelaxed=unrelaxed.cfg --log=relax_log.txt' if buildJob: if executeParams["ntasks"] > 1: mlpCommand = 'mpirun -n ' + str(executeParams["ntasks"]) + ' ' + baseCommand else: mlpCommand = baseCommand mljob = Job(executeParams,self.root,mlpCommand) with chdir(self.root): print('Building job file') mljob.write_jobfile('jobscript_relax.sh') else: with chdir(self.root): child=Popen(mlpCommand, shell=True, executable="/bin/bash") waitpid(child.pid, 0)
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 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')
<<<<<<< HEAD # Change the directory and build the folder print("Building folder for structure: {}".format(crystal.title) ) ======= # Change the directory and build the folder print("Building folder {} for structure: {}".format(configIndex,crystal.title) ) >>>>>>> 03893ba98eddd6991de841e54e88613fa8b4165d with chdir(runpath): lookupBuild[calculator["active"]](thisCalc) configIndex += 1 # Build the submission script 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('jobscript_vasp.sh') def build_relax_select_input(self): from os import remove,path