示例#1
0
        knary = len(species)
        for ilat  in range(nEnums):
            lat = enumDicts[ilat]["name"]
            
            if lat == 'protos': #for prototype structures, we want to make sure that the mindist is okay
                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<-----------------------------------------------------------------------------------------------------")
<<<<<<< HEAD

                        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:
示例#2
0
文件: mtp.py 项目: 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
示例#3
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)