Example #1
0
File: mtp.py Project: jnewey/aBuild
    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
Example #2
0
                        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
=======
                        print(thisCrystal.appMinDist, 'appropriate min distance')
################################### my changes ################################################################
#                        thisCrystal.validateCrystal()
                        if self.special_settings["AFM"]: #if there's a AFM dictionary passed in with special_settings
                            print("Checking if this structure can be AFM")
                            AFMsuccess = thisCrystal.checkAFM(self.special_settings["AFM"]["plane"],self.special_settings["AFM"]["spin_type"])#,self.special_settings["eps"] )
                            if not AFMsuccess:
Example #3
0
    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)
Example #4
0
                    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))