24 final_evaluation, para_env)
81#include "../base/base_uses.f90"
84 REAL(KIND=
dp),
DIMENSION(:),
POINTER :: x
85 REAL(KIND=
dp),
INTENT(OUT),
OPTIONAL :: f
86 REAL(KIND=
dp),
DIMENSION(:),
OPTIONAL, &
88 INTEGER,
INTENT(IN) :: master
89 LOGICAL,
INTENT(IN),
OPTIONAL :: final_evaluation
92 CHARACTER(len=*),
PARAMETER :: routineN =
'cp_eval_at'
94 INTEGER :: ensemble, handle, idg, idir, ip, &
95 nparticle, nsize, shell_index
96 LOGICAL :: explicit, my_final_evaluation
97 REAL(KIND=
dp) :: f_ts, potential_energy
98 REAL(KIND=
dp),
DIMENSION(3, 3) :: av_ptens
99 REAL(KIND=
dp),
DIMENSION(:),
POINTER :: cell_gradient, gradient_ts
106 CHARACTER(LEN=default_string_length) :: project_name
113 NULLIFY (core_particles)
114 NULLIFY (gradient_ts)
116 NULLIFY (shell_particles)
122 CALL timeset(routinen, handle)
124 CALL force_env_get(gopt_env%force_env, subsys=subsys, cell=cell)
126 core_particles=core_particles, &
127 particles=particles, &
128 shell_particles=shell_particles, &
131 spgr => gopt_env%spgr
133 my_final_evaluation = .false.
134 IF (
PRESENT(final_evaluation)) my_final_evaluation = final_evaluation
136 SELECT CASE (gopt_env%type_id)
140 SELECT CASE (gopt_env%type_id)
144 calc_force=
PRESENT(gradient), &
145 require_consistent_energy_force=gopt_env%require_consistent_energy_force)
151 IF (
PRESENT(gradient))
THEN
152 IF (master == para_env%mepos)
THEN
154 IF (spgr%keep_space_group)
THEN
162 ALLOCATE (gradient_ts(particles%n_els*3))
166 CALL cp_eval_at_ts(gopt_env, x, f_ts, gradient_ts, calc_force=.true.)
169 IF (
PRESENT(f)) f = f_ts
171 IF (
PRESENT(gradient))
THEN
172 IF (master == para_env%mepos)
THEN
173 cpassert(
ASSOCIATED(gradient))
174 gradient = gradient_ts
177 DEALLOCATE (gradient_ts)
184 IF (.NOT. virial%pv_availability) &
185 CALL cp_abort(__location__, &
186 "For a cell optimization task with CELL_OPT/TYPE "// &
187 "DIRECT_CELL_OPT, the FORCE_EVAL/STRESS_TENSOR "// &
188 "keyword MUST be defined in the input file for the "// &
189 "evaluation of the stress tensor, but none is found!")
190 IF (gopt_env%cell_env%keep_volume)
THEN
192 SELECT CASE (gopt_env%cell_method_id)
200 SELECT CASE (gopt_env%cell_method_id)
209 calc_force=
PRESENT(gradient), &
210 require_consistent_energy_force=gopt_env%require_consistent_energy_force)
212 CALL force_env_get(gopt_env%force_env, potential_energy=potential_energy)
219 IF (
PRESENT(gradient))
THEN
220 cpassert(any(virial_avg%pv_total /= 0))
222 av_ptens(:, :) = virial_avg%pv_total(:, :)/cell%deth
223 IF (master == para_env%mepos)
THEN
224 cpassert(
ASSOCIATED(gradient))
227 cpassert((
SIZE(gradient) == nsize + 6))
230 IF (spgr%keep_space_group)
THEN
235 cell_gradient => gradient(nsize + 1:nsize + 6)
236 cell_gradient = 0.0_dp
237 CALL get_dg_dh(cell_gradient, av_ptens, gopt_env%cell_env%pres_ext, cell, gopt_env%cell_env%mtrx, &
238 keep_angles=gopt_env%cell_env%keep_angles, &
239 keep_symmetry=gopt_env%cell_env%keep_symmetry, &
240 pres_int=gopt_env%cell_env%pres_int, &
241 pres_constr=gopt_env%cell_env%pres_constr, &
242 constraint_id=gopt_env%cell_env%constraint_id)
246 CALL para_env%bcast(gopt_env%cell_env%pres_int, 0)
247 IF (gopt_env%cell_env%constraint_id /=
fix_none) &
248 CALL para_env%bcast(gopt_env%cell_env%pres_constr, 0)
251 CASE (default_cell_geo_opt_id, default_cell_md_id)
252 CALL apply_cell_change(gopt_env, cell, x, update_forces=.false.)
254 CALL write_cell(cell, gopt_env%geo_section)
257 TYPE(virial_type) :: virial_avg
258 IF (my_final_evaluation)
THEN
259 CALL force_env_calc_energy_force(gopt_env%force_env, &
260 calc_force=
PRESENT(gradient), &
261 require_consistent_energy_force=gopt_env%require_consistent_energy_force)
263 CALL force_env_get(gopt_env%force_env, potential_energy=f)
266 SELECT CASE (gopt_env%cell_method_id)
267 CASE (default_cell_geo_opt_id)
268 work => section_vals_get_subs_vals(gopt_env%motion_section,
"GEO_OPT")
269 CALL section_vals_get(work, explicit=explicit)
270 IF (.NOT. explicit) &
271 CALL cp_abort(__location__, &
272 "For a cell optimization task with CELL_OPT/TYPE "// &
273 "GEO_OPT, besides the MOTION/CELL_OPT section, the "// &
274 "MOTION/GEO_OPT section MUST also be provided in "// &
275 "the input file for the evaluation of the stress "// &
276 "tensor, but none is found!")
278 CALL gopt_new_logger_create(new_logger, gopt_env%force_env%root_section, para_env, &
279 project_name, id_run=geo_opt_run)
280 CALL cp_add_default_logger(new_logger)
281 CALL cp_geo_opt(gopt_env%force_env, gopt_env%globenv, eval_opt_geo=.false.)
282 CALL force_env_get(gopt_env%force_env, potential_energy=potential_energy)
284 CASE (default_cell_md_id)
285 work => section_vals_get_subs_vals(gopt_env%motion_section,
"MD")
286 avgs_section => section_vals_get_subs_vals(work,
"AVERAGES")
287 CALL section_vals_get(work, explicit=explicit)
288 IF (.NOT. explicit) &
289 CALL cp_abort(__location__, &
290 "For a cell optimization task with CELL_OPT/TYPE MD, "// &
291 "besides the MOTION/CELL_OPT section, the MOTION/MD "// &
292 "section MUST also be provided in the input file for "// &
293 "the evaluation of the stress tensor, but none is found!")
295 CALL section_vals_val_get(gopt_env%motion_section,
"MD%ENSEMBLE", i_val=ensemble)
296 IF (ensemble /= nvt_ensemble) &
297 CALL cp_abort(__location__, &
298 "For a cell optimization task with CELL_OPT/TYPE MD, "// &
299 "the MOTION/MD/ENSEMBLE keyword MUST be set to NVT "// &
300 "and any other choice of ensemble is not supported!")
302 CALL gopt_new_logger_create(new_logger, gopt_env%force_env%root_section, para_env, &
303 project_name, id_run=mol_dyn_run)
304 CALL cp_add_default_logger(new_logger)
305 CALL create_averages(averages, avgs_section, virial_avg=.true., force_env=gopt_env%force_env)
306 CALL qs_mol_dyn(gopt_env%force_env, gopt_env%globenv, averages, rm_restart_info=.false.)
308 potential_energy = averages%avepot
309 virial_avg = averages%virial
310 CALL release_averages(averages)
313 cpabort(
"Invalid or not yet implemented type of cell optimization")
315 CALL cp_rm_default_logger()
316 CALL gopt_new_logger_release(new_logger, gopt_env%force_env%root_section, para_env, project_name, &
319 CALL virial_update(virial_avg, subsys, para_env)
326 IF (
PRESENT(gradient))
THEN
327 cpassert(any(virial_avg%pv_total /= 0))
329 av_ptens(:, :) = virial_avg%pv_total(:, :)/cell%deth
330 IF (master == para_env%mepos)
THEN
331 cpassert(
ASSOCIATED(gradient))
332 IF (spgr%keep_space_group)
THEN
333 CALL spgr_apply_rotations_stress(spgr, cell, av_ptens)
334 CALL spgr_write_stress_tensor(av_ptens, spgr)
337 CALL get_dg_dh(gradient, av_ptens, gopt_env%cell_env%pres_ext, cell, gopt_env%cell_env%mtrx, &
338 keep_angles=gopt_env%cell_env%keep_angles, &
339 keep_symmetry=gopt_env%cell_env%keep_symmetry, &
340 pres_int=gopt_env%cell_env%pres_int, &
341 pres_constr=gopt_env%cell_env%pres_constr, &
342 constraint_id=gopt_env%cell_env%constraint_id)
346 CALL para_env%bcast(gopt_env%cell_env%pres_int, 0)
347 IF (gopt_env%cell_env%constraint_id /= fix_none) &
348 CALL para_env%bcast(gopt_env%cell_env%pres_constr, 0)
352 cpabort(
"Invalid or not yet implemented type of cell optimization")
354 CASE (default_shellcore_method_id)
356 DO ip = 1, particles%n_els
357 shell_index = particles%els(ip)%shell_index
358 IF (shell_index /= 0)
THEN
360 idg = 3*(shell_index - 1) + idir
361 shell_particles%els(shell_index)%r(idir) = core_particles%els(ip)%r(idir) - x(idg)
365 CALL write_structure_data(particles%els, cell, gopt_env%motion_section)
368 CALL force_env_calc_energy_force(gopt_env%force_env, &
369 calc_force=
PRESENT(gradient), &
370 require_consistent_energy_force=gopt_env%require_consistent_energy_force)
374 CALL force_env_get(gopt_env%force_env, potential_energy=f)
378 IF (
PRESENT(gradient))
THEN
379 IF (master == para_env%mepos)
THEN
380 cpassert(
ASSOCIATED(gradient))
382 DO ip = 1, shell_particles%n_els
385 gradient(idg) = -(core_particles%els(ip)%f(idir) - shell_particles%els(ip)%f(idir))
391 cpabort(
"Invalid or not yet implemented type of optimization")
394 CALL timestop(handle)
subroutine cp_eval_at(gopt_env, x, f, gradient, master, final_evaluation, para_env)
evaluete the potential energy and its gradients using an array with same dimension as the particle_se...
Handles the type to compute averages during an MD.
subroutine, public create_averages(averages, averages_section, virial_avg, force_env)
Creates averages environment.
subroutine, public release_averages(averages)
releases the given averages env
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public henkelman1999
Handles all functions related to the CELL.
subroutine, public write_cell(cell, subsys_section, tag)
Write the cell parameters to the output unit.
contains a functional that calculates the energy and its derivatives for the geometry optimizer
subroutine, public rescale_new_cell_volume(vol, x, idg)
Rescale x(idg+1:idg+6) according to vol.
subroutine, public get_dg_dh(gradient, av_ptens, pres_ext, cell, mtrx, keep_angles, keep_symmetry, pres_int, pres_constr, constraint_id)
Computes the derivatives for the cell.
subroutine, public gopt_new_logger_release(new_logger, root_section, para_env, project_name, id_run)
releases a new logger used for cell optimization algorithm
subroutine, public gopt_new_logger_create(new_logger, root_section, para_env, project_name, id_run)
creates a new logger used for cell optimization algorithm
Handles all functions related to the CELL.
various routines to log and control the output. The idea is that decisions about where to log should ...
subroutine, public cp_rm_default_logger()
the cousin of cp_add_default_logger, decrements the stack, so that the default logger is what it has ...
subroutine, public cp_add_default_logger(logger)
adds a default logger. MUST be called before logging occours
types that represent a subsys, i.e. a part of the system
subroutine, public unpack_subsys_particles(subsys, f, r, s, v, fscale, cell)
Unpack components of a subsystem particle sets into a single vector.
subroutine, public cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell)
returns information about various attributes of the given subsys
subroutine, public pack_subsys_particles(subsys, f, r, s, v, fscale, cell)
Pack components of a subsystem particle sets into a single vector.
Contains types used for a Dimer Method calculations.
recursive subroutine, public cp_eval_at_ts(gopt_env, x, f, gradient, calc_force)
Computes the dimer energy/gradients (including the rotation of the dimer)
Interface for the force calculations.
recursive subroutine, public force_env_calc_energy_force(force_env, calc_force, consistent_energies, skip_external_control, eval_energy_forces, require_consistent_energy_force, linres, calc_stress_tensor)
Interface routine for force and energy calculations.
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
returns various attributes about the force environment
integer function, public force_env_get_nparticle(force_env)
returns the number of particles in a force environment
performs geometry optimization
subroutine, public cp_geo_opt(force_env, globenv, eval_opt_geo, rm_restart_info)
Main driver to perform geometry optimization.
contains a functional that calculates the energy and its derivatives for the geometry optimizer
subroutine, public apply_cell_change(gopt_env, cell, x, update_forces)
Apply coordinate transformations after cell (shape) change.
contains a functional that calculates the energy and its derivatives for the geometry optimizer
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
Perform a molecular dynamics (MD) run using QUICKSTEP.
subroutine, public qs_mol_dyn(force_env, globenv, averages, rm_restart_info, hmc_e_initial, hmc_e_final, mdctrl)
Main driver module for Molecular Dynamics.
Interface to the message passing library MPI.
represent a simple array based list of the given type
Define methods related to particle_type.
subroutine, public write_structure_data(particle_set, cell, input_section)
Write structure data requested by a separate structure data input section to the output unit....
Space Group Symmetry Type Module (version 1.0, Ferbruary 12, 2021)
Space Group Symmetry Module (version 1.0, January 16, 2020)
subroutine, public spgr_apply_rotations_stress(spgr, cell, stress)
routine applies the rotation matrices to the stress tensor.
subroutine, public spgr_apply_rotations_coord(spgr, coord)
routine applies the rotation matrices to the coordinates.
subroutine, public spgr_apply_rotations_force(spgr, force)
routine applies the rotation matrices to the forces.
subroutine, public spgr_write_stress_tensor(stress, spgr)
Variable precision output of the symmetrized stress tensor.
subroutine, public virial_update(virial, subsys, para_env)
Updates the virial given the virial and subsys.
Type defining parameters related to the simulation cell.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represents a system: atoms, molecules, their pos,vel,...
calculates the potential energy of a system, and its derivatives
stores all the informations relevant to an mpi environment
represent a list of objects