68#include "./base/base_uses.f90"
76 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
's_square_methods'
101 REAL(kind=
dp),
INTENT(OUT) :: s_square, s_square_ideal
103 CHARACTER(len=*),
PARAMETER :: routinen =
'compute_s_square'
105 INTEGER :: handle, nalpha, nao, nao_beta, nbeta
106 REAL(kind=
dp) :: nela, nelb, s2
107 REAL(kind=
dp),
CONTIGUOUS,
DIMENSION(:),
POINTER :: occa, occb
112 CALL timeset(routinen, handle)
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)
120 s_square_ideal = real((nela - nelb)*(nela - nelb + 2), kind=
dp)/4.0_dp
124 CALL cp_fm_create(asb, fm_struct, nrow=nalpha, ncol=nbeta)
125 CALL cp_fm_create(asb2, fm_struct, nrow=nalpha, ncol=nbeta)
137 s_square = s_square_ideal + nelb - s2
142 CALL timestop(handle)
159 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mosin
161 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
162 REAL(kind=
dp),
INTENT(OUT) :: s_square, s_square_ideal
164 CHARACTER(len=*),
PARAMETER :: routinen =
'compute_s_square_kp'
166 INTEGER :: handle, ikp, kplocal, kpmax, nalpha, &
168 INTEGER,
DIMENSION(2) :: kp_range
169 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
171 REAL(kind=
dp) :: nela, nelb, s2, wkp
172 REAL(kind=
dp),
CONTIGUOUS,
DIMENSION(:),
POINTER :: occa, occb
177 TYPE(
cp_fm_type) :: asb, asb2, fmglobal, fmlocal, rsmat, scb
178 TYPE(
cp_fm_type),
POINTER :: moc, r_alpha, r_beta
186 CALL timeset(routinen, handle)
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))
192 kplocal = kp_range(2) - kp_range(1) + 1
193 kpmax = maxval(kp_dist(2, :) - kp_dist(1, :) + 1)
197 CALL mpools_get(mpools, ao_ao_fm_pool=ao_ao_fm_pool)
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)
228 IF (ikp > kplocal) cycle
230 kp => kpoints%kp_env(ikp)%kpoint_env
232 CALL get_mo_set(mo_set=mos(1), occupation_numbers=occa)
233 CALL get_mo_set(mo_set=mos(2), occupation_numbers=occb)
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)
240 CALL cp_fm_create(asb, fm_struct, nrow=nalpha, ncol=nbeta)
241 CALL cp_fm_create(asb2, fm_struct, nrow=nalpha, ncol=nbeta)
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)
253 CALL cp_cfm_create(casb2, fm_struct, nrow=nalpha, ncol=nbeta)
254 CALL cp_fm_create(asb2, fm_struct, nrow=nalpha, ncol=nbeta)
271 CALL kpoints%para_env_inter_kp%sum(s2)
274 IF (ikp <= kplocal)
THEN
275 kp => kpoints%kp_env(ikp)%kpoint_env
277 CALL get_mo_set(mo_set=mos(1), occupation_numbers=occa)
278 CALL get_mo_set(mo_set=mos(2), occupation_numbers=occb)
286 CALL kpoints%para_env_kp%max(nela)
287 CALL kpoints%para_env_kp%max(nelb)
289 s_square_ideal = real((nela - nelb)*(nela - nelb + 2), kind=
dp)/4.0_dp
290 s_square = s_square_ideal + nelb - s2
300 CALL timestop(handle)
316 s2_restraint_control, just_energy)
320 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(INOUT) :: mo_derivs
321 REAL(kind=
dp) :: energy
323 LOGICAL :: just_energy
325 CHARACTER(len=*),
PARAMETER :: routinen =
's2_restraint'
328 REAL(kind=
dp) :: s_square, s_square_ideal
330 CALL timeset(routinen, handle)
332 SELECT CASE (s2_restraint_control%functional_form)
334 IF (just_energy)
THEN
335 CALL compute_s2_energyforce(mos, matrix_s, s_square, s_square_ideal)
337 CALL compute_s2_energyforce(mos, matrix_s, s_square, s_square_ideal, &
338 mo_derivs, s2_restraint_control%strength)
340 energy = s2_restraint_control%strength*(s_square - s2_restraint_control%target)
341 s2_restraint_control%s2_order_p = s_square
343 cpabort(
"do_s2_restraint for <S**2> not yet implemented")
345 cpabort(
"Unknown <S**2> constraint/restraint form")
348 CALL timestop(handle)
367 SUBROUTINE compute_s2_energyforce(mos, matrix_s, s_square, s_square_ideal, mo_derivs, strength)
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
376 CHARACTER(len=*),
PARAMETER :: routinen =
'compute_s2_energyforce'
378 INTEGER :: handle, i, j, nalpha, nao, nao_beta, &
379 nbeta, ncol_local, nmo_alpha, &
381 LOGICAL :: has_uniform_occupation_alpha, &
382 has_uniform_occupation_beta
384 REAL(kind=
dp),
CONTIGUOUS,
DIMENSION(:, :), &
385 POINTER :: local_data
392 CALL timeset(routinen, handle)
395 NULLIFY (fm_struct_tmp)
399 SELECT CASE (
SIZE(mos))
403 s_square_ideal = 0.0_dp
405 cpassert(
PRESENT(mo_derivs) .OR.
PRESENT(strength))
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)
414 IF (has_uniform_occupation_alpha .AND. has_uniform_occupation_beta)
THEN
416 s_square_ideal = real((nalpha - nbeta)*(nalpha - nbeta + 2), kind=
dp)/4.0_dp
420 nrow_global=nalpha, ncol_global=nbeta)
422 CALL cp_fm_create(catscb, fm_struct_tmp, name=
"C(alpha)^T*S*C(beta)")
426 CALL cp_fm_create(scb, fm_struct_tmp, name=
"S*C(beta)", set_zero=.true.)
430 CALL parallel_gemm(
'T',
'N', nalpha, nbeta, nao, 1.0_dp, c_alpha, scb, 0.0_dp, catscb)
432 CALL cp_fm_get_info(catscb, local_data=local_data, nrow_local=nrow_local, ncol_local=ncol_local)
436 s2 = s2 + local_data(i, j)**2
439 CALL para_env%sum(s2)
440 s_square = s_square_ideal + nbeta - s2
442 IF (
PRESENT(mo_derivs))
THEN
443 cpassert(
SIZE(mo_derivs, 1) == 2)
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)
450 CALL parallel_gemm(
'N',
'T', nao, nalpha, nbeta, -strength, scb, catscb, 1.0_dp, mo_derivs(1))
453 CALL cp_fm_create(sca, fm_struct_tmp, name=
"S*C(alpha)", set_zero=.true.)
457 CALL parallel_gemm(
'N',
'N', nao, nbeta, nalpha, -strength, sca, catscb, 1.0_dp, mo_derivs(2))
463 IF (.NOT. has_uniform_occupation_alpha)
THEN
464 cphint(
"The alpha orbitals (MOs) have a non-uniform occupation")
466 IF (.NOT. has_uniform_occupation_beta)
THEN
467 cphint(
"The beta orbitals (MOs) have a non-uniform occupation")
469 cphint(
"Skipping S**2 calculation")
473 cpabort(
"Alpha, beta, what else?")
476 CALL timestop(handle)
478 END SUBROUTINE compute_s2_energyforce
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
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
Defines the basic variable types.
integer, parameter, public dp
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.
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
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