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)
THEN
84 CALL cp_abort(__location__, &
85 "qmmmx_energy_and_forces got require_consistent_energy_force but force mixing is active. ")
93 CALL qmmmx_calc_energy_force_low(qmmmx_env%ext, calc_force, consistent_energies, linres,
"ext")
94 CALL qmmmx_calc_energy_force_low(qmmmx_env%core, calc_force, consistent_energies, linres,
"core")
97 CALL qmmm_env_get(qmmmx_env%core, subsys=subsys_qmmm_core)
98 CALL qmmm_env_get(qmmmx_env%ext, subsys=subsys_qmmm_extended)
100 CALL get_qs_env(qmmmx_env%ext%qs_env, input=force_env_section)
101 CALL section_vals_val_get(force_env_section,
"QMMM%FORCE_MIXING%RESTART_INFO%INDICES", i_vals=cur_indices)
102 CALL section_vals_val_get(force_env_section,
"QMMM%FORCE_MIXING%RESTART_INFO%LABELS", i_vals=cur_labels)
104 particles_qmmm_extended => subsys_qmmm_extended%particles%els
105 particles_qmmm_core => subsys_qmmm_core%particles%els
106 DO ip = 1,
SIZE(cur_indices)
109 particles_qmmm_core(cur_indices(ip))%f = particles_qmmm_extended(cur_indices(ip))%f
115 i_val=mom_conserv_type)
117 CALL section_vals_val_get(force_env_section,
"QMMM%FORCE_MIXING%MOMENTUM_CONSERVATION_REGION", &
118 i_val=mom_conserv_region)
127 cpabort(
"Got unknown MOMENTUM_CONSERVATION_REGION (not CORE, QM, or BUFFER) !")
131 DO ip = 1,
SIZE(particles_qmmm_core)
132 total_f(1:3) = total_f(1:3) + particles_qmmm_core(ip)%f(1:3)
135 mom_conserv_n = count(cur_labels >= mom_conserv_min_label)
136 delta_f = total_f/mom_conserv_n
137 DO ip = 1,
SIZE(cur_indices)
138 IF (cur_labels(ip) >= mom_conserv_min_label)
THEN
139 particles_qmmm_core(cur_indices(ip))%f = particles_qmmm_core(cur_indices(ip))%f - delta_f
143 mom_conserv_mass = 0.0_dp
144 DO ip = 1,
SIZE(cur_indices)
145 IF (cur_labels(ip) >= mom_conserv_min_label)
THEN
146 mom_conserv_mass = mom_conserv_mass + particles_qmmm_core(cur_indices(ip))%atomic_kind%mass
149 delta_a = total_f/mom_conserv_mass
150 DO ip = 1,
SIZE(cur_indices)
151 IF (cur_labels(ip) >= mom_conserv_min_label)
THEN
152 particles_qmmm_core(cur_indices(ip))%f = particles_qmmm_core(cur_indices(ip))%f - &
153 particles_qmmm_core(cur_indices(ip))%atomic_kind%mass*delta_a
160 particles_primary => subsys_primary%particles%els
161 DO ip = 1,
SIZE(particles_qmmm_core)
162 particles_primary(ip)%f = particles_qmmm_core(ip)%f
175 SUBROUTINE qmmmx_calc_energy_force_low(qmmm_env, calc_force, consistent_energies, linres, label)
177 LOGICAL,
INTENT(IN) :: calc_force, consistent_energies, linres
178 CHARACTER(*) :: label
180 CHARACTER(default_string_length) :: new_restart_fn, new_restart_hist_fn, &
181 old_restart_fn, old_restart_hist_fn
182 INTEGER,
DIMENSION(:),
POINTER :: qm_atom_index
183 LOGICAL :: saved_do_translate
184 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: saved_pos
189 NULLIFY (mm_cell, subsys_qm, subsys_mm, qm_atom_index)
191 CALL get_qs_env(qmmm_env%qs_env, input=force_env_section)
195 c_val=old_restart_fn)
196 new_restart_fn = trim(old_restart_fn)//
"-"//trim(label)
198 c_val=new_restart_fn)
202 c_val=old_restart_hist_fn)
203 new_restart_hist_fn = trim(old_restart_hist_fn)//
"-"//trim(label)
205 c_val=new_restart_hist_fn)
209 CALL fist_env_get(qmmm_env%fist_env, cell=mm_cell, subsys=subsys_mm)
210 CALL get_qs_env(qmmm_env%qs_env, cp_subsys=subsys_qm)
211 qm_atom_index => qmmm_env%qm%qm_atom_index
212 CALL apply_qmmm_wrap(subsys_mm, mm_cell, subsys_qm, qm_atom_index, saved_pos)
216 saved_do_translate = qmmm_env%qm%do_translate
217 qmmm_env%qm%do_translate = .false.
223 qmmm_env%qm%do_translate = saved_do_translate
230 c_val=old_restart_fn)
232 c_val=old_restart_hist_fn)
234 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, mimic, 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, sab_cneo, 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, matrix_vhxc, 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, xcint_weights, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Type defining parameters related to the simulation cell.
represents a system: atoms, molecules, their pos,vel,...