66  subroutine unocc_run(system, from_scratch)
 
   67    class(*),        
intent(inout) :: system
 
   68    logical,         
intent(in)    :: from_scratch
 
   74      message(1) = 
"CalculationMode = unocc not implemented for multi-system calculations" 
   85    type(electrons_t),    
intent(inout) :: sys
 
   86    logical,              
intent(in)    :: fromscratch
 
   88    type(eigensolver_t) :: eigens
 
   89    integer :: iunit, ierr, iter, ierr_rho, ik
 
   90    integer(int64) :: what_it
 
   91    logical :: read_gs, converged, forced_finish, showoccstates, is_orbital_dependent, occ_missing
 
   92    integer :: max_iter, nst_calculated, showstart
 
   93    integer :: n_filled, n_partially_filled, n_half_filled
 
   94    integer, 
allocatable :: lowest_missing(:, :), occ_states(:)
 
   95    character(len=10) :: dirname
 
   96    type(restart_t) :: restart_load_unocc, restart_load_gs, restart_dump
 
   97    logical :: write_density, bandstructure_mode, read_td_states, output_iter
 
   98    type(current_t) :: current_calculator
 
  102    if (sys%hm%pcm%run_pcm) 
then 
  109    if (max_iter < 0) max_iter = huge(max_iter)
 
  120    call parse_variable(sys%namespace, 
'UnoccShowOccStates', .false., showoccstates)
 
  122    bandstructure_mode = .false.
 
  123    if (sys%space%is_periodic() .and. sys%kpoints%get_kpoint_method() == 
kpoints_path) 
then 
  124      bandstructure_mode = .
true.
 
  127    call init_(sys%gr, sys%st)
 
  130    read_td_states = .false.
 
  131    if (bandstructure_mode) 
then 
  140      call parse_variable(sys%namespace, 
'UnoccUseTD', .false., read_td_states)
 
  144    safe_allocate(lowest_missing(1:sys%st%d%dim, 1:sys%st%nik))
 
  147    lowest_missing(:,:) = 0
 
  150    if (.not. fromscratch) 
then 
  152        mesh = sys%gr, exact = .
true.)
 
  155        call states_elec_load(restart_load_unocc, sys%namespace, sys%space, sys%st, sys%gr, sys%kpoints, &
 
  156          ierr, lowest_missing = lowest_missing)
 
  157        call restart_load_unocc%end()
 
  163      if (ierr == 0 .or. restart_load_gs%basedir == restart_load_unocc%basedir) read_gs = .false.
 
  166    if (read_td_states) 
then 
  174    if (ierr_rho == 0) 
then 
  176        call states_elec_load(restart_load_gs, sys%namespace, sys%space, sys%st, sys%gr, sys%kpoints, &
 
  177          ierr, lowest_missing = lowest_missing)
 
  180        call lda_u_load(restart_load_gs, sys%hm%lda_u, sys%st, sys%hm%energy%dft_u, ierr)
 
  182          message(1) = 
"Unable to read DFT+U information. DFT+U data will be calculated from states." 
  188      write_density = restart_load_gs%has_map()
 
  189      call restart_load_gs%end()
 
  191      write_density = .
true.
 
  194    safe_allocate(occ_states(1:sys%st%nik))
 
  195    do ik = 1, sys%st%nik
 
  196      call occupied_states(sys%st, sys%namespace, ik, n_filled, n_partially_filled, n_half_filled)
 
  197      occ_states(ik) = n_filled + n_partially_filled + n_half_filled
 
  200    is_orbital_dependent = (sys%ks%theory_level == 
hartree .or. sys%ks%theory_level == 
hartree_fock .or. &
 
  204    if (is_orbital_dependent) 
then 
  205      message(1) = 
"Be sure your gs run is well converged since you have an orbital-dependent functional." 
  206      message(2) = 
"Otherwise, the occupied states may change in CalculationMode = unocc, and your" 
  207      message(3) = 
"unoccupied states will not be consistent with the gs run." 
  211    if (ierr_rho /= 0 .or. is_orbital_dependent) 
then 
  212      occ_missing = .false.
 
  213      do ik = 1, sys%st%nik
 
  214        if (any(lowest_missing(1:sys%st%d%dim, ik) <= occ_states(ik))) 
then 
  219      if (occ_missing) 
then 
  220        if (is_orbital_dependent) 
then 
  221          message(1) = 
"For an orbital-dependent functional, all occupied orbitals must be provided." 
  222        else if (ierr_rho /= 0) 
then 
  223          message(1) = 
"Since density could not be read, all occupied orbitals must be provided." 
  226        message(2) = 
"Not all the occupied orbitals could be read." 
  227        message(3) = 
"Please run a ground-state calculation first!" 
  231      message(1) = 
"Unable to read density: Building density from wavefunctions." 
  239    if (fromscratch .or. ierr /= 0) 
then 
  240      if (fromscratch) 
then 
  242        nst_calculated = min(maxval(occ_states), minval(lowest_missing) - 1)
 
  245        nst_calculated = minval(lowest_missing) - 1
 
  247      showstart = max(nst_calculated + 1, 1)
 
  248      call lcao_run(sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st, sys%ks, &
 
  249        sys%hm, st_start = showstart)
 
  252      call v_ks_calc(sys%ks, sys%namespace, sys%space, sys%hm, sys%st, sys%ions, sys%ext_partners, &
 
  253        calc_eigenval = .false.)
 
  254      showstart = minval(occ_states(:)) + 1
 
  261    if (showstart > sys%st%nst) showstart = 1
 
  263    safe_deallocate_a(lowest_missing)
 
  265    if (showoccstates) showstart = 1
 
  269    if (bandstructure_mode) 
then 
  270      message(1) = 
"Info: The code will run in band structure mode." 
  271      message(2) = 
"      No restart information will be printed." 
  275    if (.not. bandstructure_mode) 
then 
  280      if (write_density) 
then 
  285    message(1) = 
"Info: Starting calculation of unoccupied states." 
  289    eigens%converged(:) = 0
 
  300    if (sys%st%pack_states .and. sys%hm%apply_packed()) 
call sys%st%pack()
 
  302    do iter = 1, max_iter
 
  303      output_iter = .false.
 
  304      call eigens%run(sys%namespace, sys%gr, sys%st, sys%hm, sys%space, sys%ext_partners, 1, converged, sys%st%nst_conv)
 
  319          write(iunit,
'(a)') 
'All states converged.' 
  321          write(iunit,
'(a)') 
'Some of the states are not fully converged!' 
  323        write(iunit,
'(a, e17.6)') 
'Criterion = ', eigens%tolerance
 
  329      forced_finish = 
clean_stop(sys%mc%master_comm)
 
  331      if (.not. bandstructure_mode) 
then 
  334          .or. iter == max_iter .or. forced_finish) 
