34  use, 
intrinsic :: iso_fortran_env
 
   68    integer(int64) :: type
 
   71    real(real64)       :: line_tol
 
   72    real(real64)       :: fire_mass
 
   73    integer     :: fire_integrator
 
   74    real(real64)       :: tolgrad
 
   77    integer     :: what2minimize
 
   81    type(ions_t),             
pointer :: ions
 
   82    type(hamiltonian_elec_t), 
pointer :: hm
 
   83    type(electrons_t),        
pointer :: syst
 
   84    class(mesh_t),            
pointer :: mesh
 
   85    type(states_elec_t),      
pointer :: st
 
   87    integer                           :: periodic_dim
 
   89    integer                           :: fixed_atom = 0
 
   90    type(restart_t)                   :: restart_dump
 
   92    real(real64), 
allocatable         :: cell_force(:,:)
 
   93    logical                           :: symmetrize = .false.
 
   94    real(real64), 
allocatable         :: initial_length(:)
 
   95    real(real64), 
allocatable         :: initial_rlattice(:,:)
 
   96    real(real64), 
allocatable         :: inv_initial_rlattice(:,:)
 
   99  type(geom_opt_t), 
save :: g_opt
 
  101  integer, 
parameter :: &
 
  102    MINWHAT_ENERGY = 1, &
 
  105  integer, 
parameter ::   &
 
  114    class(*),        
intent(inout) :: system
 
  115    logical,         
intent(inout) :: from_scratch
 
  121      message(1) = 
"CalculationMode = go not implemented for multi-system calculations" 
  132    type(electrons_t),   
target, 
intent(inout) :: sys
 
  133    logical,                     
intent(inout) :: fromscratch
 
  136    real(real64), 
allocatable :: coords(:)
 
  137    real(real64) :: energy
 
  139    real(real64), 
allocatable :: mass(:)
 
  140    integer :: iatom, imass
 
  141    type(restart_t) :: restart_load
 
  145    if (sys%space%periodic_dim == 1 .or. sys%space%periodic_dim == 2) 
then 
  146      message(1) = 
"Geometry optimization not allowed for systems periodic in 1D and 2D, " 
  147      message(2) = 
"as in those cases the total energy is not correct." 
  152    if (sys%hm%pcm%run_pcm) 
then 
  156    if (sys%kpoints%use_symmetries) 
then 
  160    call init_(fromscratch)
 
  163    if (.not. fromscratch) 
then 
  166        call states_elec_load(restart_load, sys%namespace, sys%space, sys%st, sys%gr, sys%kpoints, ierr)
 
  170        message(1) = 
"Unable to read wavefunctions: Starting from scratch." 
  176    call scf_init(g_opt%scfv, sys%namespace, sys%gr, sys%ions, sys%st, sys%mc, sys%hm, sys%space)
 
  179      if (.not. g_opt%scfv%calc_stress) 
then 
  180        message(1) = 
"In order to optimize the cell, one needs to set SCFCalculeStress = yes." 
  185    if (fromscratch) 
then 
  186      call lcao_run(sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st, sys%ks, sys%hm, lmm_r = g_opt%scfv%lmm_r)
 
  191      call v_ks_h_setup(sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st, sys%ks, sys%hm)
 
  194    g_opt%symmetrize = sys%kpoints%use_symmetries .or. sys%st%symmetrize_density
 
  197    safe_allocate(coords(1:g_opt%size))
 
  200    if (sys%st%pack_states .and. sys%hm%apply_packed()) 
