예제 #1
0
    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)
예제 #2
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)