32#include "./base/base_uses.f90"
37 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'negf_control_types'
38 LOGICAL,
PARAMETER,
PRIVATE :: debug_this_module = .true.
49 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atomlist_bulk, atomlist_screening
52 DIMENSION(:) :: atomlist_cell
54 INTEGER :: force_env_index = -1
56 LOGICAL :: compute_fermi_level = .false.
59 LOGICAL :: refine_fermi_level = .false.
61 REAL(kind=
dp) :: fermi_level = -1.0_dp
63 REAL(kind=
dp) :: temperature = -1.0_dp
65 REAL(kind=
dp) :: v_external = 0.0_dp
75 DIMENSION(:) :: contacts
77 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atomlist_s
80 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atomlist_s_screening
82 LOGICAL :: disable_cache = .false.
84 REAL(kind=
dp) :: conv_density = -1.0_dp
86 REAL(kind=
dp) :: conv_green = -1.0_dp
88 REAL(kind=
dp) :: conv_scf = -1.0_dp
90 REAL(kind=
dp) :: eps_geometry = -1.0_dp
92 REAL(kind=
dp) :: v_bias = -1.0_dp
94 REAL(kind=
dp) :: energy_lbound = -1.0_dp
96 REAL(kind=
dp) :: eta = -1.0_dp
98 REAL(kind=
dp) :: homo_lumo_gap = -1.0_dp
100 INTEGER :: delta_npoles = -1
102 INTEGER :: gamma_kt = -1
104 INTEGER :: integr_method = -1
106 INTEGER :: integr_min_points = -1
108 INTEGER :: integr_max_points = -1
110 INTEGER :: max_scf = -1
112 INTEGER :: nprocs = -1
114 REAL(kind=
dp) :: v_shift = -1.0_dp
116 REAL(kind=
dp) :: v_shift_offset = -1.0_dp
118 INTEGER :: v_shift_maxiters = -1
121 PRIVATE :: read_negf_atomlist
134 CHARACTER(len=*),
PARAMETER :: routinen =
'negf_control_create'
138 cpassert(.NOT.
ASSOCIATED(negf_control))
139 CALL timeset(routinen, handle)
141 ALLOCATE (negf_control)
143 CALL timestop(handle)
155 CHARACTER(len=*),
PARAMETER :: routinen =
'negf_control_release'
157 INTEGER :: handle, i, j
159 CALL timeset(routinen, handle)
161 IF (
ASSOCIATED(negf_control))
THEN
162 IF (
ALLOCATED(negf_control%atomlist_S))
DEALLOCATE (negf_control%atomlist_S)
163 IF (
ALLOCATED(negf_control%atomlist_S_screening))
DEALLOCATE (negf_control%atomlist_S_screening)
165 IF (
ALLOCATED(negf_control%contacts))
THEN
166 DO i =
SIZE(negf_control%contacts), 1, -1
167 IF (
ALLOCATED(negf_control%contacts(i)%atomlist_bulk)) &
168 DEALLOCATE (negf_control%contacts(i)%atomlist_bulk)
170 IF (
ALLOCATED(negf_control%contacts(i)%atomlist_screening)) &
171 DEALLOCATE (negf_control%contacts(i)%atomlist_screening)
173 IF (
ALLOCATED(negf_control%contacts(i)%atomlist_cell))
THEN
174 DO j =
SIZE(negf_control%contacts(i)%atomlist_cell), 1, -1
175 IF (
ALLOCATED(negf_control%contacts(i)%atomlist_cell(j)%vector)) &
176 DEALLOCATE (negf_control%contacts(i)%atomlist_cell(j)%vector)
178 DEALLOCATE (negf_control%contacts(i)%atomlist_cell)
182 DEALLOCATE (negf_control%contacts)
185 DEALLOCATE (negf_control)
188 CALL timestop(handle)
202 CHARACTER(len=*),
PARAMETER :: routinen =
'read_negf_control'
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 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: inds
210 LOGICAL :: do_negf, is_explicit
211 REAL(kind=
dp) :: eta_max, temp_current, temp_min
213 negf_section, region_section
215 CALL timeset(routinen, handle)
223 CALL section_vals_get(contact_section, n_repetition=n_rep, explicit=is_explicit)
224 IF ((.NOT. is_explicit) .AND. do_negf)
THEN
225 CALL cp_abort(__location__, &
226 "At least one contact is needed for NEGF calculation.")
229 ALLOCATE (negf_control%contacts(n_rep))
234 IF ((.NOT. is_explicit) .AND. do_negf)
THEN
235 WRITE (contact_id_str,
'(I11)') i_rep
236 CALL cp_abort(__location__, &
237 "The screening region must be defined for the contact "//trim(adjustl(contact_id_str))//
".")
240 IF (is_explicit)
THEN
241 CALL read_negf_atomlist(negf_control%contacts(i_rep)%atomlist_screening, region_section, 1, subsys)
248 IF ((.NOT. is_explicit) .AND. do_negf)
THEN
249 WRITE (contact_id_str,
'(I11)') i_rep
250 CALL cp_abort(__location__, &
251 "The bulk region must be defined for the contact "//trim(adjustl(contact_id_str))//
".")
254 IF (is_explicit)
THEN
255 CALL read_negf_atomlist(negf_control%contacts(i_rep)%atomlist_bulk, region_section, 1, subsys)
259 i_val=negf_control%contacts(i_rep)%force_env_index, &
263 CALL section_vals_get(cell_section, n_repetition=n2_rep, explicit=is_explicit)
265 IF (((.NOT. is_explicit) .OR. n2_rep /= 2) .AND. negf_control%contacts(i_rep)%force_env_index <= 0 .AND. do_negf)
THEN
266 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 trim(adjustl(contact_id_str))//
".")
274 IF (is_explicit .AND. n2_rep > 0)
THEN
275 ALLOCATE (negf_control%contacts(i_rep)%atomlist_cell(n2_rep))
277 DO i2_rep = 1, n2_rep
278 CALL read_negf_atomlist(negf_control%contacts(i_rep)%atomlist_cell(i2_rep)%vector, cell_section, i2_rep, subsys)
283 l_val=negf_control%contacts(i_rep)%refine_fermi_level, &
287 r_val=negf_control%contacts(i_rep)%fermi_level, &
288 i_rep_section=i_rep, explicit=is_explicit)
289 negf_control%contacts(i_rep)%compute_fermi_level = (.NOT. is_explicit) .OR. &
290 negf_control%contacts(i_rep)%refine_fermi_level
292 IF (do_negf .AND. negf_control%contacts(i_rep)%force_env_index <= 0 .AND. &
293 (.NOT. (is_explicit .OR. negf_control%contacts(i_rep)%refine_fermi_level)))
THEN
294 WRITE (contact_id_str,
'(I11)') i_rep
295 CALL cp_warn(__location__, &
296 "There is no way to reasonably guess the Fermi level for the bulk contact "// &
297 trim(adjustl(contact_id_str))//
" without running a separate bulk DFT calculation first. "// &
298 "Therefore, 0.0 Hartree will be used as an initial guess. It is strongly advised to enable "// &
299 "the REFINE_FERMI_LEVEL switch and to provide an initial guess using the FERMI_LEVEL keyword. "// &
300 "Alternatively, a bulk FORCE_EVAL_SECTION can be set up.")
304 r_val=negf_control%contacts(i_rep)%temperature, &
306 IF (negf_control%contacts(i_rep)%temperature <= 0.0_dp)
THEN
307 CALL cp_abort(__location__,
"Electronic temperature must be > 0")
311 r_val=negf_control%contacts(i_rep)%v_external, &
317 IF (is_explicit)
THEN
318 CALL read_negf_atomlist(negf_control%atomlist_S, region_section, 1, subsys)
336 CALL section_vals_val_get(negf_section,
"INTEGRATION_MIN_POINTS", i_val=negf_control%integr_min_points)
337 CALL section_vals_val_get(negf_section,
"INTEGRATION_MAX_POINTS", i_val=negf_control%integr_max_points)
339 IF (negf_control%integr_max_points < negf_control%integr_min_points) &
340 negf_control%integr_max_points = negf_control%integr_min_points
348 CALL section_vals_val_get(negf_section,
"V_SHIFT_MAX_ITERS", i_val=negf_control%v_shift_maxiters)
351 IF (negf_control%eta < 0.0_dp)
THEN
352 CALL cp_abort(__location__,
"ETA must be >= 0")
356 delta_npoles_min = nint(0.5_dp*(negf_control%eta/(
pi*maxval(negf_control%contacts(:)%temperature)) + 1.0_dp))
361 IF (negf_control%delta_npoles < delta_npoles_min)
THEN
363 eta_max = real(2*negf_control%delta_npoles - 1, kind=
dp)*
pi*maxval(negf_control%contacts(:)%temperature)
364 temp_current = maxval(negf_control%contacts(:)%temperature)*
kelvin
365 temp_min = negf_control%eta/(
pi*real(2*negf_control%delta_npoles - 1, kind=
dp))*
kelvin
367 WRITE (eta_current_str,
'(ES11.4E2)') negf_control%eta
368 WRITE (eta_max_str,
'(ES11.4E2)') eta_max
369 WRITE (npoles_current_str,
'(I11)') negf_control%delta_npoles
370 WRITE (npoles_min_str,
'(I11)') delta_npoles_min
371 WRITE (temp_current_str,
'(F11.3)') temp_current
372 WRITE (temp_min_str,
'(F11.3)') temp_min
374 CALL cp_abort(__location__, &
375 "Parameter DELTA_NPOLES must be at least "//trim(adjustl(npoles_min_str))// &
376 " (instead of "//trim(adjustl(npoles_current_str))// &
377 ") for given TEMPERATURE ("//trim(adjustl(temp_current_str))// &
378 " K) and ETA ("//trim(adjustl(eta_current_str))// &
379 "). Alternatively you can increase TEMPERATURE above "//trim(adjustl(temp_min_str))// &
380 " K, or decrease ETA below "//trim(adjustl(eta_max_str))// &
381 ". Please keep in mind that very tight ETA may result in dramatical precision loss"// &
382 " due to inversion of ill-conditioned matrices.")
385 negf_control%delta_npoles = delta_npoles_min
390 n_rep =
SIZE(negf_control%contacts)
391 IF (
ALLOCATED(negf_control%atomlist_S))
THEN
392 natoms_total =
SIZE(negf_control%atomlist_S)
398 IF (
ALLOCATED(negf_control%contacts(i_rep)%atomlist_screening))
THEN
399 IF (
ALLOCATED(negf_control%contacts(i_rep)%atomlist_screening)) &
400 natoms_total = natoms_total +
SIZE(negf_control%contacts(i_rep)%atomlist_screening)
404 IF (natoms_total > 0)
THEN
405 ALLOCATE (negf_control%atomlist_S_screening(natoms_total))
406 IF (
ALLOCATED(negf_control%atomlist_S))
THEN
407 natoms_total =
SIZE(negf_control%atomlist_S)
408 negf_control%atomlist_S_screening(1:natoms_total) = negf_control%atomlist_S(1:natoms_total)
414 IF (
ALLOCATED(negf_control%contacts(i_rep)%atomlist_screening))
THEN
415 natoms_current =
SIZE(negf_control%contacts(i_rep)%atomlist_screening)
417 negf_control%atomlist_S_screening(natoms_total + 1:natoms_total + natoms_current) = &
418 negf_control%contacts(i_rep)%atomlist_screening(1:natoms_current)
420 natoms_total = natoms_total + natoms_current
425 ALLOCATE (inds(natoms_total))
426 CALL sort(negf_control%atomlist_S_screening, natoms_total, inds)
430 DO i_rep = natoms_current + 1, natoms_total
431 IF (negf_control%atomlist_S_screening(i_rep) /= negf_control%atomlist_S_screening(natoms_current))
THEN
432 natoms_current = natoms_current + 1
433 negf_control%atomlist_S_screening(natoms_current) = negf_control%atomlist_S_screening(i_rep)
437 IF (natoms_current < natoms_total)
THEN
438 CALL move_alloc(negf_control%atomlist_S_screening, inds)
440 ALLOCATE (negf_control%atomlist_S_screening(natoms_current))
441 negf_control%atomlist_S_screening(1:natoms_current) = inds(1:natoms_current)
446 IF (do_negf .AND.
SIZE(negf_control%contacts) > 2)
THEN
447 CALL cp_abort(__location__, &
448 "General case (> 2 contacts) has not been implemented yet")
451 CALL timestop(handle)
461 SUBROUTINE read_negf_atomlist(atomlist, input_section, i_rep_section, subsys)
462 INTEGER,
ALLOCATABLE,
DIMENSION(:),
INTENT(out) :: atomlist
464 INTEGER,
INTENT(in) :: i_rep_section
467 CHARACTER(len=*),
PARAMETER :: routinen =
'read_negf_atomlist'
469 CHARACTER(len=default_string_length) :: index_str, natoms_str
470 CHARACTER(len=default_string_length), &
471 DIMENSION(:),
POINTER :: cptr
472 INTEGER :: first_atom, handle, iatom, ikind, imol, iname, irep, last_atom, natoms_current, &
473 natoms_max, natoms_total, nkinds, nmols, nnames, nrep_list, nrep_molname
474 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: inds
475 INTEGER,
DIMENSION(:),
POINTER :: iptr
476 LOGICAL :: is_list, is_molname
483 CALL timeset(routinen, handle)
486 molecule_set=molecule_set, &
487 molecule_kind_set=molecule_kind_set)
488 natoms_max =
SIZE(particle_set)
489 nkinds =
SIZE(molecule_kind_set)
492 n_rep_val=nrep_list, explicit=is_list)
494 n_rep_val=nrep_molname, explicit=is_molname)
498 IF (is_list .AND. nrep_list > 0)
THEN
499 DO irep = 1, nrep_list
500 CALL section_vals_val_get(input_section,
"LIST", i_rep_section=i_rep_section, i_rep_val=irep, i_vals=iptr)
502 natoms_current =
SIZE(iptr)
503 DO iatom = 1, natoms_current
504 IF (iptr(iatom) > natoms_max)
THEN
507 CALL cp_abort(__location__, &
508 "NEGF: Atomic index "//trim(index_str)//
" given in section "// &
509 trim(input_section%section%name)//
" exceeds the maximum number of atoms ("// &
510 trim(natoms_str)//
").")
514 natoms_total = natoms_total + natoms_current
518 IF (is_molname .AND. nrep_molname > 0)
THEN
519 DO irep = 1, nrep_molname
520 CALL section_vals_val_get(input_section,
"MOLNAME", i_rep_section=i_rep_section, i_rep_val=irep, c_vals=cptr)
525 IF (molecule_kind_set(ikind)%name .EQ. cptr(iname))
EXIT
528 IF (ikind <= nkinds)
THEN
529 molecule_kind => molecule_kind_set(ikind)
533 molecule => molecule_set(iptr(imol))
534 CALL get_molecule(molecule, first_atom=first_atom, last_atom=last_atom)
535 natoms_current = last_atom - first_atom + 1
536 natoms_total = natoms_total + natoms_current
539 CALL cp_abort(__location__, &
540 "NEGF: A molecule with the name '"//trim(cptr(iname))//
"' mentioned in section "// &
541 trim(input_section%section%name)//
" has not been defined. Note that names are case sensitive.")
548 IF (natoms_total > 0)
THEN
549 ALLOCATE (atomlist(natoms_total))
553 IF (is_list .AND. nrep_list > 0)
THEN
554 DO irep = 1, nrep_list
555 CALL section_vals_val_get(input_section,
"LIST", i_rep_section=i_rep_section, i_rep_val=irep, i_vals=iptr)
557 natoms_current =
SIZE(iptr)
558 atomlist(natoms_total + 1:natoms_total + natoms_current) = iptr(1:natoms_current)
559 natoms_total = natoms_total + natoms_current
563 IF (is_molname .AND. nrep_molname > 0)
THEN
564 DO irep = 1, nrep_molname
565 CALL section_vals_val_get(input_section,
"MOLNAME", i_rep_section=i_rep_section, i_rep_val=irep, c_vals=cptr)
570 IF (molecule_kind_set(ikind)%name .EQ. cptr(iname))
EXIT
573 IF (ikind <= nkinds)
THEN
574 molecule_kind => molecule_kind_set(ikind)
578 molecule => molecule_set(iptr(imol))
579 CALL get_molecule(molecule, first_atom=first_atom, last_atom=last_atom)
581 DO natoms_current = first_atom, last_atom
582 natoms_total = natoms_total + 1
583 atomlist(natoms_total) = natoms_current
592 ALLOCATE (inds(natoms_total))
593 CALL sort(atomlist, natoms_total, inds)
597 DO iatom = natoms_current + 1, natoms_total
598 IF (atomlist(iatom) /= atomlist(natoms_current))
THEN
599 natoms_current = natoms_current + 1
600 atomlist(natoms_current) = atomlist(iatom)
604 IF (natoms_current < natoms_total)
THEN
605 CALL move_alloc(atomlist, inds)
607 ALLOCATE (atomlist(natoms_current))
608 atomlist(1:natoms_current) = inds(1:natoms_current)
613 CALL timestop(handle)
614 END SUBROUTINE read_negf_atomlist
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_get(subsys, ref_count, 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)
returns information about various attributes of the given subsys
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
Define the molecule kind structure types and the corresponding functionality.
subroutine, public get_molecule_kind(molecule_kind, atom_list, bond_list, bend_list, ub_list, impr_list, opbend_list, colv_list, fixd_list, g3x3_list, g4x6_list, vsite_list, torsion_list, shell_list, name, mass, charge, kind_number, natom, nbend, nbond, nub, nimpr, nopbend, nconstraint, nconstraint_fixd, nfixd, ncolv, ng3x3, ng4x6, nvsite, nfixd_restraint, ng3x3_restraint, ng4x6_restraint, nvsite_restraint, nrestraints, nmolecule, nsgf, nshell, ntorsion, molecule_list, nelectron, nelectron_alpha, nelectron_beta, bond_kind_set, bend_kind_set, ub_kind_set, impr_kind_set, opbend_kind_set, torsion_kind_set, molname_generated)
Get informations about a molecule kind.
Define the data structure for the molecule information.
subroutine, public get_molecule(molecule, molecule_kind, lmi, lci, lg3x3, lg4x6, lcolv, first_atom, last_atom, first_shell, last_shell)
Get components from a molecule data set.
Allocatable vectors for NEGF based quantum transport calculations.
Input control types for NEGF based quantum transport calculations.
subroutine, public negf_control_create(negf_control)
allocate control options for Non-equilibrium Green's Function calculation
subroutine, public read_negf_control(negf_control, input, subsys)
Read NEGF input parameters.
subroutine, public negf_control_release(negf_control)
release memory allocated for NEGF control options
Define the data structure for the particle information.
Definition of physical constants:
real(kind=dp), parameter, public kelvin
Utilities for string manipulations.
subroutine, public integer_to_string(inumber, string)
Converts an integer number to a string. The WRITE statement will return an error message,...
All kind of helpful little routines.
represents a system: atoms, molecules, their pos,vel,...
Allocatable 1-D integer vector.
Input parameters related to the NEGF run.