call sys%st%pack()
 
  203    select case (g_opt%method)
 
  205      call minimize_multidim_nograd(g_opt%method, g_opt%size, coords, real(g_opt%step, real64) ,&
 
  206        real(g_opt%toldr, real64) , g_opt%max_iter, &
 
  210      safe_allocate(mass(1:g_opt%size))
 
  211      mass = g_opt%fire_mass
 
  213      do iatom = 1, sys%ions%natoms
 
  214        if (g_opt%fixed_atom == iatom) cycle
 
  215        if (g_opt%ions%fixed(iatom)) cycle
 
  216        if (g_opt%fire_mass <= 
m_zero) mass(imass:imass + 2) = sys%ions%mass(iatom)
 
  221      call minimize_fire(g_opt%size, coords, real(g_opt%step, real64) , real(g_opt%tolgrad, real64) , &
 
  223      safe_deallocate_a(mass)
 
  226      call minimize_multidim(g_opt%method, g_opt%size, coords, real(g_opt%step, real64) ,&
 
  227        real(g_opt%line_tol, real64) , 
real(g_opt%tolgrad, real64) , 
real(g_opt%toldr, real64) , g_opt%max_iter, &
 
  228        calc_point, write_iter_info, energy, ierr)
 
  231    if (ierr == 1025) 
then 
  233      message(1) = 
"Reached maximum number of iterations allowed by GOMaxIter." 
  235    else if (ierr /= 0) 
then 
  236      message(1) = 
"Error occurred during the GSL minimization procedure:" 
  241    if (sys%st%pack_states .and. sys%hm%apply_packed()) 
call sys%st%unpack()
 
  245    message(1) = 
"Writing final coordinates to min.xyz" 
  248    call g_opt%ions%write_xyz(
'./min')
 
  250    safe_deallocate_a(coords)
 
  253    call g_opt%scfv%criterion_list%empty()
 
  260    subroutine init_(fromscratch)
 
  261      logical,  
intent(inout) :: fromscratch
 
  263      logical :: center, does_exist
 
  264      integer :: iter, iatom, idir
 
  265      character(len=100) :: filename
 
  266      real(real64) :: default_toldr
 
  267      real(real64) :: default_step
 
  272      if (sys%space%is_periodic()) 
then 
  297      write(
message(1),
'(a)') 
'Input: [GOType = ' 
  298      if (
bitand(g_opt%type, go_ions) /= 0) 
then 
  302        if (len_trim(
message(1)) > 16) 
then 
  308        if (len_trim(
message(1)) > 16) 
then 
  317        message(1) = 
"Cell and volume optimization cannot be used simultaneously." 
  331          message(1) = 
"Cell dynamics not supported on GPUs." 
  337      do iatom = 1, sys%ions%natoms
 
  338        select type(spec=>sys%ions%atom(iatom)%species)
 
  340          write(
message(1),
'(a)') 
"Geometry optimization for all-electron potential is not implemented." 
  350      g_opt%ions   => sys%ions
 
  354      g_opt%dim    =  sys%space%dim
 
  355      g_opt%periodic_dim    =  sys%space%periodic_dim
 
  359      if (
bitand(g_opt%type, go_ions) /= 0) 
then 
  360        g_opt%size = g_opt%dim * g_opt%ions%natoms
 
  365        g_opt%size = g_opt%size + (g_opt%periodic_dim +1) * g_opt%periodic_dim / 2
 
  366        safe_allocate(g_opt%cell_force(1:g_opt%periodic_dim, 1:g_opt%periodic_dim))
 
  371        g_opt%size = g_opt%size + g_opt%periodic_dim
 
  372        safe_allocate(g_opt%cell_force(1:g_opt%periodic_dim, 1:1))
 
  374        safe_allocate(g_opt%initial_length(1:g_opt%periodic_dim))
 
  375        do idir = 1, g_opt%periodic_dim
 
  376          g_opt%initial_length(idir) = norm2(g_opt%ions%latt%rlattice(1:g_opt%periodic_dim, idir))
 
  382        safe_allocate(g_opt%initial_rlattice(1:g_opt%periodic_dim, 1:g_opt%periodic_dim))
 
  383        g_opt%initial_rlattice(1:g_opt%periodic_dim, 1:g_opt%periodic_dim) &
 
  384          = g_opt%ions%latt%rlattice(1:g_opt%periodic_dim, 1:g_opt%periodic_dim)
 
  385        safe_allocate(g_opt%inv_initial_rlattice(1:g_opt%periodic_dim, 1:g_opt%periodic_dim))
 
  386        g_opt%inv_initial_rlattice = g_opt%initial_rlattice
 
  387        call lalg_inverse(g_opt%periodic_dim, g_opt%inv_initial_rlattice, 
'dir')
 
  390      assert(g_opt%size > 0)
 
  406        g_opt%size = g_opt%size  - g_opt%dim
 
  411      do iatom = 1, g_opt%ions%natoms
 
  412        if (g_opt%ions%fixed(iatom)) 
then 
  413          g_opt%size = g_opt%size  - g_opt%dim
 
  491        default_toldr = 0.001_real64
 
  493        default_toldr = -
m_one 
  510        call parse_variable(sys%namespace, 
'GOStep', default_step, g_opt%step)
 
  525      call parse_variable(sys%namespace, 
'GOLineTol', 0.1_real64, g_opt%line_tol)
 
  535      call parse_variable(sys%namespace, 
'GOMaxIter', 200, g_opt%max_iter)
 
  536      if (g_opt%max_iter <= 0) 
then 
  537        message(1) = 
"GOMaxIter has to be larger than 0" 
  572      call parse_variable(sys%namespace, 
'GOFireIntegrator', option__gofireintegrator__verlet, g_opt%fire_integrator)
 
  593      call parse_variable(sys%namespace, 
'GOObjective', minwhat_energy, g_opt%what2minimize)
 
  654        if (g_opt%ions%natoms /= xyz%n) 
then 
  655          write(
message(1), 
'(a,i4,a,i4)') 
'I need exactly ', g_opt%ions%natoms, 
' constrains, but I found ', xyz%n
 
  659        do iatom = 1, g_opt%ions%natoms
 
  660          where(abs(xyz%atom(iatom)%x) <= 
m_epsilon)
 
  661            g_opt%ions%atom(iatom)%c = 
m_zero 
  663            g_opt%ions%atom(iatom)%c = 
m_one 
  669        if (g_opt%fixed_atom > 0) 
then 
  673        do iatom = 1, g_opt%ions%natoms
 
  674          g_opt%ions%atom(iatom)%c = 
m_zero 
  678      call io_rm(
"geom/optimization.log", sys%namespace)
 
  680      call io_rm(
"work-geom.xyz", sys%namespace)
 
  682      if (.not. fromscratch) 
then 
  683        inquire(file = 
'./last.xyz', exist = does_exist)
 
  684        if (.not. does_exist) fromscratch = .
true.
 
  687      if (.not. fromscratch) 
call g_opt%ions%read_xyz(
'./last')
 
  692        write(filename, 
'(a,i4.4,a)') 
"geom/go.", iter, 
".xyz" 
  693        inquire(file = trim(filename), exist = does_exist)
 
  695          call io_rm(trim(filename), sys%namespace)
 
  723      safe_deallocate_a(g_opt%cell_force)
 
  734  subroutine calc_point(size, coords, objective, getgrad, df)
 
  735    integer,          
intent(in)    :: size
 
  736    real(real64),     
intent(in)    :: coords(size)
 
  737    real(real64),     
intent(inout) :: objective
 
  738    integer,          
intent(in)    :: getgrad
 
  739    real(real64),     
intent(inout) :: df(size)
 
  741    integer :: iatom, idir, jdir
 
  742    real(real64), 
dimension(g_opt%periodic_dim, g_opt%periodic_dim) :: stress, scaling
 
  747    assert(
size == g_opt%size)
 
  751    if (g_opt%fixed_atom /= 0) 
then 
  752      call g_opt%ions%translate(g_opt%ions%center())
 
  756    call g_opt%ions%fold_atoms_into_cell()
 
  759    do iatom = 1, g_opt%ions%natoms
 
  760      if (.not. g_opt%syst%gr%box%contains_point(g_opt%syst%ions%pos(:, iatom))) 
then 
  761        if (g_opt%syst%space%periodic_dim /= g_opt%syst%space%dim) 
then 
  765          write(
message(1), 
'(a,i5,a)') 
"Atom ", iatom, 
" has moved outside the box during the geometry optimization." 
  771    call g_opt%ions%write_xyz(
'./work-geom', append = .
true.)
 
  778        g_opt%syst%space, g_opt%syst%hm%psolver, g_opt%syst%hm%kpoints, &
 
  779        g_opt%syst%mc, g_opt%syst%st%qtot, g_opt%ions%latt)
 
  783      g_opt%ions, g_opt%syst%ext_partners, g_opt%st)
 
  784    call density_calc(g_opt%st, g_opt%syst%gr, g_opt%st%rho)
 
  785    call v_ks_calc(g_opt%syst%ks, g_opt%syst%namespace, g_opt%syst%space, g_opt%hm, g_opt%st, &
 
  786      g_opt%ions,g_opt%syst%ext_partners, calc_eigenval = .
true.)
 
  787    call energy_calc_total(g_opt%syst%namespace, g_opt%syst%space, g_opt%hm, g_opt%syst%gr, g_opt%st, g_opt%syst%ext_partners)
 
  790    call scf_run(g_opt%scfv, g_opt%syst%namespace, g_opt%syst%space, g_opt%syst%mc, g_opt%syst%gr, &
 
  791      g_opt%ions, g_opt%syst%ext_partners, &
 
  792      g_opt%st, g_opt%syst%ks, g_opt%hm, outp = g_opt%syst%outp, verbosity = 
verb_compact, restart_dump=g_opt%restart_dump)
 
  804      stress = g_opt%syst%st%stress_tensors%total(1:g_opt%periodic_dim, 1:g_opt%periodic_dim)
 
  805      g_opt%cell_force = -stress * g_opt%ions%latt%rcell_volume
 
  808      scaling = matmul(g_opt%ions%latt%rlattice(1:g_opt%periodic_dim,1:g_opt%periodic_dim), g_opt%inv_initial_rlattice)
 
  810      g_opt%cell_force = matmul(g_opt%cell_force, transpose(scaling))
 
  814      g_opt%cell_force = 
