45 USE dbcsr_api,
ONLY: dbcsr_copy,&
74 neighbor_list_iterator_p_type,&
76 neighbor_list_set_p_type
82 #include "./base/base_uses.f90"
88 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_efield_berry'
108 TYPE(qs_environment_type),
POINTER :: qs_env
109 LOGICAL,
INTENT(IN) :: just_energy, calculate_forces
111 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_efield_berry_phase'
114 LOGICAL :: s_mstruct_changed
115 TYPE(dft_control_type),
POINTER :: dft_control
117 CALL timeset(routinen, handle)
119 NULLIFY (dft_control)
120 CALL get_qs_env(qs_env, s_mstruct_changed=s_mstruct_changed, &
121 dft_control=dft_control)
123 IF (dft_control%apply_period_efield)
THEN
124 IF (s_mstruct_changed)
CALL qs_efield_integrals(qs_env)
125 IF (dft_control%period_efield%displacement_field)
THEN
126 CALL qs_dispfield_derivatives(qs_env, just_energy, calculate_forces)
128 CALL qs_efield_derivatives(qs_env, just_energy, calculate_forces)
132 CALL timestop(handle)
140 SUBROUTINE qs_efield_integrals(qs_env)
142 TYPE(qs_environment_type),
POINTER :: qs_env
144 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_efield_integrals'
147 REAL(
dp),
DIMENSION(3) :: kvec
148 TYPE(cell_type),
POINTER :: cell
149 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: cosmat, matrix_s, sinmat
150 TYPE(dft_control_type),
POINTER :: dft_control
151 TYPE(efield_berry_type),
POINTER :: efield
153 CALL timeset(routinen, handle)
154 cpassert(
ASSOCIATED(qs_env))
156 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
158 CALL get_qs_env(qs_env=qs_env, efield=efield, cell=cell, matrix_s=matrix_s)
160 ALLOCATE (cosmat(3), sinmat(3))
162 ALLOCATE (cosmat(i)%matrix, sinmat(i)%matrix)
164 CALL dbcsr_copy(cosmat(i)%matrix, matrix_s(1)%matrix,
'COS MAT')
165 CALL dbcsr_copy(sinmat(i)%matrix, matrix_s(1)%matrix,
'SIN MAT')
166 CALL dbcsr_set(cosmat(i)%matrix, 0.0_dp)
167 CALL dbcsr_set(sinmat(i)%matrix, 0.0_dp)
169 kvec(:) =
twopi*cell%h_inv(i, :)
174 CALL timestop(handle)
176 END SUBROUTINE qs_efield_integrals
184 SUBROUTINE qs_efield_derivatives(qs_env, just_energy, calculate_forces)
185 TYPE(qs_environment_type),
POINTER :: qs_env
186 LOGICAL,
INTENT(IN) :: just_energy, calculate_forces
188 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_efield_derivatives'
190 COMPLEX(dp) :: zdet, zdeta, zi(3)
191 INTEGER :: atom_a, atom_b, handle, i, ia, iatom, icol, idir, ikind, irow, iset, ispin, j, &
192 jatom, jkind, jset, ldab, ldsa, ldsb, lsab, n1, n2, nao, natom, ncoa, ncob, nkind, nmo, &
193 nseta, nsetb, sgfa, sgfb
194 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind
195 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
197 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
198 LOGICAL :: found, uniform, use_virial
199 REAL(
dp) :: charge, ci(3), cqi(3), dab, dd, &
200 ener_field, f0, fab, fieldpol(3), &
201 focc, fpolvec(3), hmat(3, 3), occ, &
203 REAL(
dp),
DIMENSION(3) :: forcea, forceb, kvec, ra, rab, rb, ria
204 REAL(
dp),
DIMENSION(:, :),
POINTER :: cosab, iblock, rblock, sinab, work
205 REAL(
dp),
DIMENSION(:, :, :),
POINTER :: dcosab, dsinab
206 REAL(kind=
dp),
DIMENSION(:),
POINTER :: set_radius_a, set_radius_b
207 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: rpgfa, rpgfb, sphi_a, sphi_b, zeta, zetb
208 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
209 TYPE(block_p_type),
DIMENSION(3, 2) :: dcost, dsint
210 TYPE(cell_type),
POINTER :: cell
211 TYPE(cp_cfm_type),
ALLOCATABLE,
DIMENSION(:) :: eigrmat, inv_mat
212 TYPE(cp_fm_struct_type),
POINTER :: tmp_fm_struct
213 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: mo_coeff_tmp, mo_derivs_tmp
214 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: inv_work, op_fm_set, opvec
215 TYPE(cp_fm_type),
POINTER :: mo_coeff
216 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, mo_derivs
217 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: tempmat
218 TYPE(dbcsr_type),
POINTER :: cosmat, mo_coeff_b, sinmat
219 TYPE(dft_control_type),
POINTER :: dft_control
220 TYPE(efield_berry_type),
POINTER :: efield
221 TYPE(gto_basis_set_p_type),
DIMENSION(:),
POINTER :: basis_set_list
222 TYPE(gto_basis_set_type),
POINTER :: basis_set_a, basis_set_b
223 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
224 TYPE(mp_para_env_type),
POINTER :: para_env
225 TYPE(neighbor_list_iterator_p_type), &
226 DIMENSION(:),
POINTER :: nl_iterator
227 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
229 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
230 TYPE(qs_energy_type),
POINTER :: energy
231 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
232 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
233 TYPE(qs_kind_type),
POINTER :: qs_kind
234 TYPE(virial_type),
POINTER :: virial
236 CALL timeset(routinen, handle)
238 NULLIFY (dft_control, cell, particle_set)
239 CALL get_qs_env(qs_env, dft_control=dft_control, cell=cell, &
240 particle_set=particle_set, virial=virial)
241 NULLIFY (qs_kind_set, efield, para_env, sab_orb)
242 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, &
243 efield=efield, energy=energy, para_env=para_env, sab_orb=sab_orb)
246 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
247 use_virial = use_virial .AND. calculate_forces
250 cpabort(
"Stress tensor for periodic E-field not implemented")
253 fieldpol = dft_control%period_efield%polarisation
254 fieldpol = fieldpol/sqrt(dot_product(fieldpol, fieldpol))
255 fieldpol = -fieldpol*dft_control%period_efield%strength
256 hmat = cell%hmat(:, :)/
twopi
258 fpolvec(idir) = fieldpol(1)*hmat(1, idir) + fieldpol(2)*hmat(2, idir) + fieldpol(3)*hmat(3, idir)
262 natom =
SIZE(particle_set)
263 IF (calculate_forces)
THEN
264 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, force=force)
267 zi(:) = cmplx(1._dp, 0._dp,
dp)
270 CALL get_qs_kind(qs_kind_set(ikind), core_charge=charge)
271 ria = particle_set(ia)%r
274 kvec(:) =
twopi*cell%h_inv(idir, :)
275 dd = sum(kvec(:)*ria(:))
276 zdeta = cmplx(cos(dd), sin(dd), kind=
dp)**charge
277 zi(idir) = zi(idir)*zdeta
279 IF (calculate_forces)
THEN
280 IF (para_env%mepos == 0)
THEN
281 iatom = atom_of_kind(ia)
282 forcea(:) = fieldpol(:)*charge
283 force(ikind)%efield(:, iatom) = force(ikind)%efield(:, iatom) + forcea(:)
287 IF (para_env%mepos == 0) &
296 DO ispin = 1, dft_control%nspins
297 CALL get_mo_set(mo_set=mos(ispin), maxocc=occ, uniform_occupation=uniform)
298 IF (.NOT. uniform)
THEN
299 cpabort(
"Berry phase moments for non uniform MOs' occupation numbers not implemented")
304 CALL get_qs_env(qs_env=qs_env, mo_derivs=mo_derivs)
306 ALLOCATE (op_fm_set(2, dft_control%nspins))
307 ALLOCATE (opvec(2, dft_control%nspins))
308 ALLOCATE (eigrmat(dft_control%nspins))
309 ALLOCATE (inv_mat(dft_control%nspins))
310 ALLOCATE (inv_work(2, dft_control%nspins))
311 ALLOCATE (mo_derivs_tmp(
SIZE(mo_derivs)))
312 ALLOCATE (mo_coeff_tmp(
SIZE(mo_derivs)))
315 DO ispin = 1, dft_control%nspins
316 NULLIFY (tmp_fm_struct, mo_coeff)
317 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, nao=nao, nmo=nmo)
319 ncol_global=nmo, para_env=para_env, context=mo_coeff%matrix_struct%context)
320 CALL cp_fm_create(mo_derivs_tmp(ispin), mo_coeff%matrix_struct)
321 CALL cp_fm_create(mo_coeff_tmp(ispin), mo_coeff%matrix_struct)
323 DO i = 1,
SIZE(op_fm_set, 1)
324 CALL cp_fm_create(opvec(i, ispin), mo_coeff%matrix_struct)
326 CALL cp_fm_create(inv_work(i, ispin), op_fm_set(i, ispin)%matrix_struct)
328 CALL cp_cfm_create(eigrmat(ispin), op_fm_set(1, ispin)%matrix_struct)
329 CALL cp_cfm_create(inv_mat(ispin), op_fm_set(1, ispin)%matrix_struct)
333 IF (calculate_forces)
THEN
335 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
336 ALLOCATE (tempmat(2, dft_control%nspins))
337 DO ispin = 1, dft_control%nspins
338 ALLOCATE (tempmat(1, ispin)%matrix, tempmat(2, ispin)%matrix)
339 CALL dbcsr_copy(tempmat(1, ispin)%matrix, matrix_s(1)%matrix,
'TEMPMAT')
340 CALL dbcsr_copy(tempmat(2, ispin)%matrix, matrix_s(1)%matrix,
'TEMPMAT')
341 CALL dbcsr_set(tempmat(1, ispin)%matrix, 0.0_dp)
342 CALL dbcsr_set(tempmat(2, ispin)%matrix, 0.0_dp)
346 ALLOCATE (cosab(ldab, ldab), sinab(ldab, ldab), work(ldab, ldab))
347 ALLOCATE (dcosab(ldab, ldab, 3), dsinab(ldab, ldab, 3))
348 lsab = max(ldab, lsab)
350 ALLOCATE (dcost(i, 1)%block(lsab, lsab), dsint(i, 1)%block(lsab, lsab))
351 ALLOCATE (dcost(i, 2)%block(lsab, lsab), dsint(i, 2)%block(lsab, lsab))
360 IF (abs(fpolvec(idir)) .GT. 1.0e-12_dp)
THEN
361 cosmat => efield%cosmat(idir)%matrix
362 sinmat => efield%sinmat(idir)%matrix
365 DO ispin = 1, dft_control%nspins
366 IF (mos(ispin)%use_mo_coeff_b)
THEN
367 CALL get_mo_set(mo_set=mos(ispin), nao=nao, mo_coeff_b=mo_coeff_b, nmo=nmo)
370 CALL get_mo_set(mo_set=mos(ispin), nao=nao, mo_coeff=mo_coeff, nmo=nmo)
371 mo_coeff_tmp(ispin) = mo_coeff
374 CALL parallel_gemm(
"T",
"N", nmo, nmo, nao, 1.0_dp, mo_coeff_tmp(ispin), opvec(1, ispin), 0.0_dp, &
377 CALL parallel_gemm(
"T",
"N", nmo, nmo, nao, 1.0_dp, mo_coeff_tmp(ispin), opvec(2, ispin), 0.0_dp, &
382 DO ispin = 1, dft_control%nspins
386 CALL cp_cfm_solve(eigrmat(ispin), inv_mat(ispin), zdeta)
390 ci(idir) = aimag(log(zdet**occ))
392 IF (.NOT. just_energy)
THEN
395 DO ispin = 1, dft_control%nspins
396 inv_work(1, ispin)%local_data(:, :) = real(inv_mat(ispin)%local_data(:, :),
dp)
397 inv_work(2, ispin)%local_data(:, :) = aimag(inv_mat(ispin)%local_data(:, :))
398 CALL get_mo_set(mo_set=mos(ispin), nao=nao, nmo=nmo)
399 CALL parallel_gemm(
"N",
"N", nao, nmo, nmo, focc, opvec(1, ispin), inv_work(2, ispin), &
400 1.0_dp, mo_derivs_tmp(ispin))
401 CALL parallel_gemm(
"N",
"N", nao, nmo, nmo, -focc, opvec(2, ispin), inv_work(1, ispin), &
402 1.0_dp, mo_derivs_tmp(ispin))
407 IF (calculate_forces)
THEN
408 nkind =
SIZE(qs_kind_set)
409 natom =
SIZE(particle_set)
410 kvec(:) =
twopi*cell%h_inv(idir, :)
414 DO ispin = 1, dft_control%nspins
415 CALL dbcsr_set(tempmat(1, ispin)%matrix, 0.0_dp)
416 CALL dbcsr_set(tempmat(2, ispin)%matrix, 0.0_dp)
417 CALL get_mo_set(mo_set=mos(ispin), nao=nao, nmo=nmo)
418 CALL parallel_gemm(
"N",
"N", nao, nmo, nmo, 1.0_dp, mo_coeff_tmp(ispin), inv_work(1, ispin), 0.0_dp, &
420 CALL parallel_gemm(
"N",
"N", nao, nmo, nmo, 1.0_dp, mo_coeff_tmp(ispin), inv_work(2, ispin), 0.0_dp, &
423 matrix_v=opvec(1, ispin), matrix_g=mo_coeff_tmp(ispin), ncol=nmo)
425 matrix_v=opvec(2, ispin), matrix_g=mo_coeff_tmp(ispin), ncol=nmo)
429 ALLOCATE (basis_set_list(nkind))
431 qs_kind => qs_kind_set(ikind)
432 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set_a)
433 IF (
ASSOCIATED(basis_set_a))
THEN
434 basis_set_list(ikind)%gto_basis_set => basis_set_a
436 NULLIFY (basis_set_list(ikind)%gto_basis_set)
443 iatom=iatom, jatom=jatom, r=rab)
444 basis_set_a => basis_set_list(ikind)%gto_basis_set
445 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
446 basis_set_b => basis_set_list(jkind)%gto_basis_set
447 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
449 first_sgfa => basis_set_a%first_sgf
450 la_max => basis_set_a%lmax
451 la_min => basis_set_a%lmin
452 npgfa => basis_set_a%npgf
453 nseta = basis_set_a%nset
454 nsgfa => basis_set_a%nsgf_set
455 rpgfa => basis_set_a%pgf_radius
456 set_radius_a => basis_set_a%set_radius
457 sphi_a => basis_set_a%sphi
458 zeta => basis_set_a%zet
460 first_sgfb => basis_set_b%first_sgf
461 lb_max => basis_set_b%lmax
462 lb_min => basis_set_b%lmin
463 npgfb => basis_set_b%npgf
464 nsetb = basis_set_b%nset
465 nsgfb => basis_set_b%nsgf_set
466 rpgfb => basis_set_b%pgf_radius
467 set_radius_b => basis_set_b%set_radius
468 sphi_b => basis_set_b%sphi
469 zetb => basis_set_b%zet
471 atom_a = atom_of_kind(iatom)
472 atom_b = atom_of_kind(jatom)
474 ldsa =
SIZE(sphi_a, 1)
475 ldsb =
SIZE(sphi_b, 1)
476 ra(:) =
pbc(particle_set(iatom)%r(:), cell)
478 dab = sqrt(rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3))
480 IF (iatom <= jatom)
THEN
488 IF (iatom == jatom .AND. dab < 1.e-10_dp)
THEN
495 dcost(i, 1)%block = 0.0_dp
496 dsint(i, 1)%block = 0.0_dp
497 dcost(i, 2)%block = 0.0_dp
498 dsint(i, 2)%block = 0.0_dp
502 ncoa = npgfa(iset)*
ncoset(la_max(iset))
503 sgfa = first_sgfa(1, iset)
505 IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
506 ncob = npgfb(jset)*
ncoset(lb_max(jset))
507 sgfb = first_sgfb(1, jset)
509 CALL cossin(la_max(iset), npgfa(iset), zeta(:, iset), rpgfa(:, iset), la_min(iset), &
510 lb_max(jset), npgfb(jset), zetb(:, jset), rpgfb(:, jset), lb_min(jset), &
511 ra, rb, kvec, cosab, sinab, dcosab, dsinab)
513 CALL contract_all(dcost(i, 1)%block, dsint(i, 1)%block, &
514 ncoa, nsgfa(iset), sgfa, sphi_a, ldsa, &
515 ncob, nsgfb(jset), sgfb, sphi_b, ldsb, &
516 dcosab(:, :, i), dsinab(:, :, i), ldab, work, ldab)
519 CALL cossin(lb_max(jset), npgfb(jset), zetb(:, jset), rpgfb(:, jset), lb_min(jset), &
520 la_max(iset), npgfa(iset), zeta(:, iset), rpgfa(:, iset), la_min(iset), &
521 rb, ra, kvec, cosab, sinab, dcosab, dsinab)
523 dcosab(1:ncoa, 1:ncob, i) = transpose(dcosab(1:ncob, 1:ncoa, i))
524 dsinab(1:ncoa, 1:ncob, i) = transpose(dsinab(1:ncob, 1:ncoa, i))
525 CALL contract_all(dcost(i, 2)%block, dsint(i, 2)%block, &
526 ncoa, nsgfa(iset), sgfa, sphi_a, ldsa, &
527 ncob, nsgfb(jset), sgfb, sphi_b, ldsb, &
528 dcosab(:, :, i), dsinab(:, :, i), ldab, work, ldab)
534 DO ispin = 1, dft_control%nspins
535 NULLIFY (rblock, iblock)
536 CALL dbcsr_get_block_p(matrix=tempmat(1, ispin)%matrix, &
537 row=irow, col=icol, block=rblock, found=found)
539 CALL dbcsr_get_block_p(matrix=tempmat(2, ispin)%matrix, &
540 row=irow, col=icol, block=iblock, found=found)
544 cpassert(
SIZE(iblock, 1) == n1)
545 cpassert(
SIZE(iblock, 2) == n2)
548 IF (iatom <= jatom)
THEN
550 forcea(i) = forcea(i) + sum(rblock(1:n1, 1:n2)*dsint(i, 1)%block(1:n1, 1:n2)) &
551 - sum(iblock(1:n1, 1:n2)*dcost(i, 1)%block(1:n1, 1:n2))
552 forceb(i) = forceb(i) + sum(rblock(1:n1, 1:n2)*dsint(i, 2)%block(1:n1, 1:n2)) &
553 - sum(iblock(1:n1, 1:n2)*dcost(i, 2)%block(1:n1, 1:n2))
557 forcea(i) = forcea(i) + sum(transpose(rblock(1:n1, 1:n2))*dsint(i, 1)%block(1:n2, 1:n1)) &
558 - sum(transpose(iblock(1:n1, 1:n2))*dcost(i, 1)%block(1:n2, 1:n1))
559 forceb(i) = forceb(i) + sum(transpose(rblock(1:n1, 1:n2))*dsint(i, 2)%block(1:n2, 1:n1)) &
560 - sum(transpose(iblock(1:n1, 1:n2))*dcost(i, 2)%block(1:n2, 1:n1))
564 force(ikind)%efield(1:3, atom_a) = force(ikind)%efield(1:3, atom_a) - fab*fpolvec(idir)*forcea(1:3)
565 force(jkind)%efield(1:3, atom_b) = force(jkind)%efield(1:3, atom_b) - fab*fpolvec(idir)*forceb(1:3)
567 f0 = -fab*fpolvec(idir)
574 DEALLOCATE (basis_set_list)
585 cqi(idir) = qi(idir) + ci(idir)
586 IF (cqi(idir) >
pi) cqi(idir) = cqi(idir) -
twopi
587 IF (cqi(idir) < -
pi) cqi(idir) = cqi(idir) +
twopi
589 IF (abs(efield%polarisation(idir) - cqi(idir)) >
pi)
THEN
590 ti(idir) = (efield%polarisation(idir) - cqi(idir))/
pi
592 cqi(idir) = cqi(idir) + sign(1.0_dp, ti(idir))*
twopi
593 IF (abs(efield%polarisation(idir) - cqi(idir)) <
pi)
EXIT
596 ener_field = ener_field + fpolvec(idir)*cqi(idir)
600 IF (calculate_forces)
THEN
602 IF (abs(efield%field_energy - ener_field) >
pi*abs(sum(fpolvec)))
THEN
603 cpwarn(
"Large change of e-field energy detected. Correct for non-smooth energy surface")
605 efield%field_energy = ener_field
606 efield%polarisation(:) = cqi(:)
608 energy%efield = ener_field
610 IF (.NOT. just_energy)
THEN
612 DO ispin = 1, dft_control%nspins
619 ti(j) = ti(j) + hmat(j, i)*cqi(i)
624 virial%pv_virial(i, j) = virial%pv_virial(i, j) - fieldpol(i)*ti(j)
630 DO ispin = 1, dft_control%nspins
633 CALL cp_fm_release(mo_derivs_tmp(ispin))
634 IF (mos(ispin)%use_mo_coeff_b)
CALL cp_fm_release(mo_coeff_tmp(ispin))
635 DO i = 1,
SIZE(op_fm_set, 1)
636 CALL cp_fm_release(opvec(i, ispin))
637 CALL cp_fm_release(op_fm_set(i, ispin))
638 CALL cp_fm_release(inv_work(i, ispin))
641 DEALLOCATE (inv_mat, inv_work, op_fm_set, opvec, eigrmat)
642 DEALLOCATE (mo_coeff_tmp, mo_derivs_tmp)
644 IF (calculate_forces)
THEN
645 DO ikind = 1,
SIZE(atomic_kind_set)
646 CALL para_env%sum(force(ikind)%efield)
648 DEALLOCATE (cosab, sinab, work, dcosab, dsinab)
650 DEALLOCATE (dcost(i, 1)%block, dsint(i, 1)%block)
651 DEALLOCATE (dcost(i, 2)%block, dsint(i, 2)%block)
655 CALL timestop(handle)
657 END SUBROUTINE qs_efield_derivatives
665 SUBROUTINE qs_dispfield_derivatives(qs_env, just_energy, calculate_forces)
666 TYPE(qs_environment_type),
POINTER :: qs_env
667 LOGICAL,
INTENT(IN) :: just_energy, calculate_forces
669 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_dispfield_derivatives'
671 COMPLEX(dp) :: zdet, zdeta, zi(3)
672 INTEGER :: handle, i, ia, iatom, icol, idir, ikind, iodeb, irow, iset, ispin, jatom, jkind, &
673 jset, ldab, ldsa, ldsb, lsab, n1, n2, nao, natom, ncoa, ncob, nkind, nmo, nseta, nsetb, &
675 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind
676 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
678 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
679 LOGICAL :: found, uniform, use_virial
680 REAL(
dp) :: charge, ci(3), cqi(3), dab, dd, di(3), &
681 ener_field, fab, fieldpol(3), focc, &
682 hmat(3, 3), occ, omega, qi(3), &
684 REAL(
dp),
DIMENSION(3) :: dfilter, forcea, forceb, kvec, ra, rab, &
686 REAL(
dp),
DIMENSION(:, :),
POINTER :: cosab, iblock, rblock, sinab, work
687 REAL(
dp),
DIMENSION(:, :, :),
POINTER :: dcosab, dsinab, force_tmp
688 REAL(kind=
dp),
DIMENSION(:),
POINTER :: set_radius_a, set_radius_b
689 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: rpgfa, rpgfb, sphi_a, sphi_b, zeta, zetb
690 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
691 TYPE(block_p_type),
DIMENSION(3, 2) :: dcost, dsint
692 TYPE(cell_type),
POINTER :: cell
693 TYPE(cp_cfm_type),
ALLOCATABLE,
DIMENSION(:) :: eigrmat, inv_mat
694 TYPE(cp_fm_struct_type),
POINTER :: tmp_fm_struct
695 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: mo_coeff_tmp
696 TYPE(cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: inv_work, mo_derivs_tmp, op_fm_set, opvec
697 TYPE(cp_fm_type),
POINTER :: mo_coeff
698 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, mo_derivs
699 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: tempmat
700 TYPE(dbcsr_type),
POINTER :: cosmat, mo_coeff_b, sinmat
701 TYPE(dft_control_type),
POINTER :: dft_control
702 TYPE(efield_berry_type),
POINTER :: efield
703 TYPE(gto_basis_set_p_type),
DIMENSION(:),
POINTER :: basis_set_list
704 TYPE(gto_basis_set_type),
POINTER :: basis_set_a, basis_set_b
705 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
706 TYPE(mp_para_env_type),
POINTER :: para_env
707 TYPE(neighbor_list_iterator_p_type), &
708 DIMENSION(:),
POINTER :: nl_iterator
709 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
711 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
712 TYPE(qs_energy_type),
POINTER :: energy
713 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
714 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
715 TYPE(qs_kind_type),
POINTER :: qs_kind
716 TYPE(virial_type),
POINTER :: virial
718 CALL timeset(routinen, handle)
720 NULLIFY (dft_control, cell, particle_set)
721 CALL get_qs_env(qs_env, dft_control=dft_control, cell=cell, &
722 particle_set=particle_set, virial=virial)
723 NULLIFY (qs_kind_set, efield, para_env, sab_orb)
724 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, &
725 efield=efield, energy=energy, para_env=para_env, sab_orb=sab_orb)
728 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
729 use_virial = use_virial .AND. calculate_forces
732 cpabort(
"Stress tensor for periodic D-field not implemented")
735 dfilter(1:3) = dft_control%period_efield%d_filter(1:3)
737 fieldpol = dft_control%period_efield%polarisation
738 fieldpol = fieldpol/sqrt(dot_product(fieldpol, fieldpol))
739 fieldpol = fieldpol*dft_control%period_efield%strength
742 hmat = cell%hmat(:, :)/(
twopi*omega)
745 natom =
SIZE(particle_set)
746 IF (calculate_forces)
THEN
747 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, force=force)
749 ALLOCATE (force_tmp(natom, 3, 3))
752 zi(:) = cmplx(1._dp, 0._dp,
dp)
755 CALL get_qs_kind(qs_kind_set(ikind), core_charge=charge)
756 ria = particle_set(ia)%r
759 kvec(:) =
twopi*cell%h_inv(idir, :)
760 dd = sum(kvec(:)*ria(:))
761 zdeta = cmplx(cos(dd), sin(dd), kind=
dp)**charge
762 zi(idir) = zi(idir)*zdeta
764 IF (calculate_forces)
THEN
765 IF (para_env%mepos == 0)
THEN
767 force_tmp(ia, i, i) = force_tmp(ia, i, i) + charge/omega
772 rlog = aimag(log(zi))
777 DO ispin = 1, dft_control%nspins
778 CALL get_mo_set(mo_set=mos(ispin), maxocc=occ, uniform_occupation=uniform)
779 IF (.NOT. uniform)
THEN
780 cpabort(
"Berry phase moments for non uniform MO occupation numbers not implemented")
786 CALL get_qs_env(qs_env=qs_env, mo_derivs=mo_derivs)
787 ALLOCATE (op_fm_set(2, dft_control%nspins))
788 ALLOCATE (opvec(2, dft_control%nspins))
789 ALLOCATE (eigrmat(dft_control%nspins))
790 ALLOCATE (inv_mat(dft_control%nspins))
791 ALLOCATE (inv_work(2, dft_control%nspins))
792 ALLOCATE (mo_derivs_tmp(3,
SIZE(mo_derivs)))
793 ALLOCATE (mo_coeff_tmp(
SIZE(mo_derivs)))
796 DO ispin = 1, dft_control%nspins
797 NULLIFY (tmp_fm_struct, mo_coeff)
798 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, nao=nao, nmo=nmo)
800 ncol_global=nmo, para_env=para_env, context=mo_coeff%matrix_struct%context)
801 CALL cp_fm_create(mo_coeff_tmp(ispin), mo_coeff%matrix_struct)
803 CALL cp_fm_create(mo_derivs_tmp(i, ispin), mo_coeff%matrix_struct)
804 CALL cp_fm_set_all(matrix=mo_derivs_tmp(i, ispin), alpha=0.0_dp)
806 DO i = 1,
SIZE(op_fm_set, 1)
807 CALL cp_fm_create(opvec(i, ispin), mo_coeff%matrix_struct)
809 CALL cp_fm_create(inv_work(i, ispin), op_fm_set(i, ispin)%matrix_struct)
811 CALL cp_cfm_create(eigrmat(ispin), op_fm_set(1, ispin)%matrix_struct)
812 CALL cp_cfm_create(inv_mat(ispin), op_fm_set(1, ispin)%matrix_struct)
816 IF (calculate_forces)
THEN
818 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
819 ALLOCATE (tempmat(2, dft_control%nspins))
820 DO ispin = 1, dft_control%nspins
821 ALLOCATE (tempmat(1, ispin)%matrix, tempmat(2, ispin)%matrix)
822 CALL dbcsr_copy(tempmat(1, ispin)%matrix, matrix_s(1)%matrix,
'TEMPMAT')
823 CALL dbcsr_copy(tempmat(2, ispin)%matrix, matrix_s(1)%matrix,
'TEMPMAT')
824 CALL dbcsr_set(tempmat(1, ispin)%matrix, 0.0_dp)
825 CALL dbcsr_set(tempmat(2, ispin)%matrix, 0.0_dp)
829 ALLOCATE (cosab(ldab, ldab), sinab(ldab, ldab), work(ldab, ldab))
830 ALLOCATE (dcosab(ldab, ldab, 3), dsinab(ldab, ldab, 3))
831 lsab = max(lsab, ldab)
833 ALLOCATE (dcost(i, 1)%block(lsab, lsab), dsint(i, 1)%block(lsab, lsab))
834 ALLOCATE (dcost(i, 2)%block(lsab, lsab), dsint(i, 2)%block(lsab, lsab))
842 cosmat => efield%cosmat(idir)%matrix
843 sinmat => efield%sinmat(idir)%matrix
846 DO ispin = 1, dft_control%nspins
847 IF (mos(ispin)%use_mo_coeff_b)
THEN
848 CALL get_mo_set(mo_set=mos(ispin), nao=nao, mo_coeff_b=mo_coeff_b, nmo=nmo)
851 CALL get_mo_set(mo_set=mos(ispin), nao=nao, mo_coeff=mo_coeff, nmo=nmo)
852 mo_coeff_tmp(ispin) = mo_coeff
855 CALL parallel_gemm(
"T",
"N", nmo, nmo, nao, 1.0_dp, mo_coeff_tmp(ispin), opvec(1, ispin), 0.0_dp, &
858 CALL parallel_gemm(
"T",
"N", nmo, nmo, nao, 1.0_dp, mo_coeff_tmp(ispin), opvec(2, ispin), 0.0_dp, &
863 DO ispin = 1, dft_control%nspins
867 CALL cp_cfm_solve(eigrmat(ispin), inv_mat(ispin), zdeta)
871 zlog(idir) = aimag(log(zi(idir)))
873 IF (.NOT. just_energy)
THEN
875 DO ispin = 1, dft_control%nspins
876 inv_work(1, ispin)%local_data(:, :) = real(inv_mat(ispin)%local_data(:, :),
dp)
877 inv_work(2, ispin)%local_data(:, :) = aimag(inv_mat(ispin)%local_data(:, :))
878 CALL get_mo_set(mo_set=mos(ispin), nao=nao, nmo=nmo)
881 CALL parallel_gemm(
"N",
"N", nao, nmo, nmo, focc, opvec(1, ispin), inv_work(2, ispin), &
882 1.0_dp, mo_derivs_tmp(idir, ispin))
883 CALL parallel_gemm(
"N",
"N", nao, nmo, nmo, -focc, opvec(2, ispin), inv_work(1, ispin), &
884 1.0_dp, mo_derivs_tmp(idir, ispin))
890 IF (calculate_forces)
THEN
891 nkind =
SIZE(qs_kind_set)
892 natom =
SIZE(particle_set)
893 kvec(:) =
twopi*cell%h_inv(idir, :)
897 DO ispin = 1, dft_control%nspins
898 CALL dbcsr_set(tempmat(1, ispin)%matrix, 0.0_dp)
899 CALL dbcsr_set(tempmat(2, ispin)%matrix, 0.0_dp)
900 CALL get_mo_set(mo_set=mos(ispin), nao=nao, nmo=nmo)
901 CALL parallel_gemm(
"N",
"N", nao, nmo, nmo, 1.0_dp, mo_coeff_tmp(ispin), inv_work(1, ispin), 0.0_dp, &
903 CALL parallel_gemm(
"N",
"N", nao, nmo, nmo, 1.0_dp, mo_coeff_tmp(ispin), inv_work(2, ispin), 0.0_dp, &
906 matrix_v=opvec(1, ispin), matrix_g=mo_coeff_tmp(ispin), ncol=nmo)
908 matrix_v=opvec(2, ispin), matrix_g=mo_coeff_tmp(ispin), ncol=nmo)
912 ALLOCATE (basis_set_list(nkind))
914 qs_kind => qs_kind_set(ikind)
915 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set_a)
916 IF (
ASSOCIATED(basis_set_a))
THEN
917 basis_set_list(ikind)%gto_basis_set => basis_set_a
919 NULLIFY (basis_set_list(ikind)%gto_basis_set)
926 iatom=iatom, jatom=jatom, r=rab)
927 basis_set_a => basis_set_list(ikind)%gto_basis_set
928 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
929 basis_set_b => basis_set_list(jkind)%gto_basis_set
930 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
932 first_sgfa => basis_set_a%first_sgf
933 la_max => basis_set_a%lmax
934 la_min => basis_set_a%lmin
935 npgfa => basis_set_a%npgf
936 nseta = basis_set_a%nset
937 nsgfa => basis_set_a%nsgf_set
938 rpgfa => basis_set_a%pgf_radius
939 set_radius_a => basis_set_a%set_radius
940 sphi_a => basis_set_a%sphi
941 zeta => basis_set_a%zet
943 first_sgfb => basis_set_b%first_sgf
944 lb_max => basis_set_b%lmax
945 lb_min => basis_set_b%lmin
946 npgfb => basis_set_b%npgf
947 nsetb = basis_set_b%nset
948 nsgfb => basis_set_b%nsgf_set
949 rpgfb => basis_set_b%pgf_radius
950 set_radius_b => basis_set_b%set_radius
951 sphi_b => basis_set_b%sphi
952 zetb => basis_set_b%zet
954 ldsa =
SIZE(sphi_a, 1)
955 ldsb =
SIZE(sphi_b, 1)
956 ra(:) =
pbc(particle_set(iatom)%r(:), cell)
958 dab = sqrt(rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3))
960 IF (iatom <= jatom)
THEN
968 IF (iatom == jatom .AND. dab < 1.e-10_dp)
THEN
975 dcost(i, 1)%block = 0.0_dp
976 dsint(i, 1)%block = 0.0_dp
977 dcost(i, 2)%block = 0.0_dp
978 dsint(i, 2)%block = 0.0_dp
982 ncoa = npgfa(iset)*
ncoset(la_max(iset))
983 sgfa = first_sgfa(1, iset)
985 IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
986 ncob = npgfb(jset)*
ncoset(lb_max(jset))
987 sgfb = first_sgfb(1, jset)
989 CALL cossin(la_max(iset), npgfa(iset), zeta(:, iset), rpgfa(:, iset), la_min(iset), &
990 lb_max(jset), npgfb(jset), zetb(:, jset), rpgfb(:, jset), lb_min(jset), &
991 ra, rb, kvec, cosab, sinab, dcosab, dsinab)
993 CALL contract_all(dcost(i, 1)%block, dsint(i, 1)%block, &
994 ncoa, nsgfa(iset), sgfa, sphi_a, ldsa, &
995 ncob, nsgfb(jset), sgfb, sphi_b, ldsb, &
996 dcosab(:, :, i), dsinab(:, :, i), ldab, work, ldab)
999 CALL cossin(lb_max(jset), npgfb(jset), zetb(:, jset), rpgfb(:, jset), lb_min(jset), &
1000 la_max(iset), npgfa(iset), zeta(:, iset), rpgfa(:, iset), la_min(iset), &
1001 rb, ra, kvec, cosab, sinab, dcosab, dsinab)
1003 dcosab(1:ncoa, 1:ncob, i) = transpose(dcosab(1:ncob, 1:ncoa, i))
1004 dsinab(1:ncoa, 1:ncob, i) = transpose(dsinab(1:ncob, 1:ncoa, i))
1005 CALL contract_all(dcost(i, 2)%block, dsint(i, 2)%block, &
1006 ncoa, nsgfa(iset), sgfa, sphi_a, ldsa, &
1007 ncob, nsgfb(jset), sgfb, sphi_b, ldsb, &
1008 dcosab(:, :, i), dsinab(:, :, i), ldab, work, ldab)
1014 DO ispin = 1, dft_control%nspins
1015 NULLIFY (rblock, iblock)
1016 CALL dbcsr_get_block_p(matrix=tempmat(1, ispin)%matrix, &
1017 row=irow, col=icol, block=rblock, found=found)
1019 CALL dbcsr_get_block_p(matrix=tempmat(2, ispin)%matrix, &
1020 row=irow, col=icol, block=iblock, found=found)
1022 n1 =
SIZE(rblock, 1)
1023 n2 =
SIZE(rblock, 2)
1024 cpassert(
SIZE(iblock, 1) == n1)
1025 cpassert(
SIZE(iblock, 2) == n2)
1026 cpassert(lsab >= n1)
1027 cpassert(lsab >= n2)
1028 IF (iatom <= jatom)
THEN
1030 forcea(i) = forcea(i) + sum(rblock(1:n1, 1:n2)*dsint(i, 1)%block(1:n1, 1:n2)) &
1031 - sum(iblock(1:n1, 1:n2)*dcost(i, 1)%block(1:n1, 1:n2))
1032 forceb(i) = forceb(i) + sum(rblock(1:n1, 1:n2)*dsint(i, 2)%block(1:n1, 1:n2)) &
1033 - sum(iblock(1:n1, 1:n2)*dcost(i, 2)%block(1:n1, 1:n2))
1037 forcea(i) = forcea(i) + sum(transpose(rblock(1:n1, 1:n2))*dsint(i, 1)%block(1:n2, 1:n1)) &
1038 - sum(transpose(iblock(1:n1, 1:n2))*dcost(i, 1)%block(1:n2, 1:n1))
1039 forceb(i) = forceb(i) + sum(transpose(rblock(1:n1, 1:n2))*dsint(i, 2)%block(1:n2, 1:n1)) &
1040 - sum(transpose(iblock(1:n1, 1:n2))*dcost(i, 2)%block(1:n2, 1:n1))
1045 force_tmp(iatom, :, i) = force_tmp(iatom, :, i) - fab*hmat(i, idir)*forcea(:)
1046 force_tmp(jatom, :, i) = force_tmp(jatom, :, i) - fab*hmat(i, idir)*forceb(:)
1050 DEALLOCATE (basis_set_list)
1056 cqi(idir) = rlog(idir) + zlog(idir)
1057 IF (cqi(idir) >
pi) cqi(idir) = cqi(idir) -
twopi
1058 IF (cqi(idir) < -
pi) cqi(idir) = cqi(idir) +
twopi
1060 IF (calculate_forces)
THEN
1061 IF (abs(efield%polarisation(idir) - cqi(idir)) >
pi)
THEN
1062 di(idir) = (efield%polarisation(idir) - cqi(idir))/
pi
1064 cqi(idir) = cqi(idir) + sign(1.0_dp, di(idir))*
twopi
1065 IF (abs(efield%polarisation(idir) - cqi(idir)) <
pi)
EXIT
1074 ci(idir) = ci(idir) + hmat(idir, i)*cqi(i)
1079 IF (calculate_forces)
THEN
1080 ener_field = sum(ci)
1082 IF (abs(efield%field_energy - ener_field) >
pi*abs(sum(hmat)))
THEN
1083 cpwarn(
"Large change of e-field energy detected. Correct for non-smooth energy surface")
1085 efield%field_energy = ener_field
1086 efield%polarisation(:) = cqi(:)
1092 ener_field = ener_field + dfilter(i)*(fieldpol(i) - 2._dp*
twopi*ci(i))**2
1094 energy%efield = 0.25_dp*omega/
twopi*ener_field
1097 IF (para_env%is_source())
THEN
1100 WRITE (iodeb,
'(A,T61,F20.10)')
" Polarisation Quantum: ", 2._dp*
twopi*
twopi*hmat(3, 3)
1101 WRITE (iodeb,
'(A,T21,3F20.10)')
" Polarisation: ", 2._dp*
twopi*ci(1:3)
1102 WRITE (iodeb,
'(A,T21,3F20.10)')
" Displacement: ", fieldpol(1:3)
1103 WRITE (iodeb,
'(A,T21,3F20.10)')
" E-Field: ", ((fieldpol(i) - 2._dp*
twopi*ci(i)), i=1, 3)
1104 WRITE (iodeb,
'(A,T61,F20.10)')
" Disp Free Energy:", energy%efield
1108 IF (.NOT. just_energy)
THEN
1110 di(i) = -omega*(fieldpol(i) - 2._dp*
twopi*ci(i))*dfilter(i)
1113 DO ispin = 1, dft_control%nspins
1117 mo_derivs_tmp(idir, ispin))
1120 DO ispin = 1, dft_control%nspins
1125 IF (calculate_forces)
THEN
1129 iatom = atom_of_kind(ia)
1130 force(ikind)%efield(1:3, iatom) = force(ikind)%efield(1:3, iatom) + di(i)*force_tmp(ia, 1:3, i)
1135 DO ispin = 1, dft_control%nspins
1138 IF (mos(ispin)%use_mo_coeff_b)
CALL cp_fm_release(mo_coeff_tmp(ispin))
1140 CALL cp_fm_release(mo_derivs_tmp(i, ispin))
1142 DO i = 1,
SIZE(op_fm_set, 1)
1143 CALL cp_fm_release(opvec(i, ispin))
1144 CALL cp_fm_release(op_fm_set(i, ispin))
1145 CALL cp_fm_release(inv_work(i, ispin))
1148 DEALLOCATE (inv_mat, inv_work, op_fm_set, opvec, eigrmat)
1149 DEALLOCATE (mo_coeff_tmp, mo_derivs_tmp)
1151 IF (calculate_forces)
THEN
1152 DO ikind = 1,
SIZE(atomic_kind_set)
1153 CALL para_env%sum(force(ikind)%efield)
1155 DEALLOCATE (force_tmp)
1156 DEALLOCATE (cosab, sinab, work, dcosab, dsinab)
1158 DEALLOCATE (dcost(i, 1)%block, dsint(i, 1)%block)
1159 DEALLOCATE (dcost(i, 2)%block, dsint(i, 2)%block)
1163 CALL timestop(handle)
1165 END SUBROUTINE qs_dispfield_derivatives
1187 SUBROUTINE contract_all(cos_block, sin_block, &
1188 ncoa, nsgfa, sgfa, sphi_a, ldsa, &
1189 ncob, nsgfb, sgfb, sphi_b, ldsb, &
1190 cosab, sinab, ldab, work, ldwork)
1192 REAL(
dp),
DIMENSION(:, :),
POINTER :: cos_block, sin_block
1193 INTEGER,
INTENT(IN) :: ncoa, nsgfa, sgfa
1194 REAL(
dp),
DIMENSION(:, :),
INTENT(IN) :: sphi_a
1195 INTEGER,
INTENT(IN) :: ldsa, ncob, nsgfb, sgfb
1196 REAL(
dp),
DIMENSION(:, :),
INTENT(IN) :: sphi_b
1197 INTEGER,
INTENT(IN) :: ldsb
1198 REAL(
dp),
DIMENSION(:, :),
INTENT(IN) :: cosab, sinab
1199 INTEGER,
INTENT(IN) :: ldab
1200 REAL(
dp),
DIMENSION(:, :) :: work
1201 INTEGER,
INTENT(IN) :: ldwork
1205 CALL dgemm(
"N",
"N", ncoa, nsgfb, ncob, 1.0_dp, cosab(1, 1), ldab, &
1206 sphi_b(1, sgfb), ldsb, 0.0_dp, work(1, 1), ldwork)
1208 CALL dgemm(
"T",
"N", nsgfa, nsgfb, ncoa, 1.0_dp, sphi_a(1, sgfa), ldsa, &
1209 work(1, 1), ldwork, 1.0_dp, cos_block(sgfa, sgfb),
SIZE(cos_block, 1))
1212 CALL dgemm(
"N",
"N", ncoa, nsgfb, ncob, 1.0_dp, sinab(1, 1), ldab, &
1213 sphi_b(1, sgfb), ldsb, 0.0_dp, work(1, 1), ldwork)
1215 CALL dgemm(
"T",
"N", nsgfa, nsgfb, ncoa, 1.0_dp, sphi_a(1, sgfa), ldsa, &
1216 work(1, 1), ldwork, 1.0_dp, sin_block(sgfa, sgfb),
SIZE(sin_block, 1))
1218 END SUBROUTINE contract_all
subroutine pbc(r, r_pbc, s, s_pbc, a, b, c, alpha, beta, gamma, debug, info, pbc0, h, hinv)
...
static void dgemm(const char transa, const char transb, const int m, const int n, const int k, const double alpha, const double *a, const int lda, const double *b, const int ldb, const double beta, double *c, const int ldc)
Convenient wrapper to hide Fortran nature of dgemm_, swapping a and b.
Calculation of the moment integrals over Cartesian Gaussian-type functions.
subroutine, public cossin(la_max_set, npgfa, zeta, rpgfa, la_min_set, lb_max, npgfb, zetb, rpgfb, lb_min, rac, rbc, kvec, cosab, sinab, dcosab, dsinab)
...
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.
collect pointers to a block of reals
Handles all functions related to the CELL.
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_solve(matrix_a, general_a, determinant)
Solve the system of linear equations A*b=A_general using LU decomposition. Pay attention that both ma...
subroutine, public cp_cfm_scale_and_add_fm(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*b). where b is a real matrix (adapted from cp_cf...
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_create(matrix, matrix_struct, name)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_set_all(matrix, alpha, beta)
Set all elements of the full matrix to alpha. Besides, set all diagonal matrix elements to beta (if g...
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public cp_dbcsr_plus_fm_fm_t(sparse_matrix, matrix_v, matrix_g, ncol, alpha, keep_sparsity, symmetry_mode)
performs the multiplication sparse_matrix+dense_mat*dens_mat^T if matrix_g is not explicitly given,...
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_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....
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_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
Defines the basic variable types.
integer, parameter, public dp
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public gaussi
real(kind=dp), parameter, public twopi
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
Calculates the energy contribution and the mo_derivative of a static periodic electric field.
subroutine, public qs_efield_berry_phase(qs_env, just_energy, calculate_forces)
...
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_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, 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, rhs)
Get the QUICKSTEP environment.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, WannierCentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Set 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, 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_r3d_rs_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_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, basis_type, total_zeff_corr)
Get attributes of an atomic kind set.
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kTS, mu, flexible_electron_count)
Get the components of a MO set data structure.
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>
subroutine, public build_berry_moment_matrix(qs_env, cosmat, sinmat, kvec, sab_orb_external, basis_type)
...
Define the neighbor list data types and the corresponding functionality.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
type for berry phase efield matrices. At the moment only used for cosmat and sinmat
subroutine, public set_efield_matrices(efield, sinmat, cosmat, dipmat)
...
subroutine, public init_efield_matrices(efield)
...
pure subroutine, public virial_pair_force(pv_virial, f0, force, rab)
Computes the contribution to the stress tensor from two-body pair-wise forces.