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.
246 SUBROUTINE init_mo_set(mo_set, fm_pool, fm_ref, fm_struct, name, counter)
250 TYPE(
cp_fm_type),
INTENT(IN),
OPTIONAL :: fm_ref
252 CHARACTER(LEN=*),
INTENT(in) :: name
253 INTEGER,
INTENT(INOUT),
OPTIONAL :: counter
255 INTEGER :: na, nao, nb, nmo, nomo
257 cpassert(.NOT.
ASSOCIATED(mo_set%eigenvalues))
258 cpassert(.NOT.
ASSOCIATED(mo_set%occupation_numbers))
259 cpassert(.NOT.
ASSOCIATED(mo_set%mo_coeff))
261 cpassert(
PRESENT(fm_pool) .NEQV. (
PRESENT(fm_ref) .NEQV.
PRESENT(fm_struct)))
262 NULLIFY (mo_set%mo_coeff)
263 IF (
PRESENT(fm_pool))
THEN
264 ALLOCATE (mo_set%mo_coeff)
266 ELSE IF (
PRESENT(fm_ref))
THEN
267 ALLOCATE (mo_set%mo_coeff)
268 CALL cp_fm_create(mo_set%mo_coeff, fm_ref%matrix_struct, name=name)
269 ELSE IF (
PRESENT(fm_struct))
THEN
270 ALLOCATE (mo_set%mo_coeff)
271 cpassert(
ASSOCIATED(fm_struct))
272 CALL cp_fm_create(mo_set%mo_coeff, fm_struct, name=name)
275 CALL cp_fm_get_info(mo_set%mo_coeff, nrow_global=nao, ncol_global=nmo)
277 cpassert(nao >= mo_set%nao)
278 cpassert(nmo >= mo_set%nmo)
280 ALLOCATE (mo_set%eigenvalues(nmo))
281 mo_set%eigenvalues(:) = 0.0_dp
283 ALLOCATE (mo_set%occupation_numbers(nmo))
285 mo_set%occupation_numbers(:) = 0.0_dp
287 IF (mo_set%nelectron == 0)
THEN
291 IF (
modulo(mo_set%nelectron, int(mo_set%maxocc)) == 0)
THEN
292 nomo = nint(mo_set%nelectron/mo_set%maxocc)
293 mo_set%occupation_numbers(1:nomo) = mo_set%maxocc
295 nomo = int(mo_set%nelectron/mo_set%maxocc) + 1
297 mo_set%occupation_numbers(1:nomo - 1) = mo_set%maxocc
298 mo_set%occupation_numbers(nomo - ((na - nb)/2):nomo) = 1
301 cpassert(nmo >= nomo)
302 cpassert((
SIZE(mo_set%occupation_numbers) == nmo))
305 mo_set%lfomo = nomo + 1
306 mo_set%mu = mo_set%eigenvalues(nomo)
319 TYPE(
mo_set_type),
DIMENSION(2),
INTENT(IN) :: mo_array
320 LOGICAL,
INTENT(in),
OPTIONAL :: convert_dbcsr
322 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mo_set_restrict'
325 LOGICAL :: my_convert_dbcsr
327 CALL timeset(routinen, handle)
329 my_convert_dbcsr = .false.
330 IF (
PRESENT(convert_dbcsr)) my_convert_dbcsr = convert_dbcsr
332 cpassert(mo_array(1)%nmo >= mo_array(2)%nmo)
335 IF (my_convert_dbcsr)
THEN
337 mo_array(2)%nmo, 1, 1, &
338 para_env=mo_array(1)%mo_coeff%matrix_struct%para_env, &
339 blacs_env=mo_array(1)%mo_coeff%matrix_struct%context)
341 CALL cp_fm_to_fm(mo_array(1)%mo_coeff, mo_array(2)%mo_coeff, mo_array(2)%nmo)
344 CALL timestop(handle)
359 IF (
ASSOCIATED(mo_set%eigenvalues))
THEN
360 DEALLOCATE (mo_set%eigenvalues)
361 NULLIFY (mo_set%eigenvalues)
363 IF (
ASSOCIATED(mo_set%occupation_numbers))
THEN
364 DEALLOCATE (mo_set%occupation_numbers)
365 NULLIFY (mo_set%occupation_numbers)
367 IF (
ASSOCIATED(mo_set%mo_coeff))
THEN
369 DEALLOCATE (mo_set%mo_coeff)
370 NULLIFY (mo_set%mo_coeff)
372 IF (
ASSOCIATED(mo_set%mo_coeff_b))
CALL dbcsr_release_p(mo_set%mo_coeff_b)
398 SUBROUTINE get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, &
399 eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, &
400 uniform_occupation, kTS, mu, flexible_electron_count)
403 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: maxocc
404 INTEGER,
INTENT(OUT),
OPTIONAL :: homo, lfomo, nao, nelectron
405 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: n_el_f
406 INTEGER,
INTENT(OUT),
OPTIONAL :: nmo
407 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: eigenvalues, occupation_numbers
408 TYPE(
cp_fm_type),
OPTIONAL,
POINTER :: mo_coeff
409 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: mo_coeff_b
410 LOGICAL,
INTENT(OUT),
OPTIONAL :: uniform_occupation
411 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: kts, mu, flexible_electron_count
413 IF (
PRESENT(maxocc)) maxocc = mo_set%maxocc
414 IF (
PRESENT(homo)) homo = mo_set%homo
415 IF (
PRESENT(lfomo)) lfomo = mo_set%lfomo
416 IF (
PRESENT(nao)) nao = mo_set%nao
417 IF (
PRESENT(nelectron)) nelectron = mo_set%nelectron
418 IF (
PRESENT(n_el_f)) n_el_f = mo_set%n_el_f
419 IF (
PRESENT(nmo)) nmo = mo_set%nmo
420 IF (
PRESENT(eigenvalues)) eigenvalues => mo_set%eigenvalues
421 IF (
PRESENT(occupation_numbers))
THEN
422 occupation_numbers => mo_set%occupation_numbers
424 IF (
PRESENT(mo_coeff)) mo_coeff => mo_set%mo_coeff
425 IF (
PRESENT(mo_coeff_b)) mo_coeff_b => mo_set%mo_coeff_b
426 IF (
PRESENT(uniform_occupation)) uniform_occupation = mo_set%uniform_occupation
427 IF (
PRESENT(kts)) kts = mo_set%kTS
428 IF (
PRESENT(mu)) mu = mo_set%mu
429 IF (
PRESENT(flexible_electron_count)) flexible_electron_count = mo_set%flexible_electron_count
453 SUBROUTINE set_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, &
454 eigenvalues, occupation_numbers, uniform_occupation, &
455 kTS, mu, flexible_electron_count)
458 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: maxocc
459 INTEGER,
INTENT(IN),
OPTIONAL :: homo, lfomo, nao, nelectron
460 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: n_el_f
461 INTEGER,
INTENT(IN),
OPTIONAL :: nmo
462 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: eigenvalues, occupation_numbers
463 LOGICAL,
INTENT(IN),
OPTIONAL :: uniform_occupation
464 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: kts, mu, flexible_electron_count
466 IF (
PRESENT(maxocc)) mo_set%maxocc = maxocc
467 IF (
PRESENT(homo)) mo_set%homo = homo
468 IF (
PRESENT(lfomo)) mo_set%lfomo = lfomo
469 IF (
PRESENT(nao)) mo_set%nao = nao
470 IF (
PRESENT(nelectron)) mo_set%nelectron = nelectron
471 IF (
PRESENT(n_el_f)) mo_set%n_el_f = n_el_f
472 IF (
PRESENT(nmo)) mo_set%nmo = nmo
473 IF (
PRESENT(eigenvalues))
THEN
474 IF (
ASSOCIATED(mo_set%eigenvalues))
THEN
475 DEALLOCATE (mo_set%eigenvalues)
477 mo_set%eigenvalues => eigenvalues
479 IF (
PRESENT(occupation_numbers))
THEN
480 IF (
ASSOCIATED(mo_set%occupation_numbers))
THEN
481 DEALLOCATE (mo_set%occupation_numbers)
483 mo_set%occupation_numbers => occupation_numbers
485 IF (
PRESENT(uniform_occupation)) mo_set%uniform_occupation = uniform_occupation
486 IF (
PRESENT(kts)) mo_set%kTS = kts
487 IF (
PRESENT(mu)) mo_set%mu = mu
488 IF (
PRESENT(flexible_electron_count)) mo_set%flexible_electron_count = flexible_electron_count
509 INTEGER,
INTENT(IN),
OPTIONAL :: first_mo, last_mo
510 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: occupation, tolerance
513 INTEGER :: my_first_mo, my_last_mo
514 REAL(kind=
dp) :: my_occupation, my_tolerance
518 IF (
PRESENT(first_mo))
THEN
519 cpassert(first_mo >= lbound(mo_set%eigenvalues, 1))
520 my_first_mo = first_mo
522 my_first_mo = lbound(mo_set%eigenvalues, 1)
525 IF (
PRESENT(last_mo))
THEN
526 cpassert(last_mo <= ubound(mo_set%eigenvalues, 1))
529 my_last_mo = ubound(mo_set%eigenvalues, 1)
532 IF (
PRESENT(occupation))
THEN
533 my_occupation = occupation
535 my_occupation = mo_set%maxocc
538 IF (
PRESENT(tolerance))
THEN
539 my_tolerance = tolerance
541 my_tolerance = epsilon(0.0_dp)
544 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_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, nrow, ncol, set_zero)
creates a new full matrix with the given structure
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 init_mo_set(mo_set, fm_pool, fm_ref, fm_struct, name, counter)
initializes an allocated mo_set. eigenvalues, mo_coeff, occupation_numbers are valid only after this ...
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
represent a pool of elements with the same structure
keeps the information about the structure of a full matrix