m_half * (g_opt%cell_force + transpose(g_opt%cell_force))
 
  819      stress = g_opt%syst%st%stress_tensors%total(1:g_opt%periodic_dim, 1:g_opt%periodic_dim)
 
  820      do idir = 1, g_opt%periodic_dim
 
  821        g_opt%cell_force(idir, 1) = -stress(idir, idir) * g_opt%ions%latt%rcell_volume
 
  828        do idir = 1, g_opt%periodic_dim
 
  830            jdir = 1, g_opt%periodic_dim)
 
  832        call messages_info(1+g_opt%periodic_dim, namespace=g_opt%ions%namespace)
 
  835        do idir = 1, g_opt%periodic_dim
 
  837            jdir = 1, g_opt%periodic_dim)
 
  839        call messages_info(1+g_opt%periodic_dim, namespace=g_opt%ions%namespace)
 
  844    if (getgrad == 1) 
call to_grad(g_opt, df)
 
  848      do iatom = 1, g_opt%ions%natoms
 
  849        if (g_opt%ions%fixed(iatom)) cycle
 
  850        objective = objective + sum(g_opt%ions%tot_force(:, iatom)**2)
 
  853        do idir = 1, g_opt%periodic_dim
 
  854          objective = objective + sum(g_opt%cell_force(:, idir)**2)
 
  858        objective = objective + sum(g_opt%cell_force(:,1)**2)
 
  860      objective = 
