34  use, 
intrinsic :: iso_fortran_env
 
   80  integer, 
parameter ::             &
 
   81    PERTURBATION_ELECTRIC         = 1,  &
 
   88    class(perturbation_t), 
pointer :: perturbation
 
   98    real(real64) :: freq_factor(3)
 
   99    real(real64),      
allocatable :: omega(:)
 
  100    type(lr_t), 
allocatable :: lr(:,:,:)
 
  101    complex(real64),      
allocatable :: alpha_k(:, :, :, :)
 
  103    complex(real64),      
allocatable :: alpha_be_k(:, :, :, :)
 
  105    logical :: calc_hyperpol
 
  106    complex(real64)   :: alpha(3, 3, 3)
 
  107    complex(real64)   :: alpha_be(3, 3, 3)
 
  108    complex(real64)   :: alpha0(3, 3, 3)
 
  110    complex(real64)   :: alpha_be0(3, 3, 3)
 
  112    complex(real64)   :: beta (3, 3, 3)
 
  114    complex(real64)   :: chi_para(3, 3)
 
  115    complex(real64)   :: chi_dia (3, 3)
 
  116    complex(real64)   :: magn(3)
 
  119    logical :: force_no_kdotp
 
  121    logical :: calc_rotatory
 
  123    type(Born_charges_t) :: Born_charges(3)
 
  124    logical :: occ_response
 
  125    logical :: wfns_from_scratch
 
  126    logical :: calc_magnetooptics
 
  127    logical :: magnetooptics_nohvar
 
  129    logical :: kpt_output
 
  131    logical :: lrc_kernel
 
  139    class(*),        
intent(inout) :: system
 
  140    logical,         
intent(in)    :: from_scratch
 
  146      message(1) = 
"CalculationMode = em_resp not implemented for multi-system calculations" 
  157    type(electrons_t), 
intent(inout) :: sys
 
  158    logical,           
intent(in)    :: fromScratch
 
  160    type(em_resp_t)         :: em_vars
 
  161    type(sternheimer_t)     :: sh, sh_kdotp, sh2, sh_kmo, sh_mo
 
  162    type(lr_t)              :: kdotp_lr(sys%space%dim, 1)
 
  163    type(lr_t), 
allocatable :: kdotp_em_lr2(:, :, :, :)
 
  164    type(lr_t), 
allocatable :: b_lr(:, :)
 
  165    type(lr_t), 
allocatable :: kb_lr(:, :, :), k2_lr(:, :, :)
 
  166    type(lr_t), 
allocatable :: ke_lr(:, :, :, :)
 
  167    class(perturbation_t), 
pointer :: pert_kdotp, pert2_none, pert_b
 
  169    integer :: sigma, idir, idir2, ierr, iomega, ifactor
 
  170    integer :: ierr_e(3), ierr_e2(3), nfactor_ke
 
  171    character(len=100) :: str_tmp
 
  172    logical :: complex_response, have_to_calculate, use_kdotp, opp_freq, &
 
  173      exact_freq(3), complex_wfs, allocate_rho_em, allocate_rho_mo
 
  174    logical :: magnetic_pert
 
  176    real(real64) :: last_omega, frequency, dfrequency_eta
 
  177    real(real64), 
allocatable :: dl_eig(:,:,:)
 
  178    complex(real64) :: zfrequency_eta, lrc_coef(sys%space%dim, sys%space%dim)
 
  179    type(
restart_t) :: gs_restart, kdotp_restart
 
  183    if (sys%hm%pcm%run_pcm) 
then 
  187    if (sys%kpoints%use_symmetries) 
then 
  191    if (sys%kpoints%reduced%npoints /= sys%kpoints%full%npoints) 
then 
  197    select type(ptr=>em_vars%perturbation)
 
  199      if (any(abs(em_vars%omega(1:em_vars%nomega)) > 
m_epsilon)) 
then 
  204    em_vars%lrc_kernel = .false.
 
  212        is_complex = complex_response)
 
  213      call gs_restart%end()
 
  215      message(1) = 
"Previous gs calculation is required." 
  224      message(1) = 
'Info: Using real wavefunctions.' 
  226      message(1) = 
'Info: Using complex wavefunctions.' 
  231    message(1) = 
'Info: Setting up Hamiltonian for linear response' 
  233    call v_ks_h_setup(sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st, sys%ks, sys%hm)
 
  235    use_kdotp = sys%space%is_periodic() .and. .not. em_vars%force_no_kdotp
 
  239      message(1) = 
"em_resp with kdotp can only be used with semiconducting smearing" 
  245      message(1) = 
"Reading kdotp wavefunctions for periodic directions." 
  250        message(1) = 
"Unable to read kdotp wavefunctions." 
  251        message(2) = 
"Previous kdotp calculation required." 
  255      do idir = 1, sys%space%periodic_dim
 
  256        call lr_init(kdotp_lr(idir, 1))
 
  257        call lr_allocate(kdotp_lr(idir, 1), sys%st, sys%gr, allocate_rho = .false.)
 
  262        call kdotp_restart%open_dir(
wfs_tag_sigma(sys%namespace, str_tmp, 1), ierr)
 
  264          call states_elec_load(kdotp_restart, sys%namespace, sys%space, sys%st, sys%gr, sys%kpoints, ierr, &
 
  265            lr=kdotp_lr(idir, 1))
 
  267        call kdotp_restart%close_dir()
 
  270          message(1) = 
"Could not load kdotp wavefunctions from '"//trim(
wfs_tag_sigma(sys%namespace, str_tmp, 1))//
"'" 
  271          message(2) = 
"Previous kdotp calculation required." 
  276      call kdotp_restart%end()
 
  280    if (em_vars%calc_hyperpol) em_vars%nfactor = 3
 
  283    if (em_vars%calc_hyperpol .or. any(abs(em_vars%omega(1:em_vars%nomega)) > 
m_epsilon)) 
then 
  291    if (em_vars%calc_hyperpol .and. use_kdotp) 
then 
  295      call pert2_none%setup_dir(1)  
 
  296      safe_allocate(kdotp_em_lr2(1:sys%space%periodic_dim, 1:sys%space%dim, 1:em_vars%nsigma, 1:em_vars%nfactor))
 
  297      do ifactor = 1, em_vars%nfactor
 
  298        do sigma = 1, em_vars%nsigma
 
  299          do idir = 1, sys%space%periodic_dim
 
  300            do idir2 = 1, sys%space%dim
 
  301              call lr_init(kdotp_em_lr2(idir, idir2, sigma, ifactor))
 
  302              call lr_allocate(kdotp_em_lr2(idir, idir2, sigma, ifactor), sys%st, sys%gr, allocate_rho = .false.)
 
  307      call sternheimer_init(sh2, sys%namespace, sys%space, sys%gr, sys%st, sys%hm, sys%ks, sys%mc, &
 
  308        complex_response, set_ham_var = 0, set_last_occ_response = .false.)
 
  309      call sternheimer_init(sh_kdotp, sys%namespace, sys%space, sys%gr, sys%st, sys%hm, sys%ks, sys%mc, &
 
  310        complex_response, set_ham_var = 0, set_last_occ_response = .
true.)
 
  311      em_vars%occ_response = .
true.
 
  312      safe_allocate(dl_eig(1:sys%st%nst, 1:sys%st%nik, 1:sys%space%periodic_dim))
 
  317    if (em_vars%calc_magnetooptics) 
then 
  318      if (em_vars%calc_hyperpol .and. use_kdotp) 
then 
  319        message(1) = 
"Hyperpolarizability and magnetooptics with kdotp are not compatible." 
  320        message(2) = 
"Only calculation of hyperpolarizability will be performed." 
  322        em_vars%calc_magnetooptics = .false.
 
  325        em_vars%freq_factor(1) = 
m_one 
  326        em_vars%freq_factor(2) = -
m_one 
  330    magnetic_pert = .false.
 
  331    select type(ptr => em_vars%perturbation)
 
  334      if (use_kdotp) 
