(git:27c966b)
Loading...
Searching...
No Matches
qs_electrons_ne_electrode.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 Ne-electrode core-charge correction for constant-potential MD: adjusts the Ne
10!> pseudopotential core charge to follow the fluctuating total electron number.
11!> \author Nanchen DONGFANG
12! **************************************************************************************************
14 USE ieee_arithmetic, ONLY: ieee_is_finite
23 USE kinds, ONLY: dp
26 USE qs_kind_types, ONLY: get_qs_kind,&
29 USE qs_ks_types, ONLY: qs_ks_env_type,&
31#include "./base/base_uses.f90"
32
33 IMPLICIT NONE
34
35 PRIVATE
37
38 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_electrons_ne_electrode'
39
40CONTAINS
41
42! **************************************************************************************************
43!> \brief Apply Ne core correction update from the current total electron number.
44!>
45!> It is called directly on force_env once per
46!> MD step, right after qs_electrons_drift updates electrons%q, and before the SCF
47!> call, since it changes the Ne pseudopotential and must be in effect for the SCF
48!> that immediately follows.
49!>
50!> Receives the target total electron number and converts it to a per-Ne core
51!> correction using core_corr_ne = (target_nelect - neutral_electrons_ref)/N_ne.
52!> It applies the resulting value to all Ne atomic kinds in the QS subsystem by
53!> updating the underlying all-electron or GTH/SGP potential zeff_correction
54!> field. This effectively corresponds to adjusting the CORE_CORRECTION keyword
55!> for Ne.
56!>
57!> The implementation traverses the QS environment, obtains the atomic kind
58!> and QS kind arrays, and for each kind whose element symbol is 'Ne' it
59!> updates zeff_correction := core_corr_ne and keeps the associated effective
60!> charge parameters consistent with a statically parsed CORE_CORRECTION input.
61!> The resulting change is reflected in the subsequent charge and electron
62!> counts through the existing zeff_correction usage in QS routines.
63!> \param force_env ...
64!> \param target_nelect ...
65!> \param neutral_electrons_ref ...
66! **************************************************************************************************
67 SUBROUTINE apply_ne_core_correction(force_env, target_nelect, neutral_electrons_ref)
68
69 TYPE(force_env_type), POINTER :: force_env
70 REAL(kind=dp), INTENT(IN) :: target_nelect, neutral_electrons_ref
71
72 CHARACTER(LEN=*), PARAMETER :: routinen = 'apply_ne_core_correction'
73 REAL(kind=dp), PARAMETER :: core_corr_refresh_tol = 1.0e-12_dp
74
75 CHARACTER(LEN=2) :: elem
76 INTEGER :: handle, ikind, iparticle, n_ne_atoms, &
77 nkind, output_unit
78 LOGICAL :: core_corr_changed, found_ne
79 REAL(kind=dp) :: base_zeff, core_corr_ne, delta_q, &
80 new_zeff, old_zeff, zeff_scale
81 TYPE(all_potential_type), POINTER :: all_potential
82 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
83 TYPE(atomic_kind_type), POINTER :: atomic_kind
84 TYPE(cp_subsys_type), POINTER :: cp_subsys
85 TYPE(gth_potential_type), POINTER :: gth_potential
86 TYPE(qs_environment_type), POINTER :: qs_env
87 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
88 TYPE(qs_kind_type), POINTER :: qs_kind
89 TYPE(qs_ks_env_type), POINTER :: ks_env
90 TYPE(sgp_potential_type), POINTER :: sgp_potential
91
92 CALL timeset(routinen, handle)
93
94 IF (.NOT. ieee_is_finite(target_nelect) .OR. target_nelect <= 0.0_dp) THEN
95 cpabort("target electron count must be positive.")
96 END IF
97 IF (.NOT. ieee_is_finite(neutral_electrons_ref) .OR. neutral_electrons_ref <= 0.0_dp) THEN
98 cpabort("neutral_electrons_ref must be positive.")
99 END IF
100
101 ! Obtain QS environment and atomic kind / kind sets. If this is not a
102 ! QS calculation there is nothing to do.
103 NULLIFY (qs_env)
104 CALL force_env_get(force_env, qs_env=qs_env)
105 IF (.NOT. ASSOCIATED(qs_env)) THEN
106 cpabort("Ne correction requires a QS force environment.")
107 END IF
108
109 NULLIFY (cp_subsys)
110 CALL force_env_get(force_env, subsys=cp_subsys)
111 IF (.NOT. ASSOCIATED(cp_subsys)) THEN
112 cpabort("Ne correction could not access CP2K subsys.")
113 END IF
114
115 NULLIFY (atomic_kind_set)
116 NULLIFY (qs_kind_set)
117 NULLIFY (ks_env)
118 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, &
119 qs_kind_set=qs_kind_set, ks_env=ks_env)
120
121 IF (.NOT. (ASSOCIATED(atomic_kind_set) .AND. ASSOCIATED(qs_kind_set))) THEN
122 cpabort("Ne correction could not access kind sets.")
123 END IF
124
125 nkind = SIZE(atomic_kind_set, 1)
126 found_ne = .false.
127 core_corr_changed = .false.
128 n_ne_atoms = 0
129
130 DO iparticle = 1, cp_subsys%particles%n_els
131 atomic_kind => cp_subsys%particles%els(iparticle)%atomic_kind
132 IF (ASSOCIATED(atomic_kind)) THEN
133 elem = atomic_kind%element_symbol
134 elem = adjustl(elem)
135 IF (trim(elem) == 'Ne' .OR. trim(elem) == 'NE') THEN
136 n_ne_atoms = n_ne_atoms + 1
137 END IF
138 END IF
139 END DO
140
141 IF (n_ne_atoms <= 0) THEN
142 cpabort("Ne mode requested but no Ne atoms found.")
143 END IF
144
145 delta_q = target_nelect - neutral_electrons_ref
146 core_corr_ne = delta_q/real(n_ne_atoms, kind=dp)
147
148 DO ikind = 1, nkind
149 atomic_kind => atomic_kind_set(ikind)
150 qs_kind => qs_kind_set(ikind)
151
152 ! Identify Ne atomic kinds by their element symbol. Compare against
153 ! the canonical two-character symbol "Ne" (and its fully uppercase
154 ! variant) after left adjustment.
155 elem = atomic_kind%element_symbol
156 elem = adjustl(elem)
157
158 IF (trim(elem) == 'Ne' .OR. trim(elem) == 'NE') THEN
159 found_ne = .true.
160 NULLIFY (all_potential)
161 NULLIFY (gth_potential)
162 NULLIFY (sgp_potential)
163
164 CALL get_qs_kind(qs_kind, all_potential=all_potential, gth_potential=gth_potential, &
165 sgp_potential=sgp_potential)
166
167 IF (ASSOCIATED(all_potential)) THEN
168 IF (abs(all_potential%zeff_correction - core_corr_ne) > core_corr_refresh_tol) THEN
169 old_zeff = all_potential%zeff
170 base_zeff = old_zeff - all_potential%zeff_correction
171 new_zeff = base_zeff + core_corr_ne
172 IF (abs(old_zeff) > epsilon(1.0_dp)) THEN
173 zeff_scale = new_zeff/old_zeff
174 all_potential%ccore_charge = all_potential%ccore_charge*zeff_scale
175 END IF
176 all_potential%zeff = new_zeff
177 all_potential%zeff_correction = core_corr_ne
178 core_corr_changed = .true.
179 END IF
180 END IF
181 IF (ASSOCIATED(gth_potential)) THEN
182 IF (abs(gth_potential%zeff_correction - core_corr_ne) > core_corr_refresh_tol) THEN
183 old_zeff = gth_potential%zeff
184 base_zeff = old_zeff - gth_potential%zeff_correction
185 new_zeff = base_zeff + core_corr_ne
186 IF (abs(old_zeff) > epsilon(1.0_dp)) THEN
187 zeff_scale = new_zeff/old_zeff
188 gth_potential%ccore_charge = gth_potential%ccore_charge*zeff_scale
189 gth_potential%cerf_ppl = gth_potential%cerf_ppl*zeff_scale
190 END IF
191 gth_potential%zeff = new_zeff
192 gth_potential%zeff_correction = core_corr_ne
193 core_corr_changed = .true.
194 END IF
195 END IF
196 IF (ASSOCIATED(sgp_potential)) THEN
197 IF (abs(sgp_potential%zeff_correction - core_corr_ne) > core_corr_refresh_tol) THEN
198 old_zeff = sgp_potential%zeff
199 base_zeff = old_zeff - sgp_potential%zeff_correction
200 new_zeff = base_zeff + core_corr_ne
201 IF (abs(old_zeff) > epsilon(1.0_dp)) THEN
202 zeff_scale = new_zeff/old_zeff
203 sgp_potential%ccore_charge = sgp_potential%ccore_charge*zeff_scale
204 END IF
205 sgp_potential%zeff = new_zeff
206 sgp_potential%zeff_correction = core_corr_ne
207 core_corr_changed = .true.
208 END IF
209 END IF
210 END IF
211 END DO
212
213 IF (.NOT. found_ne) THEN
214 cpabort("no Ne atomic kind was found.")
215 END IF
216
217 output_unit = cp_logger_get_default_io_unit()
218 IF (output_unit > 0) THEN
219 WRITE (output_unit, *) " @ DRIVER MODE: Ne-electrode target_nelect = ", target_nelect, &
220 " neutral_electrons = ", neutral_electrons_ref
221 WRITE (output_unit, *) " @ DRIVER MODE: Ne atoms = ", n_ne_atoms, &
222 " CORE_CORRECTION per Ne = ", core_corr_ne
223 IF (.NOT. core_corr_changed) THEN
224 WRITE (output_unit, *) " @ DRIVER MODE: Ne CORE_CORRECTION refresh skipped; change <= ", &
225 core_corr_refresh_tol
226 END IF
227 END IF
228
229 IF (core_corr_changed) THEN
230 CALL get_qs_kind_set(qs_kind_set, total_zeff_corr=qs_env%total_zeff_corr)
231 END IF
232
233 IF (core_corr_changed .AND. ASSOCIATED(ks_env)) THEN
234 CALL set_ks_env(ks_env, potential_changed=.true., &
235 forces_up_to_date=.false.)
236 END IF
237
238 CALL timestop(handle)
239
240 END SUBROUTINE apply_ne_core_correction
241
Define the atomic kind types and their sub types.
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
types that represent a subsys, i.e. a part of the system
Definition of the atomic potential types.
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
returns various attributes about the force environment
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Ne-electrode core-charge correction for constant-potential MD: adjusts the Ne pseudopotential core ch...
subroutine, public apply_ne_core_correction(force_env, target_nelect, neutral_electrons_ref)
Apply Ne core correction update from the current total electron number.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, do_mtlr_present, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
subroutine, public set_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, kpoints, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env)
...
Provides all information about an atomic kind.
represents a system: atoms, molecules, their pos,vel,...
wrapper to abstract the force evaluation of the various methods
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...