63#include "./base/base_uses.f90"
68 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_density_fit'
88 INTEGER,
INTENT(IN) :: max_iter
89 REAL(kind=
dp),
INTENT(IN) :: eps_rms, step_size
90 INTEGER,
INTENT(IN) :: max_backtrack
92 CALL fit_density_matrix(qs_env, rho_struct, max_iter, eps_rms, step_size, max_backtrack)
110 entropy_weight, max_iter, eps_rms, step_size, max_backtrack)
113 TYPE(
dbcsr_type),
INTENT(IN) :: prior_hamiltonian
114 REAL(kind=
dp),
INTENT(IN) :: temperature, entropy_weight
115 INTEGER,
INTENT(IN) :: max_iter
116 REAL(kind=
dp),
INTENT(IN) :: eps_rms, step_size
117 INTEGER,
INTENT(IN) :: max_backtrack
119 CALL fit_density_matrix(qs_env, rho_struct, max_iter, eps_rms, step_size, max_backtrack, &
120 prior_hamiltonian, temperature, entropy_weight)
136 SUBROUTINE fit_density_matrix(qs_env, rho_struct, max_iter, eps_rms, step_size, max_backtrack, &
137 prior_hamiltonian, temperature, entropy_weight)
140 INTEGER,
INTENT(IN) :: max_iter
141 REAL(kind=
dp),
INTENT(IN) :: eps_rms, step_size
142 INTEGER,
INTENT(IN) :: max_backtrack
143 TYPE(
dbcsr_type),
INTENT(IN),
OPTIONAL :: prior_hamiltonian
144 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: temperature, entropy_weight
146 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fit_density_matrix'
148 INTEGER :: backtrack, handle, i, info, iteration, &
149 nao, nelectron, unit_nr
150 LOGICAL :: accepted, converged, do_kpoints, &
151 have_previous, use_relative_entropy
152 REAL(kind=
dp) :: alpha, chemical_potential, commutator_norm, direction_derivative, &
153 direction_norm2, fitted_grid_trace, idempotency_error, matrix_trace, objective, &
154 objective_trial, prior_fraction, prior_log_one_minus, relative_entropy, &
155 relative_entropy_trial, relative_temperature, relative_weight, rms, rms_trial, ss, &
157 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues, prior_eigenvalues, &
158 prior_logit_values, prior_occupations
159 REAL(kind=
dp),
DIMENSION(:),
POINTER :: tot_rho_r
162 TYPE(
cp_fm_type) :: density_orth, direction_orth, eigenvectors, gradient_orth, &
163 hamiltonian_orth, overlap_chol, previous_density, previous_gradient, prior_logit, &
164 trial_orth, work1, work2
167 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, rho_ao
177 CALL timeset(routinen, handle)
179 use_relative_entropy =
PRESENT(prior_hamiltonian)
180 cpassert(use_relative_entropy .EQV.
PRESENT(temperature))
181 cpassert(use_relative_entropy .EQV.
PRESENT(entropy_weight))
182 IF (use_relative_entropy)
THEN
183 relative_temperature = temperature
184 relative_weight = entropy_weight
185 cpassert(relative_temperature > 0.0_dp)
186 cpassert(relative_weight >= 0.0_dp)
188 relative_temperature = 1.0_dp
189 relative_weight = 0.0_dp
192 NULLIFY (auxbas_pw_pool, blacs_env, dft_control, fm_struct, gradient_ao%matrix, &
193 ks_env, matrix_s, para_env, pw_env, rho_ao, rho_g, rho_r, tot_rho_r)
195 CALL get_qs_env(qs_env, blacs_env=blacs_env, dft_control=dft_control, &
196 do_kpoints=do_kpoints, ks_env=ks_env, matrix_s=matrix_s, &
197 nelectron_total=nelectron, para_env=para_env, pw_env=pw_env)
199 IF (do_kpoints) cpabort(
"Harris CUBE_FIT is currently available only at the Gamma point")
200 IF (dft_control%nspins /= 1)
THEN
201 cpabort(
"Harris CUBE_FIT currently requires a spin-restricted calculation")
203 IF (dft_control%qs_control%gapw) cpabort(
"Harris CUBE_FIT currently supports GPW only")
205 CALL qs_rho_get(rho_struct, rho_ao=rho_ao, rho_r=rho_r, rho_g=rho_g, tot_rho_r=tot_rho_r)
206 cpassert(
ASSOCIATED(rho_ao) .AND.
SIZE(rho_ao) == 1)
207 cpassert(
ASSOCIATED(rho_r) .AND.
SIZE(rho_r) == 1)
208 cpassert(
ASSOCIATED(rho_g) .AND.
SIZE(rho_g) == 1)
211 IF (nelectron < 0 .OR. nelectron > 2*nao)
THEN
212 cpabort(
"Electron count is incompatible with the constrained AO density-matrix bounds")
215 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
216 CALL auxbas_pw_pool%create_pw(target_rspace)
217 CALL auxbas_pw_pool%create_pw(residual_rspace)
218 CALL pw_copy(rho_r(1), target_rspace)
220 ALLOCATE (gradient_ao%matrix)
221 CALL dbcsr_create(gradient_ao%matrix, template=matrix_s(1)%matrix, &
222 name=
"Harris density-fit gradient", matrix_type=dbcsr_type_symmetric)
223 CALL dbcsr_copy(gradient_ao%matrix, matrix_s(1)%matrix)
224 CALL dbcsr_set(gradient_ao%matrix, 0.0_dp)
227 nrow_global=nao, ncol_global=nao)
228 CALL cp_fm_create(overlap_chol, fm_struct, name=
"density-fit overlap")
229 CALL cp_fm_create(density_orth, fm_struct, name=
"density fit in orthogonal basis")
230 CALL cp_fm_create(direction_orth, fm_struct, name=
"density-fit search direction")
231 CALL cp_fm_create(gradient_orth, fm_struct, name=
"density-fit gradient in orthogonal basis")
232 CALL cp_fm_create(previous_density, fm_struct, name=
"previous density-fit matrix")
233 CALL cp_fm_create(previous_gradient, fm_struct, name=
"previous density-fit gradient")
234 CALL cp_fm_create(trial_orth, fm_struct, name=
"density-fit trial matrix")
235 CALL cp_fm_create(eigenvectors, fm_struct, name=
"density-fit eigenvectors")
236 IF (use_relative_entropy)
THEN
237 CALL cp_fm_create(hamiltonian_orth, fm_struct, name=
"relative-entropy prior Hamiltonian")
238 CALL cp_fm_create(prior_logit, fm_struct, name=
"relative-entropy prior logit")
240 CALL cp_fm_create(work1, fm_struct, name=
"density-fit work matrix 1")
241 CALL cp_fm_create(work2, fm_struct, name=
"density-fit work matrix 2")
243 ALLOCATE (eigenvalues(nao))
244 IF (use_relative_entropy)
THEN
245 ALLOCATE (prior_eigenvalues(nao), prior_logit_values(nao), prior_occupations(nao))
251 IF (info /= 0) cpabort(
"Overlap Cholesky decomposition failed in Harris CUBE_FIT")
254 IF (use_relative_entropy)
THEN
259 "SOLVE", pos=
"LEFT", transa=
"T")
261 "SOLVE", pos=
"RIGHT")
263 CALL cp_fm_syevd(work1, eigenvectors, prior_eigenvalues)
264 CALL fixed_trace_fermi_occupations(prior_eigenvalues, real(nelectron,
dp), &
265 relative_temperature, chemical_potential, prior_occupations)
266 CALL matrix_from_eigensystem(eigenvectors, prior_occupations, density_orth, work1)
267 prior_log_one_minus = 0.0_dp
269 prior_fraction = clipped_occupation_fraction(prior_occupations(i))
270 prior_logit_values(i) = log(prior_fraction/(1.0_dp - prior_fraction))
271 prior_log_one_minus = prior_log_one_minus + log(1.0_dp - prior_fraction)
273 CALL matrix_from_eigensystem(eigenvectors, prior_logit_values, prior_logit, work1)
279 "MULTIPLY", pos=
"RIGHT", transa=
"T")
280 CALL project_density_matrix(density_orth, eigenvectors, work1, eigenvalues, &
281 REAL(nelectron,
dp), 2.0_dp)
282 chemical_potential = 0.0_dp
283 prior_log_one_minus = 0.0_dp
285 CALL orthogonal_to_ao(density_orth, overlap_chol, work1, work2, nao)
287 CALL evaluate_density_fit(qs_env, ks_env, rho_ao, rho_r, rho_g, tot_rho_r, &
288 target_rspace, residual_rspace, objective, rms)
289 relative_entropy = 0.0_dp
290 IF (use_relative_entropy)
THEN
291 CALL fermionic_relative_entropy(density_orth, prior_logit, eigenvectors, work1, &
292 eigenvalues, prior_log_one_minus, relative_entropy)
293 objective = objective + relative_weight*relative_entropy
297 IF (logger%para_env%is_source())
THEN
302 IF (unit_nr > 0)
THEN
303 IF (use_relative_entropy)
THEN
304 WRITE (unit_nr,
"(/,T3,A,I0)") &
305 "HARRIS| Relative-entropy AO density reconstruction; basis functions: ", nao
306 WRITE (unit_nr,
"(T3,A,ES16.8)")
"HARRIS| Prior electronic temperature [a.u.]: ", &
308 WRITE (unit_nr,
"(T3,A,ES16.8)")
"HARRIS| Prior chemical potential [a.u.]: ", &
310 WRITE (unit_nr,
"(T3,A,ES16.8)")
"HARRIS| Relative-entropy weight: ", relative_weight
311 WRITE (unit_nr,
"(T3,A,ES16.8)")
"HARRIS| Initial fermionic relative entropy: ", &
314 WRITE (unit_nr,
"(/,T3,A,I0)")
"HARRIS| Constrained AO density fit; basis functions: ", nao
316 WRITE (unit_nr,
"(T3,A,I0)")
"HARRIS| Constrained electron count: ", nelectron
317 WRITE (unit_nr,
"(T3,A,ES16.8)")
"HARRIS| Initial density RMS error: ", rms
318 IF (use_relative_entropy)
THEN
319 WRITE (unit_nr,
"(T3,A)") &
320 "HARRIS| Iteration RMS error Relative entropy Objective Step"
322 WRITE (unit_nr,
"(T3,A)")
"HARRIS| Iteration RMS error Objective Step"
326 converged = rms <= eps_rms
328 have_previous = .false.
330 DO WHILE (iteration < max_iter .AND. .NOT. converged)
331 iteration = iteration + 1
333 CALL dbcsr_set(gradient_ao%matrix, 0.0_dp)
334 CALL integrate_v_rspace(v_rspace=residual_rspace, hmat=gradient_ao, &
335 qs_env=qs_env, calculate_forces=.false.)
341 "SOLVE", pos=
"LEFT", transa=
"T")
343 "SOLVE", pos=
"RIGHT")
345 IF (use_relative_entropy .AND. relative_weight > 0.0_dp)
THEN
346 CALL add_relative_entropy_gradient(density_orth, prior_logit, eigenvectors, work1, &
347 work2, eigenvalues, relative_weight, gradient_orth)
351 IF (have_previous)
THEN
358 IF (sy > 100.0_dp*epsilon(sy)*max(1.0_dp, ss))
THEN
359 alpha = min(100.0_dp*step_size, max(1.0e-6_dp*step_size, ss/sy))
364 have_previous = .true.
370 CALL project_density_matrix(trial_orth, eigenvectors, work1, eigenvalues, &
371 REAL(nelectron,
dp), 2.0_dp)
374 CALL cp_fm_trace(gradient_orth, direction_orth, direction_derivative)
375 CALL cp_fm_trace(direction_orth, direction_orth, direction_norm2)
376 IF (direction_norm2 <= 100.0_dp*epsilon(direction_norm2))
THEN
377 IF (unit_nr > 0)
WRITE (unit_nr,
"(T3,A)") &
378 "HARRIS| Density fit stopped: projected gradient reached a stationary point"
385 DO backtrack = 0, max_backtrack
388 CALL orthogonal_to_ao(trial_orth, overlap_chol, work1, work2, nao)
390 CALL evaluate_density_fit(qs_env, ks_env, rho_ao, rho_r, rho_g, tot_rho_r, &
391 target_rspace, residual_rspace, objective_trial, rms_trial)
392 relative_entropy_trial = 0.0_dp
393 IF (use_relative_entropy)
THEN
394 CALL fermionic_relative_entropy(trial_orth, prior_logit, eigenvectors, work1, &
395 eigenvalues, prior_log_one_minus, relative_entropy_trial)
396 objective_trial = objective_trial + relative_weight*relative_entropy_trial
398 IF (objective_trial <= objective + 1.0e-4_dp*step_length*direction_derivative)
THEN
402 step_length = 0.5_dp*step_length
405 IF (.NOT. accepted)
THEN
407 CALL orthogonal_to_ao(density_orth, overlap_chol, work1, work2, nao)
409 CALL evaluate_density_fit(qs_env, ks_env, rho_ao, rho_r, rho_g, tot_rho_r, &
410 target_rspace, residual_rspace, objective, rms)
411 IF (use_relative_entropy)
THEN
412 CALL fermionic_relative_entropy(density_orth, prior_logit, eigenvectors, work1, &
413 eigenvalues, prior_log_one_minus, relative_entropy)
414 objective = objective + relative_weight*relative_entropy
416 IF (unit_nr > 0)
WRITE (unit_nr,
"(T3,A)") &
417 "HARRIS| Density fit stopped: projected line search reached a stationary point"
423 objective = objective_trial
425 relative_entropy = relative_entropy_trial
426 IF (unit_nr > 0)
THEN
427 IF (use_relative_entropy)
THEN
428 WRITE (unit_nr,
"(T3,A,I7,4ES19.9)") &
429 "HARRIS| ", iteration, rms, relative_entropy, objective, alpha*step_length
431 WRITE (unit_nr,
"(T3,A,I7,3ES19.9)") &
432 "HARRIS| ", iteration, rms, objective, alpha*step_length
435 converged = rms <= eps_rms
438 CALL dbcsr_dot(rho_ao(1)%matrix, matrix_s(1)%matrix, matrix_trace)
442 commutator_norm = 0.0_dp
443 idempotency_error = 0.0_dp
444 IF (use_relative_entropy)
THEN
445 CALL matrix_commutator_norm(density_orth, hamiltonian_orth, work1, work2, nao, &
447 CALL density_matrix_idempotency_error(density_orth, work1, work2, nao, idempotency_error)
449 IF (unit_nr > 0)
THEN
450 IF (rms <= eps_rms)
THEN
451 WRITE (unit_nr,
"(T3,A,I0,A)")
"HARRIS| Density fit reached its RMS target after ", iteration,
" iterations"
452 ELSE IF (iteration >= max_iter)
THEN
453 WRITE (unit_nr,
"(T3,A,I0,A)")
"HARRIS| Density fit stopped after ", iteration,
" iterations"
455 WRITE (unit_nr,
"(T3,A,ES16.8)")
"HARRIS| Final density RMS error: ", rms
456 WRITE (unit_nr,
"(T3,A,F20.10)")
"HARRIS| AO density-matrix electron count: ", matrix_trace
457 WRITE (unit_nr,
"(T3,A,F20.10)")
"HARRIS| Fitted grid electron count: ", fitted_grid_trace
458 IF (use_relative_entropy)
THEN
459 WRITE (unit_nr,
"(T3,A,ES16.8)")
"HARRIS| Final fermionic relative entropy: ", &
461 WRITE (unit_nr,
"(T3,A,ES16.8)")
"HARRIS| Prior-Hamiltonian commutator norm: ", &
463 WRITE (unit_nr,
"(T3,A,ES16.8)")
"HARRIS| Occupation idempotency error: ", &
468 DEALLOCATE (eigenvalues)
469 IF (use_relative_entropy)
THEN
470 DEALLOCATE (prior_eigenvalues, prior_logit_values, prior_occupations)
480 IF (use_relative_entropy)
THEN
487 DEALLOCATE (gradient_ao%matrix)
488 CALL auxbas_pw_pool%give_back_pw(residual_rspace)
489 CALL auxbas_pw_pool%give_back_pw(target_rspace)
491 CALL timestop(handle)
493 END SUBROUTINE fit_density_matrix
503 SUBROUTINE fixed_trace_fermi_occupations(eigenvalues, trace_target, temperature, &
504 chemical_potential, occupations)
505 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: eigenvalues
506 REAL(kind=
dp),
INTENT(IN) :: trace_target, temperature
507 REAL(kind=
dp),
INTENT(OUT) :: chemical_potential
508 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: occupations
510 INTEGER :: i, iteration, n
511 REAL(kind=
dp) :: mu_high, mu_low, trace_value
513 n =
SIZE(eigenvalues)
514 cpassert(
SIZE(occupations) == n)
515 cpassert(temperature > 0.0_dp)
516 cpassert(trace_target >= 0.0_dp .AND. trace_target <= 2.0_dp*real(n,
dp))
518 IF (trace_target <= 0.0_dp)
THEN
520 chemical_potential = minval(eigenvalues) - 100.0_dp*temperature
522 ELSE IF (trace_target >= 2.0_dp*real(n,
dp))
THEN
524 chemical_potential = maxval(eigenvalues) + 100.0_dp*temperature
528 mu_low = minval(eigenvalues) - 100.0_dp*temperature - 1.0_dp
529 mu_high = maxval(eigenvalues) + 100.0_dp*temperature + 1.0_dp
530 DO iteration = 1, 200
531 chemical_potential = 0.5_dp*(mu_low + mu_high)
533 occupations(i) = fermi_occupation(eigenvalues(i), chemical_potential, temperature)
535 trace_value = sum(occupations)
536 IF (trace_value > trace_target)
THEN
537 mu_high = chemical_potential
539 mu_low = chemical_potential
541 IF (abs(trace_value - trace_target) <= 1.0e-13_dp*max(1.0_dp, trace_target))
EXIT
543 chemical_potential = 0.5_dp*(mu_low + mu_high)
545 occupations(i) = fermi_occupation(eigenvalues(i), chemical_potential, temperature)
548 END SUBROUTINE fixed_trace_fermi_occupations
557 PURE FUNCTION fermi_occupation(energy, chemical_potential, temperature)
RESULT(occupation)
558 REAL(kind=
dp),
INTENT(IN) :: energy, chemical_potential, temperature
559 REAL(kind=
dp) :: occupation
563 x = (energy - chemical_potential)/temperature
564 IF (x >= 50.0_dp)
THEN
565 occupation = 2.0_dp*exp(-x)
566 ELSE IF (x <= -50.0_dp)
THEN
569 occupation = 2.0_dp/(1.0_dp + exp(x))
572 END FUNCTION fermi_occupation
583 PURE FUNCTION clipped_occupation_fraction(occupation)
RESULT(fraction)
584 REAL(kind=
dp),
INTENT(IN) :: occupation
585 REAL(kind=
dp) :: fraction
587 REAL(kind=
dp),
PARAMETER :: occupation_clip = 1.0e-14_dp
589 fraction = min(1.0_dp - occupation_clip, &
590 max(occupation_clip, 0.5_dp*occupation))
592 END FUNCTION clipped_occupation_fraction
601 SUBROUTINE matrix_from_eigensystem(eigenvectors, values, matrix, work)
603 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: values
604 TYPE(
cp_fm_type),
INTENT(INOUT) :: matrix, work
611 CALL parallel_gemm(
'N',
'T', n, n, n, 1.0_dp, work, eigenvectors, 0.0_dp, matrix)
613 END SUBROUTINE matrix_from_eigensystem
627 SUBROUTINE fermionic_relative_entropy(density_orth, prior_logit, eigenvectors, work, eigenvalues, &
628 prior_log_one_minus, relative_entropy)
629 TYPE(
cp_fm_type),
INTENT(IN) :: density_orth, prior_logit
630 TYPE(
cp_fm_type),
INTENT(INOUT) :: eigenvectors, work
631 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: eigenvalues
632 REAL(kind=
dp),
INTENT(IN) :: prior_log_one_minus
633 REAL(kind=
dp),
INTENT(OUT) :: relative_entropy
636 REAL(kind=
dp) :: entropy_part, f, trace_xlogit
640 entropy_part = 0.0_dp
641 DO i = 1,
SIZE(eigenvalues)
642 f = clipped_occupation_fraction(eigenvalues(i))
643 entropy_part = entropy_part + f*log(f) + (1.0_dp - f)*log(1.0_dp - f)
645 CALL cp_fm_trace(density_orth, prior_logit, trace_xlogit)
646 relative_entropy = entropy_part - prior_log_one_minus - 0.5_dp*trace_xlogit
647 IF (relative_entropy < 0.0_dp .AND. abs(relative_entropy) < 1.0e-10_dp) relative_entropy = 0.0_dp
649 END SUBROUTINE fermionic_relative_entropy
662 SUBROUTINE add_relative_entropy_gradient(density_orth, prior_logit, eigenvectors, &
663 work1, work2, eigenvalues, weight, gradient)
664 TYPE(
cp_fm_type),
INTENT(IN) :: density_orth, prior_logit
665 TYPE(
cp_fm_type),
INTENT(INOUT) :: eigenvectors, work1, work2
666 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: eigenvalues
667 REAL(kind=
dp),
INTENT(IN) :: weight
675 DO i = 1,
SIZE(eigenvalues)
676 f = clipped_occupation_fraction(eigenvalues(i))
677 eigenvalues(i) = 0.5_dp*log(f/(1.0_dp - f))
679 CALL matrix_from_eigensystem(eigenvectors, eigenvalues, work1, work2)
683 END SUBROUTINE add_relative_entropy_gradient
694 SUBROUTINE matrix_commutator_norm(density_orth, hamiltonian_orth, work1, work2, nao, norm)
695 TYPE(
cp_fm_type),
INTENT(IN) :: density_orth, hamiltonian_orth
696 TYPE(
cp_fm_type),
INTENT(INOUT) :: work1, work2
697 INTEGER,
INTENT(IN) :: nao
698 REAL(kind=
dp),
INTENT(OUT) :: norm
700 REAL(kind=
dp) :: norm_squared
702 CALL parallel_gemm(
'N',
'N', nao, nao, nao, 1.0_dp, density_orth, hamiltonian_orth, &
704 CALL parallel_gemm(
'N',
'N', nao, nao, nao, 1.0_dp, hamiltonian_orth, density_orth, &
708 norm = sqrt(max(0.0_dp, norm_squared))
710 END SUBROUTINE matrix_commutator_norm
720 SUBROUTINE density_matrix_idempotency_error(density_orth, work1, work2, nao, error)
722 TYPE(
cp_fm_type),
INTENT(INOUT) :: work1, work2
723 INTEGER,
INTENT(IN) :: nao
724 REAL(kind=
dp),
INTENT(OUT) :: error
726 REAL(kind=
dp) :: error_squared
728 CALL parallel_gemm(
'N',
'N', nao, nao, nao, 1.0_dp, density_orth, density_orth, &
733 error = sqrt(max(0.0_dp, error_squared))
735 END SUBROUTINE density_matrix_idempotency_error
746 SUBROUTINE project_density_matrix(matrix, eigenvectors, work, eigenvalues, trace_target, max_occupation)
747 TYPE(
cp_fm_type),
INTENT(INOUT) :: matrix, eigenvectors, work
748 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: eigenvalues
749 REAL(kind=
dp),
INTENT(IN) :: trace_target, max_occupation
751 INTEGER :: i, iteration, n
752 REAL(kind=
dp) :: tau, tau_high, tau_low, trace_value
754 n =
SIZE(eigenvalues)
755 cpassert(trace_target >= 0.0_dp .AND. trace_target <= max_occupation*real(n,
dp))
757 CALL cp_fm_syevd(matrix, eigenvectors, eigenvalues)
759 IF (trace_target <= 0.0_dp)
THEN
761 ELSE IF (trace_target >= max_occupation*real(n,
dp))
THEN
762 eigenvalues = max_occupation
764 tau_low = minval(eigenvalues) - max_occupation
765 tau_high = maxval(eigenvalues)
766 DO iteration = 1, 200
767 tau = 0.5_dp*(tau_low + tau_high)
768 trace_value = sum(min(max_occupation, max(0.0_dp, eigenvalues - tau)))
769 IF (trace_value > trace_target)
THEN
774 IF (tau_high - tau_low <= 10.0_dp*epsilon(tau)*max(1.0_dp, abs(tau)))
EXIT
776 tau = 0.5_dp*(tau_low + tau_high)
778 eigenvalues(i) = min(max_occupation, max(0.0_dp, eigenvalues(i) - tau))
784 CALL parallel_gemm(
'N',
'T', n, n, n, 1.0_dp, work, eigenvectors, 0.0_dp, matrix)
786 END SUBROUTINE project_density_matrix
796 SUBROUTINE orthogonal_to_ao(density_orth, overlap_chol, work1, density_ao, nao)
797 TYPE(
cp_fm_type),
INTENT(IN) :: density_orth, overlap_chol
798 TYPE(
cp_fm_type),
INTENT(INOUT) :: work1, density_ao
799 INTEGER,
INTENT(IN) :: nao
803 "SOLVE", pos=
"RIGHT", transa=
"T")
805 END SUBROUTINE orthogonal_to_ao
820 SUBROUTINE evaluate_density_fit(qs_env, ks_env, rho_ao, rho_r, rho_g, tot_rho_r, &
821 target_rspace, residual_rspace, objective, rms)
827 REAL(kind=
dp),
DIMENSION(:),
POINTER :: tot_rho_r
830 REAL(kind=
dp),
INTENT(OUT) :: objective, rms
835 rho_gspace=rho_g(1), total_rho=tot_rho_r(1), ks_env=ks_env)
836 CALL pw_copy(rho_r(1), residual_rspace)
837 CALL pw_axpy(target_rspace, residual_rspace, alpha=-1.0_dp, beta=1.0_dp)
838 objective = 0.5_dp*
pw_integral_ab(residual_rspace, residual_rspace)
839 rms = sqrt(2.0_dp*objective/rho_r(1)%pw_grid%vol)
841 END SUBROUTINE evaluate_density_fit
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
subroutine, public cp_fm_uplo_to_full(matrix, work, uplo)
given a triangular matrix according to uplo, computes the corresponding full matrix
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_restore(fm_matrix, neig, fm_matrixb, fm_matrixout, op, pos, transa)
apply Cholesky decomposition op can be "SOLVE" (out = U^-1 * in) or "MULTIPLY" (out = U * in) pos can...
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public cp_fm_syevd(matrix, eigenvectors, eigenvalues, info)
Computes all eigenvalues and vectors of a real symmetric matrix significantly faster than syevx,...
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_rho_elec(matrix_p, matrix_p_kp, rho, rho_gspace, total_rho, ks_env, soft_valid, compute_tau, compute_grad, basis_type, der_type, idir, task_list_external, pw_env_external)
computes the density corresponding to a given density matrix on the grid
Constrained fitting of a real-space density by an AO density matrix. This is a dense reference implem...
subroutine, public fit_constrained_density(qs_env, rho_struct, max_iter, eps_rms, step_size, max_backtrack)
Fits the density currently stored in rho_struct with a spin-restricted AO density matrix....
subroutine, public fit_relative_entropy_density(qs_env, rho_struct, prior_hamiltonian, temperature, entropy_weight, max_iter, eps_rms, step_size, max_backtrack)
Reconstructs an AO density matrix using the Fermi matrix of H[n_cube] as a fermionic relative-entropy...
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.
Integrate single or product functions over a potential on a RS grid.
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment
contained for different pw related things
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.