39 use,
intrinsic :: iso_fortran_env
87 integer,
parameter :: &
88 INITRHO_PARAMAGNETIC = 1, &
96 logical :: complex_ylms
97 logical :: initialized
100 integer,
allocatable :: atom(:)
101 integer,
allocatable :: level(:)
102 integer,
allocatable :: ddim(:)
103 logical :: alternative
104 logical :: derivative
105 integer,
allocatable :: cst(:, :)
106 integer,
allocatable :: ck(:, :)
107 real(4),
allocatable :: dbuff_single(:, :, :, :)
108 complex(4),
allocatable :: zbuff_single(:, :, :, :)
109 real(real64),
allocatable :: dbuff(:, :, :, :)
110 complex(real64),
allocatable :: zbuff(:, :, :, :)
111 logical :: save_memory
112 logical :: initialized_orbitals
113 real(real64) :: orbital_scale_factor
116 logical,
allocatable :: is_empty(:)
122 real(real64),
allocatable :: radius(:)
123 real(real64) :: lapdist
127 integer,
allocatable :: basis_atom(:)
128 integer,
allocatable :: basis_orb(:)
129 integer,
allocatable :: atom_orb_basis(:, :)
130 integer,
allocatable :: norb_atom(:)
132 integer :: lsize(1:2)
133 integer :: nproc(1:2)
134 integer :: myroc(1:2)
135 integer :: desc(1:BLACS_DLEN)
136 logical,
allocatable :: calc_atom(:)
137 real(real64) :: diag_tol
138 type(submesh_t),
allocatable :: sphere(:)
139 type(batch_t),
allocatable :: orbitals(:)
140 logical,
allocatable :: is_orbital_initialized(:)
147 real(real64),
parameter,
public :: default_eigenval = 1.0e10_real64
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
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
169 this%initialized = .
true.
174 mode_default = option__lcaostart__lcao_states
175 if (ions%only_user_def) mode_default = option__lcaostart__lcao_none
232 if (this%mode == option__lcaostart__lcao_states_batch .and. st_start > 1)
then
233 message(1) =
"LCAOStart = lcao_states_batch not compatible with this run."
234 message(2) =
"Please use LCAOStart = lcao_states instead"
239 this%alternative = this%mode == option__lcaostart__lcao_states_batch
241 if (this%mode == option__lcaostart__lcao_none)
then
251 if (st%d%ispin ==
spinors .and. this%alternative)
then
252 message(1) =
"LCAOStart = lcao_states_batch is not working for spinors."
255 if (space%is_periodic() .and. this%alternative)
then
273 call parse_variable(namespace,
'LCAOComplexYlms', .false., this%complex_ylms)
275 this%complex_ylms = .false.
286 call parse_variable(namespace,
'LCAOSaveMemory', .false., this%save_memory)
289 if (
debug%info .and. st%system_grp%is_root())
then
290 call io_mkdir(
'debug/lcao', namespace)
291 iunit_o =
io_open(
'debug/lcao/orbitals', namespace, action=
'write')
292 write(iunit_o,
'(7a6)')
'iorb',
'atom',
'level',
'i',
'l',
'm',
'spin'
295 if (.not. this%alternative)
then
316 call parse_variable(namespace,
'LCAOMaximumOrbitalRadius', 20.0_real64, max_orb_radius, unit =
units_inp%length)
322 do ia = 1, ions%natoms
323 maxj = max(maxj, ions%atom(ia)%species%get_niwfs())
324 this%maxorbs = this%maxorbs + ions%atom(ia)%species%get_niwfs()
327 this%maxorbs = this%maxorbs*st%d%dim
329 if (this%maxorbs == 0)
then
330 call messages_write(
'The are no atomic orbitals available, cannot do LCAO.')
332 this%mode = option__lcaostart__lcao_none
339 safe_allocate( this%atom(1:this%maxorbs))
340 safe_allocate(this%level(1:this%maxorbs))
341 safe_allocate( this%ddim(1:this%maxorbs))
343 safe_allocate(this%is_empty(1:this%maxorbs))
344 this%is_empty = .false.
347 this%lapdist = maxval(abs(gr%idx%enlarge)*gr%spacing)
350 safe_allocate(this%radius(1:ions%natoms))
352 do ia = 1, ions%natoms
353 norbs = ions%atom(ia)%species%get_niwfs()
357 call ions%atom(ia)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
359 if(ions%atom(ia)%species%is_full())
call ions%atom(ia)%species%get_iwf_n( iorb, 1, ii)
360 maxradius = max(maxradius, ions%atom(ia)%species%get_iwf_radius( ii, is = 1))
363 maxradius = min(maxradius,
m_two*maxval(gr%box%bounding_box_l(1:space%dim)))
365 this%radius(ia) = maxradius
397 do ia = 1, ions%natoms
399 if (jj > ions%atom(ia)%species%get_niwfs()) cycle
400 call ions%atom(ia)%species%get_iwf_ilm(jj, idim, ii, ll, mm)
402 if(ions%atom(ia)%species%is_full())
then
404 call ions%atom(ia)%species%get_iwf_n( ii_tmp, 1, ii)
406 if (this%orbital_scale_factor*ions%atom(ia)%species%get_iwf_radius( ii, is = 1) >= max_orb_radius) cycle
409 this%level(iorb) = jj
410 this%ddim(iorb) = idim
412 if (
debug%info .and. st%system_grp%is_root())
then
413 write(iunit_o,
'(7i6)') iorb, this%atom(iorb), this%level(iorb), ii, ll, mm, this%ddim(iorb)
421 if (
debug%info .and. st%system_grp%is_root())
then
426 if (this%maxorbs /= iorb - 1)
then
431 call messages_write(
' orbitals cannot be used for the LCAO calculation,')
433 call messages_write(
' their radii exceeds LCAOMaximumOrbitalRadius (')
438 this%maxorbs = iorb - 1
441 if (this%maxorbs < st%nst)
then
442 call messages_write(
'Cannot do LCAO for all states because there are not enough atomic orbitals.')
482 if (n > 0 .and. n <= st%nst .and. st%nst <= this%maxorbs)
then
485 else if (n > st%nst .and. n <= this%maxorbs)
then
488 else if (n == 0)
then
490 this%norbs = min(this%maxorbs, 2*st%nst)
493 this%norbs = this%maxorbs
496 assert(this%norbs <= this%maxorbs)
498 safe_allocate(this%cst(1:this%norbs, 1:st%d%spin_channels))
499 safe_allocate(this%ck(1:this%norbs, 1:st%d%spin_channels))
500 this%initialized_orbitals = .false.
510 integer :: iatom, iorb, norbs
511 real(real64) :: maxradius
514 integer :: jatom, jorb, jbasis, ilbasis, jlbasis, proc(1:2),
info, nbl
555 call parse_variable(namespace,
'LCAOExtraOrbitals', .false., this%derivative)
562 if (this%derivative)
then
565 if (st%nst * st%smear%el_per_state > st%qtot)
then
566 message(1) =
"Lower-lying empty states may be missed with LCAOExtraOrbitals."
579 call parse_variable(namespace,
'LCAODiagTol', 1e-10_real64, this%diag_tol)
581 if (this%derivative)
then
587 safe_allocate(this%sphere(1:ions%natoms))
588 safe_allocate(this%orbitals(1:ions%natoms))
589 safe_allocate(this%is_orbital_initialized(1:ions%natoms))
590 this%is_orbital_initialized = .false.
592 safe_allocate(this%norb_atom(1:ions%natoms))
596 do iatom = 1, ions%natoms
597 this%norb_atom(iatom) = this%mult*ions%atom(iatom)%species%get_niwfs()
598 this%maxorb = max(this%maxorb, ions%atom(iatom)%species%get_niwfs())
599 this%norbs = this%norbs + ions%atom(iatom)%species%get_niwfs()
602 this%maxorb = this%maxorb*this%mult
603 this%norbs = this%norbs*this%mult
605 safe_allocate(this%basis_atom(1:this%norbs))
606 safe_allocate(this%basis_orb(1:this%norbs))
607 safe_allocate(this%atom_orb_basis(1:ions%natoms, 1:this%maxorb))
612 do iatom = 1, ions%natoms
613 norbs = ions%atom(iatom)%species%get_niwfs()
615 do iorb = 1, this%mult*norbs
617 this%atom_orb_basis(iatom, iorb) = ibasis
618 this%basis_atom(ibasis) = iatom
619 this%basis_orb(ibasis) = iorb
622 if (
debug%info .and. st%system_grp%is_root())
then
623 call ions%atom(iatom)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
624 write(iunit_o,
'(7i6)') ibasis, iatom, iorb, ii, ll, mm, 1
629 if (
debug%info .and. st%system_grp%is_root())
then
634 this%lapdist = maxval(abs(gr%idx%enlarge)*gr%spacing)
637 safe_allocate(this%radius(1:ions%natoms))
639 do iatom = 1, ions%natoms
640 norbs = ions%atom(iatom)%species%get_niwfs()
644 call ions%atom(iatom)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
646 if(ions%atom(iatom)%species%is_full())
call ions%atom(iatom)%species%get_iwf_n( iorb, 1, ii)
647 maxradius = max(maxradius, ions%atom(iatom)%species%get_iwf_radius( ii, is = 1))
650 if (this%derivative) maxradius = maxradius + this%lapdist
652 maxradius = min(maxradius,
m_two*maxval(gr%box%bounding_box_l(1:space%dim)))
654 this%radius(iatom) = maxradius
657 safe_allocate(this%calc_atom(1:ions%natoms))
658 this%calc_atom = .
true.
661#ifndef HAVE_SCALAPACK
662 this%parallel = .false.
664 this%parallel = (st%parallel_in_states .or. gr%parallel_in_domains) &
667 if (this%parallel)
then
668 nbl = min(16, this%norbs)
671 this%lsize(1) = max(1,
numroc(this%norbs, nbl, st%dom_st_proc_grid%myrow, 0, st%dom_st_proc_grid%nprow))
672 this%lsize(2) = max(1,
numroc(this%norbs, nbl, st%dom_st_proc_grid%mycol, 0, st%dom_st_proc_grid%npcol))
674 this%nproc(1) = st%dom_st_proc_grid%nprow
675 this%nproc(2) = st%dom_st_proc_grid%npcol
676 this%myroc(1) = st%dom_st_proc_grid%myrow
677 this%myroc(2) = st%dom_st_proc_grid%mycol
679 call descinit(this%desc(1), this%norbs, this%norbs, nbl, nbl, 0, 0, &
680 st%dom_st_proc_grid%context, this%lsize(1),
info)
683 write(
message(1),
'(a,i6)')
'descinit for BLACS failed with error code ',
info
687 this%calc_atom = .false.
688 do iatom = 1, ions%natoms
689 ibasis = this%atom_orb_basis(iatom, 1)
691 do jatom = 1, ions%natoms
692 jbasis = this%atom_orb_basis(jatom, 1)
694 do iorb = 1, this%norb_atom(iatom)
695 do jorb = 1, this%norb_atom(jatom)
697 ilbasis, jlbasis, proc(1), proc(2))
699 this%calc_atom(this%basis_atom(jbasis)) = &
700 this%calc_atom(this%basis_atom(jbasis)) .or. proc(2) == this%myroc(2)
718 subroutine lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r, known_lower_bound)
721 type(
grid_t),
intent(in) :: gr
722 type(
ions_t),
intent(in) :: ions
725 type(
v_ks_t),
intent(inout) :: ks
727 integer,
optional,
intent(in) :: st_start
728 real(real64),
optional,
intent(in) :: lmm_r
729 logical,
optional,
intent(out) :: known_lower_bound
732 integer :: st_start_random, required_min_nst
734 logical :: is_orbital_dependent
738 if (
present(known_lower_bound)) known_lower_bound = .false.
740 if (
present(st_start))
then
743 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
744 calc_eigenval=.not.
present(st_start), calc_current=.false.)
746 assert(st_start >= 1)
747 if (st_start > st%nst)
then
748 if (
present(known_lower_bound)) known_lower_bound = .
true.
765 if (.not.
present(st_start))
then
769 assert(
present(lmm_r))
775 message(1) =
'Info: Setting up Hamiltonian.'
779 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval=.false., &
780 calc_current=.false., calc_energy=.false., force_semilocal=is_orbital_dependent)
783 st%eigenval = default_eigenval
792 if (
present(st_start))
then
793 write(
message(1),
'(a,i8,a)')
'Performing LCAO for states ', st_start,
' and above'
797 call lcao_wf(lcao, st, gr, ions, hm, namespace, start = st_start)
803 select case (st%d%ispin)
805 required_min_nst = int(st%qtot/2)
807 required_min_nst = int(st%qtot/2)
809 required_min_nst = int(st%qtot)
812 if (lcao%norbs <= required_min_nst .and. lcao%norbs < st%nst)
then
813 st%eigenval(lcao%norbs+1:,:) =
m_zero
817 if (.not.
present(st_start))
then
822 if (lcao%mode == option__lcaostart__lcao_full)
then
823 call v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, &
824 calc_eigenval = .false., calc_current=.false.)
826 assert(
present(lmm_r))
832 if (
present(known_lower_bound) .and. lcao%norbs >= st%nst .and. .not. is_orbital_dependent) known_lower_bound = .
true.
835 if (.not. lcao_done .or. lcao%norbs < st%nst)
then
838 st_start_random = lcao%norbs + 1
842 if (
present(st_start)) st_start_random = max(st_start, st_start_random)
844 if (st_start_random > 1)
then
845 write(
message(1),
'(a,i8,a)')
'Generating random wavefunctions for states ', st_start_random,
' and above'
854 if (.not. st%fixed_spins)
then
862 if (.not. lcao_done)
then
865 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
866 calc_eigenval=.not.
present(st_start), calc_current=.false., force_semilocal=is_orbital_dependent)
867 if (.not.
present(st_start))
then
873 else if (
present(st_start))
then
875 if (st_start > 1)
then
892 type(
lcao_t),
intent(inout) :: this
896 safe_deallocate_a(this%calc_atom)
897 safe_deallocate_a(this%norb_atom)
898 safe_deallocate_a(this%basis_atom)
899 safe_deallocate_a(this%basis_orb)
900 safe_deallocate_a(this%atom_orb_basis)
901 safe_deallocate_a(this%radius)
902 safe_deallocate_a(this%sphere)
903 safe_deallocate_a(this%orbitals)
905 safe_deallocate_a(this%atom)
906 safe_deallocate_a(this%level)
907 safe_deallocate_a(this%ddim)
908 safe_deallocate_a(this%cst)
909 safe_deallocate_a(this%ck)
910 safe_deallocate_a(this%dbuff_single)
911 safe_deallocate_a(this%zbuff_single)
912 safe_deallocate_a(this%dbuff)
913 safe_deallocate_a(this%zbuff)
915 this%initialized = .false.
921 subroutine lcao_wf(this, st, gr, ions, hm, namespace, start)
922 type(
lcao_t),
intent(inout) :: this
924 type(
grid_t),
intent(in) :: gr
925 type(
ions_t),
intent(in) :: ions
928 integer,
optional,
intent(in) :: start
932 assert(this%initialized)
938 if (
present(start)) start_ = start
940 if (this%alternative)
then
942 call dlcao_alt_wf(this, st, gr, ions, hm, namespace, start_)
944 call zlcao_alt_wf(this, st, gr, ions, hm, namespace, start_)
948 call dlcao_wf(this, st, gr, ions, hm, namespace, start_)
950 call zlcao_wf(this, st, gr, ions, hm, namespace, start_)
961 type(
lcao_t),
intent(in) :: this
965 available = this%initialized .and. this%mode /= option__lcaostart__lcao_none &
974 type(
lcao_t),
intent(in) :: this
975 integer,
intent(in) :: ig
976 integer,
intent(in) :: jg
977 integer,
intent(out) :: il
978 integer,
intent(out) :: jl
979 integer,
intent(out) :: prow
980 integer,
intent(out) :: pcol
984 call infog2l(ig, jg, this%desc(1), this%nproc(1), this%nproc(2), this%myroc(1), this%myroc(2), &
1001 type(
lcao_t),
intent(inout) :: this
1002 integer,
intent(in) :: iatom
1006 if (this%is_orbital_initialized(iatom))
then
1007 call this%orbitals(iatom)%end()
1008 this%is_orbital_initialized(iatom) = .false.
1018 type(
lcao_t),
intent(inout) :: this
1020 class(
mesh_t),
intent(in) :: mesh
1022 integer,
intent(in) :: iatom
1023 integer,
intent(in) :: spin_channels
1024 real(real64),
contiguous,
intent(inout) :: rho(:, :)
1026 real(real64),
allocatable :: dorbital(:, :)
1027 complex(real64),
allocatable :: zorbital(:, :)
1028 real(real64),
allocatable :: factors(:)
1029 real(real64) :: factor, aa
1030 integer :: iorb, ip, ii, ll, mm, ispin
1031 type(
ps_t),
pointer :: ps
1032 logical :: use_stored_orbitals
1038 use_stored_orbitals = ions%atom(iatom)%species%is_ps() &
1040 .and. st%d%dim == 1 .and. .not. ions%space%is_periodic()
1044 if (use_stored_orbitals)
then
1046 assert(.not. ions%space%is_periodic())
1048 select type(spec=>ions%atom(iatom)%species)
1055 if (.not. this%alternative)
then
1058 safe_allocate(dorbital(1:mesh%np, 1:st%d%dim))
1060 safe_allocate(zorbital(1:mesh%np, 1:st%d%dim))
1063 do iorb = 1, this%norbs
1064 if (iatom /= this%atom(iorb)) cycle
1066 call ions%atom(iatom)%species%get_iwf_ilm(this%level(iorb), 1, ii, ll, mm)
1067 factor = ps%conf%occ(ii, 1)/(
m_two*ll +
m_one)
1070 call dget_ao(this, st, mesh, ions, iorb, 1, dorbital, use_psi = .
true.)
1073 rho(ip, 1) = rho(ip, 1) + factor*dorbital(ip, 1)**2
1076 call zget_ao(this, st, mesh, ions, iorb, 1, zorbital, use_psi = .
true.)
1079 rho(ip, 1) = rho(ip, 1) + factor*abs(zorbital(ip, 1))**2
1085 safe_deallocate_a(dorbital)
1086 safe_deallocate_a(zorbital)
1094 safe_allocate(factors(1:this%norb_atom(iatom)/this%mult))
1096 do iorb = 1, this%norb_atom(iatom)/this%mult
1097 call ions%atom(iatom)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
1098 factors(iorb) = ps%conf%occ(ii, 1)/(
m_two*ll +
m_one)
1102 do ip = 1, this%sphere(iatom)%np
1104 do iorb = 1, this%norb_atom(iatom)/this%mult
1105 aa = aa + factors(iorb)*this%orbitals(iatom)%dff_linear(ip, iorb)**2
1107 rho(this%sphere(iatom)%map(ip), 1) = rho(this%sphere(iatom)%map(ip), 1) + aa
1110 safe_deallocate_a(factors)
1116 ions%pos(:, iatom), mesh, spin_channels, rho)
1121 do ispin = 1, spin_channels
1124 rho(ip, ispin) = max(rho(ip, ispin),
m_zero)
1134 type(
lcao_t),
intent(inout) :: this
1137 type(
grid_t),
intent(in) :: gr
1139 type(
ions_t),
intent(in) :: ions
1140 real(real64),
intent(in) :: qtot
1141 integer,
intent(in) :: ispin
1142 real(real64),
contiguous,
intent(out) :: rho(:, :)
1144 integer :: ia, is, idir, ip, m_dim, ispin2
1147 real(real64) :: rr, rnd, phi, theta, lmag, n1, n2
1148 real(real64),
allocatable :: atom_rho(:,:), mag(:,:)
1149 real(real64),
parameter :: tol_min_mag = 1.0e-20_real64
1153 if (st%d%spin_channels == 1)
then
1154 this%gmd_opt = initrho_paramagnetic
1187 message(1) =
"Only paramagnetic and ferromagnetic options for GuessMagnetDensity can be used "
1188 message(2) =
" for Hartree-Fock and generalized Kohn-Sham calculation."
1189 message(3) =
"Please perform a LDA or GGA calculation first and restart from this calculation if you want another option."
1213 if (
parse_block(namespace,
'AtomsMagnetDirection', blk) < 0)
then
1214 message(1) =
"AtomsMagnetDirection block is not defined."
1219 message(1) =
"The number of rows in the AtomsMagnetDirection block does not equal the number of atoms."
1229 safe_allocate(mag(1:m_dim, 1:ions%natoms))
1230 do ia = 1, ions%natoms
1234 if (abs(mag(idir, ia)) < tol_min_mag) mag(idir, ia) =
m_zero
1242 safe_allocate(atom_rho(1:gr%np, 1:st%d%spin_channels))
1243 select case (this%gmd_opt)
1244 case (initrho_paramagnetic)
1245 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1250 if (st%d%spin_channels == 2)
then
1253 rho(ip, 1) =
m_half*(rho(ip, 1) + rho(ip, 2))
1254 rho(ip, 2) = rho(ip, 1)
1259 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1262 call lalg_axpy(gr%np,
m_one, atom_rho(:, ispin2), rho(:, ispin2))
1267 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1282 call lalg_axpy(gr%np, (lmag - n1 + n2)/
m_two/n2, atom_rho(:, 2), atom_rho(:, 1))
1292 call lalg_axpy(gr%np,
m_one, atom_rho(:, ispin2), rho(:, ispin2))
1298 elseif (ispin ==
spinors)
then
1309 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1317 lmag = norm2(mag(:, ia))
1318 if (lmag > n1 + n2)
then
1319 mag(:, ia) = mag(:, ia)*(n1 + n2)/lmag
1327 atom_rho(ip, 1) =
m_half*(atom_rho(ip, 1) + atom_rho(ip, 2))
1328 rho(ip, 1) = rho(ip, 1) + atom_rho(ip, 1)
1329 rho(ip, 2) = rho(ip, 2) + atom_rho(ip, 1)
1336 if (n1 - n2 < lmag)
then
1337 call lalg_axpy(gr%np, (lmag - n1 + n2)/
m_two/n2, atom_rho(:, 2), atom_rho(:, 1))
1339 elseif (n1 - n2 > lmag)
then
1340 call lalg_axpy(gr%np, (n1 - n2 - lmag)/
m_two/n1, atom_rho(:, 1), atom_rho(:, 2))
1348 if (mag(1, ia) >
m_zero)
then
1355 elseif (ispin ==
spinors)
then
1365 if (ions%atoms_dist%parallel)
then
1366 do is = 1, st%d%nspin
1367 call lalg_copy(gr%np, rho(:,is), atom_rho(:,1))
1368 call ions%atoms_dist%mpi_grp%allreduce(atom_rho(1, 1), rho(1, is), gr%np, mpi_double_precision, mpi_sum)
1374 write(
message(1),
'(a,f13.6)')
'Info: Unnormalized total charge = ', rr
1379 call lalg_scal(gr%np, st%d%nspin, qtot/rr, rho)
1381 write(
message(1),
'(a,f13.6)')
'Info: Renormalized total charge = ', rr
1386 if (st%symmetrize_density)
then
1387 do is = 1, st%d%nspin
1392 safe_deallocate_a(atom_rho)
1393 safe_deallocate_a(mag)
1400 class(
mesh_t),
intent(in) :: mesh
1401 real(real64),
contiguous,
intent(inout) :: rho(:,:)
1402 real(real64),
contiguous,
intent(in) :: atom_rho(:,:)
1403 real(real64),
intent(in) :: theta, phi
1406 real(real64) :: half_theta
1410 half_theta =
m_half * theta
1414 rho(ip, 1) = rho(ip, 1) +
cos(half_theta)**2*atom_rho(ip, 1) +
sin(half_theta)**2*atom_rho(ip, 2)
1415 rho(ip, 2) = rho(ip, 2) +
sin(half_theta)**2*atom_rho(ip, 1) +
cos(half_theta)**2*atom_rho(ip, 2)
1416 rho(ip, 3) = rho(ip, 3) +
cos(half_theta)*
sin(half_theta)*
cos(phi)*(atom_rho(ip, 1)-atom_rho(ip, 2))
1417 rho(ip, 4) = rho(ip, 4) -
cos(half_theta)*
sin(half_theta)*
sin(phi)*(atom_rho(ip, 1)-atom_rho(ip, 2))
1426 type(
lcao_t),
intent(inout) :: this
1429 type(
grid_t),
intent(in) :: gr
1430 type(
ions_t),
intent(in) :: ions
1431 integer,
optional,
intent(in) :: start
1437 if (.not. this%alternative)
then
1457 real(real64),
intent(in) :: mag(3)
1458 real(real64),
intent(in) :: lmag
1459 real(real64),
intent(out) :: theta
1460 real(real64),
intent(out) :: phi
1464 theta =
acos(max(-1.0_real64, min(1.0_real64, mag(3)/lmag)))
1469 elseif (mag(2) <
m_zero)
then
1476 phi =
atan2(mag(2), mag(1))
1492 type(
grid_t),
intent(in) :: gr
1493 integer,
intent(in) :: ist_start
1494 integer,
intent(in) :: gmd_opt
1496 integer :: ik, ist, ip
1497 real(real64),
allocatable :: md(:,:), up(:)
1498 complex(real64),
allocatable :: down(:), psi(:,:)
1499 real(real64) :: lmag, theta, phi, norm, mm(3)
1501 if (st%d%ispin /=
spinors)
return
1506 safe_allocate(psi(1:gr%np, 1:st%d%dim))
1508 select case (gmd_opt)
1509 case(initrho_paramagnetic)
1511 do ik = st%d%kpt%start, st%d%kpt%end
1512 do ist = ist_start, st%st_end
1516 psi(ip, 1) = psi(ip, 1) + psi(ip, 2)
1517 psi(ip, 2) = psi(ip, 1)
1526 do ik = st%d%kpt%start, st%d%kpt%end
1527 do ist = ist_start, st%st_end
1531 psi(ip, 1) = psi(ip, 1) + psi(ip, 2)
1541 safe_allocate(md(1:gr%np, 1:3))
1542 safe_allocate(up(1:gr%np))
1543 safe_allocate(down(1:gr%np))
1550 if (gr%parallel_in_domains)
then
1551 call gr%allreduce(mm)
1557 if (lmag > 1.0e-2_real64)
then
1567 lmag = norm2(md(ip, 1:3))
1568 if (lmag > 1.0e-10_real64)
then
1577 safe_deallocate_a(md)
1581 do ik = st%d%kpt%start, st%d%kpt%end
1582 do ist = ist_start, st%st_end
1587 norm =
sqrt(real(psi(ip, 1)*conjg(psi(ip, 1)) + psi(ip, 2)*conjg(psi(ip, 2))))
1588 psi(ip, 1) = norm * up(ip)
1589 psi(ip, 2) = norm * down(ip)
1594 safe_deallocate_a(up)
1595 safe_deallocate_a(down)
1598 safe_deallocate_a(psi)
1605#include "lcao_inc.F90"
1608#include "complex.F90"
1609#include "lcao_inc.F90"
constant times a vector plus a vector
Copies a vector x, to a vector y.
scales a vector by a constant
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
double acos(double __x) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
double sin(double __x) __attribute__((__nothrow__
double cos(double __x) __attribute__((__nothrow__
double atan2(double __y, double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
This module contains interfaces for BLACS routines Interfaces are from http:
This module provides the BLACS processor grid.
logical pure function, public blacs_proc_grid_null(this)
Module implementing boundary conditions in Octopus.
type(debug_t), save, public debug
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
integer, parameter, public spin_polarized
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_pi
some mathematical constants
integer, parameter, public hartree_fock
integer, parameter, public generalized_kohn_sham_dft
complex(real64), parameter, public m_zi
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_half
real(real64), parameter, public m_one
real(real64), parameter, public m_three
This module implements the underlying real-space grid.
subroutine, public dgrid_symmetrize_scalar_field(gr, field, suppress_warning)
This module defines classes and functions for interaction partners.
subroutine, public io_close(iunit, grp)
subroutine, public io_mkdir(fname, namespace, parents)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
A module to handle KS potential, without the external potential.
This module contains interfaces for LAPACK routines.
subroutine, public lcao_init_orbitals(this, namespace, st, gr, ions, start)
subroutine, public lcao_wf(this, st, gr, ions, hm, namespace, start)
subroutine zlcao_alt_init_orbitals(this, namespace, st, gr, ions, start)
subroutine zget_ao(this, st, mesh, ions, iorb, ispin, ao, use_psi)
subroutine, public lcao_end(this)
subroutine zlcao_alt_wf(this, st, gr, ions, hm, namespace, start)
The alternative implementation.
subroutine dlcao_wf(this, st, gr, ions, hm, namespace, start)
subroutine dlcao_alt_init_orbitals(this, namespace, st, gr, ions, start)
subroutine zlcao_wf(this, st, gr, ions, hm, namespace, start)
subroutine rotate_random_states_to_local_frame(st, gr, ist_start, gmd_opt)
Rotate the spinors with band index >= ist_start to the local frame of the magnetization.
subroutine, public lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r, known_lower_bound)
subroutine dlcao_alt_wf(this, st, gr, ions, hm, namespace, start)
The alternative implementation.
integer, parameter initrho_userdef
subroutine get_angles_from_magnetization(mag, lmag, theta, phi)
Given a magnetization vector, and its norm, this returns the corresponding inclination and azimuthal ...
integer, parameter initrho_random
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...
subroutine lcao_local_index(this, ig, jg, il, jl, prow, pcol)
subroutine lcao_guess_density(this, namespace, st, gr, hm, ions, qtot, ispin, rho)
builds a density which is the sum of the atomic densities
subroutine dinit_orbitals(this, namespace, st, gr, ions, start)
subroutine dget_ao(this, st, mesh, ions, iorb, ispin, ao, use_psi)
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...
subroutine zinit_orbitals(this, namespace, st, gr, ions, start)
subroutine lcao_atom_density(this, st, mesh, ions, iatom, spin_channels, rho)
subroutine, public lcao_init(this, namespace, space, gr, ions, st, st_start)
subroutine accumulate_rotated_density(mesh, rho, atom_rho, theta, phi)
integer, parameter initrho_ferromagnetic
logical function, public lcao_is_available(this)
Returns true if LCAO can be done.
System information (time, memory, sysname)
subroutine, public compute_and_write_magnetic_moments(gr, st, phase, ep, ions, lmm_r, calc_orb_moments, iunit, namespace)
Computes and prints the global and local magnetic moments.
subroutine, public magnetic_density(mesh, std, rho, md)
This module is intended to contain "only mathematical" functions and procedures.
This module defines various routines, operating on mesh functions.
subroutine, public zmf_normalize(mesh, dim, psi, norm)
Normalize a mesh function psi.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_obsolete_variable(namespace, name, rep)
subroutine, public messages_new_line()
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_experimental(name, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
integer function, public parse_block(namespace, name, blk, check_varinfo_)
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
integer(int64), parameter, public splitmix64_321
This module contains interfaces for ScaLAPACK routines Interfaces are from http:
integer, parameter, public smear_semiconductor
integer, parameter, public smear_fixed_occ
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)
Orthogonalize electronic states.
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.
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
logical function, public v_ks_is_orbital_dependent(ks)
Is the theory method and functional orbital-dependent?
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
subroutine, public v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Describes mesh distribution to nodes.
A type storing the information and data about a pseudopotential.
The states_elec_t class contains all electronic wave functions.