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
91 real(real64),
allocatable :: cell_force(:, :)
92 logical :: symmetrize = .false.
93 real(real64),
allocatable :: initial_length(:)
94 real(real64),
allocatable :: initial_rlattice(:, :)
95 real(real64),
allocatable :: inv_initial_rlattice(:, :)
96 real(real64) :: pressure =
m_zero
98 logical :: poscar_output = .false.
101 integer :: calculator
102 logical :: ml_preopt = .false.
105 type(geom_opt_t),
save :: g_opt
107 integer,
parameter :: &
108 MINWHAT_ENERGY = 1, &
111 integer,
parameter :: &
116 integer,
parameter :: &
117 GO_CALCULATOR_INTERNAL = 1, &
123 subroutine mattersim_paths(mattersim_share, mattersim_python, namespace)
124 character(len=*),
intent(out) :: mattersim_share, mattersim_python
125 type(namespace_t),
intent(in) :: namespace
127 logical :: python_exists
131 mattersim_share = trim(
conf%share)
132 mattersim_python = trim(mattersim_share) //
"/mattersim_env/bin/python"
133 inquire(file=trim(mattersim_python), exist=python_exists)
134 if (python_exists)
return
136 mattersim_share = share_dir
137 mattersim_python = trim(mattersim_share) //
"/mattersim_env/bin/python"
138 inquire(file=trim(mattersim_python), exist=python_exists)
139 if (python_exists)
return
141 message(1) =
'Unable to find the MatterSim Python environment.'
142 message(2) =
'Please install Octopus with MatterSim support before using the MatterSim calculator.'
148 class(*),
intent(inout) :: system
149 logical,
intent(inout) :: from_scratch
155 message(1) =
"CalculationMode = go not implemented for multi-system calculations"
167 logical,
intent(inout) :: fromscratch
170 real(real64),
allocatable :: coords(:)
171 real(real64) :: energy
173 real(real64),
allocatable :: mass(:)
174 integer :: iatom, imass
176 logical :: known_lower_bound
177 logical :: default_val
183 if (sys%space%periodic_dim == 1)
then
184 message(1) =
"Geometry optimization is not allowed for systems periodic in 1D, "
185 message(2) =
"as the ion-ion interaction and the stress tensor are not available."
189 if (sys%space%periodic_dim == 2)
then
194 if (sys%hm%pcm%run_pcm)
then
198 if (sys%kpoints%use_symmetries)
then
202 g_opt%symmetrize = sys%kpoints%use_symmetries .or. sys%st%symmetrize_density
204 call init_(fromscratch)
207 if (.not. fromscratch)
then
210 call states_elec_load(restart_load, sys%namespace, sys%space, sys%st, sys%gr, sys%kpoints, &
211 fixed_occ=.false., ierr=ierr)
213 call restart_load%end()
215 message(1) =
"Unable to read wavefunctions: Starting from scratch."
221 call scf_init(g_opt%scfv, sys%namespace, sys%gr, sys%ions, sys%st, sys%mc, sys%hm, sys%space)
224 if (.not. g_opt%scfv%calc_stress)
then
225 message(1) =
"In order to optimize the cell, one needs to set SCFCalculateStress = yes."
230 if (fromscratch)
then
231 call lcao_run(sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st, sys%ks, sys%hm, &
232 lmm_r = g_opt%scfv%lmm_r, known_lower_bound=known_lower_bound)
236 message(1) =
'Info: Setting up Hamiltonian.'
238 call v_ks_h_setup(sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st, sys%ks, sys%hm)
243 safe_allocate(coords(1:g_opt%size))
246 if (sys%st%pack_states .and. sys%hm%apply_packed())
call sys%st%pack()
249 select case (g_opt%method)
251 call minimize_multidim_nograd(g_opt%method, g_opt%size, coords, g_opt%step,&
252 g_opt%toldr, g_opt%max_iter, &
257 safe_allocate(mass(1:g_opt%size))
258 mass = g_opt%fire_mass
260 do iatom = 1, sys%ions%natoms
261 if (g_opt%fixed_atom == iatom) cycle
262 if (g_opt%ions%fixed(iatom)) cycle
263 if (g_opt%fire_mass <=
m_zero) mass(imass:imass + 2) = sys%ions%mass(iatom)
264 imass = imass + g_opt%dim
268 call minimize_fire(g_opt%size, g_opt%ions%space%dim, coords, g_opt%step, g_opt%tolgrad, &
271 safe_deallocate_a(mass)
274 call minimize_multidim(g_opt%method, g_opt%size, coords, g_opt%step ,&
275 g_opt%line_tol , g_opt%tolgrad, g_opt%toldr, g_opt%max_iter, &
280 if (ierr == 1025)
then
282 message(1) =
"Reached maximum number of iterations allowed by GOMaxIter."
285 message(1) =
"Error occurred during the GSL minimization procedure:"
290 if (sys%st%pack_states .and. sys%hm%apply_packed())
call sys%st%unpack()
294 message(1) =
"Writing final coordinates to min.xyz"
297 call g_opt%ions%write_xyz(
'./min')
299 safe_deallocate_a(coords)
302 call g_opt%scfv%criterion_list%empty()
309 subroutine init_(fromscratch)
310 logical,
intent(inout) :: fromscratch
312 logical :: center, does_exist
313 integer :: iter, iatom, idir
314 character(len=100) :: filename
315 real(real64) :: default_toldr
316 real(real64) :: default_step
321 if (sys%space%is_periodic())
then
349 write(
message(1),
'(a)')
'Input: [GOType = '
350 if (
bitand(g_opt%type, go_ions) /= 0)
then
354 if (len_trim(
message(1)) > 16)
then
360 if (len_trim(
message(1)) > 16)
then
369 message(1) =
"Cell and volume optimization cannot be used simultaneously."
381 do iatom = 1, sys%ions%natoms
382 select type(spec=>sys%ions%atom(iatom)%species)
384 write(
message(1),
'(a)')
"Geometry optimization for all-electron potential is not implemented."
394 g_opt%ions => sys%ions
398 g_opt%dim = sys%space%dim
399 g_opt%periodic_dim = sys%space%periodic_dim
403 if (
bitand(g_opt%type, go_ions) /= 0)
then
404 g_opt%size = g_opt%dim * g_opt%ions%natoms
409 g_opt%size = g_opt%size + (g_opt%periodic_dim +1) * g_opt%periodic_dim / 2
410 safe_allocate(g_opt%cell_force(1:g_opt%periodic_dim, 1:g_opt%periodic_dim))
415 g_opt%size = g_opt%size + g_opt%periodic_dim
416 safe_allocate(g_opt%cell_force(1:g_opt%periodic_dim, 1:1))
418 safe_allocate(g_opt%initial_length(1:g_opt%periodic_dim))
419 do idir = 1, g_opt%periodic_dim
420 g_opt%initial_length(idir) = norm2(g_opt%ions%latt%rlattice(1:g_opt%periodic_dim, idir))
426 safe_allocate(g_opt%initial_rlattice(1:g_opt%periodic_dim, 1:g_opt%periodic_dim))
427 g_opt%initial_rlattice(1:g_opt%periodic_dim, 1:g_opt%periodic_dim) &
428 = g_opt%ions%latt%rlattice(1:g_opt%periodic_dim, 1:g_opt%periodic_dim)
429 safe_allocate(g_opt%inv_initial_rlattice(1:g_opt%periodic_dim, 1:g_opt%periodic_dim))
430 g_opt%inv_initial_rlattice(:, :) = g_opt%initial_rlattice(:, :)
431 call lalg_inverse(g_opt%periodic_dim, g_opt%inv_initial_rlattice,
'dir')
434 if(g_opt%ions%space%is_periodic())
then
450 if (center .and.
bitand(g_opt%type, go_ions) /= 0)
then
452 g_opt%size = g_opt%size - g_opt%dim
457 do iatom = 1, g_opt%ions%natoms
458 if (g_opt%ions%fixed(iatom) .and.
bitand(g_opt%type, go_ions) /= 0)
then
459 g_opt%size = g_opt%size - g_opt%dim
463 assert(g_opt%size > 0)
539 default_toldr = 0.001_real64
541 default_toldr = -
m_one
558 call parse_variable(sys%namespace,
'GOStep', default_step, g_opt%step)
573 call parse_variable(sys%namespace,
'GOLineTol', 0.1_real64, g_opt%line_tol)
583 call parse_variable(sys%namespace,
'GOMaxIter', 200, g_opt%max_iter)
584 if (g_opt%max_iter <= 0)
then
585 message(1) =
"GOMaxIter has to be larger than 0"
622 call parse_variable(sys%namespace,
'GOFireIntegrator', option__gofireintegrator__verlet, g_opt%fire_integrator)
643 call parse_variable(sys%namespace,
'GOObjective', minwhat_energy, g_opt%what2minimize)
704 if (g_opt%ions%natoms /= xyz%n)
then
705 write(
message(1),
'(a,i4,a,i4)')
'I need exactly ', g_opt%ions%natoms,
' constrains, but I found ', xyz%n
709 do iatom = 1, g_opt%ions%natoms
710 where(abs(xyz%atom(iatom)%x) <=
m_epsilon)
711 g_opt%ions%atom(iatom)%c =
m_zero
713 g_opt%ions%atom(iatom)%c =
m_one
720 if (g_opt%fixed_atom > 0)
then
724 do iatom = 1, g_opt%ions%natoms
725 g_opt%ions%atom(iatom)%c =
m_zero
744 call parse_variable(sys%namespace,
'GOCalculator', go_calculator_internal, g_opt%calculator)
748#ifndef HAVE_MATTERSIM
750 message(1) =
'Octopus was not compiled with support for MatterSim'
773 if (sys%space%periodic_dim /= 3 .and. &
776 default_val = .false.
778 call parse_variable(sys%namespace,
'GOMLPreoptimize', default_val, g_opt%ml_preopt)
779#ifndef HAVE_MATTERSIM
780 if (g_opt%ml_preopt)
then
781 message(1) =
'Octopus was not compiled with support for MatterSim'
786 call io_mkdir(
'geom', sys%namespace)
788 if (g_opt%ml_preopt)
then
793 call io_rm(
"geom/optimization.log", sys%namespace)
795 call io_rm(
"work-geom.xyz", sys%namespace)
797 if (.not. fromscratch)
then
798 inquire(file =
'./last.xyz', exist = does_exist)
799 if (.not. does_exist) fromscratch = .
true.
802 if (.not. fromscratch)
call g_opt%ions%read_xyz(
'./last')
807 write(filename,
'(a,i4.4,a)')
"geom/go.", iter,
".xyz"
808 inquire(file = trim(filename), exist = does_exist)
810 call io_rm(trim(filename), sys%namespace)
811 if (sys%space%periodic_dim > 0)
then
812 write(filename,
'(a,i4.4,a)')
"geom/go.", iter,
".xyz_red"
813 call io_rm(trim(filename), sys%namespace)
814 write(filename,
'(a,i4.4,a)')
"geom/go.", iter,
".xsf"
815 call io_rm(trim(filename), sys%namespace)
836 call g_opt%scfv%restart_dump%end()
844 safe_deallocate_a(g_opt%cell_force)
855 subroutine calc_point(size, coords, objective, getgrad, df)
856 integer,
intent(in) :: size
857 real(real64),
intent(in) :: coords(size)
858 real(real64),
intent(inout) :: objective
859 integer,
intent(in) :: getgrad
860 real(real64),
intent(inout) :: df(size)
862 integer :: iatom, idir, jdir, iunit, command_status, command_exit
863 real(real64),
dimension(g_opt%periodic_dim, g_opt%periodic_dim) :: stress, strain, right_stretch, inv_right_stretch, &
866 character(len=MAX_PATH_LEN) :: cmd, mattersim_share, mattersim_python
870 assert(
size == g_opt%size)
880 if (g_opt%fixed_atom /= 0)
then
881 call g_opt%ions%translate(g_opt%ions%center())
886 call g_opt%ions%fold_atoms_into_cell()
889 do iatom = 1, g_opt%ions%natoms
890 if (.not. g_opt%syst%gr%box%contains_point(g_opt%ions%pos(:, iatom)))
then
891 if (g_opt%syst%space%periodic_dim /= g_opt%syst%space%dim)
then
895 write(
message(1),
'(a,i5,a)')
"Atom ", iatom,
" has moved outside the box during the geometry optimization."
901 if (g_opt%calculator==go_calculator_internal)
then
902 call g_opt%ions%write_xyz(
'./work-geom', append = .
true.)
904 if (g_opt%ions%space%is_periodic())
then
905 call write_extended_xyz_file(
'.',
'work-geom', g_opt%ions%space, g_opt%ions%latt, g_opt%ions%pos, g_opt%ions%atom, &
906 g_opt%syst%gr%box, g_opt%syst%namespace)
908 call g_opt%ions%write_xyz(
'./work-geom', append = .false.)
915 g_opt%syst%space, g_opt%syst%hm%psolver, g_opt%syst%hm%kpoints, &
916 g_opt%syst%mc, g_opt%syst%st%qtot, g_opt%ions%latt)
920 if (g_opt%ions%force_total_enforce)
then
927 select case (g_opt%calculator)
928 case (go_calculator_internal)
932 g_opt%ions, g_opt%syst%ext_partners, g_opt%st)
933 call density_calc(g_opt%st, g_opt%syst%gr, g_opt%st%rho)
934 call v_ks_calc(g_opt%syst%ks, g_opt%syst%namespace, g_opt%syst%space, g_opt%hm, g_opt%st, &
935 g_opt%ions,g_opt%syst%ext_partners, calc_eigenval = .
true.)
936 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)
939 call scf_run(g_opt%scfv, g_opt%syst%namespace, g_opt%syst%space, g_opt%syst%mc, g_opt%syst%gr, &
940 g_opt%ions, g_opt%syst%ext_partners, &
941 g_opt%st, g_opt%syst%ks, g_opt%hm, outp = g_opt%syst%outp, verbosity =
verb_compact, restart_dump=g_opt%scfv%restart_dump)
946 call mattersim_paths(mattersim_share, mattersim_python, g_opt%syst%namespace)
950 cmd = trim(mattersim_python) //
" -I " // trim(mattersim_share) &
951 //
"/scripts/run_mattersim.py work-geom.xyz ml_forces.xyz " // trim(mattersim_share)
952 call execute_command_line(trim(cmd), exitstat=command_exit, cmdstat=command_status)
953 if (command_status == 0) command_status = command_exit
955 call mpi_world%bcast(command_status, 1, mpi_integer, 0)
956 if (command_status /= 0)
then
957 write(
message(1),
'(a,i0)')
'MatterSim force calculation failed with exit status ', command_status
964 read(iunit, *) g_opt%hm%energy%total
965 do iatom = 1, g_opt%ions%natoms
966 read(iunit,*) g_opt%ions%tot_force(:, iatom)
971 read(iunit,*) g_opt%syst%st%stress_tensors%total(:, idir)
988 stress = -g_opt%syst%st%stress_tensors%total(1:g_opt%periodic_dim, 1:g_opt%periodic_dim)
992 strain = matmul(g_opt%ions%latt%rlattice(1:g_opt%periodic_dim,1:g_opt%periodic_dim), g_opt%inv_initial_rlattice)
994 inv_right_stretch = right_stretch
995 call lalg_inverse(g_opt%periodic_dim, inv_right_stretch,
'dir')
996 rotation = matmul(strain, inv_right_stretch)
1001 sym_stress = matmul(transpose(rotation), matmul(stress, rotation))
1002 sym_stress =
m_half*(sym_stress + transpose(sym_stress)) * det
1006 do idir = 1, g_opt%periodic_dim
1007 sym_stress(idir, idir) = sym_stress(idir, idir) - g_opt%pressure
1009 g_opt%cell_force = sym_stress * g_opt%ions%latt%rcell_volume
1011 g_opt%cell_force = matmul(g_opt%cell_force, inv_right_stretch)
1014 g_opt%cell_force =
m_half*(g_opt%cell_force + transpose(g_opt%cell_force))
1019 stress = g_opt%syst%st%stress_tensors%total(1:g_opt%periodic_dim, 1:g_opt%periodic_dim)
1020 do idir = 1, g_opt%periodic_dim
1021 g_opt%cell_force(idir, 1) = -(g_opt%pressure + stress(idir, idir)) * g_opt%ions%latt%rcell_volume
1027 do idir = 1, g_opt%periodic_dim
1029 jdir = 1, g_opt%periodic_dim)
1031 call messages_info(1+g_opt%periodic_dim, namespace=g_opt%ions%namespace, debug_only=.
true.)
1033 do idir = 1, ubound(g_opt%cell_force, 2)
1035 jdir = 1, g_opt%periodic_dim)
1037 call messages_info(1+g_opt%periodic_dim, namespace=g_opt%ions%namespace, debug_only=.
true.)
1042 if (getgrad == 1)
call to_grad(g_opt, df)
1046 do iatom = 1, g_opt%ions%natoms
1047 if (g_opt%ions%fixed(iatom)) cycle
1048 objective = objective + sum(g_opt%ions%tot_force(:, iatom)**2)
1051 do idir = 1, g_opt%periodic_dim
1052 objective = objective + sum(g_opt%cell_force(:, idir)**2)
1056 objective = objective + sum(g_opt%cell_force(:,1)**2)
1058 objective =
sqrt(objective)
1060 objective = g_opt%hm%energy%total
1074 real(real64) :: coords(size)
1075 real(real64) :: objective
1078 real(real64),
allocatable :: df(:)
1082 assert(
size == g_opt%size)
1085 safe_allocate(df(1:size))
1088 call calc_point(
size, coords, objective, getgrad, df)
1089 safe_deallocate_a(df)
1097 subroutine write_iter_info(geom_iter, size, energy, maxdx, maxdf, coords)
1098 integer,
intent(in) :: geom_iter
1099 integer,
intent(in) :: size
1100 real(real64),
intent(in) :: energy, maxdx, maxdf
1101 real(real64),
intent(in) :: coords(size)
1103 character(len=256) :: c_geom_iter, title, c_forces_iter
1108 write(c_geom_iter,
'(a,i4.4)')
"go.", geom_iter
1110 call g_opt%ions%write_xyz(
'geom/'//trim(c_geom_iter), comment = trim(title))
1111 call g_opt%ions%write_xyz(
'./last')
1113 if(g_opt%periodic_dim > 0)
then
1114 call g_opt%ions%write_xyz(
'geom/'//trim(c_geom_iter), comment =
'Reduced coordinates', reduce_coordinates = .
true.)
1116 g_opt%ions%pos, g_opt%ions%atom, g_opt%syst%gr, g_opt%syst%namespace)
1119 if (g_opt%syst%outp%what(option__output__forces))
then
1120 write(c_forces_iter,
'(a,i4.4)')
"forces.", geom_iter
1121 if (
bitand(g_opt%syst%outp%how(option__output__forces), option__outputformat__bild) /= 0)
then
1122 call g_opt%ions%write_bild_forces_file(
'forces', trim(c_forces_iter))
1125 g_opt%ions%pos, g_opt%ions%atom, g_opt%syst%gr, g_opt%syst%namespace, total_forces=g_opt%ions%tot_force)
1129 if (g_opt%syst%st%system_grp%is_root())
then
1130 iunit =
io_open(trim(
'geom/optimization.log'), g_opt%syst%namespace, &
1131 action =
'write', position =
'append')
1133 if (geom_iter == 1)
then
1135 write(iunit,
'(a10,5(5x,a20),a)')
'# iter',
'energy [' // trim(
units_abbrev(
units_out%energy)) //
']', &
1140 ' alpha, beta, gamma [degrees]'
1142 write(iunit,
'(a10,3(5x,a20))')
'# iter',
'energy [' // trim(
units_abbrev(
units_out%energy)) //
']', &
1156 g_opt%ions%latt%alpha, g_opt%ions%latt%beta, g_opt%ions%latt%gamma
1169 call messages_write(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", new_line = .
true.)
1171 call messages_write(
"+++++++++++++++++++++ MINIMIZATION ITER #:")
1178 if (g_opt%periodic_dim == 0)
then
1189 call messages_write(maxdf, fmt =
"f16.10,1x", print_units = .false., new_line = .
true.)
1193 call messages_write(maxdx, fmt =
"f16.10,1x", print_units = .false., new_line = .
true.)
1196 call messages_write(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", new_line = .
true.)
1197 call messages_write(
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", new_line = .
true.)
1209 real(real64),
intent(out) :: coords(:)
1211 integer :: iatom, idir, jdir, icoord
1212 real(real64) :: tmp_pos(gopt%dim), strain(g_opt%periodic_dim,g_opt%periodic_dim)
1218 if (
bitand(g_opt%type, go_ions) /= 0)
then
1219 do iatom = 1, gopt%ions%natoms
1220 if (gopt%fixed_atom == iatom) cycle
1221 if (gopt%ions%fixed(iatom)) cycle
1222 tmp_pos = gopt%ions%pos(1:gopt%dim, iatom)
1223 if (gopt%fixed_atom > 0) tmp_pos = tmp_pos - gopt%ions%pos(1:gopt%dim, gopt%fixed_atom)
1224 tmp_pos = gopt%ions%latt%cart_to_red(tmp_pos)
1225 do idir = 1, gopt%dim
1226 coords(icoord) = tmp_pos(idir)
1237 strain = matmul(gopt%ions%latt%rlattice(1:g_opt%periodic_dim, 1:g_opt%periodic_dim), g_opt%inv_initial_rlattice)
1238 do idir = 1, g_opt%periodic_dim
1239 do jdir = idir, g_opt%periodic_dim
1240 coords(icoord) = strain(idir, jdir)
1248 do idir = 1, g_opt%periodic_dim
1249 coords(icoord) = norm2(gopt%ions%latt%rlattice(1:g_opt%periodic_dim, idir))/g_opt%initial_length(idir)
1260 subroutine to_grad(gopt, grad)
1262 real(real64),
intent(out) :: grad(:)
1264 integer :: iatom, idir, jdir, icoord
1265 real(real64) :: tmp_force(1:gopt%dim)
1271 if (
bitand(g_opt%type, go_ions) /= 0)
then
1272 do iatom = 1, gopt%ions%natoms
1273 if (gopt%fixed_atom == iatom) cycle
1274 if (gopt%ions%fixed(iatom)) cycle
1275 do idir = 1, gopt%dim
1276 if (abs(gopt%ions%atom(iatom)%c(idir)) <=
m_epsilon)
then
1277 tmp_force(idir) = -gopt%ions%tot_force(idir, iatom)
1281 if (gopt%fixed_atom > 0)
then
1282 tmp_force(idir) = tmp_force(idir) + gopt%ions%tot_force(idir, gopt%fixed_atom)
1285 tmp_force = gopt%ions%latt%cart_to_red(tmp_force)
1286 do idir = 1, gopt%dim
1287 grad(icoord) = tmp_force(idir)
1295 do idir = 1, g_opt%periodic_dim
1296 do jdir = idir, g_opt%periodic_dim
1297 grad(icoord) = -g_opt%cell_force(idir, jdir)
1305 do idir = 1, g_opt%periodic_dim
1306 grad(icoord) = -g_opt%cell_force(idir, 1)
1319 real(real64),
intent(in) :: coords(:)
1321 integer :: iatom, idir, jdir, icoord
1322 real(real64) :: tmp_pos(gopt%dim, gopt%ions%natoms), strain(g_opt%periodic_dim,g_opt%periodic_dim)
1323 real(real64) :: eigenvalues(g_opt%periodic_dim)
1331 if (
bitand(g_opt%type, go_ions) /= 0)
then
1332 do iatom = 1, gopt%ions%natoms
1333 if (gopt%fixed_atom == iatom) cycle
1334 if (gopt%ions%fixed(iatom)) cycle
1335 do idir = 1, gopt%dim
1336 tmp_pos(idir, iatom) = coords(icoord)
1341 do iatom = 1, gopt%ions%natoms
1342 tmp_pos(:, iatom) = gopt%ions%latt%cart_to_red(gopt%ions%pos(:, iatom))
1348 do idir = 1, g_opt%periodic_dim
1349 do jdir = idir, g_opt%periodic_dim
1350 strain(idir, jdir) = coords(icoord)
1361 gopt%ions%latt%rlattice(1:g_opt%periodic_dim, 1:g_opt%periodic_dim) = matmul(strain, g_opt%initial_rlattice)
1367 assert(all(eigenvalues >
m_zero))
1372 do idir = 1, g_opt%periodic_dim
1373 gopt%ions%latt%rlattice(1:g_opt%periodic_dim, idir) = coords(icoord) &
1374 * gopt%initial_rlattice(1:g_opt%periodic_dim, idir)
1381 call g_opt%syst%gr%symmetrizer%symmetrize_lattice_vectors(g_opt%periodic_dim, g_opt%initial_rlattice, &
1382 gopt%ions%latt%rlattice(1:g_opt%periodic_dim, 1:g_opt%periodic_dim), gopt%symmetrize)
1383 call gopt%ions%update_lattice_vectors(gopt%ions%latt, gopt%symmetrize)
1387 if (
bitand(g_opt%type, go_ions) /= 0)
then
1389 do iatom = 1, gopt%ions%natoms
1390 if (gopt%fixed_atom == iatom) cycle
1391 if (gopt%ions%fixed(iatom)) cycle
1392 tmp_pos(:, iatom) = gopt%ions%latt%red_to_cart(tmp_pos(:, iatom))
1393 do idir = 1, gopt%dim
1394 if (abs(gopt%ions%atom(iatom)%c(idir)) <=
m_epsilon)
then
1395 gopt%ions%pos(idir, iatom) = tmp_pos(idir, iatom)
1398 if (gopt%fixed_atom > 0)
then
1399 gopt%ions%pos(:, iatom) = gopt%ions%pos(:, iatom) + gopt%ions%pos(:, gopt%fixed_atom)
1403 do iatom = 1, gopt%ions%natoms
1404 gopt%ions%pos(:, iatom) = gopt%ions%latt%red_to_cart(tmp_pos(:, iatom))
1408 if (gopt%symmetrize)
then
1409 call gopt%ions%symmetrize_atomic_coord()
1413 call gopt%ions%print_spacegroup()
1422 integer,
intent(in) :: geom_iter
1423 integer,
intent(in) :: size
1424 real(real64),
intent(in) :: energy, maxdx
1425 real(real64),
intent(in) :: coords(size)
1439 integer :: iunit, iatom, idir, command_status, command_exit
1440 logical :: has_constrains
1441 character(len=MAX_PATH_LEN) :: cmd, mattersim_share, mattersim_python
1442 character(len=64) :: constrains_arg
1448 call io_rm(
'ml_cell.xyz', g_opt%syst%namespace)
1450 if (g_opt%ions%space%is_periodic())
then
1451 call write_extended_xyz_file(
'.',
'work-geom', g_opt%ions%space, g_opt%ions%latt, g_opt%ions%pos, g_opt%ions%atom, &
1452 g_opt%syst%gr%box, g_opt%syst%namespace)
1454 call g_opt%ions%write_xyz(
'./work-geom', append = .false.)
1459 has_constrains = any(g_opt%ions%fixed) .or. g_opt%fixed_atom > 0
1460 do iatom = 1, g_opt%ions%natoms
1461 has_constrains = has_constrains .or. any(g_opt%ions%atom(iatom)%c /= 0)
1465 if (has_constrains)
then
1466 constrains_arg =
' --constrains ml_constrains.dat'
1469 do iatom = 1, g_opt%ions%natoms
1470 if (g_opt%ions%fixed(iatom) .or. iatom == g_opt%fixed_atom)
then
1471 write(iunit,
'(3(1x,i1))') (1, idir = 1, g_opt%ions%space%dim)
1473 write(iunit,
'(3(1x,i1))') (g_opt%ions%atom(iatom)%c(idir), idir = 1, g_opt%ions%space%dim)
1480 call mattersim_paths(mattersim_share, mattersim_python, g_opt%syst%namespace)
1484 write(cmd,
'(a,1x,es24.16,1x,i0,1x,l1,a)') &
1485 trim(mattersim_python) //
" -I " // trim(mattersim_share) &
1486 //
"/scripts/run_mattersim_preopt.py work-geom.xyz ml_cell.xyz " // trim(mattersim_share), &
1487 g_opt%pressure, g_opt%type, g_opt%symmetrize, trim(constrains_arg)
1488 call execute_command_line(trim(cmd), exitstat=command_exit, cmdstat=command_status)
1489 if (command_status == 0) command_status = command_exit
1492 call mpi_world%bcast(command_status, 1, mpi_integer, 0)
1493 if (command_status /= 0)
then
1494 write(
message(1),
'(a,i0)')
'MatterSim pre-optimization failed with exit status ', command_status
1502 do iatom = 1, g_opt%ions%natoms
1503 read(iunit,*) g_opt%ions%pos(:, iatom)
1508 read(iunit,*) g_opt%ions%latt%rlattice(:, idir)
1513 call g_opt%ions%update_lattice_vectors(g_opt%ions%latt, g_opt%symmetrize)
1515 if (
debug%info)
then
1516 call g_opt%ions%print_spacegroup()
1519 call g_opt%ions%fold_atoms_into_cell()
1524 g_opt%syst%space, g_opt%syst%hm%psolver, g_opt%syst%hm%kpoints, &
1525 g_opt%syst%mc, g_opt%syst%st%qtot, g_opt%ions%latt)
1529 g_opt%ions, g_opt%syst%ext_partners, g_opt%st)
1531 call g_opt%ions%print_spacegroup()
subroutine init_(fromscratch)
Note that lalg_determinant and lalg_inverse are just wrappers over the same routine.
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 forces_set_total_to_zero(ions, force)
subroutine, public geom_opt_run(system, from_scratch)
integer, parameter go_calculator_mattersim
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 ml_preopt(g_opt)
Calls a python script to do a pre-optimization based on machine-learned interatomic potential.
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)
subroutine mattersim_paths(mattersim_share, mattersim_python, namespace)
real(real64), parameter, public m_zero
real(real64), parameter, public m_epsilon
type(conf_t), public conf
Global instance of Octopus configuration.
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_extended_xyz_file(dir, fname, space, latt, pos, atoms, box, namespace)
Write an extended xyz file compatible with ASE.
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 ion_dynamics_box_update(namespace, gr, space, new_latt)
real(real64) function, dimension(1:n, 1:n), public lalg_remove_rotation(n, A)
Remove rotation from affine transformation A by computing the polar decomposition and discarding the ...
subroutine, public lcao_run(namespace, space, gr, ions, ext_partners, st, ks, hm, st_start, lmm_r, known_lower_bound)
System information (time, memory, sysname)
subroutine, public loct_strerror(errno, res)
This module is intended to contain "only mathematical" functions and procedures.
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_new_line()
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_experimental(name, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
integer, parameter, public minmethod_nmsimplex
integer, parameter, public minmethod_fire
type(mpi_grp_t), public mpi_world
This module implements the basic mulsisystem class, a container system for other systems.
type(namespace_t), public global_namespace
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
integer, parameter, public restart_type_dump
integer, parameter, public restart_type_load
subroutine, public scf_set_lower_bound_is_known(scf, known_lower_bound)
Set the flag lower_bound_is_known.
subroutine, public scf_print_mem_use(namespace)
subroutine, public scf_mix_clear(scf)
integer, parameter, public verb_compact
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
subroutine, public scf_end(scf)
subroutine, public scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, verbosity, iters_done, restart_dump)
Legacy version of the SCF code.
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, fixed_occ, 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...
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.