call messages_experimental(
"Magnetic perturbation for periodic systems", namespace=sys%namespace)
 
  335      magnetic_pert = .
true.
 
  338    if (em_vars%calc_magnetooptics .or. magnetic_pert) 
then 
  339      em_vars%occ_response = .false.
 
  343        call pert2_none%setup_dir(1)
 
  345        safe_allocate(k2_lr(1:sys%space%dim, 1:sys%space%dim, 1))
 
  346        safe_allocate(kb_lr(1:sys%space%dim, 1:sys%space%dim, 1))
 
  347        do idir = 1, sys%space%dim
 
  348          do idir2 = 1, sys%space%dim
 
  349            call lr_init(kb_lr(idir, idir2, 1))
 
  350            call lr_allocate(kb_lr(idir, idir2, 1), sys%st, sys%gr, allocate_rho = .false.)
 
  351            if (idir2 <= idir) 
then 
  352              call lr_init(k2_lr(idir, idir2, 1))
 
  353              call lr_allocate(k2_lr(idir, idir2, 1), sys%st, sys%gr, allocate_rho = .false.)
 
  358        if (sys%space%periodic_dim < sys%space%dim) 
then 
  359          if (magnetic_pert) 
then 
  360            message(1) = 
"All directions should be periodic for magnetic perturbations with kdotp." 
  362            message(1) = 
"All directions should be periodic for magnetooptics with kdotp." 
  366        if (.not. complex_response) 
then 
  367          do idir = 1, sys%space%dim
 
  371          do idir = 1, sys%space%dim
 
  375        call sternheimer_init(sh_kmo, sys%namespace, sys%space, sys%gr, sys%st, sys%hm, sys%ks, sys%mc, &
 
  376          complex_response, set_ham_var = 0, set_last_occ_response = em_vars%occ_response)
 
  380    safe_allocate(em_vars%lr(1:sys%space%dim, 1:em_vars%nsigma, 1:em_vars%nfactor))
 
  381    do ifactor = 1, em_vars%nfactor
 
  382      call born_charges_init(em_vars%Born_charges(ifactor), sys%namespace, sys%ions%natoms, &
 
  383        sys%st%val_charge, sys%st%qtot, sys%space%dim)
 
  386    if (magnetic_pert .and. sys%st%d%nspin == 1 .and. 
states_are_real(sys%st)) 
then 
  388      call sternheimer_init(sh, sys%namespace, sys%space, sys%gr, sys%st, sys%hm, sys%ks, sys%mc, &
 
  389        complex_response, set_ham_var = 0, set_last_occ_response = em_vars%occ_response)
 
  392      call sternheimer_init(sh, sys%namespace, sys%space, sys%gr, sys%st, sys%hm, sys%ks, sys%mc, &
 
  393        complex_response, set_last_occ_response = em_vars%occ_response)
 
  397    if (em_vars%lrc_kernel .and. (.not. sh%add_hartree()) &
 
  398      .and. (.not. sh%add_fxc())) 
then 
  399      message(1) = 
"Only the G = G'= 0 term of the LRC kernel is taken into account." 
  409    allocate_rho_em = sh%add_fxc() .or. sh%add_hartree()
 
  410    do ifactor = 1, em_vars%nfactor
 
  411      do idir = 1, sys%space%dim
 
  412        do sigma = 1, em_vars%nsigma
 
  413          call lr_init(em_vars%lr(idir, sigma, ifactor))
 
  414          call lr_allocate(em_vars%lr(idir, sigma, ifactor), sys%st, sys%gr, allocate_rho = allocate_rho_em)
 
  419    select type(ptr=> em_vars%perturbation)
 
  423      em_vars%kpt_output = .false.
 
  425    if (.not. use_kdotp .or. sys%st%nik == 1) em_vars%kpt_output = .false.
 
  427    if (em_vars%kpt_output) 
then 
  428      safe_allocate(em_vars%alpha_k(1:sys%space%dim, 1:sys%space%dim, 1:em_vars%nfactor, 1:sys%st%nik))
 
  431    if (em_vars%calc_magnetooptics) 
then 
  432      if (em_vars%magnetooptics_nohvar) 
then 
  433        call sternheimer_init(sh_mo, sys%namespace, sys%space, sys%gr, sys%st, sys%hm, sys%ks, sys%mc, &
 
  434          complex_response, set_ham_var = 0, set_last_occ_response = em_vars%occ_response)
 
  436        call sternheimer_init(sh_mo, sys%namespace, sys%space, sys%gr, sys%st, sys%hm, sys%ks, sys%mc, &
 
  437          complex_response, set_last_occ_response = em_vars%occ_response)
 
  441      allocate_rho_mo = sh_mo%add_fxc() .or. sh_mo%add_hartree()
 
  442      safe_allocate(b_lr(1:sys%space%dim, 1))
 
  443      do idir = 1, sys%space%dim
 
  445        call lr_allocate(b_lr(idir, 1), sys%st, sys%gr, allocate_rho = allocate_rho_mo)
 
  449        if (em_vars%kpt_output) 
then 
  450          safe_allocate(em_vars%alpha_be_k(1:sys%space%dim, 1:sys%space%dim, 1:sys%space%dim, 1:sys%st%nik))
 
  453        if (sys%kpoints%use_time_reversal .and. sys%kpoints%full%npoints > 1) nfactor_ke = em_vars%nfactor
 
  454        safe_allocate(ke_lr(1:sys%space%dim, 1:sys%space%dim, 1:em_vars%nsigma, 1:nfactor_ke))
 
  455        do idir = 1, sys%space%dim
 
  456          do idir2 = 1, sys%space%dim
 
  457            do sigma = 1, em_vars%nsigma
 
  458              do ifactor = 1, nfactor_ke
 
  459                call lr_init(ke_lr(idir, idir2, sigma, ifactor))
 
  460                call lr_allocate(ke_lr(idir, idir2, sigma, ifactor), sys%st, sys%gr, allocate_rho = .false.)
 
  472    do iomega = 1, em_vars%nomega
 
  474      em_vars%ok(1:3) = .
true.
 
  476      do ifactor = 1, em_vars%nfactor
 
  477        frequency = em_vars%freq_factor(ifactor)*em_vars%omega(iomega)
 
  478        zfrequency_eta = cmplx(frequency, em_vars%eta, real64)
 
  479        if (em_vars%calc_magnetooptics .and. ifactor == 2) zfrequency_eta = frequency - 
m_zi * em_vars%eta
 
  480        dfrequency_eta = real(zfrequency_eta, real64)
 
  482        if (abs(frequency) < 
m_epsilon .and. em_vars%calc_magnetooptics .and. use_kdotp) 
then 
  483          message(1) = 
"Magnetooptical response with kdotp requires non-zero frequency." 
  491        have_to_calculate = .
true.
 
  496        if (iomega > 1 .and. abs(em_vars%freq_factor(ifactor)) <= 
m_epsilon) have_to_calculate = .false.
 
  498        if (ifactor > 1 .and. (.not. em_vars%calc_magnetooptics)) 
