Line data Source code
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 Input control types for NEGF based quantum transport calculations
10 : ! **************************************************************************************************
11 :
12 : MODULE negf_control_types
13 : USE cp_subsys_types, ONLY: cp_subsys_get,&
14 : cp_subsys_type
15 : USE input_constants, ONLY: negf_run
16 : USE input_section_types, ONLY: section_vals_get,&
17 : section_vals_get_subs_vals,&
18 : section_vals_type,&
19 : section_vals_val_get
20 : USE kinds, ONLY: default_string_length,&
21 : dp
22 : USE mathconstants, ONLY: pi
23 : USE molecule_kind_types, ONLY: get_molecule_kind,&
24 : molecule_kind_type
25 : USE molecule_types, ONLY: get_molecule,&
26 : molecule_type
27 : USE negf_alloc_types, ONLY: negf_allocatable_ivector
28 : USE particle_types, ONLY: particle_type
29 : USE physcon, ONLY: kelvin
30 : USE string_utilities, ONLY: integer_to_string
31 : USE util, ONLY: sort
32 : #include "./base/base_uses.f90"
33 :
34 : IMPLICIT NONE
35 : PRIVATE
36 :
37 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'negf_control_types'
38 : LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .TRUE.
39 :
40 : PUBLIC :: negf_control_type, negf_control_contact_type
41 : PUBLIC :: negf_control_create, negf_control_release, read_negf_control
42 :
43 : ! **************************************************************************************************
44 : !> \brief Input parameters related to a single contact.
45 : !> \author Sergey Chulkov
46 : ! **************************************************************************************************
47 : TYPE negf_control_contact_type
48 : !> atoms belonging to bulk and screening regions
49 : INTEGER, ALLOCATABLE, DIMENSION(:) :: atomlist_bulk, atomlist_screening
50 : !> atoms belonging to the primary and secondary bulk unit cells
51 : TYPE(negf_allocatable_ivector), ALLOCATABLE, &
52 : DIMENSION(:) :: atomlist_cell
53 : !> index of the sub_force_env which should be used for bulk calculation
54 : INTEGER :: force_env_index = -1
55 : !> contact Fermi level needs to be computed
56 : LOGICAL :: compute_fermi_level = .FALSE.
57 : !> to refine contact Fermi level using NEGF
58 : LOGICAL :: refine_fermi_level = .FALSE.
59 : !> to shift energies to common zero level
60 : LOGICAL :: shift_fermi_level = .FALSE.
61 : !> to read/write H and S from/to file
62 : LOGICAL :: read_write_HS = .FALSE.
63 : !> if restart from files is really done
64 : LOGICAL :: is_restart = .FALSE.
65 : !> Fermi level or starting Fermi level
66 : REAL(kind=dp) :: fermi_level = -1.0_dp
67 : !> Fermi level shifted to the common zero-energy level
68 : REAL(kind=dp) :: fermi_level_shifted = -1.0_dp
69 : !> temperature [in a.u.]
70 : REAL(kind=dp) :: temperature = -1.0_dp
71 : !> applied electric potential
72 : REAL(kind=dp) :: v_external = 0.0_dp
73 : END TYPE negf_control_contact_type
74 :
75 : ! **************************************************************************************************
76 : !> \brief Input parameters related to the NEGF run.
77 : !> \author Sergey Chulkov
78 : ! **************************************************************************************************
79 : TYPE negf_control_type
80 : !> input options for every contact
81 : TYPE(negf_control_contact_type), ALLOCATABLE, &
82 : DIMENSION(:) :: contacts
83 : !> atoms belonging to the scattering region
84 : INTEGER, ALLOCATABLE, DIMENSION(:) :: atomlist_S
85 : !> atoms belonging to the scattering region as well as atoms belonging to
86 : !> screening regions of all the contacts
87 : INTEGER, ALLOCATABLE, DIMENSION(:) :: atomlist_S_screening
88 : !> to read/write H and S from/to file
89 : LOGICAL :: read_write_HS = .FALSE.
90 : !> to update the atomic Hamiltonian during NEGF self-consistent cycle
91 : LOGICAL :: update_HS = .TRUE.
92 : !> if NEGF SCF id restart from saved files
93 : LOGICAL :: restart_scf = .TRUE.
94 : !> if dft of entire system is done
95 : LOGICAL :: is_dft_entire = .FALSE.
96 : !> if restart from files is really done
97 : LOGICAL :: is_restart = .FALSE.
98 : !> the common restart file projectname-negf.restart is written if any of is_restart is .TRUE.
99 : LOGICAL :: write_common_restart_file = .FALSE.
100 : !> do not keep contact self-energy matrices
101 : LOGICAL :: disable_cache = .FALSE.
102 : !> convergence criteria for adaptive integration methods
103 : REAL(kind=dp) :: conv_density = -1.0_dp
104 : !> convergence criteria for iterative Lopez-Sancho algorithm
105 : REAL(kind=dp) :: conv_green = -1.0_dp
106 : !> convergence criteria for self-consistent iterations
107 : REAL(kind=dp) :: conv_scf = -1.0_dp
108 : !> accuracy in mapping atoms between different force environments
109 : REAL(kind=dp) :: eps_geometry = -1.0_dp
110 : !> applied bias [in a.u.]
111 : REAL(kind=dp) :: v_bias = -1.0_dp
112 : !> integration lower bound [in a.u.]
113 : REAL(kind=dp) :: energy_lbound = -1.0_dp
114 : !> infinitesimal offset along the imaginary axis [in a.u.]
115 : REAL(kind=dp) :: eta = -1.0_dp
116 : !> initial guess to determine the actual Fermi level of bulk contacts [in a.u.]
117 : REAL(kind=dp) :: homo_lumo_gap = -1.0_dp
118 : !> number of residuals (poles of the Fermi function)
119 : INTEGER :: delta_npoles = -1
120 : !> offset along the x-axis away from the poles of the Fermi function [in units of kT]
121 : INTEGER :: gamma_kT = -1
122 : !> integration method
123 : INTEGER :: integr_method = -1
124 : !> minimal number of grid points along the closed contour
125 : INTEGER :: integr_min_points = -1
126 : !> maximal number of grid points along the closed contour
127 : INTEGER :: integr_max_points = -1
128 : !> maximal number of SCF iterations
129 : INTEGER :: max_scf = -1
130 : !> minimal number of MPI processes to be used to compute Green's function per energy point
131 : INTEGER :: nprocs = -1
132 : !> shift in Hartree potential [in a.u.]
133 : REAL(kind=dp) :: v_shift = -1.0_dp
134 : !> initial offset to determine the correct shift in Hartree potential [in a.u.]
135 : REAL(kind=dp) :: v_shift_offset = -1.0_dp
136 : !> maximal number of iteration to determine the shift in Hartree potential
137 : INTEGER :: v_shift_maxiters = -1
138 : END TYPE negf_control_type
139 :
140 : PRIVATE :: read_negf_atomlist
141 :
142 : CONTAINS
143 :
144 : ! **************************************************************************************************
145 : !> \brief allocate control options for Non-equilibrium Green's Function calculation
146 : !> \param negf_control an object to create
147 : !> \par History
148 : !> * 02.2017 created [Sergey Chulkov]
149 : ! **************************************************************************************************
150 8 : SUBROUTINE negf_control_create(negf_control)
151 : TYPE(negf_control_type), POINTER :: negf_control
152 :
153 : CHARACTER(len=*), PARAMETER :: routineN = 'negf_control_create'
154 :
155 : INTEGER :: handle
156 :
157 4 : CPASSERT(.NOT. ASSOCIATED(negf_control))
158 4 : CALL timeset(routineN, handle)
159 :
160 4 : ALLOCATE (negf_control)
161 :
162 4 : CALL timestop(handle)
163 4 : END SUBROUTINE negf_control_create
164 :
165 : ! **************************************************************************************************
166 : !> \brief release memory allocated for NEGF control options
167 : !> \param negf_control an object to release
168 : !> \par History
169 : !> * 02.2017 created [Sergey Chulkov]
170 : ! **************************************************************************************************
171 4 : SUBROUTINE negf_control_release(negf_control)
172 : TYPE(negf_control_type), POINTER :: negf_control
173 :
174 : CHARACTER(len=*), PARAMETER :: routineN = 'negf_control_release'
175 :
176 : INTEGER :: handle, i, j
177 :
178 4 : CALL timeset(routineN, handle)
179 :
180 4 : IF (ASSOCIATED(negf_control)) THEN
181 4 : IF (ALLOCATED(negf_control%atomlist_S)) DEALLOCATE (negf_control%atomlist_S)
182 4 : IF (ALLOCATED(negf_control%atomlist_S_screening)) DEALLOCATE (negf_control%atomlist_S_screening)
183 :
184 4 : IF (ALLOCATED(negf_control%contacts)) THEN
185 12 : DO i = SIZE(negf_control%contacts), 1, -1
186 8 : IF (ALLOCATED(negf_control%contacts(i)%atomlist_bulk)) &
187 8 : DEALLOCATE (negf_control%contacts(i)%atomlist_bulk)
188 :
189 8 : IF (ALLOCATED(negf_control%contacts(i)%atomlist_screening)) &
190 8 : DEALLOCATE (negf_control%contacts(i)%atomlist_screening)
191 :
192 12 : IF (ALLOCATED(negf_control%contacts(i)%atomlist_cell)) THEN
193 24 : DO j = SIZE(negf_control%contacts(i)%atomlist_cell), 1, -1
194 16 : IF (ALLOCATED(negf_control%contacts(i)%atomlist_cell(j)%vector)) &
195 24 : DEALLOCATE (negf_control%contacts(i)%atomlist_cell(j)%vector)
196 : END DO
197 24 : DEALLOCATE (negf_control%contacts(i)%atomlist_cell)
198 : END IF
199 : END DO
200 :
201 12 : DEALLOCATE (negf_control%contacts)
202 : END IF
203 :
204 4 : DEALLOCATE (negf_control)
205 : END IF
206 :
207 4 : CALL timestop(handle)
208 4 : END SUBROUTINE negf_control_release
209 :
210 : ! **************************************************************************************************
211 : !> \brief Read NEGF input parameters.
212 : !> \param negf_control NEGF control parameters
213 : !> \param input root input section
214 : !> \param subsys subsystem environment
215 : ! **************************************************************************************************
216 4 : SUBROUTINE read_negf_control(negf_control, input, subsys)
217 : TYPE(negf_control_type), POINTER :: negf_control
218 : TYPE(section_vals_type), POINTER :: input
219 : TYPE(cp_subsys_type), POINTER :: subsys
220 :
221 : CHARACTER(len=*), PARAMETER :: routineN = 'read_negf_control'
222 :
223 : CHARACTER(len=default_string_length) :: contact_id_str, eta_current_str, eta_max_str, &
224 : npoles_current_str, npoles_min_str, temp_current_str, temp_min_str
225 : INTEGER :: delta_npoles_min, handle, i2_rep, i_rep, &
226 : n2_rep, n_rep, natoms_current, &
227 : natoms_total, run_type
228 4 : INTEGER, ALLOCATABLE, DIMENSION(:) :: inds
229 : LOGICAL :: do_negf, is_explicit
230 : REAL(kind=dp) :: eta_max, temp_current, temp_min
231 : TYPE(section_vals_type), POINTER :: cell_section, contact_section, &
232 : negf_section, region_section, &
233 : subsection
234 :
235 4 : CALL timeset(routineN, handle)
236 :
237 4 : CALL section_vals_val_get(input, "GLOBAL%RUN_TYPE", i_val=run_type)
238 4 : do_negf = run_type == negf_run
239 :
240 4 : negf_section => section_vals_get_subs_vals(input, "NEGF")
241 :
242 4 : contact_section => section_vals_get_subs_vals(negf_section, "CONTACT")
243 4 : CALL section_vals_get(contact_section, n_repetition=n_rep, explicit=is_explicit)
244 4 : IF ((.NOT. is_explicit) .AND. do_negf) THEN
245 : CALL cp_abort(__LOCATION__, &
246 0 : "At least one contact is needed for NEGF calculation.")
247 : END IF
248 :
249 20 : ALLOCATE (negf_control%contacts(n_rep))
250 12 : DO i_rep = 1, n_rep
251 8 : region_section => section_vals_get_subs_vals(contact_section, "SCREENING_REGION", i_rep_section=i_rep)
252 8 : CALL section_vals_get(region_section, explicit=is_explicit)
253 :
254 8 : IF ((.NOT. is_explicit) .AND. do_negf) THEN
255 0 : WRITE (contact_id_str, '(I11)') i_rep
256 : CALL cp_abort(__LOCATION__, &
257 0 : "The screening region must be defined for the contact "//TRIM(ADJUSTL(contact_id_str))//".")
258 : END IF
259 :
260 8 : IF (is_explicit) THEN
261 8 : CALL read_negf_atomlist(negf_control%contacts(i_rep)%atomlist_screening, region_section, 1, subsys)
262 : END IF
263 :
264 8 : region_section => section_vals_get_subs_vals(contact_section, "BULK_REGION", i_rep_section=i_rep)
265 :
266 8 : CALL section_vals_get(region_section, explicit=is_explicit)
267 :
268 8 : IF ((.NOT. is_explicit) .AND. do_negf) THEN
269 0 : WRITE (contact_id_str, '(I11)') i_rep
270 : CALL cp_abort(__LOCATION__, &
271 0 : "The bulk region must be defined for the contact "//TRIM(ADJUSTL(contact_id_str))//".")
272 : END IF
273 :
274 8 : IF (is_explicit) THEN
275 8 : CALL read_negf_atomlist(negf_control%contacts(i_rep)%atomlist_bulk, region_section, 1, subsys)
276 : END IF
277 :
278 : CALL section_vals_val_get(contact_section, "FORCE_EVAL_SECTION", &
279 : i_val=negf_control%contacts(i_rep)%force_env_index, &
280 8 : i_rep_section=i_rep)
281 :
282 8 : cell_section => section_vals_get_subs_vals(region_section, "CELL")
283 8 : CALL section_vals_get(cell_section, n_repetition=n2_rep, explicit=is_explicit)
284 :
285 8 : IF (((.NOT. is_explicit) .OR. n2_rep /= 2) .AND. negf_control%contacts(i_rep)%force_env_index <= 0 .AND. do_negf) THEN
286 0 : WRITE (contact_id_str, '(I11)') i_rep
287 : CALL cp_abort(__LOCATION__, &
288 : "You must either provide indices of atoms belonging to two adjacent bulk unit cells "// &
289 : "(BULK_REGION/CELL) for the contact, or the index of the FORCE_EVAL section (FORCE_EVAL_SECTION) "// &
290 : "which will be used to construct Kohn-Sham matrix for the bulk contact "// &
291 0 : TRIM(ADJUSTL(contact_id_str))//".")
292 : END IF
293 :
294 8 : IF (is_explicit .AND. n2_rep > 0) THEN
295 40 : ALLOCATE (negf_control%contacts(i_rep)%atomlist_cell(n2_rep))
296 :
297 24 : DO i2_rep = 1, n2_rep
298 24 : CALL read_negf_atomlist(negf_control%contacts(i_rep)%atomlist_cell(i2_rep)%vector, cell_section, i2_rep, subsys)
299 : END DO
300 : END IF
301 :
302 : CALL section_vals_val_get(contact_section, "REFINE_FERMI_LEVEL", &
303 : l_val=negf_control%contacts(i_rep)%refine_fermi_level, &
304 8 : i_rep_section=i_rep)
305 :
306 : CALL section_vals_val_get(contact_section, "FERMI_LEVEL", &
307 : r_val=negf_control%contacts(i_rep)%fermi_level, &
308 8 : i_rep_section=i_rep, explicit=is_explicit)
309 8 : IF (.NOT. is_explicit) negf_control%contacts(i_rep)%refine_fermi_level = .FALSE.
310 : negf_control%contacts(i_rep)%compute_fermi_level = (.NOT. is_explicit) .OR. &
311 8 : negf_control%contacts(i_rep)%refine_fermi_level
312 :
313 : CALL section_vals_val_get(contact_section, "FERMI_LEVEL_SHIFTED", &
314 : r_val=negf_control%contacts(i_rep)%fermi_level_shifted, &
315 8 : i_rep_section=i_rep, explicit=is_explicit)
316 8 : IF (is_explicit) negf_control%contacts(i_rep)%shift_fermi_level = .TRUE.
317 :
318 : CALL section_vals_val_get(contact_section, "TEMPERATURE", &
319 : r_val=negf_control%contacts(i_rep)%temperature, &
320 8 : i_rep_section=i_rep)
321 8 : IF (negf_control%contacts(i_rep)%temperature <= 0.0_dp) THEN
322 0 : CALL cp_abort(__LOCATION__, "Electronic temperature must be > 0")
323 : END IF
324 :
325 : CALL section_vals_val_get(contact_section, "ELECTRIC_POTENTIAL", &
326 : r_val=negf_control%contacts(i_rep)%v_external, &
327 8 : i_rep_section=i_rep)
328 :
329 8 : subsection => section_vals_get_subs_vals(contact_section, "RESTART", i_rep_section=i_rep)
330 :
331 : CALL section_vals_val_get(subsection, "READ_WRITE_HS", &
332 : l_val=negf_control%contacts(i_rep)%read_write_HS, &
333 8 : explicit=is_explicit)
334 52 : IF (is_explicit) negf_control%contacts(i_rep)%read_write_HS = .TRUE.
335 :
336 : END DO
337 :
338 4 : region_section => section_vals_get_subs_vals(negf_section, "SCATTERING_REGION")
339 4 : CALL section_vals_get(region_section, explicit=is_explicit)
340 4 : IF (is_explicit) THEN
341 4 : CALL read_negf_atomlist(negf_control%atomlist_S, region_section, 1, subsys)
342 : END IF
343 :
344 4 : subsection => section_vals_get_subs_vals(negf_section, "SCATTERING_REGION%RESTART")
345 : CALL section_vals_val_get(subsection, "READ_WRITE_HS", &
346 : l_val=negf_control%read_write_HS, &
347 4 : explicit=is_explicit)
348 4 : IF (is_explicit) negf_control%read_write_HS = .TRUE.
349 :
350 4 : CALL section_vals_val_get(negf_section, "DISABLE_CACHE", l_val=negf_control%disable_cache)
351 :
352 4 : CALL section_vals_val_get(negf_section, "EPS_DENSITY", r_val=negf_control%conv_density)
353 4 : CALL section_vals_val_get(negf_section, "EPS_GREEN", r_val=negf_control%conv_green)
354 4 : CALL section_vals_val_get(negf_section, "EPS_SCF", r_val=negf_control%conv_scf)
355 :
356 4 : CALL section_vals_val_get(negf_section, "EPS_GEO", r_val=negf_control%eps_geometry)
357 :
358 4 : CALL section_vals_val_get(negf_section, "ENERGY_LBOUND", r_val=negf_control%energy_lbound)
359 4 : CALL section_vals_val_get(negf_section, "ETA", r_val=negf_control%eta)
360 4 : CALL section_vals_val_get(negf_section, "HOMO_LUMO_GAP", r_val=negf_control%homo_lumo_gap)
361 4 : CALL section_vals_val_get(negf_section, "DELTA_NPOLES", i_val=negf_control%delta_npoles)
362 4 : CALL section_vals_val_get(negf_section, "GAMMA_KT", i_val=negf_control%gamma_kT)
363 :
364 4 : CALL section_vals_val_get(negf_section, "INTEGRATION_METHOD", i_val=negf_control%integr_method)
365 4 : CALL section_vals_val_get(negf_section, "INTEGRATION_MIN_POINTS", i_val=negf_control%integr_min_points)
366 4 : CALL section_vals_val_get(negf_section, "INTEGRATION_MAX_POINTS", i_val=negf_control%integr_max_points)
367 :
368 4 : IF (negf_control%integr_max_points < negf_control%integr_min_points) &
369 0 : negf_control%integr_max_points = negf_control%integr_min_points
370 :
371 4 : CALL section_vals_val_get(negf_section, "MAX_SCF", i_val=negf_control%max_scf)
372 :
373 4 : CALL section_vals_val_get(negf_section, "NPROC_POINT", i_val=negf_control%nprocs)
374 :
375 4 : CALL section_vals_val_get(negf_section, "V_SHIFT", r_val=negf_control%v_shift)
376 4 : CALL section_vals_val_get(negf_section, "V_SHIFT_OFFSET", r_val=negf_control%v_shift_offset)
377 4 : CALL section_vals_val_get(negf_section, "V_SHIFT_MAX_ITERS", i_val=negf_control%v_shift_maxiters)
378 :
379 4 : CALL section_vals_val_get(negf_section, "SCF%UPDATE_HS", l_val=negf_control%update_HS)
380 4 : CALL section_vals_val_get(negf_section, "SCF%RESTART_SCF", l_val=negf_control%restart_scf)
381 :
382 : ! check consistency
383 4 : IF (negf_control%eta < 0.0_dp) THEN
384 0 : CALL cp_abort(__LOCATION__, "ETA must be >= 0")
385 : END IF
386 :
387 4 : IF (n_rep > 0) THEN
388 16 : delta_npoles_min = NINT(0.5_dp*(negf_control%eta/(pi*MAXVAL(negf_control%contacts(:)%temperature)) + 1.0_dp))
389 : ELSE
390 0 : delta_npoles_min = 1
391 : END IF
392 :
393 4 : IF (negf_control%delta_npoles < delta_npoles_min) THEN
394 0 : IF (n_rep > 0) THEN
395 0 : eta_max = REAL(2*negf_control%delta_npoles - 1, kind=dp)*pi*MAXVAL(negf_control%contacts(:)%temperature)
396 0 : temp_current = MAXVAL(negf_control%contacts(:)%temperature)*kelvin
397 0 : temp_min = negf_control%eta/(pi*REAL(2*negf_control%delta_npoles - 1, kind=dp))*kelvin
398 :
399 0 : WRITE (eta_current_str, '(ES11.4E2)') negf_control%eta
400 0 : WRITE (eta_max_str, '(ES11.4E2)') eta_max
401 0 : WRITE (npoles_current_str, '(I11)') negf_control%delta_npoles
402 0 : WRITE (npoles_min_str, '(I11)') delta_npoles_min
403 0 : WRITE (temp_current_str, '(F11.3)') temp_current
404 0 : WRITE (temp_min_str, '(F11.3)') temp_min
405 :
406 : CALL cp_abort(__LOCATION__, &
407 : "Parameter DELTA_NPOLES must be at least "//TRIM(ADJUSTL(npoles_min_str))// &
408 : " (instead of "//TRIM(ADJUSTL(npoles_current_str))// &
409 : ") for given TEMPERATURE ("//TRIM(ADJUSTL(temp_current_str))// &
410 : " K) and ETA ("//TRIM(ADJUSTL(eta_current_str))// &
411 : "). Alternatively you can increase TEMPERATURE above "//TRIM(ADJUSTL(temp_min_str))// &
412 : " K, or decrease ETA below "//TRIM(ADJUSTL(eta_max_str))// &
413 : ". Please keep in mind that very tight ETA may result in dramatical precision loss"// &
414 0 : " due to inversion of ill-conditioned matrices.")
415 : ELSE
416 : ! no leads have been defined, so calculation will abort anyway
417 0 : negf_control%delta_npoles = delta_npoles_min
418 : END IF
419 : END IF
420 :
421 : ! expand scattering region by adding atoms from contact screening regions
422 4 : n_rep = SIZE(negf_control%contacts)
423 4 : IF (ALLOCATED(negf_control%atomlist_S)) THEN
424 4 : natoms_total = SIZE(negf_control%atomlist_S)
425 : ELSE
426 0 : natoms_total = 0
427 : END IF
428 :
429 12 : DO i_rep = 1, n_rep
430 12 : IF (ALLOCATED(negf_control%contacts(i_rep)%atomlist_screening)) THEN
431 : IF (ALLOCATED(negf_control%contacts(i_rep)%atomlist_screening)) &
432 8 : natoms_total = natoms_total + SIZE(negf_control%contacts(i_rep)%atomlist_screening)
433 : END IF
434 : END DO
435 :
436 4 : IF (natoms_total > 0) THEN
437 12 : ALLOCATE (negf_control%atomlist_S_screening(natoms_total))
438 4 : IF (ALLOCATED(negf_control%atomlist_S)) THEN
439 4 : natoms_total = SIZE(negf_control%atomlist_S)
440 20 : negf_control%atomlist_S_screening(1:natoms_total) = negf_control%atomlist_S(1:natoms_total)
441 : ELSE
442 0 : natoms_total = 0
443 : END IF
444 :
445 12 : DO i_rep = 1, n_rep
446 12 : IF (ALLOCATED(negf_control%contacts(i_rep)%atomlist_screening)) THEN
447 8 : natoms_current = SIZE(negf_control%contacts(i_rep)%atomlist_screening)
448 :
449 : negf_control%atomlist_S_screening(natoms_total + 1:natoms_total + natoms_current) = &
450 40 : negf_control%contacts(i_rep)%atomlist_screening(1:natoms_current)
451 :
452 8 : natoms_total = natoms_total + natoms_current
453 : END IF
454 : END DO
455 :
456 : ! sort and remove duplicated atoms
457 12 : ALLOCATE (inds(natoms_total))
458 4 : CALL sort(negf_control%atomlist_S_screening, natoms_total, inds)
459 4 : DEALLOCATE (inds)
460 :
461 4 : natoms_current = 1
462 48 : DO i_rep = natoms_current + 1, natoms_total
463 48 : IF (negf_control%atomlist_S_screening(i_rep) /= negf_control%atomlist_S_screening(natoms_current)) THEN
464 44 : natoms_current = natoms_current + 1
465 44 : negf_control%atomlist_S_screening(natoms_current) = negf_control%atomlist_S_screening(i_rep)
466 : END IF
467 : END DO
468 :
469 4 : IF (natoms_current < natoms_total) THEN
470 0 : CALL MOVE_ALLOC(negf_control%atomlist_S_screening, inds)
471 :
472 0 : ALLOCATE (negf_control%atomlist_S_screening(natoms_current))
473 0 : negf_control%atomlist_S_screening(1:natoms_current) = inds(1:natoms_current)
474 0 : DEALLOCATE (inds)
475 : END IF
476 : END IF
477 :
478 4 : IF (do_negf .AND. SIZE(negf_control%contacts) > 2) THEN
479 : CALL cp_abort(__LOCATION__, &
480 0 : "General case (> 2 contacts) has not been implemented yet")
481 : END IF
482 :
483 4 : CALL timestop(handle)
484 16 : END SUBROUTINE read_negf_control
485 :
486 : ! **************************************************************************************************
487 : !> \brief Read region-specific list of atoms.
488 : !> \param atomlist list of atoms
489 : !> \param input_section input section which contains 'LIST' and 'MOLNAME' keywords
490 : !> \param i_rep_section repetition index of the input_section
491 : !> \param subsys subsystem environment
492 : ! **************************************************************************************************
493 36 : SUBROUTINE read_negf_atomlist(atomlist, input_section, i_rep_section, subsys)
494 : INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(out) :: atomlist
495 : TYPE(section_vals_type), POINTER :: input_section
496 : INTEGER, INTENT(in) :: i_rep_section
497 : TYPE(cp_subsys_type), POINTER :: subsys
498 :
499 : CHARACTER(len=*), PARAMETER :: routineN = 'read_negf_atomlist'
500 :
501 : CHARACTER(len=default_string_length) :: index_str, natoms_str
502 : CHARACTER(len=default_string_length), &
503 36 : DIMENSION(:), POINTER :: cptr
504 : INTEGER :: first_atom, handle, iatom, ikind, imol, iname, irep, last_atom, natoms_current, &
505 : natoms_max, natoms_total, nkinds, nmols, nnames, nrep_list, nrep_molname
506 36 : INTEGER, ALLOCATABLE, DIMENSION(:) :: inds
507 36 : INTEGER, DIMENSION(:), POINTER :: iptr
508 : LOGICAL :: is_list, is_molname
509 36 : TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
510 : TYPE(molecule_kind_type), POINTER :: molecule_kind
511 36 : TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
512 : TYPE(molecule_type), POINTER :: molecule
513 36 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
514 :
515 36 : CALL timeset(routineN, handle)
516 :
517 : CALL cp_subsys_get(subsys, particle_set=particle_set, &
518 : molecule_set=molecule_set, &
519 36 : molecule_kind_set=molecule_kind_set)
520 36 : natoms_max = SIZE(particle_set)
521 36 : nkinds = SIZE(molecule_kind_set)
522 :
523 : CALL section_vals_val_get(input_section, "LIST", i_rep_section=i_rep_section, &
524 36 : n_rep_val=nrep_list, explicit=is_list)
525 : CALL section_vals_val_get(input_section, "MOLNAME", i_rep_section=i_rep_section, &
526 36 : n_rep_val=nrep_molname, explicit=is_molname)
527 :
528 : ! compute the number of atoms in the NEGF region, and check the validity of given atomic indices
529 36 : natoms_total = 0
530 36 : IF (is_list .AND. nrep_list > 0) THEN
531 16 : DO irep = 1, nrep_list
532 8 : CALL section_vals_val_get(input_section, "LIST", i_rep_section=i_rep_section, i_rep_val=irep, i_vals=iptr)
533 :
534 8 : natoms_current = SIZE(iptr)
535 48 : DO iatom = 1, natoms_current
536 48 : IF (iptr(iatom) > natoms_max) THEN
537 0 : CALL integer_to_string(iptr(iatom), index_str)
538 0 : CALL integer_to_string(natoms_max, natoms_str)
539 : CALL cp_abort(__LOCATION__, &
540 : "NEGF: Atomic index "//TRIM(index_str)//" given in section "// &
541 : TRIM(input_section%section%name)//" exceeds the maximum number of atoms ("// &
542 0 : TRIM(natoms_str)//").")
543 : END IF
544 : END DO
545 :
546 16 : natoms_total = natoms_total + natoms_current
547 : END DO
548 : END IF
549 :
550 36 : IF (is_molname .AND. nrep_molname > 0) THEN
551 56 : DO irep = 1, nrep_molname
552 28 : CALL section_vals_val_get(input_section, "MOLNAME", i_rep_section=i_rep_section, i_rep_val=irep, c_vals=cptr)
553 28 : nnames = SIZE(cptr)
554 :
555 90 : DO iname = 1, nnames
556 158 : DO ikind = 1, nkinds
557 158 : IF (molecule_kind_set(ikind)%name == cptr(iname)) EXIT
558 : END DO
559 :
560 62 : IF (ikind <= nkinds) THEN
561 34 : molecule_kind => molecule_kind_set(ikind)
562 34 : CALL get_molecule_kind(molecule_kind, nmolecule=nmols, molecule_list=iptr)
563 :
564 68 : DO imol = 1, nmols
565 34 : molecule => molecule_set(iptr(imol))
566 34 : CALL get_molecule(molecule, first_atom=first_atom, last_atom=last_atom)
567 34 : natoms_current = last_atom - first_atom + 1
568 68 : natoms_total = natoms_total + natoms_current
569 : END DO
570 : ELSE
571 : CALL cp_abort(__LOCATION__, &
572 : "NEGF: A molecule with the name '"//TRIM(cptr(iname))//"' mentioned in section "// &
573 0 : TRIM(input_section%section%name)//" has not been defined. Note that names are case sensitive.")
574 : END IF
575 : END DO
576 : END DO
577 : END IF
578 :
579 : ! create a list of atomic indices
580 36 : IF (natoms_total > 0) THEN
581 108 : ALLOCATE (atomlist(natoms_total))
582 :
583 36 : natoms_total = 0
584 :
585 36 : IF (is_list .AND. nrep_list > 0) THEN
586 16 : DO irep = 1, nrep_list
587 8 : CALL section_vals_val_get(input_section, "LIST", i_rep_section=i_rep_section, i_rep_val=irep, i_vals=iptr)
588 :
589 8 : natoms_current = SIZE(iptr)
590 48 : atomlist(natoms_total + 1:natoms_total + natoms_current) = iptr(1:natoms_current)
591 16 : natoms_total = natoms_total + natoms_current
592 : END DO
593 : END IF
594 :
595 36 : IF (is_molname .AND. nrep_molname > 0) THEN
596 56 : DO irep = 1, nrep_molname
597 28 : CALL section_vals_val_get(input_section, "MOLNAME", i_rep_section=i_rep_section, i_rep_val=irep, c_vals=cptr)
598 28 : nnames = SIZE(cptr)
599 :
600 90 : DO iname = 1, nnames
601 158 : DO ikind = 1, nkinds
602 158 : IF (molecule_kind_set(ikind)%name == cptr(iname)) EXIT
603 : END DO
604 :
605 62 : IF (ikind <= nkinds) THEN
606 34 : molecule_kind => molecule_kind_set(ikind)
607 34 : CALL get_molecule_kind(molecule_kind, nmolecule=nmols, molecule_list=iptr)
608 :
609 68 : DO imol = 1, nmols
610 34 : molecule => molecule_set(iptr(imol))
611 34 : CALL get_molecule(molecule, first_atom=first_atom, last_atom=last_atom)
612 :
613 204 : DO natoms_current = first_atom, last_atom
614 136 : natoms_total = natoms_total + 1
615 170 : atomlist(natoms_total) = natoms_current
616 : END DO
617 : END DO
618 : END IF
619 : END DO
620 : END DO
621 : END IF
622 :
623 : ! remove duplicated atoms
624 108 : ALLOCATE (inds(natoms_total))
625 36 : CALL sort(atomlist, natoms_total, inds)
626 36 : DEALLOCATE (inds)
627 :
628 36 : natoms_current = 1
629 176 : DO iatom = natoms_current + 1, natoms_total
630 176 : IF (atomlist(iatom) /= atomlist(natoms_current)) THEN
631 140 : natoms_current = natoms_current + 1
632 140 : atomlist(natoms_current) = atomlist(iatom)
633 : END IF
634 : END DO
635 :
636 36 : IF (natoms_current < natoms_total) THEN
637 0 : CALL MOVE_ALLOC(atomlist, inds)
638 :
639 0 : ALLOCATE (atomlist(natoms_current))
640 0 : atomlist(1:natoms_current) = inds(1:natoms_current)
641 0 : DEALLOCATE (inds)
642 : END IF
643 : END IF
644 :
645 36 : CALL timestop(handle)
646 36 : END SUBROUTINE read_negf_atomlist
647 0 : END MODULE negf_control_types
|