(git:27c966b)
Loading...
Searching...
No Matches
qs_electrons_utils.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Propagation of the electronic degree of freedom in constant-potential MD:
10!> generalized force, momentum kick, position drift and CSVR potentiostat step.
11!> \author Nanchen DONGFANG
12! **************************************************************************************************
15 USE kinds, ONLY: dp
16 USE physcon, ONLY: femtoseconds,&
17 kelvin
19#include "./base/base_uses.f90"
20
21 IMPLICIT NONE
22
23 PRIVATE
24 PUBLIC :: qs_electrons_force, &
28
29 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_electrons_utils'
30 REAL(KIND=dp), PARAMETER, PRIVATE :: hartree_to_ev = 27.211386245988_dp
31
32CONTAINS
33
34! **************************************************************************************************
35!> \brief Generalized electronic force: deviation of the current work function
36!> from the target, driving q toward the requested constant-potential state.
37!> \param electrons ...
38!> \return ...
39! **************************************************************************************************
40 FUNCTION qs_electrons_force(electrons) RESULT(force)
41 TYPE(qs_electrons_type), POINTER :: electrons
42 REAL(kind=dp) :: force
43
44 cpassert(ASSOCIATED(electrons))
45 IF (electrons%control_fermi) THEN
46 ! Fermi-level control. The sign is OPPOSITE to work-function control,
47 ! and deliberately so: dPhi/dq < 0 while d(e_F)/dq > 0, so the restoring
48 ! force has to change sign with the controlled variable:
49 ! current_workfunction - target_workfunction (workfunction mode)
50 ! target_ef - current_ef (fermi mode)
51 force = (electrons%target_fermi_level - electrons%current_fermi_level_eV)/hartree_to_ev
52 ELSE
53 force = (electrons%current_workfunction - electrons%target_workfunction)/hartree_to_ev
54 END IF
55
56 END FUNCTION qs_electrons_force
57
58! **************************************************************************************************
59!> \brief Half-kick of the electronic momentum from the current generalized force.
60!> \param electrons ...
61!> \param dt ...
62! **************************************************************************************************
63 SUBROUTINE qs_electrons_kick(electrons, dt)
64 TYPE(qs_electrons_type), POINTER :: electrons
65 REAL(kind=dp), INTENT(IN) :: dt
66
67 cpassert(ASSOCIATED(electrons))
68 ! A fixed mixing weight means q carries no dynamics: freeze it rather than
69 ! letting it drift under a force that no longer influences the mixing.
70 IF (electrons%lambda_is_fixed) RETURN
71 electrons%p = electrons%p + qs_electrons_force(electrons)*dt
72
73 END SUBROUTINE qs_electrons_kick
74
75! **************************************************************************************************
76!> \brief Drift of the electronic coordinate (total electron number).
77!> \param electrons ...
78!> \param dt ...
79! **************************************************************************************************
80 SUBROUTINE qs_electrons_drift(electrons, dt)
81 TYPE(qs_electrons_type), POINTER :: electrons
82 REAL(kind=dp), INTENT(IN) :: dt
83
84 cpassert(ASSOCIATED(electrons))
85 IF (electrons%lambda_is_fixed) RETURN
86 electrons%q = electrons%q + electrons%p*dt/electrons%mass
87
88 END SUBROUTINE qs_electrons_drift
89
90! **************************************************************************************************
91!> \brief Stochastic velocity rescaling ("O" step) of the electronic momentum,
92!> reusing CP2K's own CSVR rescaling_factor (Bussi-Donadio-Parrinello).
93!> \param electrons ...
94!> \param dt ...
95! **************************************************************************************************
96 SUBROUTINE qs_electrons_thermostat_step(electrons, dt)
97 TYPE(qs_electrons_type), POINTER :: electrons
98 REAL(kind=dp), INTENT(IN) :: dt
99
100 REAL(kind=dp) :: alpha, kk, old_kinetic, sigma, taut
101
102 cpassert(ASSOCIATED(electrons))
103
104 old_kinetic = 0.5_dp*electrons%p**2/electrons%mass
105 kk = old_kinetic
106 ! kelvin is the [a.u.] -> [K] conversion factor from physcon, so dividing
107 ! a temperature in K by it directly yields k_B*T in Hartree atomic units
108 ! -- this is the same idiom CP2K's own thermostat code uses, avoiding any
109 ! SI/atomic-unit mismatch with the (atomic-units) kinetic energy above.
110 ! sigma is the target kinetic energy ndeg*k_B*T/2 of the single (ndeg = 1)
111 ! electronic degree of freedom.
112 sigma = 0.5_dp*electrons%temp_potentiostat/kelvin
113
114 ! rescaling_factor expects taut expressed in units of "how often this
115 ! routine is called" (see csvr_system_utils.F). tau_potentiostat is a
116 ! plain number in femtoseconds, so the fs -> a.u. conversion is required.
117 !
118 ! NOTE ON THE ARGUMENT: dt here is the INTERVAL BETWEEN SUCCESSIVE CALLS,
119 ! not the MD timestep. It used to be the MD timestep with a hard-wired
120 ! 0.5 factor baked in, which silently assumed the OBABO placement (two
121 ! calls per step). Under BAOAB the potentiostat fires ONCE per step, so
122 ! the caller must be free to say so; nvt() now passes dt_md for BAOAB and
123 ! langevin() passes 0.5*dt_md for its OBABO placement. Getting this wrong
124 ! changes the damping by a factor of two without any other symptom.
125 taut = (electrons%tau_potentiostat/femtoseconds)/dt
126
127 ! ndeg = 1: q is a single genuine degree of freedom. With ndeg /= 1 the
128 ! sumnoises(ndeg-1, ...) term samples toward 2-DOF kinetic-energy
129 ! statistics and rescaling_factor also disables the momentum-reversal
130 ! branch that gives the correct Langevin limit at ndeg = 1.
131 alpha = rescaling_factor(kk, sigma, 1, taut, electrons%gaussian_rng_stream)
132 electrons%p = electrons%p*alpha
133 electrons%thermostat_energy = electrons%thermostat_energy + &
134 old_kinetic - 0.5_dp*electrons%p**2/electrons%mass
135
136 END SUBROUTINE qs_electrons_thermostat_step
137
138END MODULE qs_electrons_utils
real(kind=dp) function, public rescaling_factor(kk, sigma, ndeg, taut, rng_stream)
Stochastic velocity rescale, as described in Bussi, Donadio and Parrinello, J. Chem....
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public femtoseconds
Definition physcon.F:153
real(kind=dp), parameter, public kelvin
Definition physcon.F:165
State of the fictitious electronic degree of freedom (electron number q, its momentum,...
Propagation of the electronic degree of freedom in constant-potential MD: generalized force,...
real(kind=dp) function, public qs_electrons_force(electrons)
Generalized electronic force: deviation of the current work function from the target,...
subroutine, public qs_electrons_drift(electrons, dt)
Drift of the electronic coordinate (total electron number).
subroutine, public qs_electrons_thermostat_step(electrons, dt)
Stochastic velocity rescaling ("O" step) of the electronic momentum, reusing CP2K's own CSVR rescalin...
subroutine, public qs_electrons_kick(electrons, dt)
Half-kick of the electronic momentum from the current generalized force.