Octopus
dos.F90
Go to the documentation of this file.
1!! Copyright (C) 2017 N. Tancogne-Dejean
2!! Copyright (C) 2025 N. Tancogne-Dejean
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
23module dos_oct_m
24 use accel_oct_m
26 use box_oct_m
27 use comm_oct_m
28 use debug_oct_m
30 use global_oct_m
32 use io_oct_m
34 use ions_oct_m
35 use, intrinsic :: iso_fortran_env
38 use math_oct_m
39 use mesh_oct_m
41 use mpi_oct_m
46 use parser_oct_m
48 use simplex_oct_m, only: simplex_dos
51 smear_cold, &
60 use types_oct_m
61 use unit_oct_m
64
65 implicit none
66
67 private
68 public :: &
69 dos_t, &
70 dos_init, &
74
75 type dos_t
76 private
77 real(real64) :: emin
78 real(real64) :: emax
79 integer :: epoints
80 real(real64) :: de
81
82 real(real64) :: gamma
83
84 logical :: computepdos
85
86 integer :: ldos_nenergies = -1
87 real(real64), allocatable :: ldos_energies(:)
88
89 integer(int64) :: method
90 integer :: smear_func
91 contains
92 final :: dos_end
93 end type dos_t
94
95contains
96
98 subroutine dos_init(this, namespace, st, kpoints)
99 type(dos_t), intent(out) :: this
100 type(namespace_t), intent(in) :: namespace
101 type(states_elec_t), intent(in) :: st
102 type(kpoints_t), intent(in) :: kpoints
103
104 real(real64) :: evalmin, evalmax, eextend
105 integer :: npath, ie
106 type(block_t) :: blk
107
108 push_sub(dos_init)
109
110 !The range of the dos is only calculated for physical points,
111 !without the one from a k-point path
112 npath = kpoints%nkpt_in_path()
113 if (st%nik > npath) then
114 evalmin = minval(st%eigenval(1:st%nst, 1:(st%nik-npath)))
115 evalmax = maxval(st%eigenval(1:st%nst, 1:(st%nik-npath)))
116 else !In case we only have a path, e.g., a bandstructure calculation
117 evalmin = minval(st%eigenval(1:st%nst, 1:st%nik))
118 evalmax = maxval(st%eigenval(1:st%nst, 1:st%nik))
119 end if
120 ! we extend the energy mesh by this amount
121 eextend = (evalmax - evalmin) / m_four
122
123 !! The numbers 21 and 22 for tetrahedra options are reused in src/states/smear.F90
124 !%Variable DOSMethod
125 !%Type integer
126 !%Default smear
127 !%Section Output
128 !%Description
129 !% Selects the method that is used to calculate the DOS.
130 !% Currently not used for PDOS and LDOS.
131 !%Option smear 0
132 !% Smearing with the smearing function selected by <tt>DOSSmearingFunction</tt>.
133 !%Option tetrahedra 21
134 !% Linear tetrahedron method as in P. E. Bloechl, et al., <i>Phys. Rev. B</i> <b>49</b>, 16223 (1994).
135 !% Requires a regular Monkhorst-Pack generated by Octopus.
136 !%Option tetrahedra_opt 22
137 !% Improved tetrahedron method as in M. Kawamura, et al., <i>Phys. Rev. B</i> <b>89</b>, 094515 (2014).
138 !% Requires a regular Monkhorst-Pack generated by Octopus.
139 !%End
140 call parse_variable(namespace, 'DOSMethod', option__dosmethod__smear, this%method)
141
142 !%Variable DOSSmearingFunction
143 !%Type integer
144 !%Default lorentzian_smearing
145 !%Section Output
146 !%Description
147 !% This is the function used to smear the energy levels in the DOS calculation.
148 !%Option fermi_dirac 2
149 !% Simple Fermi-Dirac distribution. In this case, <tt>DOSGamma</tt> has
150 !% the meaning of an electronic temperature. DN Mermin, <i>Phys. Rev.</i> <b>137</b>, A1441 (1965).
151 !%Option cold_smearing 3
152 !% N Marzari, D Vanderbilt, A De Vita, and MC Payne, <i>Phys. Rev. Lett.</i> <b>82</b>, 3296 (1999).
153 !%Option methfessel_paxton 4
154 !% M Methfessel and AT Paxton, <i>Phys. Rev. B</i> <b>40</b>, 3616 (1989).
155 !% The expansion order of the polynomial is fixed to 1.
156 !% Occupations may be negative.
157 !%Option spline_smearing 5
158 !% Nearly identical to Gaussian smearing.
159 !% JM Holender, MJ Gillan, MC Payne, and AD Simpson, <i>Phys. Rev. B</i> <b>52</b>, 967 (1995).
160 !%Option gaussian_smearing 7
161 !% Gaussian smearing.
162 !%Option lorentzian_smearing 8
163 !% Lorentzian smearing.
164 !%End
165 call parse_variable(namespace, 'DOSSmearingFunction', smear_lorentzian, this%smear_func)
166
167 !%Variable DOSEnergyMin
168 !%Type float
169 !%Section Output
170 !%Description
171 !% Lower bound for the energy mesh of the DOS.
172 !% The default is the lowest eigenvalue, minus a quarter of the total range of eigenvalues.
173 !% This is ignored for the joint density of states, and the minimal energy is always set to zero.
174 !%End
175 call parse_variable(namespace, 'DOSEnergyMin', evalmin - eextend, this%emin, units_inp%energy)
176
177 !%Variable DOSEnergyMax
178 !%Type float
179 !%Section Output
180 !%Description
181 !% Upper bound for the energy mesh of the DOS.
182 !% The default is the highest eigenvalue, plus a quarter of the total range of eigenvalues.
183 !%End
184 call parse_variable(namespace, 'DOSEnergyMax', evalmax + eextend, this%emax, units_inp%energy)
186 !%Variable DOSEnergyPoints
187 !%Type integer
188 !%Default 500
189 !%Section Output
190 !%Description
191 !% Determines how many energy points <tt>Octopus</tt> should use for
192 !% the DOS energy grid.
193 !%End
194 call parse_variable(namespace, 'DOSEnergyPoints', 500, this%epoints)
195
196 !%Variable DOSGamma
197 !%Type float
198 !%Default 0.008 Ha
199 !%Section Output
200 !%Description
201 !% Determines the width of the Lorentzian which is used for the DOS sum.
202 !%End
203 call parse_variable(namespace, 'DOSGamma', 0.008_real64, this%gamma)
204
205 !%Variable DOSComputePDOS
206 !%Type logical
207 !%Default false
208 !%Section Output
209 !%Description
210 !% Determines if projected dos are computed or not.
211 !% At the moment, the PDOS is computed from the bare pseudo-atomic orbitals, directly taken from
212 !% the pseudopotentials. The orbitals are not orthonormalized, in order to preserve their
213 !% atomic orbitals character. As a consequence, the sum of the different PDOS does not integrate
214 !% to the total DOS.
215 !%
216 !% The radii of the orbitals are controled by the threshold defined by <tt>AOThreshold</tt>,
217 !% and the fact that they are normalized or not by <tt>AONormalize</tt>.
218 !%End
219 call parse_variable(namespace, 'DOSComputePDOS', .false., this%computepdos)
220
221 ! spacing for energy mesh
222 this%de = (this%emax - this%emin) / (this%epoints - 1)
223
224 !%Variable LDOSEnergies
225 !%Type block
226 !%Section Output
227 !%Description
228 !% Specifies the energies at which the LDOS is computed.
229 !%End
230 if (parse_block(global_namespace, 'LDOSEnergies', blk) == 0) then
231 ! There is one high symmetry k-point per line
232 this%ldos_nenergies = parse_block_cols(blk, 0)
233
234 safe_allocate(this%ldos_energies(1:this%ldos_nenergies))
235 do ie = 1, this%ldos_nenergies
236 call parse_block_float(blk, 0, ie-1, this%ldos_energies(ie))
237 end do
238 call parse_block_end(blk)
239 else
240 this%ldos_nenergies = -1
241 end if
242
243 pop_sub(dos_init)
244 end subroutine dos_init
245
247 subroutine dos_end(this)
248 type(dos_t), intent(inout) :: this
249
250 push_sub(dos_end)
251
252 safe_deallocate_a(this%ldos_energies)
253 this%ldos_nenergies = -1
254
255 pop_sub(dos_end)
256 end subroutine
257
258 ! ---------------------------------------------------------
260 subroutine dos_write_dos(this, dir, st, box, ions, mesh, hm, namespace)
261 type(dos_t), intent(in) :: this
262 character(len=*), intent(in) :: dir
263 type(states_elec_t), target, intent(in) :: st
264 class(box_t), intent(in) :: box
265 type(ions_t), target, intent(in) :: ions
266 class(mesh_t), intent(in) :: mesh
267 type(hamiltonian_elec_t), intent(in) :: hm
268 type(namespace_t), intent(in) :: namespace
269
270 integer :: ie, ik, ist, is, ns, maxdos, ib, ind
271 integer, allocatable :: iunit(:)
272 real(real64) :: energy
273 real(real64), allocatable :: tdos(:)
274 real(real64), allocatable :: dos(:,:,:)
275 character(len=64) :: filename,format_str
276 logical :: normalize
277
278 integer :: ii, ll, mm, nn, work, norb, work2
279 integer :: ia, iorb, idim
280 real(real64) :: threshold
281 real(real64), allocatable :: ddot(:,:,:)
282 complex(real64), allocatable :: zdot(:,:,:)
283 real(real64), allocatable :: weight(:,:,:)
284 type(orbitalset_t) :: os
285 type(wfs_elec_t), pointer :: epsib
286
287 type(smear_t) :: smear
288 real(real64) :: e_simplex(20)
289 real(real64) :: dos_simplex
290
291 push_sub(dos_write_dos)
292
293 ! shortcuts
294 ns = 1
295 if (st%d%nspin == 2) ns = 2
296
297 ! set up smearing parameters
298 smear%method = this%smear_func
299 smear%MP_n = 1
300
301 if (st%system_grp%is_root()) then
302 ! space for state-dependent DOS
303 safe_allocate(dos(1:this%epoints, 1:st%nst, 0:ns-1))
304 safe_allocate(iunit(0:ns-1))
305
306 ! compute band/spin-resolved density of states
307 do ist = 1, st%nst
308
309 do is = 0, ns-1
310 if (ns > 1) then
311 write(filename, '(a,i5.5,a,i1.1,a)') 'dos-', ist, '-', is+1,'.dat'
312 else
313 write(filename, '(a,i5.5,a)') 'dos-', ist, '.dat'
314 end if
315 iunit(is) = io_open(trim(dir)//'/'//trim(filename), namespace, action='write')
316 ! write header
317 write(iunit(is), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), '], band-resolved DOS'
318 end do
319
320 do ie = 1, this%epoints
321 energy = this%emin + (ie - 1) * this%de
322 dos(ie, ist, :) = m_zero
323 select case (this%method)
324 case (option__dosmethod__smear)
325 ! sum up Lorentzians
326 do ik = 1, st%nik, ns
327 do is = 0, ns-1
328 dos(ie, ist, is) = dos(ie, ist, is) + st%kweights(ik+is) / this%gamma * &
329 smear_delta_function(smear, (energy - st%eigenval(ist, ik+is)) / this%gamma)
330 end do
331 end do
332 case (option__dosmethod__tetrahedra, option__dosmethod__tetrahedra_opt)
333 ! sum up tetrahedra
334 assert(associated(hm%kpoints%simplex))
335 call profiling_in("DOS_WRITE_TETRAHEDRA")
336 !$omp parallel do private(ii, is, ll, ik, e_simplex, dos_simplex) reduction(+:dos)
337 do ii = 1, hm%kpoints%simplex%n_simplices
338 do is = 0, ns - 1
339 do ll = 1, hm%kpoints%simplex%sdim
340 ik = hm%kpoints%simplex%simplices(ii, ll)
341 ik = ns * (ik - 1) + 1
342 e_simplex(ll) = st%eigenval(ist, ik+is)
343 end do
344 call simplex_dos(hm%kpoints%simplex%rdim, e_simplex(1:hm%kpoints%simplex%sdim), energy, dos_simplex)
345 dos(ie, ist, is) = dos(ie, ist, is) + dos_simplex / hm%kpoints%simplex%n_simplices
346 end do
347 end do
348 !$omp end parallel do
349 call profiling_out("DOS_WRITE_TETRAHEDRA")
350 case default
351 assert(.false.)
352 end select
353 do is = 0, ns-1
354 write(message(1), '(2es25.16E3)') units_from_atomic(units_out%energy, energy), &
355 units_from_atomic(unit_one / units_out%energy, dos(ie, ist, is))
356 call messages_info(1, iunit(is))
357 end do
358 end do
359
360 do is = 0, ns-1
361 call io_close(iunit(is))
362 end do
363 end do
364
365 safe_allocate(tdos(1))
366
367 ! for spin-polarized calculations also output spin-resolved tDOS
368 if (st%d%nspin == spin_polarized) then
369 do is = 0, ns-1
370 write(filename, '(a,i1.1,a)') 'total-dos-', is+1,'.dat'
371 iunit(is) = io_open(trim(dir)//'/'//trim(filename), namespace, action='write')
372 ! write header
373 write(iunit(is), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), '], total DOS (spin-resolved)'
374
375 do ie = 1, this%epoints
376 energy = this%emin + (ie - 1) * this%de
377 tdos(1) = m_zero
378 do ist = 1, st%nst
379 tdos(1) = tdos(1) + dos(ie, ist, is)
380 end do
381 write(message(1), '(2es25.16E3)') units_from_atomic(units_out%energy, energy), &
382 units_from_atomic(unit_one / units_out%energy, tdos(1))
383 call messages_info(1, iunit(is))
384 end do
385
386 call io_close(iunit(is))
387 end do
388 end if
389
390
391 iunit(0) = io_open(trim(dir)//'/'//'total-dos.dat', namespace, action='write')
392 write(iunit(0), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), '], total DOS'
393
394 ! compute total density of states
395 do ie = 1, this%epoints
396 energy = this%emin + (ie - 1) * this%de
397 tdos(1) = m_zero
398 do ist = 1, st%nst
399 do is = 0, ns-1
400 tdos(1) = tdos(1) + dos(ie, ist, is)
401 end do
402 end do
403 write(message(1), '(2es25.16E3)') units_from_atomic(units_out%energy, energy), &
404 units_from_atomic(unit_one / units_out%energy, tdos(1))
405 call messages_info(1, iunit(0))
406 end do
407
408 call io_close(iunit(0))
409
410 safe_deallocate_a(tdos)
411
412
413 ! write Fermi file
414 iunit(0) = io_open(trim(dir)//'/'//'total-dos-efermi.dat', namespace, action='write')
415 write(message(1), '(3a)') '# Fermi energy [', trim(units_abbrev(units_out%energy)), &
416 '] in a format compatible with total-dos.dat'
417
418 ! this is the maximum that tdos can reach
419 maxdos = st%smear%el_per_state * st%nst
420
421 write(message(2), '(2es25.16E3)') units_from_atomic(units_out%energy, st%smear%e_fermi), m_zero
422 write(message(3), '(es25.16E3,i7)') units_from_atomic(units_out%energy, st%smear%e_fermi), maxdos
423
424 call messages_info(3, iunit(0))
425 call io_close(iunit(0))
426
427 end if
428
429 if (this%computepdos) then
430
431 !These variables are defined in basis_set/orbitalbasis.F90
432 call parse_variable(namespace, 'AOThreshold', 0.01_real64, threshold)
433 call parse_variable(namespace, 'AONormalize', .true., normalize)
434
435 do ia = 1, ions%natoms
436 !We first count how many orbital set we have
437 work = orbitalset_utils_count(ions%atom(ia)%species)
438
439 !We loop over the orbital sets of the atom ia
440 do norb = 1, work
441 call orbitalset_init(os)
442 os%spec => ions%atom(ia)%species
443
444 !We count the orbitals
445 work2 = 0
446 do iorb = 1, os%spec%get_niwfs()
447 call os%spec%get_iwf_ilm(iorb, 1, ii, ll, mm)
448 call os%spec%get_iwf_n(iorb, 1, nn)
449 if (ii == norb) then
450 os%ll = ll
451 os%nn = nn
452 os%ii = ii
453 os%radius = atomic_orbital_get_radius(os%spec, mesh, iorb, 1, &
454 option__aotruncation__ao_full, threshold)
455 work2 = work2 + 1
456 end if
457 end do
458 os%norbs = work2
459 os%ndim = 1
460 os%use_submesh = .false.
461 os%allocated_on_mesh = .true.
462 os%spec => ions%atom(ia)%species
463
464 do work = 1, os%norbs
465 ! We obtain the orbital
466 if (states_are_real(st)) then
467 call dget_atomic_orbital(namespace, ions%space, ions%latt, ions%pos(:,ia), &
468 ions%atom(ia)%species, mesh, os%sphere, os%ii, os%ll, os%jj, &
469 os, work, os%radius, os%ndim, use_mesh=.not.os%use_submesh, &
470 normalize = normalize)
471 else
472 call zget_atomic_orbital(namespace, ions%space, ions%latt, ions%pos(:,ia), &
473 ions%atom(ia)%species, mesh, os%sphere, os%ii, os%ll, os%jj, &
474 os, work, os%radius, os%ndim, &
475 use_mesh = .not. hm%phase%is_allocated() .and. .not. os%use_submesh, &
476 normalize = normalize)
477 end if
478 end do
479
480 if (hm%phase%is_allocated()) then
481 ! In case of complex wavefunction, we allocate the array for the phase correction
482 safe_allocate(os%phase(1:os%sphere%np, st%d%kpt%start:st%d%kpt%end))
483 os%phase(:,:) = m_zero
484
485 if (.not. os%use_submesh) then
486 safe_allocate(os%eorb_mesh(1:mesh%np, 1:os%norbs, 1:os%ndim, st%d%kpt%start:st%d%kpt%end))
487 os%eorb_mesh(:,:,:,:) = m_zero
488 else
489 safe_allocate(os%eorb_submesh(1:os%sphere%np, 1:os%ndim, 1:os%norbs, st%d%kpt%start:st%d%kpt%end))
490 os%eorb_submesh(:,:,:,:) = m_zero
491 end if
492
493 if (accel_is_enabled() .and. st%d%dim == 1) then
494 os%ldorbs_eorb = max(pad_pow2(os%sphere%np), 1)
495 if(.not. os%use_submesh) os%ldorbs_eorb = max(pad_pow2(os%sphere%mesh%np), 1)
496
497 safe_allocate(os%buff_eorb(st%d%kpt%start:st%d%kpt%end))
498 do ik= st%d%kpt%start, st%d%kpt%end
499 call accel_create_buffer(os%buff_eorb(ik), accel_mem_read_only, type_cmplx, os%ldorbs_eorb*os%norbs)
500 end do
501 end if
502
503 call orbitalset_update_phase(os, box%dim, st%d%kpt, hm%kpoints, (st%d%ispin==spin_polarized), &
504 vec_pot = hm%hm_base%uniform_vector_potential, &
505 vec_pot_var = hm%hm_base%vector_potential)
506 else
507 if (states_are_real(st)) then
508 call dorbitalset_transfer_to_device(os, st%d%kpt, .not. os%use_submesh)
509 else
510 call zorbitalset_transfer_to_device(os, st%d%kpt, .not. os%use_submesh)
511 end if
512 end if
513
514 if (st%system_grp%is_root()) then
515 if (os%nn /= 0) then
516 write(filename,'(a, i4.4, a1, a, i1.1, a1,a)') 'pdos-at', ia, '-', trim(os%spec%get_label()), &
517 os%nn, l_notation(os%ll), '.dat'
518 else
519 write(filename,'(a, i4.4, a1, a, a1,a)') 'pdos-at', ia, '-', trim(os%spec%get_label()), &
520 l_notation(os%ll), '.dat'
521 end if
522
523 iunit(0) = io_open(trim(dir)//'/'//trim(filename), namespace, action='write')
524 ! write header
525 write(iunit(0), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), &
526 '], projected DOS (total and orbital resolved)'
527 end if
528
529 if (states_are_real(st)) then
530 safe_allocate(ddot(1:st%d%dim, 1:os%norbs, 1:st%block_size))
531 else
532 safe_allocate(zdot(1:st%d%dim, 1:os%norbs, 1:st%block_size))
533 end if
534
535 safe_allocate(weight(1:os%norbs,1:st%nik,1:st%nst))
536 weight(1:os%norbs,1:st%nik,1:st%nst) = m_zero
537
538 do ik = st%d%kpt%start, st%d%kpt%end
539 do ib = st%group%block_start, st%group%block_end
540
541 if (hm%phase%is_allocated()) then
542 safe_allocate(epsib)
543 call st%group%psib(ib, ik)%copy_to(epsib)
544 call hm%phase%apply_to(mesh, mesh%np, .false., epsib, src = st%group%psib(ib, ik))
545 else
546 epsib => st%group%psib(ib, ik)
547 end if
548
549 if (states_are_real(st)) then
550 call dorbitalset_get_coeff_batch(os, st%d%dim, epsib, ddot(:, :, :))
551 do ist = 1, st%group%psib(ib, ik)%nst
552 ind = st%group%psib(ib, ik)%ist(ist)
553 do iorb = 1, os%norbs
554 do idim = 1, st%d%dim
555 weight(iorb, ik, ind) = weight(iorb, ik, ind) + st%kweights(ik) * abs(ddot(idim, iorb, ist))**2
556 end do
557 end do
558 end do
559 else
560 call zorbitalset_get_coeff_batch(os, st%d%dim, epsib, zdot(:, :, :))
561 do ist = 1, st%group%psib(ib, ik)%nst
562 ind = st%group%psib(ib, ik)%ist(ist)
563 do iorb = 1, os%norbs
564 do idim = 1, st%d%dim
565 weight(iorb, ik, ind) = weight(iorb, ik, ind) + st%kweights(ik) * abs(zdot(idim, iorb, ist))**2
566 end do
567 end do
568 end do
569 end if
570
571 if (hm%phase%is_allocated()) then
572 call epsib%end(copy=.false.)
573 safe_deallocate_p(epsib)
574 end if
575
576 end do
577 end do
578
579 if (st%parallel_in_states .or. st%d%kpt%parallel) then
580 call comm_allreduce(st%st_kpt_mpi_grp, weight)
581 end if
582
583 safe_deallocate_a(ddot)
584 safe_deallocate_a(zdot)
585
586 if (st%system_grp%is_root()) then
587 write(format_str,'(a,i5,a)') '(', os%norbs+2, 'es25.16E3)'
588 safe_allocate(tdos(1:os%norbs))
589 do ie = 1, this%epoints
590 energy = this%emin + (ie - 1) * this%de
591 do iorb = 1, os%norbs
592 tdos(iorb) = m_zero
593 do ist = 1, st%nst
594 do ik = 1, st%nik
595 tdos(iorb) = tdos(iorb) + weight(iorb,ik,ist) / this%gamma * &
596 smear_delta_function(smear, (energy - st%eigenval(ist, ik))/this%gamma)
597 end do
598 end do
599 end do
600
601 write(iunit(0), trim(format_str)) units_from_atomic(units_out%energy, energy), &
602 units_from_atomic(unit_one / units_out%energy, sum(tdos)), &
603 (units_from_atomic(unit_one / units_out%energy, tdos(iorb)), iorb=1,os%norbs)
604 end do
605 safe_deallocate_a(tdos)
606 call io_close(iunit(0))
607 end if
608
609 call orbitalset_end(os)
610 safe_deallocate_a(weight)
611
612 end do
613
614 end do
615
616 end if
617
618 safe_deallocate_a(iunit)
619 safe_deallocate_a(dos)
620
621 pop_sub(dos_write_dos)
622 end subroutine dos_write_dos
623
624 ! ---------------------------------------------------------
626 subroutine dos_write_jdos(this, dir, st, ions, hm, namespace)
627 type(dos_t), intent(in) :: this
628 character(len=*), intent(in) :: dir
629 type(states_elec_t), intent(in) :: st
630 type(ions_t), target, intent(in) :: ions
631 type(hamiltonian_elec_t), intent(in) :: hm
632 type(namespace_t), intent(in) :: namespace
633
634 integer :: ie, ik, val, cond, is, ns
635 integer, allocatable :: iunit(:)
636 real(real64) :: energy
637 real(real64) :: tjdos(1)
638 real(real64), allocatable :: jdos(:,:)
639 character(len=64) :: filename
640
641 type(smear_t) :: smear
642
643 push_sub(dos_write_jdos)
644
645 ! shortcuts
646 ns = 1
647 if (st%d%nspin == 2) ns = 2
648
649 ! set up smearing parameters
650 smear%method = this%smear_func
651 smear%MP_n = 1
652
653 if (st%system_grp%is_root()) then
654 ! space for state-dependent DOS
655 safe_allocate(jdos(1:this%epoints, 0:ns-1))
656 safe_allocate(iunit(0:ns-1))
657 jdos = m_zero
658
659 ! compute band/spin-resolved density of states
660 do val = 1, st%nst
661 do cond = val, st%nst
662 do ik = 1, st%nik, ns
663 do is = 0, ns-1
664 if(st%occ(val, ik+is) < m_epsilon) cycle
665 if(st%occ(cond, ik+is) > m_epsilon) cycle
666 do ie = 1, this%epoints
667 energy = (ie - 1) * this%de
668 ! sum up Lorentzians
669 jdos(ie, is) = jdos(ie, is) + st%kweights(ik+is) / this%gamma * &
670 smear_delta_function(smear, (energy - (st%eigenval(cond, ik+is)-st%eigenval(val, ik+is)))/this%gamma)
671 end do
672 end do
673 end do
674 end do
675 end do
676
677 ! for spin-polarized calculations also output spin-resolved tDOS
678 if (st%d%nspin > 1) then
679 do is = 0, ns-1
680 write(filename, '(a,i1.1,a)') 'total-jdos-', is+1,'.dat'
681 iunit(is) = io_open(trim(dir)//'/'//trim(filename), namespace, action='write')
682 ! write header
683 write(iunit(is), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), '], total JDOS (spin-resolved)'
684
685 do ie = 1, this%epoints
686 energy = (ie - 1) * this%de
687 write(message(1), '(2es25.16E3)') units_from_atomic(units_out%energy, energy), &
688 units_from_atomic(unit_one / units_out%energy, jdos(ie, is))
689 call messages_info(1, iunit(is))
690 end do
691
692 call io_close(iunit(is))
693 end do
694 end if
695
696
697 iunit(0) = io_open(trim(dir)//'/'//'total-jdos.dat', namespace, action='write')
698 write(iunit(0), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), '], total JDOS'
699
700 ! compute total joint density of states
701 do ie = 1, this%epoints
702 energy = (ie - 1) * this%de
703 tjdos(1) = m_zero
704 do is = 0, ns-1
705 tjdos(1) = tjdos(1) + jdos(ie, is)
706 end do
707 write(message(1), '(2es25.16E3)') units_from_atomic(units_out%energy, energy), &
708 units_from_atomic(unit_one / units_out%energy, tjdos(1))
709 call messages_info(1, iunit(0))
710 end do
711
712 call io_close(iunit(0))
713 end if
714
715 safe_deallocate_a(iunit)
716 safe_deallocate_a(jdos)
717
718 pop_sub(dos_write_jdos)
719 end subroutine dos_write_jdos
720
722 ! ---------------------------------------------------------
724 subroutine dos_write_ldos(this, dir, st, ions, mesh, how, namespace)
725 type(dos_t), intent(in) :: this
726 character(len=*), intent(in) :: dir
727 type(states_elec_t), intent(in) :: st
728 type(ions_t), target, intent(in) :: ions
729 class(mesh_t), intent(in) :: mesh
730 integer(int64), intent(in) :: how
731 type(namespace_t), intent(in) :: namespace
732
733 integer :: ie, ik, ist, is, ns, ip, ierr
734 character(len=MAX_PATH_LEN) :: fname, name
735 real(real64) :: weight
736 real(real64), allocatable :: ldos(:,:,:), dpsi(:,:), abs_psi2(:)
737 complex(real64), allocatable :: zpsi(:,:)
738 type(unit_t) :: fn_unit
739
740 type(smear_t) :: smear
741
742 push_sub(dos_write_ldos)
743
744 if (this%ldos_nenergies < 1) then
745 message(1) = "LDOSEnergies must be defined for Output=ldos"
746 call messages_fatal(1, namespace=namespace)
747 end if
748
749 ! shortcuts
750 ns = 1
751 if (st%d%nspin == 2) ns = 2
752
753 ! set up smearing parameters
754 smear%method = this%smear_func
755 smear%MP_n = 1
756
757 fn_unit = units_out%length**(-ions%space%dim) / units_out%energy
758
759 ! space for state-dependent DOS
760 safe_allocate(ldos(1:mesh%np, 1:this%ldos_nenergies, 1:ns))
761 ldos = m_zero
762
763 safe_allocate(abs_psi2(1:mesh%np))
764 if (states_are_real(st)) then
765 safe_allocate(dpsi(1:mesh%np, 1:st%d%dim))
766 else
767 safe_allocate(zpsi(1:mesh%np, 1:st%d%dim))
768 end if
769
770 ! compute band/spin-resolved density of states
771 do ik = st%d%kpt%start, st%d%kpt%end
772 is = st%d%get_spin_index(ik)
773 do ist = st%st_start, st%st_end
774
775 ! TODO: This will be replaced by a poin-wise batch multiplication
776 if (states_are_real(st)) then
777 call states_elec_get_state(st, mesh, ist, ik, dpsi)
778 do ip = 1, mesh%np
779 abs_psi2(ip) = dpsi(ip, 1)**2
780 end do
781 if (st%d%dim > 1) then
782 abs_psi2(ip) = abs_psi2(ip) + dpsi(ip, 2)**2
783 end if
784 else
785 call states_elec_get_state(st, mesh, ist, ik, zpsi)
786 do ip = 1, mesh%np
787 abs_psi2(ip) = real(conjg(zpsi(ip, 1)) * zpsi(ip, 1), real64)
788 end do
789 if (st%d%dim > 1) then
790 abs_psi2(ip) = abs_psi2(ip) + real(conjg(zpsi(ip, 2)) * zpsi(ip, 2), real64)
791 end if
792 end if
793
794 ! sum up Lorentzians
795 do ie = 1, this%ldos_nenergies
796 weight = st%kweights(ik) / this%gamma * &
797 smear_delta_function(smear, (this%ldos_energies(ie) - st%eigenval(ist, ik))/this%gamma)
798 call lalg_axpy(mesh%np, weight, abs_psi2, ldos(:, ie, is))
799 end do
800 end do
801 end do !ist
802
803 safe_deallocate_a(dpsi)
804 safe_deallocate_a(zpsi)
805 safe_deallocate_a(abs_psi2)
806
807 if (st%parallel_in_states .or. st%d%kpt%parallel) then
808 call comm_allreduce(st%st_kpt_mpi_grp, ldos)
809 end if
810
811 do is = 1, ns
812 do ie = 1, this%ldos_nenergies
813 write(name, '(a,i5.5)') 'ldos_en-', ie
814 fname = get_filename_with_spin(name, st%d%nspin, is)
815
816 call dio_function_output(how, dir, fname, namespace, ions%space, mesh, &
817 ldos(:, ie, is), fn_unit, ierr, pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
818 end do
819 end do
820
821 safe_deallocate_a(ldos)
822
823 pop_sub(dos_write_ldos)
824 end subroutine dos_write_ldos
825
826
827end module dos_oct_m
828
829!! Local Variables:
830!! mode: f90
831!! coding: utf-8
832!! End:
constant times a vector plus a vector
Definition: lalg_basic.F90:173
pure logical function, public accel_is_enabled()
Definition: accel.F90:402
integer, parameter, public accel_mem_read_only
Definition: accel.F90:185
subroutine, public zget_atomic_orbital(namespace, space, latt, pos, species, mesh, sm, ii, ll, jj, os, orbind, radius, d_dim, use_mesh, normalize, index_shift)
This routine returns the atomic orbital basis – provided by the pseudopotential structure in geo.
character(len=1), dimension(0:3), parameter, public l_notation
real(real64) function, public atomic_orbital_get_radius(species, mesh, iorb, ispin, truncation, threshold)
subroutine, public dget_atomic_orbital(namespace, space, latt, pos, species, mesh, sm, ii, ll, jj, os, orbind, radius, d_dim, use_mesh, normalize, index_shift)
This routine returns the atomic orbital basis – provided by the pseudopotential structure in geo.
Module that handles computing and output of various density of states.
Definition: dos.F90:118
subroutine dos_end(this)
Finalizer for the dos_t object.
Definition: dos.F90:343
subroutine, public dos_write_dos(this, dir, st, box, ions, mesh, hm, namespace)
Computes and output the DOS and the projected DOS (PDOS)
Definition: dos.F90:356
subroutine, public dos_write_jdos(this, dir, st, ions, hm, namespace)
Computes and output the joint DOS (LDOS)
Definition: dos.F90:722
subroutine, public dos_init(this, namespace, st, kpoints)
Initializes the dot_t object.
Definition: dos.F90:194
subroutine, public dos_write_ldos(this, dir, st, ions, mesh, how, namespace)
Computes and output the local DOS (LDOS)
Definition: dos.F90:820
integer, parameter, public spin_polarized
real(real64), parameter, public m_zero
Definition: global.F90:191
real(real64), parameter, public m_four
Definition: global.F90:195
real(real64), parameter, public m_epsilon
Definition: global.F90:207
subroutine, public dio_function_output(how, dir, fname, namespace, space, mesh, ff, unit, ierr, pos, atoms, grp, root)
Top-level IO routine for functions defined on the mesh.
Definition: io.F90:116
subroutine, public io_close(iunit, grp)
Definition: io.F90:467
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:402
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
integer pure function, public pad_pow2(size)
create array size, which is padded to powers of 2
Definition: math.F90:837
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:161
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:409
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:593
type(namespace_t), public global_namespace
Definition: namespace.F90:135
subroutine, public orbitalset_init(this)
Definition: orbitalset.F90:210
subroutine, public orbitalset_end(this)
Definition: orbitalset.F90:236
subroutine, public dorbitalset_transfer_to_device(os, kpt, use_mesh)
Allocate and transfer the orbitals to the device.
subroutine, public orbitalset_update_phase(os, dim, kpt, kpoints, spin_polarized, vec_pot, vec_pot_var, kpt_max)
Build the phase correction to the global phase in case the orbital crosses the border of the simulato...
Definition: orbitalset.F90:286
subroutine, public dorbitalset_get_coeff_batch(os, ndim, psib, dot, reduce)
Definition: orbitalset.F90:590
subroutine, public zorbitalset_get_coeff_batch(os, ndim, psib, dot, reduce)
subroutine, public zorbitalset_transfer_to_device(os, kpt, use_mesh)
Allocate and transfer the orbitals to the device.
integer function, public orbitalset_utils_count(species, iselect)
Count the number of orbital sets we have for a given atom.
this module contains the low-level part of the output system
Definition: output_low.F90:117
character(len=max_path_len) function, public get_filename_with_spin(output, nspin, spin_index)
Returns the filame as output, or output-spX is spin polarized.
Definition: output_low.F90:233
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:615
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:631
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:554
subroutine, public simplex_dos(rdim, esimplex, eF, dos)
Get only the DOS contribution of a single simplex.
Definition: simplex.F90:445
real(real64) function, public smear_delta_function(this, xx)
Definition: smear.F90:829
integer, parameter, public smear_fermi_dirac
Definition: smear.F90:177
integer, parameter, public smear_methfessel_paxton
Definition: smear.F90:177
integer, parameter, public smear_lorentzian
Definition: smear.F90:177
integer, parameter, public smear_spline
Definition: smear.F90:177
integer, parameter, public smear_cold
Definition: smear.F90:177
integer, parameter, public smear_gaussian
Definition: smear.F90:177
pure logical function, public states_are_real(st)
type(type_t), public type_cmplx
Definition: types.F90:136
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
character(len=20) pure function, public units_abbrev(this)
Definition: unit.F90:225
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_system_t), public units_inp
the units systems for reading and writing
type(unit_t), public unit_one
some special units required for particular quantities
class to tell whether a point is inside or outside
Definition: box.F90:143
Describes mesh distribution to nodes.
Definition: mesh.F90:187
The states_elec_t class contains all electronic wave functions.
batches of electronic states
Definition: wfs_elec.F90:141
int true(void)