42#include "../base/base_uses.f90"
47 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'glbopt_worker'
57 INTEGER :: f_env_id = -1
63 INTEGER :: gopt_max_iter = 0
64 INTEGER :: bump_steps_downwards = 0
65 INTEGER :: bump_steps_upwards = 0
66 INTEGER :: md_bumps_max = 0
67 REAL(kind=
dp) :: fragmentation_threshold = 0.0_dp
68 INTEGER :: n_atoms = -1
85 input_path, worker_id, iw)
90 CHARACTER(LEN=*),
INTENT(IN) :: input_path
91 INTEGER,
INTENT(in) :: worker_id, iw
94 REAL(kind=
dp) :: dist_in_angstrom
97 worker%root_section => root_section
103 input_declaration=input_declaration, &
104 input_path=input_path, &
105 input=root_section, &
106 output_unit=worker%iw, &
111 worker%force_env => worker%f_env%force_env
112 CALL force_env_get(worker%force_env, globenv=worker%globenv, subsys=worker%subsys)
116 CALL worker%globenv%gaussian_rng_stream%reset_to_next_substream()
125 CALL section_vals_val_get(glbopt_section,
"BUMP_STEPS_UPWARDS", i_val=worker%bump_steps_upwards)
126 CALL section_vals_val_get(glbopt_section,
"BUMP_STEPS_DOWNWARDS", i_val=worker%bump_steps_downwards)
129 worker%fragmentation_threshold = dist_in_angstrom/
angstrom
144 CHARACTER(len=default_string_length) :: command
147 IF (trim(command) ==
"md_and_gopt")
THEN
148 CALL run_mdgopt(worker, cmd, report)
150 cpabort(
"Worker: received unknown command")
162 SUBROUTINE run_mdgopt(worker, cmd, report)
167 INTEGER :: gopt_steps, iframe, md_steps, &
168 n_fragments, prev_iframe
169 REAL(kind=
dp) :: epot, temperature
170 REAL(kind=
dp),
DIMENSION(:),
POINTER :: positions
185 ALLOCATE (mdctrl_data%epot_history(worker%bump_steps_downwards + worker%bump_steps_upwards + 1))
186 mdctrl_data%epot_history = 0.0_dp
187 mdctrl_data%md_bump_counter = 0
188 mdctrl_data%bump_steps_upwards = worker%bump_steps_upwards
189 mdctrl_data%bump_steps_downwards = worker%bump_steps_downwards
190 mdctrl_data%md_bumps_max = worker%md_bumps_max
191 mdctrl_data%output_unit = worker%iw
192 mdctrl%glbopt => mdctrl_data
196 IF (iframe == 0) iframe = 1
200 IF (worker%iw > 0)
THEN
201 WRITE (worker%iw,
'(A,33X,F20.3)')
' GLBOPT| MD temperature [K]', temperature*
kelvin
202 WRITE (worker%iw,
'(A,29X,I10)')
" GLBOPT| Starting MD at trajectory frame ", iframe
206 CALL qs_mol_dyn(worker%force_env, worker%globenv, mdctrl=mdctrl_p)
208 iframe = mdctrl_data%itimes + 1
209 md_steps = iframe - prev_iframe
210 IF (worker%iw > 0)
WRITE (worker%iw,
'(A,I4,A)')
" GLBOPT| md ended after ", md_steps,
" steps."
213 IF (.NOT.
ASSOCIATED(positions))
ALLOCATE (positions(3*worker%n_atoms))
217 n_fragments = n_fragments + 1
218 IF (fix_fragmentation(positions, worker%fragmentation_threshold))
EXIT
222 IF (n_fragments > 0 .AND. worker%iw > 0)
THEN
223 WRITE (worker%iw,
'(A,13X,I10)')
" GLBOPT| Ran fix_fragmentation times:", n_fragments
227 IF (worker%iw > 0)
WRITE (worker%iw,
'(A,13X,I10)')
" GLBOPT| Starting local optimisation at trajectory frame ", iframe
228 CALL section_vals_val_set(worker%root_section,
"MOTION%GEO_OPT%STEP_START_VAL", i_val=iframe - 1)
230 i_val=iframe + worker%gopt_max_iter)
233 CALL cp_geo_opt(worker%force_env, worker%globenv, rm_restart_info=.false.)
238 gopt_steps = iframe - prev_iframe - 1
239 IF (worker%iw > 0)
WRITE (worker%iw,
'(A,I4,A)')
" GLBOPT| gopt ended after ", gopt_steps,
" steps."
241 IF (worker%iw > 0)
WRITE (worker%iw,
'(A,25X,E20.10)')
' GLBOPT| Potential Energy [Hartree]', epot
251 DEALLOCATE (positions)
252 END SUBROUTINE run_mdgopt
261 FUNCTION fix_fragmentation(positions, bondlength)
RESULT(all_connected)
262 REAL(kind=
dp),
DIMENSION(:) :: positions
263 REAL(kind=
dp) :: bondlength
264 LOGICAL :: all_connected
266 REAL(kind=
dp),
PARAMETER :: bond_thre = 1.25_dp
268 INTEGER :: cluster_edge, fragment_edge, i, j, &
269 n_particles, stack_size
270 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: stack
271 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: marked
272 REAL(kind=
dp) :: d, dr(3), min_dist, s
274 n_particles =
SIZE(positions)/3
275 ALLOCATE (stack(n_particles), marked(n_particles))
277 marked = .false.; stack_size = 0
280 marked(1) = .true.; stack(1) = 1; stack_size = 1
282 DO WHILE (stack_size > 0)
283 i = stack(stack_size); stack_size = stack_size - 1
284 DO j = 1, n_particles
285 IF (norm2(diff(positions, i, j)) < bond_thre*bondlength)
THEN
286 IF (.NOT. marked(j))
THEN
288 stack(stack_size + 1) = j; stack_size = stack_size + 1
294 all_connected = all(marked)
295 IF (all_connected)
RETURN
298 IF (count(marked) < n_particles/2) marked(:) = .NOT. (marked(:))
300 min_dist = huge(1.0_dp)
303 DO i = 1, n_particles
305 DO j = 1, n_particles
306 IF (.NOT. marked(j)) cycle
307 d = norm2(diff(positions, i, j))
308 IF (d < min_dist)
THEN
316 dr = diff(positions, cluster_edge, fragment_edge)
317 s = 1.0_dp - bondlength/norm2(dr)
318 DO i = 1, n_particles
320 positions(3*i - 2:3*i) = positions(3*i - 2:3*i) - s*dr
323 END FUNCTION fix_fragmentation
333 PURE FUNCTION diff(positions, i, j)
RESULT(dr)
334 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: positions
335 INTEGER,
INTENT(IN) :: i, j
336 REAL(kind=
dp),
DIMENSION(3) :: dr
338 dr = positions(3*i - 2:3*i) - positions(3*j - 2:3*j)
353 IF (ierr /= 0) cpabort(
"destroy_force_env failed")
Adds an entry from a swarm-message.
Returns an entry from a swarm-message.
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.
interface to use cp2k as library
recursive subroutine, public destroy_force_env(env_id, ierr, q_finalize)
deallocates the force_env with the given id
subroutine, public f_env_add_defaults(f_env_id, f_env, handle)
adds the default environments of the f_env to the stack of the defaults, and returns a new error and ...
recursive subroutine, public create_force_env(new_env_id, input_declaration, input_path, output_path, mpi_comm, output_unit, owns_out_unit, input, ierr, work_dir, initial_variables)
creates a new force environment using the given input, and writing the output to the given output uni...
subroutine, public f_env_rm_defaults(f_env, ierr, handle)
removes the default environments of the f_env to the stack of the defaults, and sets ierr accordingly...
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
performs geometry optimization
subroutine, public cp_geo_opt(force_env, globenv, eval_opt_geo, rm_restart_info)
Main driver to perform geometry optimization.
Worker routines used by global optimization schemes.
subroutine, public glbopt_worker_init(worker, input_declaration, para_env, root_section, input_path, worker_id, iw)
Initializes worker for global optimization.
subroutine, public glbopt_worker_finalize(worker)
Finalizes worker for global optimization.
subroutine, public glbopt_worker_execute(worker, cmd, report)
Central execute routine of global optimization worker.
Define type storing the global information of a run. Keep the amount of stored data small....
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.
A common interface for passing a callback into the md_run loop.
Interface to the message passing library MPI.
Definition of physical constants:
real(kind=dp), parameter, public kelvin
real(kind=dp), parameter, public angstrom
Swarm-message, a convenient data-container for with build-in serialization.
represents a system: atoms, molecules, their pos,vel,...
wrapper to abstract the force evaluation of the various methods
contains the initially parsed file and the initial parallel environment
stores all the informations relevant to an mpi environment