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 assert(present(ex) .eqv. present(ec))
216
217 if (st%d%ispin == spinors .and. .not. in_family(hm%xc%family, [xc_family_lda, xc_family_gga])) then
218 write(message(1),'(a)') 'ADSIC with non-collinear spin is currently only possible'
219 write(message(2),'(a)') 'with LDA and GGA functionals.'
220 call messages_fatal(2, namespace=namespace)
221 end if
222
223 if (xc_is_not_size_consistent(xc, namespace)) then
224 call messages_not_implemented('ADSIC with size inconsistent functionals', namespace=namespace)
225 end if
226
227 ! We compute here the number of electrons per spin channel
228 qsp = m_zero
229 if( .not. allocated(st%frozen_rho)) then
230 select case (st%d%ispin)
232 do ist = 1, st%nst
233 do ik = 1, st%nik
234 ispin = st%d%get_spin_index(ik)
235 qsp(ispin) = qsp(ispin) + st%occ(ist, ik) * st%kweights(ik)
236 end do
237 end do
238 end select
239 else
240 ! In the case of the frozen density, we can only get the charge from the integral
241 ! of the total density, including valence and frozen density
242 qsp(1:st%d%nspin) = dmf_integrate(gr, st%d%nspin, density)
243 end if
245 safe_allocate(vxc_sic(1:gr%np, 1:2))
246 safe_allocate(vh_sic(1:gr%np))
247 safe_allocate(rho(1:gr%np, 1:2))
248 ! We first compute the average xc self-interction error and we substract it
249 select case (st%d%ispin)
251 do ispin = 1, st%d%spin_channels
252 if (abs(qsp(ispin)) <= m_min_occ) cycle
253
254 rho = m_zero
255 vxc_sic = m_zero
256
257 rho(:, ispin) = density(:, ispin) / qsp(ispin)
258 if(present(ex)) then
259 ex_sic = m_zero
260 ec_sic = m_zero
261 ! This needs always to be called for the spin-polarized case
262 ! force_host is needed to ensure the correct density is used for the libxc call on GPU (see comment in xc_vxc_inc.F90)
263 call xc_get_vxc(gr, xc, st, hm%kpoints, hm%psolver, namespace, space, &
264 rho, spin_polarized, hm%ions%latt%rcell_volume, vxc_sic, ex = ex_sic, ec = ec_sic, force_host=.true.)
265 ex = ex - ex_sic * qsp(ispin)
266 ec = ec - ec_sic * qsp(ispin)
267 else
268 ! This needs always to be called for the spin-polarized case
269 ! force_host is needed to ensure the correct density is used for the libxc call on GPU (see comment in xc_vxc_inc.F90)
270 call xc_get_vxc(gr, xc, st, hm%kpoints, hm%psolver, namespace, space, &
271 rho, spin_polarized, hm%ions%latt%rcell_volume, vxc_sic, force_host=.true.)
272 end if
273
274 call lalg_axpy(gr%np, -m_one, vxc_sic(:, ispin), vxc(:, ispin))
275
276 ! We now substract the averaged Hartree self-interaction error
277 ! See Eq. 15 in [Pietezak and Vieira, Theoretical Chemistry Accounts (2021) 140:130]
278 vh_sic = m_zero
279 call dpoisson_solve(hm%psolver, namespace, vh_sic, rho(:, ispin), all_nodes=.false.)
280 call lalg_axpy(gr%np, -m_one, vh_sic, vxc(:, ispin))
281
282 ! Compute the corresponding energy contribution
283 if(present(ex)) then
284 ex = ex - m_half*dmf_dotp(gr, rho(:,ispin), vh_sic) * qsp(ispin)
285 end if
286
287 end do
288
289 case (spinors)
290 ! Here we only treat the case of LDA/GGA. We rotate the average density in the local frame
291 ! And we then compute the SIC correction from it
292 ! This cannot excerce any xc torque, by construction
293 assert(in_family(hm%xc%family, [xc_family_lda, xc_family_gga]))
294
295 do ispin = 1, 2
296 rho = m_zero
297 vxc_sic = m_zero
298 ! Averaged density in the local frame
299 do ip = 1, gr%np
300 dtot = density(ip, 1) + density(ip, 2)
301 dpol = sqrt((density(ip, 1) - density(ip, 2))**2 + &
302 m_four*(density(ip, 3)**2 + density(ip, 4)**2))
303 if(ispin == 1) then
304 rho(ip, 1) = max(m_half*(dtot + dpol), m_zero)
305 else
306 rho(ip, 2) = max(m_half*(dtot - dpol), m_zero)
307 end if
308 end do
309 nup = dmf_integrate(gr, rho(:,ispin))
310 if (nup <= m_min_occ) cycle
311 call lalg_scal(gr%np, m_one/nup, rho(:,ispin))
312
313 ! This needs always to be called for the spin-polarized case
314 if(present(ex) .and. present(ec)) then
315 ex_sic = m_zero
316 ec_sic = m_zero
317 call xc_get_vxc(gr, xc, st, hm%kpoints, hm%psolver, namespace, space, &
318 rho, spin_polarized, hm%ions%latt%rcell_volume, vxc_sic, ex = ex_sic, ec = ec_sic, force_host=.true.)
319 ex = ex - ex_sic * nup
320 ec = ec - ec_sic * nup
321 else
322 call xc_get_vxc(gr, xc, st, hm%kpoints, hm%psolver, namespace, space, &
323 rho, spin_polarized, hm%ions%latt%rcell_volume, vxc_sic, force_host=.true.)
324 end if
325
326 ! Select only the potential correspond to this spin channel
327 if(ispin == 2) then
328 vxc_sic(:, 1) = m_zero
329 else
330 vxc_sic(:, 2) = m_zero
331 end if
332
333 vh_sic = m_zero
334 call dpoisson_solve(hm%psolver, namespace, vh_sic, rho(:, ispin), all_nodes=.false.)
335 call lalg_axpy(gr%np, m_one, vh_sic, vxc_sic(:, ispin))
336 ! Compute the corresponding energy contribution
337 if(present(ex)) then
338 ex = ex - m_half*dmf_dotp(gr, rho(:,ispin), vh_sic) * nup
339 end if
340
341 do ip = 1, gr%np
342 dpol = sqrt((density(ip, 1) - density(ip, 2))**2 + &
343 m_four*(density(ip, 3)**2 + density(ip, 4)**2))
344 ! See lda_process in xc_vxc_inc.F90
345 if (dpol > xc_tiny*(density(ip, 1)+density(ip, 2))) then
346 vpol = (vxc_sic(ip, 1) - vxc_sic(ip, 2))*(density(ip, 1) - density(ip, 2))/(safe_tol(dpol, xc_tiny))
347
348 vxc(ip, 1) = vxc(ip, 1) - m_half*(vxc_sic(ip, 1) + vxc_sic(ip, 2) + vpol)
349 vxc(ip, 2) = vxc(ip, 2) - m_half*(vxc_sic(ip, 1) + vxc_sic(ip, 2) - vpol)
350 vxc(ip, 3) = vxc(ip, 3) - (vxc_sic(ip, 1) - vxc_sic(ip, 2))*density(ip, 3)/(safe_tol(dpol, xc_tiny))
351 vxc(ip, 4) = vxc(ip, 4) - (vxc_sic(ip, 1) - vxc_sic(ip, 2))*density(ip, 4)/(safe_tol(dpol, xc_tiny))
352 else
353 vxc(ip, 1) = vxc(ip, 1) - m_half*(vxc_sic(ip, 1) + vxc_sic(ip, 2))
354 vxc(ip, 2) = vxc(ip, 2) - m_half*(vxc_sic(ip, 1) + vxc_sic(ip, 2))
355 end if
356 end do
357 end do
358
359
360 end select
361
362 safe_deallocate_a(vxc_sic)
363 safe_deallocate_a(vh_sic)
364 safe_deallocate_a(rho)
365
366 pop_sub(xc_sic_calc_adsic)
367 end subroutine xc_sic_calc_adsic
368
369 ! ---------------------------------------------------------
373 subroutine xc_sic_add_fxc_adsic(namespace, xc, st, gr, rho, fxc)
374 type(namespace_t), intent(in) :: namespace
375 type(xc_t), intent(in) :: xc
376 type(states_elec_t), intent(in) :: st
377 type(grid_t), intent(in) :: gr
378 real(real64), intent(in) :: rho(:,:)
379 real(real64), contiguous, intent(inout) :: fxc(:,:,:)
380
381 real(real64), allocatable :: rho_averaged(:, :)
382 real(real64), allocatable :: fxc_sic(:,:,:)
383 real(real64) :: qtot
384 integer :: ispin
385
386 push_sub(xc_sic_add_fxc_adsic)
387
388 !Check spin and triplets
389 assert(st%d%ispin /= spinors)
390 assert(.not. allocated(st%frozen_rho))
391
392 if (bitand(xc%kernel_family, xc_family_lda) == 0) then
393 message(1) = "fxc calculation with ADSIC not implemented beyond LDAs."
394 call messages_fatal(1, namespace=namespace)
395 end if
396
397 if (xc_is_not_size_consistent(xc, namespace)) then
398 call messages_not_implemented('ADSIC with size inconsistent functionals', namespace=namespace)
399 end if
400
401 if (st%d%ispin == spinors) then
402 call messages_not_implemented('ADSIC fxc with non-collinear spin')
403 end if
404
405 ! This needs always to be called for the spin-polarized case
406 safe_allocate(rho_averaged(1:gr%np, 1:2))
407 safe_allocate(fxc_sic(1:gr%np, 1:2, 1:2))
408
409 do ispin = 1, st%d%nspin
410 rho_averaged = m_zero
411 qtot = dmf_integrate(gr, rho(:, ispin))
412 if (abs(qtot) <= m_min_occ) cycle
413
414 call lalg_copy(gr%np, rho(:, ispin), rho_averaged(:, ispin))
415 call lalg_scal(gr%np, m_one/qtot, rho_averaged(:, ispin))
416
417 fxc_sic = m_zero
418 call xc_get_fxc(xc, gr, namespace, rho_averaged, spin_polarized, fxc_sic)
419
420 call lalg_axpy(gr%np, -m_one/qtot, fxc_sic(:, ispin, ispin), fxc(:, ispin, ispin))
421 end do
422
423 safe_deallocate_a(rho_averaged)
424 safe_deallocate_a(fxc_sic)
425
426 pop_sub(xc_sic_add_fxc_adsic)
427 end subroutine xc_sic_add_fxc_adsic
428
429end module xc_sic_oct_m
430
431!! Local Variables:
432!! mode: f90
433!! coding: utf-8
434!! 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:200
real(real64), parameter, public m_four
Definition: global.F90:204
real(real64), parameter, public m_half
Definition: global.F90:206
real(real64), parameter, public m_one
Definition: global.F90:201
real(real64), parameter, public m_min_occ
Minimal occupation that is considered to be non-zero.
Definition: global.F90:227
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:1068
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:691
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:863
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:120
real(real64), parameter, public xc_tiny
Arbitrary definition of tiny, for use in XC context.
Definition: xc.F90:256
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:822
pure logical function, public in_family(family, xc_families)
Definition: xc.F90:750
subroutine, public xc_oep_end(oep)
Definition: xc_oep.F90:358
subroutine, public xc_oep_init(oep, namespace, gr, st, mc, space, oep_type)
Definition: xc_oep.F90:219
integer, parameter, public oep_type_sic
Definition: xc_oep.F90:186
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:469
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, force_host)
Definition: xc_vxc.F90:191
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
int true(void)