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
117 TYPE(
mo_set_type),
INTENT(INOUT) :: mo_set_new, mo_set_old
121 mo_set_new%maxocc = mo_set_old%maxocc
122 mo_set_new%nelectron = mo_set_old%nelectron
123 mo_set_new%n_el_f = mo_set_old%n_el_f
124 mo_set_new%nao = mo_set_old%nao
125 mo_set_new%nmo = mo_set_old%nmo
126 mo_set_new%homo = mo_set_old%homo
127 mo_set_new%lfomo = mo_set_old%lfomo
128 mo_set_new%uniform_occupation = mo_set_old%uniform_occupation
129 mo_set_new%kTS = mo_set_old%kTS
130 mo_set_new%mu = mo_set_old%mu
131 mo_set_new%flexible_electron_count = mo_set_old%flexible_electron_count
135 IF (
ASSOCIATED(mo_set_old%cmo_coeff))
THEN
136 cpassert(
ASSOCIATED(mo_set_new%cmo_coeff))
137 CALL cp_cfm_to_cfm(mo_set_old%cmo_coeff, mo_set_new%cmo_coeff)
139 CALL cp_fm_to_fm(mo_set_old%mo_coeff, mo_set_new%mo_coeff)
147 mo_set_new%eigenvalues = mo_set_old%eigenvalues
149 mo_set_new%occupation_numbers = mo_set_old%occupation_numbers
167 mo_set_new%maxocc = mo_set_old%maxocc
168 mo_set_new%nelectron = mo_set_old%nelectron
169 mo_set_new%n_el_f = mo_set_old%n_el_f
170 mo_set_new%nao = mo_set_old%nao
171 mo_set_new%nmo = mo_set_old%nmo
172 mo_set_new%homo = mo_set_old%homo
173 mo_set_new%lfomo = mo_set_old%lfomo
174 mo_set_new%uniform_occupation = mo_set_old%uniform_occupation
175 mo_set_new%kTS = mo_set_old%kTS
176 mo_set_new%mu = mo_set_old%mu
177 mo_set_new%flexible_electron_count = mo_set_old%flexible_electron_count
181 IF (
ASSOCIATED(mo_set_old%cmo_coeff))
THEN
182 ALLOCATE (mo_set_new%cmo_coeff)
183 CALL cp_cfm_create(mo_set_new%cmo_coeff, mo_set_old%cmo_coeff%matrix_struct)
184 CALL cp_cfm_to_cfm(mo_set_old%cmo_coeff, mo_set_new%cmo_coeff)
186 ALLOCATE (mo_set_new%mo_coeff)
187 CALL cp_fm_create(mo_set_new%mo_coeff, mo_set_old%mo_coeff%matrix_struct)
188 CALL cp_fm_to_fm(mo_set_old%mo_coeff, mo_set_new%mo_coeff)
191 NULLIFY (mo_set_new%mo_coeff_b)
192 IF (
ASSOCIATED(mo_set_old%mo_coeff_b))
THEN
194 CALL dbcsr_copy(mo_set_new%mo_coeff_b, mo_set_old%mo_coeff_b)
196 mo_set_new%use_mo_coeff_b = mo_set_old%use_mo_coeff_b
198 ALLOCATE (mo_set_new%eigenvalues(nmo))
199 mo_set_new%eigenvalues = mo_set_old%eigenvalues
201 ALLOCATE (mo_set_new%occupation_numbers(nmo))
202 mo_set_new%occupation_numbers = mo_set_old%occupation_numbers
223 flexible_electron_count)
226 INTEGER,
INTENT(IN) :: nao, nmo, nelectron
227 REAL(kind=
dp),
INTENT(IN) :: n_el_f, maxocc, flexible_electron_count
229 mo_set%maxocc = maxocc
230 mo_set%nelectron = nelectron
231 mo_set%n_el_f = n_el_f
236 mo_set%uniform_occupation = .true.
239 mo_set%flexible_electron_count = flexible_electron_count
241 NULLIFY (mo_set%eigenvalues)
242 NULLIFY (mo_set%occupation_numbers)
243 NULLIFY (mo_set%mo_coeff)
244 NULLIFY (mo_set%cmo_coeff)
245 NULLIFY (mo_set%mo_coeff_b)
246 mo_set%use_mo_coeff_b = .false.
265 SUBROUTINE init_mo_set(mo_set, fm_pool, fm_ref, fm_struct, name, counter, complex_coeff)
269 TYPE(
cp_fm_type),
INTENT(IN),
OPTIONAL :: fm_ref
271 CHARACTER(LEN=*),
INTENT(in) :: name
272 INTEGER,
INTENT(INOUT),
OPTIONAL :: counter
273 LOGICAL,
INTENT(IN),
OPTIONAL :: complex_coeff
275 INTEGER :: na, nao, nb, nmo, nomo
276 LOGICAL :: use_complex
279 cpassert(.NOT.
ASSOCIATED(mo_set%eigenvalues))
280 cpassert(.NOT.
ASSOCIATED(mo_set%occupation_numbers))
281 cpassert(.NOT.
ASSOCIATED(mo_set%mo_coeff))
282 cpassert(.NOT.
ASSOCIATED(mo_set%cmo_coeff))
284 cpassert(
PRESENT(fm_pool) .NEQV. (
PRESENT(fm_ref) .NEQV.
PRESENT(fm_struct)))
285 use_complex = .false.
286 IF (
PRESENT(complex_coeff)) use_complex = complex_coeff
287 IF (use_complex)
THEN
288 IF (
PRESENT(fm_pool))
THEN
290 ELSE IF (
PRESENT(fm_ref))
THEN
291 coeff_struct => fm_ref%matrix_struct
293 cpassert(
ASSOCIATED(fm_struct))
294 coeff_struct => fm_struct
296 ALLOCATE (mo_set%cmo_coeff)
297 CALL cp_cfm_create(mo_set%cmo_coeff, coeff_struct, name=name, set_zero=.true.)
298 CALL cp_cfm_get_info(mo_set%cmo_coeff, nrow_global=nao, ncol_global=nmo)
300 IF (
PRESENT(fm_pool))
THEN
301 ALLOCATE (mo_set%mo_coeff)
303 ELSE IF (
PRESENT(fm_ref))
THEN
304 ALLOCATE (mo_set%mo_coeff)
305 CALL cp_fm_create(mo_set%mo_coeff, fm_ref%matrix_struct, name=name)
306 ELSE IF (
PRESENT(fm_struct))
THEN
307 ALLOCATE (mo_set%mo_coeff)
308 cpassert(
ASSOCIATED(fm_struct))
309 CALL cp_fm_create(mo_set%mo_coeff, fm_struct, name=name)
312 CALL cp_fm_get_info(mo_set%mo_coeff, nrow_global=nao, ncol_global=nmo)
315 cpassert(nao >= mo_set%nao)
316 cpassert(nmo >= mo_set%nmo)
318 ALLOCATE (mo_set%eigenvalues(nmo))
319 mo_set%eigenvalues(:) = 0.0_dp
321 ALLOCATE (mo_set%occupation_numbers(nmo))
323 mo_set%occupation_numbers(:) = 0.0_dp
325 IF (mo_set%nelectron == 0)
THEN
329 IF (
modulo(mo_set%nelectron, int(mo_set%maxocc)) == 0)
THEN
330 nomo = nint(mo_set%nelectron/mo_set%maxocc)
331 mo_set%occupation_numbers(1:nomo) = mo_set%maxocc
333 nomo = int(mo_set%nelectron/mo_set%maxocc) + 1
335 mo_set%occupation_numbers(1:nomo - 1) = mo_set%maxocc
336 mo_set%occupation_numbers(nomo - ((na - nb)/2):nomo) = 1
339 cpassert(nmo >= nomo)
340 cpassert((
SIZE(mo_set%occupation_numbers) == nmo))
343 mo_set%lfomo = nomo + 1
344 mo_set%mu = mo_set%eigenvalues(nomo)
357 TYPE(
mo_set_type),
DIMENSION(2),
INTENT(IN) :: mo_array
358 LOGICAL,
INTENT(in),
OPTIONAL :: convert_dbcsr
360 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mo_set_restrict'
363 LOGICAL :: my_convert_dbcsr
365 CALL timeset(routinen, handle)
367 my_convert_dbcsr = .false.
368 IF (
PRESENT(convert_dbcsr)) my_convert_dbcsr = convert_dbcsr
370 cpassert(mo_array(1)%nmo >= mo_array(2)%nmo)
373 IF (my_convert_dbcsr)
THEN
375 mo_array(2)%nmo, 1, 1, &
376 para_env=mo_array(1)%mo_coeff%matrix_struct%para_env, &
377 blacs_env=mo_array(1)%mo_coeff%matrix_struct%context)
379 CALL cp_fm_to_fm(mo_array(1)%mo_coeff, mo_array(2)%mo_coeff, mo_array(2)%nmo)
382 CALL timestop(handle)
397 IF (
ASSOCIATED(mo_set%eigenvalues))
THEN
398 DEALLOCATE (mo_set%eigenvalues)
399 NULLIFY (mo_set%eigenvalues)
401 IF (
ASSOCIATED(mo_set%occupation_numbers))
THEN
402 DEALLOCATE (mo_set%occupation_numbers)
403 NULLIFY (mo_set%occupation_numbers)
405 IF (
ASSOCIATED(mo_set%mo_coeff))
THEN
407 DEALLOCATE (mo_set%mo_coeff)
408 NULLIFY (mo_set%mo_coeff)
410 IF (
ASSOCIATED(mo_set%cmo_coeff))
THEN
412 DEALLOCATE (mo_set%cmo_coeff)
413 NULLIFY (mo_set%cmo_coeff)
415 IF (
ASSOCIATED(mo_set%mo_coeff_b))
CALL dbcsr_release_p(mo_set%mo_coeff_b)
442 SUBROUTINE get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, &
443 eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, &
444 uniform_occupation, kTS, mu, flexible_electron_count, cmo_coeff)
447 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: maxocc
448 INTEGER,
INTENT(OUT),
OPTIONAL :: homo, lfomo, nao, nelectron
449 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: n_el_f
450 INTEGER,
INTENT(OUT),
OPTIONAL :: nmo
451 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: eigenvalues, occupation_numbers
452 TYPE(
cp_fm_type),
OPTIONAL,
POINTER :: mo_coeff
453 TYPE(
dbcsr_type),
OPTIONAL,
POINTER :: mo_coeff_b
454 LOGICAL,
INTENT(OUT),
OPTIONAL :: uniform_occupation
455 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: kts, mu, flexible_electron_count
458 IF (
PRESENT(maxocc)) maxocc = mo_set%maxocc
459 IF (
PRESENT(homo)) homo = mo_set%homo
460 IF (
PRESENT(lfomo)) lfomo = mo_set%lfomo
461 IF (
PRESENT(nao)) nao = mo_set%nao
462 IF (
PRESENT(nelectron)) nelectron = mo_set%nelectron
463 IF (
PRESENT(n_el_f)) n_el_f = mo_set%n_el_f
464 IF (
PRESENT(nmo)) nmo = mo_set%nmo
465 IF (
PRESENT(eigenvalues)) eigenvalues => mo_set%eigenvalues
466 IF (
PRESENT(occupation_numbers))
THEN
467 occupation_numbers => mo_set%occupation_numbers
469 IF (
PRESENT(mo_coeff)) mo_coeff => mo_set%mo_coeff
470 IF (
PRESENT(cmo_coeff)) cmo_coeff => mo_set%cmo_coeff
471 IF (
PRESENT(mo_coeff_b)) mo_coeff_b => mo_set%mo_coeff_b
472 IF (
PRESENT(uniform_occupation)) uniform_occupation = mo_set%uniform_occupation
473 IF (
PRESENT(kts)) kts = mo_set%kTS
474 IF (
PRESENT(mu)) mu = mo_set%mu
475 IF (
PRESENT(flexible_electron_count)) flexible_electron_count = mo_set%flexible_electron_count
499 SUBROUTINE set_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, &
500 eigenvalues, occupation_numbers, uniform_occupation, &
501 kTS, mu, flexible_electron_count)
504 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: maxocc
505 INTEGER,
INTENT(IN),
OPTIONAL :: homo, lfomo, nao, nelectron
506 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: n_el_f
507 INTEGER,
INTENT(IN),
OPTIONAL :: nmo
508 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: eigenvalues, occupation_numbers
509 LOGICAL,
INTENT(IN),
OPTIONAL :: uniform_occupation
510 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: kts, mu, flexible_electron_count
512 IF (
PRESENT(maxocc)) mo_set%maxocc = maxocc
513 IF (
PRESENT(homo)) mo_set%homo = homo
514 IF (
PRESENT(lfomo)) mo_set%lfomo = lfomo
515 IF (
PRESENT(nao)) mo_set%nao = nao
516 IF (
PRESENT(nelectron)) mo_set%nelectron = nelectron
517 IF (
PRESENT(n_el_f)) mo_set%n_el_f = n_el_f
518 IF (
PRESENT(nmo)) mo_set%nmo = nmo
519 IF (
PRESENT(eigenvalues))
THEN
520 IF (
ASSOCIATED(mo_set%eigenvalues))
THEN
521 DEALLOCATE (mo_set%eigenvalues)
523 mo_set%eigenvalues => eigenvalues
525 IF (
PRESENT(occupation_numbers))
THEN
526 IF (
ASSOCIATED(mo_set%occupation_numbers))
THEN
527 DEALLOCATE (mo_set%occupation_numbers)
529 mo_set%occupation_numbers => occupation_numbers
531 IF (
PRESENT(uniform_occupation)) mo_set%uniform_occupation = uniform_occupation
532 IF (
PRESENT(kts)) mo_set%kTS = kts
533 IF (
PRESENT(mu)) mo_set%mu = mu
534 IF (
PRESENT(flexible_electron_count)) mo_set%flexible_electron_count = flexible_electron_count
555 INTEGER,
INTENT(IN),
OPTIONAL :: first_mo, last_mo
556 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: occupation, tolerance
559 INTEGER :: my_first_mo, my_last_mo
560 REAL(kind=
dp) :: my_occupation, my_tolerance
564 IF (
PRESENT(first_mo))
THEN
565 cpassert(first_mo >= lbound(mo_set%eigenvalues, 1))
566 my_first_mo = first_mo
568 my_first_mo = lbound(mo_set%eigenvalues, 1)
571 IF (
PRESENT(last_mo))
THEN
572 cpassert(last_mo <= ubound(mo_set%eigenvalues, 1))
575 my_last_mo = ubound(mo_set%eigenvalues, 1)
578 IF (
PRESENT(occupation))
THEN
579 my_occupation = occupation
581 my_occupation = mo_set%maxocc
584 IF (
PRESENT(tolerance))
THEN
585 my_tolerance = tolerance
587 my_tolerance = epsilon(0.0_dp)
590 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