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
43
44 implicit none
45
46 private
47 public :: &
48 xc_sic_t, &
54
56 integer, parameter, public :: &
57 SIC_NONE = 1, & !< no self-interaction correction
58 sic_pz_oep = 2, &
59 sic_amaldi = 3, &
60 sic_adsic = 4
61
63 type xc_sic_t
64 private
65 integer, public :: level = sic_none
66 real(real64), public :: amaldi_factor
67 type(xc_oep_t), public :: oep
68 end type xc_sic_t
69
70contains
71
72 ! ---------------------------------------------------------
74 !
75 subroutine xc_sic_init(sic, namespace, gr, st, mc, space)
76 type(xc_sic_t), intent(out) :: sic
77 type(namespace_t), intent(in) :: namespace
78 type(grid_t), intent(inout) :: gr
79 type(states_elec_t), intent(in) :: st
80 type(multicomm_t), intent(in) :: mc
81 class(space_t), intent(in) :: space
82
83
84 push_sub(xc_sic_init)
85
86 !%Variable SICCorrection
87 !%Type integer
88 !%Default sic_none
89 !%Section Hamiltonian::XC
90 !%Description
91 !% This variable controls which form of self-interaction correction to use. Note that
92 !% this correction will be applied to the functional chosen by <tt>XCFunctional</tt>.
93 !%Option sic_none 1
94 !% No self-interaction correction.
95 !%Option sic_pz 2
96 !% Perdew-Zunger SIC, handled by the OEP technique.
97 !% J. P. Perdew and Alex Zunger, Phys. Rev. B 23, 5048 (1981)
98 !% Extension to the spinor case follows Tancogne-Dejean et al., J. Chem. Phys. 159, 224110 (2023)
99 !%
100 !% Note that the current implement uses canonical orbitals and not minimizing orbitals.
101 !% Please check <tt>SCDMforPZSIC</tt> for using SCDM-based Wannier orbitals instead of canonical orbitals.
102 !%Option sic_amaldi 3
103 !% Amaldi correction term. Not implemeneted for spinors.
104 !% E. Fermi and E. Amaldi, Mem. Reale Accad. Italia 6, 119 (1934)
105 !%Option sic_adsic 4
106 !% Average-density SIC.
107 !% C. Legrand <i>et al.</i>, <i>J. Phys. B</i> <b>35</b>, 1115 (2002).
108 !% Extension to the spinor case follows Tancogne-Dejean et al., J. Chem. Phys. 159, 224110 (2023)
109 !%End
110 call parse_variable(namespace, 'SICCorrection', sic_none, sic%level)
111 if (.not. varinfo_valid_option('SICCorrection', sic%level)) call messages_input_error(namespace, 'SICCorrection')
112
113 ! check whether we should introduce the Amaldi SIC correction
114 sic%amaldi_factor = m_one
115 if (sic%level == sic_amaldi) then
116 sic%amaldi_factor = (st%qtot - m_one)/st%qtot
117 if(st%d%ispin == spinors) then
118 call messages_not_implemented("Amaldi SIC with non-collinear spins")
119 end if
120 end if
121
122 if(sic%level == sic_pz_oep) then
123 call xc_oep_init(sic%oep, namespace, gr, st, mc, space, oep_type = oep_type_sic)
124
125 if(st%nik > st%d%spin_channels) then
126 call messages_not_implemented("PZ-SIC with k-points")
127 end if
128 end if
129
130 if (allocated(st%rho_core)) then
131 call messages_not_implemented('SIC with nonlinear core corrections')
132 end if
133
134 if (allocated(st%frozen_rho) .and. (sic%level == sic_pz_oep .or. sic%level == sic_amaldi)) then
135 call messages_not_implemented('PZ-SIC with frozen orbitals')
136 end if
137
138 if (space%is_periodic() .and. sic%level /= sic_none) then
139 call messages_not_implemented("SIC corrections in periodic systems")
140 end if
141
142 pop_sub(xc_sic_init)
143 end subroutine xc_sic_init
144
145 ! ---------------------------------------------------------
147 subroutine xc_sic_end(sic)
148 type(xc_sic_t), intent(inout) :: sic
149
150 if (sic%level == sic_none) return
152 push_sub(xc_sic_end)
153
154 if(sic%level == sic_pz_oep) call xc_oep_end(sic%oep)
155
156 pop_sub(xc_sic_end)
157 end subroutine xc_sic_end
159
160 ! ---------------------------------------------------------
161 subroutine xc_sic_write_info(sic, iunit, namespace)
162 type(xc_sic_t), intent(in) :: sic
163 integer, optional, intent(in) :: iunit
164 type(namespace_t), optional, intent(in) :: namespace
165
166 if (sic%level == sic_none) return
167
168 push_sub(xc_sic_write_info)
169
170 call messages_print_var_option('SICCorrection', sic%level, iunit=iunit, namespace=namespace)
171
172 pop_sub(xc_sic_write_info)
173 end subroutine xc_sic_write_info
174
175 ! ---------------------------------------------------------
192 subroutine xc_sic_calc_adsic(sic, namespace, space, gr, st, hm, xc, density, vxc, ex, ec)
193 type(xc_sic_t), intent(in) :: sic
194 type(namespace_t), intent(in) :: namespace
195 class(space_t), intent(in) :: space
196 type(grid_t), intent(in) :: gr
197 type(states_elec_t), intent(in) :: st
198 type(hamiltonian_elec_t), intent(in) :: hm
199 type(xc_t), intent(inout) :: xc
200 real(real64), contiguous, intent(in) :: density(:,:)
201 real(real64), contiguous, intent(inout) :: vxc(:,:)
202 real(real64), optional, intent(inout) :: ex, ec
203
204 integer :: ispin, ist, ik, ip
205 real(real64), allocatable :: vxc_sic(:,:), vh_sic(:), rho(:, :)
206 real(real64) :: ex_sic, ec_sic, qsp(2)
207 real(real64) :: dtot, dpol, vpol
208 real(real64) :: nup
209
210 push_sub(xc_sic_calc_adsic)
211
212 assert(sic%level == sic_adsic)
213
214 if (st%d%ispin == spinors .and. .not. in_family(hm%xc%family, [xc_family_lda, xc_family_gga])) then
215 write(message(1),'(a)') 'ADSIC with non-collinear spin is currently only possible'
216 write(message(2),'(a)') 'with LDA and GGA functionals.'
217 call messages_fatal(2, namespace=namespace)
218 end if
219
220 if (xc_is_not_size_consistent(xc, namespace)) then
221 call messages_not_implemented('ADSIC with size inconsistent functionals', namespace=namespace)
222 end if
223
224 ! We compute here the number of electrons per spin channel
225 qsp = m_zero
226 if( .not. allocated(st%frozen_rho)) then
227 select case (st%d%ispin)
229 do ist = 1, st%nst
230 do ik = 1, st%nik
231 ispin = st%d%get_spin_index(ik)
232 qsp(ispin) = qsp(ispin) + st%occ(ist, ik) * st%kweights(ik)
233 end do
234 end do
235 end select
236 else
237 ! In the case of the frozen density, we can only get the charge from the integral
238 ! of the total density, including valence and frozen density
239 qsp(1:st%d%nspin) = dmf_integrate(gr, st%d%nspin, density)
240 end if
241
242 safe_allocate(vxc_sic(1:gr%np, 1:2))
243 safe_allocate(vh_sic(1:gr%np))
244 safe_allocate(rho(1:gr%np, 1:2))
245 ! We first compute the average xc self-interction error and we substract it
246 select case (st%d%ispin)
248 do ispin = 1, st%d%nspin
249 if (abs(qsp(ispin)) <= m_min_occ) cycle
250
251 rho = m_zero
252 vxc_sic = m_zero
253
254 rho(:, ispin) = density(:, ispin) / qsp(ispin)
255 if(present(ex) .and. present(ec)) then
256 ex_sic = m_zero
257 ec_sic = m_zero
258 ! This needs always to be called for the spin-polarized case
259 call xc_get_vxc(gr, xc, st, hm%kpoints, hm%psolver, namespace, space, &
260 rho, spin_polarized, hm%ions%latt%rcell_volume, vxc_sic, ex = ex_sic, ec = ec_sic)
261 ex = ex - ex_sic * qsp(ispin)
262 ec = ec - ec_sic * qsp(ispin)
263 else
264 ! This needs always to be called for the spin-polarized case
265 call xc_get_vxc(gr, xc, st, hm%kpoints, hm%psolver, namespace, space, &
266 rho, spin_polarized, hm%ions%latt%rcell_volume, vxc_sic)
267 end if
268
269 call lalg_axpy(gr%np, -m_one, vxc_sic(:, ispin), vxc(:, ispin))
270
271 ! We now substract the averaged Hartree self-interaction error
272 ! See Eq. 15 in [Pietezak and Vieira, Theoretical Chemistry Accounts (2021) 140:130]
273 vh_sic = m_zero
274 call dpoisson_solve(hm%psolver, namespace, vh_sic, rho(:, ispin), all_nodes=.false.)
275 call lalg_axpy(gr%np, -m_one, vh_sic, vxc(:, ispin))
276
277 ! Compute the corresponding energy contribution
278 if(present(ex)) then
279 ex = ex - m_half*dmf_dotp(gr, rho(:,ispin), vh_sic) * qsp(ispin)
280 end if
281
282 end do
283
284 case (spinors)
285 ! Here we only treat the case of LDA/GGA. We rotate the average density in the local frame
286 ! And we then compute the SIC correction from it
287 ! This cannot excerce any xc torque, by construction
288 assert(in_family(hm%xc%family, [xc_family_lda, xc_family_gga]))
289
290 do ispin = 1, 2
291 rho = m_zero
292 vxc_sic = m_zero
293 ! Averaged density in the local frame
294 do ip = 1, gr%np
295 dtot = density(ip, 1) + density(ip, 2)
296 dpol = sqrt((density(ip, 1) - density(ip, 2))**2 + &
297 m_four*(density(ip, 3)**2 + density(ip, 4)**2))
298 if(ispin == 1) then
299 rho(ip, 1) = max(m_half*(dtot + dpol), m_zero)
300 else
301 rho(ip, 2) = max(m_half*(dtot - dpol), m_zero)
302 end if
303 end do
304 nup = dmf_integrate(gr, rho(:,ispin))
305 if (nup <= 1e-14_real64) cycle
306 call lalg_scal(gr%np, m_one/nup, rho(:,ispin))
307
308 ! This needs always to be called for the spin-polarized case
309 if(present(ex) .and. present(ec)) then
310 ex_sic = m_zero
311 ec_sic = m_zero
312 call xc_get_vxc(gr, xc, st, hm%kpoints, hm%psolver, namespace, space, &
313 rho, spin_polarized, hm%ions%latt%rcell_volume, vxc_sic, ex = ex_sic, ec = ec_sic)
314 ex = ex - ex_sic * nup
315 ec = ec - ec_sic * nup
316 else
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)
319 end if
320
321 ! Select only the potential correspond to this spin channel
322 if(ispin == 2) then
323 vxc_sic(:, 1) = m_zero
324 else
325 vxc_sic(:, 2) = m_zero
326 end if
327
328 vh_sic = m_zero
329 call dpoisson_solve(hm%psolver, namespace, vh_sic, rho(:, ispin), all_nodes=.false.)
330 call lalg_axpy(gr%np, m_one, vh_sic, vxc_sic(:, ispin))
331 ! Compute the corresponding energy contribution
332 if(present(ex)) then
333 ex = ex - m_half*dmf_dotp(gr, rho(:,ispin), vh_sic) * nup
334 end if
335
336 do ip = 1, gr%np
337 dpol = sqrt((density(ip, 1) - density(ip, 2))**2 + &
338 m_four*(density(ip, 3)**2 + density(ip, 4)**2))
339 vpol = (vxc_sic(ip, 1) - vxc_sic(ip, 2))*(density(ip, 1) - density(ip, 2))/(safe_tol(dpol, xc_tiny))
340
341 vxc(ip, 1) = vxc(ip, 1) - m_half*(vxc_sic(ip, 1) + vxc_sic(ip, 2) + vpol)
342 vxc(ip, 2) = vxc(ip, 2) - m_half*(vxc_sic(ip, 1) + vxc_sic(ip, 2) - vpol)
343 vxc(ip, 3) = vxc(ip, 3) - (vxc_sic(ip, 1) - vxc_sic(ip, 2))*density(ip, 3)/(safe_tol(dpol, xc_tiny))
344 vxc(ip, 4) = vxc(ip, 4) - (vxc_sic(ip, 1) - vxc_sic(ip, 2))*density(ip, 4)/(safe_tol(dpol, xc_tiny))
345 end do
346 end do
347
348
349 end select
350
351 safe_deallocate_a(vxc_sic)
352 safe_deallocate_a(vh_sic)
353 safe_deallocate_a(rho)
354
355 pop_sub(xc_sic_calc_adsic)
356 end subroutine xc_sic_calc_adsic
357
358 ! ---------------------------------------------------------
362 subroutine xc_sic_add_fxc_adsic(namespace, xc, st, gr, rho, fxc)
363 type(namespace_t), intent(in) :: namespace
364 type(xc_t), intent(in) :: xc
365 type(states_elec_t), intent(in) :: st
366 type(grid_t), intent(in) :: gr
367 real(real64), intent(in) :: rho(:,:)
368 real(real64), contiguous, intent(inout) :: fxc(:,:,:)
369
370 real(real64), allocatable :: rho_averaged(:, :)
371 real(real64), allocatable :: fxc_sic(:,:,:)
372 real(real64) :: qtot
373 integer :: ispin
374
375 push_sub(xc_sic_add_fxc_adsic)
376
377 !Check spin and triplets
378 assert(st%d%ispin /= spinors)
379 assert(.not. allocated(st%frozen_rho))
380
381 if (bitand(xc%kernel_family, xc_family_lda) == 0) then
382 message(1) = "fxc calculation with ADSIC not implemented beyond LDAs."
383 call messages_fatal(1, namespace=namespace)
384 end if
385
386 if (xc_is_not_size_consistent(xc, namespace)) then
387 call messages_not_implemented('ADSIC with size inconsistent functionals', namespace=namespace)
388 end if
389
390 if (st%d%ispin == spinors) then
391 call messages_not_implemented('ADSIC fxc with non-collinear spin')
392 end if
393
394 ! This needs always to be called for the spin-polarized case
395 safe_allocate(rho_averaged(1:gr%np, 1:2))
396 safe_allocate(fxc_sic(1:gr%np, 1:2, 1:2))
397
398 do ispin = 1, st%d%nspin
399 rho_averaged = m_zero
400 qtot = dmf_integrate(gr, rho(:, ispin))
401 if (abs(qtot) <= m_min_occ) cycle
402
403 call lalg_copy(gr%np, rho(:, ispin), rho_averaged(:, ispin))
404 call lalg_scal(gr%np, m_one/qtot, rho_averaged(:, ispin))
405
406 fxc_sic = m_zero
407 call xc_get_fxc(xc, gr, namespace, rho_averaged, spin_polarized, fxc_sic)
408
409 call lalg_axpy(gr%np, -m_one/qtot, fxc_sic(:, ispin, ispin), fxc(:, ispin, ispin))
410 end do
411
412 safe_deallocate_a(rho_averaged)
413 safe_deallocate_a(fxc_sic)
414
415 pop_sub(xc_sic_add_fxc_adsic)
416 end subroutine xc_sic_add_fxc_adsic
417
418end module xc_sic_oct_m
419
420!! Local Variables:
421!! mode: f90
422!! coding: utf-8
423!! 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:214
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:1091
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:875
This module handles spin dimensions of the states and the k-point distribution.
Definition: xc.F90:116
real(real64), parameter, public xc_tiny
Arbitrary definition of tiny, for use in XC context.
Definition: xc.F90:216
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.F90:772
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:736
subroutine, public xc_get_fxc(xcs, gr, namespace, rho, ispin, fxc, fxc_grad, fxc_grad_spin)
Returns the exchange-correlation kernel.
Definition: xc.F90:2002
pure logical function, public in_family(family, xc_families)
Definition: xc.F90:621
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:257
integer, parameter, public sic_adsic
Averaged density SIC.
Definition: xc_sic.F90:151
subroutine, public xc_sic_init(sic, namespace, gr, st, mc, space)
initialize the SIC object
Definition: xc_sic.F90:171
subroutine, public xc_sic_end(sic)
finalize the SIC and, if needed, the included OEP
Definition: xc_sic.F90:243
integer, parameter, public sic_pz_oep
Perdew-Zunger SIC (OEP way)
Definition: xc_sic.F90:151
integer, parameter, public sic_amaldi
Amaldi correction term.
Definition: xc_sic.F90:151
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:288
subroutine, public xc_sic_add_fxc_adsic(namespace, xc, st, gr, rho, fxc)
Adds to fxc the ADSIC contribution.
Definition: xc_sic.F90:458
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:158