then 
  335          call states_elec_dump(restart_dump, sys%space, sys%st, sys%gr, sys%kpoints, ierr, iter=iter)
 
  337            message(1) = 
"Unable to write states wavefunctions." 
  343      do what_it = lbound(sys%outp%output_interval, 1), ubound(sys%outp%output_interval, 1)
 
  344        if (sys%outp%what_now(what_it, iter)) 
then 
  350      if (output_iter .and. sys%outp%duringscf) 
then 
  351        write(dirname,
'(a,i4.4)') 
"unocc.",iter
 
  354          call current_calculate(current_calculator, sys%namespace, sys%gr, sys%hm, sys%space, sys%st)
 
  356        call output_all(sys%outp, sys%namespace, sys%space, dirname, sys%gr, sys%ions, iter, sys%st, sys%hm, sys%ks)
 
  357        call output_modelmb(sys%outp, sys%namespace, sys%space, dirname, sys%gr, sys%ions, iter, sys%st)
 
  360      if (converged .or. forced_finish) 
exit 
  364    if (.not. bandstructure_mode) 
call restart_dump%end()
 
  366    if (sys%st%pack_states .and. sys%hm%apply_packed()) 
then 
  370    if (any(eigens%converged(:) < occ_states(:))) 
then 
  371      write(
message(1),
'(a)') 
'Some of the occupied states are not fully converged!' 
  375    safe_deallocate_a(occ_states)
 
  377    if (.not. converged) 
then 
  378      write(
message(1),
'(a)') 
'Some of the unoccupied states are not fully converged!' 
  382    if (sys%space%is_periodic().and. sys%st%nik > sys%st%d%nspin) 
then 
  385          sys%ions, sys%gr, sys%kpoints, &
 
  386          sys%hm%phase, vec_pot = sys%hm%hm_base%uniform_vector_potential, &
 
  387          vec_pot_var = sys%hm%hm_base%vector_potential)
 
  393      call current_calculate(current_calculator, sys%namespace, sys%gr, sys%hm, sys%space, sys%st)
 
  395    call output_all(sys%outp, sys%namespace, sys%space, 
static_dir, sys%gr, sys%ions, -1, sys%st, sys%hm, sys%ks)
 
  404    subroutine init_(mesh, st)
 
  405      class(
mesh_t),       
intent(in)    :: mesh
 
  415      call eigensolver_init(eigens, sys%namespace, sys%gr, st, sys%hm, sys%mc, sys%space, deactivate_oracle=.
true.)
 
  418        message(1) = 
"With the RMMDIIS eigensolver for unocc, you will need to stop the calculation" 
  419        message(2) = 
"by hand, since the highest states will probably never converge." 
  441      character(len=50) :: str
 
  445      write(str, 
'(a,i5)') 
'Unoccupied states iteration #', iter
 
  448      write(
message(1),
'(a,i6,a,i6)') 
'Converged eigenvectors: ', minval(eigens%converged(1:st%nik))
 
  452        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, hm, mc, space, deactivate_oracle)
 
subroutine, public eigensolver_end(eigens)
 
integer, parameter, public rs_rmmdiis
 
integer, parameter, public hartree_fock
 
integer, parameter, public generalized_kohn_sham_dft
 
integer, parameter, public kohn_sham_dft
 
character(len= *), parameter, public static_dir
 
integer, parameter, public hartree
 
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.
 
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)
 
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
 
integer, parameter, public restart_type_dump
 
integer, parameter, public restart_td
 
integer, parameter, public restart_type_load
 
integer, parameter, public restart_unocc
 
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, 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, st, mesh, ierr)
 
subroutine, public states_elec_dump_rho(restart, 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)
 
This module provices a simple timer class which can be used to trigger the writing of a restart file ...
 
logical function, public restart_walltime_period_alarm(comm)
 
logical pure function, public xc_is_orbital_dependent(xcs)
Is the xc family orbital dependent.
 
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)