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