Octopus
xc_sic.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!! Copyright (C) 2022 N. Tancogne-Dejean
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
22module xc_sic_oct_m
23 use debug_oct_m
25 use global_oct_m
26 use grid_oct_m
33 use parser_oct_m
36 use space_oct_m
40 use xc_oct_m
41 use xc_f03_lib_m
42 use xc_oep_oct_m
44 use xc_vxc_oct_m
45
46 implicit none
47
48 private
49 public :: &
50 xc_sic_t, &
56
58 integer, parameter, public :: &
59 SIC_NONE = 1, & !< no self-interaction correction
60 sic_pz_oep = 2, &
61 sic_amaldi = 3, &
62 sic_adsic = 4
63
65 type xc_sic_t
66 private
67 integer, public :: level = sic_none
68 real(real64), public :: amaldi_factor
69 type(xc_oep_t), public :: oep
70 end type xc_sic_t
71
72contains
73
74 ! ---------------------------------------------------------
76 !
77 subroutine xc_sic_init(sic, namespace, gr, st, mc, space)
78 type(xc_sic_t), intent(out) :: sic
79 type(namespace_t), intent(in) :: namespace
80 type(grid_t), intent(inout) :: gr
81 type(states_elec_t), intent(in) :: st
82 type(multicomm_t), intent(in) :: mc
83 class(space_t), intent(in) :: space
84
85
86 push_sub(xc_sic_init)
87
88 !%Variable SICCorrection
89 !%Type integer
90 !%Default sic_none
91 !%Section Hamiltonian::XC
92 !%Description
93 !% This variable controls which form of self-interaction correction to use. Note that
94 !% this correction will be applied to the functional chosen by <tt>XCFunctional</tt>.
95 !%Option sic_none 1
96 !% No self-interaction correction.
97 !%Option sic_pz 2
98 !% Perdew-Zunger SIC, handled by the OEP technique.
99 !% J. P. Perdew and Alex Zunger, Phys. Rev. B 23, 5048 (1981)
100 !% Extension to the spinor case follows Tancogne-Dejean et al., J. Chem. Phys. 159, 224110 (2023)
101 !%
102 !% Note that the current implement uses canonical orbitals and not minimizing orbitals.
103 !% Please check <tt>SCDMforPZSIC</tt> for using SCDM-based Wannier orbitals instead of canonical orbitals.
104 !%Option sic_amaldi 3
105 !% Amaldi correction term. Not implemeneted for spinors.
106 !% E. Fermi and E. Amaldi, Mem. Reale Accad. Italia 6, 119 (1934)
107 !%Option sic_adsic 4
108 !% Average-density SIC.
109 !% C. Legrand <i>et al.</i>, <i>J. Phys. B</i> <b>35</b>, 1115 (2002).
110 !% Extension to the spinor case follows Tancogne-Dejean et al., J. Chem. Phys. 159, 224110 (2023)
111 !%End
112 call parse_variable(namespace, 'SICCorrection', sic_none, sic%level)
113 if (.not. varinfo_valid_option('SICCorrection', sic%level)) call messages_input_error(namespace, 'SICCorrection')
114
115 ! check whether we should introduce the Amaldi SIC correction
116 sic%amaldi_factor = m_one
117 if (sic%level == sic_amaldi) then
118 sic%amaldi_factor = (st%qtot - m_one)/st%qtot
119 if(st%d%ispin == spinors) then
120 call messages_not_implemented("Amaldi SIC with non-collinear spins")
121 end if
122 end if
123
124 if(sic%level == sic_pz_oep) then
125 call xc_oep_init(sic%oep, namespace, gr, st, mc, space, oep_type = oep_type_sic)
126
127 if(st%nik > st%d%spin_channels) then
128 call messages_not_implemented("PZ-SIC with k-points")
129 end if
130 end if
131
132 if (allocated(st%rho_core)) then
133 call messages_not_implemented('SIC with nonlinear core corrections')
134 end if
135
136 if (allocated(st%frozen_rho) .and. (sic%level == sic_pz_oep .or. sic%level == sic_amaldi)) then
137 call messages_not_implemented('PZ-SIC with frozen orbitals')
138 end if
139
140 if (space%is_periodic() .and. sic%level /= sic_none) then
141 call messages_not_implemented("SIC corrections in periodic systems")
142 end if
143
144 pop_sub(xc_sic_init)
145 end subroutine xc_sic_init
146
147 ! ---------------------------------------------------------
149 subroutine xc_sic_end(sic)
150 type(xc_sic_t), intent(inout) :: sic
151
152 if (sic%level == sic_none) return
154 push_sub(xc_sic_end)
155
156 if(sic%level == sic_pz_oep) call xc_oep_end(sic%oep)
157
158 pop_sub(xc_sic_end)
159 end subroutine xc_sic_end
161
162 ! ---------------------------------------------------------
163 subroutine xc_sic_write_info(sic, iunit, namespace)
164 type(xc_sic_t), intent(in) :: sic
165 integer, optional, intent(in) :: iunit
166 type(namespace_t), optional, intent(in) :: namespace
167
168 if (sic%level == sic_none) return
169
170 push_sub(xc_sic_write_info)
171
172 call messages_print_var_option('SICCorrection', sic%level, iunit=iunit, namespace=namespace)
173
174 pop_sub(xc_sic_write_info)
175 end subroutine xc_sic_write_info
176
177 ! ---------------------------------------------------------
194 subroutine xc_sic_calc_adsic(sic, namespace, space, gr, st, hm, xc, density, vxc, ex, ec)
195 type(xc_sic_t), intent(in) :: sic
196 type(namespace_t), intent(in) :: namespace
197 class(space_t), intent(in) :: space
198 type(grid_t), intent(in) :: gr
199 type(states_elec_t), intent(in) :: st
200 type(hamiltonian_elec_t), intent(in) :: hm
201 type(xc_t), intent(inout) :: xc
202 real(real64), contiguous, intent(in) :: density(:,:)
203 real(real64), contiguous, intent(inout) :: vxc(:,:)
204 real(real64), optional, intent(inout) :: ex, ec
205
206 integer :: ispin, ist, ik, ip
207 real(real64), allocatable :: vxc_sic(:,:), vh_sic(:), rho(:, :)
208 real(real64) :: ex_sic, ec_sic, qsp(2)
209 real(real64) :: dtot, dpol, vpol
210 real(real64) :: nup
211
212 push_sub(xc_sic_calc_adsic)
213
214 assert(sic%level == sic_adsic)
215
216 if (st%d%ispin == spinors .and. .not. in_family(hm%xc%family, [xc_family_lda, xc_family_gga])) then
217 write(message(1),'(a)') 'ADSIC with non-collinear spin is currently only possible'
218 write(message(2),'(a)') 'with LDA and GGA functionals.'
219 call messages_fatal(2, namespace=namespace)
220 end if
221
222 if (xc_is_not_size_consistent(xc, namespace)) then
223 call messages_not_implemented('ADSIC with size inconsistent functionals', namespace=namespace)
224 end if
225
226 ! We compute here the number of electrons per spin channel
227 qsp = m_zero
228 if( .not. allocated(st%frozen_rho)) then
229 select case (st%d%ispin)
231 do ist = 1, st%nst
232 do ik = 1, st%nik
233 ispin = st%d%get_spin_index(ik)
234 qsp(ispin) = qsp(ispin) + st%occ(ist, ik) * st%kweights(ik)
235 end do
236 end do
237 end select
238 else
239 ! In the case of the frozen density, we can only get the charge from the integral
240 ! of the total density, including valence and frozen density
241 qsp(1:st%d%nspin) = dmf_integrate(gr, st%d%nspin, density)
242 end if
243
244 safe_allocate(vxc_sic(1:gr%np, 1:2))
245 safe_allocate(vh_sic(1:gr%np))
246 safe_allocate(rho(1:gr%np, 1:2))
247 ! We first compute the average xc self-interction error and we substract it
248 select case (st%d%ispin)
250 do ispin = 1, st%d%nspin
251 if (abs(qsp(ispin)) <= m_min_occ) cycle
252
253 rho = m_zero
254 vxc_sic = m_zero
255
256 rho(:, ispin) = density(:, ispin) / qsp(ispin)
257 if(present(ex) .and. present(ec)) then
258 ex_sic = m_zero
259 ec_sic = m_zero
260 ! This needs always to be called for the spin-polarized case
261 call xc_get_vxc(gr, xc, st, hm%kpoints, hm%psolver, namespace, space, &
262 rho, spin_polarized, hm%ions%latt%rcell_volume, vxc_sic, ex = ex_sic, ec = ec_sic)
263 ex = ex - ex_sic * qsp(ispin)
264 ec = ec - ec_sic * qsp(ispin)
265 else
266 ! This needs always to be called for the spin-polarized case
267 call xc_get_vxc(gr, xc, st, hm%kpoints, hm%psolver, namespace, space, &
268 rho, spin_polarized, hm%ions%latt%rcell_volume, vxc_sic)
269 end if
270
271 call lalg_axpy(gr%np, -m_one, vxc_sic(:, ispin), vxc(:, ispin))
272
273 ! We now substract the averaged Hartree self-interaction error
274 ! See Eq. 15 in [Pietezak and Vieira, Theoretical Chemistry Accounts (2021) 140:130]
275 vh_sic = m_zero
276 call dpoisson_solve(hm%psolver, namespace, vh_sic, rho(:, ispin), all_nodes=.false.)
277 call lalg_axpy(gr%np, -m_one, vh_sic, vxc(:, ispin))
278
279 ! Compute the corresponding energy contribution
280 if(present(ex)) then
281 ex = ex - m_half*dmf_dotp(gr, rho(:,ispin), vh_sic) * qsp(ispin)
282 end if
283
284 end do
285
286 case (spinors)
287 ! Here we only treat the case of LDA/GGA. We rotate the average density in the local frame
288 ! And we then compute the SIC correction from it
289 ! This cannot excerce any xc torque, by construction
290 assert(in_family(hm%xc%family, [xc_family_lda, xc_family_gga]))
291
292 do ispin = 1, 2
293 rho = m_zero
294 vxc_sic = m_zero
295 ! Averaged density in the local frame
296 do ip = 1, gr%np
297 dtot = density(ip, 1) + density(ip, 2)
298 dpol = sqrt((density(ip, 1) - density(ip, 2))**2 + &
299 m_four*(density(ip, 3)**2 + density(ip, 4)**2))
300 if(ispin == 1) then
301 rho(ip, 1) = max(m_half*(dtot + dpol), m_zero)
302 else
303 rho(ip, 2) = max(m_half*(dtot - dpol), m_zero)
304 end if
305 end do
306 nup = dmf_integrate(gr, rho(:,ispin))
307 if (nup <= 1e-14_real64) cycle
308 call lalg_scal(gr%np, m_one/nup, rho(:,ispin))
309
310 ! This needs always to be called for the spin-polarized case
311 if(present(ex) .and. present(ec)) then
312 ex_sic = m_zero
313 ec_sic = m_zero
314 call xc_get_vxc(gr, xc, st, hm%kpoints, hm%psolver, namespace, space, &
315 rho, spin_polarized, hm%ions%latt%rcell_volume, vxc_sic, ex = ex_sic, ec = ec_sic)
316 ex = ex - ex_sic * nup
317 ec = ec - ec_sic * nup
318 else
319 call xc_get_vxc(gr, xc, st, hm%kpoints, hm%psolver, namespace, space, &
320 rho, spin_polarized, hm%ions%latt%rcell_volume, vxc_sic)
321 end if
322
323 ! Select only the potential correspond to this spin channel
324 if(ispin == 2) then
325 vxc_sic(:, 1) = m_zero
326 else
327 vxc_sic(:, 2) = m_zero
328 end if
329
330 vh_sic = m_zero
331 call dpoisson_solve(hm%psolver, namespace, vh_sic, rho(:, ispin), all_nodes=.false.)
332 call lalg_axpy(gr%np, m_one, vh_sic, vxc_sic(:, ispin))
333 ! Compute the corresponding energy contribution
334 if(present(ex)) then
335 ex = ex - m_half*dmf_dotp(gr, rho(:,ispin), vh_sic) * nup
336 end if
337
338 do ip = 1, gr%np
339 dpol = sqrt((density(ip, 1) - density(ip, 2))**2 + &
340 m_four*(density(ip, 3)**2 + density(ip, 4)**2))
341 vpol = (vxc_sic(ip, 1) - vxc_sic(ip, 2))*(density(ip, 1) - density(ip, 2))/(safe_tol(dpol, xc_tiny))
342
343 vxc(ip, 1) = vxc(ip, 1) - m_half*(vxc_sic(ip, 1) + vxc_sic(ip, 2) + vpol)
344 vxc(ip, 2) = vxc(ip, 2) - m_half*(vxc_sic(ip, 1) + vxc_sic(ip, 2) - vpol)
345 vxc(ip, 3) = vxc(ip, 3) - (vxc_sic(ip, 1) - vxc_sic(ip, 2))*density(ip, 3)/(safe_tol(dpol, xc_tiny))
346 vxc(ip, 4) = vxc(ip, 4) - (vxc_sic(ip, 1) - vxc_sic(ip, 2))*density(ip, 4)/(safe_tol(dpol, xc_tiny))
347 end do
348 end do
349
350
351 end select
352
353 safe_deallocate_a(vxc_sic)
354 safe_deallocate_a(vh_sic)
355 safe_deallocate_a(rho)
356
357 pop_sub(xc_sic_calc_adsic)
358 end subroutine xc_sic_calc_adsic
359
360 ! ---------------------------------------------------------
364 subroutine xc_sic_add_fxc_adsic(namespace, xc, st, gr, rho, fxc)
365 type(namespace_t), intent(in) :: namespace
366 type(xc_t), intent(in) :: xc
367 type(states_elec_t), intent(in) :: st
368 type(grid_t), intent(in) :: gr
369 real(real64), intent(in) :: rho(:,:)
370 real(real64), contiguous, intent(inout) :: fxc(:,:,:)
371
372 real(real64), allocatable :: rho_averaged(:, :)
373 real(real64), allocatable :: fxc_sic(:,:,:)
374 real(real64) :: qtot
375 integer :: ispin
376
377 push_sub(xc_sic_add_fxc_adsic)
378
379 !Check spin and triplets
380 assert(st%d%ispin /= spinors)
381 assert(.not. allocated(st%frozen_rho))
382
383 if (bitand(xc%kernel_family, xc_family_lda) == 0) then
384 message(1) = "fxc calculation with ADSIC not implemented beyond LDAs."
385 call messages_fatal(1, namespace=namespace)
386 end if
387
388 if (xc_is_not_size_consistent(xc, namespace)) then
389 call messages_not_implemented('ADSIC with size inconsistent functionals', namespace=namespace)
390 end if
391
392 if (st%d%ispin == spinors) then
393 call messages_not_implemented('ADSIC fxc with non-collinear spin')
394 end if
395
396 ! This needs always to be called for the spin-polarized case
397 safe_allocate(rho_averaged(1:gr%np, 1:2))
398 safe_allocate(fxc_sic(1:gr%np, 1:2, 1:2))
399
400 do ispin = 1, st%d%nspin
401 rho_averaged = m_zero
402 qtot = dmf_integrate(gr, rho(:, ispin))
403 if (abs(qtot) <= m_min_occ) cycle
404
405 call lalg_copy(gr%np, rho(:, ispin), rho_averaged(:, ispin))
406 call lalg_scal(gr%np, m_one/qtot, rho_averaged(:, ispin))
407
408 fxc_sic = m_zero
409 call xc_get_fxc(xc, gr, namespace, rho_averaged, spin_polarized, fxc_sic)
410
411 call lalg_axpy(gr%np, -m_one/qtot, fxc_sic(:, ispin, ispin), fxc(:, ispin, ispin))
412 end do
413
414 safe_deallocate_a(rho_averaged)
415 safe_deallocate_a(fxc_sic)
416
417 pop_sub(xc_sic_add_fxc_adsic)
418 end subroutine xc_sic_add_fxc_adsic
419
420end module xc_sic_oct_m
421
422!! Local Variables:
423!! mode: f90
424!! coding: utf-8
425!! End:
constant times a vector plus a vector
Definition: lalg_basic.F90:173
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:188
scales a vector by a constant
Definition: lalg_basic.F90:159
double sqrt(double __x) __attribute__((__nothrow__
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
integer, parameter, public spin_polarized
real(real64), parameter, public m_zero
Definition: global.F90:191
real(real64), parameter, public m_four
Definition: global.F90:195
real(real64), parameter, public m_half
Definition: global.F90:197
real(real64), parameter, public m_one
Definition: global.F90:192
real(real64), parameter, public m_min_occ
Minimal occupation that is considered to be non-zero.
Definition: global.F90:218
This module implements the underlying real-space grid.
Definition: grid.F90:119
This module defines various routines, operating on mesh functions.
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1067
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:161
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:409
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:690
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
subroutine, public dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Calculates the Poisson equation. Given the density returns the corresponding potential.
Definition: poisson.F90:872
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public xc_get_fxc(xcs, gr, namespace, rho, ispin, fxc, fxc_grad, fxc_grad_spin)
Returns the exchange-correlation kernel.
Definition: xc_kernel.F90:172
Definition: xc.F90:116
real(real64), parameter, public xc_tiny
Arbitrary definition of tiny, for use in XC context.
Definition: xc.F90:216
logical function, public xc_is_not_size_consistent(xcs, namespace)
Is one of the x or c functional is not size consistent.
Definition: xc.F90:697
pure logical function, public in_family(family, xc_families)
Definition: xc.F90:627
subroutine, public xc_oep_end(oep)
Definition: xc_oep.F90:359
subroutine, public xc_oep_init(oep, namespace, gr, st, mc, space, oep_type)
Definition: xc_oep.F90:220
integer, parameter, public oep_type_sic
Definition: xc_oep.F90:187
subroutine, public xc_sic_write_info(sic, iunit, namespace)
Definition: xc_sic.F90:259
integer, parameter, public sic_adsic
Averaged density SIC.
Definition: xc_sic.F90:153
subroutine, public xc_sic_init(sic, namespace, gr, st, mc, space)
initialize the SIC object
Definition: xc_sic.F90:173
subroutine, public xc_sic_end(sic)
finalize the SIC and, if needed, the included OEP
Definition: xc_sic.F90:245
integer, parameter, public sic_pz_oep
Perdew-Zunger SIC (OEP way)
Definition: xc_sic.F90:153
integer, parameter, public sic_amaldi
Amaldi correction term.
Definition: xc_sic.F90:153
subroutine, public xc_sic_calc_adsic(sic, namespace, space, gr, st, hm, xc, density, vxc, ex, ec)
Computes the ADSIC potential and energy.
Definition: xc_sic.F90:290
subroutine, public xc_sic_add_fxc_adsic(namespace, xc, st, gr, rho, fxc)
Adds to fxc the ADSIC contribution.
Definition: xc_sic.F90:460
subroutine, public xc_get_vxc(gr, xcs, st, kpoints, psolver, namespace, space, rho, ispin, rcell_volume, vxc, ex, ec, deltaxc, vtau, ex_density, ec_density, stress_xc, force_orbitalfree)
Definition: xc_vxc.F90:185
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
The states_elec_t class contains all electronic wave functions.
This class contains information about the self-interaction correction.
Definition: xc_sic.F90:160