sqrt(objective)
 
  862      objective = g_opt%hm%energy%total
 
  876    real(real64)    :: coords(size)
 
  877    real(real64)    :: objective
 
  880    real(real64), 
allocatable :: df(:)
 
  884    assert(
size == g_opt%size)
 
  887    safe_allocate(df(1:size))
 
  890    call calc_point(
size, coords, objective, getgrad, df)
 
  891    safe_deallocate_a(df)
 
  899  subroutine write_iter_info(geom_iter, size, energy, maxdx, maxdf, coords)
 
  900    integer,     
intent(in) :: geom_iter
 
  901    integer,     
intent(in) :: size
 
  902    real(real64),    
intent(in) :: energy, maxdx, maxdf
 
  903    real(real64),    
intent(in) :: coords(size)
 
  905    character(len=256) :: c_geom_iter, title, c_forces_iter
 
  910    write(c_geom_iter, 
'(a,i4.4)') 
"go.", geom_iter
 
  912    call io_mkdir(
'geom', g_opt%ions%namespace)
 
  913    call g_opt%ions%write_xyz(
'geom/'//trim(c_geom_iter), comment = trim(title))
 
  914    call g_opt%ions%write_xyz(
'./last')
 
  916    if(g_opt%periodic_dim > 0) 
then 
  917      call g_opt%ions%write_xyz(
'geom/'//trim(c_geom_iter), comment = 
'Reduced coordinates', reduce_coordinates = .
true.)
 
  919        g_opt%ions%pos, g_opt%ions%atom, g_opt%syst%gr, g_opt%syst%namespace)
 
  922    if (g_opt%syst%outp%what(option__output__forces)) 