then 
  501          if (have_to_calculate .and. abs(em_vars%freq_factor(ifactor - 1) * em_vars%omega(iomega) &
 
  504            do idir = 1, sys%space%dim
 
  505              call lr_copy(sys%st, sys%gr, em_vars%lr(idir, 1, ifactor - 1), em_vars%lr(idir, 1, ifactor))
 
  506              call lr_copy(sys%st, sys%gr, em_vars%lr(idir, 2, ifactor - 1), em_vars%lr(idir, 2, ifactor))
 
  508              if (em_vars%calc_hyperpol .and. use_kdotp) 
then 
  509                do idir2 = 1, sys%space%periodic_dim
 
  510                  call lr_copy(sys%st, sys%gr, kdotp_em_lr2(idir, idir2, 1, ifactor - 1), &
 
  511                    kdotp_em_lr2(idir, idir2, 1, ifactor))
 
  512                  call lr_copy(sys%st, sys%gr, kdotp_em_lr2(idir, idir2, 2, ifactor - 1), &
 
  513                    kdotp_em_lr2(idir, idir2, 2, ifactor))
 
  518            have_to_calculate = .false.
 
  523          if (have_to_calculate .and. abs(em_vars%freq_factor(ifactor - 1) * em_vars%omega(iomega) &
 
  526            do idir = 1, sys%space%dim
 
  527              call lr_copy(sys%st, sys%gr, em_vars%lr(idir, 1, ifactor - 1), em_vars%lr(idir, 2, ifactor))
 
  528              call lr_copy(sys%st, sys%gr, em_vars%lr(idir, 2, ifactor - 1), em_vars%lr(idir, 1, ifactor))
 
  530              if (em_vars%calc_hyperpol .and. use_kdotp) 
then 
  531                do idir2 = 1, sys%space%periodic_dim
 
  532                  call lr_copy(sys%st, sys%gr, kdotp_em_lr2(idir, idir2, 1, ifactor - 1), &
 
  533                    kdotp_em_lr2(idir, idir2, 2, ifactor))
 
  534                  call lr_copy(sys%st, sys%gr, kdotp_em_lr2(idir, idir2, 2, ifactor - 1), &
 
  535                    kdotp_em_lr2(idir, idir2, 1, ifactor))
 
  540            have_to_calculate = .false.
 
  546        if (iomega > 1 .and. ifactor == 1 .and. (.not. em_vars%calc_magnetooptics)) 
then 
  549          if (have_to_calculate .and. abs(frequency - last_omega) < 
m_epsilon) 
then 
  551            do idir = 1, sys%space%dim
 
  552              call lr_copy(sys%st, sys%gr, em_vars%lr(idir, 1, em_vars%nfactor), em_vars%lr(idir, 1, 1))
 
  553              call lr_copy(sys%st, sys%gr, em_vars%lr(idir, 2, em_vars%nfactor), em_vars%lr(idir, 2, 1))
 
  555              if (em_vars%calc_hyperpol .and. use_kdotp) 
then 
  556                do idir2 = 1, sys%space%periodic_dim
 
  557                  call lr_copy(sys%st, sys%gr, kdotp_em_lr2(idir, idir2, 1, em_vars%nfactor), &
 
  558                    kdotp_em_lr2(idir, idir2, 1, 1))
 
  559                  call lr_copy(sys%st, sys%gr, kdotp_em_lr2(idir, idir2, 2, em_vars%nfactor), &
 
  560                    kdotp_em_lr2(idir, idir2, 2, 1))
 
  565            have_to_calculate = .false.
 
  570          if (have_to_calculate .and. abs(frequency + last_omega) < 
m_epsilon) 
then 
  572            do idir = 1, sys%space%dim
 
  573              call lr_copy(sys%st, sys%gr, em_vars%lr(idir, 1, em_vars%nfactor), em_vars%lr(idir, 2, 1))
 
  574              call lr_copy(sys%st, sys%gr, em_vars%lr(idir, 2, em_vars%nfactor), em_vars%lr(idir, 1, 1))
 
  576              if (em_vars%calc_hyperpol .and. use_kdotp) 
then 
  577                do idir2 = 1, sys%space%periodic_dim
 
  578                  call lr_copy(sys%st, sys%gr, kdotp_em_lr2(idir, idir2, 1, em_vars%nfactor), &
 
  579                    kdotp_em_lr2(idir, idir2, 2, 1))
 
  580                  call lr_copy(sys%st, sys%gr, kdotp_em_lr2(idir, idir2, 2, em_vars%nfactor), &
 
  581                    kdotp_em_lr2(idir, idir2, 1, 1))
 
  586            have_to_calculate = .false.
 
  592        if (have_to_calculate) 
then 
  594          exact_freq(:) = .false.
 
  597            call drun_sternheimer(em_vars, sys%namespace, sys%space, sys%gr, sys%kpoints, sys%st, sys%hm, sys%mc, &
 
  600            call zrun_sternheimer(em_vars, sys%namespace, sys%space, sys%gr, sys%kpoints, sys%st, sys%hm, sys%mc, &
 
  606        if (.not. have_to_calculate) cycle
 
  609          call dcalc_properties_linear(em_vars, sys%namespace, sys%space, sys%gr, sys%kpoints, sys%st, sys%hm, sys%ks%xc, &
 
  612          call zcalc_properties_linear(em_vars, sys%namespace, sys%space, sys%gr, sys%kpoints, sys%st, sys%hm, sys%ks%xc, &
 
  624      last_omega = em_vars%freq_factor(em_vars%nfactor) * em_vars%omega(iomega)
 
  628    do idir = 1, sys%space%dim
 
  629      do sigma = 1, em_vars%nsigma
 
  630        do ifactor = 1, em_vars%nfactor
 
  631          call lr_dealloc(em_vars%lr(idir, sigma, ifactor))
 
  637    deallocate(em_vars%perturbation)
 
  640      do idir = 1, sys%space%periodic_dim
 
  645    if (em_vars%calc_hyperpol .and. use_kdotp) 
then 
  648      safe_deallocate_p(pert_kdotp)
 
  649      safe_deallocate_p(pert2_none)
 
  650      do idir = 1, sys%space%periodic_dim
 
  651        do idir2 = 1, sys%space%periodic_dim
 
  652          do sigma = 1, em_vars%nsigma
 
  653            do ifactor = 1, em_vars%nfactor
 
  654              call lr_dealloc(kdotp_em_lr2(idir, idir2, sigma, ifactor))
 
  659      safe_deallocate_a(kdotp_em_lr2)
 
  660      safe_deallocate_a(dl_eig)
 
  663    if (em_vars%kpt_output) 
then 
  664      safe_deallocate_a(em_vars%alpha_k)
 
  667    if (em_vars%calc_magnetooptics .or. magnetic_pert) 
then 
  669        safe_deallocate_p(pert2_none)
 
  671        do idir = 1, sys%space%dim
 
  672          do idir2 = 1, sys%space%dim
 
  674            if (idir2 <= idir) 
call lr_dealloc(k2_lr(idir, idir2, 1))
 
  677        safe_deallocate_a(k2_lr)
 
  678        safe_deallocate_a(kb_lr)
 
  682    if (em_vars%calc_magnetooptics) 
then 
  685      do idir = 1, sys%space%dim
 
  688      safe_deallocate_a(b_lr)
 
  691        do idir = 1, sys%space%dim
 
  692          do idir2 = 1, sys%space%dim
 
  693            do sigma = 1, em_vars%nsigma
 
  694              do ifactor = 1, nfactor_ke
 
  695                call lr_dealloc(ke_lr(idir, idir2, sigma, ifactor))
 
  700        safe_deallocate_a(ke_lr)
 
  701        if (em_vars%kpt_output) 
then 
  702          safe_deallocate_a(em_vars%alpha_be_k)
 
  705        safe_deallocate_p(pert_b)
 
  709    safe_deallocate_a(em_vars%omega)
 
  710    safe_deallocate_a(em_vars%lr)
 
  711    do ifactor = 1, em_vars%nfactor
 
  723      integer :: nrow, irow, nfreqs_in_row, ifreq, istep, perturb_type
 
  724      real(real64) :: omega_ini, omega_fin, domega
 
  755      if (
parse_block(sys%namespace, 
'EMFreqs', blk) == 0) 
then 
  763          if (nfreqs_in_row < 1) 
then 
  764            message(1) = 
"EMFreqs: invalid number of frequencies." 
  767          em_vars%nomega = em_vars%nomega + nfreqs_in_row
 
  770        safe_allocate(em_vars%omega(1:em_vars%nomega))
 
  777          if (nfreqs_in_row > 1) 
then 
  779            domega = (omega_fin - omega_ini)/(nfreqs_in_row - 
m_one)
 
  780            do istep = 0, nfreqs_in_row-1
 
  781              em_vars%omega(ifreq + istep) = omega_ini + domega*istep
 
  783            ifreq = ifreq + nfreqs_in_row
 
  785            em_vars%omega(ifreq) = omega_ini
 
  803        if (freq_sort) 
call sort(em_vars%omega)
 
  808        safe_allocate(em_vars%omega(1:em_vars%nomega))
 
  826        message(1) = 
"EMEta cannot be negative." 
  831      em_vars%calc_hyperpol = .false.
 
  832      em_vars%freq_factor(1:3) = 
m_one 
  833      em_vars%calc_magnetooptics = .false.
 
  834      em_vars%magnetooptics_nohvar = .
true.
 
  835      em_vars%kpt_output = .false.
 
  851      call parse_variable(sys%namespace, 
'EMPerturbationType', perturbation_electric, perturb_type)
 
  854      select case(perturb_type)
 
  855      case(perturbation_electric)
 
  865      select type(ptr=>em_vars%perturbation)
 
  876        call parse_variable(sys%namespace, 
'EMCalcRotatoryResponse', .false., em_vars%calc_rotatory)
 
  890        if (
parse_block(sys%namespace, 
'EMHyperpol', blk) == 0) 
then 
  897          if (abs(sum(em_vars%freq_factor(1:3))) > 
m_epsilon) 
then 
  898            message(1) = 
"Frequency factors specified by EMHyperpol must sum to zero." 
  902          em_vars%calc_hyperpol = .
true.
 
  912        call parse_variable(sys%namespace, 
'EMCalcMagnetooptics', .false., em_vars%calc_magnetooptics)
 
  922        call parse_variable(sys%namespace, 
'EMMagnetoopticsNoHVar', .
true., em_vars%magnetooptics_nohvar)
 
  933        call parse_variable(sys%namespace, 
'EMKPointOutput', .false., em_vars%kpt_output)
 
  949      call parse_variable(sys%namespace, 
'EMForceNoKdotP', .false., em_vars%force_no_kdotp)
 
  959      call parse_variable(sys%namespace, 
'EMCalcBornCharges', .false., em_vars%calc_Born)
 
  960      if (em_vars%calc_Born) 
call messages_experimental(
"Calculation of Born effective charges", namespace=sys%namespace)
 
  973      call parse_variable(sys%namespace, 
'EMOccupiedResponse', .false., em_vars%occ_response)
 
  975        message(1) = 
"EMOccupiedResponse cannot be used if there are partial occupations." 
  989      call parse_variable(sys%namespace, 
'EMWavefunctionsFromScratch', .false., em_vars%wfns_from_scratch)
 
 1001      call em_vars%perturbation%info()
 
 1002      select type(ptr=>em_vars%perturbation)
 
 1004        if (em_vars%calc_hyperpol) 
then 
 1014        message(1) = 
'Wavefunctions type: Real' 
 1016        message(1) = 
'Wavefunctions type: Complex' 
 1020      write(
message(1),
'(a,i3,a)') 
'Calculating response for ', em_vars%nomega, 
' frequencies.' 
 1032#include "em_resp_inc.F90" 
 1035#include "complex.F90" 
 1036#include "em_resp_inc.F90" 
 1043  subroutine em_resp_output(st, namespace, space, gr, hm, ions, outp, sh, em_vars, iomega, ifactor)
 
 1046    class(
space_t),           
intent(in)    :: space
 
 1047    type(
grid_t),             
intent(in)    :: gr
 
 1049    type(
ions_t),             
intent(in)    :: ions
 
 1052    type(
em_resp_t),          
intent(inout) :: em_vars
 
 1053    integer,                  
intent(in)    :: iomega
 
 1054    integer,                  
intent(in)    :: ifactor
 
 1056    integer :: iunit, idir
 
 1057    character(len=80) :: dirname, str_tmp
 
 1058    logical :: use_kdotp
 
 1059    complex(real64) :: epsilon(space%dim, space%dim)
 
 1063    use_kdotp = space%is_periodic() .and. .not. em_vars%force_no_kdotp
 
 1067    write(dirname, 
'(a, a)') 
em_resp_dir//
'freq_', trim(str_tmp)
 
 1068    call io_mkdir(trim(dirname), namespace)
 
 1070    if (sh%has_photons .and. 
mpi_world%is_root()) 
then 
 1071      iunit = 
io_open(trim(dirname)//
'/photon_coord_q', namespace, action=
'write')
 
 1073      write(iunit, 
'(a)') 
'                 Re                Im' 
 1074      do idir = 1, space%dim
 
 1083    select type(ptr=>em_vars%perturbation)
 
 1085      if ((.not. em_vars%calc_magnetooptics) .or. ifactor == 1) 
then 
 1087        if (em_vars%calc_Born) 
then 
 1088          call born_output_charges(em_vars%born_charges(ifactor), ions%atom, ions%charge, ions%natoms, &
 
 1089            namespace, space%dim, dirname, write_real = em_vars%eta < 
m_epsilon)
 
 1092        if (space%periodic_dim == space%dim) 
then 
 1096        if ((.not. space%is_periodic() .or. em_vars%force_no_kdotp) .and. em_vars%calc_rotatory) 
then 
 1121      iunit = 
io_open(trim(dirname)//
'/eta', namespace, action=
'write')
 
 1135      integer, 
intent(in) :: out_file
 
 1137      character(len=80) :: header_string
 
 1138      integer :: ii, idir, kdir
 
 1145      write(out_file, 
'(a1, a20)', advance = 
'no') 
'#', 
str_center(
"Energy", 20)
 
 1146      write(out_file, 
'(a20)', advance = 
'no') 
str_center(
"(1/3)*Tr[sigma]", 20)
 
 1147      write(out_file, 
'(a20)', advance = 
'no') 
str_center(
"Anisotropy[sigma]", 20)
 
 1149      do idir = 1, space%dim
 
 1150        do kdir = 1, space%dim
 
 1151          write(header_string,
'(a6,i1,a1,i1,a1)') 
'sigma(', idir, 
',', kdir, 
')' 
 1152          write(out_file, 
'(a20)', advance = 
'no') 
str_center(trim(header_string), 20)
 
 1158      do ii = 1, 2 + space%dim**2
 
 1169      real(real64) :: cross(space%dim, space%dim), crossp(space%dim, space%dim)
 
 1170      real(real64) :: cross_sum, crossp_sum, anisotropy
 
 1171      integer :: idir, idir2
 
 1177      iunit = 
io_open(trim(dirname)//
'/alpha', namespace, action=
'write')
 
 1179      if (.not. em_vars%ok(ifactor)) 
write(iunit, 
'(a)') 
"# WARNING: not converged" 
 1182      call output_tensor(real(em_vars%alpha(:, :, ifactor), real64), space%dim, 
units_out%polarizability, iunit=iunit)
 
 1188        cross(1:space%dim, 1:space%dim) = aimag(em_vars%alpha(1:space%dim, 1:space%dim, ifactor)) * &
 
 1189          em_vars%freq_factor(ifactor) * em_vars%omega(iomega) * (
m_four * 
m_pi / 
p_c)
 
 1191        do idir = 1, space%dim
 
 1192          do idir2 = 1, space%dim
 
 1197        iunit = 
io_open(trim(dirname)//
'/cross_section', namespace, action=
'write')
 
 1198        if (.not. em_vars%ok(ifactor)) 
write(iunit, 
'(a)') 
"# WARNING: not converged" 
 1200        crossp(1:space%dim, 1:space%dim) = matmul(cross(1:space%dim, 1:space%dim), cross(1:space%dim, 1:space%dim))
 
 1204        do idir = 1, space%dim
 
 1205          cross_sum = cross_sum + cross(idir, idir)
 
 1206          crossp_sum = crossp_sum + crossp(idir, idir)
 
 1209        anisotropy = crossp_sum - 
m_third * cross_sum**2
 
 1212        write(iunit,
'(3e20.8)', advance = 
'no') &
 
 1215        do idir = 1, space%dim
 
 1216          do idir2 = 1, space%dim
 
 1217            write(iunit,
'(e20.8)', advance = 
'no') cross(idir, idir2)
 
 1220        write(iunit,
'(a)', advance = 
'yes')
 
 1232      integer :: idir, idir1, ik
 
 1233      character(len=80) :: header_string
 
 1234      complex(real64), 
allocatable :: epsilon_k(:, :, :)
 
 1240      iunit = 
io_open(trim(dirname)//
'/epsilon', namespace, action=
'write')
 
 1241      if (.not. em_vars%ok(ifactor)) 
write(iunit, 
'(a)') 
"# WARNING: not converged" 
 1243      epsilon(1:space%dim, 1:space%dim) = &
 
 1244        4 * 
m_pi * em_vars%alpha(1:space%dim, 1:space%dim, ifactor) / ions%latt%rcell_volume
 
 1245      do idir = 1, space%dim
 
 1246        epsilon(idir, idir) = epsilon(idir, idir) + 
m_one 
 1249      write(iunit, 
'(a)') 
'# Real part of dielectric constant' 
 1250      call output_tensor(real(epsilon(1:space%dim, 1:space%dim), real64), space%dim, 
unit_one, iunit=iunit)
 
 1252      write(iunit, 
'(a)') 
'# Imaginary part of dielectric constant' 
 1255      if (em_vars%lrc_kernel) 
then 
 1257        write(iunit, 
'(a)') 
'# Without G = G'' = 0 term of the LRC kernel' 
 1259        epsilon(1:space%dim, 1:space%dim) = &
 
 1260          4 * 
m_pi * em_vars%alpha0(1:space%dim, 1:space%dim, ifactor) / ions%latt%rcell_volume
 
 1261        do idir = 1, space%dim
 
 1262          epsilon(idir, idir) = epsilon(idir, idir) + 
m_one 
 1265        write(iunit, 
'(a)') 
'# Real part of dielectric constant' 
 1266        call output_tensor(real(epsilon(1:space%dim, 1:space%dim), real64), space%dim, 
unit_one, iunit=iunit)
 
 1268        write(iunit, 
'(a)') 
'# Imaginary part of dielectric constant' 
 1274      if (em_vars%kpt_output) 
then 
 1275        safe_allocate(epsilon_k(1:space%dim, 1:space%dim, 1:hm%kpoints%reduced%npoints))
 
 1276        do ik = 1, hm%kpoints%reduced%npoints
 
 1277          do idir = 1, space%dim
 
 1278            do idir1 = 1, space%dim
 
 1279              epsilon_k(idir, idir1, ik) = 
m_four * 
m_pi * em_vars%alpha_k(idir, idir1, ifactor, ik) / ions%latt%rcell_volume
 
 1283        iunit = 
io_open(trim(dirname)//
'/epsilon_k_re', namespace, action=
'write')
 
 1285        write(iunit, 
'(a)') 
'# Real part of dielectric constant' 
 1286        write(iunit, 
'(a10)', advance = 
'no') 
'#  index  ' 
 1287        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"weight", 20)
 
 1288        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"kx", 20)
 
 1289        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"ky", 20)
 
 1290        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"kz", 20)
 
 1292        do idir = 1, space%dim
 
 1293          do idir1 = 1, space%dim
 
 1294            write(header_string,
'(a7,i1,a1,i1,a1)') 
'Re eps(', idir, 
',', idir1, 
')' 
 1295            write(iunit, 
'(a20)', advance = 
'no') 
str_center(trim(header_string), 20)
 
 1300        do ik = 1, hm%kpoints%reduced%npoints
 
 1301          write(iunit, 
'(i8)', advance = 
'no') ik
 
 1302          write(iunit, 
'(e20.8)', advance = 
'no') hm%kpoints%reduced%weight(ik)
 
 1303          do idir = 1, space%dim
 
 1304            write(iunit, 
'(e20.8)', advance = 
'no') hm%kpoints%reduced%red_point(idir, ik)
 
 1306          do idir = 1, space%dim
 
 1307            do idir1 = 1, space%dim
 
 1308              write(iunit, 
'(e20.8)', advance = 
'no') real(epsilon_k(idir, idir1, ik), real64)
 
 1315        iunit = 
io_open(trim(dirname)//
'/epsilon_k_im', namespace, action=
'write')
 
 1317        write(iunit, 
'(a)') 
'# Imaginary part of dielectric constant' 
 1318        write(iunit, 
'(a10)', advance = 
'no') 
'#  index  ' 
 1319        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"weight", 20)
 
 1320        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"kx", 20)
 
 1321        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"ky", 20)
 
 1322        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"kz", 20)
 
 1324        do idir = 1, space%dim
 
 1325          do idir1 = 1, space%dim
 
 1326            write(header_string,
'(a7,i1,a1,i1,a1)') 
'Im eps(', idir, 
',', idir1,
')' 
 1327            write(iunit, 
'(a20)', advance = 
'no') 
str_center(trim(header_string), 20)
 
 1332        do ik = 1, hm%kpoints%reduced%npoints
 
 1333          write(iunit, 
'(i8)', advance = 
'no') ik
 
 1334          write(iunit, 
'(e20.8)', advance = 
'no') hm%kpoints%reduced%weight(ik)
 
 1335          do idir = 1, space%dim
 
 1336            write(iunit, 
'(e20.8)', advance = 
'no') hm%kpoints%reduced%red_point(idir, ik)
 
 1338          do idir = 1, space%dim
 
 1339            do idir1 = 1, space%dim
 
 1340              write(iunit, 
'(e20.8)', advance = 
'no') aimag(epsilon_k(idir, idir1, ik))
 
 1346        safe_deallocate_a(epsilon_k)
 
 1356      character(len=80) :: dirname1
 
 1362      select type(ptr=>em_vars%perturbation)
 
 1365        call io_mkdir(trim(dirname1), namespace)
 
 1366        iunit = 
