Octopus
lcao.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21module lcao_oct_m
22 use atom_oct_m
24 use batch_oct_m
25 use blacs_oct_m
28 use comm_oct_m
29 use debug_oct_m
31 use epot_oct_m
32 use global_oct_m
33 use grid_oct_m
36 use io_oct_m
38 use ions_oct_m
39 use, intrinsic :: iso_fortran_env
43 use lapack_oct_m
44 use loct_oct_m
46 use math_oct_m
47 use mesh_oct_m
50 use mpi_oct_m
53 use parser_oct_m
55 use ps_oct_m
59 use smear_oct_m
60 use space_oct_m
69 use unit_oct_m
71 use v_ks_oct_m
74 use xc_oct_m
75 use xc_sic_oct_m
76
77 implicit none
78
79 private
80 public :: &
81 lcao_t, &
82 lcao_init, &
84 lcao_wf, &
85 lcao_run, &
86 lcao_end, &
89
90 type lcao_t
91 private
92 integer :: mode
93 logical :: complex_ylms
94 logical :: initialized
95 integer :: norbs
96 integer :: maxorbs
97 integer, allocatable :: atom(:)
98 integer, allocatable :: level(:)
99 integer, allocatable :: ddim(:)
100 logical :: alternative
101 logical :: derivative
102 integer, allocatable :: cst(:, :)
103 integer, allocatable :: ck(:, :)
104 real(4), allocatable :: dbuff_single(:, :, :, :)
105 complex(4), allocatable :: zbuff_single(:, :, :, :)
106 real(real64), allocatable :: dbuff(:, :, :, :)
107 complex(real64), allocatable :: zbuff(:, :, :, :)
108 logical :: save_memory
109 logical :: initialized_orbitals
110 real(real64) :: orbital_scale_factor
111
113 logical, allocatable :: is_empty(:)
114 ! !< This occurs in domain parallelization if the atom is not
115 ! !< in the local domain
116
118 logical :: keep_orb
119 real(real64), allocatable :: radius(:)
120 real(real64) :: lapdist
121 integer :: mult
122 integer :: maxorb
124 integer, allocatable :: basis_atom(:)
125 integer, allocatable :: basis_orb(:)
126 integer, allocatable :: atom_orb_basis(:, :)
127 integer, allocatable :: norb_atom(:)
128 logical :: parallel
129 integer :: lsize(1:2)
130 integer :: nproc(1:2)
131 integer :: myroc(1:2)
132 integer :: desc(1:BLACS_DLEN)
133 logical, allocatable :: calc_atom(:)
134 real(real64) :: diag_tol
135 type(submesh_t), allocatable :: sphere(:)
136 type(batch_t), allocatable :: orbitals(:)
137 logical, allocatable :: is_orbital_initialized(:)
138
139 integer :: gmd_opt
140 end type lcao_t
141
142
143 integer, parameter :: &
144 INITRHO_PARAMAGNETIC = 1, &
146 initrho_random = 3, &
147 initrho_userdef = 77
148
149contains
150
151 ! ---------------------------------------------------------
152 subroutine lcao_init(this, namespace, space, gr, ions, st, st_start)
153 type(lcao_t), intent(out) :: this
154 type(namespace_t), intent(in) :: namespace
155 type(electron_space_t), intent(in) :: space
156 type(grid_t), intent(in) :: gr
157 type(ions_t), intent(in) :: ions
158 type(states_elec_t), intent(in) :: st
159 integer, intent(in) :: st_start
160
161 integer :: ia, n, iorb, jj, maxj, idim
162 integer :: ii, ll, mm, norbs, ii_tmp
163 integer :: mode_default
164 real(real64) :: max_orb_radius, maxradius
165 integer :: iunit_o
166
167 push_sub(lcao_init)
168
169 this%initialized = .true.
170
171 ! The initial LCAO calculation is done by default if we have species representing atoms.
172 ! Otherwise, it is not the default value and has to be enforced in the input file.
173 mode_default = option__lcaostart__lcao_states
174 if (ions%only_user_def) mode_default = option__lcaostart__lcao_none
175
176 !%Variable LCAOStart
177 !%Type integer
178 !%Section SCF::LCAO
179 !%Description
180 !% Before starting a SCF calculation, <tt>Octopus</tt> can perform
181 !% a linear combination of atomic orbitals (LCAO) calculation.
182 !% These can provide <tt>Octopus</tt> with a good set
183 !% of initial wavefunctions and with a new guess for the density.
184 !% (Up to the current version, only a minimal basis set is used.)
185 !% The default is <tt>lcao_states</tt> if at least one species representing an atom is present.
186 !% The default is <tt>lcao_none</tt> if all species are <tt>species_user_defined</tt>,
187 !% <tt>species_charge_density</tt>, <tt>species_from_file</tt>, or <tt>species_jellium_slab</tt>.
188 !%
189 !% The initial guess densities for LCAO are taken from the atomic orbitals for pseudopotential species;
190 !% from the natural charge density for <tt>species_charge_density</tt>, <tt>species_point</tt>,
191 !% <tt>species_jellium</tt>, and <tt>species_jellium_slab</tt>;
192 !% or uniform for <tt>species_full_delta</tt>, <tt>species_full_gaussian</tt>,
193 !% <tt>species_user_defined</tt>, or <tt>species_from_file</tt>.
194 !% Pseudopotential species use the pseudo-wavefunctions as orbitals, full-potential atomic species
195 !% (<tt>species_full_delta</tt> and <tt>species_full_gaussian</tt>) use hydrogenic wavefunctions, and
196 !% others use harmonic-oscillator wavefunctions.
197 !%
198 !% The LCAO implementation currently does not simultaneously support k-point parallelism and states parallelism.
199 !% You must select one or the other, or alternatively use lcao_none (random wavefunctions) as an initial guess.
200 !%
201 !% Note: Some pseudopotential files (CPI, FHI for example) do not
202 !% contain full information about the orbitals. In this case,
203 !% Octopus generates the starting density from the normalized
204 !% square root of the local potential. If no orbitals are
205 !% available at all from the pseudopotential files, Octopus will
206 !% not be able to perform an LCAO and the initial states will be
207 !% randomized.
208 !%
209 !%Option lcao_none 0
210 !% Do not perform a LCAO calculation before the SCF cycle. Instead use random wavefunctions.
211 !%Option lcao_states 2
212 !% Do a LCAO calculation before the SCF cycle and use the resulting wavefunctions as
213 !% initial wavefunctions without changing the guess density.
214 !% This will speed up the convergence of the eigensolver during the first SCF iterations.
215 !%Option lcao_full 3
216 !% Do a LCAO calculation before the SCF cycle and use the LCAO wavefunctions to build a new
217 !% guess density and a new KS potential.
218 !% Using the LCAO density as a new guess density may improve the convergence, but can
219 !% also slow it down or yield wrong results (especially for spin-polarized calculations).
220 !%Option lcao_states_batch 4
221 !% (Experimental) Same as lcao_states, but faster for GPUs, large systems and parallel in states.
222 !% It is not working for spinors, however.
223 !% This is not used for unocc calculations at the moment.
224 !%End
225 call parse_variable(namespace, 'LCAOStart', mode_default, this%mode)
226 if (.not. varinfo_valid_option('LCAOStart', this%mode)) call messages_input_error(namespace, 'LCAOStart')
228 call messages_print_var_option('LCAOStart', this%mode, namespace=namespace)
230 ! LCAO alternative not implemented for st_start > 1
231 if (this%mode == option__lcaostart__lcao_states_batch .and. st_start > 1) then
232 message(1) = "LCAOStart = lcao_states_batch not compatible with this run."
233 message(2) = "Please use LCAOStart = lcao_states instead"
234 call messages_fatal(2, namespace=namespace)
235 end if
237 !TODO: Remove the alternative flag
238 this%alternative = this%mode == option__lcaostart__lcao_states_batch
239
240 if (this%mode == option__lcaostart__lcao_none) then
241 pop_sub(lcao_init)
242 return
243 end if
244
245 call messages_obsolete_variable(namespace, 'LCAOAlternative')
246
247
248 ! DAS: For spinors, you will always get magnetization in (1, 0, 0) direction, and the
249 ! eigenvalues will be incorrect. This is due to confusion between spins and spinors in the code.
250 if (st%d%ispin == spinors .and. this%alternative) then
251 message(1) = "LCAOStart = lcao_states_batch is not working for spinors."
252 call messages_fatal(1, namespace=namespace)
253 end if
254 if (space%is_periodic() .and. this%alternative) then
255 call messages_experimental("LCAOStart = lcao_states_batch in periodic systems", namespace=namespace)
256 ! specifically, if you get the message about submesh radius > box size, results will probably be totally wrong.
257 end if
258
259 !%Variable LCAOComplexYlms
260 !%Type logical
261 !%Default false
262 !%Section SCF::LCAO
263 !%Description
264 !% If set to true, and using complex states, complex spherical harmonics will be used, <i>i.e.</i>
265 !% with <math>e^{\pm i m \phi}</math>.
266 !% If false, real spherical harmonics with <math>\sin(m \phi)</math> or <math>\cos(m \phi)</math> are used.
267 !% This variable will make it more likely to get states that are eigenvectors of the <math>L_z</math>
268 !% operator, with a definite angular momentum.
269 !%End
270
271 if (states_are_complex(st)) then
272 call parse_variable(namespace, 'LCAOComplexYlms', .false., this%complex_ylms)
273 else
274 this%complex_ylms = .false.
275 end if
276
277 !%Variable LCAOSaveMemory
278 !%Type logical
279 !%Default false
280 !%Section SCF::LCAO
281 !%Description
282 !% If set to true, the LCAO will allocate extra memory needed in single precision instead of
283 !% double precision.
284 !%End
285 call parse_variable(namespace, 'LCAOSaveMemory', .false., this%save_memory)
286
287
288 if (debug%info .and. mpi_grp_is_root(mpi_world)) then
289 call io_mkdir('debug/lcao', namespace)
290 iunit_o = io_open('debug/lcao/orbitals', namespace, action='write')
291 write(iunit_o,'(7a6)') 'iorb', 'atom', 'level', 'i', 'l', 'm', 'spin'
292 end if
293
294 if (.not. this%alternative) then
295
296 !%Variable LCAOScaleFactor
297 !%Type float
298 !%Default 1.0
299 !%Section SCF::LCAO
300 !%Description
301 !% The coordinates of the atomic orbitals used by the LCAO
302 !% procedure will be rescaled by the value of this variable. 1.0 means no rescaling.
303 !%End
304 call parse_variable(namespace, 'LCAOScaleFactor', m_one, this%orbital_scale_factor)
305 call messages_print_var_value('LCAOScaleFactor', this%orbital_scale_factor, namespace=namespace)
306
307 !%Variable LCAOMaximumOrbitalRadius
308 !%Type float
309 !%Default 20.0 a.u.
310 !%Section SCF::LCAO
311 !%Description
312 !% The LCAO procedure will ignore orbitals that have an
313 !% extent greater that this value.
314 !%End
315 call parse_variable(namespace, 'LCAOMaximumOrbitalRadius', 20.0_real64, max_orb_radius, unit = units_inp%length)
316 call messages_print_var_value('LCAOMaximumOrbitalRadius', max_orb_radius, units_out%length, namespace=namespace)
317
318 ! count the number of orbitals available
319 maxj = 0
320 this%maxorbs = 0
321 do ia = 1, ions%natoms
322 maxj = max(maxj, ions%atom(ia)%species%get_niwfs())
323 this%maxorbs = this%maxorbs + ions%atom(ia)%species%get_niwfs()
324 end do
325
326 this%maxorbs = this%maxorbs*st%d%dim
327
328 if (this%maxorbs == 0) then
329 call messages_write('The are no atomic orbitals available, cannot do LCAO.')
330 call messages_warning(namespace=namespace)
331 this%mode = option__lcaostart__lcao_none
332 pop_sub(lcao_init)
333 return
334 end if
335
336 ! generate tables to know which indices each atomic orbital has
337
338 safe_allocate( this%atom(1:this%maxorbs))
339 safe_allocate(this%level(1:this%maxorbs))
340 safe_allocate( this%ddim(1:this%maxorbs))
341
342 safe_allocate(this%is_empty(1:this%maxorbs))
343 this%is_empty = .false.
344
345 ! this is determined by the stencil we are using and the spacing
346 this%lapdist = maxval(abs(gr%idx%enlarge)*gr%spacing)
347
348 ! calculate the radius of each orbital
349 safe_allocate(this%radius(1:ions%natoms))
350
351 do ia = 1, ions%natoms
352 norbs = ions%atom(ia)%species%get_niwfs()
353
354 maxradius = m_zero
355 do iorb = 1, norbs
356 call ions%atom(ia)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
357 ! For all-electron species, we need to use the principal quantum number
358 if(ions%atom(ia)%species%is_full()) call ions%atom(ia)%species%get_iwf_n( iorb, 1, ii)
359 maxradius = max(maxradius, ions%atom(ia)%species%get_iwf_radius( ii, is = 1))
360 end do
361
362 maxradius = min(maxradius, m_two*maxval(gr%box%bounding_box_l(1:space%dim)))
363
364 this%radius(ia) = maxradius
365 end do
366
367
368 ! Each atom provides niwfs pseudo-orbitals (this number is given in
369 ! ions%atom(ia)%species%niwfs for atom number ia). This number is
370 ! actually multiplied by two in case of spin-unrestricted or spinors
371 ! calculations.
372 !
373 ! The pseudo-orbitals are placed in order in the following way (Natoms
374 ! is the total number of atoms).
375 !
376 ! n = 1 => first orbital of atom 1,
377 ! n = 2 => first orbital of atom 2.
378 ! n = 3 => first orbital of atom 3.
379 ! ....
380 ! n = Natoms => first orbital of atom Natoms
381 ! n = Natoms + 1 = > second orbital of atom 1
382 ! ....
383 !
384 ! If at some point in this loop an atom pseudo cannot provide the corresponding
385 ! orbital (because the niws orbitals have been exhausted), it moves on to the following
386 ! atom.
387 !
388 ! In the spinors case, it changes a bit:
389 !
390 ! n = 1 => first spin-up orbital of atom 1, assigned to the spin-up component of the spinor.
391 ! n = 2 => first spin-down orbital of atom 1, assigned to the spin-down component of the spinor.
392 ! n = 3 => first spin-up orbital of atom 2, assigned to the spin-up component of the spinor.
393
394 iorb = 1
395 do jj = 1, maxj
396 do ia = 1, ions%natoms
397 do idim = 1,st%d%dim
398 if (jj > ions%atom(ia)%species%get_niwfs()) cycle
399 call ions%atom(ia)%species%get_iwf_ilm(jj, idim, ii, ll, mm)
400 ! For all-electron species, we need to use the principal quantum number
401 if(ions%atom(ia)%species%is_full()) then
402 ii_tmp = ii
403 call ions%atom(ia)%species%get_iwf_n( ii_tmp, 1, ii)
404 end if
405 if (this%orbital_scale_factor*ions%atom(ia)%species%get_iwf_radius( ii, is = 1) >= max_orb_radius) cycle
406
407 this%atom(iorb) = ia
408 this%level(iorb) = jj
409 this%ddim(iorb) = idim
410
411 if (debug%info .and. mpi_grp_is_root(mpi_world)) then
412 write(iunit_o,'(7i6)') iorb, this%atom(iorb), this%level(iorb), ii, ll, mm, this%ddim(iorb)
413 end if
414
415 iorb = iorb + 1
416 end do
417 end do
418 end do
419
420 if (debug%info .and. mpi_grp_is_root(mpi_world)) then
421 call io_close(iunit_o)
422 end if
423
424 ! some orbitals might have been removed because of their radii
425 if (this%maxorbs /= iorb - 1) then
426 call messages_write('Info: ')
427 call messages_write(this%maxorbs - iorb + 1)
428 call messages_write(' of ')
429 call messages_write(this%maxorbs)
430 call messages_write(' orbitals cannot be used for the LCAO calculation,')
431 call messages_new_line()
432 call messages_write(' their radii exceeds LCAOMaximumOrbitalRadius (')
433 call messages_write(max_orb_radius, units = units_out%length, fmt = '(f6.1)')
434 call messages_write(').')
435 call messages_warning(namespace=namespace)
436
437 this%maxorbs = iorb - 1
438 end if
439
440 if (this%maxorbs < st%nst) then
441 call messages_write('Cannot do LCAO for all states because there are not enough atomic orbitals.')
442 call messages_new_line()
443
444 call messages_write('Required: ')
445 call messages_write(st%nst)
446 call messages_write('. Available: ')
447 call messages_write(this%maxorbs)
448 call messages_write('. ')
449 call messages_write(st%nst - this%maxorbs)
450 call messages_write(' orbitals will be randomized.')
451 call messages_warning(namespace=namespace)
452 end if
453
454 !%Variable LCAODimension
455 !%Type integer
456 !%Section SCF::LCAO
457 !%Description
458 !% (Only applies if <tt>LCAOStart /= lcao_states_batch</tt>.)
459 !% Before starting the SCF cycle, an initial LCAO calculation can be performed
460 !% in order to obtain reasonable initial guesses for spin-orbitals and densities.
461 !% For this purpose, the code calculates a number of atomic orbitals.
462 !% The number available for a species described by a pseudopotential is all the
463 !% orbitals up the maximum angular momentum in the pseudopotential, minus any orbitals that
464 !% are found to be unbound. For non-pseudopotential species, the number is equal to
465 !% twice the valence charge.
466 !% The default dimension for the LCAO basis
467 !% set will be the sum of all these numbers, or twice the number of required orbitals
468 !% for the full calculation, whichever is less.
469 !%
470 !% This dimension however can be changed by making use of this
471 !% variable. Note that <tt>LCAODimension</tt> cannot be smaller than the
472 !% number of orbitals needed in the full calculation -- if
473 !% <tt>LCAODimension</tt> is smaller, it will be silently increased to meet
474 !% this requirement. In the same way, if <tt>LCAODimension</tt> is larger
475 !% than the available number of atomic orbitals, it will be
476 !% reduced. If you want to use the largest possible number, set
477 !% <tt>LCAODimension</tt> to a negative number.
478 !%End
479 call parse_variable(namespace, 'LCAODimension', 0, n)
480
481 if (n > 0 .and. n <= st%nst .and. st%nst <= this%maxorbs) then
482 ! n was made too small
483 this%norbs = st%nst
484 else if (n > st%nst .and. n <= this%maxorbs) then
485 ! n is a reasonable value
486 this%norbs = n
487 else if (n == 0) then
488 ! using the default
489 this%norbs = min(this%maxorbs, 2*st%nst)
490 else
491 ! n was negative, or greater than maxorbs
492 this%norbs = this%maxorbs
493 end if
494
495 assert(this%norbs <= this%maxorbs)
496
497 safe_allocate(this%cst(1:this%norbs, 1:st%d%spin_channels))
498 safe_allocate(this%ck(1:this%norbs, 1:st%d%spin_channels))
499 this%initialized_orbitals = .false.
500 else
501 call lcao2_init()
502 end if
503
504 pop_sub(lcao_init)
505
506 contains
507
508 subroutine lcao2_init()
509 integer :: iatom, iorb, norbs
510 real(real64) :: maxradius
511 integer :: ibasis
512#ifdef HAVE_SCALAPACK
513 integer :: jatom, jorb, jbasis, ilbasis, jlbasis, proc(1:2), info, nbl
514#endif
515 push_sub(lcao_init.lcao2_init)
516
517 call messages_write('Info: Using LCAO batched implementation.')
518 call messages_info(namespace=namespace)
519
520 call messages_experimental('LCAO alternative implementation', namespace=namespace)
521
522 !%Variable LCAOKeepOrbitals
523 !%Type logical
524 !%Default yes
525 !%Section SCF::LCAO
526 !%Description
527 !% Only applies if <tt>LCAOStart = lcao_states_batch</tt>.
528 !% If set to yes (the default) Octopus keeps atomic orbitals in
529 !% memory during the LCAO procedure. If set to no, the orbitals
530 !% are generated each time that they are needed, increasing
531 !% computational time but saving memory.
532 !%
533 !% When set to yes, Octopus prints the amount of memory per node
534 !% that is required to store the orbitals.
535 !%
536 !%End
537 call parse_variable(namespace, 'LCAOKeepOrbitals', .true., this%keep_orb)
538
539 !%Variable LCAOExtraOrbitals
540 !%Type logical
541 !%Default false
542 !%Section SCF::LCAO
543 !%Description
544 !% Only applies if <tt>LCAOStart = lcao_states_batch</tt>, and all species are pseudopotentials.
545 !% (experimental) If this variable is set to yes, the LCAO
546 !% procedure will add an extra set of numerical orbitals (by
547 !% using the derivative of the radial part of the original
548 !% orbitals). Note that this corresponds roughly to adding orbitals
549 !% with higher principal quantum numbers, but the same angular momentum.
550 !% This option may cause problems for unoccupied states since you may miss
551 !% some lower-lying states which correspond to higher angular momenta instead
552 !% of higher principal quantum number.
553 !%End
554 call parse_variable(namespace, 'LCAOExtraOrbitals', .false., this%derivative)
555
556 ! DAS: if you calculate the Na atom this way, spin-polarized, with just one unoccupied state,
557 ! you will obtain states (up and down) which are actually the 10th states if you start with
558 ! random wavefunctions! We really need to implement taking the derivative of the angular part
559 ! instead to be sure of getting decent results!
560
561 if (this%derivative) then
562 call messages_experimental('LCAO extra orbitals', namespace=namespace)
563
564 if (st%nst * st%smear%el_per_state > st%qtot) then
565 message(1) = "Lower-lying empty states may be missed with LCAOExtraOrbitals."
566 call messages_warning(1, namespace=namespace)
567 end if
568 end if
569
570 !%Variable LCAODiagTol
571 !%Type float
572 !%Default 1e-10
573 !%Section SCF::LCAO
574 !%Description
575 !% Only applies if <tt>LCAOStart = lcao_states_batch</tt>.
576 !% The tolerance for the diagonalization of the LCAO Hamiltonian.
577 !%End
578 call parse_variable(namespace, 'LCAODiagTol', 1e-10_real64, this%diag_tol)
579
580 if (this%derivative) then
581 this%mult = 2
582 else
583 this%mult = 1
584 end if
585
586 safe_allocate(this%sphere(1:ions%natoms))
587 safe_allocate(this%orbitals(1:ions%natoms))
588 safe_allocate(this%is_orbital_initialized(1:ions%natoms))
589 this%is_orbital_initialized = .false.
590
591 safe_allocate(this%norb_atom(1:ions%natoms))
592
593 this%maxorb = 0
594 this%norbs = 0
595 do iatom = 1, ions%natoms
596 this%norb_atom(iatom) = this%mult*ions%atom(iatom)%species%get_niwfs()
597 this%maxorb = max(this%maxorb, ions%atom(iatom)%species%get_niwfs())
598 this%norbs = this%norbs + ions%atom(iatom)%species%get_niwfs()
599 end do
600
601 this%maxorb = this%maxorb*this%mult
602 this%norbs = this%norbs*this%mult
603
604 safe_allocate(this%basis_atom(1:this%norbs))
605 safe_allocate(this%basis_orb(1:this%norbs))
606 safe_allocate(this%atom_orb_basis(1:ions%natoms, 1:this%maxorb))
607
608 ! Initialize the mapping between indices
609
610 ibasis = 0
611 do iatom = 1, ions%natoms
612 norbs = ions%atom(iatom)%species%get_niwfs()
613
614 do iorb = 1, this%mult*norbs
615 ibasis = ibasis + 1
616 this%atom_orb_basis(iatom, iorb) = ibasis
617 this%basis_atom(ibasis) = iatom
618 this%basis_orb(ibasis) = iorb
619
620 ! no stored spin index in alternative mode
621 if (debug%info .and. mpi_grp_is_root(mpi_world)) then
622 call ions%atom(iatom)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
623 write(iunit_o,'(7i6)') ibasis, iatom, iorb, ii, ll, mm, 1
624 end if
625 end do
626 end do
627
628 if (debug%info .and. mpi_grp_is_root(mpi_world)) then
629 call io_close(iunit_o)
630 end if
631
632 ! this is determined by the stencil we are using and the spacing
633 this%lapdist = maxval(abs(gr%idx%enlarge)*gr%spacing)
634
635 ! calculate the radius of each orbital
636 safe_allocate(this%radius(1:ions%natoms))
637
638 do iatom = 1, ions%natoms
639 norbs = ions%atom(iatom)%species%get_niwfs()
640
641 maxradius = m_zero
642 do iorb = 1, norbs
643 call ions%atom(iatom)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
644 ! For all-electron species, we need to use the principal quantum number
645 if(ions%atom(iatom)%species%is_full()) call ions%atom(iatom)%species%get_iwf_n( iorb, 1, ii)
646 maxradius = max(maxradius, ions%atom(iatom)%species%get_iwf_radius( ii, is = 1))
647 end do
648
649 if (this%derivative) maxradius = maxradius + this%lapdist
650
651 maxradius = min(maxradius, m_two*maxval(gr%box%bounding_box_l(1:space%dim)))
652
653 this%radius(iatom) = maxradius
654 end do
655
656 safe_allocate(this%calc_atom(1:ions%natoms))
657 this%calc_atom = .true.
658
659 ! initialize parallel data
660#ifndef HAVE_SCALAPACK
661 this%parallel = .false.
662#else
663 this%parallel = (st%parallel_in_states .or. gr%parallel_in_domains) &
664 .and. .not. blacs_proc_grid_null(st%dom_st_proc_grid)
665
666 if (this%parallel) then
667 nbl = min(16, this%norbs)
668
669 ! The size of the distributed matrix in each node
670 this%lsize(1) = max(1, numroc(this%norbs, nbl, st%dom_st_proc_grid%myrow, 0, st%dom_st_proc_grid%nprow))
671 this%lsize(2) = max(1, numroc(this%norbs, nbl, st%dom_st_proc_grid%mycol, 0, st%dom_st_proc_grid%npcol))
672
673 this%nproc(1) = st%dom_st_proc_grid%nprow
674 this%nproc(2) = st%dom_st_proc_grid%npcol
675 this%myroc(1) = st%dom_st_proc_grid%myrow
676 this%myroc(2) = st%dom_st_proc_grid%mycol
677
678 call descinit(this%desc(1), this%norbs, this%norbs, nbl, nbl, 0, 0, &
679 st%dom_st_proc_grid%context, this%lsize(1), info)
680
681 if (info /= 0) then
682 write(message(1), '(a,i6)') 'descinit for BLACS failed with error code ', info
683 call messages_fatal(1, namespace=namespace)
684 end if
685
686 this%calc_atom = .false.
687 do iatom = 1, ions%natoms
688 ibasis = this%atom_orb_basis(iatom, 1)
689
690 do jatom = 1, ions%natoms
691 jbasis = this%atom_orb_basis(jatom, 1)
692
693 do iorb = 1, this%norb_atom(iatom)
694 do jorb = 1, this%norb_atom(jatom)
695 call lcao_local_index(this, ibasis - 1 + iorb, jbasis - 1 + jorb, &
696 ilbasis, jlbasis, proc(1), proc(2))
697
698 this%calc_atom(this%basis_atom(jbasis)) = &
699 this%calc_atom(this%basis_atom(jbasis)) .or. proc(2) == this%myroc(2)
700
701 end do
702 end do
703
704 end do
705 end do
706
707 end if
708#endif
709
710 pop_sub(lcao_init.lcao2_init)
711 end subroutine lcao2_init
712
713 end subroutine lcao_init
714
715
716 ! ---------------------------------------------------------
717 subroutine lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r)
718 type(namespace_t), intent(in) :: namespace
719 type(electron_space_t), intent(in) :: space
720 type(grid_t), intent(in) :: gr
721 type(ions_t), intent(in) :: ions
722 type(partner_list_t), intent(in) :: ext_partners
723 type(states_elec_t), intent(inout) :: st
724 type(v_ks_t), intent(inout) :: ks
725 type(hamiltonian_elec_t), intent(inout) :: hm
726 integer, optional, intent(in) :: st_start
727 real(real64), optional, intent(in) :: lmm_r
728
729 type(lcao_t) :: lcao
730 integer :: st_start_random, required_min_nst
731 logical :: lcao_done
732 logical :: is_orbital_dependent
733
734 push_sub(lcao_run)
735
736 if (present(st_start)) then
737 ! If we are doing unocc calculation, do not mess with the correct eigenvalues
738 ! of the occupied states.
739 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
740 calc_eigenval=.not. present(st_start), calc_current=.false.)
741
742 assert(st_start >= 1)
743 if (st_start > st%nst) then ! nothing to be done in LCAO
744 pop_sub(lcao_run)
745 return
746 end if
747 end if
748
749 call profiling_in('LCAO_RUN')
750
751 call lcao_init(lcao, namespace, space, gr, ions, st, optional_default(st_start, 1))
752
753 call lcao_init_orbitals(lcao, namespace, st, gr, ions, start = st_start)
754
755 ! By default, we want to use vxc for the LCAO.
756 ! However, we can only do this if vxc depends on the density only
757 ! For cases like MGGA or hybrids, OEP, we cannot do this
758 is_orbital_dependent = (ks%theory_level == hartree .or. ks%theory_level == hartree_fock &
759 .or. (ks%theory_level == kohn_sham_dft .and. xc_is_orbital_dependent(ks%xc)) &
760 .or. (ks%theory_level == generalized_kohn_sham_dft .and. xc_is_orbital_dependent(ks%xc)) &
761 .or. ks%sic%level == sic_pz_oep)
762
763 if (.not. present(st_start)) then
764 call lcao_guess_density(lcao, namespace, st, gr, hm, ions, st%qtot, st%d%ispin, st%rho)
765
766 if (st%d%ispin > unpolarized) then
767 assert(present(lmm_r))
768 call write_magnetic_moments(gr, st, ions, gr%der%boundaries, lmm_r, namespace=namespace)
769 end if
770
771 ! set up Hamiltonian (we do not call v_ks_h_setup here because we do not want to
772 ! overwrite the guess density)
773 message(1) = 'Info: Setting up Hamiltonian.'
774 call messages_info(1, namespace=namespace)
775
776 ! get the effective potential (we don`t need the eigenvalues yet)
777 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval=.false., &
778 calc_current=.false., calc_energy=.false., force_semilocal=is_orbital_dependent)
779 ! eigenvalues have nevertheless to be initialized to something
780 ! This value must be larger that the highest eigenvalue from LCAO to get the correct occupations
781 st%eigenval = 1e10_real64
782 end if
783
784 lcao_done = .false.
785
786 ! after initialized, can check that LCAO is possible
787 if (lcao_is_available(lcao)) then
788 lcao_done = .true.
789
790 if (present(st_start)) then
791 write(message(1),'(a,i8,a)') 'Performing LCAO for states ', st_start, ' and above'
792 call messages_info(1, namespace=namespace)
793 end if
794
795 call lcao_wf(lcao, st, gr, ions, hm, namespace, start = st_start)
796
797 ! In some rare cases, like bad pseudopotentials with unbound orbitals,
798 ! we might not have enough orbitals to go up to the Fermi energy
799 ! In this case, we cannot set the eigenvales to a huge value, as
800 ! the smearing will not converge. We set them to zero then
801 select case (st%d%ispin)
802 case (unpolarized)
803 required_min_nst = int(st%qtot/2)
804 case (spin_polarized)
805 required_min_nst = int(st%qtot/2)
806 case (spinors)
807 required_min_nst = int(st%qtot)
808 end select
809 if (st%smear%method /= smear_fixed_occ .and. st%smear%method /= smear_semiconductor) then
810 if (lcao%norbs <= required_min_nst .and. lcao%norbs < st%nst) then
811 st%eigenval(lcao%norbs+1:,:) = m_zero
812 end if
813 end if
814
815 if (.not. present(st_start)) then
816 call states_elec_fermi(st, namespace, gr)
817 call states_elec_write_eigenvalues(min(st%nst, lcao%norbs), st, space, hm%kpoints, namespace=namespace)
818
819 ! Update the density and the Hamiltonian
820 if (lcao%mode == option__lcaostart__lcao_full) then
821 call v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, &
822 calc_eigenval = .false., calc_current=.false.)
823 if (st%d%ispin > unpolarized) then
824 assert(present(lmm_r))
825 call write_magnetic_moments(gr, st, ions, gr%der%boundaries, lmm_r, namespace=namespace)
826 end if
827 end if
828 end if
829 end if
830
831 if (.not. lcao_done .or. lcao%norbs < st%nst) then
832
833 if (lcao_done) then
834 st_start_random = lcao%norbs + 1
835 else
836 st_start_random = 1
837 end if
838 if (present(st_start)) st_start_random = max(st_start, st_start_random)
839
840 if (st_start_random > 1) then
841 write(message(1),'(a,i8,a)') 'Generating random wavefunctions for states ', st_start_random, ' and above'
842 call messages_info(1, namespace=namespace)
843 end if
844
845 ! Randomly generate the initial wavefunctions.
846 call states_elec_generate_random(st, gr, hm%kpoints, ist_start_ = st_start_random, normalized = .false.)
847
848 ! For spinors, we rotate the random states in the local frame of the magnetization
849 ! Unless the user specified the spin directions using InitialSpins
850 if (.not. st%fixed_spins) then
851 call rotate_random_states_to_local_frame(st, gr, hm%ep%reltype, st_start_random, lcao%gmd_opt)
852 end if
853
854 call messages_write('Orthogonalizing wavefunctions.')
855 call messages_info(namespace=namespace)
856 call states_elec_orthogonalize(st, namespace, gr)
857
858 if (.not. lcao_done) then
859 ! If we are doing unocc calculation, do not mess with the correct eigenvalues and occupations
860 ! of the occupied states.
861 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
862 calc_eigenval=.not. present(st_start), calc_current=.false., force_semilocal=is_orbital_dependent) ! get potentials
863 if (.not. present(st_start)) then
864 call states_elec_fermi(st, namespace, gr) ! occupations
865 end if
866
867 end if
868
869 else if (present(st_start)) then
870
871 if (st_start > 1) then
872 call messages_write('Orthogonalizing wavefunctions.')
873 call messages_info(namespace=namespace)
874 call states_elec_orthogonalize(st, namespace, gr)
875 end if
876
877 end if
878
879 call lcao_end(lcao)
880
881
882 call profiling_out('LCAO_RUN')
883 pop_sub(lcao_run)
884 end subroutine lcao_run
885
886 ! ---------------------------------------------------------
887 subroutine lcao_end(this)
888 type(lcao_t), intent(inout) :: this
889
890 push_sub(lcao_end)
891
892 safe_deallocate_a(this%calc_atom)
893 safe_deallocate_a(this%norb_atom)
894 safe_deallocate_a(this%basis_atom)
895 safe_deallocate_a(this%basis_orb)
896 safe_deallocate_a(this%atom_orb_basis)
897 safe_deallocate_a(this%radius)
898 safe_deallocate_a(this%sphere)
899 safe_deallocate_a(this%orbitals)
900
901 safe_deallocate_a(this%atom)
902 safe_deallocate_a(this%level)
903 safe_deallocate_a(this%ddim)
904 safe_deallocate_a(this%cst)
905 safe_deallocate_a(this%ck)
906 safe_deallocate_a(this%dbuff_single)
907 safe_deallocate_a(this%zbuff_single)
908 safe_deallocate_a(this%dbuff)
909 safe_deallocate_a(this%zbuff)
910
911 this%initialized = .false.
912 pop_sub(lcao_end)
913 end subroutine lcao_end
914
915
916 ! ---------------------------------------------------------
917 subroutine lcao_wf(this, st, gr, ions, hm, namespace, start)
918 type(lcao_t), intent(inout) :: this
919 type(states_elec_t), intent(inout) :: st
920 type(grid_t), intent(in) :: gr
921 type(ions_t), intent(in) :: ions
922 type(hamiltonian_elec_t), intent(in) :: hm
923 type(namespace_t), intent(in) :: namespace
924 integer, optional, intent(in) :: start
925
926 integer :: start_
927
928 assert(this%initialized)
929
930 call profiling_in("LCAO")
931 push_sub(lcao_wf)
932
933 start_ = 1
934 if (present(start)) start_ = start
935
936 if (this%alternative) then
937 if (states_are_real(st)) then
938 call dlcao_alt_wf(this, st, gr, ions, hm, namespace, start_)
939 else
940 call zlcao_alt_wf(this, st, gr, ions, hm, namespace, start_)
941 end if
942 else
943 if (states_are_real(st)) then
944 call dlcao_wf(this, st, gr, ions, hm, namespace, start_)
945 else
946 call zlcao_wf(this, st, gr, ions, hm, namespace, start_)
947 end if
948 end if
949 pop_sub(lcao_wf)
950 call profiling_out("LCAO")
951 end subroutine lcao_wf
952
953
954 ! ---------------------------------------------------------
956 logical function lcao_is_available(this) result(available)
957 type(lcao_t), intent(in) :: this
958
959 push_sub(lcao_is_available)
960
961 available = this%initialized .and. this%mode /= option__lcaostart__lcao_none &
962 .and. this%norbs > 0
964 pop_sub(lcao_is_available)
965 end function lcao_is_available
966
967
968 ! ---------------------------------------------------------
970 integer function lcao_num_orbitals(this) result(norbs)
971 type(lcao_t), intent(in) :: this
972
973 push_sub(lcao_num_orbitals)
974 norbs = this%norbs
975
976 pop_sub(lcao_num_orbitals)
977 end function lcao_num_orbitals
978
979 ! ---------------------------------------------------------
980
981 subroutine lcao_local_index(this, ig, jg, il, jl, prow, pcol)
982 type(lcao_t), intent(in) :: this
983 integer, intent(in) :: ig
984 integer, intent(in) :: jg
985 integer, intent(out) :: il
986 integer, intent(out) :: jl
987 integer, intent(out) :: prow
988 integer, intent(out) :: pcol
989
990 ! no PUSH_SUB, called too often
991#ifdef HAVE_SCALAPACK
992 call infog2l(ig, jg, this%desc(1), this%nproc(1), this%nproc(2), this%myroc(1), this%myroc(2), &
993 il, jl, prow, pcol)
994#else
995 il = ig
996 jl = jg
997 prow = 0
998 pcol = 0
999#endif
1000
1001 end subroutine lcao_local_index
1003 ! ---------------------------------------------------------
1004
1008 subroutine lcao_alt_end_orbital(this, iatom)
1009 type(lcao_t), intent(inout) :: this
1010 integer, intent(in) :: iatom
1011
1012 push_sub(lcao_alt_end_orbital)
1013
1014 if (this%is_orbital_initialized(iatom)) then
1015 call this%orbitals(iatom)%end()
1016 this%is_orbital_initialized(iatom) = .false.
1017 end if
1018
1019 pop_sub(lcao_alt_end_orbital)
1020
1021 end subroutine lcao_alt_end_orbital
1022
1023 ! ---------------------------------------------------------
1024
1025 subroutine lcao_atom_density(this, st, mesh, ions, iatom, spin_channels, rho)
1026 type(lcao_t), intent(inout) :: this
1027 type(states_elec_t), intent(in) :: st
1028 class(mesh_t), intent(in) :: mesh
1029 type(ions_t), target, intent(in) :: ions
1030 integer, intent(in) :: iatom
1031 integer, intent(in) :: spin_channels
1032 real(real64), intent(inout) :: rho(:, :)
1033
1034 real(real64), allocatable :: dorbital(:, :)
1035 complex(real64), allocatable :: zorbital(:, :)
1036 real(real64), allocatable :: factors(:)
1037 real(real64) :: factor, aa
1038 integer :: iorb, ip, ii, ll, mm, ispin
1039 type(ps_t), pointer :: ps
1040 logical :: use_stored_orbitals
1041
1042 push_sub(lcao_atom_density)
1043
1044 rho = m_zero
1045
1046 use_stored_orbitals = ions%atom(iatom)%species%is_ps() &
1047 .and. states_are_real(st) .and. spin_channels == 1 .and. lcao_is_available(this) &
1048 .and. st%d%dim == 1 .and. .not. ions%space%is_periodic()
1049
1050
1051 ! we can use the orbitals we already have calculated
1052 if (use_stored_orbitals) then
1053 !There is no periodic copies here, so this will not work for periodic systems
1054 assert(.not. ions%space%is_periodic())
1055
1056 select type(spec=>ions%atom(iatom)%species)
1057 class is(pseudopotential_t)
1058 ps => spec%ps
1059 class default
1060 assert(.false.)
1061 end select
1062
1063 if (.not. this%alternative) then
1064
1065 if (states_are_real(st)) then
1066 safe_allocate(dorbital(1:mesh%np, 1:st%d%dim))
1067 else
1068 safe_allocate(zorbital(1:mesh%np, 1:st%d%dim))
1069 end if
1070
1071 do iorb = 1, this%norbs
1072 if (iatom /= this%atom(iorb)) cycle
1073
1074 call ions%atom(iatom)%species%get_iwf_ilm(this%level(iorb), 1, ii, ll, mm)
1075 factor = ps%conf%occ(ii, 1)/(m_two*ll + m_one)
1076
1077 if (states_are_real(st)) then
1078 call dget_ao(this, st, mesh, ions, iorb, 1, dorbital, use_psi = .true.)
1079 !$omp parallel do
1080 do ip = 1, mesh%np
1081 rho(ip, 1) = rho(ip, 1) + factor*dorbital(ip, 1)**2
1082 end do
1083 else
1084 call zget_ao(this, st, mesh, ions, iorb, 1, zorbital, use_psi = .true.)
1085 !$omp parallel do
1086 do ip = 1, mesh%np
1087 rho(ip, 1) = rho(ip, 1) + factor*abs(zorbital(ip, 1))**2
1088 end do
1089 end if
1090
1091 end do
1092
1093 safe_deallocate_a(dorbital)
1094 safe_deallocate_a(zorbital)
1095
1096 else
1097
1098 ! for simplicity, always use real ones here.
1099 call dlcao_alt_get_orbital(this, this%sphere(iatom), ions, 1, iatom, this%norb_atom(iatom))
1100
1101 ! the extra orbitals with the derivative are not relevant here, hence we divide by this%mult
1102 safe_allocate(factors(1:this%norb_atom(iatom)/this%mult))
1103
1104 do iorb = 1, this%norb_atom(iatom)/this%mult
1105 call ions%atom(iatom)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
1106 factors(iorb) = ps%conf%occ(ii, 1)/(m_two*ll + m_one)
1107 end do
1108
1109 !$omp parallel do private(ip, aa, iorb) if(.not. this%sphere(iatom)%overlap)
1110 do ip = 1, this%sphere(iatom)%np
1111 aa = m_zero
1112 do iorb = 1, this%norb_atom(iatom)/this%mult
1113 aa = aa + factors(iorb)*this%orbitals(iatom)%dff_linear(ip, iorb)**2
1114 end do
1115 rho(this%sphere(iatom)%map(ip), 1) = rho(this%sphere(iatom)%map(ip), 1) + aa
1116 end do
1117
1118 safe_deallocate_a(factors)
1119
1120 end if
1121
1122 else
1123 call species_atom_density(ions%atom(iatom)%species, ions%namespace, ions%space, ions%latt, &
1124 ions%pos(:, iatom), mesh, spin_channels, rho)
1125 end if
1126
1127 ! The above code can sometimes return negative values of the density. Here we avoid introducing
1128 ! them in the calculation of v_s, mixing, ...
1129 do ispin = 1, spin_channels
1130 !$omp parallel do simd
1131 do ip = 1, mesh%np
1132 rho(ip, ispin) = max(rho(ip, ispin), m_zero)
1133 end do
1134 end do
1135
1136 pop_sub(lcao_atom_density)
1137 end subroutine lcao_atom_density
1138
1139 ! ---------------------------------------------------------
1141 subroutine lcao_guess_density(this, namespace, st, gr, hm, ions, qtot, ispin, rho)
1142 type(lcao_t), intent(inout) :: this
1143 type(namespace_t), intent(in) :: namespace
1144 type(states_elec_t), intent(in) :: st
1145 type(grid_t), intent(in) :: gr
1146 type(hamiltonian_elec_t), intent(in) :: hm
1147 type(ions_t), intent(in) :: ions
1148 real(real64), intent(in) :: qtot
1149 integer, intent(in) :: ispin
1150 real(real64), contiguous, intent(out) :: rho(:, :)
1151
1152 integer :: ia, is, idir, ip, m_dim
1153 integer(int64), save :: iseed = splitmix64_321
1154 type(block_t) :: blk
1155 real(real64) :: rr, rnd, phi, theta, lmag, n1, n2
1156 real(real64), allocatable :: atom_rho(:,:), mag(:,:)
1157 real(real64), parameter :: tol_min_mag = 1.0e-20_real64
1158
1159 push_sub(lcao_guess_density)
1160
1161 if (st%d%spin_channels == 1) then
1162 this%gmd_opt = initrho_paramagnetic
1163 else
1164 !%Variable GuessMagnetDensity
1165 !%Type integer
1166 !%Default ferromagnetic
1167 !%Section SCF::LCAO
1168 !%Description
1169 !% The guess density for the SCF cycle is just the sum of all the atomic densities.
1170 !% When performing spin-polarized or non-collinear-spin calculations this option sets
1171 !% the guess magnetization density.
1172 !%
1173 !% For anti-ferromagnetic configurations, the <tt>user_defined</tt> option should be used.
1174 !%
1175 !% Note that if the <tt>paramagnetic</tt> option is used, the final ground state will also be
1176 !% paramagnetic, but the same is not true for the other options.
1177 !%Option paramagnetic 1
1178 !% Magnetization density is zero.
1179 !%Option ferromagnetic 2
1180 !% Magnetization density is the sum of the atomic magnetization densities.
1181 !%Option random 3
1182 !% Each atomic magnetization density is randomly rotated.
1183 !%Option user_defined 77
1184 !% The atomic magnetization densities are rotated so that the magnetization
1185 !% vector has the same direction as a vector provided by the user. In this case,
1186 !% the <tt>AtomsMagnetDirection</tt> block has to be set.
1187 !%End
1188 call parse_variable(namespace, 'GuessMagnetDensity', initrho_ferromagnetic, this%gmd_opt)
1189 if (.not. varinfo_valid_option('GuessMagnetDensity', this%gmd_opt)) call messages_input_error(namespace, 'GuessMagnetDensity')
1190 call messages_print_var_option('GuessMagnetDensity', this%gmd_opt, namespace=namespace)
1191 end if
1192
1193 if (parse_is_defined(namespace, 'GuessMagnetDensity') .and. (hm%theory_level == hartree_fock &
1194 .or. hm%theory_level == generalized_kohn_sham_dft)) then
1195 message(1) = "GuessMagnetDensity cannot be used for Hartree-Fock and generalized Kohn-Sham calculation."
1196 message(2) = "Please perform a LDA or GGA calculation first and restart from this calculation."
1197 call messages_fatal(2, namespace=namespace)
1198 end if
1199
1200 if (this%gmd_opt == initrho_userdef) then
1201 !%Variable AtomsMagnetDirection
1202 !%Type block
1203 !%Section SCF::LCAO
1204 !%Description
1205 !% This option is only used when <tt>GuessMagnetDensity</tt> is
1206 !% set to <tt>user_defined</tt>. It provides a direction for the
1207 !% magnetization vector of each atom when building the guess
1208 !% density. In order to do that, the user should specify the
1209 !% coordinates of a vector that has the desired direction and
1210 !% norm. Note that it is necessary to maintain the ordering in
1211 !% which the species were defined in the coordinates
1212 !% specifications.
1213 !%
1214 !% For spin-polarized calculations, the vectors should have only
1215 !% one component; for non-collinear-spin calculations, they
1216 !% should have three components. If the norm of the vector is greater
1217 !% than the number of valence electrons in the atom, it will be rescaled
1218 !% to this number, which is the maximum possible magnetization.
1219 !%End
1220 if (parse_block(namespace, 'AtomsMagnetDirection', blk) < 0) then
1221 message(1) = "AtomsMagnetDirection block is not defined."
1222 call messages_fatal(1, namespace=namespace)
1223 end if
1224
1225 if (parse_block_n(blk) /= ions%natoms) then
1226 message(1) = "The number of rows in the AtomsMagnetDirection block does not equal the number of atoms."
1227 call messages_fatal(1, namespace=namespace)
1228 end if
1229
1230 if (ispin == spin_polarized) then
1231 m_dim = 1
1232 elseif(ispin == spinors) then
1233 m_dim = 3
1234 endif
1235
1236 safe_allocate(mag(1:m_dim, 1:ions%natoms))
1237 do ia = 1, ions%natoms
1238 !Read from AtomsMagnetDirection block
1239 do idir = 1, m_dim
1240 call parse_block_float(blk, ia-1, idir-1, mag(idir, ia))
1241 if (abs(mag(idir, ia)) < tol_min_mag) mag(idir, ia) = m_zero
1242 end do
1243 end do
1244 call parse_block_end(blk)
1245 end if
1246
1247 rho = m_zero
1248
1249 safe_allocate(atom_rho(1:gr%np, 1:st%d%spin_channels))
1250 select case (this%gmd_opt)
1251 case (initrho_paramagnetic)
1252 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1253 call lcao_atom_density(this, st, gr, ions, ia, st%d%spin_channels, atom_rho)
1254 call lalg_axpy(gr%np, st%d%spin_channels, m_one, atom_rho, rho)
1255 end do
1256
1257 if (st%d%spin_channels == 2) then
1258 !$omp parallel do
1259 do ip = 1, gr%np
1260 rho(ip, 1) = m_half*(rho(ip, 1) + rho(ip, 2))
1261 rho(ip, 2) = rho(ip, 1)
1262 end do
1263 end if
1264
1266 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1267 call lcao_atom_density(this, st, gr, ions, ia, 2, atom_rho(1:gr%np, 1:2))
1268 rho(1:gr%np, 1:2) = rho(1:gr%np, 1:2) + atom_rho(1:gr%np, 1:2)
1269 end do
1270
1271 case (initrho_random) ! Randomly oriented spins
1272 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1273 call lcao_atom_density(this, st, gr, ions, ia, 2, atom_rho)
1274
1275 ! For charge neutral atoms, the magnetization density will always be zero
1276 ! In order to still make a random spin structure, we then reassign the charge in
1277 ! one spin channel to have a 1 \nu_B for this atom, with a random direction
1278 !
1279 ! An example where this is needed is a Xe3 cluster where we put an excess charge
1280 ! Each atom is neutral but the full system has a net magnetiation
1281 n1 = dmf_integrate(gr, atom_rho(:, 1))
1282 n2 = dmf_integrate(gr, atom_rho(:, 2))
1283
1284 if (is_close(n1, n2)) then
1285 lmag = m_one
1286
1287 call lalg_axpy(gr%np, (lmag - n1 + n2)/m_two/n2, atom_rho(:, 2), atom_rho(:, 1))
1288 call lalg_scal(gr%np, (n1 + n2 - lmag)/m_two/n2, atom_rho(:, 2))
1289 end if
1290
1291
1292 if (ispin == spin_polarized) then
1293 call quickrnd(iseed, rnd)
1294 rnd = rnd - m_half
1295 if (rnd > m_zero) then
1296 rho(1:gr%np, 1:2) = rho(1:gr%np, 1:2) + atom_rho(1:gr%np, 1:2)
1297 else
1298 rho(1:gr%np, 1) = rho(1:gr%np, 1) + atom_rho(1:gr%np, 2)
1299 rho(1:gr%np, 2) = rho(1:gr%np, 2) + atom_rho(1:gr%np, 1)
1300 end if
1301 elseif (ispin == spinors) then
1302 call quickrnd(iseed, phi)
1303 call quickrnd(iseed, theta)
1304 phi = phi*m_two*m_pi
1305 theta = theta*m_pi*m_half
1306
1307 call accumulate_rotated_density(gr, rho, atom_rho, theta, phi)
1308 end if
1309 end do
1310
1311 case (initrho_userdef) ! User-defined
1312 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1313 !Get atomic density
1314 call lcao_atom_density(this, st, gr, ions, ia, 2, atom_rho)
1315
1316 !Scale magnetization density
1317 n1 = dmf_integrate(gr, atom_rho(:, 1))
1318 n2 = dmf_integrate(gr, atom_rho(:, 2))
1319
1320 lmag = norm2(mag(:, ia))
1321 if (lmag > n1 + n2) then
1322 mag = mag*(n1 + n2)/lmag
1323 lmag = n1 + n2
1324 elseif (abs(lmag) <= m_epsilon) then
1325 if (abs(n1 - n2) <= m_epsilon) then
1326 call lalg_axpy(gr%np, 2, m_one, atom_rho, rho)
1327 else
1328 !$omp parallel do simd
1329 do ip = 1, gr%np
1330 atom_rho(ip, 1) = m_half*(atom_rho(ip, 1) + atom_rho(ip, 2))
1331 rho(ip, 1) = rho(ip, 1) + atom_rho(ip, 1)
1332 rho(ip, 2) = rho(ip, 2) + atom_rho(ip, 1)
1333 end do
1334 end if
1335 cycle
1336 end if
1337
1338 if (.not. is_close(n1 - n2, lmag) .and. abs(n2) > m_epsilon) then
1339 if (n1 - n2 < lmag) then
1340 call lalg_axpy(gr%np, (lmag - n1 + n2)/m_two/n2, atom_rho(:, 2), atom_rho(:, 1))
1341 call lalg_scal(gr%np, (n1 + n2 - lmag)/m_two/n2, atom_rho(:, 2))
1342 elseif (n1 - n2 > lmag) then
1343 call lalg_axpy(gr%np, (n1 - n2 - lmag)/m_two/n1, atom_rho(:, 1), atom_rho(:, 2))
1344 call lalg_scal(gr%np, (n1 + n2 + lmag)/m_two/n1, atom_rho(:, 1))
1345 end if
1346 end if
1347
1348 !Rotate magnetization density
1349 if (ispin == spin_polarized) then
1350
1351 if (mag(1, ia) > m_zero) then
1352 call lalg_axpy(gr%np, 2, m_one, atom_rho, rho)
1353 else
1354 call lalg_axpy(gr%np, m_one, atom_rho(:,2), rho(:,1))
1355 call lalg_axpy(gr%np, m_one, atom_rho(:,1), rho(:,2))
1356 end if
1357
1358 elseif (ispin == spinors) then
1359
1360 call get_angles_from_magnetization(mag(:, ia), lmag, theta, phi)
1361 call accumulate_rotated_density(gr, rho, atom_rho, theta, phi)
1362 end if
1363 end do
1364
1365 end select
1366
1367
1368 if (ions%atoms_dist%parallel) then
1369 do is = 1, st%d%nspin
1370 call lalg_copy(gr%np, rho(:,is), atom_rho(:,1))
1371 call ions%atoms_dist%mpi_grp%allreduce(atom_rho(1, 1), rho(1, is), gr%np, mpi_double_precision, mpi_sum)
1372 end do
1373 end if
1374
1375 ! we now renormalize the density (necessary if we have a charged system)
1376 rr = integrated_charge_density(gr, st, rho)
1377 write(message(1),'(a,f13.6)')'Info: Unnormalized total charge = ', rr
1378 call messages_info(1, namespace=namespace)
1379
1380 ! We only renormalize if the density is not zero
1381 if (abs(rr) > m_epsilon) then
1382 call lalg_scal(gr%np, st%d%nspin, qtot/rr, rho)
1383 rr = integrated_charge_density(gr, st, rho)
1384 write(message(1),'(a,f13.6)')'Info: Renormalized total charge = ', rr
1385 call messages_info(1, namespace=namespace)
1386 end if
1387
1388 ! Symmetrize the density if needed
1389 if (st%symmetrize_density) then
1390 do is = 1, st%d%nspin
1391 call dgrid_symmetrize_scalar_field(gr, rho(:, is))
1392 end do
1393 end if
1394
1395 safe_deallocate_a(atom_rho)
1396 safe_deallocate_a(mag)
1397
1398 pop_sub(lcao_guess_density)
1399 end subroutine lcao_guess_density
1400
1402 real(real64) function integrated_charge_density(gr, st, rho) result(rr)
1403 type(grid_t), intent(in) :: gr
1404 type(states_elec_t), intent(in) :: st
1405 real(real64), intent(in) :: rho(:,:)
1406
1407 integer :: is
1408
1409 rr = m_zero
1410 do is = 1, st%d%spin_channels
1411 rr = rr + dmf_integrate(gr, rho(:, is), reduce = .false.)
1412 end do
1413
1414 call gr%allreduce(rr)
1415 end function integrated_charge_density
1416
1417 ! ---------------------------------------------------------
1418 subroutine accumulate_rotated_density(mesh, rho, atom_rho, theta, phi)
1419 class(mesh_t), intent(in) :: mesh
1420 real(real64), intent(inout) :: rho(:,:)
1421 real(real64), intent(in) :: atom_rho(:,:)
1422 real(real64), intent(in) :: theta, phi
1423
1424 integer :: ip
1425 real(real64) :: half_theta
1426
1428
1429 half_theta = m_half * theta
1430
1431 !$omp parallel do simd
1432 do ip = 1, mesh%np
1433 rho(ip, 1) = rho(ip, 1) + cos(half_theta)**2*atom_rho(ip, 1) + sin(half_theta)**2*atom_rho(ip, 2)
1434 rho(ip, 2) = rho(ip, 2) + sin(half_theta)**2*atom_rho(ip, 1) + cos(half_theta)**2*atom_rho(ip, 2)
1435 rho(ip, 3) = rho(ip, 3) + cos(half_theta)*sin(half_theta)*cos(phi)*(atom_rho(ip, 1)-atom_rho(ip, 2))
1436 rho(ip, 4) = rho(ip, 4) - cos(half_theta)*sin(half_theta)*sin(phi)*(atom_rho(ip, 1)-atom_rho(ip, 2))
1437 end do
1438
1440 end subroutine accumulate_rotated_density
1441
1442 ! ---------------------------------------------------------
1443
1444 subroutine lcao_init_orbitals(this, namespace, st, gr, ions, start)
1445 type(lcao_t), intent(inout) :: this
1446 type(namespace_t), intent(in) :: namespace
1447 type(states_elec_t), intent(inout) :: st
1448 type(grid_t), intent(in) :: gr
1449 type(ions_t), intent(in) :: ions
1450 integer, optional, intent(in) :: start
1451
1452 if (.not. lcao_is_available(this)) return
1453
1454 push_sub(lcao_init_orbitals)
1455
1456 if (.not. this%alternative) then
1457 if (states_are_real(st)) then
1458 call dinit_orbitals(this, namespace, st, gr, ions, start)
1459 else
1460 call zinit_orbitals(this, namespace, st, gr, ions, start)
1461 end if
1462 else
1463 if (states_are_real(st)) then
1464 call dlcao_alt_init_orbitals(this, namespace, st, gr, ions, start)
1465 else
1466 call zlcao_alt_init_orbitals(this, namespace, st, gr, ions, start)
1467 end if
1468
1469 end if
1470
1471 pop_sub(lcao_init_orbitals)
1472 end subroutine lcao_init_orbitals
1473
1475 subroutine get_angles_from_magnetization(mag, lmag, theta, phi)
1476 real(real64), intent(in) :: mag(:)
1477 real(real64), intent(in) :: lmag
1478 real(real64), intent(out) :: theta
1479 real(real64), intent(out) :: phi
1480
1481 real(real64) :: arg
1482
1483 assert(lmag > m_zero)
1484
1485 theta = acos(mag(3)/lmag)
1486
1487 if (abs(mag(1)) <= m_epsilon) then
1488 if (abs(mag(2)) <= m_epsilon) then
1489 phi = m_zero
1490 elseif (mag(2) < m_zero) then
1491 phi = m_pi*m_three*m_half
1492 else
1493 phi = m_pi*m_half
1494 end if
1495 else
1496 ! In some rare cases this can be larger than one
1497 arg = mag(1)/sin(theta)/lmag
1498 if (abs(arg) > m_one) arg = sign(m_one, arg)
1499
1500 phi = acos(arg)
1501 if (mag(2) < m_zero) then
1502 phi = m_two*m_pi - phi
1503 end if
1504 end if
1505
1506 end subroutine get_angles_from_magnetization
1507
1508
1515 subroutine rotate_random_states_to_local_frame(st, gr, rel_type, ist_start, gmd_opt)
1516 type(states_elec_t), intent(inout) :: st
1517 type(grid_t), intent(in) :: gr
1518 integer, intent(in) :: rel_type
1519 integer, intent(in) :: ist_start
1520 integer, intent(in) :: gmd_opt
1522 integer :: ik, ist, ip
1523 real(real64), allocatable :: md(:,:), up(:)
1524 complex(real64), allocatable :: down(:), psi(:,:)
1525 real(real64) :: lmag, theta, phi, norm, mm(3)
1526
1527 if (st%d%ispin /= spinors) return
1528 if (gmd_opt == initrho_random) return
1529
1531
1532 safe_allocate(psi(1:gr%np, 1:st%d%dim))
1533
1534 select case (gmd_opt)
1536 ! Random spinors should have no net magnetization
1537 do ik = st%d%kpt%start, st%d%kpt%end
1538 do ist = ist_start, st%st_end
1539 call states_elec_get_state(st, gr, ist, ik, psi)
1540 !$omp parallel do private(norm)
1541 do ip = 1, gr%np
1542 psi(ip, 1) = psi(ip, 1) + psi(ip, 2)
1543 psi(ip, 2) = psi(ip, 1)
1544 end do
1545 call zmf_normalize(gr, st%d%dim, psi)
1546 call states_elec_set_state(st, gr, ist, ik, psi)
1547 end do
1548 end do
1549
1551 ! Random spinors magnetization is aligned along the z axis
1552 do ik = st%d%kpt%start, st%d%kpt%end
1553 do ist = ist_start, st%st_end
1554 call states_elec_get_state(st, gr, ist, ik, psi)
1555 !$omp parallel do
1556 do ip = 1, gr%np
1557 psi(ip, 1) = psi(ip, 1) + psi(ip, 2)
1558 psi(ip, 2) = m_zero
1559 end do
1560 call zmf_normalize(gr, st%d%dim, psi)
1561 call states_elec_set_state(st, gr, ist, ik, psi)
1562 end do
1563 end do
1564
1565 case(initrho_userdef)
1566 ! Random spinors magnetization is aligned along the local frame
1567 safe_allocate(md(1:gr%np, 1:3))
1568 safe_allocate(up(1:gr%np))
1569 safe_allocate(down(1:gr%np))
1570 call magnetic_density(gr, st%d, st%rho, md)
1571
1572 mm(1) = dmf_integrate(gr, md(:, 1), reduce = .false.)
1573 mm(2) = dmf_integrate(gr, md(:, 2), reduce = .false.)
1574 mm(3) = dmf_integrate(gr, md(:, 3), reduce = .false.)
1575
1576 if (gr%parallel_in_domains) then
1577 call gr%allreduce(mm)
1578 end if
1579
1580 ! If the density has a net direction, we align globally the spinors to this direction
1581 ! This allows to generate random pure states
1582 lmag = norm2(mm)
1583 if (lmag > 1.0e-2_real64) then
1584 call get_angles_from_magnetization(mm, lmag, theta, phi)
1585 up(:) = cos(theta/m_two)
1586 down(:) = exp(-m_zi * phi) * sin(theta/m_two)
1587 else
1588 ! We do a rotation in the local frame
1589 ! Note that this produces mixed states, so the norm of the magnetization is smaller than 1
1590 !
1591 !$omp parallel do private(lmag, theta, phi)
1592 do ip = 1, gr%np
1593 lmag = norm2(md(ip, 1:3))
1594 call get_angles_from_magnetization(md(ip,:), lmag, theta, phi)
1595 up(ip) = cos(theta/m_two)
1596 down(ip) = exp(-m_zi * phi) * sin(theta/m_two)
1597 end do
1598 safe_deallocate_a(md)
1599 end if
1600
1601 ! Rotate the spinors
1602 do ik = st%d%kpt%start, st%d%kpt%end
1603 do ist = ist_start, st%st_end
1604 call states_elec_get_state(st, gr, ist, ik, psi)
1605 call zmf_normalize(gr, st%d%dim, psi)
1606 !$omp parallel do private(norm)
1607 do ip = 1, gr%np
1608 norm = sqrt(real(psi(ip, 1)*conjg(psi(ip, 1)) + psi(ip, 2)*conjg(psi(ip, 2))))
1609 psi(ip, 1) = norm * up(ip)
1610 psi(ip, 2) = norm * down(ip)
1611 end do
1612 call states_elec_set_state(st, gr, ist, ik, psi)
1613 end do
1614 end do
1615 safe_deallocate_a(up)
1616 safe_deallocate_a(down)
1617
1618 end select
1619 safe_deallocate_a(psi)
1620
1623
1624#include "undef.F90"
1625#include "real.F90"
1626#include "lcao_inc.F90"
1627
1628#include "undef.F90"
1629#include "complex.F90"
1630#include "lcao_inc.F90"
1631
1632
1633end module lcao_oct_m
1634
1635!! Local Variables:
1636!! mode: f90
1637!! coding: utf-8
1638!! End:
subroutine info()
Definition: em_resp.F90:1096
constant times a vector plus a vector
Definition: lalg_basic.F90:171
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:186
scales a vector by a constant
Definition: lalg_basic.F90:157
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:180
double acos(double __x) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
double sin(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
double cos(double __x) __attribute__((__nothrow__
subroutine lcao2_init()
Definition: lcao.F90:602
This module implements batches of mesh functions.
Definition: batch.F90:133
This module contains interfaces for BLACS routines Interfaces are from http:
Definition: blacs.F90:27
This module provides the BLACS processor grid.
logical pure function, public blacs_proc_grid_null(this)
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:122
type(debug_t), save, public debug
Definition: debug.F90:156
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
integer, parameter, public spin_polarized
real(real64), parameter, public m_two
Definition: global.F90:190
real(real64), parameter, public m_zero
Definition: global.F90:188
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:186
real(real64), parameter, public m_epsilon
Definition: global.F90:204
real(real64), parameter, public m_half
Definition: global.F90:194
real(real64), parameter, public m_one
Definition: global.F90:189
This module implements the underlying real-space grid.
Definition: grid.F90:117
subroutine, public dgrid_symmetrize_scalar_field(gr, field, suppress_warning)
Definition: grid.F90:669
This module defines classes and functions for interaction partners.
Definition: io.F90:114
subroutine, public io_close(iunit, grp)
Definition: io.F90:418
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:311
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:352
A module to handle KS potential, without the external potential.
integer, parameter, public hartree
integer, parameter, public hartree_fock
integer, parameter, public generalized_kohn_sham_dft
integer, parameter, public kohn_sham_dft
This module contains interfaces for LAPACK routines.
Definition: lapack.F90:118
subroutine, public lcao_init_orbitals(this, namespace, st, gr, ions, start)
Definition: lcao.F90:1491
subroutine, public lcao_wf(this, st, gr, ions, hm, namespace, start)
Definition: lcao.F90:964
subroutine zlcao_alt_init_orbitals(this, namespace, st, gr, ions, start)
Definition: lcao.F90:3332
subroutine zget_ao(this, st, mesh, ions, iorb, ispin, ao, use_psi)
Definition: lcao.F90:3300
subroutine, public lcao_end(this)
Definition: lcao.F90:934
subroutine, public lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r)
Definition: lcao.F90:764
subroutine zlcao_alt_wf(this, st, gr, ions, hm, namespace, start)
The alternative implementation.
Definition: lcao.F90:3385
subroutine dlcao_wf(this, st, gr, ions, hm, namespace, start)
Definition: lcao.F90:1811
subroutine dlcao_alt_init_orbitals(this, namespace, st, gr, ions, start)
Definition: lcao.F90:2212
subroutine zlcao_wf(this, st, gr, ions, hm, namespace, start)
Definition: lcao.F90:2923
subroutine dlcao_alt_wf(this, st, gr, ions, hm, namespace, start)
The alternative implementation.
Definition: lcao.F90:2265
integer, parameter initrho_userdef
Definition: lcao.F90:236
subroutine get_angles_from_magnetization(mag, lmag, theta, phi)
Given a magnetization vector, and its norm, this returns the corresponding inclination and azimuthal ...
Definition: lcao.F90:1522
integer, parameter initrho_random
Definition: lcao.F90:236
subroutine rotate_random_states_to_local_frame(st, gr, rel_type, ist_start, gmd_opt)
Rotate the spinors with band index >= ist_start to the local frame of the magnetization.
Definition: lcao.F90:1562
subroutine lcao_alt_end_orbital(this, iatom)
This function deallocates a set of an atomic orbitals for an atom. It can be called when the batch is...
Definition: lcao.F90:1055
subroutine lcao_local_index(this, ig, jg, il, jl, prow, pcol)
Definition: lcao.F90:1028
integer function, public lcao_num_orbitals(this)
Returns the number of LCAO orbitas.
Definition: lcao.F90:1017
subroutine lcao_guess_density(this, namespace, st, gr, hm, ions, qtot, ispin, rho)
builds a density which is the sum of the atomic densities
Definition: lcao.F90:1188
subroutine dinit_orbitals(this, namespace, st, gr, ions, start)
Definition: lcao.F90:2071
real(real64) function integrated_charge_density(gr, st, rho)
Computes the integral of rho, summed over spin channels.
Definition: lcao.F90:1449
integer, parameter initrho_paramagnetic
Definition: lcao.F90:236
subroutine dget_ao(this, st, mesh, ions, iorb, ispin, ao, use_psi)
Definition: lcao.F90:2180
subroutine dlcao_alt_get_orbital(this, sphere, ions, ispin, iatom, norbs)
This function generates the set of an atomic orbitals for an atom and stores it in the batch orbitalb...
Definition: lcao.F90:2727
subroutine zinit_orbitals(this, namespace, st, gr, ions, start)
Definition: lcao.F90:3191
subroutine lcao_atom_density(this, st, mesh, ions, iatom, spin_channels, rho)
Definition: lcao.F90:1072
subroutine, public lcao_init(this, namespace, space, gr, ions, st, st_start)
Definition: lcao.F90:246
subroutine accumulate_rotated_density(mesh, rho, atom_rho, theta, phi)
Definition: lcao.F90:1465
integer, parameter initrho_ferromagnetic
Definition: lcao.F90:236
logical function, public lcao_is_available(this)
Returns true if LCAO can be done.
Definition: lcao.F90:1003
subroutine, public write_magnetic_moments(mesh, st, ions, boundaries, lmm_r, iunit, namespace)
Definition: magnetic.F90:205
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:115
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:530
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1028
subroutine, public messages_new_line()
Definition: messages.F90:1117
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:414
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:696
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1068
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:599
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
Definition: mpi.F90:370
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:270
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:502
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:618
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:623
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:552
Definition: ps.F90:114
integer(int64), parameter, public splitmix64_321
Definition: quickrnd.F90:135
This module contains interfaces for ScaLAPACK routines Interfaces are from http:
Definition: scalapack.F90:131
integer, parameter, public smear_semiconductor
Definition: smear.F90:171
integer, parameter, public smear_fixed_occ
Definition: smear.F90:171
subroutine, public species_atom_density(species, namespace, space, latt, pos, mesh, spin_channels, rho)
pure logical function, public states_are_complex(st)
pure logical function, public states_are_real(st)
subroutine, public states_elec_orthogonalize(st, namespace, mesh)
Orthonormalizes nst orbitals in mesh (honours state parallelization).
This module defines routines to write information about states.
subroutine, public states_elec_write_eigenvalues(nst, st, space, kpoints, error, st_start, compact, iunit, namespace)
write the eigenvalues for some states to a file.
subroutine, public states_elec_fermi(st, namespace, mesh, compute_spin)
calculate the Fermi level for the states in this object
subroutine, public states_elec_generate_random(st, mesh, kpoints, ist_start_, ist_end_, ikpt_start_, ikpt_end_, normalized)
randomize states
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:132
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
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
Definition: v_ks.F90:738
subroutine, public v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
Definition: v_ks.F90:684
Definition: xc.F90:114
logical pure function, public xc_is_orbital_dependent(xcs)
Is the xc family orbital dependent.
Definition: xc.F90:533
integer, parameter, public sic_pz_oep
Perdew-Zunger SIC (OEP way)
Definition: xc_sic.F90:148
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:169
Describes mesh distribution to nodes.
Definition: mesh.F90:186
A type storing the information and data about a pseudopotential.
Definition: ps.F90:184
The states_elec_t class contains all electronic wave functions.
int true(void)