def setup_relax_select_input(self): from os import remove, path from aBuild.enumeration import Enumerate from aBuild.database.crystal import Crystal from aBuild.fitting.mtp import MTP from aBuild.utility import unpackProtos, getAllPerms, getProtoPaths from glob import glob self.dataset = "gss" # rename(path.join(self.root,'fitting/mtp') fittingRoot = path.join(self.root, 'fitting', 'mtp') for ilat in range(self.nEnums): lat = self.enumDicts[ilat]["lattice"] if lat == 'protos': structures = getProtoPaths() # subdivide = [structures[x:x+100] for x in range() ] for struct in structures: print("Proto structure:", struct) scrambleOrder = getAllPerms(self.knary, justCyclic='uniqueUnaries' in struct) for scramble in scrambleOrder: thisCrystal = Crystal(struct, self.species) #print("Atom counts before scramble {}".format(thisCrystal.atom_counts)) thisCrystal.scrambleAtoms(scramble) #print("Atom counts after scramble {}".format(thisCrystal.atom_counts)) with open(path.join(fittingRoot, 'to-relax.cfg'), 'a+') as f: f.writelines('\n'.join( thisCrystal.lines('mtprelax'))) else: enumLattice = Enumerate(self.enumDicts[ilat]) for struct in range(1, enumLattice.nConfigs + 1): print("Lattice", lat, "structure:", struct) enumLattice.generatePOSCAR(struct) thisCrystal = Crystal( path.join(enumLattice.root, "poscar.{}.{}".format(lat, struct)), self.species) with open(path.join(fittingRoot, 'to-relax.cfg'), 'a+') as f: f.writelines('\n'.join(thisCrystal.lines('mtprelax'))) delpath = path.join(enumLattice.root, "poscar.{}.{}".format(lat, struct)) remove(delpath) fittingRoot = path.join(self.root, 'fitting', 'mtp') thisMTP = MTP(fittingRoot, settings=self.fitting) thisMTP.calc_grade() thisMTP.write_relaxin()
def build_relax_select_input(self): from os import remove, path from aBuild.enumeration import Enumerate from aBuild.database.crystal import Crystal from aBuild.fitting.mtp import MTP from aBuild.utility import unpackProtos, getAllPerms from glob import glob fittingRoot = path.join(self.root, 'fitting', 'mtp') for ilat in range(self.nEnums): lat = self.enumDicts[ilat]["lattice"] enumLattice = Enumerate(self.enumDicts[ilat]) if lat == 'protos': structures = getProtoPaths() for struct in structures: scrambleOrder = getAllPerms(self.knary, justCyclic='uniqueUnaries' in struct) for scramble in scrambleOrder: thisCrystal = Crystal(struct, species=self.species) thisCrystal.scrambleAtoms(scramble) thisMTP = MTP(fittingRoot, dataSet=[thisCrystal], forRelax=True) with open(path.join(fittingRoot, 'to-relax.cfg'), 'a+') as f: f.writelines(thisMTP.lines) else: for struct in range(1, enumLattice.nEnumStructs + 1): enumLattice.generatePOSCAR(struct) thisCrystal = Crystal.fromPOSCAR( enumLattice.root, self.species, filename="poscar.{}.{}".format(lat, struct), title=' '.join([lat, " str #: {}"]).format(struct)) thisMTP = MTP(fittingRoot, dataSet=[thisCrystal], forRelax=True) with open(path.join(fittingRoot, 'to-relax.cfg'), 'a+') as f: f.writelines(thisMTP.lines) delpath = path.join(enumLattice.root, "poscar.{}.{}".format(lat, struct)) remove(delpath) thisMTP.write_relaxin()
def enumerate(self, dataset): from aBuild.enumeration import Enumerate nEnums = len(self.specs[dataset]["lattice"]) for index in range(nEnums): enumController = Enumerate.fromYAML(self.specs[dataset], index, self.knary, self.root) enumController.buildInputFile(False) enumController.enumerate(False)
def enums(self): from aBuild.enumeration import Enumerate nEnums = len(self.specs[self.dataset]["lattice"]) enums = [] for index in range(nEnums): enums.append( Enumerate.fromYAML(self.specs[self.dataset], index, self.knary, self.root)) return enums
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 enumerate(self,dataset): from aBuild.enumeration import Enumerate self.dataset = dataset for index in range(self.nEnums): enumController = Enumerate(self.enumDicts[index]) enumController.buildInputFile(False) enumController.enumerate(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 build_ToRelax(self, enumDicts, species, AFM=False, start=1, end=None): from aBuild.enumeration import Enumerate from aBuild.utility import unpackProtos, getAllPerms, getProtoPaths from aBuild.database.crystal import Crystal from os import remove, path print('Building to-relax.cfg') print(enumDicts) nEnums = len(enumDicts) knary = len(species) for ilat in range(nEnums): lat = enumDicts[ilat]["name"] if lat == 'protos': structures = getProtoPaths(knary) for struct in structures: print("Proto structure:", struct) scrambleOrder = getAllPerms(knary, justCyclic='uniqueUnaries' in struct) for scramble in scrambleOrder: thisCrystal = Crystal(struct, species) #print("Atom counts before scramble {}".format(thisCrystal.atom_counts)) thisCrystal.scrambleAtoms(scramble) if not thisCrystal.concsOK( concRestrictions=enumDicts[ilat]["concs"]): continue print(thisCrystal.title) mindist = thisCrystal.minDist print( mindist, "actual min dist<-----------------------------------------------------------------------------------------------------" ) if mindist > 2 and thisCrystal.nAtoms < 60: if not AFM: print('Adding to file') #print("Atom counts after scramble {}".format(thisCrystal.atom_counts)) with open(path.join(self.root, 'to-relax.cfg'), 'a+') as f: f.writelines('\n'.join( thisCrystal.lines('mtprelax'))) elif thisCrystal.getAFMPlanes([1, 0, 0]): print("Original Crystal is AFM compatible") with open( path.join(self.root, 'to-relax.cfg_' + str(start)), 'a+') as f: f.writelines('\n'.join( thisCrystal.lines('mtprelax'))) # break else: print("Checking super-periodics") superCrystal = thisCrystal.superPeriodics(2) if superCrystal != []: print('Found a super-Periodic that works') print(superCrystal.basis, 'basis') print(superCrystal.atom_counts, 'atom counts') with open( path.join( self.root, 'to-relax.cfg_' + str(start)), 'a+') as f: f.writelines('\n'.join( superCrystal.lines('mtprelax'))) # break else: enumLattice = Enumerate(enumDicts[ilat]) print(end, 'end') if end == None: end = enumLattice.nConfigs + 1 filetag = '' else: filetag = '_' + str(start) #for struct in range(enumLattice.nConfigs+1): for struct in range(start, end): print("Lattice", lat, "structure:", struct) enumLattice.generatePOSCAR(struct) thisCrystal = Crystal( path.join(enumLattice.root, "poscar.{}.{}".format(lat, struct)), species) if not AFM: print('Writing to file!!!!!', end) with open( path.join(self.root, 'to_relax.cfg' + filetag), 'a+') as f: f.writelines('\n'.join( thisCrystal.lines('mtprelax'))) elif thisCrystal.getAFMPlanes([1, 0, 0]): print("Original Crystal is AFM compatible") with open( path.join(self.root, 'to_relax.cfg' + filetag), 'a+') as f: f.writelines('\n'.join( thisCrystal.lines('mtprelax'))) else: print("Checking super-periodics") superCrystal = thisCrystal.superPeriodics(2) if superCrystal != []: print('Found a super-Periodic that works') with open( path.join(self.root, 'to_relax.cfg' + filetag), 'a+') as f: f.writelines('\n'.join( superCrystal.lines('mtprelax'))) # print(thisCrystal.appMinDist,' approp Min Dist') # print(thisCrystal.minDist, 'actual min dist') # with open(path.join(self.root,'to-relax.cfg'),'a+') as f: # f.writelines('\n'.join(thisCrystal.lines('mtprelax') )) delpath = path.join(enumLattice.root, "poscar.{}.{}".format(lat, struct)) remove(delpath) end = None
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)
print("Something is wrong with this prototype structure. (min dist or nAtoms). Not adding to to-relax.") else: #if there's no special AFM settings, check other things ################################################################################################################ #I increased the indention for this block if mindist > 2 and thisCrystal.nAtoms < 60: print('Adding to file') #print("Atom counts after scramble {}".format(thisCrystal.atom_counts)) with open(path.join(self.root,'to-relax.cfg'),'a+') as f: f.writelines('\n'.join(thisCrystal.lines('mtprelax') ) ) ###########################################my changes########################################################## else: print("Something is wrong with this prototype structure. (min dist or nAtoms). Not adding to to-relax.") ################################################################################################################ >>>>>>> 03893ba98eddd6991de841e54e88613fa8b4165d else: enumLattice = Enumerate(enumDicts[ilat]) if end == None: end = enumLattice.nConfigs + 1 filetag = '' else: filetag = '_' + str(start) #for struct in range(enumLattice.nConfigs+1): for struct in range(start, end): print("Lattice",lat, "structure:",struct) enumLattice.generatePOSCAR(struct) thisCrystal = Crystal(path.join(enumLattice.root,"poscar.{}.{}".format(lat,struct)),species) if not AFM: with open(path.join(self.root,'to_relax.cfg' + filetag),'a+') as f: f.writelines('\n'.join(thisCrystal.lines('mtprelax') )) elif thisCrystal.getAFMPlanes([1,0,0]):