65 subroutine unocc_run(system, from_scratch)
66 class(*),
intent(inout) :: system
67 logical,
intent(in) :: from_scratch
73 message(1) =
"CalculationMode = unocc not implemented for multi-system calculations"
84 type(electrons_t),
intent(inout) :: sys
85 logical,
intent(in) :: fromscratch
87 type(eigensolver_t) :: eigens
88 integer :: iunit, ierr, iter, ierr_rho, ik
89 integer(int64) :: what_it
90 logical :: read_gs, converged, forced_finish, showoccstates, is_orbital_dependent, occ_missing
91 integer :: max_iter, nst_calculated, showstart
92 integer :: n_filled, n_partially_filled, n_half_filled
93 integer,
allocatable :: lowest_missing(:, :), occ_states(:)
94 character(len=10) :: dirname
95 type(restart_t) :: restart_load_unocc, restart_load_gs, restart_dump
96 logical :: write_density, bandstructure_mode, read_td_states, output_iter
97 type(current_t) :: current_calculator
101 if (sys%hm%pcm%run_pcm)
then
108 if (max_iter < 0) max_iter = huge(max_iter)
119 call parse_variable(sys%namespace,
'UnoccShowOccStates', .false., showoccstates)
121 bandstructure_mode = .false.
122 if (sys%space%is_periodic() .and. sys%kpoints%get_kpoint_method() ==
kpoints_path)
then
123 bandstructure_mode = .
true.
126 call init_(sys%gr, sys%st)
129 read_td_states = .false.
130 if (bandstructure_mode)
then
139 call parse_variable(sys%namespace,
'UnoccUseTD', .false., read_td_states)
143 safe_allocate(lowest_missing(1:sys%st%d%dim, 1:sys%st%nik))
146 lowest_missing(:,:) = 0
149 if (.not. fromscratch)
then
151 mesh = sys%gr, exact = .
true.)
154 call states_elec_load(restart_load_unocc, sys%namespace, sys%space, sys%st, sys%gr, sys%kpoints, &
155 ierr, lowest_missing = lowest_missing)
165 if (read_td_states)
then
173 if (ierr_rho == 0)
then
175 call states_elec_load(restart_load_gs, sys%namespace, sys%space, sys%st, sys%gr, sys%kpoints, &
176 ierr, lowest_missing = lowest_missing)
179 call lda_u_load(restart_load_gs, sys%hm%lda_u, sys%st, sys%hm%energy%dft_u, ierr)
181 message(1) =
"Unable to read DFT+U information. DFT+U data will be calculated from states."
190 write_density = .
true.
193 safe_allocate(occ_states(1:sys%st%nik))
194 do ik = 1, sys%st%nik
195 call occupied_states(sys%st, sys%namespace, ik, n_filled, n_partially_filled, n_half_filled)
196 occ_states(ik) = n_filled + n_partially_filled + n_half_filled
199 is_orbital_dependent = (sys%ks%theory_level ==
hartree .or. sys%ks%theory_level ==
hartree_fock .or. &
200 (sys%ks%theory_level ==
kohn_sham_dft .and. xc_is_orbital_dependent(sys%ks%xc)) &
203 if (is_orbital_dependent)
then
204 message(1) =
"Be sure your gs run is well converged since you have an orbital-dependent functional."
205 message(2) =
"Otherwise, the occupied states may change in CalculationMode = unocc, and your"
206 message(3) =
"unoccupied states will not be consistent with the gs run."
210 if (ierr_rho /= 0 .or. is_orbital_dependent)
then
211 occ_missing = .false.
212 do ik = 1, sys%st%nik
213 if (any(lowest_missing(1:sys%st%d%dim, ik) <= occ_states(ik)))
then
218 if (occ_missing)
then
219 if (is_orbital_dependent)
then
220 message(1) =
"For an orbital-dependent functional, all occupied orbitals must be provided."
221 else if (ierr_rho /= 0)
then
222 message(1) =
"Since density could not be read, all occupied orbitals must be provided."
225 message(2) =
"Not all the occupied orbitals could be read."
226 message(3) =
"Please run a ground-state calculation first!"
230 message(1) =
"Unable to read density: Building density from wavefunctions."
238 if (fromscratch .or. ierr /= 0)
then
239 if (fromscratch)
then
241 nst_calculated = min(maxval(occ_states), minval(lowest_missing) - 1)
244 nst_calculated = minval(lowest_missing) - 1
246 showstart = max(nst_calculated + 1, 1)
247 call lcao_run(sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st, sys%ks, &
248 sys%hm, st_start = showstart)
251 call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, sys%st, sys%ions, sys%ext_partners, &
252 calc_eigenval = .false.)
253 showstart = minval(occ_states(:)) + 1
260 if (showstart > sys%st%nst) showstart = 1
262 safe_deallocate_a(lowest_missing)
264 if (showoccstates) showstart = 1
268 if (bandstructure_mode)
then
269 message(1) =
"Info: The code will run in band structure mode."
270 message(2) =
" No restart information will be printed."
274 if (.not. bandstructure_mode)
then
279 if (write_density)
then
284 message(1) =
"Info: Starting calculation of unoccupied states."
288 eigens%converged(:) = 0
299 if (sys%st%pack_states .and. sys%hm%apply_packed())
call sys%st%pack()
301 do iter = 1, max_iter
302 output_iter = .false.
303 call eigens%run(sys%namespace, sys%gr, sys%st, sys%hm, 1, converged, sys%st%nst_conv)
318 write(iunit,
'(a)')
'All states converged.'
320 write(iunit,
'(a)')
'Some of the states are not fully converged!'
322 write(iunit,
'(a, e17.6)')
'Criterion = ', eigens%tolerance
328 forced_finish =
clean_stop(sys%mc%master_comm)
330 if (.not. bandstructure_mode)
then
332 if (converged .or. (modulo(iter, sys%outp%restart_write_interval) == 0) &
333 .or. iter == max_iter .or. forced_finish)
then
334 call states_elec_dump(restart_dump, sys%space, sys%st, sys%gr, sys%kpoints, ierr, iter=iter)
336 message(1) =
"Unable to write states wavefunctions."
342 do what_it = lbound(sys%outp%output_interval, 1), ubound(sys%outp%output_interval, 1)
343 if (sys%outp%what_now(what_it, iter))
then
349 if (output_iter .and. sys%outp%duringscf)
then
350 write(dirname,
'(a,i4.4)')
"unocc.",iter
353 call current_calculate(current_calculator, sys%namespace, sys%gr, sys%hm, sys%space, sys%st)
355 call output_all(sys%outp, sys%namespace, sys%space, dirname, sys%gr, sys%ions, iter, sys%st, sys%hm, sys%ks)
356 call output_modelmb(sys%outp, sys%namespace, sys%space, dirname, sys%gr, sys%ions, iter, sys%st)
359 if (converged .or. forced_finish)
exit
363 if (.not. bandstructure_mode)
call restart_end(restart_dump)
365 if (sys%st%pack_states .and. sys%hm%apply_packed())
then
369 if (any(eigens%converged(:) < occ_states(:)))
then
370 write(
message(1),
'(a)')
'Some of the occupied states are not fully converged!'
374 safe_deallocate_a(occ_states)
376 if (.not. converged)
then
377 write(
message(1),
'(a)')
'Some of the unoccupied states are not fully converged!'
381 if (sys%space%is_periodic().and. sys%st%nik > sys%st%d%nspin)
then
384 sys%ions, sys%gr, sys%kpoints, &
385 sys%hm%phase, vec_pot = sys%hm%hm_base%uniform_vector_potential, &
386 vec_pot_var = sys%hm%hm_base%vector_potential)
392 call current_calculate(current_calculator, sys%namespace, sys%gr, sys%hm, sys%space, sys%st)
394 call output_all(sys%outp, sys%namespace, sys%space,
static_dir, sys%gr, sys%ions, -1, sys%st, sys%hm, sys%ks)
403 subroutine init_(mesh, st)
404 class(
mesh_t),
intent(in) :: mesh
417 message(1) =
"With the RMMDIIS eigensolver for unocc, you will need to stop the calculation"
418 message(2) =
"by hand, since the highest states will probably never converge."
440 character(len=50) :: str
444 write(str,
'(a,i5)')
'Unoccupied states iteration #', iter
447 write(
message(1),
'(a,i6,a,i6)')
'Converged states: ', minval(eigens%converged(1:st%nik))
451 eigens%diff, st_start = showstart, compact = .
true., namespace=sys%namespace)
subroutine init_(fromscratch)
subroutine, public current_calculate(this, namespace, gr, hm, space, st)
Compute total electronic current density.
subroutine, public current_init(this, namespace)
This module implements a calculator for the density and defines related functions.
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
subroutine, public eigensolver_init(eigens, namespace, gr, st, mc, space)
subroutine, public eigensolver_end(eigens)
integer, parameter, public rs_rmmdiis
character(len= *), parameter, public static_dir
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)
integer, parameter, public kpoints_path
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
subroutine, public lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r)
subroutine, public lda_u_load(restart, this, st, dftu_energy, ierr, occ_only, u_only)
integer, parameter, public dft_u_none
This module defines the meshes, which are used in Octopus.
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
subroutine, public messages_not_implemented(feature, namespace)
character(len=512), private msg
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_obsolete_variable(namespace, name, rep)
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_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
type(mpi_grp_t), public mpi_world
This module implements the basic mulsisystem class, a container system for other systems.
subroutine, public output_modelmb(outp, namespace, space, dir, gr, ions, iter, st)
this module contains the output system
logical function, public output_needs_current(outp, states_are_real)
subroutine, public output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
logical function, public clean_stop(comm)
returns true if a file named stop exists
integer, parameter, public restart_gs
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
integer, parameter, public restart_type_dump
logical pure function, public restart_has_map(restart)
Returns true if the restart was from a different order of mesh points.
integer, parameter, public restart_td
integer, parameter, public restart_type_load
integer, parameter, public restart_unocc
logical pure function, public restart_are_basedirs_equal(type1, type2)
Returns true if...
subroutine, public restart_end(restart)
subroutine, public scf_state_info(namespace, st)
subroutine, public scf_print_mem_use(namespace)
pure logical function, public states_are_real(st)
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_write_bandstructure(dir, namespace, nst, st, ions, mesh, kpoints, phase, vec_pot, vec_pot_var)
calculate and write the bandstructure
subroutine, public states_elec_fermi(st, namespace, mesh, compute_spin)
calculate the Fermi level for the states in this object
subroutine, public states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
Allocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public occupied_states(st, namespace, ik, n_filled, n_partially_filled, n_half_filled, filled, partially_filled, half_filled)
return information about occupied orbitals in many-body state
subroutine, public states_elec_allocate_current(st, space, mesh)
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_dump(restart, space, st, mesh, kpoints, ierr, iter, lr, st_start_writing, verbose)
subroutine, public states_elec_load(restart, namespace, space, st, mesh, kpoints, ierr, iter, lr, lowest_missing, label, verbose, skip)
returns in ierr: <0 => Fatal error, or nothing read =0 => read all wavefunctions >0 => could only rea...
subroutine, public states_elec_load_rho(restart, space, st, mesh, ierr)
subroutine, public states_elec_dump_rho(restart, space, st, mesh, ierr, iter)
subroutine, public unocc_run(system, from_scratch)
subroutine unocc_run_legacy(sys, fromscratch)
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
Class describing the electron system.
Describes mesh distribution to nodes.
Container class for lists of system_oct_m::system_t.
The states_elec_t class contains all electronic wave functions.
subroutine write_iter_(namespace, st)