39 use,
intrinsic :: iso_fortran_env
93 logical :: complex_ylms
94 logical :: initialized
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
113 logical,
allocatable :: is_empty(:)
119 real(real64),
allocatable :: radius(:)
120 real(real64) :: lapdist
124 integer,
allocatable :: basis_atom(:)
125 integer,
allocatable :: basis_orb(:)
126 integer,
allocatable :: atom_orb_basis(:, :)
127 integer,
allocatable :: norb_atom(:)
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(:)
143 integer,
parameter :: &
144 INITRHO_PARAMAGNETIC = 1, &
149 real(real64),
parameter,
public :: default_eigenval = 1.0e10_real64
154 subroutine lcao_init(this, namespace, space, gr, ions, st, st_start)
155 type(lcao_t),
intent(out) :: this
156 type(namespace_t),
intent(in) :: namespace
157 type(electron_space_t),
intent(in) :: space
158 type(grid_t),
intent(in) :: gr
159 type(ions_t),
intent(in) :: ions
160 type(states_elec_t),
intent(in) :: st
161 integer,
intent(in) :: st_start
163 integer :: ia, n, iorb, jj, maxj, idim
164 integer :: ii, ll, mm, norbs, ii_tmp
165 integer :: mode_default
166 real(real64) :: max_orb_radius, maxradius
171 this%initialized = .
true.
175 mode_default = option__lcaostart__lcao_states
176 if (ions%only_user_def) mode_default = option__lcaostart__lcao_none
233 if (this%mode == option__lcaostart__lcao_states_batch .and. st_start > 1)
then
234 message(1) =
"LCAOStart = lcao_states_batch not compatible with this run."
235 message(2) =
"Please use LCAOStart = lcao_states instead"
240 this%alternative = this%mode == option__lcaostart__lcao_states_batch
242 if (this%mode == option__lcaostart__lcao_none)
then
252 if (st%d%ispin ==
spinors .and. this%alternative)
then
253 message(1) =
"LCAOStart = lcao_states_batch is not working for spinors."
256 if (space%is_periodic() .and. this%alternative)
then
274 call parse_variable(namespace,
'LCAOComplexYlms', .false., this%complex_ylms)
276 this%complex_ylms = .false.
287 call parse_variable(namespace,
'LCAOSaveMemory', .false., this%save_memory)
291 call io_mkdir(
'debug/lcao', namespace)
292 iunit_o =
io_open(
'debug/lcao/orbitals', namespace, action=
'write')
293 write(iunit_o,
'(7a6)')
'iorb',
'atom',
'level',
'i',
'l',
'm',
'spin'
296 if (.not. this%alternative)
then
317 call parse_variable(namespace,
'LCAOMaximumOrbitalRadius', 20.0_real64, max_orb_radius, unit =
units_inp%length)
323 do ia = 1, ions%natoms
324 maxj = max(maxj, ions%atom(ia)%species%get_niwfs())
325 this%maxorbs = this%maxorbs + ions%atom(ia)%species%get_niwfs()
328 this%maxorbs = this%maxorbs*st%d%dim
330 if (this%maxorbs == 0)
then
331 call messages_write(
'The are no atomic orbitals available, cannot do LCAO.')
333 this%mode = option__lcaostart__lcao_none
340 safe_allocate( this%atom(1:this%maxorbs))
341 safe_allocate(this%level(1:this%maxorbs))
342 safe_allocate( this%ddim(1:this%maxorbs))
344 safe_allocate(this%is_empty(1:this%maxorbs))
345 this%is_empty = .false.
348 this%lapdist = maxval(abs(gr%idx%enlarge)*gr%spacing)
351 safe_allocate(this%radius(1:ions%natoms))
353 do ia = 1, ions%natoms
354 norbs = ions%atom(ia)%species%get_niwfs()
358 call ions%atom(ia)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
360 if(ions%atom(ia)%species%is_full())
call ions%atom(ia)%species%get_iwf_n( iorb, 1, ii)
361 maxradius = max(maxradius, ions%atom(ia)%species%get_iwf_radius( ii, is = 1))
364 maxradius = min(maxradius,
m_two*maxval(gr%box%bounding_box_l(1:space%dim)))
366 this%radius(ia) = maxradius
398 do ia = 1, ions%natoms
400 if (jj > ions%atom(ia)%species%get_niwfs()) cycle
401 call ions%atom(ia)%species%get_iwf_ilm(jj, idim, ii, ll, mm)
403 if(ions%atom(ia)%species%is_full())
then
405 call ions%atom(ia)%species%get_iwf_n( ii_tmp, 1, ii)
407 if (this%orbital_scale_factor*ions%atom(ia)%species%get_iwf_radius( ii, is = 1) >= max_orb_radius) cycle
410 this%level(iorb) = jj
411 this%ddim(iorb) = idim
414 write(iunit_o,
'(7i6)') iorb, this%atom(iorb), this%level(iorb), ii, ll, mm, this%ddim(iorb)
427 if (this%maxorbs /= iorb - 1)
then
432 call messages_write(
' orbitals cannot be used for the LCAO calculation,')
434 call messages_write(
' their radii exceeds LCAOMaximumOrbitalRadius (')
439 this%maxorbs = iorb - 1
442 if (this%maxorbs < st%nst)
then
443 call messages_write(
'Cannot do LCAO for all states because there are not enough atomic orbitals.')
483 if (n > 0 .and. n <= st%nst .and. st%nst <= this%maxorbs)
then
486 else if (n > st%nst .and. n <= this%maxorbs)
then
489 else if (n == 0)
then
491 this%norbs = min(this%maxorbs, 2*st%nst)
494 this%norbs = this%maxorbs
497 assert(this%norbs <= this%maxorbs)
499 safe_allocate(this%cst(1:this%norbs, 1:st%d%spin_channels))
500 safe_allocate(this%ck(1:this%norbs, 1:st%d%spin_channels))
501 this%initialized_orbitals = .false.
511 integer :: iatom, iorb, norbs
512 real(real64) :: maxradius
515 integer :: jatom, jorb, jbasis, ilbasis, jlbasis, proc(1:2),
info, nbl
556 call parse_variable(namespace,
'LCAOExtraOrbitals', .false., this%derivative)
563 if (this%derivative)
then
566 if (st%nst * st%smear%el_per_state > st%qtot)
then
567 message(1) =
"Lower-lying empty states may be missed with LCAOExtraOrbitals."
580 call parse_variable(namespace,
'LCAODiagTol', 1e-10_real64, this%diag_tol)
582 if (this%derivative)
then
588 safe_allocate(this%sphere(1:ions%natoms))
589 safe_allocate(this%orbitals(1:ions%natoms))
590 safe_allocate(this%is_orbital_initialized(1:ions%natoms))
591 this%is_orbital_initialized = .false.
593 safe_allocate(this%norb_atom(1:ions%natoms))
597 do iatom = 1, ions%natoms
598 this%norb_atom(iatom) = this%mult*ions%atom(iatom)%species%get_niwfs()
599 this%maxorb = max(this%maxorb, ions%atom(iatom)%species%get_niwfs())
600 this%norbs = this%norbs + ions%atom(iatom)%species%get_niwfs()
603 this%maxorb = this%maxorb*this%mult
604 this%norbs = this%norbs*this%mult
606 safe_allocate(this%basis_atom(1:this%norbs))
607 safe_allocate(this%basis_orb(1:this%norbs))
608 safe_allocate(this%atom_orb_basis(1:ions%natoms, 1:this%maxorb))
613 do iatom = 1, ions%natoms
614 norbs = ions%atom(iatom)%species%get_niwfs()
616 do iorb = 1, this%mult*norbs
618 this%atom_orb_basis(iatom, iorb) = ibasis
619 this%basis_atom(ibasis) = iatom
620 this%basis_orb(ibasis) = iorb
624 call ions%atom(iatom)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
625 write(iunit_o,
'(7i6)') ibasis, iatom, iorb, ii, ll, mm, 1
635 this%lapdist = maxval(abs(gr%idx%enlarge)*gr%spacing)
638 safe_allocate(this%radius(1:ions%natoms))
640 do iatom = 1, ions%natoms
641 norbs = ions%atom(iatom)%species%get_niwfs()
645 call ions%atom(iatom)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
647 if(ions%atom(iatom)%species%is_full())
call ions%atom(iatom)%species%get_iwf_n( iorb, 1, ii)
648 maxradius = max(maxradius, ions%atom(iatom)%species%get_iwf_radius( ii, is = 1))
651 if (this%derivative) maxradius = maxradius + this%lapdist
653 maxradius = min(maxradius,
m_two*maxval(gr%box%bounding_box_l(1:space%dim)))
655 this%radius(iatom) = maxradius
658 safe_allocate(this%calc_atom(1:ions%natoms))
659 this%calc_atom = .
true.
662#ifndef HAVE_SCALAPACK
663 this%parallel = .false.
665 this%parallel = (st%parallel_in_states .or. gr%parallel_in_domains) &
668 if (this%parallel)
then
669 nbl = min(16, this%norbs)
672 this%lsize(1) = max(1,
numroc(this%norbs, nbl, st%dom_st_proc_grid%myrow, 0, st%dom_st_proc_grid%nprow))
673 this%lsize(2) = max(1,
numroc(this%norbs, nbl, st%dom_st_proc_grid%mycol, 0, st%dom_st_proc_grid%npcol))
675 this%nproc(1) = st%dom_st_proc_grid%nprow
676 this%nproc(2) = st%dom_st_proc_grid%npcol
677 this%myroc(1) = st%dom_st_proc_grid%myrow
678 this%myroc(2) = st%dom_st_proc_grid%mycol
680 call descinit(this%desc(1), this%norbs, this%norbs, nbl, nbl, 0, 0, &
681 st%dom_st_proc_grid%context, this%lsize(1),
info)
684 write(
message(1),
'(a,i6)')
'descinit for BLACS failed with error code ',
info
688 this%calc_atom = .false.
689 do iatom = 1, ions%natoms
690 ibasis = this%atom_orb_basis(iatom, 1)
692 do jatom = 1, ions%natoms
693 jbasis = this%atom_orb_basis(jatom, 1)
695 do iorb = 1, this%norb_atom(iatom)
696 do jorb = 1, this%norb_atom(jatom)
698 ilbasis, jlbasis, proc(1), proc(2))
700 this%calc_atom(this%basis_atom(jbasis)) = &
701 this%calc_atom(this%basis_atom(jbasis)) .or. proc(2) == this%myroc(2)
719 subroutine lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r)
722 type(
grid_t),
intent(in) :: gr
723 type(
ions_t),
intent(in) :: ions
726 type(
v_ks_t),
intent(inout) :: ks
728 integer,
optional,
intent(in) :: st_start
729 real(real64),
optional,
intent(in) :: lmm_r
732 integer :: st_start_random, required_min_nst
734 logical :: is_orbital_dependent
738 if (
present(st_start))
then
741 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
742 calc_eigenval=.not.
present(st_start), calc_current=.false.)
744 assert(st_start >= 1)
745 if (st_start > st%nst)
then
765 if (.not.
present(st_start))
then
766 call lcao_guess_density(lcao, namespace, st, gr, hm, ions, st%qtot, st%d%ispin, st%rho)
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))
833 if (.not. lcao_done .or. lcao%norbs < st%nst)
then
836 st_start_random = lcao%norbs + 1
840 if (
present(st_start)) st_start_random = max(st_start, st_start_random)
842 if (st_start_random > 1)
then
843 write(
message(1),
'(a,i8,a)')
'Generating random wavefunctions for states ', st_start_random,
' and above'
852 if (.not. st%fixed_spins)
then
860 if (.not. lcao_done)
then
863 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
864 calc_eigenval=.not.
present(st_start), calc_current=.false., force_semilocal=is_orbital_dependent)
865 if (.not.
present(st_start))
then
871 else if (
present(st_start))
then
873 if (st_start > 1)
then
890 type(
lcao_t),
intent(inout) :: this
894 safe_deallocate_a(this%calc_atom)
895 safe_deallocate_a(this%norb_atom)
896 safe_deallocate_a(this%basis_atom)
897 safe_deallocate_a(this%basis_orb)
898 safe_deallocate_a(this%atom_orb_basis)
899 safe_deallocate_a(this%radius)
900 safe_deallocate_a(this%sphere)
901 safe_deallocate_a(this%orbitals)
903 safe_deallocate_a(this%atom)
904 safe_deallocate_a(this%level)
905 safe_deallocate_a(this%ddim)
906 safe_deallocate_a(this%cst)
907 safe_deallocate_a(this%ck)
908 safe_deallocate_a(this%dbuff_single)
909 safe_deallocate_a(this%zbuff_single)
910 safe_deallocate_a(this%dbuff)
911 safe_deallocate_a(this%zbuff)
913 this%initialized = .false.
919 subroutine lcao_wf(this, st, gr, ions, hm, namespace, start)
920 type(
lcao_t),
intent(inout) :: this
922 type(
grid_t),
intent(in) :: gr
923 type(
ions_t),
intent(in) :: ions
926 integer,
optional,
intent(in) :: start
930 assert(this%initialized)
936 if (
present(start)) start_ = start
938 if (this%alternative)
then
940 call dlcao_alt_wf(this, st, gr, ions, hm, namespace, start_)
942 call zlcao_alt_wf(this, st, gr, ions, hm, namespace, start_)
946 call dlcao_wf(this, st, gr, ions, hm, namespace, start_)
948 call zlcao_wf(this, st, gr, ions, hm, namespace, start_)
959 type(
lcao_t),
intent(in) :: this
963 available = this%initialized .and. this%mode /= option__lcaostart__lcao_none &
973 type(
lcao_t),
intent(in) :: this
984 type(
lcao_t),
intent(in) :: this
985 integer,
intent(in) :: ig
986 integer,
intent(in) :: jg
987 integer,
intent(out) :: il
988 integer,
intent(out) :: jl
989 integer,
intent(out) :: prow
990 integer,
intent(out) :: pcol
994 call infog2l(ig, jg, this%desc(1), this%nproc(1), this%nproc(2), this%myroc(1), this%myroc(2), &
1011 type(
lcao_t),
intent(inout) :: this
1012 integer,
intent(in) :: iatom
1016 if (this%is_orbital_initialized(iatom))
then
1017 call this%orbitals(iatom)%end()
1018 this%is_orbital_initialized(iatom) = .false.
1028 type(
lcao_t),
intent(inout) :: this
1030 class(
mesh_t),
intent(in) :: mesh
1032 integer,
intent(in) :: iatom
1033 integer,
intent(in) :: spin_channels
1034 real(real64),
intent(inout) :: rho(:, :)
1036 real(real64),
allocatable :: dorbital(:, :)
1037 complex(real64),
allocatable :: zorbital(:, :)
1038 real(real64),
allocatable :: factors(:)
1039 real(real64) :: factor, aa
1040 integer :: iorb, ip, ii, ll, mm, ispin
1041 type(
ps_t),
pointer :: ps
1042 logical :: use_stored_orbitals
1048 use_stored_orbitals = ions%atom(iatom)%species%is_ps() &
1050 .and. st%d%dim == 1 .and. .not. ions%space%is_periodic()
1054 if (use_stored_orbitals)
then
1056 assert(.not. ions%space%is_periodic())
1058 select type(spec=>ions%atom(iatom)%species)
1065 if (.not. this%alternative)
then
1068 safe_allocate(dorbital(1:mesh%np, 1:st%d%dim))
1070 safe_allocate(zorbital(1:mesh%np, 1:st%d%dim))
1073 do iorb = 1, this%norbs
1074 if (iatom /= this%atom(iorb)) cycle
1076 call ions%atom(iatom)%species%get_iwf_ilm(this%level(iorb), 1, ii, ll, mm)
1077 factor = ps%conf%occ(ii, 1)/(
m_two*ll +
m_one)
1080 call dget_ao(this, st, mesh, ions, iorb, 1, dorbital, use_psi = .
true.)
1083 rho(ip, 1) = rho(ip, 1) + factor*dorbital(ip, 1)**2
1086 call zget_ao(this, st, mesh, ions, iorb, 1, zorbital, use_psi = .
true.)
1089 rho(ip, 1) = rho(ip, 1) + factor*abs(zorbital(ip, 1))**2
1095 safe_deallocate_a(dorbital)
1096 safe_deallocate_a(zorbital)
1104 safe_allocate(factors(1:this%norb_atom(iatom)/this%mult))
1106 do iorb = 1, this%norb_atom(iatom)/this%mult
1107 call ions%atom(iatom)%species%get_iwf_ilm(iorb, 1, ii, ll, mm)
1108 factors(iorb) = ps%conf%occ(ii, 1)/(
m_two*ll +
m_one)
1112 do ip = 1, this%sphere(iatom)%np
1114 do iorb = 1, this%norb_atom(iatom)/this%mult
1115 aa = aa + factors(iorb)*this%orbitals(iatom)%dff_linear(ip, iorb)**2
1117 rho(this%sphere(iatom)%map(ip), 1) = rho(this%sphere(iatom)%map(ip), 1) + aa
1120 safe_deallocate_a(factors)
1126 ions%pos(:, iatom), mesh, spin_channels, rho)
1131 do ispin = 1, spin_channels
1134 rho(ip, ispin) = max(rho(ip, ispin),
m_zero)
1144 type(
lcao_t),
intent(inout) :: this
1147 type(
grid_t),
intent(in) :: gr
1149 type(
ions_t),
intent(in) :: ions
1150 real(real64),
intent(in) :: qtot
1151 integer,
intent(in) :: ispin
1152 real(real64),
contiguous,
intent(out) :: rho(:, :)
1154 integer :: ia, is, idir, ip, m_dim
1157 real(real64) :: rr, rnd, phi, theta, lmag, n1, n2
1158 real(real64),
allocatable :: atom_rho(:,:), mag(:,:)
1159 real(real64),
parameter :: tol_min_mag = 1.0e-20_real64
1163 if (st%d%spin_channels == 1)
then
1164 this%gmd_opt = initrho_paramagnetic
1197 message(1) =
"GuessMagnetDensity cannot be used for Hartree-Fock and generalized Kohn-Sham calculation."
1198 message(2) =
"Please perform a LDA or GGA calculation first and restart from this calculation."
1222 if (
parse_block(namespace,
'AtomsMagnetDirection', blk) < 0)
then
1223 message(1) =
"AtomsMagnetDirection block is not defined."
1228 message(1) =
"The number of rows in the AtomsMagnetDirection block does not equal the number of atoms."
1238 safe_allocate(mag(1:m_dim, 1:ions%natoms))
1239 do ia = 1, ions%natoms
1243 if (abs(mag(idir, ia)) < tol_min_mag) mag(idir, ia) =
m_zero
1251 safe_allocate(atom_rho(1:gr%np, 1:st%d%spin_channels))
1252 select case (this%gmd_opt)
1253 case (initrho_paramagnetic)
1254 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1259 if (st%d%spin_channels == 2)
then
1262 rho(ip, 1) =
m_half*(rho(ip, 1) + rho(ip, 2))
1263 rho(ip, 2) = rho(ip, 1)
1268 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1270 rho(1:gr%np, 1:2) = rho(1:gr%np, 1:2) + atom_rho(1:gr%np, 1:2)
1274 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1289 call lalg_axpy(gr%np, (lmag - n1 + n2)/
m_two/n2, atom_rho(:, 2), atom_rho(:, 1))
1298 rho(1:gr%np, 1:2) = rho(1:gr%np, 1:2) + atom_rho(1:gr%np, 1:2)
1300 rho(1:gr%np, 1) = rho(1:gr%np, 1) + atom_rho(1:gr%np, 2)
1301 rho(1:gr%np, 2) = rho(1:gr%np, 2) + atom_rho(1:gr%np, 1)
1303 elseif (ispin ==
spinors)
then
1314 do ia = ions%atoms_dist%start, ions%atoms_dist%end
1322 lmag = norm2(mag(:, ia))
1323 if (lmag > n1 + n2)
then
1324 mag = mag*(n1 + n2)/lmag
1332 atom_rho(ip, 1) =
m_half*(atom_rho(ip, 1) + atom_rho(ip, 2))
1333 rho(ip, 1) = rho(ip, 1) + atom_rho(ip, 1)
1334 rho(ip, 2) = rho(ip, 2) + atom_rho(ip, 1)
1341 if (n1 - n2 < lmag)
then
1342 call lalg_axpy(gr%np, (lmag - n1 + n2)/
m_two/n2, atom_rho(:, 2), atom_rho(:, 1))
1344 elseif (n1 - n2 > lmag)
then
1345 call lalg_axpy(gr%np, (n1 - n2 - lmag)/
m_two/n1, atom_rho(:, 1), atom_rho(:, 2))
1353 if (mag(1, ia) >
m_zero)
then
1360 elseif (ispin ==
spinors)
then
1370 if (ions%atoms_dist%parallel)
then
1371 do is = 1, st%d%nspin
1372 call lalg_copy(gr%np, rho(:,is), atom_rho(:,1))
1373 call ions%atoms_dist%mpi_grp%allreduce(atom_rho(1, 1), rho(1, is), gr%np, mpi_double_precision, mpi_sum)
1379 write(
message(1),
'(a,f13.6)')
'Info: Unnormalized total charge = ', rr
1384 call lalg_scal(gr%np, st%d%nspin, qtot/rr, rho)
1386 write(
message(1),
'(a,f13.6)')
'Info: Renormalized total charge = ', rr
1391 if (st%symmetrize_density)
then
1392 do is = 1, st%d%nspin
1397 safe_deallocate_a(atom_rho)
1398 safe_deallocate_a(mag)
1404 real(real64) function integrated_charge_density(gr, st, rho) result(rr)
1405 type(
grid_t),
intent(in) :: gr
1407 real(real64),
intent(in) :: rho(:,:)
1412 do is = 1, st%d%spin_channels
1416 call gr%allreduce(rr)
1421 class(mesh_t),
intent(in) :: mesh
1422 real(real64),
intent(inout) :: rho(:,:)
1423 real(real64),
intent(in) :: atom_rho(:,:)
1424 real(real64),
intent(in) :: theta, phi
1427 real(real64) :: half_theta
1431 half_theta = m_half * theta
1435 rho(ip, 1) = rho(ip, 1) +
cos(half_theta)**2*atom_rho(ip, 1) +
sin(half_theta)**2*atom_rho(ip, 2)
1436 rho(ip, 2) = rho(ip, 2) +
sin(half_theta)**2*atom_rho(ip, 1) +
cos(half_theta)**2*atom_rho(ip, 2)
1437 rho(ip, 3) = rho(ip, 3) +
cos(half_theta)*
sin(half_theta)*
cos(phi)*(atom_rho(ip, 1)-atom_rho(ip, 2))
1438 rho(ip, 4) = rho(ip, 4) -
cos(half_theta)*
sin(half_theta)*
sin(phi)*(atom_rho(ip, 1)-atom_rho(ip, 2))
1447 type(
lcao_t),
intent(inout) :: this
1448 type(namespace_t),
intent(in) :: namespace
1449 type(states_elec_t),
intent(inout) :: st
1450 type(grid_t),
intent(in) :: gr
1451 type(ions_t),
intent(in) :: ions
1452 integer,
optional,
intent(in) :: start
1458 if (.not. this%alternative)
then
1459 if (states_are_real(st))
then
1465 if (states_are_real(st))
then
1478 real(real64),
intent(in) :: mag(:)
1479 real(real64),
intent(in) :: lmag
1480 real(real64),
intent(out) :: theta
1481 real(real64),
intent(out) :: phi
1485 assert(lmag > m_zero)
1487 theta =
acos(mag(3)/lmag)
1489 if (abs(mag(1)) <= m_epsilon)
then
1490 if (abs(mag(2)) <= m_epsilon)
then
1492 elseif (mag(2) < m_zero)
then
1493 phi = m_pi*m_three*m_half
1499 arg = mag(1)/
sin(theta)/lmag
1500 if (abs(arg) > m_one) arg = sign(m_one, arg)
1503 if (mag(2) < m_zero)
then
1504 phi = m_two*m_pi - phi
1518 type(states_elec_t),
intent(inout) :: st
1519 type(grid_t),
intent(in) :: gr
1520 integer,
intent(in) :: rel_type
1521 integer,
intent(in) :: ist_start
1522 integer,
intent(in) :: gmd_opt
1524 integer :: ik, ist, ip
1525 real(real64),
allocatable :: md(:,:), up(:)
1526 complex(real64),
allocatable :: down(:), psi(:,:)
1527 real(real64) :: lmag, theta, phi, norm, mm(3)
1529 if (st%d%ispin /= spinors)
return
1534 safe_allocate(psi(1:gr%np, 1:st%d%dim))
1536 select case (gmd_opt)
1539 do ik = st%d%kpt%start, st%d%kpt%end
1540 do ist = ist_start, st%st_end
1541 call states_elec_get_state(st, gr, ist, ik, psi)
1544 psi(ip, 1) = psi(ip, 1) + psi(ip, 2)
1545 psi(ip, 2) = psi(ip, 1)
1547 call zmf_normalize(gr, st%d%dim, psi)
1548 call states_elec_set_state(st, gr, ist, ik, psi)
1554 do ik = st%d%kpt%start, st%d%kpt%end
1555 do ist = ist_start, st%st_end
1556 call states_elec_get_state(st, gr, ist, ik, psi)
1559 psi(ip, 1) = psi(ip, 1) + psi(ip, 2)
1562 call zmf_normalize(gr, st%d%dim, psi)
1563 call states_elec_set_state(st, gr, ist, ik, psi)
1569 safe_allocate(md(1:gr%np, 1:3))
1570 safe_allocate(up(1:gr%np))
1571 safe_allocate(down(1:gr%np))
1572 call magnetic_density(gr, st%d, st%rho, md)
1574 mm(1) = dmf_integrate(gr, md(:, 1), reduce = .false.)
1575 mm(2) = dmf_integrate(gr, md(:, 2), reduce = .false.)
1576 mm(3) = dmf_integrate(gr, md(:, 3), reduce = .false.)
1578 if (gr%parallel_in_domains)
then
1579 call gr%allreduce(mm)
1585 if (lmag > 1.0e-2_real64)
then
1587 up(:) =
cos(theta/m_two)
1588 down(:) =
exp(-m_zi * phi) *
sin(theta/m_two)
1595 lmag = norm2(md(ip, 1:3))
1597 up(ip) =
cos(theta/m_two)
1598 down(ip) =
exp(-m_zi * phi) *
sin(theta/m_two)
1600 safe_deallocate_a(md)
1604 do ik = st%d%kpt%start, st%d%kpt%end
1605 do ist = ist_start, st%st_end
1606 call states_elec_get_state(st, gr, ist, ik, psi)
1607 call zmf_normalize(gr, st%d%dim, psi)
1610 norm =
sqrt(real(psi(ip, 1)*conjg(psi(ip, 1)) + psi(ip, 2)*conjg(psi(ip, 2))))
1611 psi(ip, 1) = norm * up(ip)
1612 psi(ip, 2) = norm * down(ip)
1614 call states_elec_set_state(st, gr, ist, ik, psi)
1617 safe_deallocate_a(up)
1618 safe_deallocate_a(down)
1621 safe_deallocate_a(psi)
1628#include "lcao_inc.F90"
1631#include "complex.F90"
1632#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 sqrt(double __x) __attribute__((__nothrow__
double cos(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
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_half
real(real64), parameter, public m_one
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.
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.
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, public lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r)
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 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 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.
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)
integer function, public lcao_num_orbitals(this)
Returns the number of LCAO orbitas.
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)
real(real64) function integrated_charge_density(gr, st, rho)
Computes the integral of rho, summed over spin channels.
integer, parameter initrho_paramagnetic
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.
subroutine, public write_magnetic_moments(mesh, st, ions, boundaries, lmm_r, iunit, namespace)
This module is intended to contain "only mathematical" functions and procedures.
This module defines various routines, operating on mesh functions.
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)
type(mpi_grp_t), public mpi_world
logical function, public parse_is_defined(namespace, name)
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)
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.
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)
subroutine, public v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
logical pure function, public xc_is_orbital_dependent(xcs)
Is the xc family orbital dependent.
integer, parameter, public sic_pz_oep
Perdew-Zunger SIC (OEP way)
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.