68#include "./base/base_uses.f90"
76 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_loc_main'
95 SUBROUTINE qs_loc_driver(qs_env, qs_loc_env, print_loc_section, myspin, ext_mo_coeff)
100 INTEGER,
INTENT(IN) :: myspin
101 TYPE(
cp_fm_type),
INTENT(IN),
OPTIONAL,
TARGET :: ext_mo_coeff
103 CHARACTER(len=*),
PARAMETER :: routinen =
'qs_loc_driver'
105 INTEGER :: dim_op, handle, i, imo, imoloc, j, lb, &
106 loc_method, nao, nmosub, restricted, ub
107 INTEGER,
DIMENSION(:),
POINTER :: ivec
108 LOGICAL,
SAVE :: first_time = .true.
109 REAL(
dp),
DIMENSION(6) :: weights
110 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: vecbuffer
113 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: moloc_coeff
114 TYPE(
cp_fm_type),
DIMENSION(:, :),
POINTER :: op_fm_set
116 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: op_sm_set
123 CALL timeset(routinen, handle)
124 NULLIFY (para_env, mos, dft_control)
125 NULLIFY (cell, localized_wfn_control, moloc_coeff, op_sm_set, op_fm_set)
126 qs_loc_env%first_time = first_time
127 qs_loc_env%target_time = qs_env%target_time
128 qs_loc_env%start_time = qs_env%start_time
131 localized_wfn_control=localized_wfn_control, &
132 moloc_coeff=moloc_coeff, op_sm_set=op_sm_set, op_fm_set=op_fm_set, cell=cell, &
133 weights=weights, dim_op=dim_op)
135 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, &
136 para_env=para_env, mos=mos, input=input)
139 IF (dft_control%restricted)
THEN
141 CALL section_vals_val_get(low_spin_roks_section,
"SPIN_CONFIGURATION", i_rep_val=1, i_vals=ivec)
142 restricted =
SIZE(ivec)
148 IF (
PRESENT(ext_mo_coeff))
THEN
149 locorb => ext_mo_coeff
151 CALL get_mo_set(mo_set=mos(myspin), mo_coeff=locorb)
154 loc_method = localized_wfn_control%localization_method
156 nmosub = localized_wfn_control%nloc_states(myspin)
157 IF (localized_wfn_control%operator_type ==
op_loc_berry)
THEN
159 NULLIFY (tmp_fm_struct)
161 ncol_global=nmosub, para_env=para_env, &
162 context=locorb%matrix_struct%context)
164 ALLOCATE (op_fm_set(2, dim_op))
166 DO j = 1,
SIZE(op_fm_set, 1)
175 IF (localized_wfn_control%do_mixed)
THEN
176 CALL loc_mixed_method(qs_env, qs_loc_env, print_loc_section, myspin, op_fm_set)
178 SELECT CASE (localized_wfn_control%operator_type)
181 op_fm_set, para_env, cell, weights, myspin, print_loc_section, &
182 restricted=restricted)
184 cpabort(
"Boys localization not implemented")
187 op_fm_set, myspin, print_loc_section)
192 IF (localized_wfn_control%operator_type ==
op_loc_berry)
THEN
193 IF (
ASSOCIATED(op_fm_set))
THEN
195 DO j = 1,
SIZE(op_fm_set, 1)
199 DEALLOCATE (op_fm_set)
205 lb = localized_wfn_control%lu_bound_states(1, myspin)
206 ub = localized_wfn_control%lu_bound_states(2, myspin)
209 ALLOCATE (vecbuffer(1, nao))
210 nmosub =
SIZE(localized_wfn_control%loc_states, 1)
216 imo = localized_wfn_control%loc_states(i, myspin)
219 nao, 1, transpose=.true.)
222 DEALLOCATE (vecbuffer)
224 nmosub = localized_wfn_control%nloc_states(myspin)
225 CALL cp_fm_to_fm(moloc_coeff(myspin), locorb, nmosub, 1, lb)
229 IF (localized_wfn_control%print_cubes)
THEN
230 CALL loc_print(qs_env, qs_loc_env, moloc_coeff, myspin, print_loc_section)
234 CALL timestop(handle)
249 SUBROUTINE loc_mixed_method(qs_env, qs_loc_env, print_loc_section, myspin, op_fm_set)
254 INTEGER,
INTENT(IN) :: myspin
255 TYPE(
cp_fm_type),
DIMENSION(:, :),
POINTER :: op_fm_set
257 CHARACTER(len=*),
PARAMETER :: routinen =
'loc_mixed_method'
259 INTEGER :: dim_op, handle, jspin, loc_method, nao, &
260 ndummy, nextra, ngextra, nguess, nmo, &
261 nmosub, norextra, restricted
262 INTEGER,
DIMENSION(2) :: nelectron_spin
263 INTEGER,
DIMENSION(:),
POINTER :: ivec
264 LOGICAL :: do_ortho, has_unit_metric, &
265 my_guess_atomic, my_guess_wan
266 REAL(
dp),
DIMENSION(6) :: weights
267 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: tmp_mat
271 TYPE(
cp_fm_type) :: mos_guess, tmp_fm, tmp_fm_1, vectors_2
272 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: moloc_coeff
275 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s_kp, op_sm_set
276 TYPE(
dbcsr_type),
POINTER :: refmatrix, tmatrix
284 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
287 CALL timeset(routinen, handle)
289 NULLIFY (moloc_coeff, op_sm_set)
290 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, para_env=para_env, mos=mos, input=input)
293 IF (dft_control%restricted)
THEN
295 CALL section_vals_val_get(low_spin_roks_section,
"SPIN_CONFIGURATION", i_rep_val=1, i_vals=ivec)
296 restricted =
SIZE(ivec)
302 localized_wfn_control=localized_wfn_control, &
303 moloc_coeff=moloc_coeff, op_sm_set=op_sm_set, cell=cell, &
304 weights=weights, dim_op=dim_op)
306 CALL get_mo_set(mo_set=mos(myspin), nao=nao, nmo=nmo)
307 loc_method = localized_wfn_control%localization_method
308 nmosub = localized_wfn_control%nloc_states(myspin)
310 cpassert(localized_wfn_control%operator_type ==
op_loc_berry)
311 cpassert(localized_wfn_control%do_mixed)
313 my_guess_atomic = .false.
317 nextra = localized_wfn_control%nextra
319 my_guess_atomic = .true.
320 my_guess_wan = .false.
322 SELECT CASE (localized_wfn_control%coeff_po_guess)
325 my_guess_atomic = .true.
326 NULLIFY (atomic_kind_set, qs_kind_set, particle_set, matrix_s_kp, sab_orb, p_rmpv, &
329 atomic_kind_set=atomic_kind_set, &
330 qs_kind_set=qs_kind_set, &
331 particle_set=particle_set, &
332 matrix_s_kp=matrix_s_kp, &
333 has_unit_metric=has_unit_metric, &
334 nelectron_spin=nelectron_spin, &
337 refmatrix => matrix_s_kp(1, 1)%matrix
340 DO jspin = 1, dft_control%nspins
341 ALLOCATE (p_rmpv(jspin)%matrix)
342 tmatrix => p_rmpv(jspin)%matrix
344 matrix_type=dbcsr_type_symmetric)
349 dft_control%nspins, nelectron_spin, 0, para_env)
351 my_guess_atomic = .false.
352 my_guess_wan = .true.
354 my_guess_atomic = .false.
357 norextra = nmo - nmosub
358 CALL get_mo_set(mo_set=mos(myspin), mo_coeff=mo_coeff)
360 ncol_global=norextra, para_env=para_env, context=mo_coeff%matrix_struct%context)
363 ALLOCATE (tmp_mat(nao, norextra))
370 IF (my_guess_atomic .OR. my_guess_wan)
THEN
372 SELECT CASE (localized_wfn_control%coeff_po_guess_mo_space)
383 ncol_global=ndummy, para_env=para_env, &
384 context=mo_coeff%matrix_struct%context)
388 IF (my_guess_atomic)
THEN
394 IF (has_unit_metric)
THEN
404 ELSEIF (my_guess_wan)
THEN
405 nguess = localized_wfn_control%nguess(myspin)
406 ALLOCATE (tmp_mat(nao, nguess))
410 ngextra = nmosub - nguess
413 IF (ngextra > 0)
THEN
415 ncol_global=ngextra, para_env=para_env, &
416 context=mo_coeff%matrix_struct%context)
419 ALLOCATE (tmp_mat(nao, ngextra))
428 ALLOCATE (tmp_mat(nao, nmosub))
435 IF ((my_guess_atomic) .OR. (my_guess_wan))
THEN
437 IF (has_unit_metric)
THEN
446 op_fm_set, para_env, cell, weights, myspin, print_loc_section, &
447 restricted=restricted, &
448 nextra=nextra, nmo=nmo, vectors_2=vectors_2, guess_mos=mos_guess)
452 op_fm_set, para_env, cell, weights, myspin, print_loc_section, &
453 restricted=restricted, &
454 nextra=nextra, nmo=nmo, vectors_2=vectors_2)
460 op_fm_set, para_env, cell, weights, myspin, print_loc_section, &
461 restricted=restricted, nextra=0)
464 CALL timestop(handle)
466 END SUBROUTINE loc_mixed_method
476 SUBROUTINE loc_print(qs_env, qs_loc_env, moloc_coeff, ispin, print_loc_section)
480 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: moloc_coeff
481 INTEGER,
INTENT(IN),
OPTIONAL :: ispin
484 CHARACTER(LEN=default_string_length) :: my_pos
485 INTEGER :: i, ir, istate, j, jstate, n_rep, ncubes, &
487 INTEGER,
DIMENSION(:),
POINTER :: bounds,
list, list_cubes
488 LOGICAL :: append_cube, list_cubes_setup
489 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: centers
493 list_cubes_setup = .false.
494 NULLIFY (bounds,
list, list_cubes)
497 localized_wfn_control=localized_wfn_control)
502 ncubes = bounds(2) - bounds(1) + 1
504 list_cubes_setup = .true.
505 ALLOCATE (list_cubes(ncubes))
507 list_cubes(ir) = bounds(1) + (ir - 1)
514 IF (.NOT. list_cubes_setup)
THEN
518 i_rep_val=ir, i_vals=
list)
519 IF (
ASSOCIATED(
list))
THEN
522 list_cubes(i + ncubes) =
list(i)
524 ncubes = ncubes +
SIZE(
list)
527 IF (ncubes > 0) list_cubes_setup = .true.
531 IF (.NOT. list_cubes_setup)
THEN
532 list_cubes_setup = .true.
533 ncubes = localized_wfn_control%nloc_states(1)
535 ALLOCATE (list_cubes(ncubes))
542 ncubes =
SIZE(list_cubes)
544 ncubes = min(ncubes, nmo)
545 ALLOCATE (centers(6, ncubes))
547 istate = list_cubes(i)
548 DO j = 1, localized_wfn_control%nloc_states(ispin)
549 jstate = localized_wfn_control%loc_states(j, ispin)
550 IF (istate == jstate)
THEN
551 centers(1:6, i) = localized_wfn_control%centers_set(ispin)%array(1:6, j)
561 IF (append_cube)
THEN
565 CALL qs_print_cubes(qs_env, moloc_coeff(ispin), ncubes, list_cubes, centers, &
566 print_key,
"loc"//trim(adjustl(qs_loc_env%tag_mo)), &
567 ispin=ispin, file_position=my_pos)
570 DEALLOCATE (list_cubes)
572 END SUBROUTINE loc_print
Define the atomic kind types and their sub types.
Handles all functions related to the CELL.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_set(matrix, alpha)
...
Routines that link DBCSR and CP2K concepts together.
subroutine, public cp_dbcsr_alloc_block_from_nbl(matrix, sab_orb, desymmetrize)
allocate the blocks of a dbcsr based on the neighbor list
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
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_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_submatrix(fm, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
sets a submatrix of a full matrix fm(start_row:start_row+n_rows,start_col:start_col+n_cols) = alpha*o...
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_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
gets a submatrix of a full matrix op(target_m)(1:n_rows,1:n_cols) =fm(start_row:start_row+n_rows,...
subroutine, public cp_fm_init_random(matrix, ncol, start_col)
fills a matrix with random numbers
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
integer, parameter, public default_string_length
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
Utility routines for the memory handling.
Interface to the message passing library MPI.
Define the data structure for the particle information.
Routine to return block diagonal density matrix. Blocks correspond to the atomic densities.
subroutine, public calculate_atomic_block_dm(pmatrix, matrix_s, atomic_kind_set, qs_kind_set, nspin, nelectron_spin, ounit, para_env)
returns a block diagonal density matrix. Blocks correspond to the atomic densities.
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.
Driver for the localization that should be general for all the methods available and all the definiti...
subroutine, public qs_loc_driver(qs_env, qs_loc_env, print_loc_section, myspin, ext_mo_coeff)
set up the calculation of localized orbitals
Driver for the localization that should be general for all the methods available and all the definiti...
subroutine, public optimize_loc_pipek(qs_env, method, qs_loc_env, vectors, zij_fm_set, ispin, print_loc_section)
...
subroutine, public optimize_loc_berry(method, qs_loc_env, vectors, op_sm_set, zij_fm_set, para_env, cell, weights, ispin, print_loc_section, restricted, nextra, nmo, vectors_2, guess_mos)
Calculate and optimize the spread functional as calculated from the selected mos and by the definitio...
subroutine, public qs_print_cubes(qs_env, mo_coeff, nstates, state_list, centers, print_key, root, ispin, idir, state0, file_position)
write the cube files for a set of selected states
New version of the module for the localization of the molecular orbitals This should be able to use d...
subroutine, public get_qs_loc_env(qs_loc_env, cell, local_molecules, localized_wfn_control, moloc_coeff, op_sm_set, op_fm_set, para_env, particle_set, weights, dim_op)
...
collects routines that perform operations directly related to MOs
subroutine, public make_basis_simple(vmatrix, ncol)
given a set of vectors, return an orthogonal (C^T C == 1) set spanning the same space (notice,...
subroutine, public make_basis_sm(vmatrix, ncol, matrix_s)
returns an S-orthonormal basis v (v^T S v ==1)
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.
Define the neighbor list data types and the corresponding functionality.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
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.
A type that holds controlling information for the calculation of the spread of wfn and the optimizati...
contains all the info needed by quickstep to calculate the spread of a selected set of orbitals and i...