def errorsReport(self, datafile=None, predictFile=None): from aBuild.database.dataset import dataset from numpy.linalg import norm from numpy import average, array dataSet = dataset(datafile, self.species, lFormat='mlp') predictSet = dataset(predictFile, self.species, lFormat='mlp') diffsEnergy = [] diffsForces = [] for i in dataSet.crystals: for j in predictSet.crystals: if j.title.strip() == i.title.strip(): print("Found match") diffsEnergy.append(i.results["energyF"] - j.results["energyF"]) diffsForces.append( average( norm(array(i.results["forces"]) - array(j.results["forces"]), axis=1))) from matplotlib import pyplot pyplot.subplot(121) pyplot.hist(diffsEnergy, bins=30) pyplot.subplot(122) pyplot.hist(diffsForces, bins=30) pyplot.savefig('errorPlot.png')
def gatherResults(self, file=None, folder=None): from os import path from glob import glob from aBuild.database.dataset import dataset if file is not None: dataSet = dataset( file, self.species, lFormat='mlp', ) dataSet.writeReport('mlp') else: trainingRoot = path.join(self.root, 'training_set') with chdir(trainingRoot): enumdirs = glob("E.*") activedirs = glob("A.*") pures = glob("pure*") dirs = [ path.join(trainingRoot, x) for x in enumdirs + activedirs + pures ] trainingSet = dataset(dirs, self.species, calculator=self.calculator["active"].upper()) trainingSet.writeReport('vasp')
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 augmentTraining(self): from os import path from aBuild.database.dataset import dataset newTraining = path.join(self.root, 'fitting', 'mtp', 'new_training.cfg') trainingRoot = path.join(self.root, 'training_set') dSet = dataset(newTraining, self.species, lFormat='mlpselect') dSet.buildFolders(trainingRoot, self.calculator, foldername='A')
def generateConvexHull(self, file='dataReport_VASP.txt', plotAll=True): from os import path from aBuild.database.dataset import dataset dataFile = path.join(self.root, file) if not path.isfile(dataFile): msg.fatal('data file does not exist') data = dataset(dataFile, self.species) data.generateConvexHullPlot(plotAll=plotAll)
def setup_training_set(self, runGetKpoints=True): from os import path from aBuild.database.dataset import dataset self.dataset = "trainingset" trainingRoot = path.join(self.root, 'training_set') trainingSet = dataset(self.enumDicts, self.species) trainingSet.buildFolders(trainingRoot, self.calculator, runGetKpoints=runGetKpoints)
def setup_train(self, trainingRoot, species): from os import path, remove from glob import glob from aBuild.calculators.vasp import VASP from aBuild.fitting.mtp import MTP from aBuild.jobs import Job from aBuild.database.dataset import dataset # 1. Pull all VASP data and compile into file train.cfg # 2. Copy/Build a blank potential file called pot.mtp # 3. Build a submission script with chdir(trainingRoot): enumdirs = glob("E.*") # activedirs = [] activedirs = glob("A.*") #puredirs = glob("pure*") dirs = [path.join(trainingRoot, x) for x in enumdirs + activedirs] if dirs != []: print('Building dataset') trainingSet = dataset(dirs, species, calculator='VASP') ##### if path.isfile(path.join(self.root, 'train.cfg')): msg.info( 'train.cfg file found! Deleting and building from scratch.') remove(path.join(self.root, 'train.cfg')) with open(path.join(self.root, 'train.cfg'), 'a+') as f: for crystal in trainingSet.crystals: if crystal.results["fEnth"] < 100 and crystal.minDist > 1.5: print("Building: {}".format(crystal.title)) f.writelines('\n'.join(crystal.lines('mtptrain'))) else: print( "Not adding structure {}. Seems like an extreme one.". format(crystal.title)) print("Energy: {}".format(crystal.results["energyF"])) print("MinDist: {}".format(crystal.minDist)) self.write_blank_pot(len(species)) self.calc_grade() self.train(self.settings["execution"])
for index in range(self.nEnums): enumController = Enumerate(self.enumDicts[index]) enumController.buildInputFile(False) enumController.enumerate(False) # BUild VASP folders so I can generate training data def setup_training_set(self,runGetKpoints = True): from os import path from aBuild.database.dataset import dataset self.dataset = "trainingset" trainingRoot = path.join(self.root,'training_set') <<<<<<< HEAD trainingSet = dataset(self.enumDicts,self.species,restrictions = 'AFM' in self.calculator[self.calculator["active"]]) ======= ############################################################################3 self.special_settings["eps"] = 1e-3 #epsilon for checking if atoms are in same layer ############################################################################ trainingSet = dataset(self.enumDicts,self.species,special_settings = self.special_settings)######### ADDED SPECIAL_SETTINGS >>>>>>> 03893ba98eddd6991de841e54e88613fa8b4165d trainingSet.buildFolders(trainingRoot,self.calculator,runGetKpoints = runGetKpoints) <<<<<<< HEAD def setupHandler(self,model,tag,start = 1,end = None): ======= def setupHandler(self,model,tag,start = 1): >>>>>>> 03893ba98eddd6991de841e54e88613fa8b4165d