io_open(trim(dirname1)//
'/susceptibility', namespace, action=
'write')
 
 1368        iunit = 
io_open(trim(dirname)//
'/susceptibility', namespace, action=
'write')
 
 1371      if (.not. em_vars%ok(ifactor)) 
write(iunit, 
'(a)') 
"# WARNING: not converged" 
 1375      if (.not. use_kdotp) 
then 
 1376        write(iunit, 
'(2a)') 
'# Paramagnetic contribution to the susceptibility tensor [ppm a.u.]' 
 1378        write(iunit, 
'(1x)')
 
 1380        write(iunit, 
'(2a)') 
'# Diamagnetic contribution to the susceptibility tensor [ppm a.u.]' 
 1382        write(iunit, 
'(1x)')
 
 1385      write(iunit, 
'(2a)') 
'# Total susceptibility tensor [ppm a.u.]' 
 1386      call output_tensor(real(em_vars%chi_para(:, :) + em_vars%chi_dia(:,:), real64) , &
 
 1388      write(iunit, 
'(1x)')
 
 1392      if (.not. use_kdotp) 
then 
 1393        write(iunit, 
'(2a)') 
'# Paramagnetic contribution to the susceptibility tensor [ppm cgs / mol]' 
 1395        write(iunit, 
'(1x)')
 
 1397        write(iunit, 
'(2a)') 
'# Diamagnetic contribution to the susceptibility tensor [ppm cgs / mol]' 
 1399        write(iunit, 
'(1x)')
 
 1402      write(iunit, 
'(2a)') 
'# Total susceptibility tensor [ppm cgs / mol]' 
 1403      call output_tensor(real(em_vars%chi_para(:, :) + em_vars%chi_dia(:,:), real64), &
 
 1405      write(iunit, 
'(1x)')
 
 1409        write(iunit, 
'(1a)') 
'# Magnetization [ppm a.u.]' 
 1422      integer :: idir, isigma
 
 1426      do idir = 1, space%dim
 
 1429          if (space%dim == 3 .and. outp%what(option__output__elf)) 
then 
 1430            if (em_vars%nsigma == 1) 
then 
 1431              call zlr_calc_elf(st, space, gr, hm%kpoints, em_vars%lr(idir, 1, ifactor))
 
 1433              call zlr_calc_elf(st, space, gr, hm%kpoints, em_vars%lr(idir, 1, ifactor), em_vars%lr(idir, 2, ifactor))
 
 1436          do isigma = 1, em_vars%nsigma
 
 1437            call zoutput_lr(outp, namespace, space, dirname, st, gr, em_vars%lr(idir, isigma, ifactor), idir, isigma, ions, &
 
 1442          if (space%dim == 3 .and. outp%what(option__output__elf)) 
then 
 1443            if (em_vars%nsigma == 1) 
then 
 1444              call dlr_calc_elf(st, space, gr, hm%kpoints, em_vars%lr(idir, 1, ifactor))
 
 1446              call dlr_calc_elf(st, space, gr, hm%kpoints, em_vars%lr(idir, 1, ifactor), em_vars%lr(idir, 2, ifactor))
 
 1450          do isigma = 1, em_vars%nsigma
 
 1451            call doutput_lr(outp, namespace, space, dirname, st, gr, em_vars%lr(idir, isigma, ifactor), idir, isigma, ions, &
 
 1471      complex(real64) :: dic
 
 1472      complex(real64), 
allocatable :: psi(:, :, :, :)
 
 1478        message(1) = 
"Info: Calculating rotatory response." 
 1483        safe_allocate(psi(1:gr%np_part, 1:st%d%dim, st%st_start:st%st_end, st%d%kpt%start:st%d%kpt%end))
 
 1488        do idir = 1, space%dim
 
 1489          call angular_momentum%setup_dir(idir)
 
 1491            + angular_momentum%zexpectation_value(namespace, space, gr, hm, st, psi, &
 
 1492            em_vars%lr(idir, 1, ifactor)%zdl_psi) &
 
 1493            + angular_momentum%zexpectation_value(namespace, space, gr, hm, st, &
 
 1494            em_vars%lr(idir, 2, ifactor)%zdl_psi, psi)
 
 1497        safe_deallocate_a(psi)
 
 1499        safe_deallocate_p(angular_momentum)
 
 1505          iunit = 
io_open(trim(dirname)//
'/rotatory_strength', namespace, action=
'write')
 
 1508          write(iunit, 
'(a1,a20,a20,a20)') 
'#', 
str_center(
"Energy", 20), 
str_center(
"R", 20), 
str_center(
"Re[beta]", 20)
 
 1514          if (abs(em_vars%omega(iomega)) > 
m_epsilon) ff = real(dic, real64) /(
m_three*em_vars%omega(iomega))
 
 1530      complex(real64) :: epsilon_m(4), diff(4), eps_mk(space%dim)
 
 1537      assert(space%dim == 3)
 
 1540      do idir = 1, space%dim
 
 1544      diff(4) = (diff(1) + diff(2) + diff(3)) / 
m_three 
 1546      iunit = 
io_open(trim(dirname)//
'/alpha_mo', namespace, action=
'write')
 
 1548      if (.not. em_vars%ok(ifactor)) 
write(iunit, 
'(a)') 
"# WARNING: not converged" 
 1550      write(iunit, 
'(a1, a25)', advance = 
'no') 
'#', 
str_center(
" ", 25)
 
 1551      write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"   yz,x = -zy,x", 20)
 
 1552      write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"   zx,y = -xz,y", 20)
 
 1553      write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"   xy,z = -yx,z", 20)
 
 1554      write(iunit, 
'(a20)', advance = 
'no') 
str_center(
" Average", 20)
 
 1557      write(iunit, 
'(a25)', advance = 
'no') 
str_center(
"Re alpha [a.u.]", 25)
 
 1558      do idir = 1, space%dim + 1
 
 1559        write(iunit, 
'(e20.8)', advance = 
'no') real(diff(idir), real64)
 
 1563      write(iunit, 
'(a25)', advance = 
'no') 
str_center(
"Im alpha [a.u.]", 25)
 
 1564      do idir = 1, space%dim + 1
 
 1565        write(iunit, 
'(e20.8)', advance = 
'no') aimag(diff(idir))
 
 1569      if (space%is_periodic()) 
then 
 1571        assert(space%periodic_dim == 3)
 
 1573        do idir = 1, space%dim
 
 1574          epsilon_m(idir) = 4 * 
m_pi * diff(idir) / ions%latt%rcell_volume
 
 1576        epsilon_m(4) = 4 * 
m_pi * diff(4) / ions%latt%rcell_volume
 
 1578        write(iunit, 
'(a25)', advance = 
'no') 
str_center(
"Re epsilon (B = 1 a.u.)", 25)
 
 1579        do idir = 1, space%dim + 1
 
 1580          write(iunit, 
'(e20.8)', advance = 
'no') real(epsilon_m(idir), real64)
 
 1584        write(iunit, 
'(a25)', advance = 
'no') 
str_center(
"Im epsilon (B = 1 a.u.)", 25)
 
 1585        do idir = 1, space%dim + 1
 
 1586          write(iunit, 
'(e20.8)', advance = 
'no') aimag(epsilon_m(idir))
 
 1590        if (em_vars%lrc_kernel) 
then 
 1592          write(iunit, 
'(a)') 
'# Without the G = G'' = 0 term of the LRC kernel' 
 1596          do idir = 1, space%dim
 
 1600            epsilon_m(idir) = 4 * 
m_pi * diff(idir) / ions%latt%rcell_volume
 
 1602          diff(4) = (diff(1) + diff(2) + diff(3)) / 
m_three 
 1603          epsilon_m(4) = 4 * 
m_pi * diff(4) / ions%latt%rcell_volume
 
 1605          write(iunit, 
'(a1, a25)', advance = 
'no') 
'#', 
str_center(
" ", 25)
 
 1606          write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"   yz,x = -zy,x", 20)
 
 1607          write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"   zx,y = -xz,y", 20)
 
 1608          write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"   xy,z = -yx,z", 20)
 
 1609          write(iunit, 
'(a20)', advance = 
'no') 
str_center(
" Average", 20)
 
 1612          write(iunit, 
'(a25)', advance = 
'no') 
str_center(
"Re alpha [a.u.]", 25)
 
 1613          do idir = 1, space%dim + 1
 
 1614            write(iunit, 
'(e20.8)', advance = 
'no') real(diff(idir), real64)
 
 1618          write(iunit, 
'(a25)', advance = 
'no') 
str_center(
"Im alpha [a.u.]", 25)
 
 1619          do idir = 1, space%dim + 1
 
 1620            write(iunit, 
'(e20.8)', advance = 
'no') aimag(diff(idir))
 
 1624          write(iunit, 
'(a25)', advance = 
'no') 
str_center(
"Re epsilon (B = 1 a.u.)", 25)
 
 1625          do idir = 1, space%dim + 1
 
 1626            write(iunit, 
'(e20.8)', advance = 
'no') real(epsilon_m(idir), real64)
 
 1630          write(iunit, 
'(a25)', advance = 
'no') 
str_center(
"Im epsilon (B = 1 a.u.)", 25)
 
 1631          do idir = 1, space%dim + 1
 
 1632            write(iunit, 
'(e20.8)', advance = 
'no') aimag(epsilon_m(idir))
 
 1639      if (space%is_periodic() .and. em_vars%kpt_output) 
