80#include "./base/base_uses.f90"
86 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_cdft_methods'
87 LOGICAL,
PARAMETER,
PRIVATE :: debug_this_module = .false.
106 LOGICAL :: calc_pot, calculate_forces
108 CHARACTER(len=*),
PARAMETER :: routinen =
'becke_constraint'
114 CALL timeset(routinen, handle)
115 CALL get_qs_env(qs_env, dft_control=dft_control)
116 cdft_control => dft_control%qs_control%cdft_control
122 CALL becke_constraint_low(qs_env)
125 CALL cdft_constraint_integrate(qs_env)
127 IF (calculate_forces)
CALL cdft_constraint_force(qs_env)
129 CALL timestop(handle)
140 SUBROUTINE becke_constraint_low(qs_env, just_gradients)
142 LOGICAL,
OPTIONAL :: just_gradients
144 CHARACTER(len=*),
PARAMETER :: routinen =
'becke_constraint_low'
146 INTEGER :: handle, i, iatom, igroup, ind(3), ip, j, &
147 jatom, jp, k, natom, np(3), nskipped
148 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: catom
149 INTEGER,
DIMENSION(2, 3) :: bo, bo_conf
150 LOGICAL :: in_memory, my_just_gradients
151 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: is_constraint, skip_me
152 LOGICAL,
ALLOCATABLE,
DIMENSION(:, :) :: atom_in_group
153 REAL(kind=
dp) :: dist1, dist2, dmyexp, dvol, eps_cavity, &
154 my1, my1_homo, myexp, sum_cell_f_all, &
156 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: cell_functions, ds_dr_i, ds_dr_j, &
158 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: d_sum_pm_dr, dp_i_dri
159 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: dp_i_drj
160 REAL(kind=
dp),
DIMENSION(3) :: cell_v, dist_vec, dmy_dr_i, dmy_dr_j, &
161 dr, dr1_r2, dr_i_dr, dr_ij_dr, &
162 dr_j_dr, grid_p, r, r1, shift
163 REAL(kind=
dp),
DIMENSION(:),
POINTER :: cutoffs
172 NULLIFY (cutoffs, cell, dft_control, particle_set, group, charge, cdft_control)
173 CALL timeset(routinen, handle)
177 particle_set=particle_set, &
179 dft_control=dft_control)
180 cdft_control => dft_control%qs_control%cdft_control
181 becke_control => cdft_control%becke_control
182 group => cdft_control%group
183 cutoffs => becke_control%cutoffs
184 IF (cdft_control%atomic_charges) &
185 charge => cdft_control%charge
187 IF (cdft_control%save_pot)
THEN
188 in_memory = becke_control%in_memory
190 eps_cavity = becke_control%eps_cavity
192 my_just_gradients = .false.
193 IF (
PRESENT(just_gradients)) my_just_gradients = just_gradients
194 IF (my_just_gradients)
THEN
197 IF (becke_control%vector_buffer%store_vectors)
THEN
198 ALLOCATE (becke_control%vector_buffer%distances(natom))
199 ALLOCATE (becke_control%vector_buffer%distance_vecs(3, natom))
200 IF (in_memory)
ALLOCATE (becke_control%vector_buffer%pair_dist_vecs(3, natom, natom))
201 ALLOCATE (becke_control%vector_buffer%position_vecs(3, natom))
203 ALLOCATE (becke_control%vector_buffer%R12(natom, natom))
205 cell_v(i) = cell%hmat(i, i)
207 DO iatom = 1, natom - 1
208 DO jatom = iatom + 1, natom
209 r = particle_set(iatom)%r
210 r1 = particle_set(jatom)%r
212 r(i) =
modulo(r(i), cell%hmat(i, i)) - cell%hmat(i, i)/2._dp
213 r1(i) =
modulo(r1(i), cell%hmat(i, i)) - cell%hmat(i, i)/2._dp
215 dist_vec = (r - r1) - anint((r - r1)/cell_v)*cell_v
216 IF (becke_control%vector_buffer%store_vectors)
THEN
217 becke_control%vector_buffer%position_vecs(:, iatom) = r(:)
218 IF (iatom == 1 .AND. jatom == natom) becke_control%vector_buffer%position_vecs(:, jatom) = r1(:)
220 becke_control%vector_buffer%pair_dist_vecs(:, iatom, jatom) = dist_vec(:)
221 becke_control%vector_buffer%pair_dist_vecs(:, jatom, iatom) = -dist_vec(:)
224 becke_control%vector_buffer%R12(iatom, jatom) = sqrt(dot_product(dist_vec, dist_vec))
225 becke_control%vector_buffer%R12(jatom, iatom) = becke_control%vector_buffer%R12(iatom, jatom)
229 ALLOCATE (catom(cdft_control%natoms))
230 IF (cdft_control%save_pot .OR. &
231 becke_control%cavity_confine .OR. &
232 becke_control%should_skip)
THEN
233 ALLOCATE (is_constraint(natom))
234 is_constraint = .false.
239 ALLOCATE (skip_me(natom))
240 DO i = 1, cdft_control%natoms
241 catom(i) = cdft_control%atoms(i)
244 IF (cdft_control%save_pot .OR. &
245 becke_control%cavity_confine .OR. &
246 becke_control%should_skip) &
247 is_constraint(catom(i)) = .true.
249 bo = group(1)%weight%pw_grid%bounds_local
250 dvol = group(1)%weight%pw_grid%dvol
251 dr = group(1)%weight%pw_grid%dr
252 np = group(1)%weight%pw_grid%npts
253 shift = -real(
modulo(np, 2),
dp)*dr/2.0_dp
255 cell_v(i) = cell%hmat(i, i)
262 IF (becke_control%cavity_confine)
THEN
263 bo_conf(1, 3) = becke_control%confine_bounds(1)
264 bo_conf(2, 3) = becke_control%confine_bounds(2)
266 ALLOCATE (atom_in_group(
SIZE(group), natom))
267 atom_in_group = .false.
268 DO igroup = 1,
SIZE(group)
269 ALLOCATE (group(igroup)%gradients(3*natom, bo_conf(1, 1):bo_conf(2, 1), &
270 bo_conf(1, 2):bo_conf(2, 2), &
271 bo_conf(1, 3):bo_conf(2, 3)))
272 group(igroup)%gradients = 0.0_dp
273 ALLOCATE (group(igroup)%d_sum_const_dR(3, natom))
274 group(igroup)%d_sum_const_dR = 0.0_dp
275 DO ip = 1,
SIZE(group(igroup)%atoms)
276 atom_in_group(igroup, group(igroup)%atoms(ip)) = .true.
281 ALLOCATE (sum_cell_f_group(
SIZE(group)))
282 ALLOCATE (cell_functions(natom))
284 ALLOCATE (ds_dr_j(3))
285 ALLOCATE (ds_dr_i(3))
286 ALLOCATE (d_sum_pm_dr(3, natom))
287 ALLOCATE (dp_i_drj(3, natom, natom))
288 ALLOCATE (dp_i_dri(3, natom))
292 DO k = bo(1, 1), bo(2, 1)
293 DO j = bo(1, 2), bo(2, 2)
294 DO i = bo(1, 3), bo(2, 3)
297 IF (becke_control%cavity_confine)
THEN
298 IF (becke_control%cavity%array(k, j, i) < eps_cavity) cycle
301 grid_p(1) = k*dr(1) + shift(1)
302 grid_p(2) = j*dr(2) + shift(2)
303 grid_p(3) = i*dr(3) + shift(3)
305 cell_functions = 1.0_dp
307 IF (becke_control%vector_buffer%store_vectors) becke_control%vector_buffer%distances = 0.0_dp
310 DO igroup = 1,
SIZE(group)
311 group(igroup)%d_sum_const_dR = 0.0_dp
317 IF (skip_me(iatom))
THEN
318 cell_functions(iatom) = 0.0_dp
319 IF (becke_control%should_skip)
THEN
320 IF (is_constraint(iatom)) nskipped = nskipped + 1
321 IF (nskipped == cdft_control%natoms)
THEN
323 IF (becke_control%cavity_confine)
THEN
324 becke_control%cavity%array(k, j, i) = 0.0_dp
332 IF (becke_control%vector_buffer%store_vectors)
THEN
333 IF (becke_control%vector_buffer%distances(iatom) .EQ. 0.0_dp)
THEN
334 r = becke_control%vector_buffer%position_vecs(:, iatom)
335 dist_vec = (r - grid_p) - anint((r - grid_p)/cell_v)*cell_v
336 dist1 = sqrt(dot_product(dist_vec, dist_vec))
337 becke_control%vector_buffer%distance_vecs(:, iatom) = dist_vec
338 becke_control%vector_buffer%distances(iatom) = dist1
340 dist_vec = becke_control%vector_buffer%distance_vecs(:, iatom)
341 dist1 = becke_control%vector_buffer%distances(iatom)
344 r = particle_set(iatom)%r
346 r(ip) =
modulo(r(ip), cell%hmat(ip, ip)) - cell%hmat(ip, ip)/2._dp
348 dist_vec = (r - grid_p) - anint((r - grid_p)/cell_v)*cell_v
349 dist1 = sqrt(dot_product(dist_vec, dist_vec))
351 IF (dist1 .LE. cutoffs(iatom))
THEN
353 IF (dist1 .LE. th) dist1 = th
354 dr_i_dr(:) = dist_vec(:)/dist1
357 IF (jatom .NE. iatom)
THEN
363 IF (jatom < iatom)
THEN
364 IF (.NOT. skip_me(jatom)) cycle
366 IF (becke_control%vector_buffer%store_vectors)
THEN
367 IF (becke_control%vector_buffer%distances(jatom) .EQ. 0.0_dp)
THEN
368 r1 = becke_control%vector_buffer%position_vecs(:, jatom)
369 dist_vec = (r1 - grid_p) - anint((r1 - grid_p)/cell_v)*cell_v
370 dist2 = sqrt(dot_product(dist_vec, dist_vec))
371 becke_control%vector_buffer%distance_vecs(:, jatom) = dist_vec
372 becke_control%vector_buffer%distances(jatom) = dist2
374 dist_vec = becke_control%vector_buffer%distance_vecs(:, jatom)
375 dist2 = becke_control%vector_buffer%distances(jatom)
378 r1 = particle_set(jatom)%r
380 r1(ip) =
modulo(r1(ip), cell%hmat(ip, ip)) - cell%hmat(ip, ip)/2._dp
382 dist_vec = (r1 - grid_p) - anint((r1 - grid_p)/cell_v)*cell_v
383 dist2 = sqrt(dot_product(dist_vec, dist_vec))
386 IF (becke_control%vector_buffer%store_vectors)
THEN
387 dr1_r2 = becke_control%vector_buffer%pair_dist_vecs(:, iatom, jatom)
389 dr1_r2 = (r - r1) - anint((r - r1)/cell_v)*cell_v
391 IF (dist2 .LE. th) dist2 = th
392 tmp_const = (becke_control%vector_buffer%R12(iatom, jatom)**3)
393 dr_ij_dr(:) = dr1_r2(:)/tmp_const
395 dr_j_dr = dist_vec(:)/dist2
396 dmy_dr_j(:) = -(dr_j_dr(:)/becke_control%vector_buffer%R12(iatom, jatom) - (dist1 - dist2)*dr_ij_dr(:))
398 dmy_dr_i(:) = dr_i_dr(:)/becke_control%vector_buffer%R12(iatom, jatom) - (dist1 - dist2)*dr_ij_dr(:)
401 my1 = (dist1 - dist2)/becke_control%vector_buffer%R12(iatom, jatom)
402 IF (becke_control%adjust)
THEN
404 my1 = my1 + becke_control%aij(iatom, jatom)*(1.0_dp - my1**2)
407 myexp = 1.5_dp*my1 - 0.5_dp*my1**3
409 dmyexp = 1.5_dp - 1.5_dp*my1**2
410 tmp_const = (1.5_dp**2)*dmyexp*(1 - myexp**2)* &
411 (1.0_dp - ((1.5_dp*myexp - 0.5_dp*(myexp**3))**2))
413 ds_dr_i(:) = -0.5_dp*tmp_const*dmy_dr_i(:)
415 ds_dr_j(:) = -0.5_dp*tmp_const*dmy_dr_j(:)
416 IF (becke_control%adjust)
THEN
417 tmp_const = 1.0_dp - 2.0_dp*my1_homo* &
418 becke_control%aij(iatom, jatom)
419 ds_dr_i(:) = ds_dr_i(:)*tmp_const
421 ds_dr_j(:) = ds_dr_j(:)*tmp_const
425 myexp = 1.5_dp*myexp - 0.5_dp*myexp**3
426 myexp = 1.5_dp*myexp - 0.5_dp*myexp**3
427 tmp_const = 0.5_dp*(1.0_dp - myexp)
428 cell_functions(iatom) = cell_functions(iatom)*tmp_const
430 IF (abs(tmp_const) .LE. th) tmp_const = tmp_const + th
432 dp_i_dri(:, iatom) = dp_i_dri(:, iatom) + ds_dr_i(:)/tmp_const
434 dp_i_drj(:, iatom, jatom) = ds_dr_j(:)/tmp_const
437 IF (dist2 .LE. cutoffs(jatom))
THEN
438 tmp_const = 0.5_dp*(1.0_dp + myexp)
439 cell_functions(jatom) = cell_functions(jatom)*tmp_const
441 IF (abs(tmp_const) .LE. th) tmp_const = tmp_const + th
444 dp_i_drj(:, jatom, iatom) = -ds_dr_i(:)/tmp_const
447 dp_i_dri(:, jatom) = dp_i_dri(:, jatom) - ds_dr_j(:)/tmp_const
450 skip_me(jatom) = .true.
456 dp_i_dri(:, iatom) = cell_functions(iatom)*dp_i_dri(:, iatom)
458 d_sum_pm_dr(:, iatom) = d_sum_pm_dr(:, iatom) + dp_i_dri(:, iatom)
459 IF (is_constraint(iatom))
THEN
460 DO igroup = 1,
SIZE(group)
461 IF (.NOT. atom_in_group(igroup, iatom)) cycle
462 DO jp = 1,
SIZE(group(igroup)%atoms)
463 IF (iatom == group(igroup)%atoms(jp))
THEN
468 group(igroup)%d_sum_const_dR(1:3, iatom) = group(igroup)%d_sum_const_dR(1:3, iatom) + &
469 group(igroup)%coeff(ip)*dp_i_dri(:, iatom)
473 IF (jatom .NE. iatom)
THEN
475 dp_i_drj(:, iatom, jatom) = cell_functions(iatom)*dp_i_drj(:, iatom, jatom)
477 d_sum_pm_dr(:, jatom) = d_sum_pm_dr(:, jatom) + dp_i_drj(:, iatom, jatom)
478 IF (is_constraint(iatom))
THEN
479 DO igroup = 1,
SIZE(group)
480 IF (.NOT. atom_in_group(igroup, iatom)) cycle
482 DO jp = 1,
SIZE(group(igroup)%atoms)
483 IF (iatom == group(igroup)%atoms(jp))
THEN
488 group(igroup)%d_sum_const_dR(1:3, jatom) = group(igroup)%d_sum_const_dR(1:3, jatom) + &
489 group(igroup)%coeff(ip)* &
490 dp_i_drj(:, iatom, jatom)
497 cell_functions(iatom) = 0.0_dp
498 skip_me(iatom) = .true.
499 IF (becke_control%should_skip)
THEN
500 IF (is_constraint(iatom)) nskipped = nskipped + 1
501 IF (nskipped == cdft_control%natoms)
THEN
503 IF (becke_control%cavity_confine)
THEN
504 becke_control%cavity%array(k, j, i) = 0.0_dp
512 IF (nskipped == cdft_control%natoms) cycle
514 sum_cell_f_group = 0.0_dp
515 DO igroup = 1,
SIZE(group)
516 DO ip = 1,
SIZE(group(igroup)%atoms)
517 sum_cell_f_group(igroup) = sum_cell_f_group(igroup) + group(igroup)%coeff(ip)* &
518 cell_functions(group(igroup)%atoms(ip))
521 sum_cell_f_all = 0.0_dp
523 sum_cell_f_all = sum_cell_f_all + cell_functions(ip)
526 IF (in_memory .AND. abs(sum_cell_f_all) .GT. 0.0_dp)
THEN
527 DO igroup = 1,
SIZE(group)
529 group(igroup)%gradients(3*(iatom - 1) + 1:3*(iatom - 1) + 3, k, j, i) = &
530 group(igroup)%d_sum_const_dR(1:3, iatom)/sum_cell_f_all - sum_cell_f_group(igroup)* &
531 d_sum_pm_dr(1:3, iatom)/(sum_cell_f_all**2)
536 IF (.NOT. my_just_gradients .AND. abs(sum_cell_f_all) .GT. 0.000001)
THEN
537 DO igroup = 1,
SIZE(group)
538 group(igroup)%weight%array(k, j, i) = sum_cell_f_group(igroup)/sum_cell_f_all
540 IF (cdft_control%atomic_charges)
THEN
541 DO iatom = 1, cdft_control%natoms
542 charge(iatom)%array(k, j, i) = cell_functions(catom(iatom))/sum_cell_f_all
553 DEALLOCATE (d_sum_pm_dr)
554 DEALLOCATE (dp_i_drj)
555 DEALLOCATE (dp_i_dri)
556 DO igroup = 1,
SIZE(group)
557 DEALLOCATE (group(igroup)%d_sum_const_dR)
559 DEALLOCATE (atom_in_group)
560 IF (becke_control%vector_buffer%store_vectors)
THEN
561 DEALLOCATE (becke_control%vector_buffer%pair_dist_vecs)
565 IF (
ALLOCATED(is_constraint)) &
566 DEALLOCATE (is_constraint)
568 DEALLOCATE (cell_functions)
570 DEALLOCATE (sum_cell_f_group)
571 DEALLOCATE (becke_control%vector_buffer%R12)
572 IF (becke_control%vector_buffer%store_vectors)
THEN
573 DEALLOCATE (becke_control%vector_buffer%distances)
574 DEALLOCATE (becke_control%vector_buffer%distance_vecs)
575 DEALLOCATE (becke_control%vector_buffer%position_vecs)
577 CALL timestop(handle)
579 END SUBROUTINE becke_constraint_low
589 LOGICAL :: calc_pot, calculate_forces
591 CHARACTER(len=*),
PARAMETER :: routinen =
'hirshfeld_constraint'
597 CALL timeset(routinen, handle)
598 CALL get_qs_env(qs_env, dft_control=dft_control)
599 cdft_control => dft_control%qs_control%cdft_control
605 CALL hirshfeld_constraint_low(qs_env)
608 CALL cdft_constraint_integrate(qs_env)
610 IF (calculate_forces)
CALL cdft_constraint_force(qs_env)
612 CALL timestop(handle)
621 SUBROUTINE hirshfeld_constraint_low(qs_env, just_gradients)
623 LOGICAL,
OPTIONAL :: just_gradients
625 CHARACTER(len=*),
PARAMETER :: routinen =
'hirshfeld_constraint_low'
627 INTEGER :: atom_a, atoms_memory, atoms_memory_num, handle, i, iatom, iex, igroup, ikind, &
628 ithread, j, k, natom, npme, nthread, num_atoms, num_species, numexp, subpatch_pattern
629 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: num_species_small
630 INTEGER,
DIMENSION(2, 3) :: bo
631 INTEGER,
DIMENSION(3) :: lb_pw, lb_rs, npts, ub_pw, ub_rs
632 INTEGER,
DIMENSION(:),
POINTER :: atom_list, cores
633 LOGICAL :: my_just_gradients
634 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: compute_charge, is_constraint
635 REAL(kind=
dp) :: alpha, coef, eps_rho_rspace, exp_eval, &
637 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: coefficients
638 REAL(kind=
dp),
DIMENSION(3) :: dr_pw, dr_rs, origin, r2, r_pbc, ra
639 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: pab
656 DIMENSION(:) :: rs_single, rs_single_charge, rs_single_dr
658 NULLIFY (atom_list, atomic_kind_set, dft_control, &
659 hirshfeld_env, particle_set, pw_env, auxbas_pw_pool, para_env, &
660 auxbas_rs_desc, cdft_control, pab, &
661 hirshfeld_control, cell, rho_r, rho)
663 CALL timeset(routinen, handle)
665 atomic_kind_set=atomic_kind_set, &
666 particle_set=particle_set, &
670 dft_control=dft_control, &
677 cdft_control => dft_control%qs_control%cdft_control
678 hirshfeld_control => cdft_control%hirshfeld_control
679 hirshfeld_env => hirshfeld_control%hirshfeld_env
682 my_just_gradients = .false.
683 IF (
PRESENT(just_gradients)) my_just_gradients = just_gradients
684 IF (my_just_gradients)
THEN
685 cdft_control%in_memory = .true.
686 hirshfeld_control%print_density = .false.
689 ALLOCATE (coefficients(natom))
690 ALLOCATE (is_constraint(natom))
693 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
696 dr_pw(1) = rho_r(1)%pw_grid%dr(1)
697 dr_pw(2) = rho_r(1)%pw_grid%dr(2)
698 dr_pw(3) = rho_r(1)%pw_grid%dr(3)
699 lb_pw(1:3) = rho_r(1)%pw_grid%bounds_local(1, 1:3)
700 ub_pw(1:3) = rho_r(1)%pw_grid%bounds_local(2, 1:3)
701 npts = rho_r(1)%pw_grid%npts
702 origin(1) = (dr_pw(1)*npts(1))*0.5_dp
703 origin(2) = (dr_pw(2)*npts(2))*0.5_dp
704 origin(3) = (dr_pw(3)*npts(3))*0.5_dp
706 CALL pw_env_get(pw_env, auxbas_rs_desc=auxbas_rs_desc, &
707 auxbas_pw_pool=auxbas_pw_pool)
711 dr_rs(1) = rs_rho_all%desc%dh(1, 1)
712 dr_rs(2) = rs_rho_all%desc%dh(2, 2)
713 dr_rs(3) = rs_rho_all%desc%dh(3, 3)
714 lb_rs(1) = lbound(rs_rho_all%r(:, :, :), 1)
715 lb_rs(2) = lbound(rs_rho_all%r(:, :, :), 2)
716 lb_rs(3) = lbound(rs_rho_all%r(:, :, :), 3)
717 ub_rs(1) = ubound(rs_rho_all%r(:, :, :), 1)
718 ub_rs(2) = ubound(rs_rho_all%r(:, :, :), 2)
719 ub_rs(3) = ubound(rs_rho_all%r(:, :, :), 3)
722 DO igroup = 1,
SIZE(cdft_control%group)
724 IF (igroup == 2 .AND. .NOT. cdft_control%in_memory)
THEN
727 bo = cdft_control%group(igroup)%weight%pw_grid%bounds_local
730 coefficients(:) = 0.0_dp
731 is_constraint = .false.
732 DO i = 1,
SIZE(cdft_control%group(igroup)%atoms)
733 coefficients(cdft_control%group(igroup)%atoms(i)) = cdft_control%group(igroup)%coeff(i)
734 is_constraint(cdft_control%group(igroup)%atoms(i)) = .true.
742 IF (hirshfeld_control%print_density .AND. igroup == 1)
THEN
743 ALLOCATE (cdft_control%group(igroup)%hw_rho_atomic(cdft_control%natoms))
744 ALLOCATE (rs_single(cdft_control%natoms))
745 DO i = 1, cdft_control%natoms
752 CALL pw_zero(cdft_control%group(igroup)%weight)
754 CALL auxbas_pw_pool%create_pw(cdft_control%group(igroup)%hw_rho_total_constraint)
755 CALL pw_set(cdft_control%group(igroup)%hw_rho_total_constraint, 1.0_dp)
757 IF (igroup == 1)
THEN
758 CALL auxbas_pw_pool%create_pw(cdft_control%hw_rho_total)
759 CALL pw_set(cdft_control%hw_rho_total, 1.0_dp)
761 IF (hirshfeld_control%print_density)
THEN
762 DO iatom = 1, cdft_control%natoms
763 CALL auxbas_pw_pool%create_pw(cdft_control%group(igroup)%hw_rho_atomic(iatom))
764 CALL pw_set(cdft_control%group(igroup)%hw_rho_atomic(iatom), 1.0_dp)
769 IF (cdft_control%atomic_charges .AND. igroup == 1)
THEN
770 ALLOCATE (cdft_control%group(igroup)%hw_rho_atomic_charge(cdft_control%natoms))
771 ALLOCATE (rs_single_charge(cdft_control%natoms))
772 ALLOCATE (compute_charge(natom))
773 compute_charge = .false.
775 DO i = 1, cdft_control%natoms
778 compute_charge(cdft_control%atoms(i)) = .true.
781 DO iatom = 1, cdft_control%natoms
782 CALL auxbas_pw_pool%create_pw(cdft_control%group(igroup)%hw_rho_atomic_charge(iatom))
783 CALL pw_set(cdft_control%group(igroup)%hw_rho_atomic_charge(iatom), 1.0_dp)
791 DO ikind = 1,
SIZE(atomic_kind_set)
792 numexp = hirshfeld_env%kind_shape_fn(ikind)%numexp
793 IF (numexp <= 0) cycle
794 CALL get_atomic_kind(atomic_kind_set(ikind), natom=num_species, atom_list=atom_list)
795 ALLOCATE (cores(num_species))
798 alpha = hirshfeld_env%kind_shape_fn(ikind)%zet(iex)
799 coef = hirshfeld_env%kind_shape_fn(ikind)%coef(iex)
802 DO iatom = 1, num_species
803 atom_a = atom_list(iatom)
804 ra(:) =
pbc(particle_set(atom_a)%r, cell)
805 IF (rs_rho_all%desc%parallel .AND. .NOT. rs_rho_all%desc%distributed)
THEN
806 IF (
modulo(iatom, rs_rho_all%desc%group_size) == rs_rho_all%desc%my_pos)
THEN
817 atom_a = atom_list(iatom)
818 pab(1, 1) = coef*hirshfeld_env%charges(atom_a)
819 ra(:) =
pbc(particle_set(atom_a)%r, cell)
821 IF (hirshfeld_control%use_atomic_cutoff)
THEN
823 ra=ra, rb=ra, rp=ra, &
824 zetp=alpha, eps=hirshfeld_control%atomic_cutoff, &
825 pab=pab, o1=0, o2=0, &
826 prefactor=1.0_dp, cutoff=0.0_dp)
829 IF (igroup == 1)
THEN
831 (/0.0_dp, 0.0_dp, 0.0_dp/), 1.0_dp, pab, 0, 0, &
832 rs_rho_all, radius=radius, &
834 subpatch_pattern=subpatch_pattern)
837 IF (is_constraint(atom_a))
THEN
839 (/0.0_dp, 0.0_dp, 0.0_dp/), coefficients(atom_a), &
840 pab, 0, 0, rs_rho_constr, &
843 subpatch_pattern=subpatch_pattern)
846 IF (hirshfeld_control%print_density .AND. igroup == 1)
THEN
847 IF (is_constraint(atom_a))
THEN
848 DO iatom = 1, cdft_control%natoms
849 IF (atom_a == cdft_control%atoms(iatom))
EXIT
851 cpassert(iatom <= cdft_control%natoms)
853 (/0.0_dp, 0.0_dp, 0.0_dp/), 1.0_dp, pab, 0, 0, &
854 rs_single(iatom), radius=radius, &
856 subpatch_pattern=subpatch_pattern)
860 IF (cdft_control%atomic_charges .AND. igroup == 1)
THEN
861 IF (compute_charge(atom_a))
THEN
862 DO iatom = 1, cdft_control%natoms
863 IF (atom_a == cdft_control%atoms(iatom))
EXIT
865 cpassert(iatom <= cdft_control%natoms)
867 (/0.0_dp, 0.0_dp, 0.0_dp/), 1.0_dp, pab, 0, 0, &
868 rs_single_charge(iatom), radius=radius, &
870 subpatch_pattern=subpatch_pattern)
880 IF (igroup == 1)
THEN
884 CALL transfer_rs2pw(rs_rho_constr, cdft_control%group(igroup)%hw_rho_total_constraint)
888 CALL hfun_scale(cdft_control%group(igroup)%weight%array, &
889 cdft_control%group(igroup)%hw_rho_total_constraint%array, &
890 cdft_control%hw_rho_total%array, divide=.true., &
891 small=hirshfeld_control%eps_cutoff)
894 IF (cdft_control%atomic_charges .AND. igroup == 1)
THEN
895 DO i = 1, cdft_control%natoms
896 CALL transfer_rs2pw(rs_single_charge(i), cdft_control%group(igroup)%hw_rho_atomic_charge(i))
897 CALL hfun_scale(cdft_control%charge(i)%array, &
898 cdft_control%group(igroup)%hw_rho_atomic_charge(i)%array, &
899 cdft_control%hw_rho_total%array, divide=.true., &
900 small=hirshfeld_control%eps_cutoff)
905 IF (hirshfeld_control%print_density .AND. igroup == 1)
THEN
906 DO i = 1, cdft_control%natoms
907 CALL transfer_rs2pw(rs_single(i), cdft_control%group(igroup)%hw_rho_atomic(i))
914 DO igroup = 1,
SIZE(cdft_control%group)
916 CALL auxbas_pw_pool%give_back_pw(cdft_control%group(igroup)%hw_rho_total_constraint)
918 IF (.NOT. cdft_control%in_memory .AND. igroup == 1)
THEN
919 CALL auxbas_pw_pool%give_back_pw(cdft_control%hw_rho_total)
922 IF (hirshfeld_control%print_density .AND. igroup == 1)
THEN
923 DO i = 1, cdft_control%natoms
925 CALL auxbas_pw_pool%give_back_pw(cdft_control%group(igroup)%hw_rho_atomic(i))
927 DEALLOCATE (rs_single)
928 DEALLOCATE (cdft_control%group(igroup)%hw_rho_atomic)
931 IF (cdft_control%atomic_charges .AND. igroup == 1)
THEN
932 DO i = 1, cdft_control%natoms
934 CALL auxbas_pw_pool%give_back_pw(cdft_control%group(igroup)%hw_rho_atomic_charge(i))
936 DEALLOCATE (rs_single_charge)
937 DEALLOCATE (compute_charge)
938 DEALLOCATE (cdft_control%group(igroup)%hw_rho_atomic_charge)
943 IF (cdft_control%in_memory)
THEN
944 DO igroup = 1,
SIZE(cdft_control%group)
945 ALLOCATE (cdft_control%group(igroup)%gradients_x(1*natom, lb_pw(1):ub_pw(1), &
946 lb_pw(2):ub_pw(2), lb_pw(3):ub_pw(3)))
947 cdft_control%group(igroup)%gradients_x(:, :, :, :) = 0.0_dp
951 IF (cdft_control%in_memory)
THEN
952 DO igroup = 1,
SIZE(cdft_control%group)
957 atoms_memory = hirshfeld_control%atoms_memory
959 DO ikind = 1,
SIZE(atomic_kind_set)
960 numexp = hirshfeld_env%kind_shape_fn(ikind)%numexp
961 IF (numexp <= 0) cycle
962 CALL get_atomic_kind(atomic_kind_set(ikind), natom=num_species, atom_list=atom_list)
964 ALLOCATE (pw_single_dr(num_species))
965 ALLOCATE (rs_single_dr(num_species))
967 DO i = 1, num_species
968 CALL auxbas_pw_pool%create_pw(pw_single_dr(i))
972 atoms_memory_num =
SIZE((/(j, j=1, num_species, atoms_memory)/))
976 IF (num_species > atoms_memory)
THEN
977 ALLOCATE (num_species_small(atoms_memory_num + 1))
978 num_species_small(1:atoms_memory_num) = (/(j, j=1, num_species, atoms_memory)/)
979 num_species_small(atoms_memory_num + 1) = num_species
981 ALLOCATE (num_species_small(2))
982 num_species_small(:) = (/1, num_species/)
985 DO k = 1,
SIZE(num_species_small) - 1
986 IF (num_species > atoms_memory)
THEN
987 ALLOCATE (cores(num_species_small(k + 1) - (num_species_small(k) - 1)))
989 ALLOCATE (cores(num_species))
992 DO i = num_species_small(k), num_species_small(k + 1)
998 alpha = hirshfeld_env%kind_shape_fn(ikind)%zet(iex)
999 coef = hirshfeld_env%kind_shape_fn(ikind)%coef(iex)
1000 prefactor = 2.0_dp*alpha
1004 DO iatom = 1,
SIZE(cores)
1005 atom_a = atom_list(iatom + (num_species_small(k) - 1))
1006 ra(:) =
pbc(particle_set(atom_a)%r, cell)
1008 IF (rs_rho_all%desc%parallel .AND. .NOT. rs_rho_all%desc%distributed)
THEN
1009 IF (
modulo(iatom, rs_rho_all%desc%group_size) == rs_rho_all%desc%my_pos)
THEN
1020 atom_a = atom_list(iatom + (num_species_small(k) - 1))
1021 pab(1, 1) = coef*hirshfeld_env%charges(atom_a)
1022 ra(:) =
pbc(particle_set(atom_a)%r, cell)
1023 subpatch_pattern = 0
1026 IF (hirshfeld_control%use_atomic_cutoff)
THEN
1028 ra=ra, rb=ra, rp=ra, &
1029 zetp=alpha, eps=hirshfeld_control%atomic_cutoff, &
1030 pab=pab, o1=0, o2=0, &
1031 prefactor=1.0_dp, cutoff=0.0_dp)
1035 (/0.0_dp, 0.0_dp, 0.0_dp/), prefactor, &
1036 pab, 0, 0, rs_single_dr(iatom + (num_species_small(k) - 1)), &
1039 subpatch_pattern=subpatch_pattern)
1044 DO iatom = num_species_small(k), num_species_small(k + 1)
1052 DO iatom = 1, num_species
1053 atom_a = atom_list(iatom)
1054 cdft_control%group(igroup)%gradients_x(atom_a, :, :, :) = pw_single_dr(iatom)%array(:, :, :)
1055 CALL auxbas_pw_pool%give_back_pw(pw_single_dr(iatom))
1058 DEALLOCATE (rs_single_dr)
1059 DEALLOCATE (num_species_small)
1060 DEALLOCATE (pw_single_dr)
1066 IF (cdft_control%in_memory)
THEN
1067 DO igroup = 1,
SIZE(cdft_control%group)
1068 ALLOCATE (cdft_control%group(igroup)%gradients_y(1*num_atoms, lb_pw(1):ub_pw(1), &
1069 lb_pw(2):ub_pw(2), lb_pw(3):ub_pw(3)))
1070 ALLOCATE (cdft_control%group(igroup)%gradients_z(1*num_atoms, lb_pw(1):ub_pw(1), &
1071 lb_pw(2):ub_pw(2), lb_pw(3):ub_pw(3)))
1072 cdft_control%group(igroup)%gradients_y(:, :, :, :) = cdft_control%group(igroup)%gradients_x(:, :, :, :)
1073 cdft_control%group(igroup)%gradients_z(:, :, :, :) = cdft_control%group(igroup)%gradients_x(:, :, :, :)
1078 IF (cdft_control%in_memory)
THEN
1080 DO igroup = 1,
SIZE(cdft_control%group)
1083 coefficients(:) = 0.0_dp
1084 is_constraint = .false.
1085 DO i = 1,
SIZE(cdft_control%group(igroup)%atoms)
1086 coefficients(cdft_control%group(igroup)%atoms(i)) = cdft_control%group(igroup)%coeff(i)
1087 is_constraint(cdft_control%group(igroup)%atoms(i)) = .true.
1090 DO k = lb_pw(3), ub_pw(3)
1091 DO j = lb_pw(2), ub_pw(2)
1092 DO i = lb_pw(1), ub_pw(1)
1095 ra(:) = particle_set(iatom)%r
1097 IF (cdft_control%hw_rho_total%array(i, j, k) > hirshfeld_control%eps_cutoff)
THEN
1099 exp_eval = (coefficients(iatom) - &
1100 cdft_control%group(igroup)%weight%array(i, j, k))/ &
1101 cdft_control%hw_rho_total%array(i, j, k)
1103 r2 = (/i*dr_pw(1), j*dr_pw(2), k*dr_pw(3)/) + origin
1104 r_pbc =
pbc(ra, r2, cell)
1107 cdft_control%group(igroup)%gradients_x(iatom, i, j, k) = &
1108 cdft_control%group(igroup)%gradients_x(iatom, i, j, k)* &
1112 cdft_control%group(igroup)%gradients_y(iatom, i, j, k) = &
1113 cdft_control%group(igroup)%gradients_y(iatom, i, j, k)* &
1117 cdft_control%group(igroup)%gradients_z(iatom, i, j, k) = &
1118 cdft_control%group(igroup)%gradients_z(iatom, i, j, k)* &
1127 CALL auxbas_pw_pool%give_back_pw(cdft_control%hw_rho_total)
1132 IF (
ALLOCATED(coefficients))
DEALLOCATE (coefficients)
1133 IF (
ALLOCATED(is_constraint))
DEALLOCATE (is_constraint)
1135 CALL timestop(handle)
1137 END SUBROUTINE hirshfeld_constraint_low
1144 SUBROUTINE cdft_constraint_integrate(qs_env)
1147 CHARACTER(len=*),
PARAMETER :: routinen =
'cdft_constraint_integrate'
1149 INTEGER :: handle, i, iatom, igroup, ikind, ivar, &
1150 iw, jatom, natom, nvar
1151 LOGICAL :: is_becke, paw_atom
1152 REAL(kind=
dp) :: dvol, eps_cavity, sign
1153 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: de, strength, target_val
1154 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: electronic_charge, gapw_offset
1165 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1170 NULLIFY (para_env, dft_control, particle_set, rho_r, energy, rho, &
1171 logger, cdft_constraint_section, qs_kind_set, mp_rho, &
1172 rho0_mpole, group, charge)
1173 CALL timeset(routinen, handle)
1176 particle_set=particle_set, &
1179 dft_control=dft_control, &
1180 para_env=para_env, &
1181 qs_kind_set=qs_kind_set)
1183 cpassert(
ASSOCIATED(qs_kind_set))
1185 iw =
cp_print_key_unit_nr(logger, cdft_constraint_section,
"PROGRAM_RUN_INFO", extension=
".cdftLog")
1186 cdft_control => dft_control%qs_control%cdft_control
1188 becke_control => cdft_control%becke_control
1189 IF (is_becke .AND. .NOT.
ASSOCIATED(becke_control)) &
1190 cpabort(
"Becke control has not been allocated.")
1191 group => cdft_control%group
1193 nvar =
SIZE(cdft_control%target)
1194 ALLOCATE (strength(nvar))
1195 ALLOCATE (target_val(nvar))
1197 strength(:) = cdft_control%strength(:)
1198 target_val(:) = cdft_control%target(:)
1201 dvol = group(1)%weight%pw_grid%dvol
1202 IF (cdft_control%atomic_charges)
THEN
1203 charge => cdft_control%charge
1204 ALLOCATE (electronic_charge(cdft_control%natoms, dft_control%nspins))
1205 electronic_charge = 0.0_dp
1208 DO i = 1, dft_control%nspins
1209 DO igroup = 1,
SIZE(group)
1210 SELECT CASE (group(igroup)%constraint_type)
1226 cpabort(
"Unknown constraint type.")
1228 IF (is_becke .AND. (cdft_control%external_control .AND. becke_control%cavity_confine))
THEN
1230 eps_cavity = becke_control%eps_cavity
1232 CALL cp_abort(__location__, &
1233 "Multiple constraints not yet supported by parallel mixed calculations.")
1234 de(igroup) = de(igroup) + sign*
accurate_dot_product(group(igroup)%weight%array, rho_r(i)%array, &
1235 becke_control%cavity_mat, eps_cavity)*dvol
1237 de(igroup) = de(igroup) + sign*
pw_integral_ab(group(igroup)%weight, rho_r(i), local_only=.true.)
1240 IF (cdft_control%atomic_charges)
THEN
1241 DO iatom = 1, cdft_control%natoms
1242 electronic_charge(iatom, i) =
pw_integral_ab(charge(iatom), rho_r(i), local_only=.true.)
1247 CALL para_env%sum(de)
1248 IF (cdft_control%atomic_charges)
THEN
1249 CALL para_env%sum(electronic_charge)
1252 IF (cdft_control%fragment_density .AND. .NOT. cdft_control%fragments_integrated)
THEN
1253 CALL prepare_fragment_constraint(qs_env)
1255 IF (dft_control%qs_control%gapw)
THEN
1257 IF (cdft_control%fragment_density) &
1258 CALL cp_abort(__location__, &
1259 "Fragment constraints not yet compatible with GAPW.")
1260 ALLOCATE (gapw_offset(nvar, dft_control%nspins))
1261 gapw_offset = 0.0_dp
1262 CALL get_qs_env(qs_env, rho0_mpole=rho0_mpole)
1264 DO i = 1, dft_control%nspins
1265 DO igroup = 1,
SIZE(group)
1266 DO iatom = 1,
SIZE(group(igroup)%atoms)
1267 SELECT CASE (group(igroup)%constraint_type)
1283 cpabort(
"Unknown constraint type.")
1285 jatom = group(igroup)%atoms(iatom)
1286 CALL get_atomic_kind(particle_set(jatom)%atomic_kind, kind_number=ikind)
1287 CALL get_qs_kind(qs_kind_set(ikind), paw_atom=paw_atom)
1289 gapw_offset(igroup, i) = gapw_offset(igroup, i) + sign*group(igroup)%coeff(iatom)*mp_rho(jatom)%q0(i)
1294 IF (cdft_control%atomic_charges)
THEN
1295 DO iatom = 1, cdft_control%natoms
1296 jatom = cdft_control%atoms(iatom)
1297 CALL get_atomic_kind(particle_set(jatom)%atomic_kind, kind_number=ikind)
1298 CALL get_qs_kind(qs_kind_set(ikind), paw_atom=paw_atom)
1300 DO i = 1, dft_control%nspins
1301 electronic_charge(iatom, i) = electronic_charge(iatom, i) + mp_rho(jatom)%q0(i)
1306 DO i = 1, dft_control%nspins
1308 de(ivar) = de(ivar) + gapw_offset(ivar, i)
1311 DEALLOCATE (gapw_offset)
1314 cdft_control%value(:) = de(:)
1315 energy%cdft = 0.0_dp
1317 energy%cdft = energy%cdft + (de(ivar) - target_val(ivar))*strength(ivar)
1322 DEALLOCATE (de, strength, target_val)
1323 IF (cdft_control%atomic_charges)
DEALLOCATE (electronic_charge)
1325 CALL timestop(handle)
1327 END SUBROUTINE cdft_constraint_integrate
1333 SUBROUTINE cdft_constraint_force(qs_env)
1336 CHARACTER(len=*),
PARAMETER :: routinen =
'cdft_constraint_force'
1338 INTEGER :: handle, i, iatom, igroup, ikind, ispin, &
1340 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
1341 INTEGER,
DIMENSION(2, 3) :: bo
1342 INTEGER,
DIMENSION(3) :: lb, ub
1343 REAL(kind=
dp) :: dvol, eps_cavity, sign
1344 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: strength
1345 REAL(kind=
dp),
DIMENSION(:),
POINTER :: cutoffs
1358 CALL timeset(routinen, handle)
1359 NULLIFY (atomic_kind_set, cell, para_env, dft_control, particle_set, &
1360 rho, rho_r, force, cutoffs, becke_control, group)
1363 atomic_kind_set=atomic_kind_set, &
1365 particle_set=particle_set, &
1369 dft_control=dft_control, &
1373 cdft_control => dft_control%qs_control%cdft_control
1374 becke_control => cdft_control%becke_control
1375 group => cdft_control%group
1376 nvar =
SIZE(cdft_control%target)
1377 ALLOCATE (strength(nvar))
1378 strength(:) = cdft_control%strength(:)
1379 cutoffs => cdft_control%becke_control%cutoffs
1380 eps_cavity = cdft_control%becke_control%eps_cavity
1383 atom_of_kind=atom_of_kind, &
1385 DO igroup = 1,
SIZE(cdft_control%group)
1386 ALLOCATE (cdft_control%group(igroup)%integrated(3, natom))
1387 cdft_control%group(igroup)%integrated = 0.0_dp
1390 lb(1:3) = rho_r(1)%pw_grid%bounds_local(1, 1:3)
1391 ub(1:3) = rho_r(1)%pw_grid%bounds_local(2, 1:3)
1392 bo = cdft_control%group(1)%weight%pw_grid%bounds_local
1393 dvol = cdft_control%group(1)%weight%pw_grid%dvol
1397 IF (.NOT. cdft_control%becke_control%in_memory)
THEN
1398 CALL becke_constraint_low(qs_env, just_gradients=.true.)
1402 IF (.NOT. cdft_control%in_memory)
THEN
1403 CALL hirshfeld_constraint_low(qs_env, just_gradients=.true.)
1408 IF (.NOT.
ASSOCIATED(becke_control%cavity_mat))
THEN
1410 DO k = bo(1, 1), bo(2, 1)
1411 DO j = bo(1, 2), bo(2, 2)
1412 DO i = bo(1, 3), bo(2, 3)
1414 IF (cdft_control%becke_control%cavity_confine)
THEN
1415 IF (cdft_control%becke_control%cavity%array(k, j, i) < eps_cavity) cycle
1418 DO igroup = 1,
SIZE(cdft_control%group)
1420 DO ispin = 1, dft_control%nspins
1422 SELECT CASE (cdft_control%group(igroup)%constraint_type)
1426 IF (ispin == 1)
THEN
1433 IF (ispin == 2) cycle
1436 IF (ispin == 1) cycle
1438 cpabort(
"Unknown constraint type.")
1443 cdft_control%group(igroup)%integrated(:, iatom) = &
1444 cdft_control%group(igroup)%integrated(:, iatom) + sign* &
1445 cdft_control%group(igroup)%gradients(3*(iatom - 1) + 1:3*(iatom - 1) + 3, k, j, i) &
1446 *rho_r(ispin)%array(k, j, i) &
1451 cdft_control%group(igroup)%integrated(1, iatom) = &
1452 cdft_control%group(igroup)%integrated(1, iatom) + sign* &
1453 cdft_control%group(igroup)%gradients_x(iatom, k, j, i) &
1454 *rho_r(ispin)%array(k, j, i) &
1457 cdft_control%group(igroup)%integrated(2, iatom) = &
1458 cdft_control%group(igroup)%integrated(2, iatom) + sign* &
1459 cdft_control%group(igroup)%gradients_y(iatom, k, j, i) &
1460 *rho_r(ispin)%array(k, j, i) &
1463 cdft_control%group(igroup)%integrated(3, iatom) = &
1464 cdft_control%group(igroup)%integrated(3, iatom) + sign* &
1465 cdft_control%group(igroup)%gradients_z(iatom, k, j, i) &
1466 *rho_r(ispin)%array(k, j, i) &
1480 DO k = lbound(cdft_control%becke_control%cavity_mat, 1), ubound(cdft_control%becke_control%cavity_mat, 1)
1481 DO j = lbound(cdft_control%becke_control%cavity_mat, 2), ubound(cdft_control%becke_control%cavity_mat, 2)
1482 DO i = lbound(cdft_control%becke_control%cavity_mat, 3), ubound(cdft_control%becke_control%cavity_mat, 3)
1485 IF (cdft_control%becke_control%cavity_mat(k, j, i) < eps_cavity) cycle
1487 DO igroup = 1,
SIZE(group)
1489 DO ispin = 1, dft_control%nspins
1490 SELECT CASE (group(igroup)%constraint_type)
1494 IF (ispin == 1)
THEN
1501 IF (ispin == 2) cycle
1504 IF (ispin == 1) cycle
1506 cpabort(
"Unknown constraint type.")
1512 cdft_control%group(igroup)%integrated(:, iatom) = &
1513 cdft_control%group(igroup)%integrated(:, iatom) + sign* &
1514 cdft_control%group(igroup)%gradients(3*(iatom - 1) + 1:3*(iatom - 1) + 3, k, j, i) &
1515 *rho_r(ispin)%array(k, j, i) &
1520 cdft_control%group(igroup)%integrated(1, iatom) = &
1521 cdft_control%group(igroup)%integrated(1, iatom) + sign* &
1522 cdft_control%group(igroup)%gradients_x(iatom, k, j, i) &
1523 *rho_r(ispin)%array(k, j, i) &
1526 cdft_control%group(igroup)%integrated(2, iatom) = &
1527 cdft_control%group(igroup)%integrated(2, iatom) + sign* &
1528 cdft_control%group(igroup)%gradients_y(iatom, k, j, i) &
1529 *rho_r(ispin)%array(k, j, i) &
1532 cdft_control%group(igroup)%integrated(3, iatom) = &
1533 cdft_control%group(igroup)%integrated(3, iatom) + sign* &
1534 cdft_control%group(igroup)%gradients_z(iatom, k, j, i) &
1535 *rho_r(ispin)%array(k, j, i) &
1548 IF (.NOT. cdft_control%transfer_pot)
THEN
1550 DO igroup = 1,
SIZE(group)
1551 DEALLOCATE (cdft_control%group(igroup)%gradients)
1554 DO igroup = 1,
SIZE(group)
1555 DEALLOCATE (cdft_control%group(igroup)%gradients_x)
1556 DEALLOCATE (cdft_control%group(igroup)%gradients_y)
1557 DEALLOCATE (cdft_control%group(igroup)%gradients_z)
1562 DO igroup = 1,
SIZE(group)
1563 CALL para_env%sum(group(igroup)%integrated)
1569 IF (para_env%is_source())
THEN
1570 DO igroup = 1,
SIZE(group)
1572 ikind = kind_of(iatom)
1573 i = atom_of_kind(iatom)
1574 force(ikind)%rho_elec(:, i) = force(ikind)%rho_elec(:, i) + group(igroup)%integrated(:, iatom)*strength(igroup)
1579 DEALLOCATE (strength)
1580 DO igroup = 1,
SIZE(group)
1581 DEALLOCATE (group(igroup)%integrated)
1585 CALL timestop(handle)
1587 END SUBROUTINE cdft_constraint_force
1594 SUBROUTINE prepare_fragment_constraint(qs_env)
1597 CHARACTER(len=*),
PARAMETER :: routinen =
'prepare_fragment_constraint'
1599 INTEGER :: handle, i, iatom, igroup, natom, &
1600 nelectron_total, nfrag_spins
1601 LOGICAL :: is_becke, needs_spin_density
1602 REAL(kind=
dp) :: dvol, multiplier(2), nelectron_frag
1614 NULLIFY (para_env, dft_control, logger, subsys, pw_env, auxbas_pw_pool, group)
1615 CALL timeset(routinen, handle)
1619 dft_control=dft_control, &
1622 cdft_control => dft_control%qs_control%cdft_control
1624 becke_control => cdft_control%becke_control
1625 IF (is_becke .AND. .NOT.
ASSOCIATED(becke_control)) &
1626 cpabort(
"Becke control has not been allocated.")
1627 group => cdft_control%group
1628 dvol = group(1)%weight%pw_grid%dvol
1630 IF (.NOT. qs_env%single_point_run) &
1631 CALL cp_abort(__location__, &
1632 "CDFT fragment constraints are only compatible with single "// &
1633 "point calculations (run_type ENERGY or ENERGY_FORCE).")
1634 IF (dft_control%qs_control%gapw) &
1635 CALL cp_abort(__location__, &
1636 "CDFT fragment constraint not compatible with GAPW.")
1637 needs_spin_density = .false.
1640 DO igroup = 1,
SIZE(group)
1641 SELECT CASE (group(igroup)%constraint_type)
1645 needs_spin_density = .true.
1647 CALL cp_abort(__location__, &
1648 "CDFT fragment constraint not yet compatible with "// &
1649 "spin specific constraints.")
1651 cpabort(
"Unknown constraint type.")
1654 IF (needs_spin_density)
THEN
1657 IF (cdft_control%flip_fragment(i)) multiplier(i) = -1.0_dp
1661 ALLOCATE (cdft_control%fragments(nfrag_spins, 2))
1662 ALLOCATE (rho_frag(nfrag_spins))
1664 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1666 CALL auxbas_pw_pool%create_pw(cdft_control%fragments(1, 1))
1668 cdft_control%fragment_a_fname, 1.0_dp)
1669 CALL auxbas_pw_pool%create_pw(cdft_control%fragments(1, 2))
1671 cdft_control%fragment_b_fname, 1.0_dp)
1673 IF (needs_spin_density)
THEN
1674 CALL auxbas_pw_pool%create_pw(cdft_control%fragments(2, 1))
1676 cdft_control%fragment_a_spin_fname, multiplier(1))
1677 CALL auxbas_pw_pool%create_pw(cdft_control%fragments(2, 2))
1679 cdft_control%fragment_b_spin_fname, multiplier(2))
1682 DO i = 1, nfrag_spins
1683 CALL auxbas_pw_pool%create_pw(rho_frag(i))
1684 CALL pw_copy(cdft_control%fragments(i, 1), rho_frag(i))
1685 CALL pw_axpy(cdft_control%fragments(i, 2), rho_frag(i), 1.0_dp)
1686 CALL auxbas_pw_pool%give_back_pw(cdft_control%fragments(i, 1))
1687 CALL auxbas_pw_pool%give_back_pw(cdft_control%fragments(i, 2))
1689 DEALLOCATE (cdft_control%fragments)
1694 IF (nint(nelectron_frag) /= nelectron_total) &
1695 CALL cp_abort(__location__, &
1696 "The number of electrons in the reference and interacting "// &
1697 "configurations does not match. Check your fragment cube files.")
1699 cdft_control%target = 0.0_dp
1700 DO igroup = 1,
SIZE(group)
1706 IF (is_becke .AND. (cdft_control%external_control .AND. becke_control%cavity_confine))
THEN
1707 cdft_control%target(igroup) = cdft_control%target(igroup) + &
1709 becke_control%cavity_mat, becke_control%eps_cavity)*dvol
1711 cdft_control%target(igroup) = cdft_control%target(igroup) + &
1712 pw_integral_ab(group(igroup)%weight, rho_frag(i), local_only=.true.)
1715 CALL para_env%sum(cdft_control%target)
1717 IF (cdft_control%atomic_charges)
THEN
1718 ALLOCATE (cdft_control%charges_fragment(cdft_control%natoms, nfrag_spins))
1719 DO i = 1, nfrag_spins
1720 DO iatom = 1, cdft_control%natoms
1721 cdft_control%charges_fragment(iatom, i) = &
1722 pw_integral_ab(cdft_control%charge(iatom), rho_frag(i), local_only=.true.)
1725 CALL para_env%sum(cdft_control%charges_fragment)
1727 DO i = 1, nfrag_spins
1728 CALL auxbas_pw_pool%give_back_pw(rho_frag(i))
1730 DEALLOCATE (rho_frag)
1731 cdft_control%fragments_integrated = .true.
1733 CALL timestop(handle)
1735 END SUBROUTINE prepare_fragment_constraint
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
All kind of helpful little routines.
real(kind=dp) function, public exp_radius_very_extended(la_min, la_max, lb_min, lb_max, pab, o1, o2, ra, rb, rp, zetp, eps, prefactor, cutoff, epsabs)
computes the radius of the Gaussian outside of which it is smaller than eps
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
Handles all functions related to the CELL.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
A wrapper around pw_to_cube() which accepts particle_list_type.
subroutine, public cp_cube_to_pw(grid, filename, scaling, silent)
Thin wrapper around routine cube_to_pw.
Fortran API for the grid package, which is written in C.
integer, parameter, public grid_func_ab
subroutine, public collocate_pgf_product(la_max, zeta, la_min, lb_max, zetb, lb_min, ra, rab, scale, pab, o1, o2, rsgrid, ga_gb_function, radius, use_subpatch, subpatch_pattern)
low level collocation of primitive gaussian functions
The types needed for the calculation of Hirshfeld charges and related functions.
sums arrays of real/complex numbers with much reduced round-off as compared to a naive implementation...
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
Define the data structure for the particle information.
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 ...
Subroutines for building CDFT constraints.
subroutine, public becke_constraint(qs_env, calc_pot, calculate_forces)
Driver routine for calculating a Becke constraint.
subroutine, public hirshfeld_constraint(qs_env, calc_pot, calculate_forces)
Driver routine for calculating a Hirshfeld constraint.
Defines CDFT control structures.
Utility subroutines for CDFT calculations.
subroutine, public cdft_constraint_print(qs_env, electronic_charge)
Prints information about CDFT constraints.
subroutine, public hirshfeld_constraint_init(qs_env)
Initializes Gaussian Hirshfeld constraints.
subroutine, public becke_constraint_init(qs_env)
Initializes the Becke constraint environment.
subroutine, public hfun_scale(fout, fun1, fun2, divide, small)
Calculate fout = fun1/fun2 or fout = fun1*fun2.
subroutine, public cdft_print_hirshfeld_density(qs_env)
Prints Hirshfeld weight function and promolecule density.
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, 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, 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, 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, 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, ecoul_1c, rho0_s_rs, rho0_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)
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, 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, 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, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_rho0_mpole(rho0_mpole, g0_h, vg0_h, iat, ikind, lmax_0, l0_ikind, mp_gau_ikind, mp_rho, norm_g0l_h, qlm_gg, qlm_car, qlm_tot, zet0_h, igrid_zet0_s, rpgf0_h, rpgf0_s, max_rpgf0_s, rho0_s_rs, rho0_s_gs)
...
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...
types that represent a quickstep subsys
subroutine, public qs_subsys_get(subsys, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell, energy, force, qs_kind_set, cp_subsys, nelectron_total, nelectron_spin)
...
subroutine, public rs_grid_create(rs, desc)
...
subroutine, public transfer_rs2pw(rs, pw)
...
subroutine, public rs_grid_release(rs_grid)
releases the given rs grid (see doc/ReferenceCounting.html)
subroutine, public rs_grid_zero(rs)
Initialize grid to zero.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
quantities needed for a Hirshfeld based partitioning of real space
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 ...
control parameters for CDFT simulations
Provides all information about a quickstep kind.
keeps the density in various representations, keeping track of which ones are valid.