def test_planar_average(self): ''' Test the code for averaging the density''' test_grid = np.zeros(shape=(3, 3, 3)) for i in range(3): test_grid[i, :, 0] = float(i) planar = md.planar_average(test_grid, 3, 3, 3) self.assertAlmostEqual(planar[0], 1.0) planar = md.planar_average(test_grid, 3, 3, 3, axis='x') self.assertAlmostEqual(planar[2], 0.66666667)
#------------------------------------------------------------------ # 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') plt.show() np.savetxt(output_file, shifted_planar) #------------------------------------------------------------------ # Calculate Workfunction Value. (Workfunction = Vacuum Level - Fermi Level)
# 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) #---------------------------------------------------------------------------------- # CONVERT TO PLANAR DENSITIES #---------------------------------------------------------------------------------- grid_pot_bulk, electrons_bulk = md.density_2_grid(vasp_pot,NGX,NGY,NGZ,True,Volume) planar_bulk = md.planar_average(grid_pot_bulk,NGX,NGY,NGZ) #----------------------------------------------------------------------------------
# This section should not be altered #------------------------------------------------------------------ #vasp_pot, NGX, NGY, NGZ, Lattice = pot.read_vasp_density(input_file) #vector_a,vector_b,vector_c,av,bv,cv = pot.matrix_2_abc(Lattice) #resolution_x = vector_a/NGX #resolution_y = vector_b/NGY #resolution_z = vector_c/NGZ #grid_pot, electrons = pot.density_2_grid(vasp_pot,NGX,NGY,NGZ) potential, atoms = ase.io.cube.read_cube(input_file, read_data=True) vector_a = np.linalg.norm(atoms.cell[1]) vector_b = np.linalg.norm(atoms.cell[1]) vector_c = np.linalg.norm(atoms.cell[2]) NGX = len(potential) NGY = len(potential[0]) NGZ = len(potential[0][0]) resolution_x = vector_a / NGX resolution_y = vector_b / NGY resolution_z = vector_c / NGZ print NGX, NGY, NGZ #------------------------------------------------------------------ ## POTENTIAL planar = md.planar_average(potential, 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) ##------------------------------------------------------------------
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) ##------------------------------------------------------------------
# This section should not be altered #------------------------------------------------------------------ #vasp_pot, NGX, NGY, NGZ, Lattice = pot.read_vasp_density(input_file) #vector_a,vector_b,vector_c,av,bv,cv = pot.matrix_2_abc(Lattice) #resolution_x = vector_a/NGX #resolution_y = vector_b/NGY #resolution_z = vector_c/NGZ #grid_pot, electrons = pot.density_2_grid(vasp_pot,NGX,NGY,NGZ) potential, atoms = ase.io.cube.read_cube(input_file,read_data=True) vector_a = np.linalg.norm(atoms.cell[1]) vector_b = np.linalg.norm(atoms.cell[1]) vector_c = np.linalg.norm(atoms.cell[2]) NGX = len(potential) NGY = len(potential[0]) NGZ = len(potential[0][0]) resolution_x = vector_a/NGX resolution_y = vector_b/NGY resolution_z = vector_c/NGZ print NGX,NGY,NGZ #------------------------------------------------------------------ ## POTENTIAL planar = md.planar_average(potential,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) ##------------------------------------------------------------------