then 
 1640        iunit = 
io_open(trim(dirname)//
'/epsilon_mo_k', namespace, action=
'write')
 
 1642        write(iunit, 
'(a)') 
'# Contribution to dielectric tensor for B = 1 a.u.' 
 1643        write(iunit, 
'(a10)', advance = 
'no') 
'#  index  ' 
 1644        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"weight", 20)
 
 1645        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"kx", 20)
 
 1646        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"ky", 20)
 
 1647        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"kz", 20)
 
 1648        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"Re eps_yz,x", 20)
 
 1649        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"Re eps_zx,y", 20)
 
 1650        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"Re eps_xy,z", 20)
 
 1651        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"Im eps_yz,x", 20)
 
 1652        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"Im eps_zx,y", 20)
 
 1653        write(iunit, 
'(a20)', advance = 
'no') 
str_center(
"Im eps_xy,z", 20)
 
 1656        do ik = 1, hm%kpoints%reduced%npoints
 
 1657          write(iunit, 
'(i8)', advance = 
'no') ik
 
 1658          write(iunit, 
'(e20.8)', advance = 
'no') hm%kpoints%reduced%weight(ik)
 
 1659          do idir = 1, space%dim
 
 1661              em_vars%alpha_be_k(
magn_dir(idir, 2), 
magn_dir(idir, 1), idir, ik)) / ions%latt%rcell_volume
 
 1664          do idir = 1, space%dim
 
 1665            write(iunit, 
'(e20.8)', advance = 
'no') hm%kpoints%reduced%red_point(idir, ik)
 
 1667          do idir = 1, space%dim
 
 1668            write(iunit, 
'(e20.8)', advance = 
'no') real(eps_mk(idir), real64)
 
 1670          do idir = 1, space%dim
 
 1671            write(iunit, 
'(e20.8)', advance = 
'no') aimag(eps_mk(idir))
 
 1688    class(
box_t),       
intent(in) :: box
 
 1689    complex(real64),    
