コード例 #1
0
 def test_macroscopic_average(self):
     '''Test the macroscopic averaging function'''
     f = 2.
     fs = 100
     x = np.arange(fs)
     potential = [np.sin(2 * np.pi * f * (i/float(fs))) for i in np.arange(fs)]
     macro = md.macroscopic_average(potential, 50, 1)
     self.assertAlmostEqual(macro[20], 0.)
コード例 #2
0
ファイル: gyp_old.py プロジェクト: lgyEthan/ethan.cms
    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)
    #------------------------------------------------------------------
    max_data = [0, 0]
    i = 0
    for a in planar:
        i += 1
        if max_data[1] < a:
コード例 #3
0
ファイル: efield-2d.py プロジェクト: woal777/materialDesign
                else:
                    charge.append(-2)
            else:
                if j % 2 == 1:
                    charge.append(-2)
                else:
                    charge.append(+1)
                
def distance(p1, p2):
    return math.sqrt(((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2))

def pot(r):
    arr = [i / distance(r, j) for i, j in zip(charge, position)]
    return sum(arr)

print(sum(charge))

space = n * 0.5
x = np.linspace(-space - 0.1, n + space + 0.1, 200)
y = [pot([r, 100 - 0.2]) for r in x]
res = 0.05
macro = md.macroscopic_average(y, 1, res)
double_macro = md.macroscopic_average(macro, 1, res)
plt.plot(x, y)
plt.plot(x, macro)
plt.plot(x, double_macro)
plt.show()

np.savetxt('1d.dat', np.array([x, y]).transpose())
np.savetxt('1d-macro.dat', np.array([x, double_macro]).transpose())
コード例 #4
0
ファイル: electro_pot.py プロジェクト: woal777/materialDesign
            to_print = False
    
    arr = np.array(arr, dtype=float)
    arr = arr.reshape(size)

new = np.sum(arr, axis=0) / arr.shape[0]
new = np.sum(new, axis=0) / arr.shape[0]

def five_point(arr, dx):
    return (-arr[3:] + 8 * arr[2:-1] - 8 * arr[1:-2] + arr[:-3]) / 12 / dx

def two_point(arr, dx):

    return (arr[1:] - arr[:-1]) / dx

macro = macroscopic_average(new, 3.822, 0.24)
macro = macroscopic_average(macro, 3.822, 0.12)
# macro = macroscopic_average(macro, 3.822, 0.24)
x = np.linspace(-10, 50, size[2])
diff = five_point(macro[::2], x[1] - x[0])
plt.plot(np.linspace(-10, 50, size[2]), new)
plt.plot(np.linspace(-10, 50, size[2]), macro)
plt.show()
plt.plot(np.linspace(-10, 50, size[2] //2 - 2), diff)
plt.show()
np.savetxt('x.dat', np.linspace(-10, 50, size[2]))
np.savetxt('x.dat', np.linspace(-10, 50, size[2] // 2 -2))
np.savetxt('planar.dat', new)
np.savetxt('macro.dat', macro)
np.savetxt('diff.dat', -diff)
# plt.ylim(-100, 0)
コード例 #5
0
ファイル: efield-1d.py プロジェクト: woal777/materialDesign
#%%
import matplotlib.pyplot as plt
import numpy as np
import macrodensity as md

position = [0, 1, 2, 3, 4]
charge = [0.5, -1, 1, -1, 0.5]


def pot(r):
    arr = [i / abs(r - j) for i, j in zip(charge, position)]

    return sum(arr)


x = np.linspace(-2.1, 6.1, 100)
y = [pot(r) for r in x]
macro = md.macroscopic_average(y, 1, 0.1)
double_macro = md.macroscopic_average(macro, 1, 0.05)
double_macro = md.macroscopic_average(double_macro, 1, 0.05)
plt.plot(x, y)
# plt.plot(x, macro)
plt.plot(x, double_macro)

np.savetxt('1d.dat', np.array([x, y]).transpose())
np.savetxt('1d-macro.dat', np.array([x, double_macro]).transpose())
plt.show()
コード例 #6
0
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)
##------------------------------------------------------------------
コード例 #7
0
    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


if __name__ == '__main__':
    os.chdir(
        '/home/jinho93/oxides/perobskite/lanthanum-aluminate/periodic_step/vasp/from-2012/1.0ps'
    )
    vasp_pot, NGX, NGY, NGZ, Lattice = md.read_vasp_density('LOCPOT')

#%%
x, y = slice(-5, 1, 200)
macro = md.macroscopic_average(y, 32, 1)
# macro = md.macroscopic_average(macro, 32, 1)
plt.plot(x, y)
plt.plot(x, macro)
output = [x, y, macro]
output = np.array(output)
output = np.transpose(output)
np.savetxt('loc.dat', output)
コード例 #8
0
ファイル: bonding.py プロジェクト: woal777/materialDesign
    ter, brig = 0, 0
    for b in bondings:
        if b[0] == 1 and b[1] == 0:
            ter += 1
        elif b[0] == 2 and b[1] == 0:
            brig += 1

    print(ter, brig)
# %%

import numpy as np
import macrodensity as md
arr = np.genfromtxt('/home/jinho93/molecule/dems/25/100/temp.dat')
arr = arr[:, 3]
mac = md.macroscopic_average(arr, 1, 0.1)
import matplotlib.pyplot as plt

plt.plot(mac)

np.savetxt('/home/jinho93/mac.dat', mac)
# %%
a = np.genfromtxt('mac.dat')
# %%
print(a)
# %%
from pymatgen.io.vasp import Vasprun
from pymatgen import Element
from pymatgen.electronic_structure.plotter import DosPlotter
dsp = DosPlotter()
vrun = Vasprun('vasprun.xml')
コード例 #9
0
ファイル: 2d-plot.py プロジェクト: woal777/materialDesign
m_range = 155
# dis = 190 // 2
dis = 256 // 2
plt.plot([0, dat.shape[1]], [m_range, m_range])
plt.plot([0, dat.shape[1]], [m_range + dis, m_range + dis])
# arr = dat[200:200+51,:]
arr = dat[m_range:m_range + dis, :]
# line = np.sum(arr, axis=0) / arr.shape[9]
# plt.imshow(dat)
plt.show()
plt.imshow(arr)
# %%
import macrodensity as md
# plt.plot(line)
plt.subplot(211)
macro = md.macroscopic_average(line, 1, 1 / dat.shape[1] * 5 * 3)
plt.plot(line)
plt.plot(macro)
plt.xlim((0, len(line)))
plt.subplot(212)
plt.imshow(arr)

#%%
plt.imshow(img_45)
#%%
from scipy import interpolate
start = 271 + 55
disp = 55
plt.imshow(img_45[:, start:start + disp])
plt.show()
line = np.sum(img_45[:, start:start + disp], axis=1) / disp
コード例 #10
0
from pymatgen.io.vasp import Chgcar
import os
import matplotlib.pyplot as plt
import macrodensity
import numpy as np

os.chdir(
    '/home/jinho93/oxides/perobskite/strontium-titanate/slab/nbsto/0.superlattice/4.long/20uc/symm/3.pure/1.percent/norel/vac/parchg'
)
chg = Chgcar.from_file('PARCHG')
structure = chg.poscar.structure
data: np.ndarray = chg.data['total']
z = chg.get_average_along_axis(2)
xaxis = np.linspace(0, chg.poscar.structure.lattice.c, len(z))
dz = xaxis[1] - xaxis[0]
z /= (chg.dim[2]) * dz
macro = macrodensity.macroscopic_average(z, 44.8, 1)
np.savetxt('z.dat', np.array([xaxis, z]).transpose())
np.savetxt('macro.dat', np.array([xaxis, macro]).transpose())

# macro = macrodensity.macroscopic_average(z, 4.1, chg.structure.lattice.c / chg.dim[2])
# np.savetxt('macro.dat', np.array([xaxis, macro]).transpose())