32 USE dbcsr_api,
ONLY: &
33 dbcsr_create, dbcsr_distribution_type, dbcsr_filter, dbcsr_iterator_blocks_left, &
34 dbcsr_iterator_next_block, dbcsr_iterator_start, dbcsr_iterator_stop, dbcsr_iterator_type, &
35 dbcsr_multiply, dbcsr_p_type, dbcsr_release, dbcsr_reserve_diag_blocks, dbcsr_type, &
36 dbcsr_type_no_symmetry
38 USE lapack,
ONLY: lapack_ssyev
51 #include "./base/base_uses.f90"
56 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'minbas_methods'
75 TYPE(qs_environment_type),
POINTER :: qs_env
76 TYPE(mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
77 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: quambo
78 TYPE(dbcsr_p_type),
DIMENSION(:),
OPTIONAL, &
80 INTEGER,
INTENT(IN),
OPTIONAL :: iounit
81 LOGICAL,
INTENT(IN),
OPTIONAL :: full_ortho
82 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: eps_filter
84 CHARACTER(len=*),
PARAMETER :: routinen =
'minbas_calculation'
86 INTEGER :: handle, homo, i, iab, ispin, nao, natom, &
87 ndep, nmao, nmo, nmx, np, np1, nspin, &
89 INTEGER,
DIMENSION(:),
POINTER :: col_blk_sizes, row_blk_sizes
90 LOGICAL :: do_minbas, my_full_ortho
91 REAL(kind=
dp) :: my_eps_filter
92 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: dval, dvalo, dvalv, eigval
93 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
94 TYPE(cp_fm_struct_type),
POINTER :: fm_struct_a, fm_struct_b, fm_struct_c, &
95 fm_struct_d, fm_struct_e
96 TYPE(cp_fm_type) :: fm1, fm2, fm3, fm4, fm5, fm6, fma, fmb, &
98 TYPE(cp_fm_type),
POINTER :: fm_mos
99 TYPE(dbcsr_distribution_type),
POINTER :: dbcsr_dist
100 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
101 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
102 TYPE(dbcsr_type) :: smao, sortho
103 TYPE(dbcsr_type),
POINTER :: smat
104 TYPE(dft_control_type),
POINTER :: dft_control
105 TYPE(mp_para_env_type),
POINTER :: para_env
106 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
107 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
108 TYPE(qs_ks_env_type),
POINTER :: ks_env
110 CALL timeset(routinen, handle)
112 IF (
PRESENT(iounit))
THEN
118 IF (
PRESENT(full_ortho))
THEN
119 my_full_ortho = full_ortho
121 my_full_ortho = .false.
124 IF (
PRESENT(eps_filter))
THEN
125 my_eps_filter = eps_filter
127 my_eps_filter = 1.0e-10_dp
130 CALL get_qs_env(qs_env, dft_control=dft_control)
131 nspin = dft_control%nspins
134 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, natom=natom)
135 CALL get_ks_env(ks_env=ks_env, particle_set=particle_set, dbcsr_dist=dbcsr_dist)
136 ALLOCATE (row_blk_sizes(natom), col_blk_sizes(natom))
139 nmao = sum(col_blk_sizes)
142 IF (col_blk_sizes(iab) < 0) &
143 cpabort(
"Number of MAOs has to be specified in KIND section for all elements")
145 CALL get_mo_set(mo_set=mos(1), nao=nao, nmo=nmo)
147 IF (unit_nr > 0)
THEN
148 WRITE (unit_nr,
'(T2,A,T71,I10)')
'Total Number of Atomic Basis Set Functions :', nao
149 WRITE (unit_nr,
'(T2,A,T71,I10)')
'Total Number of Minimal Basis Set Functions :', nmao
151 WRITE (unit_nr,
'(T2,A,T71,I10)')
'Total Number of Molecular Orbitals available :', nmo
155 WRITE (unit_nr,
'(T2,A,i2,T71,I10)') &
156 'Total Number of Molecular Orbitals available for Spin ', ispin, nmx
160 cpassert(nmao <= nao)
167 IF (unit_nr > 0)
THEN
168 WRITE (unit_nr,
'(T2,A)')
'Localized Minimal Basis Analysis not possible'
171 ELSEIF (nmo /= nmx)
THEN
172 IF (unit_nr > 0)
THEN
173 WRITE (unit_nr,
'(T2,A)')
'Different Number of Alpha and Beta MOs'
174 WRITE (unit_nr,
'(T2,A)')
'Localized Minimal Basis Analysis not possible'
179 IF (unit_nr > 0)
THEN
180 WRITE (unit_nr,
'(T2,A)')
'WARNING: Only a subset of MOs is available: Analysis depends on MOs'
191 ALLOCATE (quambo(ispin)%matrix)
192 CALL dbcsr_create(matrix=quambo(ispin)%matrix, &
193 name=
"QUAMBO", dist=dbcsr_dist, matrix_type=dbcsr_type_no_symmetry, &
194 row_blk_size=row_blk_sizes, col_blk_size=col_blk_sizes, nze=0)
202 CALL dbcsr_create(sortho, name=
"SORTHO", dist=dbcsr_dist, matrix_type=dbcsr_type_no_symmetry, &
203 row_blk_size=col_blk_sizes, col_blk_size=col_blk_sizes, nze=0)
204 CALL dbcsr_reserve_diag_blocks(matrix=sortho)
206 DEALLOCATE (row_blk_sizes, col_blk_sizes)
209 CALL get_qs_env(qs_env=qs_env, para_env=para_env, blacs_env=blacs_env)
210 NULLIFY (fm_struct_a, fm_struct_b)
212 para_env=para_env, context=blacs_env)
214 para_env=para_env, context=blacs_env)
221 smat => matrix_s(1, 1)%matrix
225 CALL dbcsr_create(smao, name=
"S*MAO", template=mao_coef(1)%matrix)
226 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, smat, mao_coef(ispin)%matrix, 0.0_dp, smao)
230 CALL parallel_gemm(
"T",
"N", nmo, nmao, nao, 1.0_dp, fm_mos, fm1, 0.0_dp, fm2)
231 CALL dbcsr_release(smao)
233 IF (unit_nr > 0)
THEN
234 WRITE (unit_nr,
'(T2,A,T51,A,i2,T71,I10)')
'MOs in Occupied Valence Set',
'Spin ', ispin, homo
237 NULLIFY (fm_struct_c)
239 para_env=para_env, context=blacs_env)
243 CALL parallel_gemm(
"N",
"T", nvirt, nvirt, nmao, 1.0_dp, fm2, fm2, 0.0_dp, fm3, &
244 a_first_row=homo + 1, b_first_row=homo + 1)
245 ALLOCATE (eigval(nvirt))
250 IF (unit_nr > 0)
THEN
251 WRITE (unit_nr,
'(T2,A,T51,A,i2,T71,I10)')
'MOs in Virtual Valence Set',
'Spin ', ispin, np
254 CALL parallel_gemm(
"N",
"T", nvirt, nvirt, np, 1.0_dp, fm4, fm4, 0.0_dp, fm3, &
255 a_first_col=np1, b_first_col=np1)
257 ALLOCATE (dval(nmao), dvalo(nmao), dvalv(nmao))
258 NULLIFY (fm_struct_d)
260 para_env=para_env, context=blacs_env)
262 NULLIFY (fm_struct_e)
264 para_env=para_env, context=blacs_env)
267 CALL parallel_gemm(
"N",
"N", nvirt, nmao, nvirt, 1.0_dp, fm3, fm2, 0.0_dp, fm5, &
268 b_first_row=homo + 1)
269 CALL parallel_gemm(
"T",
"N", nmao, nmao, nvirt, 1.0_dp, fm2, fm5, 0.0_dp, fm6, &
270 a_first_row=homo + 1)
272 CALL parallel_gemm(
"T",
"N", nmao, nmao, homo, 1.0_dp, fm2, fm2, 0.0_dp, fm6)
275 dval(i) = 1.0_dp/sqrt(dvalo(i) + dvalv(i))
283 CALL parallel_gemm(
"T",
"N", nmao, nmao, nmo, 1.0_dp, fma, fma, 0.0_dp, fm6)
284 IF (my_full_ortho)
THEN
286 CALL cp_fm_power(fm6, fmwork, -0.5_dp, 1.0e-12_dp, ndep)
287 IF (ndep > 0 .AND. unit_nr > 0)
THEN
288 WRITE (unit_nr,
'(T2,A,T71,I10)')
'Warning: linear dependent basis ', ndep
290 CALL parallel_gemm(
"N",
"N", nmo, nmao, nmao, 1.0_dp, fma, fm6, 0.0_dp, fmb)
294 CALL diag_sqrt_invert(sortho)
296 CALL parallel_gemm(
"N",
"N", nmo, nmao, nmao, 1.0_dp, fma, fm6, 0.0_dp, fmb)
299 CALL parallel_gemm(
"N",
"N", nao, nmao, nmo, 1.0_dp, fm_mos, fmb, 0.0_dp, fm1)
301 CALL dbcsr_filter(quambo(ispin)%matrix, my_eps_filter)
303 DEALLOCATE (eigval, dval, dvalo, dvalv)
304 CALL cp_fm_release(fm3)
305 CALL cp_fm_release(fm4)
306 CALL cp_fm_release(fm5)
307 CALL cp_fm_release(fm6)
308 CALL cp_fm_release(fmwork)
316 CALL cp_fm_release(fm1)
317 CALL cp_fm_release(fm2)
318 CALL cp_fm_release(fma)
319 CALL cp_fm_release(fmb)
322 CALL dbcsr_release(sortho)
325 IF (
PRESENT(mao))
THEN
335 CALL timestop(handle)
343 SUBROUTINE diag_sqrt_invert(sortho)
344 TYPE(dbcsr_type) :: sortho
346 INTEGER :: i, iatom, info, jatom, lwork, n
347 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: w, work
348 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: amat, bmat
349 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: sblock
350 TYPE(dbcsr_iterator_type) :: dbcsr_iter
352 CALL dbcsr_iterator_start(dbcsr_iter, sortho)
353 DO WHILE (dbcsr_iterator_blocks_left(dbcsr_iter))
354 CALL dbcsr_iterator_next_block(dbcsr_iter, iatom, jatom, sblock)
355 cpassert(iatom == jatom)
357 lwork = max(n*n, 100)
358 ALLOCATE (amat(n, n), bmat(n, n), w(n), work(lwork))
359 amat(1:n, 1:n) = sblock(1:n, 1:n)
361 CALL lapack_ssyev(
"V",
"U", n, amat, n, w, work, lwork, info)
363 w(1:n) = 1._dp/sqrt(w(1:n))
365 bmat(1:n, i) = amat(1:n, i)*w(i)
367 sblock(1:n, 1:n) = matmul(amat, transpose(bmat))
368 DEALLOCATE (amat, bmat, w, work)
370 CALL dbcsr_iterator_stop(dbcsr_iter)
372 END SUBROUTINE diag_sqrt_invert
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
basic linear algebra operations for full matrices
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public cp_fm_power(matrix, work, exponent, threshold, n_dependent, verbose, eigvals)
...
subroutine, public choose_eigv_solver(matrix, eigenvectors, eigenvalues, info)
Choose the Eigensolver depending on which library is available ELPA seems to be unstable for small sy...
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_diag(matrix, diag)
returns the diagonal elements of a fm
subroutine, public cp_fm_to_fm_submat(msource, mtarget, nrow, ncol, s_firstrow, s_firstcol, t_firstrow, t_firstcol)
copy just a part ot the matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
Defines the basic variable types.
integer, parameter, public dp
Interface to the LAPACK F77 library.
Calculate MAO's and analyze wavefunctions.
subroutine, public mao_generate_basis(qs_env, mao_coef, ref_basis_set, pmat_external, smat_external, molecular, max_iter, eps_grad, nmao_external, eps1_mao, iolevel, unit_nr)
...
Interface to the message passing library MPI.
Calculate localized minimal basis.
subroutine, public minbas_calculation(qs_env, mos, quambo, mao, iounit, full_ortho, eps_filter)
...
basic linear algebra operations for full matrixes
Define methods related to particle_type.
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis)
Get the components of a particle set.
Define the data structure for the particle information.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, WannierCentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, matrix_ks_im_kp, rho, rho_xc, vppl, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, task_list, task_list_soft, kpoints, do_kpoints, atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, particle_set, energy, force, local_particles, local_molecules, molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, nelectron_total, nelectron_spin)
...
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)
Get the components of a MO set data structure.