Exemplo n.º 1
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]
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def test_read_vasp(self):
     '''Test the function for reading CHGCAR/LOCPOT'''
     charge, ngx, ngy, ngz, lattice = md.read_vasp_density('CHGCAR.test')
     self.assertEqual(charge[0], -.76010173913E+01)
     self.assertEqual(charge[56 * 56 * 56 - 1], -4.4496715627)
     self.assertEqual(lattice[0, 0], 2.7150000)
     self.assertEqual(ngx, 56)
Exemplo n.º 4
0
    def test_ipr(self):
        '''Test the ipr function'''

        parchg = pkg_resources.resource_filename(
            __name__, path_join('..', 'CHGCAR.test'))

        dens, ngx, ngy, ngz, lattice = md.read_vasp_density(parchg, quiet=True)
        self.assertAlmostEqual(md.inverse_participation_ratio(dens), 1.407e-5)
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def test_read_vasp(self):
     '''Test the function for reading CHGCAR/LOCPOT'''
     chgcar = pkg_resources.resource_filename(
         __name__, path_join('..', 'CHGCAR.test'))
     charge, ngx, ngy, ngz, lattice = md.read_vasp_density(chgcar,
                                                           quiet=True)
     for v, t in ((charge, np.ndarray), (ngx, int), (ngy, int), (ngz, int),
                  (lattice, np.ndarray)):
         self.assertIsInstance(v, t)
     self.assertEqual(charge[0], -.76010173913E+01)
     self.assertEqual(charge[56 * 56 * 56 - 1], -4.4496715627)
     self.assertEqual(lattice[0, 0], 2.7150000)
     self.assertEqual(ngx, 56)
Exemplo n.º 7
0
            log.write("--------------------\n")
            log.write(
                "[WARNING] Fermi energy is not extracted. Shifting is not done\n"
            )
            print(
                "[WARNING] fermi energy is not extracted. Shifting is not done"
            )
    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:
Exemplo n.º 8
0
import macrodensity as md
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import os

input_file = ''
lattice_vector = 3.90821

vasp_pot, NGX, NGY, NGZ, Lattice = md.read_vasp_density(input_file + 'LOCPOT')
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)
# MACROSCOPIC AVERAGE
macro = md.macroscopic_average(planar, lattice_vector, resolution_z)
x = np.linspace(0, 1, len(planar))
fig, ax1 = plt.subplots(1, 1, sharex=True)

textsize = 22
mpl.rcParams['xtick.labelsize'] = textsize
mpl.rcParams['ytick.labelsize'] = textsize
mpl.rcParams['figure.figsize'] = (10, 6)
ax1.plot(x, planar, label="Planar", lw=3)
ax1.plot(x, macro, label="Macroscopic", lw=3)

ax1.set_xlim(0, 1)
Exemplo n.º 9
0
#! /usr/bin/env python
import macrodensity as md
import math
import numpy as np
import matplotlib.pyplot as plt
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)
## 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]
Exemplo n.º 10
0
#! /usr/bin/env python
import macrodensity as md
import math
import numpy as np
import matplotlib.pyplot as plt
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
Exemplo n.º 11
0
import matplotlib.pyplot as plt
import csv
from itertools import izip


potential_file = 'LOCPOT' # The file with VASP output for potential
coordinate_file = 'POSCAR' # The coordinates file NOTE NOTE This must be in vasp 4 format 
species = "O"  # The species whose on-site potential you are interested in 
sample_cube = [5,5,5] # The size of the sampling cube in units of mesh points (NGX/Y/Z)

# Nothing below here should require changing
#------------------------------------------------------------------
# Get the potential
# This section should not be altered
#------------------------------------------------------------------
vasp_pot, NGX, NGY, NGZ, Lattice = md.read_vasp_density(potential_file)
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)
## 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)
#------------------------------------------------------------------

##------------------------------------------------------------------
## Getting the potentials for a group of atoms, in this case the Os
## NOTE THIS REQUIRES ASE to be available https://wiki.fysik.dtu.dk/ase/index.html
##------------------------------------------------------------------
##------------------------------------------------------------------
Exemplo n.º 12
0
import macrodensity as md
import math
import numpy as np
import matplotlib.pyplot as plt





#------------------------------------------------------------------
#   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)
Exemplo n.º 13
0
import csv
from itertools import izip

potential_file = 'LOCPOT'  # The file with VASP output for potential
coordinate_file = 'POSCAR'  # The coordinates file NOTE NOTE This must be in vasp 4 format
species = "O"  # The species whose on-site potential you are interested in
sample_cube = [
    5, 5, 5
]  # The size of the sampling cube in units of mesh points (NGX/Y/Z)

# Nothing below here should require changing
#------------------------------------------------------------------
# Get the potential
# This section should not be altered
#------------------------------------------------------------------
vasp_pot, NGX, NGY, NGZ, Lattice = md.read_vasp_density(potential_file)
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)
## 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)
#------------------------------------------------------------------

##------------------------------------------------------------------
## Getting the potentials for a group of atoms, in this case the Os
## NOTE THIS REQUIRES ASE to be available https://wiki.fysik.dtu.dk/ase/index.html
##------------------------------------------------------------------
Exemplo n.º 14
0
#! /usr/bin/env python
import macrodensity as md
import math
import numpy as np
import matplotlib.pyplot as plt

input_file = 'LOCPOT'
lattice_vector = 4.75
output_file = 'planar.dat'
# No need to alter anything after here
#------------------------------------------------------------------
# Get the potential
# This section should not be altered
#------------------------------------------------------------------
vasp_pot, NGX, NGY, NGZ, Lattice = md.read_vasp_density(input_file)
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)
## MACROSCOPIC AVERAGE
macro  = md.macroscopic_average(planar,lattice_vector,resolution_z)
plt.plot(planar)
plt.plot(macro)
plt.savefig('Planar.eps')
plt.show()
np.savetxt(output_file,planar)
##------------------------------------------------------------------
Exemplo n.º 15
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