コード例 #1
0
 def test_density_2_grid(self):
     '''Test the function for projecting the potential onto a grid'''
     charge, ngx, ngy, ngz, lattice = md.read_vasp_density('CHGCAR.test')
     grid_pot, electrons = md.density_2_grid(charge, ngx, ngy, ngz)
     self.assertAlmostEqual(grid_pot[0, 0, 0], -.76010173913E+01)
     self.assertAlmostEqual(grid_pot[55, 55, 55], -4.4496715627)
     self.assertAlmostEqual(electrons, 8.00000, places=4)
コード例 #2
0
    def __init__(self, settings_obj,):

        self.settings_obj = settings_obj

        try:
            if self.settings_obj.poscar_path:
                self.structure = Structure.from_file(self.settings_obj.poscar_path)
            else:
                self.structure = Structure.from_file('POSCAR')
        except FileNotFoundError as e:
            print(e)
            print('The given filepath for the poscar did not find a poscar file, ensure POSCAR is at the end '
                  'e.g. /POSCAR. if no filepath was given then no poscar was found in the current directory.')


        # currently only works for orthogonal structures
        if not self.check_orthog_lat():
            print('exiting prog')
            sys.exit()


        #raplce any vacuums with the default small value so that we can do voronoi analysis - it crashes for structures with large vacuum spaces
        # note the size of the vacuum size swapped isn't important, will find voronoi vertices there but they'll be removed as they'll be outside of the unshifted structure or inside layers!
        # only issue may be sites near the edges -> these will be ranked low due to potential sum
        self.orig_struct, self.downwards_shifts, self.lowest_atoms, self.highest_atoms, self.structure = self.find_vacuums() #this changes structure to one without vacuum. copies the old structure as self.orig_struct

        # find the number of ions we are intercalating
        self.no_ions = int(self.settings_obj.int_dens * self.structure.num_sites) # density*no of sites = # to intercalate

        #use md package to get the points of high potential
        try:
            if self.settings_obj.locpot_path:
                self.vasp_pot, self.NGX, self.NGY, self.NGZ, self.lattice = md.read_vasp_density(self.settings_obj.locpot_path)
            else:
                self.vasp_pot, self.NGX, self.NGY, self.NGZ, self.lattice = md.read_vasp_density('LOCPOT')
            self.grid_pot, self.electrons = md.density_2_grid(self.vasp_pot, self.NGX, self.NGY, self.NGZ)  # generate the grid of potentials
            self.settings_obj.locpot = True
        except FileNotFoundError as e:
            print(e)
            print('The given filepath for the locpot did not find a locpot file, ensure LOCPOT is at the end '
                  'e.g. /LOCPOT. if no filepath was given then no locpot was found in the current directory.')
            self.settings_obj.locpot = False



        # get the intersitials using voronoi decomposition
        self.interstitial_sites = self.get_interstitials()   #### SLOW! very very slow!!

        # go back to the original, unshifted structure
        #self.shifted_structure = self.structure.copy()
        self.structure = self.orig_struct.copy()

        # convert interstitial sites back to fractional coords (previously were in cartesian due to the shifts!
        self.interstitial_sites = [([i[0][0] / self.structure.lattice.a, i[0][1] / self.structure.lattice.b,
                                     i[0][2] / self.structure.lattice.c], i[1]) for i in
                                   self.interstitial_sites]
コード例 #3
0
 def test_density_2_grid(self):
     '''Test the function for projecting the potential onto a grid'''
     chgcar = pkg_resources.resource_filename(
                 __name__, path_join('..', 'CHGCAR.test'))
     charge, ngx, ngy, ngz, lattice = md.read_vasp_density(chgcar,
                                                           quiet=True)
     grid_pot, electrons = md.density_2_grid(charge, ngx, ngy, ngz)
     self.assertAlmostEqual(grid_pot[0, 0, 0], - .76010173913E+01)
     self.assertAlmostEqual(grid_pot[55, 55, 55], -4.4496715627)
     self.assertAlmostEqual(electrons, 8.00000, places=4)