intent(in) :: beta(:, :, :)
 
 1690    real(real64),       
intent(in) :: freq_factor(:)
 
 1691    logical,            
intent(in) :: converged
 
 1692    character(len=*),   
intent(in) :: dirname
 
 1695    complex(real64) :: bpar(1:box%dim), bper(1:box%dim), bk(1:box%dim)
 
 1696    complex(real64) :: HRS_VV, HRS_HV
 
 1697    integer :: ii, jj, kk, iunit
 
 1704    iunit = 
io_open(trim(dirname)//
'/beta', namespace, action=
'write')
 
 1706    if (.not. converged) 
write(iunit, 
'(a)') 
"# WARNING: not converged" 
 1708    write(iunit, 
'(a,3(f4.1,a),2a)', advance=
'no') 
'First hyperpolarizability tensor: beta(', &
 
 1709      freq_factor(1), 
', ', freq_factor(2), 
', ', freq_factor(3), 
') [', &
 
 1717          write(iunit,
'(a,e20.8,e20.8)') 
'beta '// &
 
 1725    if (box%dim == 3) 
then 
 1731          bpar(ii) = bpar(ii) + beta(ii, jj, jj) + beta(jj, ii, jj) + beta(jj, jj, ii)
 
 1732          bper(ii) = bper(ii) + 