then 
  923      write(c_forces_iter, 
'(a,i4.4)') 
"forces.", geom_iter
 
  924      if (
bitand(g_opt%syst%outp%how(option__output__forces), option__outputformat__bild) /= 0) 
then 
  925        call g_opt%ions%write_bild_forces_file(
'forces', trim(c_forces_iter))
 
  928          g_opt%ions%pos, g_opt%ions%atom, g_opt%syst%gr, g_opt%syst%namespace, total_forces=g_opt%ions%tot_force)
 
  933      iunit = 
io_open(trim(
'geom/optimization.log'), g_opt%syst%namespace, &
 
  934        action = 
'write', position = 
'append')
 
  936      if (geom_iter == 1) 
then 
  938          write(iunit, 
'(a10,5(5x,a20),a)') 
'#     iter',
'energy [' // trim(
units_abbrev(
units_out%energy)) // 
']', &
 
  943            ' alpha, beta, gamma [degrees]' 
  945          write(iunit, 
'(a10,3(5x,a20))') 
'#     iter',
'energy [' // trim(
units_abbrev(
units_out%energy)) // 
']', &
 
  959          g_opt%ions%latt%alpha, g_opt%ions%latt%beta, g_opt%ions%latt%gamma
 
  972    call messages_write(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", new_line = .
true.)
 
  981    if (g_opt%periodic_dim == 0) 
then 
  996      call messages_write(maxdx, fmt = 
"f16.10,1x", print_units = .false., new_line = .
true.)
 
  999    call messages_write(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", new_line = .
true.)
 
 1000    call messages_write(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", new_line = .
true.)
 
 1012    real(real64),         
intent(out) :: coords(:)
 
 1014    integer :: iatom, idir, jdir, icoord
 
 1015    real(real64) :: tmp_pos(gopt%dim), strain(g_opt%periodic_dim,g_opt%periodic_dim)
 
 1021    if (
bitand(g_opt%type, go_ions) /= 0) 
then 
 1022      do iatom = 1, gopt%ions%natoms
 
 1023        if (gopt%fixed_atom == iatom) cycle
 
 1024        if (gopt%ions%fixed(iatom)) cycle
 
 1025        tmp_pos = gopt%ions%pos(1:gopt%dim, iatom)
 
 1026        if (gopt%fixed_atom > 0) tmp_pos = tmp_pos - gopt%ions%pos(1:gopt%dim, gopt%fixed_atom)
 
 1027        tmp_pos = gopt%ions%latt%cart_to_red(tmp_pos)
 
 1028        do idir = 1, gopt%dim
 
 1029          coords(icoord) = tmp_pos(idir)
 
 1038      strain = matmul(gopt%ions%latt%rlattice, g_opt%inv_initial_rlattice)
 
 1039      do idir = 1, g_opt%periodic_dim
 
 1040        do jdir = idir, g_opt%periodic_dim
 
 1041          coords(icoord) = strain(idir, jdir)
 
 1049      do idir = 1, g_opt%periodic_dim
 
 1050        coords(icoord) = norm2(gopt%ions%latt%rlattice(1:g_opt%periodic_dim, idir))/g_opt%initial_length(idir)
 
 1061  subroutine to_grad(gopt, grad)
 
 1063    real(real64),      
intent(out) :: grad(:)
 
 1065    integer :: iatom, idir, jdir, icoord
 
 1066    real(real64) :: tmp_force(1:gopt%dim)
 
 1072    if (
bitand(g_opt%type, go_ions) /= 0) 
then 
 1073      do iatom = 1, gopt%ions%natoms
 
 1074        if (gopt%fixed_atom == iatom) cycle
 
 1075        if (gopt%ions%fixed(iatom)) cycle
 
 1076        do idir = 1, gopt%dim
 
 1077          if (abs(gopt%ions%atom(iatom)%c(idir)) <= 
m_epsilon) 
then 
 1078            tmp_force(idir) = -gopt%ions%tot_force(idir, iatom)
 
 1082          if (gopt%fixed_atom > 0) 
then 
 1083            tmp_force(idir) = tmp_force(idir) + gopt%ions%tot_force(idir, gopt%fixed_atom)
 
 1086        tmp_force = gopt%ions%latt%cart_to_red(tmp_force)
 
 1087        do idir = 1, gopt%dim
 
 1088          grad(icoord) = tmp_force(idir)
 
 1096      do idir = 1, g_opt%periodic_dim
 
 1097        do jdir = idir, g_opt%periodic_dim
 
 1098          grad(icoord) = -g_opt%cell_force(idir, jdir)
 
 1106      do idir = 1, g_opt%periodic_dim
 
 1107        grad(icoord) = -g_opt%cell_force(idir, 1)
 
 1120    real(real64),         