コード例 #4
0
def slice(fr, end, density):
    grid_pot, electrons = md.density_2_grid(vasp_pot, NGX, NGY, NGZ)

    dim = [NGX, NGY, NGZ]
    dim = np.array(dim)

    start = np.array('0.85000  0.48765  0.62783'.split()).astype(float)
    to = np.array('0.85000  0.50000  0.75409'.split()).astype(float)

    # start = start * dim
    # to = to * dim
    new = []
    dis = []
    for n in np.linspace(fr, end, density):
        tmp = (to - start) * n
        dis.append(np.sqrt(sum((tmp * np.diagonal(Lattice))**2)))
        tmp += start
        new.append(tmp)

    new = np.array(new)
    # new = new.round()
    # new = new.astype(int)

    arr = []
    arr2 = []
    tmp = None
    size = 8
    for i, j in zip(new, dis):
        if reduce(lambda x, y: x * y, tmp == i):
            continue
        tmp = i
        a, _ = md.cube_potential(i, [0, 0, 0], [size, size, size], grid_pot,
                                 NGX, NGY, NGZ)
        arr.append(a)
        arr2.append(j)
    return arr2, arr
コード例 #5
0
ファイル: gyp_old.py プロジェクト: lgyEthan/ethan.cms
            )
    else:
        log.write("--------------------\n")
        log.write("(Manually set) Fermi energy= [" + str(fermi_e) + " ] eV.\n")
        log.write("--------------------\n")

    #------------------------------------------------------------------
    # Get the potential
    #------------------------------------------------------------------
    vasp_pot, NGX, NGY, NGZ, Lattice = md.read_vasp_density(input_file,
                                                            quiet=True)
    vector_a, vector_b, vector_c, av, bv, cv = md.matrix_2_abc(Lattice)
    resolution_x = vector_a / NGX
    resolution_y = vector_b / NGY
    resolution_z = vector_c / NGZ
    grid_pot, electrons = md.density_2_grid(vasp_pot, NGX, NGY, NGZ)

    #------------------------------------------------------------------
    # POTENTIAL
    #------------------------------------------------------------------
    planar = md.planar_average(grid_pot, NGX, NGY, NGZ)
    shifted_planar = planar - fermi_e
    plt.plot(shifted_planar)

    #------------start: MACROSCOPIC AVERAGE
    if Macro_average:
        macro = md.macroscopic_average(planar, lattice_vector, resolution_z)
        plt.plot(macro)
    #------------end: MACROSCOPIC AVERAGE

    plt.savefig('Planar.eps')
コード例 #6
0
ファイル: ActiveSpace.py プロジェクト: WMD-group/MacroDensity
import csv
from itertools import izip




#------------------------------------------------------------------
# Get the potential
# This section should not be altered
#------------------------------------------------------------------
vasp_pot, NGX, NGY, NGZ, Lattice = md.read_vasp_density('LOCPOT.slab')
vector_a,vector_b,vector_c,av,bv,cv = md.matrix_2_abc(Lattice)
resolution_x = vector_a/NGX
resolution_y = vector_b/NGY
resolution_z = vector_c/NGZ
grid_pot, electrons = md.density_2_grid(vasp_pot,NGX,NGY,NGZ)
cutoff_varience = 1E-4
hanksConstant = 4.89E-7
## Get the gradiens (Field), if required.
## Comment out if not required, due to compuational expense.
#grad_x,grad_y,grad_z = np.gradient(grid_pot[:,:,:],resolution_x,resolution_y,resolution_z)
#------------------------------------------------------------------


##------------------------------------------------------------------
## Get the equation for the plane
## This is the section for plotting on a user defined plane; 
## uncomment commands if this is the option that you want.
##------------------------------------------------------------------
## Input section (define the plane with 3 points)
#a_point = [0, 0, 0]
コード例 #7
0