m_two*beta(ii, jj, jj) - 
m_three*beta(jj, ii, jj) + 
m_two*beta(jj, jj, ii)
 
 1740      bk(1:box%dim) = 
m_three*
m_half*(bpar(1:box%dim) - bper(1:box%dim))
 
 1743        write(iunit, 
'(a, 2e20.8)') 
'beta // '//
index2axis(ii), &
 
 1751        write(iunit, 
'(a, 2e20.8)') 
'beta _L '//
index2axis(ii), &
 
 1759        write(iunit, 
'(a, 2e20.8)') 
'beta  k '//
index2axis(ii), &
 
 1767      write(iunit, 
'(a)') 
'beta for liquid- or gas-phase hyper-Rayleigh scattering:' 
 1768      write(iunit, 
'(a, 2e20.8)') 
'VV polarization ', &
 
 1771      write(iunit, 
'(a, 2e20.8)') 
'HV polarization ', &
 
 1787      class(
box_t),      
intent(in)  :: box
 
 1788      complex(real64),   
intent(in)  :: beta(:, :, :)
 
 1789      complex(real64),   
intent(out) :: HRS_VV, HRS_HV
 
 1791      complex(real64) :: HRS_A, HRS_B, HRS_C, HRS_D, HRS_E
 
 1792      complex(real64) :: HRS_B1, HRS_B2, HRS_C1, HRS_C2, HRS_C3, HRS_D1, HRS_D2, HRS_D3, HRS_E1, HRS_E2
 
 1800        hrs_a = hrs_a + beta(ii,ii,ii)**2
 
 1808            hrs_b = hrs_b + beta(ii,ii,ii) * (beta(ii,jj,jj) + beta(jj,ii,jj) + beta(jj,jj,ii))
 
 1809            hrs_c = hrs_c + (beta(ii,ii,jj) + beta(ii,jj,ii) + beta(jj,ii,ii))**2
 
 1814      hrs_d = (beta(1,1,2) + beta(1,2,1) + beta(2,1,1)) * (beta(2,3,3) + beta(3,2,3) + beta(3,3,2)) &
 
 1815        + (beta(2,2,3) + beta(2,3,2) + beta(3,2,2)) * (beta(3,1,1) + beta(1,3,1) + beta(1,1,3)) &
 
 1816        + (beta(3,3,1) + beta(3,1,3) + beta(1,3,3)) * (beta(1,2,2) + beta(2,1,2) + beta(2,2,1))
 
 1818      hrs_e = (beta(1,2,3) + beta(1,3,2) + beta(2,1,3) + beta(2,3,1) + beta(3,1,2) + beta(3,2,1))**2
 
 1820      hrs_vv = (
m_one / 7.0_real64)     * hrs_a &
 
 1821        + (
m_two / 35.0_real64)  * hrs_b &
 
 1823        + (
m_two / 105.0_real64) * hrs_d &
 
 1824        + (
m_one / 105.0_real64) * hrs_e
 
 1835            hrs_b1 = hrs_b1 + beta(ii,ii,ii) * beta(ii,jj,jj)
 
 1836            hrs_b2 = hrs_b2 + beta(ii,ii,ii) * (beta(jj,ii,jj) + beta(jj,jj,ii))
 
 1837            hrs_c1 = hrs_c1 + (beta(ii,ii,jj) + beta(ii,jj,ii))**2
 
 1838            hrs_c2 = hrs_c2 + beta(jj,ii,ii) * (beta(ii,ii,jj) + beta(ii,jj,ii))
 
 1839            hrs_c3 = hrs_c3 + beta(jj,ii,ii)**2
 
 1844      hrs_d1 = (beta(1,1,2) + beta(1,2,1) + beta(2,1,1)) * (beta(3,2,3) + beta(3,3,2)) &
 
 1845        + (beta(2,2,3) + beta(2,3,2) + beta(3,2,2)) * (beta(1,3,1) + beta(1,1,3)) &
 
 1846        + (beta(3,3,1) + beta(3,1,3) + beta(1,3,3)) * (beta(2,1,2) + beta(2,2,1))
 
 1847      hrs_d2 = (beta(1,1,2) + beta(1,2,1)) * beta(2,3,3) &
 
 1848        + (beta(2,2,3) + beta(2,3,2)) * beta(3,1,1) &
 
 1849        + (beta(3,3,1) + beta(3,1,3)) * beta(1,2,2)
 
 1850      hrs_d3 = beta(2,1,1) * beta(2,3,3) &
 
 1851        + beta(3,2,2) * beta(3,1,1) &
 
 1852        + beta(1,3,3) * beta(1,2,2)
 
 1854      hrs_e1 = (beta(1,2,3) + beta(1,3,2))**2 &
 
 1855        + (beta(2,1,3) + beta(2,3,1))**2 &
 
 1856        + (beta(3,1,2) + beta(3,2,1))**2
 
 1858      hrs_e2 = (beta(1,2,3) + beta(1,3,2)) * (beta(2,1,3) + beta(2,3,1)) &
 
 1859        + (beta(2,1,3) + beta(2,3,1)) * (beta(3,1,2) + beta(3,2,1)) &
 
 1860        + (beta(3,1,2) + beta(3,2,1)) * (beta(1,2,3) + beta(1,3,2))
 
 1862      hrs_hv = (
m_one   / 35.0_real64)  * hrs_a &
 
 1863        + (
m_four  / 105.0_real64) * hrs_b1 &
 
 1864        - (
m_one   / 35.0_real64)  * hrs_b2 &
 
 1865        + (
m_two   / 105.0_real64) * hrs_c1 &
 
 1866        - (
m_one   / 35.0_real64)  * hrs_c2 &
 
 1867        + (
m_three / 35.0_real64)  * hrs_c3 &
 
 1868        - (
m_one   / 105.0_real64) * hrs_d1 &
 
 1869        - (
m_one   / 105.0_real64) * hrs_d2 &
 
 1870        + (
m_two   / 35.0_real64)  * hrs_d3 &
 
 1871        + (
m_one   / 35.0_real64)  * hrs_e1 &
 
 1872        - (
m_one   / 105.0_real64) * hrs_e2
 