intent(in)    :: coords(:)
 
 1122    integer :: iatom, idir, jdir, icoord
 
 1123    real(real64) :: tmp_pos(gopt%dim, gopt%ions%natoms), strain(g_opt%periodic_dim,g_opt%periodic_dim)
 
 1131    if (
bitand(g_opt%type, go_ions) /= 0) 
then 
 1132      do iatom = 1, gopt%ions%natoms
 
 1133        if (gopt%fixed_atom == iatom) cycle
 
 1134        if (gopt%ions%fixed(iatom)) cycle
 
 1135        do idir = 1, gopt%dim
 
 1136          tmp_pos(idir, iatom) = coords(icoord)
 
 1141      do iatom = 1, gopt%ions%natoms
 
 1142        tmp_pos(:, iatom) = gopt%ions%latt%cart_to_red(gopt%ions%pos(:, iatom))
 
 1148      do idir = 1, g_opt%periodic_dim
 
 1149        do jdir = idir, g_opt%periodic_dim
 
 1150          strain(idir, jdir) = coords(icoord)
 
 1158      gopt%ions%latt%rlattice = matmul(strain, g_opt%initial_rlattice)
 
 1162      call gopt%ions%update_lattice_vectors(gopt%ions%latt, gopt%symmetrize)
 
 1167      do idir = 1, g_opt%periodic_dim
 
 1168        gopt%ions%latt%rlattice(1:g_opt%periodic_dim, idir) = coords(icoord) &
 
 1169          * gopt%initial_rlattice(1:g_opt%periodic_dim, idir)
 
 1173      if (gopt%symmetrize) 
then 
 1176      call gopt%ions%update_lattice_vectors(gopt%ions%latt, gopt%symmetrize)
 
 1180    if (
bitand(g_opt%type, go_ions) /= 0) 
then 
 1182      do iatom = 1, gopt%ions%natoms
 
 1183        if (gopt%fixed_atom == iatom) cycle
 
 1184        if (gopt%ions%fixed(iatom)) cycle
 
 1185        tmp_pos(:, iatom) = gopt%ions%latt%red_to_cart(tmp_pos(:, iatom))
 
 1186        do idir = 1, gopt%dim
 
 1187          if (abs(gopt%ions%atom(iatom)%c(idir)) <= 
m_epsilon) 
then 
 1188            gopt%ions%pos(idir, iatom) = tmp_pos(idir, iatom)
 
 1191        if (gopt%fixed_atom > 0) 
then 
 1192          gopt%ions%pos(:, iatom) = gopt%ions%pos(:, iatom) + gopt%ions%pos(:, gopt%fixed_atom)
 
 1196      do iatom = 1, gopt%ions%natoms
 
 1197        gopt%ions%pos(:, iatom) = gopt%ions%latt%red_to_cart(tmp_pos(:, iatom))
 
 1201    if (gopt%symmetrize) 
then 
 1202      call gopt%ions%symmetrize_atomic_coord()
 
 1211    integer,     
intent(in) :: geom_iter
 
 1212    integer,     
intent(in) :: size
 
 1213    real(real64),    
intent(in) :: energy, maxdx
 
 1214    real(real64),    
intent(in) :: coords(size)
 
 1231    integer,          
intent(in)    :: size
 
 1232    real(real64),     
intent(inout) :: rlattice(size,size)
 
 1234    real(real64) :: strain(size,size)
 
 1235    real(real64) :: tol = 1.0e-14_real64
 
 1243    strain = matmul(rlattice, g_opt%inv_initial_rlattice)
 
 1248    if (g_opt%symmetrize) 
then 
 1252      strain = 
m_half * (strain + transpose(strain))
 
 1259    rlattice = matmul(strain, g_opt%initial_rlattice)
 
subroutine init_(fromscratch)
 
Define which routines can be seen from the outside.
 
subroutine minimize_multidim(method, dim, x, step, line_tol, tolgrad, toldr, maxiter, f, write_iter_info, minimum, ierr)
 
