(git:27c966b)
Loading...
Searching...
No Matches
s_square_methods.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Methods related to (\cal S)^2 (i.e. spin)
10!> \par History
11!> 03.2006 copied compute_s_square from qs_scf_post (Joost VandeVondele)
12!> 08.2021 revised (Matthias Krack, MK)
13!> \author Joost VandeVondele
14! **************************************************************************************************
16
19 USE cp_cfm_types, ONLY: cp_cfm_create,&
25 USE cp_dbcsr_api, ONLY: dbcsr_p_type
36 USE cp_fm_types, ONLY: cp_fm_create,&
43 USE kinds, ONLY: dp
44 USE kpoint_types, ONLY: get_kpoint_env,&
48 USE mathconstants, ONLY: one,&
49 z_one,&
50 z_zero,&
51 zero
62 USE qs_matrix_pools, ONLY: mpools_get,&
64 USE qs_mo_types, ONLY: get_mo_set,&
68#include "./base/base_uses.f90"
69
70 IMPLICIT NONE
71
72 PRIVATE
73
74 ! Global parameters
75
76 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 's_square_methods'
77
79 PUBLIC :: s2_restraint
80
81CONTAINS
82
83! **************************************************************************************************
84!> \brief Compute the expectation value <(\cal S)^2> of the single determinant defined by the
85!> spin up (alpha) and spin down (beta) orbitals
86!> \param mos [in] MO set with all MO information including the alpha and beta MO coefficients
87!> \param matrix_s [in] AO overlap matrix S (do not mix with the spin operator (\cal S))
88!> \param s_square [out] <(\cal S)^2> including potential spin contaminations
89!> \param s_square_ideal [out] Ideal value for <(\cal S)^2> without any spin contaminations
90!> \par History
91!> 07.2004 created (Joost VandeVondele)
92!> 08.2021 revised (Matthias Krack, MK)
93!> 10.2026 adapted and generalized to partial occupation and k-points
94!> \note
95!> See Eqs. 2.271 and 2.272 in Modern Quantum Chemistry by A. Szabo and N. S. Ostlund
96! **************************************************************************************************
97 SUBROUTINE compute_s_square(mos, matrix_s, s_square, s_square_ideal)
98
99 TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mos
100 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
101 REAL(kind=dp), INTENT(OUT) :: s_square, s_square_ideal
102
103 CHARACTER(len=*), PARAMETER :: routinen = 'compute_s_square'
104
105 INTEGER :: handle, nalpha, nao, nao_beta, nbeta
106 REAL(kind=dp) :: nela, nelb, s2
107 REAL(kind=dp), CONTIGUOUS, DIMENSION(:), POINTER :: occa, occb
108 TYPE(cp_fm_struct_type), POINTER :: fm_struct
109 TYPE(cp_fm_type) :: asb, asb2, scb
110 TYPE(cp_fm_type), POINTER :: c_alpha, c_beta
111
112 CALL timeset(routinen, handle)
113
114 CALL get_mo_set(mo_set=mos(1), mo_coeff=c_alpha, nmo=nalpha, nao=nao)
115 CALL get_mo_set(mo_set=mos(2), mo_coeff=c_beta, nmo=nbeta, nao=nao_beta)
116 cpassert(nao == nao_beta)
117 CALL get_mo_set(mo_set=mos(1), n_el_f=nela, occupation_numbers=occa)
118 CALL get_mo_set(mo_set=mos(2), n_el_f=nelb, occupation_numbers=occb)
119 ! Eq. 2.272 in Modern Quantum Chemistry by A. Szabo and N. S. Ostlund
120 s_square_ideal = real((nela - nelb)*(nela - nelb + 2), kind=dp)/4.0_dp
121 ! Create MO overlap matrix
122 CALL cp_fm_get_info(c_beta, matrix_struct=fm_struct)
123 ! Prepare C(alpha)^T*S*C(beta)
124 CALL cp_fm_create(asb, fm_struct, nrow=nalpha, ncol=nbeta)
125 CALL cp_fm_create(asb2, fm_struct, nrow=nalpha, ncol=nbeta)
126 CALL cp_fm_create(scb, fm_struct)
127 ! Compute S*C(beta)
128 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, c_beta, scb, nbeta)
129 ! Compute C(alpha)^T*S*C(beta)
130 CALL parallel_gemm('T', 'N', nalpha, nbeta, nao, one, c_alpha, scb, zero, asb)
131 ! square the matrix elements
132 CALL cp_fm_schur_product(asb, asb, asb2)
133 ! occupation number weighting
134 CALL cp_fm_row_scale(asb2, occa)
135 CALL cp_fm_column_scale(asb2, occb)
136 s2 = cp_fm_sumall(asb2)
137 s_square = s_square_ideal + nelb - s2
138 CALL cp_fm_release(scb)
139 CALL cp_fm_release(asb)
140 CALL cp_fm_release(asb2)
141
142 CALL timestop(handle)
143
144 END SUBROUTINE compute_s_square
145
146! **************************************************************************************************
147!> \brief Compute the expectation value <(\cal S)^2> of the single determinant defined by the
148!> spin up (alpha) and spin down (beta) orbitals
149!> \param mosin ...
150!> \param kpoints ...
151!> \param matrix_s ...
152!> \param s_square [out] <(\cal S)^2> including potential spin contaminations
153!> \param s_square_ideal [out] Ideal value for <(\cal S)^2> without any spin contaminations
154!> \par History
155!> 10.2026 adapted and generalized to partial occupation and k-points
156! **************************************************************************************************
157 SUBROUTINE compute_s_square_kp(mosin, kpoints, matrix_s, s_square, s_square_ideal)
158
159 TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mosin
160 TYPE(kpoint_type), INTENT(IN), POINTER :: kpoints
161 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s
162 REAL(kind=dp), INTENT(OUT) :: s_square, s_square_ideal
163
164 CHARACTER(len=*), PARAMETER :: routinen = 'compute_s_square_kp'
165
166 INTEGER :: handle, ikp, kplocal, kpmax, nalpha, &
167 nao, nbeta
168 INTEGER, DIMENSION(2) :: kp_range
169 INTEGER, DIMENSION(:, :), POINTER :: kp_dist
170 LOGICAL :: wfn_real
171 REAL(kind=dp) :: nela, nelb, s2, wkp
172 REAL(kind=dp), CONTIGUOUS, DIMENSION(:), POINTER :: occa, occb
173 TYPE(cp_cfm_type) :: casb, casb2, cscb, csmat
174 TYPE(cp_cfm_type), POINTER :: c_alpha, c_beta
175 TYPE(cp_fm_pool_type), POINTER :: ao_ao_fm_pool
176 TYPE(cp_fm_struct_type), POINTER :: fm_struct, matrix_struct
177 TYPE(cp_fm_type) :: asb, asb2, fmglobal, fmlocal, rsmat, scb
178 TYPE(cp_fm_type), POINTER :: moc, r_alpha, r_beta
179 TYPE(kpoint_env_type), POINTER :: kp
180 TYPE(kpoint_operator_context_type) :: op_ctx
181 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
182 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
183 POINTER :: sab_nl
184 TYPE(qs_matrix_pools_type), POINTER :: mpools
185
186 CALL timeset(routinen, handle)
187
188 CALL get_kpoint_info(kpoints, use_real_wfn=wfn_real, kp_range=kp_range, &
189 kp_dist=kp_dist, sab_nl=sab_nl)
190 cpassert(ASSOCIATED(sab_nl))
191
192 kplocal = kp_range(2) - kp_range(1) + 1
193 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
194
195 ! fm pools to be used within a kpoint group
196 CALL get_kpoint_info(kpoints, mpools=mpools)
197 CALL mpools_get(mpools, ao_ao_fm_pool=ao_ao_fm_pool)
198 CALL fm_pool_create_fm(ao_ao_fm_pool, fmlocal)
199 CALL cp_fm_get_info(fmlocal, matrix_struct=matrix_struct)
200 IF (wfn_real) THEN
201 CALL cp_fm_create(rsmat, matrix_struct)
202 ELSE
203 CALL cp_cfm_create(csmat, matrix_struct)
204 END IF
205 CALL fm_pool_give_back_fm(ao_ao_fm_pool, fmlocal)
206
207 ! fm matrix_structure for the global environment
208 CALL get_mo_set(mo_set=mosin(1), mo_coeff=moc, nao=nao)
209 CALL cp_fm_create(fmglobal, moc%matrix_struct, nrow=nao, ncol=nao)
210 ! The overlap is spin free: the routine drives every instance under the
211 ! single spin-free key.
212 CALL kpoint_operator_context_create(op_ctx, kpoints, fmglobal, 1)
213 CALL kpoint_operator_prepare(op_ctx, matrix_s, kpoint_slot_s, matrix_row=kpoint_spin_free)
214 DO ikp = 1, kpmax
215 CALL kpoint_operator_start(op_ctx, ikp, kpoint_spin_free, matrix_s, kpoint_slot_s, &
216 use_grid=.false., matrix_row=kpoint_spin_free)
217 END DO
218 CALL cp_fm_release(fmglobal)
219
220 s2 = 0.0_dp
221 DO ikp = 1, kpmax
222 IF (wfn_real) THEN
223 CALL kpoint_operator_finish(op_ctx, ikp, kpoint_spin_free, kpoint_slot_s, fm_re=rsmat)
224 ELSE
225 CALL kpoint_operator_finish(op_ctx, ikp, kpoint_spin_free, kpoint_slot_s, cmat=csmat)
226 END IF
227
228 IF (ikp > kplocal) cycle
229
230 kp => kpoints%kp_env(ikp)%kpoint_env
231 CALL get_kpoint_env(kp, wkp=wkp, mos=mos)
232 CALL get_mo_set(mo_set=mos(1), occupation_numbers=occa)
233 CALL get_mo_set(mo_set=mos(2), occupation_numbers=occb)
234
235 IF (wfn_real) THEN
236 CALL get_mo_set(mo_set=mos(1), mo_coeff=r_alpha, nmo=nalpha)
237 CALL get_mo_set(mo_set=mos(2), mo_coeff=r_beta, nmo=nbeta)
238 CALL cp_fm_get_info(r_beta, matrix_struct=fm_struct)
239 CALL cp_fm_create(scb, fm_struct)
240 CALL cp_fm_create(asb, fm_struct, nrow=nalpha, ncol=nbeta)
241 CALL cp_fm_create(asb2, fm_struct, nrow=nalpha, ncol=nbeta)
242 CALL parallel_gemm('N', 'N', nao, nbeta, nao, one, rsmat, r_beta, zero, scb)
243 CALL parallel_gemm('T', 'N', nalpha, nbeta, nao, one, r_alpha, scb, zero, asb)
244 CALL cp_fm_schur_product(asb, asb, asb2)
245 CALL cp_fm_release(scb)
246 CALL cp_fm_release(asb)
247 ELSE
248 CALL get_mo_set(mo_set=mos(1), cmo_coeff=c_alpha, nmo=nalpha)
249 CALL get_mo_set(mo_set=mos(2), cmo_coeff=c_beta, nmo=nbeta)
250 CALL cp_cfm_get_info(c_beta, matrix_struct=fm_struct)
251 CALL cp_cfm_create(cscb, fm_struct)
252 CALL cp_cfm_create(casb, fm_struct, nrow=nalpha, ncol=nbeta)
253 CALL cp_cfm_create(casb2, fm_struct, nrow=nalpha, ncol=nbeta)
254 CALL cp_fm_create(asb2, fm_struct, nrow=nalpha, ncol=nbeta)
255 CALL parallel_gemm('N', 'N', nao, nbeta, nao, z_one, csmat, c_beta, z_zero, cscb)
256 CALL parallel_gemm('C', 'N', nalpha, nbeta, nao, z_one, c_alpha, cscb, z_zero, casb)
257 CALL cp_cfm_schur_product_cc(casb, casb, casb2)
258 CALL cp_cfm_to_fm(casb2, asb2)
259 CALL cp_cfm_release(cscb)
260 CALL cp_cfm_release(casb)
261 CALL cp_cfm_release(casb2)
262 END IF
263 CALL cp_fm_row_scale(asb2, occa)
264 CALL cp_fm_column_scale(asb2, occb)
265 s2 = s2 + wkp*cp_fm_sumall(asb2)
266 CALL cp_fm_release(asb2)
267
268 END DO
269
270 !sum s2 over kp group
271 CALL kpoints%para_env_inter_kp%sum(s2)
272
273 ikp = 1
274 IF (ikp <= kplocal) THEN
275 kp => kpoints%kp_env(ikp)%kpoint_env
276 CALL get_kpoint_env(kp, mos=mos)
277 CALL get_mo_set(mo_set=mos(1), occupation_numbers=occa)
278 CALL get_mo_set(mo_set=mos(2), occupation_numbers=occb)
279 nela = sum(occa)
280 nelb = sum(occb)
281 ELSE
282 nela = 0
283 nelb = 0
284 END IF
285 !
286 CALL kpoints%para_env_kp%max(nela)
287 CALL kpoints%para_env_kp%max(nelb)
288 !
289 s_square_ideal = real((nela - nelb)*(nela - nelb + 2), kind=dp)/4.0_dp
290 s_square = s_square_ideal + nelb - s2
291
293
294 IF (wfn_real) THEN
295 CALL cp_fm_release(rsmat)
296 ELSE
297 CALL cp_cfm_release(csmat)
298 END IF
299
300 CALL timestop(handle)
301
302 END SUBROUTINE compute_s_square_kp
303
304! **************************************************************************************************
305!> \brief restrains/constrains the value of s2 in a calculation
306!> \param mos input
307!> \param matrix_s input
308!> \param mo_derivs inout if present, add the derivative of s_square wrt mos to mo_derivs
309!> \param energy ...
310!> \param s2_restraint_control ...
311!> \param just_energy ...
312!> \par History
313!> 07.2004 created [ Joost VandeVondele ]
314! **************************************************************************************************
315 SUBROUTINE s2_restraint(mos, matrix_s, mo_derivs, energy, &
316 s2_restraint_control, just_energy)
317
318 TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mos
319 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
320 TYPE(cp_fm_type), DIMENSION(:), INTENT(INOUT) :: mo_derivs
321 REAL(kind=dp) :: energy
322 TYPE(s2_restraint_type), POINTER :: s2_restraint_control
323 LOGICAL :: just_energy
324
325 CHARACTER(len=*), PARAMETER :: routinen = 's2_restraint'
326
327 INTEGER :: handle
328 REAL(kind=dp) :: s_square, s_square_ideal
329
330 CALL timeset(routinen, handle)
331
332 SELECT CASE (s2_restraint_control%functional_form)
333 CASE (do_s2_constraint)
334 IF (just_energy) THEN
335 CALL compute_s2_energyforce(mos, matrix_s, s_square, s_square_ideal)
336 ELSE
337 CALL compute_s2_energyforce(mos, matrix_s, s_square, s_square_ideal, &
338 mo_derivs, s2_restraint_control%strength)
339 END IF
340 energy = s2_restraint_control%strength*(s_square - s2_restraint_control%target)
341 s2_restraint_control%s2_order_p = s_square
342 CASE (do_s2_restraint) ! not yet implemented
343 cpabort("do_s2_restraint for <S**2> not yet implemented")
344 CASE DEFAULT
345 cpabort("Unknown <S**2> constraint/restraint form")
346 END SELECT
347
348 CALL timestop(handle)
349
350 END SUBROUTINE s2_restraint
351
352! **************************************************************************************************
353!> \brief Compute the expectation value <(\cal S)^2> of the single determinant defined by the
354!> spin up (alpha) and spin down (beta) orbitals
355!> \param mos [in] MO set with all MO information including the alpha and beta MO coefficients
356!> \param matrix_s [in] AO overlap matrix S (do not mix with the spin operator (\cal S))
357!> \param s_square [out] <(\cal S)^2> including potential spin contaminations
358!> \param s_square_ideal [out] Ideal value for <(\cal S)^2> without any spin contaminations
359!> \param mo_derivs [inout] If present, add the derivative of s_square wrt the MOs to mo_derivs
360!> \param strength [in] Strength for constraining or restraining (\cal S)^2
361!> \par History
362!> 07.2004 created (Joost VandeVondele)
363!> 08.2021 revised (Matthias Krack, MK)
364!> \note
365!> See Eqs. 2.271 and 2.272 in Modern Quantum Chemistry by A. Szabo and N. S. Ostlund
366! **************************************************************************************************
367 SUBROUTINE compute_s2_energyforce(mos, matrix_s, s_square, s_square_ideal, mo_derivs, strength)
368
369 TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mos
370 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
371 REAL(kind=dp), INTENT(OUT) :: s_square, s_square_ideal
372 TYPE(cp_fm_type), DIMENSION(:), INTENT(INOUT), &
373 OPTIONAL :: mo_derivs
374 REAL(kind=dp), INTENT(IN), OPTIONAL :: strength
375
376 CHARACTER(len=*), PARAMETER :: routinen = 'compute_s2_energyforce'
377
378 INTEGER :: handle, i, j, nalpha, nao, nao_beta, &
379 nbeta, ncol_local, nmo_alpha, &
380 nmo_beta, nrow_local
381 LOGICAL :: has_uniform_occupation_alpha, &
382 has_uniform_occupation_beta
383 REAL(kind=dp) :: s2
384 REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :), &
385 POINTER :: local_data
386 TYPE(cp_blacs_env_type), POINTER :: context
387 TYPE(cp_fm_struct_type), POINTER :: fm_struct_tmp
388 TYPE(cp_fm_type) :: catscb, sca, scb
389 TYPE(cp_fm_type), POINTER :: c_alpha, c_beta
390 TYPE(mp_para_env_type), POINTER :: para_env
391
392 CALL timeset(routinen, handle)
393
394 NULLIFY (context)
395 NULLIFY (fm_struct_tmp)
396 NULLIFY (local_data)
397 NULLIFY (para_env)
398
399 SELECT CASE (SIZE(mos))
400 CASE (1)
401 ! Spin restricted case, i.e. nothing to do
402 s_square = 0.0_dp
403 s_square_ideal = 0.0_dp
404 ! Restraining or constraining (\cal S) does not make sense
405 cpassert(PRESENT(mo_derivs) .OR. PRESENT(strength))
406 CASE (2)
407 CALL get_mo_set(mo_set=mos(1), mo_coeff=c_alpha, homo=nalpha, nmo=nmo_alpha, nao=nao)
408 CALL get_mo_set(mo_set=mos(2), mo_coeff=c_beta, homo=nbeta, nmo=nmo_beta, nao=nao_beta)
409 cpassert(nao == nao_beta)
410 has_uniform_occupation_alpha = has_uniform_occupation(mo_set=mos(1), last_mo=nalpha)
411 has_uniform_occupation_beta = has_uniform_occupation(mo_set=mos(2), last_mo=nbeta)
412 ! This makes only sense if we have uniform occupations for the alpha and beta spin MOs while
413 ! ignoring potentially added MOs with zero occupation
414 IF (has_uniform_occupation_alpha .AND. has_uniform_occupation_beta) THEN
415 ! Eq. 2.272 in Modern Quantum Chemistry by A. Szabo and N. S. Ostlund
416 s_square_ideal = real((nalpha - nbeta)*(nalpha - nbeta + 2), kind=dp)/4.0_dp
417 ! Create overlap matrix
418 CALL cp_fm_get_info(c_alpha, para_env=para_env, context=context)
419 CALL cp_fm_struct_create(fm_struct_tmp, para_env=para_env, context=context, &
420 nrow_global=nalpha, ncol_global=nbeta)
421 ! Prepare C(alpha)^T*S*C(beta)
422 CALL cp_fm_create(catscb, fm_struct_tmp, name="C(alpha)^T*S*C(beta)")
423 CALL cp_fm_struct_release(fm_struct_tmp)
424 ! Create S*C(beta)
425 CALL cp_fm_get_info(c_beta, matrix_struct=fm_struct_tmp)
426 CALL cp_fm_create(scb, fm_struct_tmp, name="S*C(beta)", set_zero=.true.)
427 ! Compute S*C(beta)
428 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, c_beta, scb, nbeta)
429 ! Compute C(alpha)^T*S*C(beta)
430 CALL parallel_gemm('T', 'N', nalpha, nbeta, nao, 1.0_dp, c_alpha, scb, 0.0_dp, catscb)
431 ! Eq. 2.271 in Modern Quantum Chemistry by A. Szabo and N. S. Ostlund
432 CALL cp_fm_get_info(catscb, local_data=local_data, nrow_local=nrow_local, ncol_local=ncol_local)
433 s2 = 0.0_dp
434 DO j = 1, ncol_local
435 DO i = 1, nrow_local
436 s2 = s2 + local_data(i, j)**2
437 END DO
438 END DO
439 CALL para_env%sum(s2)
440 s_square = s_square_ideal + nbeta - s2
441 ! Only needed for constraining or restraining (\cal S)
442 IF (PRESENT(mo_derivs)) THEN
443 cpassert(SIZE(mo_derivs, 1) == 2)
444 ! This gets really wrong for fractional occupations
445 CALL get_mo_set(mo_set=mos(1), uniform_occupation=has_uniform_occupation_alpha)
446 cpassert(has_uniform_occupation_alpha)
447 CALL get_mo_set(mo_set=mos(2), uniform_occupation=has_uniform_occupation_beta)
448 cpassert(has_uniform_occupation_beta)
449 ! Add -strength*S*C(beta)*(C(alpha)^T*S*C(beta))^T to the alpha MO derivatives
450 CALL parallel_gemm('N', 'T', nao, nalpha, nbeta, -strength, scb, catscb, 1.0_dp, mo_derivs(1))
451 ! Create S*C(alpha)
452 CALL cp_fm_get_info(c_alpha, matrix_struct=fm_struct_tmp)
453 CALL cp_fm_create(sca, fm_struct_tmp, name="S*C(alpha)", set_zero=.true.)
454 ! Compute S*C(alpha)
455 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, c_alpha, sca, nalpha)
456 ! Add -strength*S*C(alpha)*C(alpha)^T*S*C(beta) to the beta MO derivatives
457 CALL parallel_gemm('N', 'N', nao, nbeta, nalpha, -strength, sca, catscb, 1.0_dp, mo_derivs(2))
458 CALL cp_fm_release(sca)
459 END IF
460 CALL cp_fm_release(scb)
461 CALL cp_fm_release(catscb)
462 ELSE
463 IF (.NOT. has_uniform_occupation_alpha) THEN
464 cphint("The alpha orbitals (MOs) have a non-uniform occupation")
465 END IF
466 IF (.NOT. has_uniform_occupation_beta) THEN
467 cphint("The beta orbitals (MOs) have a non-uniform occupation")
468 END IF
469 cphint("Skipping S**2 calculation")
470 END IF
471 CASE DEFAULT
472 ! We should never get here
473 cpabort("Alpha, beta, what else?")
474 END SELECT
475
476 CALL timestop(handle)
477
478 END SUBROUTINE compute_s2_energyforce
479
480END MODULE s_square_methods
methods related to the blacs parallel environment
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_schur_product_cc(matrix_a, matrix_b, matrix_c)
Computes the element-wise (Schur) product of two matrices: C = A \circ conjg(B) .
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, matrix_struct, para_env)
Returns information about a full matrix.
subroutine, public cp_cfm_to_fm(msource, mtargetr, mtargeti)
Copy real and imaginary parts of a complex full matrix into separate real-value full matrices.
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
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_row_scale(matrixa, scaling)
scales row i of matrix a with scaling(i)
subroutine, public cp_fm_schur_product(matrix_a, matrix_b, matrix_c)
computes the schur product of two matrices c_ij = a_ij * b_ij
subroutine, public cp_fm_column_scale(matrixa, scaling, first_col, source)
Scales columns of the full matrix by corresponding factors.
pool for for elements that are retained and released
subroutine, public fm_pool_create_fm(pool, element, name)
returns an element, allocating it if none is in the pool
subroutine, public fm_pool_give_back_fm(pool, element)
returns the element to the pool
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
Definition cp_fm_types.F:15
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
real(kind=dp) function, public cp_fm_sumall(matrix, fun)
summing up all the elements of the matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_s2_restraint
integer, parameter, public do_s2_constraint
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_env(kpoint_env, nkpoint, wkp, xkp, is_local, mos)
Get information from a single kpoint environment.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered, lattice_fft)
Retrieve information from a kpoint environment.
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
real(kind=dp), parameter, public one
real(kind=dp), parameter, public zero
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
Assembly of real and complex k-point operators from real-space DBCSR matrices. Outputs use the distri...
subroutine, public kpoint_operator_context_create(ctx, kpoints, ao_ao_fm, nspin)
Create an empty operator context. The context owns no buffers after this call; they are created on fi...
subroutine, public kpoint_operator_prepare(ctx, rsmat, slot, prepared, matrix_row, target)
Prepare an immutable operator slot for group-local assembly. Refresh after the source values change,...
subroutine, public kpoint_operator_finish(ctx, ikp, ispin, slot, cmat, fm_re)
Finish one started instance: build its prepared group-local operator, or merge received parts into cm...
integer, parameter, public kpoint_spin_free
Row of rsmat that carries the spin-free operator image. S and T carry no spin copies: drivers launch ...
integer, parameter, public kpoint_slot_s
subroutine, public kpoint_operator_start(ctx, ikp, ispin, rsmat, slot, grid, use_grid, matrix_row)
Start one operator for one global round and spin. The service walks all groups with a k point in this...
subroutine, public kpoint_operator_context_release(ctx)
Release the context together with every buffer it created. Call once, at the end of the fixed-layout ...
wrapper for the pools of matrixes
subroutine, public mpools_get(mpools, ao_mo_fm_pools, ao_ao_fm_pool, mo_mo_fm_pools, ao_mosub_fm_pools, mosub_mosub_fm_pools, maxao_maxmo_fm_pool, maxao_maxao_fm_pool, maxmo_maxmo_fm_pool)
returns various attributes of the mpools (notably the pools contained in it)
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
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, cmo_coeff)
Get the components of a MO set data structure.
logical function, public has_uniform_occupation(mo_set, first_mo, last_mo, occupation, tolerance)
Check if the set of MOs in mo_set specifed by the MO index range [first_mo,last_mo] an integer occupa...
Define the neighbor list data types and the corresponding functionality.
Methods related to (\cal S)^2 (i.e. spin).
subroutine, public s2_restraint(mos, matrix_s, mo_derivs, energy, s2_restraint_control, just_energy)
restrains/constrains the value of s2 in a calculation
subroutine, public compute_s_square_kp(mosin, kpoints, matrix_s, s_square, s_square_ideal)
Compute the expectation value <(\cal S)^2> of the single determinant defined by the spin up (alpha) a...
subroutine, public compute_s_square(mos, matrix_s, s_square, s_square_ideal)
Compute the expectation value <(\cal S)^2> of the single determinant defined by the spin up (alpha) a...
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
Represent a complex full matrix.
represent a pool of elements with the same structure
keeps the information about the structure of a full matrix
represent a full matrix
Keeps information about a specific k-point.
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Caller-owned assembly context for a fixed geometry and parallel layout. OT retains it for one inner S...
container for the pools of matrixes used by qs