(git:9754b87)
Loading...
Searching...
No Matches
smeagol_interface.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief CP2K+SMEAGOL interface.
10!> \author Sergey Chulkov
11!> \author Christian Ahart
12!> \author Clotilde Cucinotta
13! **************************************************************************************************
15 USE bibliography, ONLY: ahart2024, &
16 bailey2006, &
17 cite_reference
18 USE cell_types, ONLY: cell_type, &
23 USE cp_files, ONLY: close_file, &
30 USE cp_dbcsr_api, ONLY: dbcsr_copy, &
40 USE kinds, ONLY: dp, &
41 int_8
42 USE kpoint_types, ONLY: get_kpoint_info, &
45#if defined(__SMEAGOL)
46 USE mmpi_negf, ONLY: create_communicators_negf, &
47 destroy_communicators_negf
48 USE mnegf_interface, ONLY: negf_interface
49 USE negfmod, ONLY: smeagolglobal_em_nas => em_nas, &
50 smeagolglobal_em_nau => em_nau, &
51 smeagolglobal_em_nso => em_nso, &
52 smeagolglobal_em_nuo => em_nuo, &
53 smeagolglobal_negfon => negfon
54#endif
55 USE physcon, ONLY: bohr, &
56 evolt
58 USE pw_types, ONLY: pw_r3d_rs_type
63 USE qs_ks_types, ONLY: qs_ks_env_type, &
66 USE qs_rho_types, ONLY: qs_rho_get, &
68 USE qs_subsys_types, ONLY: qs_subsys_get, &
81#include "./base/base_uses.f90"
82
83 IMPLICIT NONE
84 PRIVATE
85
86 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'smeagol_interface'
87
90
91CONTAINS
92
93! **************************************************************************************************
94!> \brief Save overlap, Kohn-Sham, electron density, and energy-density matrices of semi-infinite
95!> electrodes in SIESTA format.
96!> \param qs_env QuickStep environment
97! **************************************************************************************************
98 SUBROUTINE run_smeagol_bulktrans(qs_env)
99 TYPE(qs_environment_type), POINTER :: qs_env
100
101 CHARACTER(LEN=*), PARAMETER :: routinen = 'run_smeagol_bulktrans'
102
103 CHARACTER(len=32) :: hst_fmt
104 INTEGER :: funit, handle, img, ispin, lead_label, &
105 log_unit, nimages, nspin
106 INTEGER(kind=int_8) :: ielem
107 INTEGER, DIMENSION(2) :: max_ij_cell_image
108 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
109 LOGICAL :: do_kpoints, has_unit_metric, not_regtest
110 REAL(kind=dp) :: h_to_ry
111 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: matrix_siesta_1d, nelectrons
112 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: matrix_siesta_2d
113 TYPE(dbcsr_p_type), ALLOCATABLE, DIMENSION(:) :: matrix_kp_generic
114 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks_kp, matrix_s_kp, matrix_w_kp, &
115 rho_ao_kp
116 TYPE(dft_control_type), POINTER :: dft_control
117 TYPE(kpoint_type), POINTER :: kpoints
118 TYPE(mp_para_env_type), POINTER :: para_env
119 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
120 POINTER :: sab_nl
121 TYPE(pw_r3d_rs_type), POINTER :: v_hartree_rspace
122 TYPE(qs_energy_type), POINTER :: energy
123 TYPE(qs_ks_env_type), POINTER :: ks_env
124 TYPE(qs_rho_type), POINTER :: rho
125 TYPE(qs_subsys_type), POINTER :: subsys
126 TYPE(scf_control_type), POINTER :: scf_control
127 TYPE(siesta_distrib_csc_struct_type) :: siesta_struct
128 TYPE(smeagol_control_type), POINTER :: smeagol_control
129
130 CALL get_qs_env(qs_env, dft_control=dft_control)
131 smeagol_control => dft_control%smeagol_control
132 IF (.NOT. (smeagol_control%smeagol_enabled .AND. smeagol_control%run_type == smeagol_runtype_bulktransport)) RETURN
133
134 CALL timeset(routinen, handle)
135
137 h_to_ry = smeagol_control%to_smeagol_energy_units
138 not_regtest = .NOT. smeagol_control%do_regtest
139
140 lead_label = smeagol_control%lead_label
141 nspin = dft_control%nspins
142
143 NULLIFY (v_hartree_rspace)
144 CALL get_qs_env(qs_env, energy=energy, para_env=para_env, subsys=subsys, &
145 scf_control=scf_control, &
146 do_kpoints=do_kpoints, kpoints=kpoints, &
147 matrix_ks_kp=matrix_ks_kp, matrix_s_kp=matrix_s_kp, &
148 rho=rho, sab_orb=sab_nl, v_hartree_rspace=v_hartree_rspace)
149 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
150
151 IF (not_regtest) THEN
152 ! save average electrostatic potential of the electrode along transport direction
153 CALL write_average_hartree_potential(v_hartree_rspace, smeagol_control%project_name)
154 END IF
155
156 IF (log_unit > 0) THEN
157 WRITE (log_unit, '(/,T2,A,T61,ES20.10E2)') "SMEAGOL| E_FERMI [a.u.] = ", energy%efermi
158 END IF
159
160 IF (do_kpoints) THEN
161 nimages = dft_control%nimages
162 CALL get_kpoint_info(kpoints, cell_to_index=cell_to_index)
163 ELSE
164 nimages = 1
165 ALLOCATE (cell_to_index(0:0, 0:0, 0:0))
166 cell_to_index(0, 0, 0) = 1
167 ! We do need at least two cell images along transport direction.
168 cpabort("Please enable k-points")
169 END IF
170
171 ! largest index of cell images along i and j cell vectors
172 ! e.g., (2,0) in case of 5 cell images (0,0), (1,0), (-1,0), (2,0), and (-2,0)
173 ! -1 means to use all available cell images along a particular cell vector.
174 max_ij_cell_image(:) = -1
175 DO img = 1, 2
176 IF (smeagol_control%n_cell_images(img) > 0) THEN
177 max_ij_cell_image(img) = smeagol_control%n_cell_images(img)/2
178 END IF
179 END DO
180
181 ALLOCATE (matrix_kp_generic(nimages))
182
183 ! compute energy-density (W) matrix. We may need it later to calculate NEGF forces
184 CALL get_qs_env(qs_env, has_unit_metric=has_unit_metric)
185 IF (.NOT. has_unit_metric) THEN
186 CALL get_qs_env(qs_env, matrix_w_kp=matrix_w_kp)
187 IF (.NOT. ASSOCIATED(matrix_w_kp)) THEN
188 NULLIFY (matrix_w_kp)
189 CALL get_qs_env(qs_env, ks_env=ks_env)
190 CALL dbcsr_allocate_matrix_set(matrix_w_kp, nspin, nimages)
191 DO ispin = 1, nspin
192 DO img = 1, nimages
193 ALLOCATE (matrix_w_kp(ispin, img)%matrix)
194 CALL dbcsr_copy(matrix_w_kp(ispin, img)%matrix, matrix_s_kp(1, 1)%matrix, name="W MATRIX")
195 CALL dbcsr_set(matrix_w_kp(ispin, img)%matrix, 0.0_dp)
196 END DO
197 END DO
198 CALL set_ks_env(ks_env, matrix_w_kp=matrix_w_kp)
199 END IF
200 END IF
201 CALL compute_matrix_w(qs_env, calc_forces=.true.)
202
203 ! obtain the sparsity pattern of the overlap matrix
204 DO img = 1, nimages
205 matrix_kp_generic(img)%matrix => matrix_s_kp(1, img)%matrix
206 END DO
207
208 CALL siesta_struct_create(siesta_struct, matrix_kp_generic, subsys, cell_to_index, &
209 sab_nl, para_env, max_ij_cell_image, do_merge=.false., gather_root=para_env%source)
210
211 ! write 'bulklft.DAT' and 'bulkrgt.DAT' files
212 funit = -1
213 IF (not_regtest .AND. para_env%mepos == para_env%source) THEN
214 ! I/O process
215 IF (lead_label == smeagol_bulklead_left .OR. lead_label == smeagol_bulklead_leftright) THEN
216 CALL open_file("bulklft.DAT", file_status="REPLACE", file_form="FORMATTED", file_action="WRITE", unit_number=funit)
217
218 CALL write_bulk_dat_file(funit, siesta_struct, smeagol_control%project_name, nspin, &
219 energy%efermi, scf_control%smear%ELECTRONIC_TEMPERATURE, &
220 h_to_ry, do_kpoints, max_ij_cell_image)
221
222 CALL close_file(funit)
223 END IF
224
225 IF (lead_label == smeagol_bulklead_right .OR. lead_label == smeagol_bulklead_leftright) THEN
226 CALL open_file("bulkrgt.DAT", file_status="REPLACE", file_form="FORMATTED", file_action="WRITE", unit_number=funit)
227
228 CALL write_bulk_dat_file(funit, siesta_struct, smeagol_control%project_name, nspin, &
229 energy%efermi, scf_control%smear%ELECTRONIC_TEMPERATURE, &
230 h_to_ry, do_kpoints, max_ij_cell_image)
231
232 CALL close_file(funit)
233 END IF
234 END IF
235
236 ! write project_name.HST file
237 funit = -1
238 IF (para_env%mepos == para_env%source) THEN
239 ALLOCATE (matrix_siesta_1d(siesta_struct%n_nonzero_elements))
240 ALLOCATE (matrix_siesta_2d(siesta_struct%n_nonzero_elements, nspin))
241
242 IF (not_regtest) THEN
243 CALL open_file(trim(smeagol_control%project_name)//".HST", &
244 file_status="REPLACE", file_form="FORMATTED", file_action="WRITE", unit_number=funit)
245 END IF
246 ELSE
247 ALLOCATE (matrix_siesta_1d(1))
248 ALLOCATE (matrix_siesta_2d(1, nspin))
249 END IF
250
251 !DO img = 1, nimages
252 ! matrix_kp_generic(img)%matrix => matrix_s_kp(1, img)%matrix
253 !END DO
254 CALL convert_dbcsr_to_distributed_siesta(matrix_siesta_1d, matrix_kp_generic, siesta_struct, para_env)
255
256 DO ispin = 1, nspin
257 DO img = 1, nimages
258 matrix_kp_generic(img)%matrix => matrix_ks_kp(ispin, img)%matrix
259 END DO
260 CALL convert_dbcsr_to_distributed_siesta(matrix_siesta_2d(:, ispin), matrix_kp_generic, siesta_struct, para_env)
261 END DO
262 ! As SIESTA's default energy unit is Rydberg, scale the KS-matrix
263 matrix_siesta_2d(:, :) = h_to_ry*matrix_siesta_2d(:, :)
264
265 IF (funit > 0) THEN ! not_regtest .AND. para_env%mepos == para_env%source
266 WRITE (hst_fmt, '(A,I0,A)') "(", nspin, "ES26.17E3)"
267 DO ielem = 1, siesta_struct%n_nonzero_elements
268 WRITE (funit, '(ES26.17E3)') matrix_siesta_1d(ielem)
269 WRITE (funit, hst_fmt) matrix_siesta_2d(ielem, :)
270 END DO
271
272 CALL close_file(funit)
273 END IF
274
275 ! write density matrix
276 DO ispin = 1, nspin
277 DO img = 1, nimages
278 matrix_kp_generic(img)%matrix => rho_ao_kp(ispin, img)%matrix
279 END DO
280 CALL convert_dbcsr_to_distributed_siesta(matrix_siesta_2d(:, ispin), matrix_kp_generic, siesta_struct, para_env)
281 END DO
282
283 IF (para_env%mepos == para_env%source) THEN
284 ALLOCATE (nelectrons(nspin))
285 DO ispin = 1, nspin
286 nelectrons(ispin) = accurate_dot_product(matrix_siesta_2d(:, ispin), matrix_siesta_1d)
287 END DO
288
289 cpassert(log_unit > 0)
290 IF (nspin > 1) THEN
291 WRITE (log_unit, '(T2,A,T61,F20.10)') "SMEAGOL| Number of alpha-spin electrons: ", nelectrons(1)
292 WRITE (log_unit, '(T2,A,T61,F20.10)') "SMEAGOL| Number of beta-spin electrons: ", nelectrons(2)
293 ELSE
294 WRITE (log_unit, '(T2,A,T61,F20.10)') "SMEAGOL| Number of electrons: ", nelectrons(1)
295 END IF
296 DEALLOCATE (nelectrons)
297
298 IF (not_regtest) THEN
299 CALL open_file(trim(smeagol_control%project_name)//".DM", &
300 file_status="REPLACE", file_form="UNFORMATTED", file_action="WRITE", unit_number=funit)
301
302 CALL write_bulk_dm_file(funit, siesta_struct, nspin, matrix_siesta_2d)
303
304 CALL close_file(funit)
305 END IF
306 END IF
307
308 CALL get_qs_env(qs_env, matrix_w_kp=matrix_w_kp)
309 IF (ASSOCIATED(matrix_w_kp)) THEN
310 ! write energy density matrix
311 DO ispin = 1, nspin
312 DO img = 1, nimages
313 matrix_kp_generic(img)%matrix => matrix_w_kp(ispin, img)%matrix
314 END DO
315 CALL convert_dbcsr_to_distributed_siesta(matrix_siesta_2d(:, ispin), matrix_kp_generic, &
316 siesta_struct, para_env)
317 END DO
318
319 IF (not_regtest .AND. para_env%mepos == para_env%source) THEN
320 CALL open_file(trim(smeagol_control%project_name)//".EDM", &
321 file_status="REPLACE", file_form="UNFORMATTED", file_action="WRITE", unit_number=funit)
322
323 CALL write_bulk_dm_file(funit, siesta_struct, nspin, matrix_siesta_2d)
324
325 CALL close_file(funit)
326 END IF
327 END IF
328
329 DEALLOCATE (matrix_siesta_2d)
330 DEALLOCATE (matrix_siesta_1d)
331
332 DEALLOCATE (matrix_kp_generic)
333 IF (.NOT. do_kpoints) DEALLOCATE (cell_to_index)
334
335 CALL siesta_struct_release(siesta_struct)
336 CALL timestop(handle)
337 END SUBROUTINE run_smeagol_bulktrans
338
339! **************************************************************************************************
340!> \brief Write a sparse matrix structure file in SIESTA format. Should be called on I/O MPI process only.
341!> \param funit file to write
342!> \param siesta_struct sparse matrix structure in SIESTA format
343!> \param system_label SMEAGOL project name (first components of file names, i.e. system_label.HST)
344!> \param nspin number of spin components
345!> \param EFermi Fermi level
346!> \param temperature electronic temperature
347!> \param H_to_Ry Hartree to Rydberg scale factor
348!> \param do_kpoints whether to perform k-point calculation. Should always be enabled as
349!> SMEAGOL expects at least 3 cell replicas along the transport direction
350!> \param max_ij_cell_image maximum cell-replica indices along i- and j- lattice vectors
351!> (perpendicular the transport direction)
352! **************************************************************************************************
353 SUBROUTINE write_bulk_dat_file(funit, siesta_struct, system_label, nspin, EFermi, temperature, &
354 H_to_Ry, do_kpoints, max_ij_cell_image)
355 INTEGER, INTENT(in) :: funit
356 TYPE(siesta_distrib_csc_struct_type), INTENT(in) :: siesta_struct
357 CHARACTER(len=*), INTENT(in) :: system_label
358 INTEGER, INTENT(in) :: nspin
359 REAL(kind=dp), INTENT(in) :: efermi, temperature, h_to_ry
360 LOGICAL, INTENT(in) :: do_kpoints
361 INTEGER, DIMENSION(2), INTENT(in) :: max_ij_cell_image
362
363 CHARACTER(LEN=*), PARAMETER :: routinen = 'write_bulk_dat_file'
364
365 INTEGER :: handle, icol, irow, nao_supercell, &
366 nao_unitcell
367 INTEGER, DIMENSION(2) :: ncells_siesta
368
369 CALL timeset(routinen, handle)
370
371 ! ++ header
372 nao_unitcell = siesta_struct%nrows
373 nao_supercell = siesta_struct%ncols
374 ncells_siesta(1:2) = 2*max_ij_cell_image(1:2) + 1
375
376 ! SMEAGOL expects Temperature and Fermi energy in Rydberg energy units, not in Hartree energy units.
377 ! It is why these values are doubled.
378
379 WRITE (funit, '(1X,A20,3I12,2ES26.17E3,3I12)') &
380 system_label, nao_unitcell, nspin, siesta_struct%n_nonzero_elements, &
381 h_to_ry*efermi, h_to_ry*temperature, ncells_siesta(1:2), nao_supercell
382
383 ! ++ number of non-zero matrix elements on each row and
384 ! the index of the first non-zero matrix element on this row -1 in 1D data array.
385 DO irow = 1, nao_unitcell
386 WRITE (funit, '(2I12)') siesta_struct%n_nonzero_cols(irow), siesta_struct%row_offset(irow)
387 END DO
388
389 DO icol = 1, nao_supercell
390 WRITE (funit, '(I12)') siesta_struct%indxuo(icol)
391 END DO
392
393 ! ++ column indices of non-zero matrix elements
394 DO irow = 1, nao_unitcell
395 DO icol = 1, siesta_struct%n_nonzero_cols(irow)
396 WRITE (funit, '(I12)') siesta_struct%col_index(siesta_struct%row_offset(irow) + icol)
397
398 IF (do_kpoints) THEN
399 WRITE (funit, '(F21.16,5X,F21.16,5X,F21.16)') siesta_struct%xij(:, siesta_struct%row_offset(irow) + icol)
400 END IF
401 END DO
402 END DO
403
404 CALL timestop(handle)
405 END SUBROUTINE write_bulk_dat_file
406
407! **************************************************************************************************
408!> \brief Write an (energy-) density matrix. Should be called on I/O MPI process only.
409!> \param funit file to write
410!> \param siesta_struct sparse matrix structure in SIESTA format
411!> \param nspin number of spin components
412!> \param matrix_siesta non-zero matrix elements (1:siesta_struct%n_nonzero_elements, 1:nspin)
413! **************************************************************************************************
414 SUBROUTINE write_bulk_dm_file(funit, siesta_struct, nspin, matrix_siesta)
415 INTEGER, INTENT(in) :: funit
416 TYPE(siesta_distrib_csc_struct_type), INTENT(in) :: siesta_struct
417 INTEGER, INTENT(in) :: nspin
418 REAL(kind=dp), DIMENSION(:, :), INTENT(in) :: matrix_siesta
419
420 CHARACTER(LEN=*), PARAMETER :: routinen = 'write_bulk_dm_file'
421
422 INTEGER :: handle, irow, ispin
423
424 CALL timeset(routinen, handle)
425
426 ! ++ number of compressed rows, number of spin components
427 WRITE (funit) siesta_struct%nrows, nspin
428
429 ! ++ number of non-zero matrix elements on each compressed row.
430 ! The sparsity pattern for alpha- and beta-spin density matrices are identical
431 WRITE (funit) siesta_struct%n_nonzero_cols
432
433 ! ++ column indices of non-zero matrix elements
434 DO irow = 1, siesta_struct%nrows
435 WRITE (funit) siesta_struct%col_index(siesta_struct%row_offset(irow) + 1: &
436 siesta_struct%row_offset(irow) + siesta_struct%n_nonzero_cols(irow))
437 END DO
438
439 ! ++ non-zero matrix blocks
440 DO ispin = 1, nspin
441 DO irow = 1, siesta_struct%nrows
442 WRITE (funit) matrix_siesta(siesta_struct%row_offset(irow) + 1: &
443 siesta_struct%row_offset(irow) + siesta_struct%n_nonzero_cols(irow), ispin)
444 END DO
445 END DO
446
447 CALL timestop(handle)
448 END SUBROUTINE write_bulk_dm_file
449
450! **************************************************************************************************
451!> \brief Write the average value of Hartree potential along transport direction.
452!> SMEAGOL assumes that the transport direction coincides with z-axis.
453!> \param v_hartree_rspace Hartree potential on a real-space 3-D grid
454!> \param project_name SMEAGOL project name
455!> \note This routine assumes that the lattice vector 'k' coincides with z-axis
456! **************************************************************************************************
457 SUBROUTINE write_average_hartree_potential(v_hartree_rspace, project_name)
458 TYPE(pw_r3d_rs_type), POINTER :: v_hartree_rspace
459 CHARACTER(len=*), INTENT(in) :: project_name
460
461 CHARACTER(LEN=*), PARAMETER :: routinen = 'write_average_hartree_potential'
462
463 INTEGER :: funit, handle, iz, lz, uz
464 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: v_hartree_z_average
465 REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :, :), &
466 POINTER :: cr3d
467 TYPE(pw_grid_type), POINTER :: pw_grid
468
469 CALL timeset(routinen, handle)
470
471 pw_grid => v_hartree_rspace%pw_grid
472 cr3d => v_hartree_rspace%array
473
474 ALLOCATE (v_hartree_z_average(pw_grid%bounds(1, 3):pw_grid%bounds(2, 3)))
475 v_hartree_z_average(:) = 0.0_dp
476
477 lz = pw_grid%bounds_local(1, 3)
478 uz = pw_grid%bounds_local(2, 3)
479
480 ! save average electrostatic potential
481 DO iz = lz, uz
482 v_hartree_z_average(iz) = accurate_sum(cr3d(:, :, iz))
483 END DO
484 CALL pw_grid%para%group%sum(v_hartree_z_average)
485 v_hartree_z_average(:) = v_hartree_z_average(:)/ &
486 (real(pw_grid%npts(1), kind=dp)*real(pw_grid%npts(2), kind=dp))
487
488 funit = -1
489 IF (pw_grid%para%group%mepos == pw_grid%para%group%source) THEN
490 CALL open_file(trim(adjustl(project_name))//"-VH_AV.dat", &
491 file_status="REPLACE", file_form="FORMATTED", file_action="WRITE", unit_number=funit)
492 WRITE (funit, '(A,T10,A,T25,A)') "#", "z (A)", "V_H average (eV)"
493 DO iz = lz, uz
494 WRITE (funit, '(F20.10,ES20.10E3)') pw_grid%dh(3, 3)*real(iz - lz, kind=dp)/bohr, &
495 v_hartree_z_average(iz)/pw_grid%dvol*evolt
496 END DO
497 CALL close_file(funit)
498 END IF
499
500 DEALLOCATE (v_hartree_z_average)
501 CALL timestop(handle)
502 END SUBROUTINE write_average_hartree_potential
503
504! **************************************************************************************************
505!> \brief Align Hatree potential of semi-infinite leads to match bulk-transport calculation
506!> and apply external electrostatic potential (bias).
507!> \param v_hartree_rspace Hartree potential on a real-space 3-D grid [inout]
508!> \param cell unit cell
509!> \param HartreeLeadsLeft z-coordinate of the left lead
510!> \param HartreeLeadsRight z-coordinate of the right lead
511!> \param HartreeLeadsBottom average Hartree potential (from bulk-transport calculation)
512!> at HartreeLeadsLeft and HartreeLeadsRight
513!> \param Vbias the value of external potential to apply
514!> \param zleft starting point of external potential drop (initial value 0.5*Vbias)
515!> \param zright final point of external potential drop (final value -0.5*Vbias)
516!> \param isexplicit_zright whether zright has beed provided explicitly via the input file.
517!> If not, use the cell boundary.
518!> \param isexplicit_bottom whether the reference Hatree potential for bulk regions has been
519!> provided explicitly via the input file. If not, do not align the
520!> potential at all (instead of aligning it to 0 which is incorrect).
521!> \note This routine assumes that the lattice vector 'k' coincides with z-axis
522! **************************************************************************************************
523 SUBROUTINE smeagol_shift_v_hartree(v_hartree_rspace, cell, &
524 HartreeLeadsLeft, HartreeLeadsRight, HartreeLeadsBottom, &
525 Vbias, zleft, zright, isexplicit_zright, isexplicit_bottom)
526 TYPE(pw_r3d_rs_type), POINTER :: v_hartree_rspace
527 TYPE(cell_type), POINTER :: cell
528 REAL(kind=dp), INTENT(in) :: hartreeleadsleft, hartreeleadsright, &
529 hartreeleadsbottom, vbias, zleft, &
530 zright
531 LOGICAL, INTENT(in) :: isexplicit_zright, isexplicit_bottom
532
533 CHARACTER(LEN=*), PARAMETER :: routinen = 'smeagol_shift_v_hartree'
534
535 INTEGER :: handle, iz, l_right, lz, u_left, uz
536 REAL(kind=dp) :: v_average_left, v_average_right, &
537 v_bias_iz, zright_explicit
538 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: v_hartree_z_average
539 REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :, :), &
540 POINTER :: cr3d
541 REAL(kind=dp), DIMENSION(3) :: r, r_pbc
542 TYPE(pw_grid_type), POINTER :: pw_grid
543
544 CALL timeset(routinen, handle)
545 pw_grid => v_hartree_rspace%pw_grid
546 cr3d => v_hartree_rspace%array
547
548 zright_explicit = zright
549 IF (.NOT. isexplicit_zright) THEN
550 r_pbc(:) = (/0.0_dp, 0.0_dp, 1.0_dp/)
551 CALL scaled_to_real(r, r_pbc, cell)
552 zright_explicit = r(3)
553 END IF
554
555 ALLOCATE (v_hartree_z_average(pw_grid%bounds(1, 3):pw_grid%bounds(2, 3)))
556
557 lz = pw_grid%bounds_local(1, 3)
558 uz = pw_grid%bounds_local(2, 3)
559
560 v_hartree_z_average(:) = 0.0_dp
561 DO iz = lz, uz
562 v_hartree_z_average(iz) = accurate_sum(cr3d(:, :, iz))
563 END DO
564
565 CALL pw_grid%para%group%sum(v_hartree_z_average)
566 v_hartree_z_average(:) = v_hartree_z_average(:)/ &
567 (real(pw_grid%npts(1), kind=dp)*real(pw_grid%npts(2), kind=dp))
568
569 ! z-indices of the V_hartree related to the left lead: pw_grid%bounds(1,3) .. u_left
570 r(1:3) = (/0.0_dp, 0.0_dp, hartreeleadsleft/)
571 CALL real_to_scaled(r_pbc, r, cell)
572 u_left = nint(r_pbc(3)*real(pw_grid%npts(3), kind=dp)) + pw_grid%bounds(1, 3)
573 IF (u_left > pw_grid%bounds(2, 3)) u_left = pw_grid%bounds(2, 3)
574
575 ! z-indices of the V_hartree related to the right lead: l_right .. pw_grid%bounds(2, 3)
576 r(1:3) = (/0.0_dp, 0.0_dp, hartreeleadsright/)
577 CALL real_to_scaled(r_pbc, r, cell)
578 l_right = nint(r_pbc(3)*real(pw_grid%npts(3), kind=dp)) + pw_grid%bounds(1, 3)
579 IF (l_right > pw_grid%bounds(2, 3)) l_right = pw_grid%bounds(2, 3)
580
581 cpassert(u_left <= l_right)
582
583 v_average_left = v_hartree_z_average(u_left)
584 v_average_right = v_hartree_z_average(l_right)
585
586 ! align electrostatic potential of leads' regions with ones from bulk transport calculation
587 IF (isexplicit_bottom) THEN
588 v_hartree_z_average(:) = hartreeleadsbottom*pw_grid%dvol - 0.5_dp*(v_average_left + v_average_right)
589 ELSE
590 ! do not align electrostatic potential
591 v_hartree_z_average(:) = 0.0_dp
592 END IF
593
594 ! external Vbias
595 ! TO DO: convert zright and zleft to scaled coordinates instead
596 DO iz = lz, uz
597 r_pbc(1) = 0.0_dp
598 r_pbc(2) = 0.0_dp
599 r_pbc(3) = real(iz - pw_grid%bounds(1, 3), kind=dp)/real(pw_grid%npts(3), kind=dp)
600 CALL scaled_to_real(r, r_pbc, cell)
601 IF (r(3) < zleft) THEN
602 v_bias_iz = 0.5_dp*vbias
603 ELSE IF (r(3) > zright_explicit) THEN
604 v_bias_iz = -0.5_dp*vbias
605 ELSE
606 v_bias_iz = vbias*(0.5_dp - (r(3) - zleft)/(zright_explicit - zleft))
607 END IF
608 v_hartree_z_average(iz) = v_hartree_z_average(iz) + v_bias_iz*pw_grid%dvol
609 END DO
610
611 DO iz = lz, uz
612 cr3d(:, :, iz) = cr3d(:, :, iz) + v_hartree_z_average(iz)
613 END DO
614
615 DEALLOCATE (v_hartree_z_average)
616 CALL timestop(handle)
617 END SUBROUTINE smeagol_shift_v_hartree
618
619! **************************************************************************************************
620!> \brief Run NEGF/SMEAGOL transport calculation.
621!> \param qs_env QuickStep environment
622!> \param last converged SCF iterations; compute NEGF properties [in]
623!> \param iter index of the current iteration [in]
624!> \param rho_ao_kp refined electron density; to be mixed with electron density from the previous
625!> SCF iteration [out]
626! **************************************************************************************************
627 SUBROUTINE run_smeagol_emtrans(qs_env, last, iter, rho_ao_kp)
628 TYPE(qs_environment_type), POINTER :: qs_env
629 LOGICAL, INTENT(in) :: last
630 INTEGER, INTENT(in) :: iter
631 TYPE(dbcsr_p_type), DIMENSION(:, :), OPTIONAL, &
632 POINTER :: rho_ao_kp
633
634 CHARACTER(LEN=*), PARAMETER :: routinen = 'run_smeagol_emtrans'
635
636 INTEGER :: handle, img, ispin, md_step, natoms, &
637 nimages, nspin
638 INTEGER, DIMENSION(2) :: max_ij_cell_image, n_cell_images
639 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
640 LOGICAL :: do_kpoints, local_ldos, local_trcoeff, &
641 negfon_saved, structure_changed
642 REAL(kind=dp) :: h_to_ry
643 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: matrix_s_csc_merged
644 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: dnew_csc_merged, enew_csc_merged, &
645 matrix_ks_csc_merged
646 TYPE(cell_type), POINTER :: ucell
647 TYPE(cp_logger_type), POINTER :: logger
648 TYPE(dbcsr_p_type), ALLOCATABLE, DIMENSION(:) :: matrix_kp_generic
649 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks_kp, matrix_s_kp, matrix_w_kp
650 TYPE(dft_control_type), POINTER :: dft_control
651 TYPE(kpoint_type), POINTER :: kpoints
652 TYPE(mp_para_env_type), POINTER :: para_env
653 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
654 POINTER :: sab_nl
655 TYPE(qs_subsys_type), POINTER :: subsys
656 TYPE(scf_control_type), POINTER :: scf_control
657 TYPE(siesta_distrib_csc_struct_type) :: siesta_struct_merged
658 TYPE(smeagol_control_type), POINTER :: smeagol_control
659
660 logger => cp_get_default_logger()
661
662 CALL get_qs_env(qs_env, dft_control=dft_control)
663
664 nspin = dft_control%nspins
665 smeagol_control => dft_control%smeagol_control
666 h_to_ry = smeagol_control%to_smeagol_energy_units
667
668 IF (.NOT. (smeagol_control%smeagol_enabled .AND. smeagol_control%run_type == smeagol_runtype_emtransport)) RETURN
669 CALL timeset(routinen, handle)
670
671 NULLIFY (kpoints, matrix_s_kp, matrix_ks_kp, matrix_w_kp, para_env, sab_nl, scf_control, subsys)
672#if defined(__SMEAGOL)
673 CALL cite_reference(ahart2024)
674 CALL cite_reference(bailey2006)
675
676 cpassert(ASSOCIATED(smeagol_control%aux))
677 CALL get_qs_env(qs_env, para_env=para_env, scf_control=scf_control, &
678 do_kpoints=do_kpoints, kpoints=kpoints, &
679 matrix_ks_kp=matrix_ks_kp, matrix_s_kp=matrix_s_kp, matrix_w_kp=matrix_w_kp, &
680 sab_orb=sab_nl, subsys=subsys)
681 CALL qs_subsys_get(subsys, cell=ucell, natom=natoms)
682
683 IF (do_kpoints) THEN
684 nimages = dft_control%nimages
685 CALL get_kpoint_info(kpoints, cell_to_index=cell_to_index)
686 ELSE
687 nimages = 1
688 ALLOCATE (cell_to_index(0:0, 0:0, 0:0))
689 cell_to_index(0, 0, 0) = 1
690 END IF
691
692 max_ij_cell_image(:) = -1
693 DO img = 1, 2
694 IF (smeagol_control%n_cell_images(img) > 0) THEN
695 max_ij_cell_image(img) = smeagol_control%n_cell_images(img)/2
696 END IF
697 END DO
698
699 ! obtain the sparsity pattern of the Kohn-Sham matrix
700 ALLOCATE (matrix_kp_generic(nimages))
701 DO img = 1, nimages
702 matrix_kp_generic(img)%matrix => matrix_s_kp(1, img)%matrix
703 END DO
704
705 CALL siesta_struct_create(siesta_struct_merged, matrix_kp_generic, subsys, &
706 cell_to_index, sab_nl, para_env, max_ij_cell_image, do_merge=.true., gather_root=-1)
707
708 ! Number of unit cells along (x and y ?) directions
709 n_cell_images(1:2) = 2*max_ij_cell_image(1:2) + 1
710
711 ALLOCATE (matrix_s_csc_merged(siesta_struct_merged%n_nonzero_elements))
712 ALLOCATE (matrix_ks_csc_merged(siesta_struct_merged%n_nonzero_elements, nspin))
713
714 CALL convert_dbcsr_to_distributed_siesta(matrix_s_csc_merged, matrix_kp_generic, siesta_struct_merged, para_env)
715
716 DO ispin = 1, nspin
717 DO img = 1, nimages
718 matrix_kp_generic(img)%matrix => matrix_ks_kp(ispin, img)%matrix
719 END DO
720
721 CALL convert_dbcsr_to_distributed_siesta(matrix_ks_csc_merged(:, ispin), matrix_kp_generic, &
722 siesta_struct_merged, para_env)
723 END DO
724
725 IF (smeagol_control%aux%md_iter_level > 0) THEN
726 CALL cp_get_iter_nr(logger%iter_info, smeagol_control%aux%md_iter_level, iter_nr=md_step)
727 ELSE IF (smeagol_control%aux%md_iter_level == 0) THEN
728 ! single-point energy calculation : there is only one MD step in this case
729 md_step = smeagol_control%aux%md_first_step
730 ELSE
731 ! first invocation of the subroutine : initialise md_iter_level and md_first_step variables
732 smeagol_control%aux%md_iter_level = cp_get_iter_level_by_name(logger%iter_info, "MD")
733
734 IF (smeagol_control%aux%md_iter_level <= 0) &
735 smeagol_control%aux%md_iter_level = cp_get_iter_level_by_name(logger%iter_info, "GEO_OPT")
736
737 IF (smeagol_control%aux%md_iter_level <= 0) &
738 smeagol_control%aux%md_iter_level = 0
739
740 ! index of the first GEO_OPT / MD step
741 IF (smeagol_control%aux%md_iter_level > 0) THEN
742 CALL cp_get_iter_nr(logger%iter_info, smeagol_control%aux%md_iter_level, iter_nr=smeagol_control%aux%md_first_step)
743 ELSE
744 ! it has already been initialised in read_smeagol_control()
745 smeagol_control%aux%md_first_step = 0
746 END IF
747
748 md_step = smeagol_control%aux%md_first_step
749 END IF
750
751 CALL reademtr(smeagol_control, natoms, gamma_negf=.false.)
752 CALL readoptionsnegf_dft(smeagol_control, ucell, torqueflag=.false., torquelin=.false.)
753
754 CALL emtrans_options(smeagol_control, &
755 matrix_s=matrix_s_kp(1, 1)%matrix, para_env=para_env, iter=iter, &
756 istep=md_step, inicoor=smeagol_control%aux%md_first_step, iv=0, &
757 delta=smeagol_control%aux%delta, nk=kpoints%nkp)
758
759 CALL create_communicators_negf(parent_comm=para_env%get_handle(), &
760 nprocs_inverse=smeagol_control%aux%nprocs_inverse, &
761 nparallelk=smeagol_control%aux%NParallelK)
762
763 ALLOCATE (dnew_csc_merged(siesta_struct_merged%n_nonzero_elements, nspin))
764 ALLOCATE (enew_csc_merged(siesta_struct_merged%n_nonzero_elements, nspin))
765
766 ! As SMEAGOL's default energy unit is Rydberg, scale the KS-matrix
767 matrix_ks_csc_merged(:, :) = h_to_ry*matrix_ks_csc_merged(:, :)
768
769 ! SMEAGOL computes current if EM.OrderN = .false., otherwise the printed current is equal to 0.
770 ! The following computes current regardless the value of EM.OrderN parameter
771 IF (last) THEN
772 negfon_saved = smeagolglobal_negfon
773 smeagolglobal_negfon = .false.
774 END IF
775
776 IF (last) THEN
777 local_trcoeff = smeagol_control%aux%TrCoeff
778 local_ldos = .true. ! TO DO: find out initial value of ldos
779 ELSE
780 local_trcoeff = .false.
781 local_ldos = .false.
782 END IF
783
784 ! number of atoms in the unit cell
785 smeagolglobal_em_nau = natoms ! number of atoms in the unit cell
786
787 ! number of atomic orbitals in the unit cell.
788 ! This global variable defines the size of temporary arrays for (P)DOS calculation.
789 ! This should be the total number of the atomic orbitals in the unit cell,
790 ! instead of the number of atomic orbitals local to the current MPI process.
791 smeagolglobal_em_nuo = siesta_struct_merged%ncols/(n_cell_images(1)*n_cell_images(2))
792
793 ! number of atoms in the super cell
794 smeagolglobal_em_nas = SIZE(siesta_struct_merged%xa)
795
796 ! number of atomic orbitals in the super cell
797 smeagolglobal_em_nso = siesta_struct_merged%ncols
798
799 ! The following global variables are only used in writephibin() which is not called by this interface
800 ! smeagolglobal_em_isa => isa
801 ! smeagolglobal_em_iaorb => iaorb
802 ! smeagolglobal_em_iphorb => iphorb
803
804 structure_changed = (iter == 1)
805
806 CALL negf_interface( &
807 ! distributed Kohn-Sham, overlap, density, and energy-density matrices in SIESTA format
808 h=matrix_ks_csc_merged, &
809 s=matrix_s_csc_merged, &
810 dm=dnew_csc_merged, &
811 omega=enew_csc_merged, &
812 ! interatomic distances for each non-zero matrix element
813 xij=siesta_struct_merged%xij, &
814 ! number of atomic orbitals in a supercell
815 no_s=siesta_struct_merged%ncols, &
816 ! number of atomic orbitals in the unit cell
817 no_u=siesta_struct_merged%ncols/(n_cell_images(1)*n_cell_images(2)), &
818 ! number of AOs local to the given MPI process
819 no_u_node=siesta_struct_merged%nrows, &
820 ! atomic coordinates for each atom in the supercell
821 xa=siesta_struct_merged%xa, &
822 ! unused dummy variable na_u
823 na_u=natoms, &
824 ! number of atoms in the supercell
825 na_s=SIZE(siesta_struct_merged%xa), &
826 ! number of spin-components
827 nspinrealinputmatrix=nspin, &
828 ! number of non-zero matrix element
829 maxnh=int(siesta_struct_merged%n_nonzero_elements), &
830 ! number of non-zero matrix elements on each locally stored row
831 numh=siesta_struct_merged%n_nonzero_cols, &
832 ! offset (index-1) of first non-zero matrix elements on each locally stored row
833 listhptr=siesta_struct_merged%row_offset, &
834 ! column number (AO index) for each non-zero matrix element
835 listh=siesta_struct_merged%col_index, &
836 ! number of k-points
837 nkpts=kpoints%nkp, &
838 ! k-point coordinates
839 kpoint=kpoints%xkp, &
840 ! k-point weight
841 weight_k=kpoints%wkp, &
842 ! index of equivalent atomic orbital within the primary unit cell for each AO in the supercell
843 indxuo=siesta_struct_merged%indxuo, &
844 ! list of atomic indices on which each AO (in the supercell) is centred
845 iaorb=siesta_struct_merged%iaorb, &
846 ! GEO_OPT / MD step index
847 md_step=md_step, &
848 ! GEO_OPT / MD at which SMEAGOL should allocate its internal data structures
849 inicoor=smeagol_control%aux%md_first_step, &
850 ! ivv (step over bias, first IV step should always be 0 (hardcoded in SMEAGOL)
851 ! we iterate over GEO_OPT / MD steps instead of bias steps in order not to overwrite
852 ! TRC (Transmission coefficients) files
853 iv_step=md_step - smeagol_control%aux%md_first_step, &
854 ! applied electrostatic bias
855 vb=smeagol_control%aux%VBias*h_to_ry, &
856 ! index of the currect SCF iteration
857 scf_step=iter, &
858 ! compute density matrix (.FALSE.) or properties (.TRUE.)
859 last_scf_step=last, &
860 ! recompute self-energy matrices
861 structurechanged=structure_changed, &
862 ! electronic temperature in Ry
863 temp=smeagol_control%aux%temperature*h_to_ry, &
864 ! number of unit cell replicas along i-, and j- cell verctors
865 nsc=n_cell_images, &
866 ! name of SMEAGOL project (partial file name for files created by SMEAGOL)
867 slabel=smeagol_control%project_name, &
868 ! number of integration points along real axis, circular path and a line in imaginary space parallel to the real axis
869 nenergr=smeagol_control%aux%NEnergR, &
870 nenergic=smeagol_control%aux%NEnergIC, &
871 nenergil=smeagol_control%aux%NEnergIL, &
872 ! number of poles
873 npoles=smeagol_control%aux%NPoles, &
874 ! small imaginary shift that makes matrix inversion computationally stable
875 delta=smeagol_control%aux%deltamin*h_to_ry, &
876 ! integration lower bound
877 energlb=smeagol_control%aux%EnergLB*h_to_ry, &
878 ! [unused dummy arguments] initial (VInitial) and final (VFinal) voltage
879 vinitial=smeagol_control%aux%VBias, &
880 vfinal=smeagol_control%aux%VBias, &
881 !
882 spincl=smeagol_control%aux%SpinCL, &
883 ! number of slices for OrderN matrix inversion
884 nslices=smeagol_control%aux%NSlices, &
885 ! whether to compute transmission coefficients (TrCoeff), IETS spectrum (CalcIETS), and local Dnsity-of-States (ldos)
886 trcoeff=local_trcoeff, &
887 calciets=smeagol_control%aux%CalcIETS, &
888 ldos=local_ldos, &
889 ! Transmission coefficients are only computed for certain runtypes (encoded with magic numbers).
890 ! In case of idyn=0, transmission coefficients are always computed.
891 idyn=0, &
892 ! do not compute transmission coefficient for initial GEO_OPT / MD iterations
893 tmdskip=smeagol_control%aux%tmdskip, &
894 ! computes transmission coefficients once for each 'tmdsampling' MD iterations
895 tmdsampling=smeagol_control%aux%tmdsampling)
896
897 ! *** Bound-state correction method ***
898
899 ! smeagol_control%bs_add : BS.Add (.FALSE.) ; add bound states
900 ! smeagol_control%bs_method : BS.Method (0) ; 0 - use effective Hamiltonian; 1 - add small imaginary part to the selfenergies
901 ! smeagol_control%bssc : BS.SetOccupation (1)
902 IF (smeagol_control%aux%bs_add .AND. smeagol_control%aux%bs_method == 1 .AND. smeagol_control%aux%bssc == 0 .AND. &
903 kpoints%nkp > 1 .AND. (.NOT. last)) THEN
904
905 CALL negf_interface(h=matrix_ks_csc_merged, &
906 s=matrix_s_csc_merged, &
907 dm=dnew_csc_merged, &
908 omega=enew_csc_merged, &
909 xij=siesta_struct_merged%xij, &
910 no_s=siesta_struct_merged%ncols, &
911 no_u=siesta_struct_merged%ncols/(n_cell_images(1)*n_cell_images(2)), &
912 no_u_node=siesta_struct_merged%nrows, &
913 xa=siesta_struct_merged%xa, &
914 ! unused dummy variable
915 na_u=natoms, &
916 na_s=SIZE(siesta_struct_merged%xa), &
917 nspinrealinputmatrix=nspin, &
918 maxnh=int(siesta_struct_merged%n_nonzero_elements), &
919 numh=siesta_struct_merged%n_nonzero_cols, &
920 listhptr=siesta_struct_merged%row_offset, &
921 listh=siesta_struct_merged%col_index, &
922 nkpts=kpoints%nkp, &
923 kpoint=kpoints%xkp, &
924 weight_k=kpoints%wkp, &
925 indxuo=siesta_struct_merged%indxuo, &
926 iaorb=siesta_struct_merged%iaorb, &
927 md_step=md_step, &
928 inicoor=smeagol_control%aux%md_first_step, &
929 iv_step=md_step - smeagol_control%aux%md_first_step, &
930 vb=smeagol_control%aux%VBias*h_to_ry, &
931 ! This line is the only difference from the first Negf_Interface() call
932 scf_step=merge(2, 1, structure_changed), &
933 last_scf_step=last, &
934 structurechanged=structure_changed, &
935 temp=smeagol_control%aux%temperature*h_to_ry, &
936 nsc=n_cell_images, &
937 slabel=smeagol_control%project_name, &
938 nenergr=smeagol_control%aux%NEnergR, &
939 nenergic=smeagol_control%aux%NEnergIC, &
940 nenergil=smeagol_control%aux%NEnergIL, &
941 npoles=smeagol_control%aux%NPoles, &
942 delta=smeagol_control%aux%deltamin*h_to_ry, &
943 energlb=smeagol_control%aux%EnergLB*h_to_ry, &
944 ! unused dummy variable
945 vinitial=smeagol_control%aux%VBias, &
946 ! unused dummy variable
947 vfinal=smeagol_control%aux%VBias, &
948 spincl=smeagol_control%aux%SpinCL, &
949 nslices=smeagol_control%aux%NSlices, &
950 trcoeff=local_trcoeff, &
951 calciets=smeagol_control%aux%CalcIETS, &
952 ldos=local_ldos, &
953 idyn=0, & !
954 tmdskip=smeagol_control%aux%tmdskip, &
955 tmdsampling=smeagol_control%aux%tmdsampling)
956 END IF
957
958 ! Restore ovewriten EM.OrderN parameter
959 IF (last) THEN
960 smeagolglobal_negfon = negfon_saved
961 END IF
962
963 IF (PRESENT(rho_ao_kp)) THEN
964 DO ispin = 1, nspin
965 DO img = 1, nimages
966 ! To be on a safe size, zeroize the new density matrix first. It is not actually needed.
967 CALL dbcsr_set(rho_ao_kp(ispin, img)%matrix, 0.0_dp)
968 matrix_kp_generic(img)%matrix => rho_ao_kp(ispin, img)%matrix
969 END DO
970
971 CALL convert_distributed_siesta_to_dbcsr(matrix_kp_generic, dnew_csc_merged(:, ispin), &
972 siesta_struct_merged, para_env)
973 END DO
974
975 ! current-induced forces
976 IF (smeagol_control%emforces) THEN
977 enew_csc_merged(:, :) = (1.0_dp/h_to_ry)*enew_csc_merged(:, :)
978
979 DO ispin = 1, nspin
980 DO img = 1, nimages
981 ! To be on a safe size, zeroize the new energy-density matrix first. It is not actually needed.
982 CALL dbcsr_set(matrix_w_kp(ispin, img)%matrix, 0.0_dp)
983 matrix_kp_generic(img)%matrix => matrix_w_kp(ispin, img)%matrix
984 END DO
985
986 CALL convert_distributed_siesta_to_dbcsr(matrix_kp_generic, enew_csc_merged(:, ispin), &
987 siesta_struct_merged, para_env)
988 END DO
989 END IF
990 END IF
991
992 CALL destroy_communicators_negf()
994
995 DEALLOCATE (dnew_csc_merged, enew_csc_merged)
996 DEALLOCATE (matrix_s_csc_merged, matrix_ks_csc_merged)
997
998 CALL siesta_struct_release(siesta_struct_merged)
999
1000 IF (.NOT. do_kpoints) DEALLOCATE (cell_to_index)
1001#else
1002 CALL cp_abort(__location__, &
1003 "CP2K was compiled with no SMEAGOL support.")
1004 mark_used(last)
1005 mark_used(iter)
1006 mark_used(rho_ao_kp)
1007 ! local variables
1008 mark_used(cell_to_index)
1009 mark_used(do_kpoints)
1010 mark_used(dnew_csc_merged)
1011 mark_used(enew_csc_merged)
1012 mark_used(img)
1013 mark_used(ispin)
1014 mark_used(local_ldos)
1015 mark_used(local_trcoeff)
1016 mark_used(max_ij_cell_image)
1017 mark_used(matrix_kp_generic)
1018 mark_used(matrix_ks_csc_merged)
1019 mark_used(matrix_s_csc_merged)
1020 mark_used(md_step)
1021 mark_used(natoms)
1022 mark_used(negfon_saved)
1023 mark_used(nimages)
1024 mark_used(n_cell_images)
1025 mark_used(siesta_struct_merged)
1026 mark_used(structure_changed)
1027 mark_used(ucell)
1028#endif
1029
1030 CALL timestop(handle)
1031 END SUBROUTINE run_smeagol_emtrans
1032
1033END MODULE smeagol_interface
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public bailey2006
integer, save, public ahart2024
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public scaled_to_real(r, s, cell)
Transform scaled cell coordinates real coordinates. r=h*s.
Definition cell_types.F:516
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
Definition cell_types.F:486
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_set(matrix, alpha)
...
DBCSR operations in CP2K.
Utility routines to open and close files. Tracking of preconnections.
Definition cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition cp_files.F:308
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Definition cp_files.F:119
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_get_iter_level_by_name(iteration_info, level_name)
Return the index of an iteration level by its name.
subroutine, public cp_get_iter_nr(iteration_info, rlevel, iter_nr, last_iter)
Return the current iteration number at a given level.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public smeagol_runtype_emtransport
integer, parameter, public smeagol_bulklead_leftright
integer, parameter, public smeagol_bulklead_left
integer, parameter, public smeagol_bulklead_right
integer, parameter, public smeagol_runtype_bulktransport
sums arrays of real/complex numbers with much reduced round-off as compared to a naive implementation...
Definition kahan_sum.F:29
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
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.
Interface to the message passing library MPI.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public evolt
Definition physcon.F:183
real(kind=dp), parameter, public bohr
Definition physcon.F:147
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.
subroutine, public set_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, vppl, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, kpoints, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, task_list, task_list_soft, subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env)
...
Utility subroutine for qs energy calculation.
Definition qs_matrix_w.F:14
subroutine, public compute_matrix_w(qs_env, calc_forces)
Refactoring of qs_energies_scf. Moves computation of matrix_w into separate subroutine.
Definition qs_matrix_w.F:62
Define the neighbor list data types and the corresponding functionality.
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...
types that represent a quickstep subsys
subroutine, public qs_subsys_get(subsys, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell, energy, force, qs_kind_set, cp_subsys, nelectron_total, nelectron_spin)
...
parameters that control an scf iteration
Input control types for NEGF/SMEAGOL transport calculations.
CP2K+SMEAGOL interface.
subroutine, public readoptionsnegf_dft(smeagol_control, ucell, torqueflag, torquelin)
subroutine, public reademtr(smeagol_control, natoms, gamma_negf)
subroutine, public emtrans_deallocate_global_arrays()
subroutine, public emtrans_options(smeagol_control, matrix_s, para_env, iter, istep, inicoor, iv, delta, nk)
CP2K+SMEAGOL interface.
subroutine, public run_smeagol_emtrans(qs_env, last, iter, rho_ao_kp)
Run NEGF/SMEAGOL transport calculation.
subroutine, public run_smeagol_bulktrans(qs_env)
Save overlap, Kohn-Sham, electron density, and energy-density matrices of semi-infinite electrodes in...
subroutine, public smeagol_shift_v_hartree(v_hartree_rspace, cell, hartreeleadsleft, hartreeleadsright, hartreeleadsbottom, vbias, zleft, zright, isexplicit_zright, isexplicit_bottom)
Align Hatree potential of semi-infinite leads to match bulk-transport calculation and apply external ...
Routines to convert sparse matrices between DBCSR (distributed-blocks compressed sparse rows) and SIE...
subroutine, public siesta_struct_release(siesta_struct)
Release a SIESTA matrix structure.
subroutine, public siesta_struct_create(siesta_struct, matrix_dbcsr_kp, subsys, cell_to_index, sab_nl, para_env, max_ij_cell_image, do_merge, gather_root)
Map non-zero matrix blocks between sparse matrices in DBCSR and SIESTA formats.
subroutine, public convert_distributed_siesta_to_dbcsr(matrix_dbcsr_kp, matrix_siesta, siesta_struct, para_env)
Convert matrix from DBCSR to sparse SIESTA format.
subroutine, public convert_dbcsr_to_distributed_siesta(matrix_siesta, matrix_dbcsr_kp, siesta_struct, para_env)
Convert matrix from DBCSR to sparse SIESTA format.
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
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.
stores all the informations relevant to an mpi environment
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.
Sparsity pattern of replicated SIESTA compressed sparse column (CSC) matrices.