45#include "./base/base_uses.f90"
51 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_mo_types'
59 LOGICAL :: use_mo_coeff_b = .false.
65 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues => null(), &
66 occupation_numbers => null()
69 REAL(kind=
dp) :: maxocc = -1
71 INTEGER :: nelectron = -1
72 REAL(kind=
dp) :: n_el_f = -1.0_dp
80 LOGICAL :: uniform_occupation = .false.
82 REAL(kind=
dp) :: kts = -1.0_dp
84 REAL(kind=
dp) :: mu = 0.0_dp
86 REAL(kind=
dp) :: flexible_electron_count = -1.0_dp
112 TYPE(
mo_set_type),
INTENT(INOUT) :: mo_set_new, mo_set_old
116 mo_set_new%maxocc = mo_set_old%maxocc
117 mo_set_new%nelectron = mo_set_old%nelectron
118 mo_set_new%n_el_f = mo_set_old%n_el_f
119 mo_set_new%nao = mo_set_old%nao
120 mo_set_new%nmo = mo_set_old%nmo
121 mo_set_new%homo = mo_set_old%homo
122 mo_set_new%lfomo = mo_set_old%lfomo
123 mo_set_new%uniform_occupation = mo_set_old%uniform_occupation
124 mo_set_new%kTS = mo_set_old%kTS
125 mo_set_new%mu = mo_set_old%mu
126 mo_set_new%flexible_electron_count = mo_set_old%flexible_electron_count
130 IF (
ASSOCIATED(mo_set_old%cmo_coeff))
THEN
131 cpassert(
ASSOCIATED(mo_set_new%cmo_coeff))
132 CALL cp_cfm_to_cfm(mo_set_old%cmo_coeff, mo_set_new%cmo_coeff)
134 CALL cp_fm_to_fm(mo_set_old%mo_coeff, mo_set_new%mo_coeff)
142 mo_set_new%eigenvalues = mo_set_old%eigenvalues
144 mo_set_new%occupation_numbers = mo_set_old%occupation_numbers
162 mo_set_new%maxocc = mo_set_old%maxocc
163 mo_set_new%nelectron = mo_set_old%nelectron
164 mo_set_new%n_el_f = mo_set_old%n_el_f
165 mo_set_new%nao = mo_set_old%nao
166 mo_set_new%nmo = mo_set_old%nmo
167 mo_set_new%homo = mo_set_old%homo
168 mo_set_new%lfomo = mo_set_old%lfomo
169 mo_set_new%uniform_occupation = mo_set_old%uniform_occupation
170 mo_set_new%kTS = mo_set_old%kTS
171 mo_set_new%mu = mo_set_old%mu
172 mo_set_new%flexible_electron_count = mo_set_old%flexible_electron_count
176 IF (
ASSOCIATED(mo_set_old%cmo_coeff))
THEN
177 ALLOCATE (mo_set_new%cmo_coeff)
178 CALL cp_cfm_create(mo_set_new%cmo_coeff, mo_set_old%cmo_coeff%matrix_struct)
179 CALL cp_cfm_to_cfm(mo_set_old%cmo_coeff, mo_set_new%cmo_coeff)
181 ALLOCATE (mo_set_new%mo_coeff)
182 CALL cp_fm_create(mo_set_new%mo_coeff, mo_set_old%mo_coeff%matrix_struct)
183 CALL cp_fm_to_fm(mo_set_old%mo_coeff, mo_set_new%mo_coeff)
186 NULLIFY (mo_set_new%mo_coeff_b)
187 IF (
ASSOCIATED(mo_set_old%mo_coeff_b))
THEN
189 CALL dbcsr_copy(mo_set_new%mo_coeff_b, mo_set_old%mo_coeff_b)
191 mo_set_new%use_mo_coeff_b = mo_set_old%use_mo_coeff_b
193 ALLOCATE (mo_set_new%eigenvalues(nmo))
194 mo_set_new%eigenvalues = mo_set_old%eigenvalues
196 ALLOCATE (mo_set_new%occupation_numbers(nmo))
197 mo_set_new%occupation_numbers = mo_set_old%occupation_numbers
218 flexible_electron_count)
221 INTEGER,
INTENT(IN) :: nao, nmo, nelectron
222 REAL(kind=
dp),
INTENT(IN) :: n_el_f, maxocc, flexible_electron_count
224 mo_set%maxocc = maxocc
225 mo_set%nelectron = nelectron
226 mo_set%n_el_f = n_el_f
231 mo_set%uniform_occupation = .true.
234 mo_set%flexible_electron_count = flexible_electron_count
236 NULLIFY (mo_set%eigenvalues)
237 NULLIFY (mo_set%occupation_numbers)
238 NULLIFY (mo_set%mo_coeff)
239 NULLIFY (mo_set%cmo_coeff)
240 NULLIFY (mo_set%mo_coeff_b)
241 mo_set%use_mo_coeff_b = .false.
260 SUBROUTINE init_mo_set(mo_set, fm_pool, fm_ref, fm_struct, name, counter, complex_coeff)
264 TYPE(
cp_fm_type),
INTENT(IN),
OPTIONAL :: fm_ref
266 CHARACTER(LEN=*),
INTENT(in) :: name
267 INTEGER,
INTENT(INOUT),
OPTIONAL :: counter
268 LOGICAL,
INTENT(IN),
OPTIONAL :: complex_coeff
270 INTEGER :: na, nao, nb, nmo, nomo
271 LOGICAL :: use_complex
274 cpassert(.NOT.
ASSOCIATED(mo_set%eigenvalues))
275 cpassert(.NOT.
ASSOCIATED(mo_set%occupation_numbers))
276 cpassert(.NOT.
ASSOCIATED(mo_set%mo_coeff))
277 cpassert(.NOT.
ASSOCIATED(mo_set%cmo_coeff))
279 cpassert(
PRESENT(fm_pool) .NEQV. (
PRESENT(fm_ref) .NEQV.
PRESENT(fm_struct)))
280 use_complex = .false.
281 IF (
PRESENT(complex_coeff)) use_complex = complex_coeff
282 IF (use_complex)
THEN
283 IF (
PRESENT(fm_pool))
THEN
285 ELSE IF (
PRESENT(fm_ref))
THEN
286 coeff_struct => fm_ref%matrix_struct
288 cpassert(
ASSOCIATED(fm_struct))
289 coeff_struct => fm_struct
291 ALLOCATE (mo_set%cmo_coeff)
292 CALL cp_cfm_create(mo_set%cmo_coeff, coeff_struct, name=name, set_zero=.true.)
293 CALL cp_cfm_get_info(mo_set%cmo_coeff, nrow_global=nao, ncol_global=nmo)
295 IF (
PRESENT(fm_pool))
THEN
296 ALLOCATE (mo_set%mo_coeff)
298 ELSE IF (
PRESENT(fm_ref))
THEN
299 ALLOCATE (mo_set%mo_coeff)
300 CALL cp_fm_create(mo_set%mo_coeff, fm_ref%matrix_struct, name=name)
301 ELSE IF (
PRESENT(fm_struct))
THEN
302 ALLOCATE (mo_set%mo_coeff)
303 cpassert(
ASSOCIATED(fm_struct))
304 CALL cp_fm_create(mo_set%mo_coeff, fm_struct, name=name)
307 CALL cp_fm_get_info(mo_set%mo_coeff, nrow_global=nao, ncol_global=nmo)
310 cpassert(nao >= mo_set%nao)
311 cpassert(nmo >= mo_set%nmo)
313 ALLOCATE (mo_set%eigenvalues(nmo))
314 mo_set%eigenvalues(:) = 0.0_dp
316 ALLOCATE (mo_set%occupation_numbers(nmo))
318 mo_set%occupation_numbers(:) = 0.0_dp
320 IF (mo_set%nelectron == 0)
THEN
324 IF (
modulo(mo_set%nelectron, int(mo_set%maxocc)) == 0)
THEN
325 nomo = nint(mo_set%nelectron/mo_set%maxocc)
326 mo_set%occupation_numbers(1:nomo) = mo_set%maxocc
328 nomo = int(mo_set%nelectron/mo_set%maxocc) + 1
330 mo_set%occupation_numbers(1:nomo - 1) = mo_set%maxocc
331 mo_set%occupation_numbers(nomo - ((na - nb)/2):nomo) = 1
334 cpassert(nmo >= nomo)
335 cpassert((
SIZE(mo_set%occupation_numbers) == nmo))
338 mo_set%lfomo = nomo + 1
339 mo_set%mu = mo_set%eigenvalues(nomo)
352 TYPE(
mo_set_type),
DIMENSION(2),
INTENT(IN) :: mo_array
353 LOGICAL,
INTENT(in),
OPTIONAL :: convert_dbcsr
355 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mo_set_restrict'
358 LOGICAL :: my_convert_dbcsr
360 CALL timeset(routinen, handle)
362 my_convert_dbcsr = .false.
363 IF (
PRESENT(convert_dbcsr)) my_convert_dbcsr = convert_dbcsr
365 cpassert(mo_array(1)%nmo >= mo_array(2)%nmo)
368 IF (my_convert_dbcsr)
THEN
370 mo_array(2)%nmo, 1, 1, &
371 para_env=mo_array(1)%mo_coeff%matrix_struct%para_env, &
372 blacs_env=mo_array(1)%mo_coeff%matrix_struct%context)
374 CALL cp_fm_to_fm(mo_array(1)%mo_coeff, mo_array(2)%mo_coeff, mo_array(2)%nmo)
377 CALL timestop(handle)
392 IF (
ASSOCIATED(mo_set%eigenvalues))
THEN
393 DEALLOCATE (mo_set%eigenvalues)
394 NULLIFY (mo_set%eigenvalues)
396 IF (
ASSOCIATED(mo_set%occupation_numbers))
THEN
397 DEALLOCATE (mo_set%occupation_numbers)
398 NULLIFY (mo_set%occupation_numbers)
400 IF (
ASSOCIATED(mo_set%mo_coeff))
THEN
402 DEALLOCATE (mo_set%mo_coeff)
403 NULLIFY (mo_set%mo_coeff)
405 IF (
ASSOCIATED(mo_set%cmo_coeff))
THEN
407 DEALLOCATE (mo_set%cmo_coeff)
408 NULLIFY (mo_set%cmo_coeff)
410 IF (
ASSOCIATED(mo_set%mo_coeff_b))
CALL dbcsr_release_p(mo_set%mo_coeff_b)
437 SUBROUTINE get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, &
438 eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, &
439 uniform_occupation, kTS, mu, flexible_electron_count, cmo_coeff)
442 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: maxocc
443 INTEGER,
INTENT(OUT),
OPTIONAL :: homo, lfomo, nao, nelectron
444 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: n_el_f
445 INTEGER,
INTENT(OUT),
OPTIONAL :: nmo
446 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: eigenvalues, occupation_numbers
447 TYPE(
cp_fm_type),
OPTIONAL,
POINTER :: mo_coeff
448 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: mo_coeff_b
449 LOGICAL,
INTENT(OUT),
OPTIONAL :: uniform_occupation
450 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: kts, mu, flexible_electron_count
453 IF (
PRESENT(maxocc)) maxocc = mo_set%maxocc
454 IF (
PRESENT(homo)) homo = mo_set%homo
455 IF (
PRESENT(lfomo)) lfomo = mo_set%lfomo
456 IF (
PRESENT(nao)) nao = mo_set%nao
457 IF (
PRESENT(nelectron)) nelectron = mo_set%nelectron
458 IF (
PRESENT(n_el_f)) n_el_f = mo_set%n_el_f
459 IF (
PRESENT(nmo)) nmo = mo_set%nmo
460 IF (
PRESENT(eigenvalues)) eigenvalues => mo_set%eigenvalues
461 IF (
PRESENT(occupation_numbers))
THEN
462 occupation_numbers => mo_set%occupation_numbers
464 IF (
PRESENT(mo_coeff)) mo_coeff => mo_set%mo_coeff
465 IF (
PRESENT(cmo_coeff)) cmo_coeff => mo_set%cmo_coeff
466 IF (
PRESENT(mo_coeff_b)) mo_coeff_b => mo_set%mo_coeff_b
467 IF (
PRESENT(uniform_occupation)) uniform_occupation = mo_set%uniform_occupation
468 IF (
PRESENT(kts)) kts = mo_set%kTS
469 IF (
PRESENT(mu)) mu = mo_set%mu
470 IF (
PRESENT(flexible_electron_count)) flexible_electron_count = mo_set%flexible_electron_count
494 SUBROUTINE set_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, &
495 eigenvalues, occupation_numbers, uniform_occupation, &
496 kTS, mu, flexible_electron_count)
499 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: maxocc
500 INTEGER,
INTENT(IN),
OPTIONAL :: homo, lfomo, nao, nelectron
501 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: n_el_f
502 INTEGER,
INTENT(IN),
OPTIONAL :: nmo
503 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: eigenvalues, occupation_numbers
504 LOGICAL,
INTENT(IN),
OPTIONAL :: uniform_occupation
505 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: kts, mu, flexible_electron_count
507 IF (
PRESENT(maxocc)) mo_set%maxocc = maxocc
508 IF (
PRESENT(homo)) mo_set%homo = homo
509 IF (
PRESENT(lfomo)) mo_set%lfomo = lfomo
510 IF (
PRESENT(nao)) mo_set%nao = nao
511 IF (
PRESENT(nelectron)) mo_set%nelectron = nelectron
512 IF (
PRESENT(n_el_f)) mo_set%n_el_f = n_el_f
513 IF (
PRESENT(nmo)) mo_set%nmo = nmo
514 IF (
PRESENT(eigenvalues))
THEN
515 IF (
ASSOCIATED(mo_set%eigenvalues))
THEN
516 DEALLOCATE (mo_set%eigenvalues)
518 mo_set%eigenvalues => eigenvalues
520 IF (
PRESENT(occupation_numbers))
THEN
521 IF (
ASSOCIATED(mo_set%occupation_numbers))
THEN
522 DEALLOCATE (mo_set%occupation_numbers)
524 mo_set%occupation_numbers => occupation_numbers
526 IF (
PRESENT(uniform_occupation)) mo_set%uniform_occupation = uniform_occupation
527 IF (
PRESENT(kts)) mo_set%kTS = kts
528 IF (
PRESENT(mu)) mo_set%mu = mu
529 IF (
PRESENT(flexible_electron_count)) mo_set%flexible_electron_count = flexible_electron_count
550 INTEGER,
INTENT(IN),
OPTIONAL :: first_mo, last_mo
551 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: occupation, tolerance
554 INTEGER :: my_first_mo, my_last_mo
555 REAL(kind=
dp) :: my_occupation, my_tolerance
559 IF (
PRESENT(first_mo))
THEN
560 cpassert(first_mo >= lbound(mo_set%eigenvalues, 1))
561 my_first_mo = first_mo
563 my_first_mo = lbound(mo_set%eigenvalues, 1)
566 IF (
PRESENT(last_mo))
THEN
567 cpassert(last_mo <= ubound(mo_set%eigenvalues, 1))
570 my_last_mo = ubound(mo_set%eigenvalues, 1)
573 IF (
PRESENT(occupation))
THEN
574 my_occupation = occupation
576 my_occupation = mo_set%maxocc
579 IF (
PRESENT(tolerance))
THEN
580 my_tolerance = tolerance
582 my_tolerance = epsilon(0.0_dp)
585 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....
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 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
type(cp_fm_struct_type) function, pointer, public fm_pool_get_el_struct(pool)
returns the structure of the elements in this 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, complex_coeff)
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.
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...
subroutine, public reassign_allocated_mos(mo_set_new, mo_set_old)
reassign an already allocated mo_set
Represent a complex full matrix.
represent a pool of elements with the same structure
keeps the information about the structure of a full matrix