18 dbcsr_csr_dbcsr_blkrow_dist, dbcsr_csr_destroy, dbcsr_csr_type, dbcsr_csr_write, &
21 dbcsr_type_no_symmetry, dbcsr_type_symmetric
51#include "./base/base_uses.f90"
57 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_scf_csr_write'
79 CHARACTER(len=*),
PARAMETER :: routinen =
'write_ks_matrix_csr'
81 INTEGER :: handle, output_unit
82 LOGICAL :: do_kpoints, do_ks_csr_write, real_space
84 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks
88 CALL timeset(routinen, handle)
99 IF (do_ks_csr_write)
THEN
100 CALL get_qs_env(qs_env=qs_env, kpoints=kpoints, matrix_ks_kp=matrix_ks, do_kpoints=do_kpoints)
104 IF (do_kpoints .AND. .NOT. real_space)
THEN
105 CALL write_matrix_kp_csr(mat=matrix_ks, dft_section=dft_section, &
106 kpoints=kpoints, prefix=
"KS")
108 CALL write_matrix_csr(dft_section, mat=matrix_ks, kpoints=kpoints, do_kpoints=do_kpoints, &
113 CALL timestop(handle)
129 CHARACTER(len=*),
PARAMETER :: routinen =
'write_s_matrix_csr'
131 INTEGER :: handle, output_unit
132 LOGICAL :: do_kpoints, do_s_csr_write, real_space
134 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
138 CALL timeset(routinen, handle)
140 NULLIFY (dft_section)
149 IF (do_s_csr_write)
THEN
150 CALL get_qs_env(qs_env=qs_env, kpoints=kpoints, matrix_s_kp=matrix_s, do_kpoints=do_kpoints)
154 IF (do_kpoints .AND. .NOT. real_space)
THEN
155 CALL write_matrix_kp_csr(mat=matrix_s, dft_section=dft_section, &
156 kpoints=kpoints, prefix=
"S")
158 CALL write_matrix_csr(dft_section, mat=matrix_s, kpoints=kpoints, do_kpoints=do_kpoints, &
163 CALL timestop(handle)
178 CHARACTER(len=*),
PARAMETER :: routinen =
'write_p_matrix_csr'
180 INTEGER :: handle, output_unit
181 LOGICAL :: do_kpoints, do_p_csr_write, real_space
183 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
188 CALL timeset(routinen, handle)
190 NULLIFY (dft_section)
199 IF (do_p_csr_write)
THEN
200 CALL get_qs_env(qs_env=qs_env, kpoints=kpoints, rho=rho, do_kpoints=do_kpoints)
205 IF (do_kpoints .AND. .NOT. real_space)
THEN
206 CALL write_matrix_kp_csr(mat=rho_ao_kp, dft_section=dft_section, &
207 kpoints=kpoints, prefix=
"P")
209 CALL write_matrix_csr(dft_section, mat=rho_ao_kp, kpoints=kpoints, do_kpoints=do_kpoints, &
214 CALL timestop(handle)
229 CHARACTER(len=*),
PARAMETER :: routinen =
'write_hcore_matrix_csr'
231 INTEGER :: handle, output_unit
232 LOGICAL :: do_h_csr_write, do_kpoints, real_space
234 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_h
238 CALL timeset(routinen, handle)
240 NULLIFY (dft_section)
249 IF (do_h_csr_write)
THEN
250 CALL get_qs_env(qs_env=qs_env, kpoints=kpoints, matrix_h_kp=matrix_h, do_kpoints=do_kpoints)
254 IF (do_kpoints .AND. .NOT. real_space)
THEN
255 CALL write_matrix_kp_csr(mat=matrix_h, dft_section=dft_section, &
256 kpoints=kpoints, prefix=
"HCORE")
258 CALL write_matrix_csr(dft_section, mat=matrix_h, kpoints=kpoints, do_kpoints=do_kpoints, &
263 CALL timestop(handle)
279 SUBROUTINE write_matrix_csr(dft_section, mat, kpoints, prefix, do_kpoints)
284 CHARACTER(*),
INTENT(in) :: prefix
285 LOGICAL,
INTENT(IN) :: do_kpoints
287 CHARACTER(len=*),
PARAMETER :: routinen =
'write_matrix_csr'
289 CHARACTER(LEN=default_path_length) :: file_name, fileformat, subs_string
290 INTEGER :: handle, ic, ispin, ncell, nspin, &
292 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: index_to_cell
293 INTEGER,
ALLOCATABLE,
DIMENSION(:, :, :) :: cell_to_index
294 INTEGER,
DIMENSION(:, :),
POINTER :: i2c
295 INTEGER,
DIMENSION(:, :, :),
POINTER :: c2i
296 LOGICAL :: bin, do_symmetric, uptr
297 REAL(kind=
dp) :: thld
299 TYPE(dbcsr_csr_type) :: mat_csr
300 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_nosym
305 CALL timeset(routinen, handle)
310 subs_string =
"PRINT%"//prefix//
"_CSR_WRITE"
317 fileformat =
"UNFORMATTED"
319 fileformat =
"FORMATTED"
327 i2c => kpoints%index_to_cell
328 c2i => kpoints%cell_to_index
335 IF (do_symmetric)
THEN
336 CALL desymmetrize_rs_matrix(mat, mat_nosym, cell_to_index, index_to_cell, kpoints)
337 ncell =
SIZE(index_to_cell, 2)
339 ALLOCATE (cell_to_index(lbound(c2i, 1):ubound(c2i, 1), &
340 lbound(c2i, 2):ubound(c2i, 2), &
341 lbound(c2i, 3):ubound(c2i, 3)))
342 cell_to_index(lbound(c2i, 1):ubound(c2i, 1), &
343 lbound(c2i, 2):ubound(c2i, 2), &
344 lbound(c2i, 3):ubound(c2i, 3)) = c2i
346 ALLOCATE (index_to_cell(3, ncell))
347 index_to_cell(1:3, 1:ncell) = i2c
353 IF (output_unit > 0)
THEN
354 WRITE (output_unit,
"(/,A15,T15,I4,A)") prefix//
" CSR write| ", &
355 ncell,
" periodic images"
356 WRITE (output_unit,
"(T7,A,T17,A,T24,A,T31,A)")
"Number",
"X",
"Y",
"Z"
358 WRITE (output_unit,
"(T8,I3,T15,I3,T22,I3,T29,I3)") ic, index_to_cell(:, ic)
367 CALL dbcsr_copy(matrix_nosym, mat_nosym(ispin, ic)%matrix)
368 WRITE (file_name,
'(2(A,I0))') prefix//
"_SPIN_", ispin,
"_R_", ic
373 CALL dbcsr_copy(matrix_nosym, mat(ispin, ic)%matrix)
375 WRITE (file_name,
'(A,I0)') prefix//
"_SPIN_", ispin
379 mat_csr, dbcsr_csr_dbcsr_blkrow_dist)
383 extension=
".csr", middle_name=trim(file_name), &
384 file_status=
"REPLACE", file_form=fileformat)
385 CALL dbcsr_csr_write(mat_csr, unit_nr, upper_triangle=uptr, threshold=thld, binary=bin)
388 CALL dbcsr_csr_destroy(mat_csr)
395 DEALLOCATE (cell_to_index, index_to_cell)
396 IF (do_symmetric)
THEN
405 CALL timestop(handle)
407 END SUBROUTINE write_matrix_csr
419 SUBROUTINE write_matrix_kp_csr(mat, dft_section, kpoints, prefix)
424 CHARACTER(*),
INTENT(in) :: prefix
426 CHARACTER(len=*),
PARAMETER :: routinen =
'write_matrix_kp_csr'
428 CHARACTER(LEN=default_path_length) :: file_name, fileformat, subs_string
429 INTEGER :: handle, igroup, ik, ikp, ispin, kplocal, &
430 nkp_groups, output_unit, unit_nr
431 INTEGER,
DIMENSION(2) :: kp_range
432 INTEGER,
DIMENSION(:, :),
POINTER :: kp_dist
433 LOGICAL :: bin, uptr, use_real_wfn
434 REAL(kind=
dp) :: thld
435 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
437 TYPE(dbcsr_csr_type) :: mat_csr
439 TYPE(
dbcsr_type),
POINTER :: imatrix, imatrix_nosym, rmatrix, &
444 CALL timeset(routinen, handle)
449 subs_string =
"PRINT%"//prefix//
"_CSR_WRITE"
456 fileformat =
"UNFORMATTED"
458 fileformat =
"FORMATTED"
464 CALL get_kpoint_info(kpoints, xkp=xkp, use_real_wfn=use_real_wfn, kp_range=kp_range, &
465 nkp_groups=nkp_groups, kp_dist=kp_dist, sab_nl=sab_nl)
469 matrix_type=dbcsr_type_symmetric)
472 IF (.NOT. use_real_wfn)
THEN
474 ALLOCATE (rmatrix_nosym, imatrix, imatrix_nosym)
475 CALL dbcsr_create(rmatrix_nosym, template=mat(1, 1)%matrix, &
476 matrix_type=dbcsr_type_no_symmetry)
478 matrix_type=dbcsr_type_antisymmetric)
479 CALL dbcsr_create(imatrix_nosym, template=mat(1, 1)%matrix, &
480 matrix_type=dbcsr_type_no_symmetry)
486 kplocal = kp_range(2) - kp_range(1) + 1
488 DO ispin = 1,
SIZE(mat, 1)
489 DO igroup = 1, nkp_groups
491 ik = kp_dist(1, igroup) + ikp - 1
493 IF (use_real_wfn)
THEN
496 xkp=xkp(1:3, ik), cell_to_index=kpoints%cell_to_index, sab_nl=sab_nl)
505 CALL rskp_transform(rmatrix=rmatrix, cmatrix=imatrix, rsmat=mat, ispin=ispin, &
506 xkp=xkp(1:3, ik), cell_to_index=kpoints%cell_to_index, sab_nl=sab_nl)
514 imatrix=imatrix_nosym, &
516 dist_format=dbcsr_csr_dbcsr_blkrow_dist)
519 WRITE (file_name,
'(2(A,I0))') prefix//
"_SPIN_", ispin,
"_K_", ik
521 extension=
".csr", middle_name=trim(file_name), &
522 file_status=
"REPLACE", file_form=fileformat)
523 CALL dbcsr_csr_write(mat_csr, unit_nr, upper_triangle=uptr, threshold=thld, binary=bin)
527 CALL dbcsr_csr_destroy(mat_csr)
533 IF (.NOT. use_real_wfn)
THEN
537 DEALLOCATE (rmatrix_nosym, imatrix, imatrix_nosym)
539 CALL timestop(handle)
541 END SUBROUTINE write_matrix_kp_csr
552 SUBROUTINE desymmetrize_rs_matrix(mat, mat_nosym, cell_to_index, index_to_cell, kpoints)
556 INTENT(INOUT),
POINTER :: mat_nosym
557 INTEGER,
ALLOCATABLE,
DIMENSION(:, :, :), &
558 INTENT(OUT) :: cell_to_index
559 INTEGER,
ALLOCATABLE,
DIMENSION(:, :),
INTENT(OUT) :: index_to_cell
562 CHARACTER(len=*),
PARAMETER :: routinen =
'desymmetrize_rs_matrix'
564 INTEGER :: handle, iatom, ic, icn, icol, irow, &
565 ispin, jatom, ncell, nomirror, nspin, &
567 INTEGER,
DIMENSION(3) :: cell
568 INTEGER,
DIMENSION(:, :),
POINTER :: i2c
569 INTEGER,
DIMENSION(:, :, :),
POINTER :: c2i
570 LOGICAL :: found, lwtr
571 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
573 DIMENSION(:),
POINTER :: nl_iterator
577 CALL timeset(routinen, handle)
579 i2c => kpoints%index_to_cell
580 c2i => kpoints%cell_to_index
585 nx = max(abs(lbound(c2i, 1)), abs(ubound(c2i, 1)))
586 ny = max(abs(lbound(c2i, 2)), abs(ubound(c2i, 3)))
587 nz = max(abs(lbound(c2i, 3)), abs(ubound(c2i, 3)))
588 ALLOCATE (cell_to_index(-nx:nx, -ny:ny, -nz:nz))
589 cell_to_index(lbound(c2i, 1):ubound(c2i, 1), &
590 lbound(c2i, 2):ubound(c2i, 2), &
591 lbound(c2i, 3):ubound(c2i, 3)) = c2i
597 IF (cell_to_index(-cell(1), -cell(2), -cell(3)) == 0) &
598 nomirror = nomirror + 1
602 ALLOCATE (index_to_cell(3, ncell + nomirror))
603 index_to_cell(:, 1:ncell) = i2c
607 cell = index_to_cell(:, ic)
608 IF (cell_to_index(-cell(1), -cell(2), -cell(3)) == 0)
THEN
609 nomirror = nomirror + 1
610 index_to_cell(:, ncell + nomirror) = -cell
611 cell_to_index(-cell(1), -cell(2), -cell(3)) = ncell + nomirror
614 ncell = ncell + nomirror
622 ALLOCATE (mat_nosym(ispin, ic)%matrix)
624 template=mat(1, 1)%matrix, &
625 matrix_type=dbcsr_type_no_symmetry)
627 sab_nl, desymmetrize=.true.)
628 CALL dbcsr_set(mat_nosym(ispin, ic)%matrix, 0.0_dp)
638 ic = cell_to_index(cell(1), cell(2), cell(3))
639 icn = cell_to_index(-cell(1), -cell(2), -cell(3))
646 IF (iatom > jatom)
THEN
653 row=irow, col=icol, block=block, found=found)
660 row=iatom, col=jatom, block=transpose(block))
662 row=jatom, col=iatom, block=block)
665 row=iatom, col=jatom, block=block)
667 row=jatom, col=iatom, block=transpose(block))
679 CALL timestop(handle)
681 END SUBROUTINE desymmetrize_rs_matrix
logical function, public dbcsr_has_symmetry(matrix)
...
subroutine, public dbcsr_convert_dbcsr_to_csr(dbcsr_mat, csr_mat)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_csr_create_and_convert_complex(rmatrix, imatrix, csr_mat, dist_format)
Combines csr_create_from_dbcsr and convert_dbcsr_to_csr to produce a complex CSR matrix.
subroutine, public dbcsr_csr_create_from_dbcsr(dbcsr_mat, csr_mat, dist_format, csr_sparsity, numnodes)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_put_block(matrix, row, col, block, summation)
...
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.
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_path_length
Routines needed for kpoint calculation.
subroutine, public rskp_transform(rmatrix, cmatrix, rsmat, ispin, xkp, cell_to_index, sab_nl, is_complex, rs_sign)
Transformation of real space matrices to a kpoint.
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym)
Retrieve information from a kpoint environment.
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, mimic, 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, sab_cneo, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Define the neighbor list data types and the corresponding functionality.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
subroutine, public get_neighbor_list_set_p(neighbor_list_sets, nlist, symmetric)
Return the components of the first neighbor list set.
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
Functions to print the KS and S matrix in the CSR format to file.
subroutine, public write_s_matrix_csr(qs_env, input)
writing the overlap matrix in csr format into a file
subroutine, public write_ks_matrix_csr(qs_env, input)
writing the KS matrix in csr format into a file
subroutine, public write_p_matrix_csr(qs_env, input)
writing the density matrix in csr format into a file
subroutine, public write_hcore_matrix_csr(qs_env, input)
writing the core Hamiltonian matrix in csr format into a file
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains information about kpoints.
keeps the density in various representations, keeping track of which ones are valid.