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
33 use io_oct_m
35 use ions_oct_m
36 use, intrinsic :: iso_fortran_env
39 use math_oct_m
40 use mesh_oct_m
42 use mpi_oct_m
47 use parser_oct_m
52 smear_cold, &
61 use types_oct_m
62 use unit_oct_m
65
66 implicit none
67
68 private
69 public :: &
70 dos_t, &
71 dos_init, &
75
76 type dos_t
77 private
78 real(real64) :: emin
79 real(real64) :: emax
80 integer :: epoints
81 real(real64) :: de
82
83 real(real64) :: gamma
84
85 logical :: computepdos
86
87 integer :: ldos_nenergies = -1
88 real(real64), allocatable :: ldos_energies(:)
89
90 integer(int64) :: method
91 integer :: smear_func
92 contains
93 final :: dos_end
94 end type dos_t
95
96contains
97
99 subroutine dos_init(this, namespace, st, kpoints)
100 type(dos_t), intent(out) :: this
101 type(namespace_t), intent(in) :: namespace
102 type(states_elec_t), intent(in) :: st
103 type(kpoints_t), intent(in) :: kpoints
104
105 real(real64) :: evalmin, evalmax, eextend
106 integer :: npath, ie
107 type(block_t) :: blk
108
109 push_sub(dos_init)
110
111 !The range of the dos is only calculated for physical points,
112 !without the one from a k-point path
113 npath = kpoints%nkpt_in_path()
114 if (st%nik > npath) then
115 evalmin = minval(st%eigenval(1:st%nst, 1:(st%nik-npath)))
116 evalmax = maxval(st%eigenval(1:st%nst, 1:(st%nik-npath)))
117 else !In case we only have a path, e.g., a bandstructure calculation
118 evalmin = minval(st%eigenval(1:st%nst, 1:st%nik))
119 evalmax = maxval(st%eigenval(1:st%nst, 1:st%nik))
120 end if
121 ! we extend the energy mesh by this amount
122 eextend = (evalmax - evalmin) / m_four
123
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 !%Option smear 0
131 !% Smearing with the smearing function selected by <tt>DOSSmearingFunction</tt>.
132 !%Option tetrahedra
133 !% Linear tetrahedron method as in P. E. Bloechl, et al., <i>Phys. Rev. B</i> <b>49</b>, 16223 (1994).
134 !% Requires a regular Monkhorst-Pack generated by Octopus.
135 !%Option tetrahedra_opt
136 !% Improved tetrahedron method as in M. Kawamura, et al., <i>Phys. Rev. B</i> <b>89</b>, 094515 (2014).
137 !% Requires a regular Monkhorst-Pack generated by Octopus.
138 !%End
139 call parse_variable(namespace, 'DOSMethod', option__dosmethod__smear, this%method)
140
141 !%Variable DOSSmearingFunction
142 !%Type integer
143 !%Default lorentzian_smearing
144 !%Section Output
145 !%Description
146 !% This is the function used to smear the energy levels in the DOS calculation.
147 !%Option fermi_dirac 2
148 !% Simple Fermi-Dirac distribution. In this case, <tt>DOSGamma</tt> has
149 !% the meaning of an electronic temperature. DN Mermin, <i>Phys. Rev.</i> <b>137</b>, A1441 (1965).
150 !%Option cold_smearing 3
151 !% N Marzari, D Vanderbilt, A De Vita, and MC Payne, <i>Phys. Rev. Lett.</i> <b>82</b>, 3296 (1999).
152 !%Option methfessel_paxton 4
153 !% M Methfessel and AT Paxton, <i>Phys. Rev. B</i> <b>40</b>, 3616 (1989).
154 !% The expansion order of the polynomial is fixed to 1.
155 !% Occupations may be negative.
156 !%Option spline_smearing 5
157 !% Nearly identical to Gaussian smearing.
158 !% JM Holender, MJ Gillan, MC Payne, and AD Simpson, <i>Phys. Rev. B</i> <b>52</b>, 967 (1995).
159 !%Option gaussian_smearing
160 !% Gaussian smearing.
161 !%Option lorentzian_smearing
162 !% Lorentzian smearing.
163 !%End
164 call parse_variable(namespace, 'DOSSmearingFunction', smear_lorentzian, this%smear_func)
165
166 !%Variable DOSEnergyMin
167 !%Type float
168 !%Section Output
169 !%Description
170 !% Lower bound for the energy mesh of the DOS.
171 !% The default is the lowest eigenvalue, minus a quarter of the total range of eigenvalues.
172 !% This is ignored for the joint density of states, and the minimal energy is always set to zero.
173 !%End
174 call parse_variable(namespace, 'DOSEnergyMin', evalmin - eextend, this%emin, units_inp%energy)
176 !%Variable DOSEnergyMax
177 !%Type float
178 !%Section Output
179 !%Description
180 !% Upper bound for the energy mesh of the DOS.
181 !% The default is the highest eigenvalue, plus a quarter of the total range of eigenvalues.
182 !%End
183 call parse_variable(namespace, 'DOSEnergyMax', evalmax + eextend, this%emax, units_inp%energy)
184
185 !%Variable DOSEnergyPoints
186 !%Type integer
187 !%Default 500
188 !%Section Output
189 !%Description
190 !% Determines how many energy points <tt>Octopus</tt> should use for
191 !% the DOS energy grid.
192 !%End
193 call parse_variable(namespace, 'DOSEnergyPoints', 500, this%epoints)
195 !%Variable DOSGamma
196 !%Type float
197 !%Default 0.008 Ha
198 !%Section Output
199 !%Description
200 !% Determines the width of the Lorentzian which is used for the DOS sum.
201 !%End
202 call parse_variable(namespace, 'DOSGamma', 0.008_real64, this%gamma)
203
204 !%Variable DOSComputePDOS
205 !%Type logical
206 !%Default false
207 !%Section Output
208 !%Description
209 !% Determines if projected dos are computed or not.
210 !% At the moment, the PDOS is computed from the bare pseudo-atomic orbitals, directly taken from
211 !% the pseudopotentials. The orbitals are not orthonormalized, in order to preserve their
212 !% atomic orbitals character. As a consequence, the sum of the different PDOS does not integrate
213 !% to the total DOS.
214 !%
215 !% The radii of the orbitals are controled by the threshold defined by <tt>AOThreshold</tt>,
216 !% and the fact that they are normalized or not by <tt>AONormalize</tt>.
217 !%End
218 call parse_variable(namespace, 'DOSComputePDOS', .false., this%computepdos)
219
220 ! spacing for energy mesh
221 this%de = (this%emax - this%emin) / (this%epoints - 1)
222
223 !%Variable LDOSEnergies
224 !%Type block
225 !%Section Output
226 !%Description
227 !% Specifies the energies at which the LDOS is computed.
228 !%End
229 if (parse_block(global_namespace, 'LDOSEnergies', blk) == 0) then
230 ! There is one high symmetry k-point per line
231 this%ldos_nenergies = parse_block_cols(blk, 0)
232
233 safe_allocate(this%ldos_energies(1:this%ldos_nenergies))
234 do ie = 1, this%ldos_nenergies
235 call parse_block_float(blk, 0, ie-1, this%ldos_energies(ie))
236 end do
237 call parse_block_end(blk)
238 else
239 this%ldos_nenergies = -1
240 end if
241
242 pop_sub(dos_init)
243 end subroutine dos_init
244
246 subroutine dos_end(this)
247 type(dos_t), intent(inout) :: this
248
249 push_sub(dos_end)
250
251 safe_deallocate_a(this%ldos_energies)
252 this%ldos_nenergies = -1
253
254 pop_sub(dos_end)
255 end subroutine
256
257 ! ---------------------------------------------------------
259 subroutine dos_write_dos(this, dir, st, box, ions, mesh, hm, namespace)
260 type(dos_t), intent(in) :: this
261 character(len=*), intent(in) :: dir
262 type(states_elec_t), target, intent(in) :: st
263 class(box_t), intent(in) :: box
264 type(ions_t), target, intent(in) :: ions
265 class(mesh_t), intent(in) :: mesh
266 type(hamiltonian_elec_t), intent(in) :: hm
267 type(namespace_t), intent(in) :: namespace
268
269 integer :: ie, ik, ist, is, ns, maxdos, ib, ind, nvertices
270 integer, allocatable :: iunit(:)
271 real(real64) :: energy
272 real(real64), allocatable :: tdos(:)
273 real(real64), allocatable :: dos(:,:,:)
274 character(len=64) :: filename,format_str
275 logical :: normalize
276
277 integer :: ii, ll, mm, nn, work, norb, work2
278 integer :: ia, iorb, idim
279 real(real64) :: threshold
280 real(real64), allocatable :: ddot(:,:,:)
281 complex(real64), allocatable :: zdot(:,:,:)
282 real(real64), allocatable :: weight(:,:,:)
283 type(orbitalset_t) :: os
284 type(wfs_elec_t), pointer :: epsib
285
286 type(smear_t) :: smear
287 type(simplex_t), pointer :: simplex
288 real(real64) :: e_simplex(20), a_simplex(4), dos_simplex(4)
289 real(real64), allocatable :: energies(:), dos_simplex_batch(:,:), dos_thread(:,:)
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 dos(:, :, :) = m_zero
305 safe_allocate(iunit(0:ns-1))
306
307 ! compute band/spin-resolved density of states
308 do ist = 1, st%nst
309
310 do is = 0, ns-1
311 if (ns > 1) then
312 write(filename, '(a,i5.5,a,i1.1,a)') 'dos-', ist, '-', is+1,'.dat'
313 else
314 write(filename, '(a,i5.5,a)') 'dos-', ist, '.dat'
315 end if
316 iunit(is) = io_open(trim(dir)//'/'//trim(filename), namespace, action='write')
317 ! write header
318 write(iunit(is), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), '], band-resolved DOS'
319 end do
320
321 select case (this%method)
322 case (option__dosmethod__smear)
323 do ie = 1, this%epoints
324 energy = this%emin + (ie - 1) * this%de
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 end do
333
334 case (option__dosmethod__tetrahedra, option__dosmethod__tetrahedra_opt)
335 assert(associated(hm%kpoints%reduced%simplex))
336 simplex => hm%kpoints%reduced%simplex
337 nvertices = simplex%rdim + 1
338 assert(nvertices <= 4)
339 call profiling_in("DOS_WRITE_TETRAHEDRA")
340 safe_allocate(energies(1:this%epoints))
341 do ie = 1, this%epoints
342 energies(ie) = this%emin + (ie - 1) * this%de
343 end do
344 !$omp parallel private(ii, is, ll, ik, ie, e_simplex, dos_simplex_batch, dos_thread)
345 safe_allocate(dos_simplex_batch(1:nvertices, 1:this%epoints))
346 safe_allocate(dos_thread(1:this%epoints, 0:ns-1))
347 dos_thread = m_zero
348 !$omp do schedule(static)
349 do ii = 1, simplex%n_simplices
350 do is = 0, ns - 1
351 do ll = 1, simplex%sdim
352 ik = simplex%simplices(ii, ll)
353 ik = ns * (ik - 1) + 1
354 e_simplex(ll) = st%eigenval(ist, ik+is)
355 end do
356
357 call simplex_dos(simplex%rdim, e_simplex(1:simplex%sdim), energies, dos_simplex_batch)
358
359 do ie = 1, this%epoints
360 dos_thread(ie, is) = dos_thread(ie, is) + sum(dos_simplex_batch(1:nvertices, ie)) / simplex%n_points
361 end do
362 end do
363 end do
364 !$omp end do
365 !$omp critical
366 dos(:, ist, :) = dos(:, ist, :) + dos_thread
367 !$omp end critical
368 safe_deallocate_a(dos_thread)
369 safe_deallocate_a(dos_simplex_batch)
370 !$omp end parallel
371 safe_deallocate_a(energies)
372 call profiling_out("DOS_WRITE_TETRAHEDRA")
373
374 case default
375 assert(.false.)
376 end select
377
378 do ie = 1, this%epoints
379 energy = this%emin + (ie - 1) * this%de
380 do is = 0, ns-1
381 write(message(1), '(2es25.16E3)') units_from_atomic(units_out%energy, energy), &
382 units_from_atomic(unit_one / units_out%energy, dos(ie, ist, is))
383 call messages_info(1, iunit(is))
384 end do
385 end do
386
387 do is = 0, ns-1
388 call io_close(iunit(is))
389 end do
390 end do
391
392 safe_allocate(tdos(1))
393
394 ! for spin-polarized calculations also output spin-resolved tDOS
395 if (st%d%nspin == spin_polarized) then
396 do is = 0, ns-1
397 write(filename, '(a,i1.1,a)') 'total-dos-', is+1,'.dat'
398 iunit(is) = io_open(trim(dir)//'/'//trim(filename), namespace, action='write')
399 ! write header
400 write(iunit(is), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), '], total DOS (spin-resolved)'
401
402 do ie = 1, this%epoints
403 energy = this%emin + (ie - 1) * this%de
404 tdos(1) = m_zero
405 do ist = 1, st%nst
406 tdos(1) = tdos(1) + dos(ie, ist, is)
407 end do
408 write(message(1), '(2es25.16E3)') units_from_atomic(units_out%energy, energy), &
409 units_from_atomic(unit_one / units_out%energy, tdos(1))
410 call messages_info(1, iunit(is))
411 end do
412
413 call io_close(iunit(is))
414 end do
415 end if
416
417
418 iunit(0) = io_open(trim(dir)//'/'//'total-dos.dat', namespace, action='write')
419 write(iunit(0), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), '], total DOS'
420
421 ! compute total density of states
422 do ie = 1, this%epoints
423 energy = this%emin + (ie - 1) * this%de
424 tdos(1) = m_zero
425 do ist = 1, st%nst
426 do is = 0, ns-1
427 tdos(1) = tdos(1) + dos(ie, ist, is)
428 end do
429 end do
430 write(message(1), '(2es25.16E3)') units_from_atomic(units_out%energy, energy), &
431 units_from_atomic(unit_one / units_out%energy, tdos(1))
432 call messages_info(1, iunit(0))
433 end do
434
435 call io_close(iunit(0))
436
437 safe_deallocate_a(tdos)
438
439
440 ! write Fermi file
441 iunit(0) = io_open(trim(dir)//'/'//'total-dos-efermi.dat', namespace, action='write')
442 write(message(1), '(3a)') '# Fermi energy [', trim(units_abbrev(units_out%energy)), &
443 '] in a format compatible with total-dos.dat'
444
445 ! this is the maximum that tdos can reach
446 maxdos = st%smear%el_per_state * st%nst
447
448 write(message(2), '(2es25.16E3)') units_from_atomic(units_out%energy, st%smear%e_fermi), m_zero
449 write(message(3), '(es25.16E3,i7)') units_from_atomic(units_out%energy, st%smear%e_fermi), maxdos
450
451 call messages_info(3, iunit(0))
452 call io_close(iunit(0))
453
454 end if
455
456 if (this%computepdos) then
457
458 !These variables are defined in basis_set/orbitalbasis.F90
459 call parse_variable(namespace, 'AOThreshold', 0.01_real64, threshold)
460 call parse_variable(namespace, 'AONormalize', .true., normalize)
461
462 do ia = 1, ions%natoms
463 !We first count how many orbital set we have
464 work = orbitalset_utils_count(ions%atom(ia)%species)
465
466 !We loop over the orbital sets of the atom ia
467 do norb = 1, work
468 call orbitalset_init(os)
469 os%spec => ions%atom(ia)%species
470
471 !We count the orbitals
472 work2 = 0
473 do iorb = 1, os%spec%get_niwfs()
474 call os%spec%get_iwf_ilm(iorb, 1, ii, ll, mm)
475 call os%spec%get_iwf_n(iorb, 1, nn)
476 if (ii == norb) then
477 os%ll = ll
478 os%nn = nn
479 os%ii = ii
480 os%radius = atomic_orbital_get_radius(os%spec, mesh, iorb, 1, &
481 option__aotruncation__ao_full, threshold)
482 work2 = work2 + 1
483 end if
484 end do
485 os%norbs = work2
486 os%ndim = 1
487 os%use_submesh = .false.
488 os%allocated_on_mesh = .true.
489 os%spec => ions%atom(ia)%species
490
491 do work = 1, os%norbs
492 ! We obtain the orbital
493 if (states_are_real(st)) then
494 call dget_atomic_orbital(namespace, ions%space, ions%latt, ions%pos(:,ia), &
495 ions%atom(ia)%species, mesh, os%sphere, os%ii, os%ll, os%jj, &
496 os, work, os%radius, os%ndim, use_mesh=.not.os%use_submesh, &
497 normalize = normalize)
498 else
499 call zget_atomic_orbital(namespace, ions%space, ions%latt, ions%pos(:,ia), &
500 ions%atom(ia)%species, mesh, os%sphere, os%ii, os%ll, os%jj, &
501 os, work, os%radius, os%ndim, &
502 use_mesh = .not. hm%phase%is_allocated() .and. .not. os%use_submesh, &
503 normalize = normalize)
504 end if
505 end do
506
507 if (hm%phase%is_allocated()) then
508 ! In case of complex wavefunction, we allocate the array for the phase correction
509 safe_allocate(os%phase(1:os%sphere%np, st%d%kpt%start:st%d%kpt%end))
510 os%phase(:,:) = m_zero
511
512 if (.not. os%use_submesh) then
513 safe_allocate(os%eorb_mesh(1:mesh%np, 1:os%norbs, 1:os%ndim, st%d%kpt%start:st%d%kpt%end))
514 os%eorb_mesh(:,:,:,:) = m_zero
515 else
516 safe_allocate(os%eorb_submesh(1:os%sphere%np, 1:os%ndim, 1:os%norbs, st%d%kpt%start:st%d%kpt%end))
517 os%eorb_submesh(:,:,:,:) = m_zero
518 end if
519
520 if (accel_is_enabled() .and. st%d%dim == 1) then
521 os%ldorbs_eorb = max(pad_pow2(os%sphere%np), 1)
522 if(.not. os%use_submesh) os%ldorbs_eorb = max(pad_pow2(os%sphere%mesh%np), 1)
523
524 safe_allocate(os%buff_eorb(st%d%kpt%start:st%d%kpt%end))
525 do ik= st%d%kpt%start, st%d%kpt%end
526 call accel_create_buffer(os%buff_eorb(ik), accel_mem_read_only, type_cmplx, os%ldorbs_eorb*os%norbs)
527 end do
528 end if
529
530 call orbitalset_update_phase(os, box%dim, st%d%kpt, hm%kpoints, (st%d%ispin==spin_polarized), &
531 vec_pot = hm%hm_base%uniform_vector_potential, &
532 vec_pot_var = hm%hm_base%vector_potential)
533 else
534 if (states_are_real(st)) then
535 call dorbitalset_transfer_to_device(os, st%d%kpt, .not. os%use_submesh)
536 else
537 call zorbitalset_transfer_to_device(os, st%d%kpt, .not. os%use_submesh)
538 end if
539 end if
540
541 if (st%system_grp%is_root()) then
542 if (os%nn /= 0) then
543 write(filename,'(a, i4.4, a1, a, i1.1, a1,a)') 'pdos-at', ia, '-', trim(os%spec%get_label()), &
544 os%nn, l_notation(os%ll), '.dat'
545 else
546 write(filename,'(a, i4.4, a1, a, a1,a)') 'pdos-at', ia, '-', trim(os%spec%get_label()), &
547 l_notation(os%ll), '.dat'
548 end if
549
550 iunit(0) = io_open(trim(dir)//'/'//trim(filename), namespace, action='write')
551 ! write header
552 write(iunit(0), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), &
553 '], projected DOS (total and orbital resolved)'
554 end if
555
556 if (states_are_real(st)) then
557 safe_allocate(ddot(1:st%d%dim, 1:os%norbs, 1:st%block_size))
558 else
559 safe_allocate(zdot(1:st%d%dim, 1:os%norbs, 1:st%block_size))
560 end if
561
562 safe_allocate(weight(1:os%norbs,1:st%nik,1:st%nst))
563 weight(1:os%norbs,1:st%nik,1:st%nst) = m_zero
564
565 do ik = st%d%kpt%start, st%d%kpt%end
566 do ib = st%group%block_start, st%group%block_end
567
568 if (hm%phase%is_allocated()) then
569 safe_allocate(epsib)
570 call st%group%psib(ib, ik)%copy_to(epsib)
571 call hm%phase%apply_to(mesh, mesh%np, .false., epsib, src = st%group%psib(ib, ik))
572 else
573 epsib => st%group%psib(ib, ik)
574 end if
575
576 if (states_are_real(st)) then
577 call dorbitalset_get_coeff_batch(os, st%d%dim, epsib, ddot(:, :, :))
578 do ist = 1, st%group%psib(ib, ik)%nst
579 ind = st%group%psib(ib, ik)%ist(ist)
580 do iorb = 1, os%norbs
581 do idim = 1, st%d%dim
582 weight(iorb, ik, ind) = weight(iorb, ik, ind) + st%kweights(ik) * abs(ddot(idim, iorb, ist))**2
583 end do
584 end do
585 end do
586 else
587 call zorbitalset_get_coeff_batch(os, st%d%dim, epsib, zdot(:, :, :))
588 do ist = 1, st%group%psib(ib, ik)%nst
589 ind = st%group%psib(ib, ik)%ist(ist)
590 do iorb = 1, os%norbs
591 do idim = 1, st%d%dim
592 weight(iorb, ik, ind) = weight(iorb, ik, ind) + st%kweights(ik) * abs(zdot(idim, iorb, ist))**2
593 end do
594 end do
595 end do
596 end if
597
598 if (hm%phase%is_allocated()) then
599 call epsib%end(copy=.false.)
600 safe_deallocate_p(epsib)
601 end if
602
603 end do
604 end do
605
606 if (st%parallel_in_states .or. st%d%kpt%parallel) then
607 call comm_allreduce(st%st_kpt_mpi_grp, weight)
608 end if
609
610 safe_deallocate_a(ddot)
611 safe_deallocate_a(zdot)
612
613 if (st%system_grp%is_root()) then
614 write(format_str,'(a,i5,a)') '(', os%norbs+2, 'es25.16E3)'
615 safe_allocate(tdos(1:os%norbs))
616 do ie = 1, this%epoints
617 energy = this%emin + (ie - 1) * this%de
618 tdos(:) = m_zero
619
620 select case (this%method)
621 case (option__dosmethod__smear)
622 do iorb = 1, os%norbs
623 do ist = 1, st%nst
624 do ik = 1, st%nik
625 tdos(iorb) = tdos(iorb) + weight(iorb,ik,ist) / this%gamma * &
626 smear_delta_function(smear, (energy - st%eigenval(ist, ik))/this%gamma)
627 end do
628 end do
629 end do
630 case (option__dosmethod__tetrahedra, option__dosmethod__tetrahedra_opt)
631 assert(associated(hm%kpoints%reduced%simplex))
632 simplex => hm%kpoints%reduced%simplex
633 nvertices = simplex%rdim + 1
634 assert(nvertices <= 4)
635 call profiling_in("DOS_WRITE_PDOS_TETRAHEDRA")
636 !$omp parallel do collapse(3) reduction(+:tdos) &
637 !$omp private(iorb, ist, ii, is, ll, ik, e_simplex, a_simplex, dos_simplex)
638 do iorb = 1, os%norbs
639 do ist = 1, st%nst
640 do ii = 1, simplex%n_simplices
641 do is = 0, ns - 1
642 do ll = 1, simplex%sdim
643 ik = simplex%simplices(ii, ll)
644 ik = ns * (ik - 1) + 1
645 e_simplex(ll) = st%eigenval(ist, ik+is)
646 end do
647
648 do ll = 1, nvertices
649 ik = simplex%simplices(ii, ll)
650 ik = ns * (ik - 1) + 1
651 if (st%kweights(ik+is) > m_epsilon) then
652 a_simplex(ll) = weight(iorb, ik+is, ist) / st%kweights(ik+is)
653 else
654 a_simplex(ll) = m_zero
655 end if
656 end do
657
658 call simplex_dos(simplex%rdim, e_simplex(1:simplex%sdim), energy, dos_simplex(1:nvertices))
659 tdos(iorb) = tdos(iorb) + sum(a_simplex(1:nvertices) * dos_simplex(1:nvertices)) / &
660 simplex%n_points
661 end do
662 end do
663 end do
664 end do
665 !$omp end parallel do
666 call profiling_out("DOS_WRITE_PDOS_TETRAHEDRA")
667 case default
668 assert(.false.)
669 end select
670
671 write(iunit(0), trim(format_str)) units_from_atomic(units_out%energy, energy), &
672 units_from_atomic(unit_one / units_out%energy, sum(tdos)), &
673 (units_from_atomic(unit_one / units_out%energy, tdos(iorb)), iorb=1,os%norbs)
674 end do
675 safe_deallocate_a(tdos)
676 call io_close(iunit(0))
677 end if
678
679 call orbitalset_end(os)
680 safe_deallocate_a(weight)
681
682 end do
683
684 end do
685
686 end if
687
688 safe_deallocate_a(iunit)
689 safe_deallocate_a(dos)
690
691 pop_sub(dos_write_dos)
692 end subroutine dos_write_dos
693
694 ! ---------------------------------------------------------
696 subroutine dos_write_jdos(this, dir, st, ions, hm, namespace)
697 type(dos_t), intent(in) :: this
698 character(len=*), intent(in) :: dir
699 type(states_elec_t), intent(in) :: st
700 type(ions_t), target, intent(in) :: ions
701 type(hamiltonian_elec_t), intent(in) :: hm
702 type(namespace_t), intent(in) :: namespace
703
704 integer :: ie, ik, val, cond, is, ns, ll, ii, nvertices
705 integer, allocatable :: iunit(:)
706 real(real64) :: energy
707 real(real64) :: tjdos(1), e_simplex(20), occ_simplex(4)
708 real(real64), allocatable :: jdos(:,:), energies(:), dos_simplex(:,:)
709 character(len=64) :: filename
710
711 type(smear_t) :: smear
712 type(simplex_t), pointer :: simplex
713
714 push_sub(dos_write_jdos)
715
716 ! shortcuts
717 ns = 1
718 if (st%d%nspin == 2) ns = 2
719
720 ! set up smearing parameters
721 smear%method = this%smear_func
722 smear%MP_n = 1
723
724 if (st%system_grp%is_root()) then
725 ! space for state-dependent DOS
726 safe_allocate(jdos(1:this%epoints, 0:ns-1))
727 safe_allocate(iunit(0:ns-1))
728 jdos = m_zero
729
730 select case (this%method)
731 case (option__dosmethod__smear)
732 ! compute band/spin-resolved density of states
733 do val = 1, st%nst
734 do cond = val, st%nst
735 do ik = 1, st%nik, ns
736 do is = 0, ns-1
737 if(st%occ(val, ik+is) < m_epsilon) cycle
738 if(st%occ(cond, ik+is) > m_epsilon) cycle
739 do ie = 1, this%epoints
740 energy = (ie - 1) * this%de
741 ! sum up Lorentzians
742 jdos(ie, is) = jdos(ie, is) + st%kweights(ik+is) / this%gamma * &
743 smear_delta_function(smear, (energy - (st%eigenval(cond, ik+is)-st%eigenval(val, ik+is)))/this%gamma)
744 end do
745 end do
746 end do
747 end do
748 end do
749 case (option__dosmethod__tetrahedra, option__dosmethod__tetrahedra_opt)
750 assert(associated(hm%kpoints%reduced%simplex))
751 simplex => hm%kpoints%reduced%simplex
752 nvertices = simplex%rdim + 1
753 assert(nvertices <= 4)
754 call profiling_in("DOS_WRITE_JDOS_TETRAHEDRA")
755 safe_allocate(energies(1:this%epoints))
756 do ie = 1, this%epoints
757 energies(ie) = (ie - 1) * this%de
758 end do
759 !$omp parallel reduction(+:jdos) &
760 !$omp private(val, cond, ie, ii, is, ll, ik, e_simplex, occ_simplex, dos_simplex)
761 safe_allocate(dos_simplex(1:nvertices, 1:this%epoints))
762 !$omp do collapse(3) schedule(dynamic)
763 do val = 1, st%nst
764 do cond = 1, st%nst
765 do ii = 1, simplex%n_simplices
766 if (cond < val) cycle
767 do is = 0, ns - 1
768 do ll = 1, simplex%sdim
769 ik = simplex%simplices(ii, ll)
770 ik = ns * (ik - 1) + 1
771 e_simplex(ll) = st%eigenval(cond, ik+is) - st%eigenval(val, ik+is)
772 end do
773
774 do ll = 1, nvertices
775 ik = simplex%simplices(ii, ll)
776 ik = ns * (ik - 1) + 1
777 if (st%occ(val, ik+is) > m_epsilon .and. st%occ(cond, ik+is) < m_epsilon) then
778 occ_simplex(ll) = m_one
779 else
780 occ_simplex(ll) = m_zero
781 end if
782 end do
783
784 call simplex_dos(simplex%rdim, e_simplex(1:simplex%sdim), energies, dos_simplex)
785 do ie = 1, this%epoints
786 jdos(ie, is) = jdos(ie, is) + sum(occ_simplex(1:nvertices) * dos_simplex(1:nvertices, ie)) / &
787 simplex%n_points
788 end do
789 end do
790 end do
791 end do
792 end do
793 !$omp end do
794 safe_deallocate_a(dos_simplex)
795 !$omp end parallel
796 safe_deallocate_a(energies)
797 call profiling_out("DOS_WRITE_JDOS_TETRAHEDRA")
798 case default
799 assert(.false.)
800 end select
801
802 ! for spin-polarized calculations also output spin-resolved tDOS
803 if (st%d%nspin > 1) then
804 do is = 0, ns-1
805 write(filename, '(a,i1.1,a)') 'total-jdos-', is+1,'.dat'
806 iunit(is) = io_open(trim(dir)//'/'//trim(filename), namespace, action='write')
807 ! write header
808 write(iunit(is), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), '], total JDOS (spin-resolved)'
809
810 do ie = 1, this%epoints
811 energy = (ie - 1) * this%de
812 write(message(1), '(2es25.16E3)') units_from_atomic(units_out%energy, energy), &
813 units_from_atomic(unit_one / units_out%energy, jdos(ie, is))
814 call messages_info(1, iunit(is))
815 end do
816
817 call io_close(iunit(is))
818 end do
819 end if
820
821
822 iunit(0) = io_open(trim(dir)//'/'//'total-jdos.dat', namespace, action='write')
823 write(iunit(0), '(3a)') '# energy [', trim(units_abbrev(units_out%energy)), '], total JDOS'
824
825 ! compute total joint density of states
826 do ie = 1, this%epoints
827 energy = (ie - 1) * this%de
828 tjdos(1) = m_zero
829 do is = 0, ns-1
830 tjdos(1) = tjdos(1) + jdos(ie, is)
831 end do
832 write(message(1), '(2es25.16E3)') units_from_atomic(units_out%energy, energy), &
833 units_from_atomic(unit_one / units_out%energy, tjdos(1))
834 call messages_info(1, iunit(0))
835 end do
836
837 call io_close(iunit(0))
838 end if
839
840 safe_deallocate_a(iunit)
841 safe_deallocate_a(jdos)
842
843 pop_sub(dos_write_jdos)
844 end subroutine dos_write_jdos
845
846
847 ! ---------------------------------------------------------
849 subroutine dos_write_ldos(this, dir, st, ions, gr, hm, how, namespace)
850 type(dos_t), intent(in) :: this
851 character(len=*), intent(in) :: dir
852 type(states_elec_t), intent(in) :: st
853 type(ions_t), target, intent(in) :: ions
854 type(grid_t), intent(in) :: gr
855 type(hamiltonian_elec_t), intent(in) :: hm
856 integer(int64), intent(in) :: how
857 type(namespace_t), intent(in) :: namespace
858
859 integer :: ie, ik, ist, is, ns, ip, ifull, ierr, ii, ll, nvertices, ikpoint
860 integer :: iop, iiop, nops, nops_max
861 character(len=MAX_PATH_LEN) :: fname, name
862 logical :: has_local_corner
863 real(real64) :: weight, e_simplex(20)
864 real(real64), allocatable :: ldos(:,:,:), dpsi(:,:), abs_psi2(:), abs_psi2_symm(:), ldos_weights(:,:,:)
865 real(real64), allocatable :: dos_simplex(:,:)
866 complex(real64), allocatable :: zpsi(:,:)
867 type(unit_t) :: fn_unit
868
869 type(smear_t) :: smear
870 type(simplex_t), pointer :: simplex
871
872 push_sub(dos_write_ldos)
873
874 if (this%ldos_nenergies < 1) then
875 message(1) = "LDOSEnergies must be defined for Output=ldos"
876 call messages_fatal(1, namespace=namespace)
877 end if
878
879 ! shortcuts
880 ns = 1
881 if (st%d%nspin == 2) ns = 2
882
883 ! set up smearing parameters
884 smear%method = this%smear_func
885 smear%MP_n = 1
886
887 fn_unit = units_out%length**(-ions%space%dim) / units_out%energy
888
889 ! space for state-dependent DOS
890 safe_allocate(ldos(1:gr%np, 1:this%ldos_nenergies, 1:ns))
891 ldos = m_zero
892
893 safe_allocate(abs_psi2(1:gr%np))
894 if (states_are_real(st)) then
895 safe_allocate(dpsi(1:gr%np, 1:st%d%dim))
896 else
897 safe_allocate(zpsi(1:gr%np, 1:st%d%dim))
898 end if
899
900 select case (this%method)
901 case (option__dosmethod__smear)
902 nops_max = 1
903 safe_allocate(ldos_weights(1:this%ldos_nenergies, st%d%kpt%start:st%d%kpt%end, 1:nops_max))
904 case (option__dosmethod__tetrahedra, option__dosmethod__tetrahedra_opt)
905 assert(associated(hm%kpoints%full%simplex))
906 simplex => hm%kpoints%full%simplex
907 nvertices = simplex%rdim + 1
908 assert(nvertices <= 4)
909 nops_max = 1
910 do ifull = 1, hm%kpoints%full%npoints
911 nops_max = max(nops_max, hm%kpoints%get_full_symmetry_op_index(ifull))
912 end do
913 safe_allocate(ldos_weights(1:this%ldos_nenergies, st%d%kpt%start:st%d%kpt%end, 1:nops_max))
914 safe_allocate(abs_psi2_symm(1:gr%np))
915 case default
916 assert(.false.)
917 end select
918
919 do ist = st%st_start, st%st_end
920 ldos_weights(:, :, :) = m_zero
921
922 select case (this%method)
923 case (option__dosmethod__smear)
924 do ik = st%d%kpt%start, st%d%kpt%end
925 do ie = 1, this%ldos_nenergies
926 ldos_weights(ie, ik, 1) = st%kweights(ik) / this%gamma * &
927 smear_delta_function(smear, (this%ldos_energies(ie) - st%eigenval(ist, ik))/this%gamma)
928 end do
929 end do
930 case (option__dosmethod__tetrahedra, option__dosmethod__tetrahedra_opt)
931 call profiling_in('DOS_WRITE_LDOS_TETRAHEDRA')
932 !$omp parallel reduction(+:ldos_weights) &
933 !$omp private(ii, is, ll, ik, ie, e_simplex, dos_simplex, ifull, iiop, has_local_corner)
934 safe_allocate(dos_simplex(1:nvertices, 1:this%ldos_nenergies))
935 !$omp do collapse(2) schedule(dynamic)
936 do ii = 1, simplex%n_simplices
937 do is = 0, ns - 1
938 has_local_corner = .false.
939 do ll = 1, simplex%sdim
940 ik = hm%kpoints%get_equiv(simplex%simplices(ii, ll))
941 ik = ns * (ik - 1) + 1 + is
942 e_simplex(ll) = st%eigenval(ist, ik)
943 if (ik >= st%d%kpt%start .and. ik <= st%d%kpt%end) has_local_corner = .true.
944 end do
945 if (.not. has_local_corner) cycle
946
947 call simplex_dos(simplex%rdim, e_simplex(1:simplex%sdim), this%ldos_energies, &
948 dos_simplex(1:nvertices, 1:this%ldos_nenergies))
949 do ie = 1, this%ldos_nenergies
950 do ll = 1, nvertices
951 ifull = simplex%simplices(ii, ll)
952 iiop = hm%kpoints%get_full_symmetry_op_index(ifull)
953 ik = hm%kpoints%get_equiv(ifull)
954 ik = ns * (ik - 1) + 1 + is
955 if (ik >= st%d%kpt%start .and. ik <= st%d%kpt%end) then
956 ldos_weights(ie, ik, iiop) = ldos_weights(ie, ik, iiop) + dos_simplex(ll, ie) / simplex%n_points
957 end if
958 end do
959 end do
960 end do
961 end do
962 !$omp end do
963 safe_deallocate_a(dos_simplex)
964 !$omp end parallel
965 call profiling_out('DOS_WRITE_LDOS_TETRAHEDRA')
966 case default
967 assert(.false.)
968 end select
969
970 do ik = st%d%kpt%start, st%d%kpt%end
971 is = st%d%get_spin_index(ik)
972
973 if (states_are_real(st)) then
974 call states_elec_get_state(st, gr, ist, ik, dpsi)
975 do ip = 1, gr%np
976 abs_psi2(ip) = dpsi(ip, 1)**2
977 end do
978 if (st%d%dim > 1) then
979 do ip = 1, gr%np
980 abs_psi2(ip) = abs_psi2(ip) + dpsi(ip, 2)**2
981 end do
982 end if
983 else
984 call states_elec_get_state(st, gr, ist, ik, zpsi)
985 do ip = 1, gr%np
986 abs_psi2(ip) = real(conjg(zpsi(ip, 1)) * zpsi(ip, 1), real64)
987 end do
988 if (st%d%dim > 1) then
989 do ip = 1, gr%np
990 abs_psi2(ip) = abs_psi2(ip) + real(conjg(zpsi(ip, 2)) * zpsi(ip, 2), real64)
991 end do
992 end if
993 end if
994
995 select case (this%method)
996 case (option__dosmethod__smear)
997 do ie = 1, this%ldos_nenergies
998 weight = ldos_weights(ie, ik, 1)
999 call lalg_axpy(gr%np, weight, abs_psi2, ldos(:, ie, is))
1000 end do
1001 case (option__dosmethod__tetrahedra, option__dosmethod__tetrahedra_opt)
1002 ikpoint = st%d%get_kpoint_index(ik)
1003 nops = kpoints_get_num_symmetry_ops(hm%kpoints, ikpoint)
1004 do iiop = 1, nops
1005 iop = abs(kpoints_get_symmetry_ops(hm%kpoints, ikpoint, iiop))
1006 call dgrid_symmetrize_single(gr, iop, abs_psi2, abs_psi2_symm, suppress_warning = .true.)
1007 do ie = 1, this%ldos_nenergies
1008 weight = ldos_weights(ie, ik, iiop)
1009 call lalg_axpy(gr%np, weight, abs_psi2_symm, ldos(:, ie, is))
1010 end do
1011 end do
1012 case default
1013 assert(.false.)
1014 end select
1015 end do
1016 end do
1017
1018 safe_deallocate_a(ldos_weights)
1019 safe_deallocate_a(dpsi)
1020 safe_deallocate_a(zpsi)
1021 safe_deallocate_a(abs_psi2)
1022 safe_deallocate_a(abs_psi2_symm)
1023
1024 if (st%parallel_in_states .or. st%d%kpt%parallel) then
1025 call comm_allreduce(st%st_kpt_mpi_grp, ldos)
1026 end if
1027
1028 do is = 1, ns
1029 do ie = 1, this%ldos_nenergies
1030 write(name, '(a,i5.5)') 'ldos_en-', ie
1031 fname = get_filename_with_spin(name, st%d%nspin, is)
1032
1033 if (hm%kpoints%use_symmetries .and. &
1034 .not. (this%method == option__dosmethod__tetrahedra .or. this%method == option__dosmethod__tetrahedra_opt)) then
1035 call dgrid_symmetrize_scalar_field(gr, ldos(:, ie, is), suppress_warning = .true.)
1036 end if
1037 call dio_function_output(how, dir, fname, namespace, ions%space, gr, &
1038 ldos(:, ie, is), fn_unit, ierr, pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
1039 end do
1040 end do
1041
1042 safe_deallocate_a(ldos)
1043
1044 pop_sub(dos_write_ldos)
1045 end subroutine dos_write_ldos
1046
1047
1048end module dos_oct_m
1049
1050!! Local Variables:
1051!! mode: f90
1052!! coding: utf-8
1053!! 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:342
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:355
subroutine, public dos_write_jdos(this, dir, st, ions, hm, namespace)
Computes and output the joint DOS (JDOS)
Definition: dos.F90:792
subroutine, public dos_init(this, namespace, st, kpoints)
Initializes the dot_t object.
Definition: dos.F90:195
subroutine, public dos_write_ldos(this, dir, st, ions, gr, hm, how, namespace)
Computes and output the local DOS (LDOS)
Definition: dos.F90:945
integer, parameter, public spin_polarized
real(real64), parameter, public m_zero
Definition: global.F90:200
real(real64), parameter, public m_four
Definition: global.F90:204
real(real64), parameter, public m_epsilon
Definition: global.F90:216
real(real64), parameter, public m_one
Definition: global.F90:201
This module implements the underlying real-space grid.
Definition: grid.F90:119
subroutine, public dgrid_symmetrize_single(gr, iop, field, symm_field, suppress_warning)
Definition: grid.F90:726
subroutine, public dgrid_symmetrize_scalar_field(gr, field, suppress_warning)
Definition: grid.F90:672
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
integer pure function, public kpoints_get_num_symmetry_ops(this, ik)
Definition: kpoints.F90:1730
integer pure function, public kpoints_get_symmetry_ops(this, ik, index)
Definition: kpoints.F90:1743
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:846
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:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
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
real(real64) function, public smear_delta_function(this, xx)
Definition: smear.F90:832
integer, parameter, public smear_fermi_dirac
Definition: smear.F90:176
integer, parameter, public smear_methfessel_paxton
Definition: smear.F90:176
integer, parameter, public smear_lorentzian
Definition: smear.F90:176
integer, parameter, public smear_spline
Definition: smear.F90:176
integer, parameter, public smear_cold
Definition: smear.F90:176
integer, parameter, public smear_gaussian
Definition: smear.F90:176
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
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
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)