Esempio n. 1
0
    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()
Esempio n. 2
0
    def randomDisplacements(self, POSCAR):
        from os import path

        from aBuild.database.crystal import Crystal

        toRelax = path.join(self.root, 'fitting', 'mtp', 'to_relax.cfg')
        for i in range(1000):
            thisCrystal = Crystal(POSCAR, systemSpecies=self.species)
            thisCrystal.randomDisplace()
            print(thisCrystal.lines('mtprelax'))
            with open(toRelax, 'a+') as f:
                f.writelines('\n'.join(thisCrystal.lines('mtprelax')))
Esempio n. 3
0
        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')
        #pyplot.savefig('errorForces.png')
        
        

    def randomDisplacements(self,POSCAR):
        from os import path
        
        from aBuild.database.crystal import Crystal

        toRelax = path.join(self.root,'fitting','mtp','to_relax.cfg')
        for i in range(1000):
            thisCrystal = Crystal(POSCAR,systemSpecies = self.species)
            thisCrystal.randomDisplace()
            print(thisCrystal.lines('mtprelax'))
            with open(toRelax, 'a+') as f:
                f.writelines('\n'.join(thisCrystal.lines('mtprelax')))
                
        
Esempio n. 4
0
File: mtp.py Progetto: 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
Esempio n. 5
0
    def build_ToRelax(self, enums, 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')
        nEnums = len(enums)
        knary = len(species)
        for ilat in range(nEnums):
            lat = enums[ilat].lattice.lattice_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=enums[ilat]["concs"]):
                            continue
                        mindist = thisCrystal.minDist

                        if mindist > 2:
                            with open(path.join(self.root, 'to_relax.cfg'),
                                      'a+') as f:
                                f.writelines('\n'.join(
                                    thisCrystal.lines('mtprelax')))
            else:
                enumLattice = enums[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("Generating {} crystal structure # {}.".format(
                        lat, struct))
                    enumLattice.generatePOSCAR(struct)
                    # When initializing a crystal object from a poscar generated by makestr.x, I know that the crystal species is
                    # the same as the system species because it generates zeros in the atom counts list.
                    print('initializing object')
                    thisCrystal = Crystal.from_poscar(
                        path.join(enumLattice.root,
                                  "poscar.{}.{}".format(lat, struct)), species)
                    thisCrystal.set_latpar(modify=enumLattice.latticeExpand)

                    with open(path.join(self.root, 'to_relax.cfg' + filetag),
                              'a+') as f:
                        f.writelines('\n'.join(thisCrystal.lines('mtprelax')))

                    delpath = path.join(enumLattice.root,
                                        "poscar.{}.{}".format(lat, struct))
                    remove(delpath)