本文整理汇总了Python中gpaw.xc.XC.calculate_fxc方法的典型用法代码示例。如果您正苦于以下问题:Python XC.calculate_fxc方法的具体用法?Python XC.calculate_fxc怎么用?Python XC.calculate_fxc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gpaw.xc.XC
的用法示例。
在下文中一共展示了XC.calculate_fxc方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate_Kxc
# 需要导入模块: from gpaw.xc import XC [as 别名]
# 或者: from gpaw.xc.XC import calculate_fxc [as 别名]
def calculate_Kxc(gd,
nt_sG,
npw,
Gvec_Gc,
nG,
vol,
bcell_cv,
R_av,
setups,
D_asp,
functional='ALDA',
density_cut=None):
"""ALDA kernel"""
# The soft part
#assert np.abs(nt_sG[0].shape - nG).sum() == 0
if functional == 'ALDA_X':
x_only = True
A_x = -3. / 4. * (3. / np.pi)**(1. / 3.)
nspins = len(nt_sG)
assert nspins in [1, 2]
fxc_sg = nspins**(1. / 3.) * 4. / 9. * A_x * nt_sG**(-2. / 3.)
else:
assert len(nt_sG) == 1
x_only = False
fxc_sg = np.zeros_like(nt_sG)
xc = XC(functional[1:])
xc.calculate_fxc(gd, nt_sG, fxc_sg)
if density_cut is not None:
fxc_sg[np.where(nt_sG * len(nt_sG) < density_cut)] = 0.0
# FFT fxc(r)
nG0 = nG[0] * nG[1] * nG[2]
tmp_sg = [np.fft.fftn(fxc_sg[s]) * vol / nG0 for s in range(len(nt_sG))]
r_vg = gd.get_grid_point_coordinates()
Kxc_sGG = np.zeros((len(fxc_sg), npw, npw), dtype=complex)
for s in range(len(fxc_sg)):
for iG in range(npw):
for jG in range(npw):
dG_c = Gvec_Gc[iG] - Gvec_Gc[jG]
if (nG / 2 - np.abs(dG_c) > 0).all():
index = (dG_c + nG) % nG
Kxc_sGG[s, iG, jG] = tmp_sg[s][index[0],
index[1],
index[2]]
else: # not in the fft index
dG_v = np.dot(dG_c, bcell_cv)
dGr_g = gemmdot(dG_v, r_vg, beta=0.0)
Kxc_sGG[s, iG, jG] = gd.integrate(np.exp(-1j * dGr_g)
* fxc_sg[s])
# The PAW part
KxcPAW_sGG = np.zeros_like(Kxc_sGG)
dG_GGv = np.zeros((npw, npw, 3))
for iG in range(npw):
for jG in range(npw):
dG_c = Gvec_Gc[iG] - Gvec_Gc[jG]
dG_GGv[iG, jG] = np.dot(dG_c, bcell_cv)
for a, setup in enumerate(setups):
if rank == a % size:
rgd = setup.xc_correction.rgd
n_qg = setup.xc_correction.n_qg
nt_qg = setup.xc_correction.nt_qg
nc_g = setup.xc_correction.nc_g
nct_g = setup.xc_correction.nct_g
Y_nL = setup.xc_correction.Y_nL
dv_g = rgd.dv_g
D_sp = D_asp[a]
B_pqL = setup.xc_correction.B_pqL
D_sLq = np.inner(D_sp, B_pqL.T)
nspins = len(D_sp)
f_sg = rgd.empty(nspins)
ft_sg = rgd.empty(nspins)
n_sLg = np.dot(D_sLq, n_qg)
nt_sLg = np.dot(D_sLq, nt_qg)
# Add core density
n_sLg[:, 0] += np.sqrt(4. * np.pi) / nspins * nc_g
nt_sLg[:, 0] += np.sqrt(4. * np.pi) / nspins * nct_g
coefatoms_GG = np.exp(-1j * np.inner(dG_GGv, R_av[a]))
for n, Y_L in enumerate(Y_nL):
w = weight_n[n]
f_sg[:] = 0.0
n_sg = np.dot(Y_L, n_sLg)
if x_only:
f_sg = nspins * (4 / 9.) * A_x * (nspins * n_sg)**(-2 / 3.)
else:
xc.calculate_fxc(rgd, n_sg, f_sg)
ft_sg[:] = 0.0
nt_sg = np.dot(Y_L, nt_sLg)
if x_only:
ft_sg = nspins * (4 / 9.) * (A_x
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from gpaw.xc import XC [as 别名]
# 或者: from gpaw.xc.XC import calculate_fxc [as 别名]
#.........这里部分代码省略.........
.5*paw.density.nt_sg[0]])
else:
nt_sg = paw.density.nt_sg
# check if D_sp have been changed before
D_asp = self.paw.density.D_asp
for a, D_sp in D_asp.items():
if len(D_sp) != kss.npspins:
if len(D_sp) == 1:
D_asp[a] = np.array([0.5 * D_sp[0], 0.5 * D_sp[0]])
else:
D_asp[a] = np.array([D_sp[0] + D_sp[1]])
# restrict the density if needed
if fg:
nt_s = nt_sg
else:
nt_s = self.gd.zeros(nt_sg.shape[0])
for s in range(nt_sg.shape[0]):
self.restrict(nt_sg[s], nt_s[s])
gd = paw.density.gd
# initialize vxc or fxc
if self.derivativeLevel==0:
raise NotImplementedError
if kss.npspins==2:
v_g=nt_sg[0].copy()
else:
v_g=nt_sg.copy()
elif self.derivativeLevel==1:
pass
elif self.derivativeLevel==2:
fxc_sg = np.zeros(nt_sg.shape)
self.xc.calculate_fxc(gd, nt_sg, fxc_sg)
else:
raise ValueError('derivativeLevel can only be 0,1,2')
## self.paw.my_nuclei = []
ns=self.numscale
xc=self.xc
print >> self.txt, 'XC',nij,'transitions'
for ij in range(eh_comm.rank, nij, eh_comm.size):
print >> self.txt,'XC kss['+'%d'%ij+']'
timer = Timer()
timer.start('init')
timer2 = Timer()
if self.derivativeLevel >= 1:
# vxc is available
# We use the numerical two point formula for calculating
# the integral over fxc*n_ij. The results are
# vvt_s smooth integral
# nucleus.I_sp atom based correction matrices (pack2)
# stored on each nucleus
timer2.start('init v grids')
vp_s=np.zeros(nt_s.shape,nt_s.dtype.char)
vm_s=np.zeros(nt_s.shape,nt_s.dtype.char)
if kss.npspins == 2: # spin polarised
nv_s = nt_s.copy()
nv_s[kss[ij].pspin] += ns * kss[ij].get(fg)
xc.calculate(gd, nv_s, vp_s)
nv_s = nt_s.copy()
nv_s[kss[ij].pspin] -= ns * kss[ij].get(fg)
xc.calculate(gd, nv_s, vm_s)
示例3: calculate_Kxc
# 需要导入模块: from gpaw.xc import XC [as 别名]
# 或者: from gpaw.xc.XC import calculate_fxc [as 别名]
def calculate_Kxc(pd, nt_sG, R_av, setups, D_asp, functional='ALDA',
density_cut=None):
"""ALDA kernel"""
gd = pd.gd
npw = pd.ngmax
nG = pd.gd.N_c
vol = pd.gd.volume
bcell_cv = np.linalg.inv(pd.gd.cell_cv)
G_Gv = pd.get_reciprocal_vectors()
# The soft part
#assert np.abs(nt_sG[0].shape - nG).sum() == 0
if functional == 'ALDA_X':
x_only = True
A_x = -3. / 4. * (3. / np.pi)**(1. / 3.)
nspins = len(nt_sG)
assert nspins in [1, 2]
fxc_sg = nspins**(1. / 3.) * 4. / 9. * A_x * nt_sG**(-2. / 3.)
else:
assert len(nt_sG) == 1
x_only = False
fxc_sg = np.zeros_like(nt_sG)
xc = XC(functional[1:])
xc.calculate_fxc(gd, nt_sG, fxc_sg)
if density_cut is not None:
fxc_sg[np.where(nt_sG * len(nt_sG) < density_cut)] = 0.0
# FFT fxc(r)
nG0 = nG[0] * nG[1] * nG[2]
tmp_sg = [np.fft.fftn(fxc_sg[s]) * vol / nG0 for s in range(len(nt_sG))]
r_vg = gd.get_grid_point_coordinates()
Kxc_sGG = np.zeros((len(fxc_sg), npw, npw), dtype=complex)
for s in range(len(fxc_sg)):
for iG, iQ in enumerate(pd.Q_qG[0]):
iQ_c = (np.unravel_index(iQ, nG) + nG // 2) % nG - nG // 2
for jG, jQ in enumerate(pd.Q_qG[0]):
jQ_c = (np.unravel_index(jQ, nG) + nG // 2) % nG - nG // 2
ijQ_c = (iQ_c - jQ_c)
if (abs(ijQ_c) < nG // 2).all():
Kxc_sGG[s, iG, jG] = tmp_sg[s][tuple(ijQ_c)]
# The PAW part
KxcPAW_sGG = np.zeros_like(Kxc_sGG)
dG_GGv = np.zeros((npw, npw, 3))
for v in range(3):
dG_GGv[:, :, v] = np.subtract.outer(G_Gv[:, v], G_Gv[:, v])
for a, setup in enumerate(setups):
if rank == a % size:
rgd = setup.xc_correction.rgd
n_qg = setup.xc_correction.n_qg
nt_qg = setup.xc_correction.nt_qg
nc_g = setup.xc_correction.nc_g
nct_g = setup.xc_correction.nct_g
Y_nL = setup.xc_correction.Y_nL
dv_g = rgd.dv_g
D_sp = D_asp[a]
B_pqL = setup.xc_correction.B_pqL
D_sLq = np.inner(D_sp, B_pqL.T)
nspins = len(D_sp)
f_sg = rgd.empty(nspins)
ft_sg = rgd.empty(nspins)
n_sLg = np.dot(D_sLq, n_qg)
nt_sLg = np.dot(D_sLq, nt_qg)
# Add core density
n_sLg[:, 0] += np.sqrt(4. * np.pi) / nspins * nc_g
nt_sLg[:, 0] += np.sqrt(4. * np.pi) / nspins * nct_g
coefatoms_GG = np.exp(-1j * np.inner(dG_GGv, R_av[a]))
for n, Y_L in enumerate(Y_nL):
w = weight_n[n]
f_sg[:] = 0.0
n_sg = np.dot(Y_L, n_sLg)
if x_only:
f_sg = nspins * (4 / 9.) * A_x * (nspins * n_sg)**(-2 / 3.)
else:
xc.calculate_fxc(rgd, n_sg, f_sg)
ft_sg[:] = 0.0
nt_sg = np.dot(Y_L, nt_sLg)
if x_only:
ft_sg = nspins * (4 / 9.) * (A_x
* (nspins * nt_sg)**(-2 / 3.))
else:
xc.calculate_fxc(rgd, nt_sg, ft_sg)
for i in range(len(rgd.r_g)):
coef_GG = np.exp(-1j * np.inner(dG_GGv, R_nv[n])
* rgd.r_g[i])
for s in range(len(f_sg)):
KxcPAW_sGG[s] += w * np.dot(coef_GG,
(f_sg[s, i] -
ft_sg[s, i])
* dv_g[i]) * coefatoms_GG
#.........这里部分代码省略.........
示例4: calculate_Kxc
# 需要导入模块: from gpaw.xc import XC [as 别名]
# 或者: from gpaw.xc.XC import calculate_fxc [as 别名]
def calculate_Kxc(gd, nt_sG, npw, Gvec_Gc, nG, vol,
bcell_cv, R_av, setups, D_asp):
"""LDA kernel"""
# The soft part
assert np.abs(nt_sG[0].shape - nG).sum() == 0
xc = XC('LDA')
fxc_sg = np.zeros_like(nt_sG)
xc.calculate_fxc(gd, nt_sG, fxc_sg)
fxc_g = fxc_sg[0]
# FFT fxc(r)
nG0 = nG[0] * nG[1] * nG[2]
tmp_g = np.fft.fftn(fxc_g) * vol / nG0
r_vg = gd.get_grid_point_coordinates()
Kxc_GG = np.zeros((npw, npw), dtype=complex)
for iG in range(npw):
for jG in range(npw):
dG_c = Gvec_Gc[iG] - Gvec_Gc[jG]
if (nG / 2 - np.abs(dG_c) > 0).all():
index = (dG_c + nG) % nG
Kxc_GG[iG, jG] = tmp_g[index[0], index[1], index[2]]
else: # not in the fft index
dG_v = np.dot(dG_c, bcell_cv)
dGr_g = gemmdot(dG_v, r_vg, beta=0.0)
Kxc_GG[iG, jG] = gd.integrate(np.exp(-1j*dGr_g)*fxc_g)
KxcPAW_GG = np.zeros_like(Kxc_GG)
# The PAW part
dG_GGv = np.zeros((npw, npw, 3))
for iG in range(npw):
for jG in range(npw):
dG_c = Gvec_Gc[iG] - Gvec_Gc[jG]
dG_GGv[iG, jG] = np.dot(dG_c, bcell_cv)
for a, setup in enumerate(setups):
if rank == a % size:
rgd = setup.xc_correction.rgd
n_qg = setup.xc_correction.n_qg
nt_qg = setup.xc_correction.nt_qg
nc_g = setup.xc_correction.nc_g
nct_g = setup.xc_correction.nct_g
Y_nL = setup.xc_correction.Y_nL
dv_g = rgd.dv_g
D_sp = D_asp[a]
B_pqL = setup.xc_correction.B_pqL
D_sLq = np.inner(D_sp, B_pqL.T)
nspins = len(D_sp)
assert nspins == 1
f_sg = rgd.empty(nspins)
ft_sg = rgd.empty(nspins)
n_sLg = np.dot(D_sLq, n_qg)
nt_sLg = np.dot(D_sLq, nt_qg)
# Add core density
n_sLg[:, 0] += sqrt(4 * pi) / nspins * nc_g
nt_sLg[:, 0] += sqrt(4 * pi) / nspins * nct_g
coefatoms_GG = np.exp(-1j * np.inner(dG_GGv, R_av[a]))
for n, Y_L in enumerate(Y_nL):
w = weight_n[n]
f_sg[:] = 0.0
n_sg = np.dot(Y_L, n_sLg)
xc.calculate_fxc(rgd, n_sg, f_sg)
ft_sg[:] = 0.0
nt_sg = np.dot(Y_L, nt_sLg)
xc.calculate_fxc(rgd, nt_sg, ft_sg)
coef_GGg = np.exp(-1j * np.outer(np.inner(dG_GGv, R_nv[n]),
rgd.r_g)).reshape(npw,npw,rgd.ng)
KxcPAW_GG += w * np.dot(coef_GGg, (f_sg[0]-ft_sg[0]) * dv_g) * coefatoms_GG
world.sum(KxcPAW_GG)
Kxc_GG += KxcPAW_GG
return Kxc_GG / vol