50#include "./base/base_uses.f90"
55 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'minbas_methods'
79 INTEGER,
INTENT(IN),
OPTIONAL :: iounit
80 LOGICAL,
INTENT(IN),
OPTIONAL :: full_ortho
81 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: eps_filter
83 CHARACTER(len=*),
PARAMETER :: routinen =
'minbas_calculation'
85 INTEGER :: handle, homo, i, iab, ispin, nao, natom, &
86 ndep, nmao, nmo, nmx, np, np1, nspin, &
88 INTEGER,
DIMENSION(:),
POINTER :: col_blk_sizes, row_blk_sizes
89 LOGICAL :: do_minbas, my_full_ortho
90 REAL(kind=
dp) :: my_eps_filter
91 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: dval, dvalo, dvalv, eigval
94 fm_struct_d, fm_struct_e
95 TYPE(
cp_fm_type) :: fm1, fm2, fm3, fm4, fm5, fm6, fma, fmb, &
100 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
106 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
109 CALL timeset(routinen, handle)
111 IF (
PRESENT(iounit))
THEN
117 IF (
PRESENT(full_ortho))
THEN
118 my_full_ortho = full_ortho
120 my_full_ortho = .false.
123 IF (
PRESENT(eps_filter))
THEN
124 my_eps_filter = eps_filter
126 my_eps_filter = 1.0e-10_dp
129 CALL get_qs_env(qs_env, dft_control=dft_control)
130 nspin = dft_control%nspins
133 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, natom=natom)
134 CALL get_ks_env(ks_env=ks_env, particle_set=particle_set, dbcsr_dist=dbcsr_dist)
135 ALLOCATE (row_blk_sizes(natom), col_blk_sizes(natom))
138 nmao = sum(col_blk_sizes)
141 IF (col_blk_sizes(iab) < 0) &
142 cpabort(
"Number of MAOs has to be specified in KIND section for all elements")
144 CALL get_mo_set(mo_set=mos(1), nao=nao, nmo=nmo)
146 IF (unit_nr > 0)
THEN
147 WRITE (unit_nr,
'(T2,A,T71,I10)')
'Total Number of Atomic Basis Set Functions :', nao
148 WRITE (unit_nr,
'(T2,A,T71,I10)')
'Total Number of Minimal Basis Set Functions :', nmao
150 WRITE (unit_nr,
'(T2,A,T71,I10)')
'Total Number of Molecular Orbitals available :', nmo
154 WRITE (unit_nr,
'(T2,A,i2,T71,I10)') &
155 'Total Number of Molecular Orbitals available for Spin ', ispin, nmx
159 cpassert(nmao <= nao)
166 IF (unit_nr > 0)
THEN
167 WRITE (unit_nr,
'(T2,A)')
'Localized Minimal Basis Analysis not possible'
170 ELSEIF (nmo /= nmx)
THEN
171 IF (unit_nr > 0)
THEN
172 WRITE (unit_nr,
'(T2,A)')
'Different Number of Alpha and Beta MOs'
173 WRITE (unit_nr,
'(T2,A)')
'Localized Minimal Basis Analysis not possible'
178 IF (unit_nr > 0)
THEN
179 WRITE (unit_nr,
'(T2,A)')
'WARNING: Only a subset of MOs is available: Analysis depends on MOs'
190 ALLOCATE (quambo(ispin)%matrix)
192 name=
"QUAMBO", dist=dbcsr_dist, matrix_type=dbcsr_type_no_symmetry, &
193 row_blk_size=row_blk_sizes, col_blk_size=col_blk_sizes)
201 CALL dbcsr_create(sortho, name=
"SORTHO", dist=dbcsr_dist, matrix_type=dbcsr_type_no_symmetry, &
202 row_blk_size=col_blk_sizes, col_blk_size=col_blk_sizes)
205 DEALLOCATE (row_blk_sizes, col_blk_sizes)
208 CALL get_qs_env(qs_env=qs_env, para_env=para_env, blacs_env=blacs_env)
209 NULLIFY (fm_struct_a, fm_struct_b)
211 para_env=para_env, context=blacs_env)
213 para_env=para_env, context=blacs_env)
220 smat => matrix_s(1, 1)%matrix
224 CALL dbcsr_create(smao, name=
"S*MAO", template=mao_coef(1)%matrix)
225 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, smat, mao_coef(ispin)%matrix, 0.0_dp, smao)
229 CALL parallel_gemm(
"T",
"N", nmo, nmao, nao, 1.0_dp, fm_mos, fm1, 0.0_dp, fm2)
232 IF (unit_nr > 0)
THEN
233 WRITE (unit_nr,
'(T2,A,T51,A,i2,T71,I10)')
'MOs in Occupied Valence Set',
'Spin ', ispin, homo
236 NULLIFY (fm_struct_c)
238 para_env=para_env, context=blacs_env)
242 CALL parallel_gemm(
"N",
"T", nvirt, nvirt, nmao, 1.0_dp, fm2, fm2, 0.0_dp, fm3, &
243 a_first_row=homo + 1, b_first_row=homo + 1)
244 ALLOCATE (eigval(nvirt))
249 IF (unit_nr > 0)
THEN
250 WRITE (unit_nr,
'(T2,A,T51,A,i2,T71,I10)')
'MOs in Virtual Valence Set',
'Spin ', ispin, np
253 CALL parallel_gemm(
"N",
"T", nvirt, nvirt, np, 1.0_dp, fm4, fm4, 0.0_dp, fm3, &
254 a_first_col=np1, b_first_col=np1)
256 ALLOCATE (dval(nmao), dvalo(nmao), dvalv(nmao))
257 NULLIFY (fm_struct_d)
259 para_env=para_env, context=blacs_env)
261 NULLIFY (fm_struct_e)
263 para_env=para_env, context=blacs_env)
266 CALL parallel_gemm(
"N",
"N", nvirt, nmao, nvirt, 1.0_dp, fm3, fm2, 0.0_dp, fm5, &
267 b_first_row=homo + 1)
268 CALL parallel_gemm(
"T",
"N", nmao, nmao, nvirt, 1.0_dp, fm2, fm5, 0.0_dp, fm6, &
269 a_first_row=homo + 1)
271 CALL parallel_gemm(
"T",
"N", nmao, nmao, homo, 1.0_dp, fm2, fm2, 0.0_dp, fm6)
274 dval(i) = 1.0_dp/sqrt(dvalo(i) + dvalv(i))
282 CALL parallel_gemm(
"T",
"N", nmao, nmao, nmo, 1.0_dp, fma, fma, 0.0_dp, fm6)
283 IF (my_full_ortho)
THEN
285 CALL cp_fm_power(fm6, fmwork, -0.5_dp, 1.0e-12_dp, ndep)
286 IF (ndep > 0 .AND. unit_nr > 0)
THEN
287 WRITE (unit_nr,
'(T2,A,T71,I10)')
'Warning: linear dependent basis ', ndep
289 CALL parallel_gemm(
"N",
"N", nmo, nmao, nmao, 1.0_dp, fma, fm6, 0.0_dp, fmb)
293 CALL diag_sqrt_invert(sortho)
295 CALL parallel_gemm(
"N",
"N", nmo, nmao, nmao, 1.0_dp, fma, fm6, 0.0_dp, fmb)
298 CALL parallel_gemm(
"N",
"N", nao, nmao, nmo, 1.0_dp, fm_mos, fmb, 0.0_dp, fm1)
302 DEALLOCATE (eigval, dval, dvalo, dvalv)
324 IF (
PRESENT(mao))
THEN
334 CALL timestop(handle)
342 SUBROUTINE diag_sqrt_invert(sortho)
345 INTEGER :: i, iatom, info, jatom, lwork, n
346 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: w, work
347 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: amat, bmat
348 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: sblock
354 cpassert(iatom == jatom)
356 lwork = max(n*n, 100)
357 ALLOCATE (amat(n, n), bmat(n, n), w(n), work(lwork))
358 amat(1:n, 1:n) = sblock(1:n, 1:n)
360 CALL dsyev(
"V",
"U", n, amat, n, w, work, lwork, info)
362 w(1:n) = 1._dp/sqrt(w(1:n))
364 bmat(1:n, i) = amat(1:n, i)*w(i)
366 sblock(1:n, 1:n) = matmul(amat, transpose(bmat))
367 DEALLOCATE (amat, bmat, w, work)
371 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...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_reserve_diag_blocks(matrix)
Reserves all diagonal blocks.
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
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_pp, 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, harris_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, eeq, 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_pp, 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.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...