39#include "./base/base_uses.f90"
45 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_mo_types'
52 LOGICAL :: use_mo_coeff_b = .false.
58 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues => null(), &
59 occupation_numbers => null()
62 REAL(kind=
dp) :: maxocc = -1
64 INTEGER :: nelectron = -1
65 REAL(kind=
dp) :: n_el_f = -1.0_dp
73 LOGICAL :: uniform_occupation = .false.
75 REAL(kind=
dp) :: kts = -1.0_dp
77 REAL(kind=
dp) :: mu = 0.0_dp
79 REAL(kind=
dp) :: flexible_electron_count = -1.0_dp
110 TYPE(
mo_set_type),
INTENT(INOUT) :: mo_set_new, mo_set_old
114 mo_set_new%maxocc = mo_set_old%maxocc
115 mo_set_new%nelectron = mo_set_old%nelectron
116 mo_set_new%n_el_f = mo_set_old%n_el_f
117 mo_set_new%nao = mo_set_old%nao
118 mo_set_new%nmo = mo_set_old%nmo
119 mo_set_new%homo = mo_set_old%homo
120 mo_set_new%lfomo = mo_set_old%lfomo
121 mo_set_new%uniform_occupation = mo_set_old%uniform_occupation
122 mo_set_new%kTS = mo_set_old%kTS
123 mo_set_new%mu = mo_set_old%mu
124 mo_set_new%flexible_electron_count = mo_set_old%flexible_electron_count
128 CALL cp_fm_to_fm(mo_set_old%mo_coeff, mo_set_new%mo_coeff)
135 mo_set_new%eigenvalues = mo_set_old%eigenvalues
137 mo_set_new%occupation_numbers = mo_set_old%occupation_numbers
155 mo_set_new%maxocc = mo_set_old%maxocc
156 mo_set_new%nelectron = mo_set_old%nelectron
157 mo_set_new%n_el_f = mo_set_old%n_el_f
158 mo_set_new%nao = mo_set_old%nao
159 mo_set_new%nmo = mo_set_old%nmo
160 mo_set_new%homo = mo_set_old%homo
161 mo_set_new%lfomo = mo_set_old%lfomo
162 mo_set_new%uniform_occupation = mo_set_old%uniform_occupation
163 mo_set_new%kTS = mo_set_old%kTS
164 mo_set_new%mu = mo_set_old%mu
165 mo_set_new%flexible_electron_count = mo_set_old%flexible_electron_count
169 NULLIFY (mo_set_new%mo_coeff)
170 ALLOCATE (mo_set_new%mo_coeff)
171 CALL cp_fm_create(mo_set_new%mo_coeff, mo_set_old%mo_coeff%matrix_struct)
172 CALL cp_fm_to_fm(mo_set_old%mo_coeff, mo_set_new%mo_coeff)
174 NULLIFY (mo_set_new%mo_coeff_b)
175 IF (
ASSOCIATED(mo_set_old%mo_coeff_b))
THEN
177 CALL dbcsr_copy(mo_set_new%mo_coeff_b, mo_set_old%mo_coeff_b)
179 mo_set_new%use_mo_coeff_b = mo_set_old%use_mo_coeff_b
181 ALLOCATE (mo_set_new%eigenvalues(nmo))
182 mo_set_new%eigenvalues = mo_set_old%eigenvalues
184 ALLOCATE (mo_set_new%occupation_numbers(nmo))
185 mo_set_new%occupation_numbers = mo_set_old%occupation_numbers
206 flexible_electron_count)
209 INTEGER,
INTENT(IN) :: nao, nmo, nelectron
210 REAL(kind=
dp),
INTENT(IN) :: n_el_f, maxocc, flexible_electron_count
212 mo_set%maxocc = maxocc
213 mo_set%nelectron = nelectron
214 mo_set%n_el_f = n_el_f
219 mo_set%uniform_occupation = .true.
222 mo_set%flexible_electron_count = flexible_electron_count
224 NULLIFY (mo_set%eigenvalues)
225 NULLIFY (mo_set%occupation_numbers)
226 NULLIFY (mo_set%mo_coeff)
227 NULLIFY (mo_set%mo_coeff_b)
228 mo_set%use_mo_coeff_b = .false.
249 TYPE(
cp_fm_type),
INTENT(IN),
OPTIONAL :: fm_ref
251 CHARACTER(LEN=*),
INTENT(in) :: name
253 INTEGER :: nao, nmo, nomo
255 cpassert(.NOT.
ASSOCIATED(mo_set%eigenvalues))
256 cpassert(.NOT.
ASSOCIATED(mo_set%occupation_numbers))
257 cpassert(.NOT.
ASSOCIATED(mo_set%mo_coeff))
259 cpassert(
PRESENT(fm_pool) .NEQV. (
PRESENT(fm_ref) .NEQV.
PRESENT(fm_struct)))
260 NULLIFY (mo_set%mo_coeff)
261 IF (
PRESENT(fm_pool))
THEN
262 ALLOCATE (mo_set%mo_coeff)
264 ELSE IF (
PRESENT(fm_ref))
THEN
265 ALLOCATE (mo_set%mo_coeff)
266 CALL cp_fm_create(mo_set%mo_coeff, fm_ref%matrix_struct, name=name)
267 ELSE IF (
PRESENT(fm_struct))
THEN
268 ALLOCATE (mo_set%mo_coeff)
269 cpassert(
ASSOCIATED(fm_struct))
270 CALL cp_fm_create(mo_set%mo_coeff, fm_struct, name=name)
273 CALL cp_fm_get_info(mo_set%mo_coeff, nrow_global=nao, ncol_global=nmo)
275 cpassert(nao >= mo_set%nao)
276 cpassert(nmo >= mo_set%nmo)
278 ALLOCATE (mo_set%eigenvalues(nmo))
279 mo_set%eigenvalues(:) = 0.0_dp
281 ALLOCATE (mo_set%occupation_numbers(nmo))
283 mo_set%occupation_numbers(:) = 0.0_dp
285 IF (mo_set%nelectron == 0)
THEN
289 IF (
modulo(mo_set%nelectron, int(mo_set%maxocc)) == 0)
THEN
290 nomo = nint(mo_set%nelectron/mo_set%maxocc)
291 mo_set%occupation_numbers(1:nomo) = mo_set%maxocc
293 nomo = int(mo_set%nelectron/mo_set%maxocc) + 1
295 mo_set%occupation_numbers(1:nomo - 1) = mo_set%maxocc
296 mo_set%occupation_numbers(nomo) = mo_set%nelectron - (nomo - 1)*mo_set%maxocc
299 cpassert(nmo >= nomo)
300 cpassert((
SIZE(mo_set%occupation_numbers) == nmo))
303 mo_set%lfomo = nomo + 1
304 mo_set%mu = mo_set%eigenvalues(nomo)
317 TYPE(
mo_set_type),
DIMENSION(2),
INTENT(IN) :: mo_array
318 LOGICAL,
INTENT(in),
OPTIONAL :: convert_dbcsr
320 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mo_set_restrict'
323 LOGICAL :: my_convert_dbcsr
325 CALL timeset(routinen, handle)
327 my_convert_dbcsr = .false.
328 IF (
PRESENT(convert_dbcsr)) my_convert_dbcsr = convert_dbcsr
330 cpassert(mo_array(1)%nmo >= mo_array(2)%nmo)
333 IF (my_convert_dbcsr)
THEN
335 mo_array(2)%nmo, 1, 1, &
336 para_env=mo_array(1)%mo_coeff%matrix_struct%para_env, &
337 blacs_env=mo_array(1)%mo_coeff%matrix_struct%context)
339 CALL cp_fm_to_fm(mo_array(1)%mo_coeff, mo_array(2)%mo_coeff, mo_array(2)%nmo)
342 CALL timestop(handle)
357 IF (
ASSOCIATED(mo_set%eigenvalues))
THEN
358 DEALLOCATE (mo_set%eigenvalues)
359 NULLIFY (mo_set%eigenvalues)
361 IF (
ASSOCIATED(mo_set%occupation_numbers))
THEN
362 DEALLOCATE (mo_set%occupation_numbers)
363 NULLIFY (mo_set%occupation_numbers)
365 IF (
ASSOCIATED(mo_set%mo_coeff))
THEN
367 DEALLOCATE (mo_set%mo_coeff)
368 NULLIFY (mo_set%mo_coeff)
370 IF (
ASSOCIATED(mo_set%mo_coeff_b))
CALL dbcsr_release_p(mo_set%mo_coeff_b)
396 SUBROUTINE get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, &
397 eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, &
398 uniform_occupation, kTS, mu, flexible_electron_count)
401 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: maxocc
402 INTEGER,
INTENT(OUT),
OPTIONAL :: homo, lfomo, nao, nelectron
403 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: n_el_f
404 INTEGER,
INTENT(OUT),
OPTIONAL :: nmo
405 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: eigenvalues, occupation_numbers
406 TYPE(
cp_fm_type),
OPTIONAL,
POINTER :: mo_coeff
407 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: mo_coeff_b
408 LOGICAL,
INTENT(OUT),
OPTIONAL :: uniform_occupation
409 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: kts, mu, flexible_electron_count
411 IF (
PRESENT(maxocc)) maxocc = mo_set%maxocc
412 IF (
PRESENT(homo)) homo = mo_set%homo
413 IF (
PRESENT(lfomo)) lfomo = mo_set%lfomo
414 IF (
PRESENT(nao)) nao = mo_set%nao
415 IF (
PRESENT(nelectron)) nelectron = mo_set%nelectron
416 IF (
PRESENT(n_el_f)) n_el_f = mo_set%n_el_f
417 IF (
PRESENT(nmo)) nmo = mo_set%nmo
418 IF (
PRESENT(eigenvalues)) eigenvalues => mo_set%eigenvalues
419 IF (
PRESENT(occupation_numbers))
THEN
420 occupation_numbers => mo_set%occupation_numbers
422 IF (
PRESENT(mo_coeff)) mo_coeff => mo_set%mo_coeff
423 IF (
PRESENT(mo_coeff_b)) mo_coeff_b => mo_set%mo_coeff_b
424 IF (
PRESENT(uniform_occupation)) uniform_occupation = mo_set%uniform_occupation
425 IF (
PRESENT(kts)) kts = mo_set%kTS
426 IF (
PRESENT(mu)) mu = mo_set%mu
427 IF (
PRESENT(flexible_electron_count)) flexible_electron_count = mo_set%flexible_electron_count
451 SUBROUTINE set_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, &
452 eigenvalues, occupation_numbers, uniform_occupation, &
453 kTS, mu, flexible_electron_count)
456 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: maxocc
457 INTEGER,
INTENT(IN),
OPTIONAL :: homo, lfomo, nao, nelectron
458 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: n_el_f
459 INTEGER,
INTENT(IN),
OPTIONAL :: nmo
460 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: eigenvalues, occupation_numbers
461 LOGICAL,
INTENT(IN),
OPTIONAL :: uniform_occupation
462 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: kts, mu, flexible_electron_count
464 IF (
PRESENT(maxocc)) mo_set%maxocc = maxocc
465 IF (
PRESENT(homo)) mo_set%homo = homo
466 IF (
PRESENT(lfomo)) mo_set%lfomo = lfomo
467 IF (
PRESENT(nao)) mo_set%nao = nao
468 IF (
PRESENT(nelectron)) mo_set%nelectron = nelectron
469 IF (
PRESENT(n_el_f)) mo_set%n_el_f = n_el_f
470 IF (
PRESENT(nmo)) mo_set%nmo = nmo
471 IF (
PRESENT(eigenvalues))
THEN
472 IF (
ASSOCIATED(mo_set%eigenvalues))
THEN
473 DEALLOCATE (mo_set%eigenvalues)
475 mo_set%eigenvalues => eigenvalues
477 IF (
PRESENT(occupation_numbers))
THEN
478 IF (
ASSOCIATED(mo_set%occupation_numbers))
THEN
479 DEALLOCATE (mo_set%occupation_numbers)
481 mo_set%occupation_numbers => occupation_numbers
483 IF (
PRESENT(uniform_occupation)) mo_set%uniform_occupation = uniform_occupation
484 IF (
PRESENT(kts)) mo_set%kTS = kts
485 IF (
PRESENT(mu)) mo_set%mu = mu
486 IF (
PRESENT(flexible_electron_count)) mo_set%flexible_electron_count = flexible_electron_count
507 INTEGER,
INTENT(IN),
OPTIONAL :: first_mo, last_mo
508 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: occupation, tolerance
511 INTEGER :: my_first_mo, my_last_mo
512 REAL(kind=
dp) :: my_occupation, my_tolerance
516 IF (
PRESENT(first_mo))
THEN
517 cpassert(first_mo >= lbound(mo_set%eigenvalues, 1))
518 my_first_mo = first_mo
520 my_first_mo = lbound(mo_set%eigenvalues, 1)
523 IF (
PRESENT(last_mo))
THEN
524 cpassert(last_mo <= ubound(mo_set%eigenvalues, 1))
527 my_last_mo = ubound(mo_set%eigenvalues, 1)
530 IF (
PRESENT(occupation))
THEN
531 my_occupation = occupation
533 my_occupation = mo_set%maxocc
536 IF (
PRESENT(tolerance))
THEN
537 my_tolerance = tolerance
539 my_tolerance = epsilon(0.0_dp)
542 has_uniform_occupation = all(abs(mo_set%occupation_numbers(my_first_mo:my_last_mo) - my_occupation) < my_tolerance)
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
subroutine, public dbcsr_release_p(matrix)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_init_p(matrix)
...
DBCSR operations in CP2K.
subroutine, public dbcsr_copy_columns_hack(matrix_b, matrix_a, ncol, source_start, target_start, para_env, blacs_env)
hack for dbcsr_copy_columns
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
represent the structure of a full matrix
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
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp, nrow, ncol, set_zero)
creates a new full matrix with the given structure
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
Defines the basic variable types.
integer, parameter, public dp
Definition and initialisation of the mo data type.
subroutine, public duplicate_mo_set(mo_set_new, mo_set_old)
allocate a new mo_set, and copy the old data
subroutine, public set_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, uniform_occupation, kts, mu, flexible_electron_count)
Set the components of a MO set data structure.
subroutine, public allocate_mo_set(mo_set, nao, nmo, nelectron, n_el_f, maxocc, flexible_electron_count)
Allocates a mo set and partially initializes it (nao,nmo,nelectron, and flexible_electron_count are v...
subroutine, public mo_set_restrict(mo_array, convert_dbcsr)
make the beta orbitals explicitly equal to the alpha orbitals effectively copying the orbital data
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction 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...
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.
subroutine, public reassign_allocated_mos(mo_set_new, mo_set_old)
reassign an already allocated mo_set
subroutine, public init_mo_set(mo_set, fm_pool, fm_ref, fm_struct, name)
initializes an allocated mo_set. eigenvalues, mo_coeff, occupation_numbers are valid only after this ...
represent a pool of elements with the same structure
keeps the information about the structure of a full matrix