(git:3f0d10b)
Loading...
Searching...
No Matches
cc4s_export.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Molecular and Gamma-point periodic CC4S export from restricted RI-HF.
10!> RI_FLAVOR MO stores a weighted AO-pair triangle. The full vertex is
11!> C^T (T + T^T) C, dressed with the symmetric Coulomb inverse square root.
12!> The SCF tensors and orbitals are read only. MO transformations are distributed
13!> and bounded output pieces are gathered to the writing rank.
14! **************************************************************************************************
16 USE iso_fortran_env, ONLY: file_storage_size
17 USE cell_types, ONLY: cell_type,&
22 USE cp_dbcsr_api, ONLY: dbcsr_p_type,&
31 USE cp_fm_types, ONLY: cp_fm_create,&
38 USE cp_output_handling, ONLY: cp_p_file,&
44 USE dbt_api, ONLY: &
45 dbt_contract, dbt_copy, dbt_copy_matrix_to_tensor, dbt_create, dbt_destroy, dbt_get_block, &
46 dbt_get_info, dbt_iterator_blocks_left, dbt_iterator_next_block, dbt_iterator_start, &
47 dbt_iterator_stop, dbt_iterator_type, dbt_nblks_total, dbt_pgrid_create, &
48 dbt_pgrid_destroy, dbt_pgrid_type, dbt_type
49 USE hfx_types, ONLY: hfx_type
50 USE ieee_arithmetic, ONLY: ieee_is_finite
53 sic_none,&
55 USE input_cp2k_hfx, ONLY: ri_mo
60 USE kinds, ONLY: default_path_length,&
61 dp,&
62 dp_size,&
63 int_8
64 USE machine, ONLY: m_walltime
68 USE qs_mo_types, ONLY: get_mo_set,&
74#include "./base/base_uses.f90"
75
76 IMPLICIT NONE
77 PRIVATE
78 PUBLIC :: write_cc4s
79 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cc4s_export'
80 ! MPI statistics count bytes in default integers. DBT/DBM also use default-integer
81 ! counts and grow buffers by up to 30%; leave a factor of two for data storage.
82 INTEGER(int_8), PARAMETER :: output_count_limit = int(huge(0), int_8)/dp_size
83 INTEGER(int_8), PARAMETER :: backend_data_limit = output_count_limit/2
84 ! Up to four 64-bit indices per block, with allocation/communication headroom.
85 INTEGER(int_8), PARAMETER :: backend_block_limit = int(huge(0), int_8)/64
86 REAL(dp), PARAMETER :: elements_per_mib = 1024.0_dp**2/real(dp_size, dp)
87
88CONTAINS
89
90! **************************************************************************************************
91!> \brief Check the requested export, canonicalize private Fock/overlap copies and write tensors.
92!> \param qs_env QS environment after SCF
93!> \param converged Whether the SCF actually converged (including the outer SCF)
94! **************************************************************************************************
95 SUBROUTINE write_cc4s(qs_env, converged)
96 TYPE(qs_environment_type), POINTER :: qs_env
97 LOGICAL, INTENT(IN) :: converged
98
99 CHARACTER(len=*), PARAMETER :: routinen = 'write_cc4s'
100 REAL(dp), PARAMETER :: hf_fraction_tolerance = 1.0e-14_dp
101
102 CHARACTER(len=8) :: method
103 CHARACTER(len=default_path_length) :: filename
104 INTEGER :: frozen, functional, handle, homo, max_iter, method_id, nao, nmo, nri, nstored, &
105 output_unit, poisson_periodic, stage_handle
106 INTEGER(KIND=int_8) :: buffer_elements, total_elements
107 INTEGER, DIMENSION(2) :: dims2
108 INTEGER, DIMENSION(3) :: dims3
109 LOGICAL :: admm_section_present, do_kpoints, &
110 enabled, periodic
111 REAL(dp) :: amp_conv, cutoff_radius, energy_conv, export_start, fermi_energy, max_cutoff, &
112 max_memory_mb, memory_mb, output_buffer_mib, vertex_norm, write_start
113 REAL(dp), ALLOCATABLE :: eigenvalues(:)
114 REAL(dp), DIMENSION(5) :: elapsed
115 TYPE(cell_type), POINTER :: cell
116 TYPE(cp_fm_struct_type), POINTER :: fm_struct
117 TYPE(cp_fm_type) :: fm_active, fm_coeff, fm_fock, &
118 fm_overlap, fm_work
119 TYPE(cp_fm_type), POINTER :: mo_coeff
120 TYPE(cp_logger_type), POINTER :: logger
121 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s
122 TYPE(dbcsr_type) :: coefficient_matrix
123 TYPE(dbt_type) :: coefficients
124 TYPE(dft_control_type), POINTER :: dft_control
125 TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data
126 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
127 TYPE(mp_para_env_type), POINTER :: para_env
128 TYPE(scf_control_type), POINTER :: scf_control
129 TYPE(section_vals_type), POINTER :: admm_section, input, print_section
130
131 logger => cp_get_default_logger()
132 CALL get_qs_env(qs_env, input=input)
133 print_section => section_vals_get_subs_vals(input, "DFT%PRINT%CC4S")
134 enabled = cp_printkey_is_on(logger%iter_info, print_section)
135 IF (.NOT. enabled) RETURN
136 IF (.NOT. qs_env%single_point_run) THEN
137 CALL cp_abort(__location__, "CC4S: export requires a single-point RUN_TYPE ENERGY or ENERGY_FORCE")
138 END IF
139 IF (.NOT. btest(cp_print_key_should_output(logger%iter_info, print_section), cp_p_file)) RETURN
140 CALL section_vals_val_get(print_section, "FILENAME", c_val=filename)
141 IF (filename(1:1) == '=' .OR. filename == '__STD_OUT__') THEN
142 CALL cp_abort(__location__, &
143 "CC4S: FILENAME must be a file prefix, not an exact name (=name) or __STD_OUT__")
144 END IF
145 CALL timeset(routinen, handle)
146 export_start = m_walltime()
147 elapsed = 0.0_dp
148 output_unit = cp_logger_get_default_io_unit(logger)
149
150 CALL section_vals_val_get(print_section, "METHOD", i_val=method_id)
151 CALL section_vals_val_get(print_section, "N_FROZEN_CORE", i_val=frozen)
152 CALL section_vals_val_get(print_section, "MAX_ITER", i_val=max_iter)
153 CALL section_vals_val_get(print_section, "ENERGY_CONVERGENCE", r_val=energy_conv)
154 CALL section_vals_val_get(print_section, "AMPLITUDES_CONVERGENCE", r_val=amp_conv)
155 CALL section_vals_val_get(print_section, "MAX_MEMORY", r_val=max_memory_mb)
156 CALL section_vals_val_get(print_section, "OUTPUT_BUFFER_SIZE", r_val=output_buffer_mib)
157 IF (.NOT. ieee_is_finite(output_buffer_mib)) THEN
158 cpabort("CC4S: OUTPUT_BUFFER_SIZE must be finite")
159 END IF
160 IF (output_buffer_mib < 1.0_dp/elements_per_mib .OR. &
161 output_buffer_mib > real(huge(1), dp)/elements_per_mib) THEN
162 CALL cp_abort(__location__, &
163 "CC4S: OUTPUT_BUFFER_SIZE must hold at least one Real64 value and fit the MPI integer count")
164 END IF
165 buffer_elements = floor(output_buffer_mib*elements_per_mib, kind=int_8)
166 SELECT CASE (method_id)
167 CASE (1)
168 method = 'MP2'
169 CASE (2)
170 method = 'CCSD'
171 CASE (3)
172 method = 'CCSD_T'
173 CASE DEFAULT
174 cpabort("CC4S: unsupported method")
175 END SELECT
176 IF (.NOT. ieee_is_finite(max_memory_mb)) cpabort("CC4S: MAX_MEMORY must be finite")
177 IF (max_iter < 1 .OR. energy_conv <= 0.0_dp .OR. amp_conv <= 0.0_dp .OR. max_memory_mb <= 0.0_dp) THEN
178 CALL cp_abort(__location__, &
179 "CC4S: iteration, convergence and memory limits must be positive")
180 END IF
181 CALL get_qs_env(qs_env, x_data=x_data, mos=mos, para_env=para_env, dft_control=dft_control, &
182 cell=cell, do_kpoints=do_kpoints, scf_control=scf_control, &
183 matrix_ks=matrix_ks, matrix_s=matrix_s)
184 IF (dft_control%qs_control%cdft) THEN
185 cpabort("CC4S: constrained DFT is unsupported")
186 END IF
187 IF (.NOT. converged) THEN
188 cpabort("CC4S: export requires a converged SCF")
189 END IF
190 CALL section_vals_val_get(input, "DFT%POISSON%PERIODIC", i_val=poisson_periodic)
191 IF (do_kpoints) THEN
192 cpabort("CC4S: k-point sampling is unsupported")
193 END IF
194 periodic = all(cell%perd == 1) .AND. poisson_periodic == use_perd_xyz
195 IF (.NOT. periodic .AND. &
196 (any(cell%perd /= 0) .OR. poisson_periodic /= use_perd_none)) THEN
197 CALL cp_abort(__location__, &
198 "CC4S: CELL and POISSON must both use PERIODIC NONE or both PERIODIC XYZ")
199 END IF
200 IF (periodic .AND. dft_control%charge /= 0) THEN
201 cpabort("CC4S: periodic cells must be neutral")
202 END IF
203 IF (dft_control%nspins /= 1 .OR. dft_control%uks .OR. dft_control%roks .OR. dft_control%smear) THEN
204 CALL cp_abort(__location__, &
205 "CC4S: a restricted closed-shell reference without smearing is required")
206 END IF
207 admm_section => section_vals_get_subs_vals(input, "DFT%AUXILIARY_DENSITY_MATRIX_METHOD")
208 CALL section_vals_get(admm_section, explicit=admm_section_present)
209 IF (admm_section_present) THEN
210 cpabort("CC4S: AUXILIARY_DENSITY_MATRIX_METHOD is unsupported")
211 END IF
212 IF (dft_control%dft_plus_u .OR. dft_control%sic_method_id /= sic_none) THEN
213 cpabort("CC4S: DFT+U and self-interaction corrections are unsupported")
214 END IF
215 CALL section_vals_val_get(input, "DFT%XC%XC_FUNCTIONAL%_SECTION_PARAMETERS_", i_val=functional)
216 IF (functional /= xc_none) THEN
217 CALL cp_abort(__location__, &
218 "CC4S: canonical HF orbitals required; use XC_FUNCTIONAL NONE")
219 END IF
220 IF (.NOT. ASSOCIATED(x_data)) THEN
221 cpabort("CC4S: enable HF with RI_FLAVOR MO")
222 END IF
223 IF (SIZE(x_data, 1) /= 1) THEN
224 CALL cp_abort(__location__, &
225 "CC4S: exactly one HF section is allowed")
226 END IF
227 IF (abs(x_data(1, 1)%general_parameter%fraction - 1.0_dp) > hf_fraction_tolerance) THEN
228 cpabort("CC4S: HF FRACTION must be 1")
229 END IF
230 IF (.NOT. x_data(1, 1)%do_hfx_ri) THEN
231 cpabort("CC4S: enable HF/RI with RI_FLAVOR MO")
232 END IF
233 IF (.NOT. ASSOCIATED(x_data(1, 1)%ri_data)) THEN
234 cpabort("CC4S: RI-HFX data are unavailable")
235 END IF
236 IF (x_data(1, 1)%ri_data%flavor /= ri_mo) THEN
237 cpabort("CC4S: HF/RI requires RI_FLAVOR MO")
238 END IF
239 cutoff_radius = 0.0_dp
240 IF (periodic) THEN
241 IF (.NOT. x_data(1, 1)%ri_data%same_op .OR. &
242 x_data(1, 1)%ri_data%hfx_pot%potential_type /= do_potential_truncated) THEN
243 CALL cp_abort(__location__, &
244 "CC4S: periodic export requires TRUNCATED HF interaction and the same RI metric; use RI_METRIC HFX")
245 END IF
246 cutoff_radius = x_data(1, 1)%ri_data%hfx_pot%cutoff_radius
247 max_cutoff = 0.5_dp*min(plane_distance(1, 0, 0, cell), &
248 plane_distance(0, 1, 0, cell), plane_distance(0, 0, 1, cell))
249 IF (cutoff_radius <= 0.0_dp .OR. cutoff_radius >= max_cutoff) THEN
250 CALL cp_abort(__location__, &
251 "CC4S: positive HF CUTOFF_RADIUS must be smaller than half the minimal cell plane spacing")
252 END IF
253 ELSE
254 IF (.NOT. x_data(1, 1)%ri_data%same_op .OR. &
255 x_data(1, 1)%ri_data%hfx_pot%potential_type /= do_potential_coulomb) THEN
256 CALL cp_abort(__location__, &
257 "CC4S: molecular HF interaction and RI metric must both be COULOMB")
258 END IF
259 END IF
260
261 CALL get_mo_set(mos(1), mo_coeff=mo_coeff, homo=homo, nmo=nstored, nao=nao)
262 IF (homo < 1 .OR. homo > nstored) THEN
263 cpabort("CC4S: no occupied orbitals")
264 END IF
265 IF (.NOT. has_uniform_occupation(mos(1), first_mo=1, last_mo=homo, occupation=2.0_dp) .OR. &
266 .NOT. has_uniform_occupation(mos(1), first_mo=homo + 1, last_mo=nstored, occupation=0.0_dp)) THEN
267 CALL cp_abort(__location__, &
268 "CC4S: occupations must be 2 below the HOMO and 0 above")
269 END IF
270 IF (frozen < 0 .OR. frozen >= homo) THEN
271 CALL cp_abort(__location__, &
272 "CC4S: N_FROZEN_CORE must leave at least one occupied orbital")
273 END IF
274 CALL dbt_get_info(x_data(1, 1)%ri_data%t_3c_int_ctr_1(1, 1), nfull_total=dims3)
275 nri = dims3(2)
276 cpassert(dims3(1) == nao .AND. dims3(3) == nao .AND. nri > 0)
277 ! Check quadratic storage before canonicalization; the full AO vertex is never gathered.
278 IF (limited_product([int(nao, int_8), int(nao, int_8)], backend_data_limit) > backend_data_limit) THEN
279 cpabort("CC4S: canonical matrices exceed backend count limits")
280 END IF
281 IF (limited_product([int(nri, int_8), int(nri, int_8)], backend_data_limit) > backend_data_limit) THEN
282 cpabort("CC4S: RI metric exceeds backend count limits")
283 END IF
284 ! Canonicalization precedes batch selection; reject an insufficient budget before allocation.
285 memory_mb = real(dp_size, dp)*6.0_dp*real(nao, dp)**2/1.0e6_dp
286 IF (memory_mb > max_memory_mb) THEN
287 cpabort("CC4S: canonicalization exceeds MAX_MEMORY [MB]")
288 END IF
289 elapsed = 0.0_dp
290
291 ! Always diagonalize private copies, including for OT or a complete stored MO set.
292 ! Drop overlap null modes using the same cutoff as SCF; do not export placeholder energies.
293 NULLIFY (fm_struct)
294 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, &
295 template_fmstruct=mo_coeff%matrix_struct)
296 CALL cp_fm_create(fm_fock, fm_struct)
297 CALL cp_fm_create(fm_overlap, fm_struct)
298 CALL cp_fm_create(fm_coeff, fm_struct)
299 CALL cp_fm_create(fm_work, fm_struct)
300 CALL cp_fm_struct_release(fm_struct)
301 CALL copy_dbcsr_to_fm(matrix_ks(1)%matrix, fm_fock)
302 CALL copy_dbcsr_to_fm(matrix_s(1)%matrix, fm_overlap)
303 ALLOCATE (eigenvalues(nao))
304 CALL cp_fm_geeig_canon(fm_fock, fm_overlap, fm_coeff, eigenvalues, fm_work, &
305 scf_control%eps_eigval, nmo_retained=nmo)
306 IF (nmo <= homo) THEN
307 CALL cp_abort(__location__, &
308 "CC4S: no virtual orbitals after removing overlap null modes")
309 END IF
310 IF (eigenvalues(homo + 1) <= eigenvalues(homo)) THEN
311 CALL cp_abort(__location__, &
312 "CC4S: a positive HOMO-LUMO gap is required")
313 END IF
314 fermi_energy = 0.5_dp*(eigenvalues(homo) + eigenvalues(homo + 1))
315 nmo = nmo - frozen
316 total_elements = vertex_size(nri, nmo)
317 buffer_elements = min(buffer_elements, total_elements, output_count_limit)
318 ! The initial coefficient copy can have a different block partition. Bound its
319 ! metadata by the number of elements before entering DBCSR/DBT conversion.
320 IF (limited_product([int(nao, int_8), int(nmo, int_8)], backend_block_limit) > backend_block_limit) THEN
321 cpabort("CC4S: coefficients exceed backend count limits")
322 END IF
323 IF (output_unit > 0) THEN
324 WRITE (output_unit, '(/,T3,A)') "CC4S| Reference export"
325 WRITE (output_unit, '(T3,A,T60,A21)') "CC4S| Reference:", "Restricted RI-HF"
326 IF (periodic) THEN
327 WRITE (output_unit, '(T3,A,T60,A21)') "CC4S| Boundary conditions:", "Periodic Gamma"
328 WRITE (output_unit, '(T3,A,T60,A21)') "CC4S| Coulomb interaction:", "TRUNCATED"
329 WRITE (output_unit, '(T3,A,T69,F12.6)') "CC4S| Coulomb cutoff radius [bohr]:", cutoff_radius
330 ELSE
331 WRITE (output_unit, '(T3,A,T60,A21)') "CC4S| Boundary conditions:", "Isolated"
332 WRITE (output_unit, '(T3,A,T60,A21)') "CC4S| Coulomb interaction:", "COULOMB"
333 END IF
334 WRITE (output_unit, '(T3,A)') "CC4S|"
335 WRITE (output_unit, '(T3,A,T69,I12)') "CC4S| Number of auxiliary basis functions:", nri
336 WRITE (output_unit, '(T3,A,T69,I12)') "CC4S| Number of exported orbitals:", nmo
337 WRITE (output_unit, '(T3,A,T69,I12)') "CC4S| Number of exported occupied orbitals:", homo - frozen
338 WRITE (output_unit, '(T3,A,T69,I12)') "CC4S| Number of exported virtual orbitals:", nmo - homo + frozen
339 WRITE (output_unit, '(T3,A,T69,I12)') "CC4S| Number of frozen occupied orbitals:", frozen
340 WRITE (output_unit, '(T3,A,T63,F18.6)') &
341 "CC4S| Expected Coulomb vertex size [MiB]:", real(total_elements, dp)/elements_per_mib
342 WRITE (output_unit, '(T3,A)') "CC4S|"
343 WRITE (output_unit, '(T3,A,T69,F12.6)') &
344 "CC4S| Actual output buffer size per MPI rank [MiB]:", real(buffer_elements, dp)/elements_per_mib
345 END IF
346 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nmo, template_fmstruct=mo_coeff%matrix_struct)
347 CALL cp_fm_create(fm_active, fm_struct, name="CC4S active orbitals")
348 CALL cp_fm_struct_release(fm_struct)
349 CALL cp_fm_to_fm(fm_coeff, fm_active, ncol=nmo, source_start=frozen + 1)
350 CALL cp_fm_to_dbcsr_row_template(coefficient_matrix, fm_active, matrix_s(1)%matrix)
351 CALL dbt_create(coefficient_matrix, coefficients, name="CC4S coefficients")
352 CALL dbt_copy_matrix_to_tensor(coefficient_matrix, coefficients)
353 CALL dbcsr_release(coefficient_matrix)
354 CALL cp_fm_release(fm_active)
355 CALL cp_fm_release(fm_fock)
356 CALL cp_fm_release(fm_overlap)
357 CALL cp_fm_release(fm_coeff)
358 CALL cp_fm_release(fm_work)
359
360 CALL dbt_get_info(x_data(1, 1)%ri_data%t_2c_int(1, 1), nfull_total=dims2)
361 cpassert(all(dims2 == nri))
362 ! Transform and export one orbital range at a time; never retain the complete vertex.
363 CALL export_vertex_batches(x_data(1, 1)%ri_data%t_3c_int_ctr_1(1, 1), &
364 x_data(1, 1)%ri_data%t_2c_int(1, 1), coefficients, para_env, &
365 logger, print_section, nmo, max_memory_mb, buffer_elements, &
366 periodic, cutoff_radius, cell%hmat, output_unit, vertex_norm, elapsed, &
367 homo - frozen, eigenvalues(frozen + 1:frozen + nmo), fermi_energy)
368 CALL dbt_destroy(coefficients)
369 CALL timeset("cc4s_write_files", stage_handle)
370 write_start = m_walltime()
371 IF (para_env%is_source()) THEN
372 CALL write_cc4s_in(logger, print_section, method, homo - frozen, max_iter, energy_conv, amp_conv)
373 END IF
374 elapsed(5) = elapsed(5) + m_walltime() - write_start
375 CALL timestop(stage_handle)
376 IF (para_env%is_source()) THEN
377 IF (output_unit > 0) THEN
378 WRITE (output_unit, '(/,T3,A)') "CC4S| Export completed"
379 WRITE (output_unit, '(T3,A,T56,ES25.16)') "CC4S| Vertex norm squared [Ha]:", vertex_norm
380 WRITE (output_unit, '(T3,A,T56,ES25.16)') &
381 "CC4S| Sum of exported orbital energies [Ha]:", sum(eigenvalues(frozen + 1:frozen + nmo))
382 WRITE (output_unit, '(T3,A)') "CC4S|"
383 filename = cp_print_key_generate_filename(logger, print_section, 'EigenEnergies', '.yaml', .false.)
384 WRITE (output_unit, '(T3,A,T41,A)') "CC4S| Orbital energies metadata:", &
385 adjustr(filename(:max(40, len_trim(filename))))
386 filename = cp_print_key_generate_filename(logger, print_section, 'EigenEnergies', '.elements', .false.)
387 WRITE (output_unit, '(T3,A,T41,A)') "CC4S| Orbital energies data:", &
388 adjustr(filename(:max(40, len_trim(filename))))
389 filename = cp_print_key_generate_filename(logger, print_section, 'CoulombVertex', '.yaml', .false.)
390 WRITE (output_unit, '(T3,A,T41,A)') "CC4S| Coulomb vertex metadata:", &
391 adjustr(filename(:max(40, len_trim(filename))))
392 filename = cp_print_key_generate_filename(logger, print_section, 'CoulombVertex', '.elements', .false.)
393 WRITE (output_unit, '(T3,A,T41,A)') "CC4S| Coulomb vertex file:", &
394 adjustr(filename(:max(40, len_trim(filename))))
395 CALL print_vertex_file_size(output_unit, filename)
396 END IF
397 END IF
398 DEALLOCATE (eigenvalues)
399 CALL para_env%sync()
400 elapsed(1) = m_walltime() - export_start
401 ! Report the longest rank-local elapsed times; only the source rank writes files.
402 CALL para_env%max(elapsed)
403 IF (output_unit > 0) THEN
404 WRITE (output_unit, '(T3,A,T69,F12.3)') "CC4S| Total export time [s]:", elapsed(1)
405 WRITE (output_unit, '(T3,A,T69,F12.3)') "CC4S| Orbital transformation time [s]:", elapsed(2)
406 WRITE (output_unit, '(T3,A,T69,F12.3)') "CC4S| Metric contraction time [s]:", elapsed(3)
407 WRITE (output_unit, '(T3,A,T69,F12.3)') "CC4S| Output gathering time [s]:", elapsed(4)
408 WRITE (output_unit, '(T3,A,T69,F12.3)') "CC4S| File writing time [s]:", elapsed(5)
409 END IF
410 IF (para_env%is_source()) THEN
411 IF (output_unit > 0) THEN
412 WRITE (output_unit, '(/,T3,A)') "CC4S| Generated CC4S input"
413 filename = cp_print_key_generate_filename(logger, print_section, extension='.in', my_local=.false.)
414 WRITE (output_unit, '(T3,A,T41,A)') "CC4S| Generated input file:", &
415 adjustr(filename(:max(40, len_trim(filename))))
416 IF (method == 'CCSD_T') THEN
417 WRITE (output_unit, '(T3,A,T73,A8)') "CC4S| Requested method:", 'CCSD(T)'
418 ELSE
419 WRITE (output_unit, '(T3,A,T73,A8)') "CC4S| Requested method:", trim(method)
420 END IF
421 IF (method /= 'MP2') THEN
422 WRITE (output_unit, '(T3,A,T69,I12)') "CC4S| Maximum CCSD iterations:", max_iter
423 WRITE (output_unit, '(T3,A,T73,ES8.1)') "CC4S| CCSD energy convergence [Ha]:", energy_conv
424 WRITE (output_unit, '(T3,A,T73,ES8.1)') "CC4S| CCSD amplitudes convergence:", amp_conv
425 END IF
426 END IF
427 END IF
428 CALL timestop(handle)
429 END SUBROUTINE write_cc4s
430
431! **************************************************************************************************
432!> \brief Report the actual size of the closed binary vertex file, in MiB, on the writing rank.
433!> \param output_unit Log output unit
434!> \param filename Export filename generated by the print key
435! **************************************************************************************************
436 SUBROUTINE print_vertex_file_size(output_unit, filename)
437 INTEGER, INTENT(IN) :: output_unit
438 CHARACTER(len=*), INTENT(IN) :: filename
439
440 INTEGER :: io_status
441 INTEGER(int_8) :: file_size
442 REAL(dp) :: size_mib
443
444 file_size = -1_int_8
445 size_mib = -1.0_dp
446 INQUIRE (file=trim(filename), size=file_size, iostat=io_status)
447 IF (io_status == 0) THEN
448 IF (file_size >= 0_int_8) THEN
449 size_mib = real(file_size, dp)*real(file_storage_size, dp)/(8.0_dp*1024.0_dp**2)
450 END IF
451 END IF
452 IF (size_mib >= 0.0_dp) THEN
453 WRITE (output_unit, '(T3,A,T63,F18.6)') "CC4S| Written Coulomb vertex size [MiB]:", size_mib
454 ELSE
455 WRITE (output_unit, '(T3,A,T63,A18)') "CC4S| Written Coulomb vertex size [MiB]:", "unavailable"
456 END IF
457 END SUBROUTINE print_vertex_file_size
458
459! **************************************************************************************************
460!> \brief Transform and stream orbital batches, using private auxiliary slices of the SCF triangle.
461!> \param integrals Live SCF tensor, ordered (AO, RI, AO)
462!> \param metric Live SCF inverse square root of the RI metric
463!> \param coefficients Distributed active canonical orbitals
464!> \param para_env MPI parallel environment
465!> \param logger Logger for output selection and naming
466!> \param print_section CC4S print key
467!> \param nmo Number of active orbitals
468!> \param max_memory_mb Estimated additional workspace limit per rank, in decimal MB
469!> \param buffer_elements Maximum number of Real64 values in each output piece
470!> \param periodic Whether the cell is three-dimensionally periodic at Gamma
471!> \param cutoff_radius Truncated Coulomb cutoff in bohr
472!> \param hmat Cell vectors in bohr
473!> \param output_unit Log output unit
474!> \param vertex_norm Squared vertex norm on the writing rank
475!> \param elapsed Accumulated wall times: total, transformation, metric, gathering, writing
476!> \param homo Number of active occupied orbitals
477!> \param eigenvalues Active canonical orbital energies
478!> \param fermi_energy Energy inside the HOMO-LUMO gap
479! **************************************************************************************************
480 SUBROUTINE export_vertex_batches(integrals, metric, coefficients, para_env, logger, print_section, &
481 nmo, max_memory_mb, buffer_elements, periodic, cutoff_radius, hmat, &
482 output_unit, vertex_norm, elapsed, homo, eigenvalues, fermi_energy)
483 TYPE(dbt_type), INTENT(INOUT) :: integrals, metric, coefficients
484 TYPE(mp_para_env_type), POINTER :: para_env
485 TYPE(cp_logger_type), POINTER :: logger
486 TYPE(section_vals_type), POINTER :: print_section
487 INTEGER, INTENT(IN) :: nmo
488 REAL(dp), INTENT(IN) :: max_memory_mb
489 INTEGER(KIND=int_8), INTENT(IN) :: buffer_elements
490 LOGICAL, INTENT(IN) :: periodic
491 REAL(dp), INTENT(IN) :: cutoff_radius, hmat(3, 3)
492 INTEGER, INTENT(IN) :: output_unit
493 REAL(dp), INTENT(OUT) :: vertex_norm
494 REAL(dp), INTENT(INOUT) :: elapsed(5)
495 INTEGER, INTENT(IN) :: homo
496 REAL(dp), INTENT(IN) :: eigenvalues(nmo), fermi_energy
497
498 INTEGER :: block_width, bounds2(2, 2), bounds3(2, 3), handle, im, ir, iunit, mb, &
499 metric_blocks(2), mfirst, mlast, nao, nri, pdims(3), pdims2(2), rb, rfirst, rlast
500 INTEGER, ALLOCATABLE :: ao(:), d1(:), d2(:), d3(:), mo(:), ri(:)
501 REAL(dp) :: memory_mb, pressure, start, trial_m, &
502 trial_r
503 REAL(dp), ALLOCATABLE :: values(:)
504 TYPE(dbt_pgrid_type) :: grid, grid2
505 TYPE(dbt_type) :: ao_triangle, coeff, coeff_batch, gamma, &
506 half, metric_copy, triangle
507
508 ALLOCATE (ao(dbt_nblks_total(integrals, 1)), ri(dbt_nblks_total(integrals, 2)))
509 CALL dbt_get_info(integrals, blk_size_1=ao, blk_size_2=ri)
510 nao = sum(ao)
511 nri = sum(ri)
512 ! Smaller orbital blocks may be necessary for one output stripe to fit the backend.
513 block_width = 16
514 DO WHILE (limited_product([int(nri, int_8), int(nmo, int_8), int(block_width, int_8)], &
515 backend_data_limit) > backend_data_limit .AND. block_width > 1)
516 block_width = block_width/2
517 END DO
518 ALLOCATE (mo(1 + (nmo - 1)/block_width))
519 mo = block_width
520 mo(SIZE(mo)) = nmo - (SIZE(mo) - 1)*block_width
521 CALL dbt_get_info(metric, nblks_total=metric_blocks)
522 ! Reblocking can refine both original and requested auxiliary partitions.
523 IF (limited_product([int(para_env%num_pe, int_8), int(metric_blocks(1), int_8) + SIZE(ri, kind=int_8), &
524 int(metric_blocks(2), int_8) + SIZE(ri, kind=int_8)], &
525 backend_block_limit) > backend_block_limit) THEN
526 cpabort("CC4S: RI metric metadata exceeds backend limits")
527 END IF
528 mb = SIZE(mo)
529 rb = SIZE(ri)
530 ! Bound the busiest rank without assuming balanced distribution. Include private operands,
531 ! simultaneously live results, and conservative redistribution/communication copies.
532 pressure = batch_pressure(ao, ri, mo, mb, rb, para_env%num_pe, buffer_elements, max_memory_mb)
533 DO WHILE (pressure > 1.0_dp .AND. (mb > 1 .OR. rb > 1))
534 trial_m = huge(0.0_dp)
535 trial_r = huge(0.0_dp)
536 IF (mb > 1) trial_m = batch_pressure(ao, ri, mo, mb/2 + modulo(mb, 2), rb, para_env%num_pe, &
537 buffer_elements, max_memory_mb)
538 IF (rb > 1) trial_r = batch_pressure(ao, ri, mo, mb, rb/2 + modulo(rb, 2), para_env%num_pe, &
539 buffer_elements, max_memory_mb)
540 IF (trial_m <= trial_r) THEN
541 mb = mb/2 + modulo(mb, 2)
542 ELSE
543 rb = rb/2 + modulo(rb, 2)
544 END IF
545 pressure = min(trial_m, trial_r)
546 END DO
547 memory_mb = batch_workspace(nao, nri, nmo, mo, ri, mb, rb, buffer_elements)
548 IF (.NOT. batch_counts_fit(ao, ri, mo, mb, rb, para_env%num_pe)) THEN
549 cpabort("CC4S: minimum batch exceeds backend count limits")
550 END IF
551 IF (output_unit > 0) THEN
552 WRITE (output_unit, '(T3,A,T69,F12.3)') &
553 "CC4S| Estimated export workspace per MPI rank [MB]:", memory_mb
554 WRITE (output_unit, '(T3,A,T69,F12.3)') &
555 "CC4S| Export workspace budget per MPI rank [MB]:", max_memory_mb
556 END IF
557 IF (memory_mb > max_memory_mb) THEN
558 CALL cp_abort(__location__, &
559 "CC4S: minimum transformation batch exceeds MAX_MEMORY; increase the limit or reduce OUTPUT_BUFFER_SIZE")
560 END IF
561 IF (output_unit > 0) THEN
562 WRITE (output_unit, '(T3,A,T69,I12)') "CC4S| Maximum orbitals per transformation batch:", batch_width(mo, mb)
563 WRITE (output_unit, '(T3,A,T69,I12)') "CC4S| Maximum auxiliary functions per batch:", batch_width(ri, rb)
564 WRITE (output_unit, '(T3,A,T69,I12)') "CC4S| Number of orbital batches:", 1 + (SIZE(mo) - 1)/mb
565 WRITE (output_unit, '(T3,A,T69,I12)') "CC4S| Number of auxiliary batches:", 1 + (SIZE(ri) - 1)/rb
566 END IF
567 pdims = 0
568 pdims2 = 0
569 CALL dbt_pgrid_create(para_env, pdims, grid, tensor_dims=[SIZE(mo), SIZE(ri), SIZE(ao)])
570 CALL dbt_pgrid_create(para_env, pdims2, grid2, tensor_dims=[SIZE(ao), SIZE(mo)])
571 CALL create_2c_tensor(coeff, d1, d2, grid2, ao, mo, name="CC4S active coefficients")
572 DEALLOCATE (d1, d2)
573 CALL dbt_copy(coefficients, coeff)
574 ! The metric and integrals can have different auxiliary block partitions.
575 CALL create_2c_tensor(metric_copy, d1, d2, grid2, ri, ri, name="CC4S inverse metric")
576 DEALLOCATE (d1, d2)
577 CALL dbt_copy(metric, metric_copy)
578 ALLOCATE (values(buffer_elements))
579 vertex_norm = 0.0_dp
580 iunit = -1
581 start = m_walltime()
582 IF (para_env%is_source()) THEN
583 CALL write_eigen_energies_files(logger, print_section, nmo, homo, eigenvalues, fermi_energy)
584 CALL open_coulomb_vertex_file(logger, print_section, nri, nmo, periodic, cutoff_radius, hmat, iunit)
585 END IF
586 elapsed(5) = elapsed(5) + m_walltime() - start
587 DO im = 1, SIZE(mo), mb
588 CALL dbt_create(coeff, coeff_batch, name="CC4S coefficient batch")
589 CALL create_3c_tensor(gamma, d1, d2, d3, grid, ri, mo, mo, [1, 2], [3], &
590 name="CC4S Coulomb vertex batch")
591 DEALLOCATE (d1, d2, d3)
592 mfirst = sum(mo(:im - 1)) + 1
593 mlast = sum(mo(:im + min(mb - 1, SIZE(mo) - im)))
594 bounds2(:, 1) = [1, nao]
595 bounds2(:, 2) = [mfirst, mlast]
596 CALL dbt_copy(coeff, coeff_batch, bounds=bounds2)
597 DO ir = 1, SIZE(ri), rb
598 rfirst = sum(ri(:ir - 1)) + 1
599 rlast = sum(ri(:ir + min(rb - 1, SIZE(ri) - ir)))
600 start = m_walltime()
601 CALL timeset("cc4s_transform", handle)
602 bounds3(:, 1) = [1, nao]
603 bounds3(:, 2) = [rfirst, rlast]
604 bounds3(:, 3) = [1, nao]
605 CALL dbt_create(integrals, ao_triangle)
606 CALL create_3c_tensor(half, d1, d2, d3, grid, mo, ri, ao, [1], [2, 3], &
607 name="CC4S half transform")
608 DEALLOCATE (d1, d2, d3)
609 ! Copy only this auxiliary slice. Contractions never receive live SCF tensors.
610 CALL dbt_copy(integrals, ao_triangle, bounds=bounds3)
611 CALL dbt_contract(1.0_dp, coeff_batch, ao_triangle, 0.0_dp, half, &
612 contract_1=[1], notcontract_1=[2], contract_2=[1], notcontract_2=[2, 3], &
613 map_1=[1], map_2=[2, 3], filter_eps=0.0_dp)
614 ! Restore the weighted AO triangle before transforming the second orbital index.
615 ! Sum, not average: diagonal atom blocks carry weight 1/2.
616 CALL dbt_contract(1.0_dp, coeff_batch, ao_triangle, 1.0_dp, half, &
617 contract_1=[1], notcontract_1=[2], contract_2=[3], notcontract_2=[2, 1], &
618 map_1=[1], map_2=[2, 3], filter_eps=0.0_dp)
619 CALL dbt_destroy(ao_triangle)
620 CALL create_3c_tensor(triangle, d1, d2, d3, grid, ri, mo, mo, [1, 2], [3], &
621 name="CC4S MO batch")
622 DEALLOCATE (d1, d2, d3)
623 CALL dbt_contract(1.0_dp, half, coeff, 0.0_dp, triangle, &
624 contract_1=[3], notcontract_1=[1, 2], contract_2=[1], notcontract_2=[2], &
625 map_1=[3, 1], map_2=[2], filter_eps=0.0_dp)
626 CALL dbt_destroy(half)
627 CALL timestop(handle)
628 elapsed(2) = elapsed(2) + m_walltime() - start
629 start = m_walltime()
630 CALL timeset("cc4s_metric", handle)
631 CALL dbt_contract(1.0_dp, metric_copy, triangle, 1.0_dp, gamma, &
632 contract_1=[1], notcontract_1=[2], contract_2=[1], notcontract_2=[2, 3], &
633 map_1=[1], map_2=[2, 3], filter_eps=0.0_dp)
634 CALL dbt_destroy(triangle)
635 CALL timestop(handle)
636 elapsed(3) = elapsed(3) + m_walltime() - start
637 END DO
638 CALL write_coulomb_vertex_batch(para_env, nri, nmo, gamma, iunit, mfirst, mlast, values, vertex_norm, elapsed)
639 CALL dbt_destroy(gamma)
640 CALL dbt_destroy(coeff_batch)
641 END DO
642 start = m_walltime()
643 IF (para_env%is_source()) CALL cp_print_key_finished_output(iunit, logger, print_section)
644 elapsed(5) = elapsed(5) + m_walltime() - start
645 DEALLOCATE (values)
646 CALL dbt_destroy(metric_copy)
647 CALL dbt_destroy(coeff)
648 CALL dbt_pgrid_destroy(grid)
649 CALL dbt_pgrid_destroy(grid2)
650 DEALLOCATE (ao, ri, mo)
651 END SUBROUTINE export_vertex_batches
652
653! **************************************************************************************************
654!> \brief Positive product, saturated at limit+1, without overflowing intermediate products.
655!> \param factors Nonnegative factors
656!> \param limit Maximum supported value, strictly below HUGE(int_8)
657!> \return Product or limit+1 if the limit would be exceeded
658! **************************************************************************************************
659 PURE FUNCTION limited_product(factors, limit) RESULT(value)
660 INTEGER(int_8), INTENT(IN) :: factors(:), limit
661 INTEGER(int_8) :: value
662
663 INTEGER :: i
664
665 value = 1_int_8
666 DO i = 1, SIZE(factors)
667 IF (factors(i) == 0_int_8) THEN
668 value = 0_int_8
669 RETURN
670 END IF
671 END DO
672 DO i = 1, SIZE(factors)
673 IF (value > limit/factors(i)) THEN
674 value = limit + 1_int_8
675 RETURN
676 END IF
677 value = value*factors(i)
678 END DO
679 END FUNCTION limited_product
680
681! **************************************************************************************************
682!> \brief Validate the complete stream extent before constructing offsets or opening files.
683!> \param nri Number of auxiliary functions
684!> \param nmo Number of active orbitals
685!> \return Number of exported Real64 elements
686! **************************************************************************************************
687 FUNCTION vertex_size(nri, nmo) RESULT(elements)
688 INTEGER, INTENT(IN) :: nri, nmo
689 INTEGER(int_8) :: elements
690
691 INTEGER(int_8), PARAMETER :: file_limit = huge(0_int_8)/dp_size
692
693 cpassert(nri > 0 .AND. nmo > 0)
694 elements = limited_product([int(nri, int_8), int(nmo, int_8), int(nmo, int_8)], file_limit)
695 IF (elements > file_limit) cpabort("CC4S: vertex exceeds stream position range")
696 END FUNCTION vertex_size
697
698! **************************************************************************************************
699!> \brief Intersect a block segment with an output piece before narrowing to local indices.
700!> \param start Zero-based global offset of the block segment
701!> \param length Number of values in the block segment
702!> \param offset Zero-based global offset of the output piece
703!> \param count Number of values in the output piece
704!> \param lo First overlapping block index, or 1 for an empty intersection
705!> \param hi Last overlapping block index, or 0 for an empty intersection
706! **************************************************************************************************
707 PURE SUBROUTINE segment_overlap(start, length, offset, count, lo, hi)
708 INTEGER(int_8), INTENT(IN) :: start
709 INTEGER, INTENT(IN) :: length
710 INTEGER(int_8), INTENT(IN) :: offset, count
711 INTEGER, INTENT(OUT) :: lo, hi
712
713 INTEGER(int_8) :: first, last
714
715 first = max(start, offset)
716 last = min(start + int(length, int_8), offset + count)
717 lo = 1
718 hi = 0
719 IF (first >= last) RETURN
720 lo = int(first - start) + 1
721 hi = int(last - start)
722 END SUBROUTINE segment_overlap
723
724! **************************************************************************************************
725!> \brief Bound backend data and metadata independently of the user memory budget.
726!> \param ao AO block sizes
727!> \param ri Auxiliary block sizes
728!> \param mo MO block sizes
729!> \param mb MO blocks in a batch
730!> \param rb Auxiliary blocks in a batch
731!> \param nranks Maximum replication multiplicity
732!> \param pressure Maximum ratio of a count bound to its supported limit
733!> \return Whether every intermediate is safely representable, even on one rank
734! **************************************************************************************************
735 FUNCTION batch_counts_fit(ao, ri, mo, mb, rb, nranks, pressure) RESULT(fits)
736 INTEGER, INTENT(IN) :: ao(:), ri(:), mo(:), mb, rb, nranks
737 REAL(dp), INTENT(OUT), OPTIONAL :: pressure
738 LOGICAL :: fits
739
740 INTEGER(int_8), PARAMETER :: product_limit = huge(0_int_8)/dp_size
741
742 INTEGER(int_8) :: a, b, block_count, data_count, m, na, &
743 nb, nm, nq, nr, q, r
744
745 a = sum(int(ao, int_8))
746 r = sum(int(ri, int_8))
747 m = sum(int(mo, int_8))
748 b = int(batch_width(mo, mb), int_8)
749 q = int(batch_width(ri, rb), int_8)
750 na = SIZE(ao, kind=int_8)
751 nr = SIZE(ri, kind=int_8)
752 nm = SIZE(mo, kind=int_8)
753 nb = int(mb, int_8)
754 nq = int(rb, int_8)
755 data_count = max(limited_product([a, a, q], product_limit), &
756 limited_product([b, q, a], product_limit), &
757 limited_product([q, m, b], product_limit), &
758 limited_product([r, m, b], product_limit))
759 ! Allow refinement in three dimensions and replicated partial-result metadata
760 ! received from every rank. Payload buffers in TAS replication are per peer.
761 block_count = max(limited_product([8_int_8, int(nranks, int_8), na, nm], product_limit), &
762 limited_product([8_int_8, int(nranks, int_8), na, na, nq], product_limit), &
763 limited_product([8_int_8, int(nranks, int_8), nb, nq, na], product_limit), &
764 limited_product([8_int_8, int(nranks, int_8), nq, nm, nb], product_limit), &
765 limited_product([8_int_8, int(nranks, int_8), nr, nm, nb], product_limit))
766 fits = data_count <= backend_data_limit .AND. block_count <= backend_block_limit
767 IF (PRESENT(pressure)) pressure = max(real(data_count, dp)/real(backend_data_limit, dp), &
768 REAL(block_count, dp)/REAL(backend_block_limit, dp))
769 END FUNCTION batch_counts_fit
770
771! **************************************************************************************************
772!> \brief Score a candidate batch against both workspace and integer-count limits.
773!> \param ao AO block sizes
774!> \param ri Auxiliary block sizes
775!> \param mo MO block sizes
776!> \param mb MO blocks in a batch
777!> \param rb Auxiliary blocks in a batch
778!> \param nranks Maximum replication multiplicity
779!> \param buffer_elements Output buffer length
780!> \param max_memory_mb Additional workspace budget
781!> \return Score no larger than one for an admissible batch
782! **************************************************************************************************
783 FUNCTION batch_pressure(ao, ri, mo, mb, rb, nranks, buffer_elements, max_memory_mb) RESULT(pressure)
784 INTEGER, INTENT(IN) :: ao(:), ri(:), mo(:), mb, rb, nranks
785 INTEGER(int_8), INTENT(IN) :: buffer_elements
786 REAL(dp), INTENT(IN) :: max_memory_mb
787 REAL(dp) :: pressure
788
789 REAL(dp) :: count_pressure
790
791 pressure = batch_workspace(sum(ao), sum(ri), sum(mo), mo, ri, mb, rb, buffer_elements)/max_memory_mb
792 IF (.NOT. batch_counts_fit(ao, ri, mo, mb, rb, nranks, count_pressure)) pressure = max(pressure, count_pressure)
793 END FUNCTION batch_pressure
794
795! **************************************************************************************************
796!> \brief Largest number of functions in a group of consecutive tensor blocks.
797!> \param sizes Block sizes
798!> \param blocks Number of blocks per batch
799!> \return Maximum batch width
800! **************************************************************************************************
801 FUNCTION batch_width(sizes, blocks) RESULT(width)
802 INTEGER, INTENT(IN) :: sizes(:), blocks
803 INTEGER :: width
804
805 INTEGER :: i
806
807 width = 0
808 DO i = 1, SIZE(sizes), blocks
809 width = max(width, sum(sizes(i:i + min(blocks - 1, SIZE(sizes) - i))))
810 END DO
811 END FUNCTION batch_width
812
813! **************************************************************************************************
814!> \brief Conservative busiest-rank workspace estimate, without a balanced-distribution assumption.
815!> Four copies allow for private operands, contraction results and redistribution buffers.
816!> Excludes existing SCF storage, allocator overhead and CC4S. This is not an RSS limit.
817!> \param nao Number of AO functions
818!> \param nri Number of auxiliary functions
819!> \param nmo Number of active orbitals
820!> \param mo Orbital block sizes
821!> \param ri Auxiliary block sizes
822!> \param mb Orbital blocks per batch
823!> \param rb Auxiliary blocks per batch
824!> \param buffer_elements Reusable output buffer length
825!> \return Estimated additional memory per rank in decimal MB
826! **************************************************************************************************
827 FUNCTION batch_workspace(nao, nri, nmo, mo, ri, mb, rb, buffer_elements) RESULT(memory_mb)
828 INTEGER, INTENT(IN) :: nao, nri, nmo, mo(:), ri(:), mb, rb
829 INTEGER(KIND=int_8), INTENT(IN) :: buffer_elements
830 REAL(dp) :: memory_mb
831
832 REAL(dp) :: a, b, fixed, m, q, r, work
833
834 a = real(nao, dp)
835 r = real(nri, dp)
836 m = real(nmo, dp)
837 b = real(batch_width(mo, mb), dp)
838 q = real(batch_width(ri, rb), dp)
839 fixed = 4.0_dp*(r*r + a*m) + 2.0_dp*real(buffer_elements, dp)
840 work = 4.0_dp*(a*a*q + b*q*a + q*m*b + r*m*b + a*b)
841 memory_mb = real(dp_size, dp)*max(6.0_dp*a*a, fixed + work)/1.0e6_dp
842 END FUNCTION batch_workspace
843
844! **************************************************************************************************
845!> \brief Write EigenEnergies.yaml and EigenEnergies.elements (CC4S format, Hartree units).
846!> \param logger Logger for output selection and naming
847!> \param print_section CC4S print key
848!> \param nMO Number of active canonical orbitals
849!> \param homo Number of active occupied orbitals
850!> \param eigenvalues Active orbital energies in Hartree
851!> \param fermi_energy Energy inside the HOMO-LUMO gap
852! **************************************************************************************************
853 SUBROUTINE write_eigen_energies_files(logger, print_section, nMO, homo, eigenvalues, fermi_energy)
854 TYPE(cp_logger_type), POINTER :: logger
855 TYPE(section_vals_type), POINTER :: print_section
856 INTEGER, INTENT(IN) :: nmo, homo
857 REAL(kind=dp), INTENT(IN) :: eigenvalues(nmo), fermi_energy
858
859 INTEGER :: i, iunit
860
861 iunit = cp_print_key_unit_nr(logger, print_section, extension='.yaml', middle_name='EigenEnergies', &
862 file_status='REPLACE', file_position='REWIND')
863 WRITE (iunit, '(A)') 'version: 100'
864 WRITE (iunit, '(A)') 'type: Tensor'
865 WRITE (iunit, '(A)') 'scalarType: Real64'
866 WRITE (iunit, '(A)') 'dimensions:'
867 WRITE (iunit, '(A,I0)') '- length: ', nmo
868 WRITE (iunit, '(A)') ' type: State'
869 WRITE (iunit, '(A)') 'elements:'
870 WRITE (iunit, '(A)') ' type: TextFile'
871 WRITE (iunit, '(A)') 'unit: 1.0'
872 WRITE (iunit, '(A)') 'metaData:'
873 WRITE (iunit, '(A,ES25.16)') ' fermiEnergy: ', fermi_energy
874 WRITE (iunit, '(A,I0)') ' homoIndex: ', homo
875 WRITE (iunit, '(A)') ' energies:'
876 DO i = 1, nmo
877 WRITE (iunit, '(A,ES25.16)') ' - ', eigenvalues(i)
878 END DO
879 CALL cp_print_key_finished_output(iunit, logger, print_section)
880
881 iunit = cp_print_key_unit_nr(logger, print_section, extension='.elements', middle_name='EigenEnergies', &
882 file_status='REPLACE', file_position='REWIND')
883 DO i = 1, nmo
884 WRITE (iunit, '(ES25.16)') eigenvalues(i)
885 END DO
886 CALL cp_print_key_finished_output(iunit, logger, print_section)
887
888 END SUBROUTINE write_eigen_energies_files
889
890! **************************************************************************************************
891!> \brief Gather and write one orbital range in bounded pieces, preserving Fortran element order.
892!> \param para_env MPI parallel environment
893!> \param nRI Number of auxiliary functions
894!> \param nMO Number of active canonical orbitals
895!> \param gamma Distributed vertex, with data only in the selected third-index range
896!> \param iunit Open stream unit on the writing rank
897!> \param first_mo First orbital in this batch
898!> \param last_mo Last orbital in this batch
899!> \param values Reusable output buffer
900!> \param vertex_norm Accumulated squared norm on the writing rank
901!> \param elapsed Accumulated wall times
902! **************************************************************************************************
903 SUBROUTINE write_coulomb_vertex_batch(para_env, nRI, nMO, gamma, iunit, first_mo, last_mo, &
904 values, vertex_norm, elapsed)
905 TYPE(mp_para_env_type), POINTER :: para_env
906 INTEGER, INTENT(IN) :: nri, nmo
907 TYPE(dbt_type), INTENT(INOUT) :: gamma
908 INTEGER, INTENT(IN) :: iunit, first_mo, last_mo
909 REAL(dp), INTENT(INOUT) :: values(:), vertex_norm, elapsed(5)
910
911 INTEGER :: column, handle, hi, ind(3), j, k, lo, &
912 sizes(3)
913 INTEGER(KIND=int_8) :: count, first, last, mirror, nvalues, &
914 offset, row, segment, start, used, &
915 within
916 INTEGER, ALLOCATABLE :: off1(:), off2(:), off3(:)
917 LOGICAL :: found
918 REAL(dp) :: start_time
919 REAL(dp), ALLOCATABLE :: block(:, :, :)
920 TYPE(dbt_iterator_type) :: iter
921
922 start_time = m_walltime()
923 CALL timeset("cc4s_gather", handle)
924 cpassert(SIZE(values, kind=int_8) <= output_count_limit)
925 ALLOCATE (off1(dbt_nblks_total(gamma, 1)), off2(dbt_nblks_total(gamma, 2)), &
926 off3(dbt_nblks_total(gamma, 3)))
927 CALL dbt_get_info(gamma, blk_offset_1=off1, blk_offset_2=off2, blk_offset_3=off3)
928 DO column = first_mo, last_mo
929 offset = int(nri, int_8)*int(nmo, int_8)*int(column - 1, int_8)
930 nvalues = offset + int(nri, int_8)*int(column, int_8)
931 ! Gather one triangle only. Write its transpose from identical values for exact symmetry.
932 DO WHILE (offset < nvalues)
933 count = min(SIZE(values, kind=int_8), nvalues - offset)
934 values = 0.0_dp
935 ! Blocks own disjoint elements; threads fill disjoint parts of the bounded buffer.
936!$OMP PARALLEL DEFAULT(NONE) &
937!$OMP SHARED(gamma, off1, off2, off3, nRI, nMO, offset, count, values) &
938!$OMP PRIVATE(iter, ind, sizes, block, found, j, k, first, last, start, lo, hi)
939 CALL dbt_iterator_start(iter, gamma)
940 DO WHILE (dbt_iterator_blocks_left(iter))
941 CALL dbt_iterator_next_block(iter, ind, blk_size=sizes)
942 first = int(off1(ind(1)) - 1, int_8) + int(nri, int_8)* &
943 (int(off2(ind(2)) - 1, int_8) + int(nmo, int_8)*int(off3(ind(3)) - 1, int_8))
944 last = first + int(sizes(1), int_8) + int(nri, int_8)* &
945 (int(sizes(2) - 1, int_8) + int(nmo, int_8)*int(sizes(3) - 1, int_8))
946 IF (first >= offset + count .OR. last <= offset) cycle
947 CALL dbt_get_block(gamma, ind, block, found)
948 cpassert(found)
949 DO k = 1, sizes(3)
950 DO j = 1, sizes(2)
951 start = first + int(nri, int_8)*(int(j - 1, int_8) + int(nmo, int_8)*int(k - 1, int_8))
952 CALL segment_overlap(start, sizes(1), offset, count, lo, hi)
953 IF (lo > hi) cycle
954 values(start + lo - offset:start + hi - offset) = block(lo:hi, j, k)
955 END DO
956 END DO
957 DEALLOCATE (block)
958 END DO
959 CALL dbt_iterator_stop(iter)
960!$OMP END PARALLEL
961 CALL para_env%sum(values(:count), para_env%source)
962 CALL timestop(handle)
963 elapsed(4) = elapsed(4) + m_walltime() - start_time
964 start_time = m_walltime()
965 CALL timeset("cc4s_write_files", handle)
966 IF (para_env%is_source()) THEN
967 CALL write_coulomb_vertex_block(iunit, offset, values(:count))
968 vertex_norm = vertex_norm + sum(values(:count)**2)
969 used = 0_int_8
970 DO WHILE (used < count)
971 within = modulo(offset + used, int(nri, int_8)*int(nmo, int_8))
972 row = within/int(nri, int_8) + 1_int_8
973 within = modulo(within, int(nri, int_8))
974 segment = min(count - used, int(nri, int_8) - within)
975 IF (row < column) THEN
976 mirror = within + int(nri, int_8)*(int(column - 1, int_8) + int(nmo, int_8)*(row - 1_int_8))
977 CALL write_coulomb_vertex_block(iunit, mirror, values(used + 1:used + segment))
978 vertex_norm = vertex_norm + sum(values(used + 1:used + segment)**2)
979 END IF
980 used = used + segment
981 END DO
982 END IF
983 CALL timestop(handle)
984 elapsed(5) = elapsed(5) + m_walltime() - start_time
985 start_time = m_walltime()
986 CALL timeset("cc4s_gather", handle)
987 offset = offset + count
988 END DO
989 END DO
990 DEALLOCATE (off1, off2, off3)
991 CALL timestop(handle)
992 elapsed(4) = elapsed(4) + m_walltime() - start_time
993 END SUBROUTINE write_coulomb_vertex_batch
994
995! **************************************************************************************************
996!> \brief Write the Coulomb vertex header and open its raw binary elements file.
997!> \param logger Logger for output selection and naming
998!> \param print_section CC4S print key
999!> \param nRI Number of auxiliary functions
1000!> \param nMO Number of active canonical orbitals
1001!> \param periodic Whether the cell is three-dimensionally periodic at Gamma
1002!> \param cutoff_radius Truncated Coulomb cutoff in bohr (zero for molecular Coulomb)
1003!> \param hmat Cell vectors as columns, in bohr
1004!> \param iunit Open stream unit for vertex elements
1005! **************************************************************************************************
1006 SUBROUTINE open_coulomb_vertex_file(logger, print_section, nRI, nMO, periodic, cutoff_radius, hmat, iunit)
1007 TYPE(cp_logger_type), POINTER :: logger
1008 TYPE(section_vals_type), POINTER :: print_section
1009 INTEGER, INTENT(IN) :: nri, nmo
1010 LOGICAL, INTENT(IN) :: periodic
1011 REAL(kind=dp), INTENT(IN) :: cutoff_radius, hmat(3, 3)
1012 INTEGER, INTENT(OUT) :: iunit
1013
1014 INTEGER :: i
1015
1016 iunit = cp_print_key_unit_nr(logger, print_section, extension='.yaml', middle_name='CoulombVertex', &
1017 file_status='REPLACE', file_position='REWIND')
1018 WRITE (iunit, '(A)') 'version: 100'
1019 WRITE (iunit, '(A)') 'type: Tensor'
1020 WRITE (iunit, '(A)') 'scalarType: Real64'
1021 WRITE (iunit, '(A)') 'dimensions:'
1022 WRITE (iunit, '(A,I0)') '- length: ', nri
1023 WRITE (iunit, '(A)') ' type: AuxiliaryField'
1024 WRITE (iunit, '(A,I0)') '- length: ', nmo
1025 WRITE (iunit, '(A)') ' type: State'
1026 WRITE (iunit, '(A,I0)') '- length: ', nmo
1027 WRITE (iunit, '(A)') ' type: State'
1028 WRITE (iunit, '(A)') 'elements:'
1029 WRITE (iunit, '(A)') ' type: IeeeBinaryFile'
1030 WRITE (iunit, '(A)') 'unit: 1.0'
1031 WRITE (iunit, '(A)') 'metaData:'
1032 IF (periodic) THEN
1033 WRITE (iunit, '(A)') ' boundaryConditions: "periodic-3d-gamma"'
1034 WRITE (iunit, '(A)') ' interactionPotential: "TRUNCATED"'
1035 WRITE (iunit, '(A,ES25.16)') ' cutoffRadiusBohr: ', cutoff_radius
1036 WRITE (iunit, '(A)') ' madelungCorrection: 0.0'
1037 WRITE (iunit, '(A)') ' latticeVectorsBohr:'
1038 DO i = 1, 3
1039 WRITE (iunit, '(A,ES25.16,A,ES25.16,A,ES25.16,A)') &
1040 ' - [', hmat(1, i), ', ', hmat(2, i), ', ', hmat(3, i), ']'
1041 END DO
1042 ELSE
1043 WRITE (iunit, '(A)') ' boundaryConditions: "molecular"'
1044 WRITE (iunit, '(A)') ' interactionPotential: "COULOMB"'
1045 END IF
1046 CALL cp_print_key_finished_output(iunit, logger, print_section)
1047
1048 iunit = cp_print_key_unit_nr(logger, print_section, extension='.elements', middle_name='CoulombVertex', &
1049 file_status='REPLACE', file_position='REWIND', &
1050 file_form='UNFORMATTED', file_access='STREAM')
1051 END SUBROUTINE open_coulomb_vertex_file
1052
1053! **************************************************************************************************
1054!> \brief Write a contiguous vertex block at an explicit position in the raw elements file.
1055!> \param iunit Open stream unit for vertex elements
1056!> \param offset Zero-based element offset in auxiliary-orbital-orbital storage order
1057!> \param values Contiguous block of vertex elements
1058! **************************************************************************************************
1059 SUBROUTINE write_coulomb_vertex_block(iunit, offset, values)
1060 INTEGER, INTENT(IN) :: iunit
1061 INTEGER(KIND=int_8), INTENT(IN) :: offset
1062 REAL(kind=dp), CONTIGUOUS, INTENT(IN) :: values(:)
1063
1064 INTEGER :: io_status
1065 INTEGER(KIND=int_8) :: position
1066
1067 ! Use CP2K's Real64 byte size, independent of direct-access record-length units.
1068 cpassert(offset >= 0_int_8)
1069 cpassert(SIZE(values, kind=int_8) > 0_int_8)
1070 cpassert(SIZE(values, kind=int_8) <= huge(position)/int(dp_size, int_8) - offset)
1071 position = offset*int(dp_size, int_8) + 1_int_8
1072 WRITE (iunit, pos=position, iostat=io_status) values
1073 IF (io_status /= 0) THEN
1074 cpabort("CC4S: failed writing CoulombVertex.elements")
1075 END IF
1076 END SUBROUTINE write_coulomb_vertex_block
1077
1078! **************************************************************************************************
1079!> \brief Write the CC4S algorithm sequence and solver settings to cc4s.in.
1080!> \param logger Logger for output selection and naming
1081!> \param print_section CC4S print key
1082!> \param method Requested correlation method: MP2, CCSD or CCSD_T
1083!> \param nocc Number of exported occupied spatial orbitals
1084!> \param max_iter Maximum coupled-cluster iterations
1085!> \param energy_conv CC4S energy convergence threshold
1086!> \param amp_conv CC4S amplitude convergence threshold
1087! **************************************************************************************************
1088 SUBROUTINE write_cc4s_in(logger, print_section, method, nocc, max_iter, energy_conv, amp_conv)
1089 TYPE(cp_logger_type), POINTER :: logger
1090 TYPE(section_vals_type), POINTER :: print_section
1091 CHARACTER(LEN=*), INTENT(IN) :: method
1092 INTEGER, INTENT(IN) :: nocc, max_iter
1093 REAL(dp), INTENT(IN) :: energy_conv, amp_conv
1094
1095 CHARACTER(len=default_path_length) :: filename
1096 INTEGER :: iunit
1097
1098 iunit = cp_print_key_unit_nr(logger, print_section, extension='.in', &
1099 file_status='REPLACE', file_position='REWIND')
1100
1101 ! --- common header: read tensors, slice, build integrals ---
1102 filename = cp_print_key_generate_filename(logger, print_section, 'CoulombVertex', '.yaml', .false.)
1103 CALL write_tensor_read(iunit, filename, 'CoulombVertex')
1104 filename = cp_print_key_generate_filename(logger, print_section, 'EigenEnergies', '.yaml', .false.)
1105 CALL write_tensor_read(iunit, filename, 'EigenEnergies')
1106 WRITE (iunit, '(A)') '- name: DefineHolesAndParticles'
1107 WRITE (iunit, '(A)') ' in:'
1108 WRITE (iunit, '(A)') ' eigenEnergies: EigenEnergies'
1109 WRITE (iunit, '(A)') ' out:'
1110 WRITE (iunit, '(A)') ' slicedEigenEnergies: EigenEnergies'
1111 WRITE (iunit, '(A)') '- name: SliceOperator'
1112 WRITE (iunit, '(A)') ' in:'
1113 WRITE (iunit, '(A)') ' slicedEigenEnergies: EigenEnergies'
1114 WRITE (iunit, '(A)') ' operator: CoulombVertex'
1115 WRITE (iunit, '(A)') ' out:'
1116 WRITE (iunit, '(A)') ' slicedOperator: CoulombVertex'
1117 WRITE (iunit, '(A)') '- name: VertexCoulombIntegrals'
1118 WRITE (iunit, '(A)') ' in:'
1119 WRITE (iunit, '(A)') ' slicedCoulombVertex: CoulombVertex'
1120 WRITE (iunit, '(A)') ' out:'
1121 WRITE (iunit, '(A)') ' coulombIntegrals: CoulombIntegrals'
1122
1123 ! --- MP2 (always included) ---
1124 WRITE (iunit, '(A)') '- name: SecondOrderPerturbationTheory'
1125 WRITE (iunit, '(A)') ' in:'
1126 WRITE (iunit, '(A)') ' coulombIntegrals: CoulombIntegrals'
1127 WRITE (iunit, '(A)') ' slicedEigenEnergies: EigenEnergies'
1128 WRITE (iunit, '(A)') ' out:'
1129 WRITE (iunit, '(A)') ' energy: Mp2Energy'
1130
1131 ! --- CoupledCluster (CCSD, CCSD_T) ---
1132 SELECT CASE (trim(method))
1133 CASE ('MP2')
1134 ! The MP2 driver is complete above.
1135 CASE ('CCSD', 'CCSD_T')
1136 CALL write_coupled_cluster_step(iunit, 'Ccsd', 'Amplitudes', nocc, max_iter, energy_conv, amp_conv)
1137 CASE DEFAULT
1138 cpabort("CC4S: unsupported method")
1139 END SELECT
1140
1141 ! --- PerturbativeTriples (CCSD_T only) ---
1142 IF (trim(method) == 'CCSD_T') THEN
1143 WRITE (iunit, '(A)') '- name: PerturbativeTriples'
1144 WRITE (iunit, '(A)') ' in:'
1145 WRITE (iunit, '(A)') ' slicedEigenEnergies: EigenEnergies'
1146 WRITE (iunit, '(A)') ' amplitudes: Amplitudes'
1147 WRITE (iunit, '(A)') ' coulombIntegrals: CoulombIntegrals'
1148 WRITE (iunit, '(A)') ' out: {}'
1149 END IF
1150
1151 CALL cp_print_key_finished_output(iunit, logger, print_section)
1152
1153 END SUBROUTINE write_cc4s_in
1154
1155! **************************************************************************************************
1156!> \brief Write a single CoupledCluster step to the cc4s.in file.
1157!> \param iunit Output file unit
1158!> \param cc_method CC4S coupled-cluster method
1159!> \param amp_key CC4S output key for amplitudes
1160!> \param nocc Number of exported occupied spatial orbitals
1161!> \param max_iter Maximum coupled-cluster iterations
1162!> \param energy_conv CC4S energy convergence threshold
1163!> \param amp_conv CC4S amplitude convergence threshold
1164! **************************************************************************************************
1165 SUBROUTINE write_coupled_cluster_step(iunit, cc_method, amp_key, nocc, max_iter, energy_conv, amp_conv)
1166 INTEGER, INTENT(IN) :: iunit
1167 CHARACTER(LEN=*), INTENT(IN) :: cc_method, amp_key
1168 INTEGER, INTENT(IN) :: nocc, max_iter
1169 REAL(dp), INTENT(IN) :: energy_conv, amp_conv
1170
1171 WRITE (iunit, '(A)') '- name: CoupledCluster'
1172 WRITE (iunit, '(A)') ' in:'
1173 WRITE (iunit, '(A)') ' method: '//trim(cc_method)
1174 ! Match CC4S v1.1 defaults using the occupied space after frozen-core removal.
1175 WRITE (iunit, '(A,I0)') ' integralsSliceSize: ', nocc
1176 WRITE (iunit, '(A)') ' slicedEigenEnergies: EigenEnergies'
1177 WRITE (iunit, '(A)') ' coulombIntegrals: CoulombIntegrals'
1178 WRITE (iunit, '(A)') ' slicedCoulombVertex: CoulombVertex'
1179 WRITE (iunit, '(A,I0)') ' maxIterations: ', max_iter
1180 WRITE (iunit, '(A,ES25.16)') ' energyConvergence: ', energy_conv
1181 WRITE (iunit, '(A,ES25.16)') ' amplitudesConvergence: ', amp_conv
1182 WRITE (iunit, '(A)') ' mixer:'
1183 WRITE (iunit, '(A)') ' type: DiisMixer'
1184 WRITE (iunit, '(A)') ' maxResidua: 4'
1185 WRITE (iunit, '(A)') ' out:'
1186 WRITE (iunit, '(A)') ' amplitudes: '//trim(amp_key)
1187 WRITE (iunit, '(A)') ' energy: CoupledClusterEnergy'
1188
1189 END SUBROUTINE write_coupled_cluster_step
1190
1191! **************************************************************************************************
1192!> \brief Write a tensor reference relative to the generated CC4S input's directory.
1193!> \param iunit CC4S input unit
1194!> \param filename Generated tensor header filename
1195!> \param destination CC4S tensor name
1196! **************************************************************************************************
1197 SUBROUTINE write_tensor_read(iunit, filename, destination)
1198 INTEGER, INTENT(IN) :: iunit
1199 CHARACTER(len=*), INTENT(IN) :: filename, destination
1200
1201 INTEGER :: i
1202
1203 WRITE (iunit, '(A)') '- name: Read'
1204 WRITE (iunit, '(A)') ' in:'
1205 WRITE (iunit, '(A)', advance='NO') " fileName: '"
1206 ! A quoted YAML scalar preserves spaces and punctuation; apostrophes are doubled.
1207 DO i = index(filename, '/', back=.true.) + 1, len_trim(filename)
1208 WRITE (iunit, '(A)', advance='NO') filename(i:i)
1209 IF (filename(i:i) == "'") WRITE (iunit, '(A)', advance='NO') "'"
1210 END DO
1211 WRITE (iunit, '(A)') "'"
1212 WRITE (iunit, '(A)') ' out:'
1213 WRITE (iunit, '(A)') ' destination: '//destination
1214 END SUBROUTINE write_tensor_read
1215
1216END MODULE cc4s_export
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Molecular and Gamma-point periodic CC4S export from restricted RI-HF. RI_FLAVOR MO stores a weighted ...
Definition cc4s_export.F:15
subroutine, public write_cc4s(qs_env, converged)
Check the requested export, canonicalize private Fock/overlap copies and write tensors.
Definition cc4s_export.F:96
Handles all functions related to the CELL.
Definition cell_types.F:15
integer, parameter, public use_perd_xyz
Definition cell_types.F:42
integer, parameter, public use_perd_none
Definition cell_types.F:42
real(kind=dp) function, public plane_distance(h, k, l, cell)
Calculate the distance between two lattice planes as defined by a triple of Miller indices (hkl).
Definition cell_types.F:325
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_release(matrix)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan, check_plan)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public cp_fm_to_dbcsr_row_template(matrix, fm_in, template)
Utility function to copy a specially shaped fm to dbcsr_matrix The result matrix will be the matrix i...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
Definition cp_fm_diag.F:17
subroutine, public cp_fm_geeig_canon(amatrix, bmatrix, eigenvectors, eigenvalues, work, epseig, nmo_retained)
General Eigenvalue Problem AX = BXE Use canonical diagonalization : U*s**(-1/2).
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
Definition cp_fm_types.F:15
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
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...
character(len=default_path_length) function, public cp_print_key_generate_filename(logger, print_key, middle_name, extension, my_local)
Utility function that returns a unit number to write the print key. Might open a file with a unique f...
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
logical function, public cp_printkey_is_on(iteration_info, print_key)
returns true if the printlevel activates this printkey does not look if this iteration it should be p...
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...
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, file_access)
...
This is the start of a dbt_api, all publically needed functions are exported here....
Definition dbt_api.F:17
Calculation of the incomplete Gamma function F_n(t) for multi-center integrals over Cartesian Gaussia...
Definition gamma.F:15
Types and set/get functions for HFX.
Definition hfx_types.F:16
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_potential_truncated
integer, parameter, public do_potential_coulomb
integer, parameter, public sic_none
integer, parameter, public xc_none
function that builds the hartree fock exchange section of the input
integer, parameter, public ri_mo
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp_size
Definition kinds.F:36
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_path_length
Definition kinds.F:58
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition machine.F:144
Interface to the message passing library MPI.
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, matrix_vhxc, 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, xcint_weights, 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.
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
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...
Utility methods to build 3-center integral tensors of various types.
subroutine, public create_2c_tensor(t2c, dist_1, dist_2, pgrid, sizes_1, sizes_2, order, name)
...
subroutine, public create_3c_tensor(t3c, dist_1, dist_2, dist_3, pgrid, sizes_1, sizes_2, sizes_3, map1, map2, name)
...
parameters that control an scf iteration
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
keeps the information about the structure of a full matrix
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:474
stores all the informations relevant to an mpi environment