subroutine out_dielectric_constant()
epsilon = 1 + 4 * pi * alpha/volume
 
subroutine calc_beta_hrs(box, beta, HRS_VV, HRS_HV)
calculate hyper-Rayleigh scattering hyperpolarizabilities SJ Cyvin, JE Rauch, and JC Decius,...
 
subroutine out_circular_dichroism()
See D Varsano, LA Espinosa Leal, Xavier Andrade, MAL Marques, Rosa di Felice, Angel Rubio,...
 
subroutine out_magnetooptics
 
subroutine out_susceptibility()
 
subroutine dcalc_properties_linear(em_vars, namespace, space, gr, kpoints, st, hm, xc, ions, outp)
 
subroutine out_wfn_and_densities()
 
subroutine drun_sternheimer(em_vars, namespace, space, gr, kpoints, st, hm, mc, ions)
 
subroutine out_polarizability()
 
subroutine dcalc_properties_nonlinear(em_vars, namespace, space, gr, st, hm, xc)
 
subroutine zrun_sternheimer(em_vars, namespace, space, gr, kpoints, st, hm, mc, ions)
 
subroutine cross_section_header(out_file)
Note: this should be in spectrum.F90.
 
subroutine zcalc_properties_nonlinear(em_vars, namespace, space, gr, st, hm, xc)
 
subroutine zcalc_properties_linear(em_vars, namespace, space, gr, kpoints, st, hm, xc, ions, outp)
 
This is the common interface to a sorting routine. It performs the shell algorithm,...
 
subroutine, public born_charges_end(this)
 
subroutine, public born_output_charges(this, atom, charge, natoms, namespace, dim, dirname, write_real)
 
subroutine, public born_charges_init(this, namespace, natoms, val_charge, qtot, dim)
 
integer pure function, public magn_dir(dir, ind)
 
subroutine, public dlr_calc_elf(st, space, gr, kpoints, lr, lr_m)
 
subroutine, public zlr_calc_elf(st, space, gr, kpoints, lr, lr_m)
 
character(len=12) function, public freq2str(freq)
 
integer, parameter perturbation_magnetic
 
subroutine em_resp_run_legacy(sys, fromScratch)
 
subroutine, public out_hyperpolarizability(box, beta, freq_factor, converged, dirname, namespace)
Ref: David M Bishop, Rev Mod Phys 62, 343 (1990) beta generalized to lack of Kleinman symmetry.
 
subroutine, public em_resp_run(system, from_scratch)
 
subroutine em_resp_output(st, namespace, space, gr, hm, ions, outp, sh, em_vars, iomega, ifactor)
 
integer, parameter perturbation_none
 
real(real64), parameter, public m_two
 
real(real64), parameter, public m_huge
 
real(real64), parameter, public m_zero
 
real(real64), parameter, public m_four
 
real(real64), parameter, public m_third
 
real(real64), parameter, public m_pi
some mathematical constants
 
complex(real64), parameter, public m_z0
 
complex(real64), parameter, public m_zi
 
real(real64), parameter, public m_epsilon
 
character(len= *), parameter, public em_resp_dir
 
real(real64), parameter, public m_half
 
real(real64), parameter, public p_c
Electron gyromagnetic ratio, see Phys. Rev. Lett. 130, 071801 (2023)
 
real(real64), parameter, public m_one
 
real(real64), parameter, public m_three
 
real(real64), parameter, public m_five
 
This module implements the underlying real-space grid.
 
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)
 
character(len=100) function, public kdotp_wfs_tag(dir, dir2)
 
subroutine, public zlr_orth_response(mesh, st, lr, omega)
 
subroutine, public lr_copy(st, mesh, src, dest)
 
subroutine, public lr_allocate(lr, st, mesh, allocate_rho)
 
subroutine, public lr_init(lr)
 
subroutine, public lr_dealloc(lr)
 
subroutine, public dlr_orth_response(mesh, st, lr, omega)
 
System information (time, memory, sysname)
 
This module defines various routines, operating on mesh functions.
 
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=68), parameter, public hyphens
 
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_experimental(name, namespace)
 
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
 
type(mpi_grp_t), public mpi_world
 
This module handles the communicators for the various parallelization strategies.
 
This module implements the basic mulsisystem class, a container system for other systems.
 
this module contains the low-level part of the output system
 
this module contains the output system
 
subroutine, public zoutput_lr(outp, namespace, space, dir, st, mesh, lr, idir, isigma, ions, pert_unit)
 
subroutine, public doutput_lr(outp, namespace, space, dir, st, mesh, lr, idir, isigma, ions, pert_unit)
 
integer function, public parse_block(namespace, name, blk, check_varinfo_)
 
integer, parameter, public restart_kdotp
 
integer, parameter, public restart_gs
 
integer, parameter, public restart_type_load
 
integer, parameter, public smear_fixed_occ
 
logical pure function, public smear_is_semiconducting(this)
 
This module is intended to contain "only mathematical" functions and procedures.
 
pure logical function, public states_are_complex(st)
 
pure logical function, public states_are_real(st)
 
This module handles spin dimensions of the states and the k-point distribution.
 
subroutine, public states_elec_deallocate_wfns(st)
Deallocates the KS wavefunctions defined within a states_elec_t structure.
 
This module handles reading and writing restart information for the states_elec_t.
 
subroutine, public states_elec_look_and_load(restart, namespace, space, st, mesh, kpoints, is_complex, packed)
 
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...
 
character(len=100) function, public wfs_tag_sigma(namespace, base_name, isigma)
 
subroutine, public sternheimer_unset_kxc(this)
 
subroutine, public sternheimer_end(this)
 
subroutine, public sternheimer_build_kxc(this, namespace, mesh, st, xc)
 
subroutine, public sternheimer_init(this, namespace, space, gr, st, hm, ks, mc, wfs_are_cplx, set_ham_var, set_occ_response, set_last_occ_response, occ_response_by_sternheimer)
 
character(len=80) function, public str_center(s_in, l_in)
puts space around string, so that it is centered
 
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
 
character(len=20) pure function, public units_abbrev(this)
 
This module defines the unit system, used for input and output.
 
type(unit_t), public unit_ppm
Parts per million.
 
type(unit_system_t), public units_out
 
type(unit_t), public unit_susc_ppm_cgs
Some magnetic stuff.
 
type(unit_system_t), public units_inp
the units systems for reading and writing
 
type(unit_t), public unit_one
some special units required for particular quantities
 
This module is intended to contain simple general-purpose utility functions and procedures.
 
subroutine, public output_tensor(tensor, ndim, unit, write_average, iunit, namespace)
 
character pure function, public index2axis(idir)
 
subroutine, public v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
 
class to tell whether a point is inside or outside
 
Class describing the electron system.
 
Description of the grid, containing information on derivatives, stencil, and symmetries.
 
Container class for lists of system_oct_m::system_t.
 
The states_elec_t class contains all electronic wave functions.