subroutine minimize_fire(dim, x, step, tolgrad, maxiter, f, write_iter_info, en, ierr, mass, integrator)
Implementation of the Fast Inertial Relaxation Engine (FIRE)
 
pure logical function, public accel_is_enabled()
 
type(debug_t), save, public debug
 
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 energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit, full)
This subroutine calculates the total energy of the system. Basically, it adds up the KS eigenvalues,...
 
subroutine, public geom_opt_run(system, from_scratch)
 
subroutine symmetrize_lattice_vectors(g_opt, size, rlattice)
Given a symmetric lattice vector, symmetrize another one.
 
subroutine calc_point_ng(size, coords, objective)
Same as calc_point, but without the gradients. No intents here is unfortunately required because the ...
 
subroutine to_grad(gopt, grad)
Transfer data from the forces to the work array for the gradients (grad)
 
integer, parameter go_cell
 
integer, parameter minwhat_forces
 
subroutine write_iter_info_ng(geom_iter, size, energy, maxdx, coords)
Same as write_iter_info, but without the gradients.
 
subroutine write_iter_info(geom_iter, size, energy, maxdx, maxdf, coords)
Output the information after each iteration of the geometry optimization.
 
subroutine calc_point(size, coords, objective, getgrad, df)
Note: you might think it would be better to change the arguments with '(size)' below to '(:)'....
 
subroutine to_coords(gopt, coords)
Transfer the data from the data structures to the work array (coords)
 
integer, parameter go_volume
 
subroutine from_coords(gopt, coords)
Transfer the data from the work array (coords) to the actual data structures.
 
subroutine geom_opt_run_legacy(sys, fromscratch)
 
real(real64), parameter, public m_zero
 
real(real64), parameter, public m_epsilon
 
real(real64), parameter, public m_half
 
real(real64), parameter, public m_one
 
subroutine, public hamiltonian_elec_epot_generate(this, namespace, space, gr, ions, ext_partners, st, time)
 
subroutine, public write_xsf_geometry_file(dir, fname, space, latt, pos, atoms, mesh, namespace, total_forces)
 
subroutine, public io_close(iunit, grp)
 
subroutine, public io_rm(fname, namespace)
 
subroutine, public io_mkdir(fname, namespace, parents)
 
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
 
subroutine, public electrons_lattice_vectors_update(namespace, gr, space, psolver, kpoints, mc, qtot, new_latt)
 
subroutine, public lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r)
 
This module is intended to contain "only mathematical" functions and procedures.
 
subroutine, public dzero_small_elements_matrix(nn, aa, tol)
 
This module defines the meshes, which are used in Octopus.
 
subroutine, public messages_not_implemented(feature, namespace)
 
subroutine, public messages_warning(no_lines, all_nodes, namespace)
 
subroutine, public messages_obsolete_variable(namespace, name, rep)
 
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
 
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)
 
integer minmethod_nmsimplex
 
logical function mpi_grp_is_root(grp)
 
type(mpi_grp_t), public mpi_world
 
This module implements the basic mulsisystem class, a container system for other systems.
 
logical function, public parse_is_defined(namespace, name)
 
integer, parameter, public read_coords_err
for read_coords_info::file_type
 
subroutine, public read_coords_init(gf)
 
subroutine, public read_coords_end(gf)
 
subroutine, public read_coords_read(what, gf, space, namespace)
 
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
 
integer, parameter, public restart_type_load
 
subroutine, public restart_end(restart)
 
subroutine, public scf_print_mem_use(namespace)
 
subroutine, public scf_mix_clear(scf)
 
subroutine, public scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, verbosity, iters_done, restart_load, restart_dump)
 
integer, parameter, public verb_compact
 
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
 
subroutine, public scf_end(scf)
 
subroutine, public states_elec_deallocate_wfns(st)
Deallocates the KS wavefunctions defined within a states_elec_t structure.
 
subroutine, public states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
Allocates 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_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 dsymmetrize_tensor_cart(symm, tensor, use_non_symmorphic)
Symmetric a rank-2 tensor defined in Cartesian space.
 
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_femtosecond
Time in femtoseconds.
 
type(unit_t), public unit_amu
Mass in atomic mass units (AKA Dalton).
 
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)
 
An abstract type for all electron species.
 
Class describing the electron system.
 
Container class for lists of system_oct_m::system_t.