#------------------------------------------------------------------
#   READING
# Get the two potentials and change them to a planar average.
# This section should not be altered
#------------------------------------------------------------------
# SLAB
vasp_pot, NGX, NGY, NGZ, Lattice = md.read_vasp_density('CHGCAR.Slab')
mag_a,mag_b,mag_c,vec_a,vec_b,vec_c = md.matrix_2_abc(Lattice)
resolution_x = mag_a/NGX
resolution_y = mag_b/NGY
resolution_z = mag_c/NGZ
Volume = md.get_volume(vec_a,vec_b,vec_c)
grid_pot_slab, electrons_slab = md.density_2_grid(vasp_pot,NGX,NGY,NGZ,True,Volume)
# Save the lattce vectors for use later
Vector_A = [vec_a,vec_b,vec_c]
#----------------------------------------------------------------------------------
# CONVERT TO PLANAR DENSITIES
#----------------------------------------------------------------------------------
planar_slab = md.planar_average(grid_pot_slab,NGX,NGY,NGZ)
# BULK
vasp_pot, NGX, NGY, NGZ, Lattice = md.read_vasp_density('CHGCAR.Bulk')
mag_a,mag_b,mag_c,vec_a,vec_b,vec_c = md.matrix_2_abc(Lattice)
resolution_x = mag_a/NGX
resolution_y = mag_b/NGY
resolution_z = mag_c/NGZ
# Save the lattce vectors for use later
Vector_B = [vec_a,vec_b,vec_c]
Volume = md.get_volume(vec_a,vec_b,vec_c)
コード例 #8
0
    def __init__(
        self,
        settings_obj,
    ):
        self.settings_obj = settings_obj

        try:
            if self.settings_obj.poscar_path:
                self.structure = Structure.from_file(
                    self.settings_obj.poscar_path)
            else:
                self.structure = Structure.from_file('POSCAR')
        except FileNotFoundError as e:
            print(e)
            print(
                'The given filepath for the poscar did not find a poscar file, ensure POSCAR is at the end '
                'e.g. /POSCAR. if no filepath was given then no poscar was found in the current directory.'
            )

        self.no_ions = int(self.settings_obj.int_dens *
                           self.structure.num_sites)

        try:
            if self.settings_obj.locpot_path:
                self.vasp_pot, self.NGX, self.NGY, self.NGZ, self.lattice = md.read_vasp_density(
                    self.settings_obj.locpot_path)
            else:
                self.vasp_pot, self.NGX, self.NGY, self.NGZ, self.lattice = md.read_vasp_density(
                    'LOCPOT')
            self.grid_pot, self.electrons = md.density_2_grid(
                self.vasp_pot, self.NGX, self.NGY,
                self.NGZ)  # generate the grid of potentials

        except FileNotFoundError as e:
            print(e)
            print(
                'The given filepath for the locpot did not find a locpot file, ensure LOCPOT is at the end '
                'e.g. /LOCPOT. if no filepath was given then no locpot was found in the current directory.'
            )

        # then run as normal, once voronoi done and cells found, convert back and carry on
        if not self.check_orthog_lat():
            print('exiting prog')
            sys.exit()
        self.find_vacuums(
        )  #this changes structure to one without vacuum. copies the old structure as self.orig_struct

        self.evaluator = ValenceIonicRadiusEvaluator(
            self.structure
        )  #computes site valence and ionic radii using bond valence analyser.
        # note this uses the sites, periodic table, bond valence, composition and local env packages! (as well as structure)
        self.radii = self.evaluator.radii
        self.valences = self.evaluator.valences

        self.interstitial = Interstitial(
            self.structure,
            radii=self.radii,
            valences=self.valences,
            symmetry_flag=self.settings_obj.sym_dist)
        # this evaluates the structure and uses radii and valence to generate voronoi sites depending on whether vertex,
        # facecenter or edge center is selected.
        # note: not sur eif hsould set oxi_state = False. By default it is true and it then uses ionic radii in the calculation,
        #  shouldnt really change centres? Returns and interstitial object. ._defect_sites returns the coordinates and labels of
        #  all intersittial sites which were found from the voronoi nodes/edges/faces/all depending on settings.
        # sym if False so we get all sites, including symmetry inequivalent sites!

        print('\n')
        self.interstitial_sites = [
            ([site._fcoords[0], site._fcoords[1],
              site._fcoords[2]], site.properties.get('voronoi_radius', None))
            for site in self.interstitial._defect_sites
        ]  # this creates a list of tuples: [ (array of site location
        # fractional coordinates, Voronoi radius') ]
        #  replaced  with self.get_nearest_neighbour_dist(site)

        # shift vornoi up if shifted!
        self.interstitial_sites = [
            ([
                i[0][0] * self.structure.lattice.a -
                self.downwards_shifts[0][0],
                i[0][1] * self.structure.lattice.b -
                self.downwards_shifts[1][1],
                i[0][2] * self.structure.lattice.c -
                self.downwards_shifts[2][2]
            ], i[1]) for i in self.interstitial_sites
        ]  #shift it and convert to cart coords at the same time

        # go back to the original, unshifted structure
        self.shifted_structure = self.structure.copy()
        self.structure = self.orig_struct.copy()
        self.interstitial_sites = [([
            i[0][0] / self.structure.lattice.a,
            i[0][1] / self.structure.lattice.b,
            i[0][2] / self.structure.lattice.c
        ], i[1]) for i in self.interstitial_sites
                                   ]  # convert it back to fractional coords