41#include "./base/base_uses.f90"
47 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qmmmx_force'
65 require_consistent_energy_force)
67 LOGICAL,
INTENT(IN) :: calc_force, consistent_energies, linres
68 LOGICAL,
INTENT(IN),
OPTIONAL :: require_consistent_energy_force
70 INTEGER :: ip, mom_conserv_min_label, &
71 mom_conserv_n, mom_conserv_region, &
73 INTEGER,
POINTER :: cur_indices(:), cur_labels(:)
74 REAL(
dp) :: delta_a(3), delta_f(3), &
75 mom_conserv_mass, total_f(3)
76 TYPE(
cp_subsys_type),
POINTER :: subsys_primary, subsys_qmmm_core, &
78 TYPE(
particle_type),
DIMENSION(:),
POINTER :: particles_primary, particles_qmmm_core, &
79 particles_qmmm_extended
82 IF (
PRESENT(require_consistent_energy_force))
THEN
83 IF (require_consistent_energy_force) &
84 CALL cp_abort(__location__, &
85 "qmmmx_energy_and_forces got require_consistent_energy_force but force mixing is active. ")
92 CALL qmmmx_calc_energy_force_low(qmmmx_env%ext, calc_force, consistent_energies, linres,
"ext")
93 CALL qmmmx_calc_energy_force_low(qmmmx_env%core, calc_force, consistent_energies, linres,
"core")
96 CALL qmmm_env_get(qmmmx_env%core, subsys=subsys_qmmm_core)
97 CALL qmmm_env_get(qmmmx_env%ext, subsys=subsys_qmmm_extended)
99 CALL get_qs_env(qmmmx_env%ext%qs_env, input=force_env_section)
100 CALL section_vals_val_get(force_env_section,
"QMMM%FORCE_MIXING%RESTART_INFO%INDICES", i_vals=cur_indices)
101 CALL section_vals_val_get(force_env_section,
"QMMM%FORCE_MIXING%RESTART_INFO%LABELS", i_vals=cur_labels)
103 particles_qmmm_extended => subsys_qmmm_extended%particles%els
104 particles_qmmm_core => subsys_qmmm_core%particles%els
105 DO ip = 1,
SIZE(cur_indices)
108 particles_qmmm_core(cur_indices(ip))%f = particles_qmmm_extended(cur_indices(ip))%f
114 i_val=mom_conserv_type)
116 CALL section_vals_val_get(force_env_section,
"QMMM%FORCE_MIXING%MOMENTUM_CONSERVATION_REGION", &
117 i_val=mom_conserv_region)
126 cpabort(
"Got unknown MOMENTUM_CONSERVATION_REGION (not CORE, QM, or BUFFER) !")
130 DO ip = 1,
SIZE(particles_qmmm_core)
131 total_f(1:3) = total_f(1:3) + particles_qmmm_core(ip)%f(1:3)
134 mom_conserv_n = count(cur_labels >= mom_conserv_min_label)
135 delta_f = total_f/mom_conserv_n
136 DO ip = 1,
SIZE(cur_indices)
137 IF (cur_labels(ip) >= mom_conserv_min_label)
THEN
138 particles_qmmm_core(cur_indices(ip))%f = particles_qmmm_core(cur_indices(ip))%f - delta_f
142 mom_conserv_mass = 0.0_dp
143 DO ip = 1,
SIZE(cur_indices)
144 IF (cur_labels(ip) >= mom_conserv_min_label) &
145 mom_conserv_mass = mom_conserv_mass + particles_qmmm_core(cur_indices(ip))%atomic_kind%mass
147 delta_a = total_f/mom_conserv_mass
148 DO ip = 1,
SIZE(cur_indices)
149 IF (cur_labels(ip) >= mom_conserv_min_label)
THEN
150 particles_qmmm_core(cur_indices(ip))%f = particles_qmmm_core(cur_indices(ip))%f - &
151 particles_qmmm_core(cur_indices(ip))%atomic_kind%mass*delta_a
158 particles_primary => subsys_primary%particles%els
159 DO ip = 1,
SIZE(particles_qmmm_core)
160 particles_primary(ip)%f = particles_qmmm_core(ip)%f
173 SUBROUTINE qmmmx_calc_energy_force_low(qmmm_env, calc_force, consistent_energies, linres, label)
175 LOGICAL,
INTENT(IN) :: calc_force, consistent_energies, linres
176 CHARACTER(*) :: label
178 CHARACTER(default_string_length) :: new_restart_fn, new_restart_hist_fn, &
179 old_restart_fn, old_restart_hist_fn
180 INTEGER,
DIMENSION(:),
POINTER :: qm_atom_index
181 LOGICAL :: saved_do_translate
182 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: saved_pos
187 NULLIFY (mm_cell, subsys_qm, subsys_mm, qm_atom_index)
189 CALL get_qs_env(qmmm_env%qs_env, input=force_env_section)
193 c_val=old_restart_fn)
194 new_restart_fn = trim(old_restart_fn)//
"-"//trim(label)
196 c_val=new_restart_fn)
200 c_val=old_restart_hist_fn)
201 new_restart_hist_fn = trim(old_restart_hist_fn)//
"-"//trim(label)
203 c_val=new_restart_hist_fn)
207 CALL fist_env_get(qmmm_env%fist_env, cell=mm_cell, subsys=subsys_mm)
208 CALL get_qs_env(qmmm_env%qs_env, cp_subsys=subsys_qm)
209 qm_atom_index => qmmm_env%qm%qm_atom_index
210 CALL apply_qmmm_wrap(subsys_mm, mm_cell, subsys_qm, qm_atom_index, saved_pos)
214 saved_do_translate = qmmm_env%qm%do_translate
215 qmmm_env%qm%do_translate = .false.
221 qmmm_env%qm%do_translate = saved_do_translate
228 c_val=old_restart_fn)
230 c_val=old_restart_hist_fn)
232 END SUBROUTINE qmmmx_calc_energy_force_low
Handles all functions related to the CELL.
types that represent a subsys, i.e. a part of the system
subroutine, public fist_env_get(fist_env, atomic_kind_set, particle_set, ewald_pw, local_particles, local_molecules, molecule_kind_set, molecule_set, cell, cell_ref, ewald_env, fist_nonbond_env, thermo, para_env, subsys, qmmm, qmmm_env, input, shell_model, shell_model_ad, shell_particle_set, core_particle_set, multipoles, results, exclusions, efield)
Purpose: Get the FIST environment.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
Define the data structure for the particle information.
Calculates QM/MM energy and forces.
subroutine, public qmmm_calc_energy_force(qmmm_env, calc_force, consistent_energies, linres)
calculates the qm/mm energy and forces
integer, parameter, public force_mixing_label_qm_core
integer, parameter, public force_mixing_label_buffer
integer, parameter, public force_mixing_label_qm_dynamics
Basic container type for QM/MM.
subroutine, public qmmm_env_get(qmmm_env, subsys, potential_energy, kinetic_energy)
...
subroutine, public apply_qmmm_unwrap(subsys_mm, subsys_qm, qm_atom_index, saved_pos)
...
subroutine, public apply_qmmm_wrap(subsys_mm, mm_cell, subsys_qm, qm_atom_index, saved_pos)
wrap positions (with mm periodicity)
Calculates QM/MM energy and forces with Force-Mixing.
subroutine, public qmmmx_calc_energy_force(qmmmx_env, calc_force, consistent_energies, linres, require_consistent_energy_force)
calculates the qm/mm energy and forces
Basic container type for QM/MM with force mixing.
Routines used for force-mixing QM/MM calculations.
subroutine, public apply_qmmmx_translate(qmmmx_env)
Apply translation to the full system in order to center the QM system into the QM box.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.
Type defining parameters related to the simulation cell.
represents a system: atoms, molecules, their pos,vel,...