Skip to content

Commit

Permalink
MD: Refactor REFTRAJ / EVAL_ENERGY_FORCES keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Sep 11, 2023
1 parent 113f45f commit 96b3c5e
Show file tree
Hide file tree
Showing 23 changed files with 163 additions and 33 deletions.
18 changes: 16 additions & 2 deletions src/motion/input_cp2k_md.F
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ MODULE input_cp2k_md
lchar_t,&
real_t
USE kinds, ONLY: dp
USE reftraj_types, ONLY: REFTRAJ_EVAL_ENERGY,&
REFTRAJ_EVAL_ENERGY_FORCES,&
REFTRAJ_EVAL_NONE
USE string_utilities, ONLY: s2a
#include "../base/base_uses.f90"

Expand Down Expand Up @@ -551,15 +554,26 @@ SUBROUTINE create_reftraj_section(section)
CALL section_add_keyword(section, keyword)
CALL keyword_release(keyword)

CALL keyword_create(keyword, __LOCATION__, name="EVAL", &
description="Selects the properties to evaluate for each retrieved snapshot during a REFTRAJ run", &
default_i_val=REFTRAJ_EVAL_NONE, &
enum_i_vals=(/REFTRAJ_EVAL_NONE, REFTRAJ_EVAL_ENERGY, REFTRAJ_EVAL_ENERGY_FORCES/), &
enum_c_vals=s2a("NONE", "ENERGY", "ENERGY_FORCES"), &
enum_desc=s2a("Evaluate nothing", "Evaluate only the energy", "Evaluate energy and forces"))
CALL section_add_keyword(section, keyword)
CALL keyword_release(keyword)

CALL keyword_create(keyword, __LOCATION__, name="eval_energy_forces", &
description="Evaluate energy and forces for each retrieved snapshot during a REFTRAJ run", &
repeats=.FALSE., default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
repeats=.FALSE., default_l_val=.FALSE., lone_keyword_l_val=.TRUE., &
deprecation_notice="Please use MOTION / MD / REFTRAJ / EVAL instead.")
CALL section_add_keyword(section, keyword)
CALL keyword_release(keyword)

CALL keyword_create(keyword, __LOCATION__, name="eval_forces", &
description="Evaluate the forces for each retrieved snapshot during a REFTRAJ run", &
repeats=.FALSE., default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
repeats=.FALSE., default_l_val=.FALSE., lone_keyword_l_val=.TRUE., &
deprecation_notice="Please use MOTION / MD / REFTRAJ / EVAL instead.")
CALL section_add_keyword(section, keyword)
CALL keyword_release(keyword)

Expand Down
8 changes: 5 additions & 3 deletions src/motion/integrator.F
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ MODULE integrator
USE qmmm_util, ONLY: apply_qmmm_walls_reflective
USE qmmmx_update, ONLY: qmmmx_update_force_env
USE qs_environment_types, ONLY: get_qs_env
USE reftraj_types, ONLY: reftraj_type
USE reftraj_types, ONLY: REFTRAJ_EVAL_ENERGY_FORCES,&
REFTRAJ_EVAL_NONE,&
reftraj_type
USE reftraj_util, ONLY: compute_msd_reftraj
USE rt_propagation_methods, ONLY: propagation_step
USE rt_propagation_output, ONLY: rt_prop_output
Expand Down Expand Up @@ -1656,8 +1658,8 @@ SUBROUTINE reftraj(md_env)
! Compute energy and forces
![NB] let reftraj work with force mixing which does not have consistent energies and forces
CALL force_env_calc_energy_force(force_env, &
calc_force=(reftraj_env%info%eval_forces .OR. reftraj_env%info%eval_ef), &
eval_energy_forces=reftraj_env%info%eval_ef, &
calc_force=(reftraj_env%info%eval == REFTRAJ_EVAL_ENERGY_FORCES), &
eval_energy_forces=(reftraj_env%info%eval /= REFTRAJ_EVAL_NONE), &
require_consistent_energy_force=.FALSE.)
! Metadynamics
Expand Down
5 changes: 3 additions & 2 deletions src/motion/md_energies.F
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ MODULE md_energies
kelvin
USE qmmm_types, ONLY: qmmm_env_type
USE qs_linres_polar_utils, ONLY: write_polarisability_tensor
USE reftraj_types, ONLY: reftraj_type
USE reftraj_types, ONLY: REFTRAJ_EVAL_NONE,&
reftraj_type
USE simpar_types, ONLY: simpar_type
USE thermal_region_types, ONLY: thermal_regions_type
USE thermal_region_utils, ONLY: print_thermal_regions_temperature
Expand Down Expand Up @@ -228,7 +229,7 @@ SUBROUTINE md_ener_reftraj(md_env, md_ener)
CALL zero_md_ener(md_ener, tkind=.FALSE., tshell=.FALSE.)
CALL get_md_env(md_env=md_env, force_env=force_env, reftraj=reftraj)

IF (reftraj%info%eval_ef) THEN
IF (reftraj%info%eval /= REFTRAJ_EVAL_NONE) THEN
CALL force_env_get(force_env, potential_energy=md_ener%epot)
ELSE
md_ener%epot = reftraj%epot
Expand Down
19 changes: 14 additions & 5 deletions src/motion/reftraj_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ MODULE reftraj_types
PUBLIC :: reftraj_type, reftraj_msd_type, &
create_reftraj, release_reftraj

INTEGER, PARAMETER, PUBLIC :: REFTRAJ_EVAL_NONE = 101
INTEGER, PARAMETER, PUBLIC :: REFTRAJ_EVAL_ENERGY = 102
INTEGER, PARAMETER, PUBLIC :: REFTRAJ_EVAL_ENERGY_FORCES = 103

! **************************************************************************************************
!> \brief parameters related to the analysis of previously generated trajecorties
!> \author MI
Expand All @@ -38,8 +42,7 @@ MODULE reftraj_types
INTEGER :: first_snapshot = 0
INTEGER :: last_snapshot = 0
INTEGER :: stride = 0
LOGICAL :: eval_ef = .FALSE.
LOGICAL :: eval_forces = .FALSE.
INTEGER :: eval = REFTRAJ_EVAL_NONE
LOGICAL :: variable_volume = .FALSE.
LOGICAL :: msd = .FALSE.
TYPE(cp_parser_type), POINTER :: traj_parser => NULL()
Expand Down Expand Up @@ -89,6 +92,7 @@ SUBROUTINE create_reftraj(reftraj, reftraj_section, para_env)
TYPE(mp_para_env_type), POINTER :: para_env

CHARACTER(LEN=default_path_length) :: filename
LOGICAL :: old_eval_ef, old_eval_forces

NULLIFY (reftraj%info)
NULLIFY (reftraj%msd)
Expand All @@ -113,9 +117,14 @@ SUBROUTINE create_reftraj(reftraj, reftraj_section, para_env)
CALL section_vals_val_get(reftraj_section, "FIRST_SNAPSHOT", i_val=reftraj%info%first_snapshot)
CALL section_vals_val_get(reftraj_section, "LAST_SNAPSHOT", i_val=reftraj%info%last_snapshot)
CALL section_vals_val_get(reftraj_section, "STRIDE", i_val=reftraj%info%stride)
CALL section_vals_val_get(reftraj_section, "EVAL_ENERGY_FORCES", l_val=reftraj%info%eval_ef)
CALL section_vals_val_get(reftraj_section, "EVAL_FORCES", l_val=reftraj%info%eval_forces)
IF (reftraj%info%eval_forces) reftraj%info%eval_ef = .TRUE.
CALL section_vals_val_get(reftraj_section, "EVAL", i_val=reftraj%info%eval)

! Read deprecated keywords to retain backwards compatibility.
! For details see: https://github.com/cp2k/cp2k/issues/894
CALL section_vals_val_get(reftraj_section, "EVAL_ENERGY_FORCES", l_val=old_eval_ef)
CALL section_vals_val_get(reftraj_section, "EVAL_FORCES", l_val=old_eval_forces)
IF (old_eval_ef) reftraj%info%eval = REFTRAJ_EVAL_ENERGY
IF (old_eval_forces) reftraj%info%eval = REFTRAJ_EVAL_ENERGY_FORCES

CALL section_vals_val_get(reftraj_section, "MSD%_SECTION_PARAMETERS_", &
l_val=reftraj%info%msd)
Expand Down
2 changes: 2 additions & 0 deletions tests/Fist/regtest-1-2/TEST_FILES
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ deca_ala3.inp 2 1.0E-14 -
deca_ala_reftraj.inp 2 1.0E-14 -1.0361509045299999
deca_ala4.inp 2 2e-12 -1.04188113936
deca_ala_reftraj2.inp 2 2e-12 -1.04188113933
deca_ala_reftraj2_deprecated.inp 2 2e-12 -1.04188113933
deca_ala_reftraj3.inp 2 1.0E-14 -1.0415155385499999
deca_ala_reftraj3_deprecated.inp 2 1.0E-14 -1.0415155385499999
deca_ala5.inp 2 1.0E-14 -0.96264611636700004
h2po4.inp 2 1.0E-14 -0.793833783008E+01
#MOL_SET
Expand Down
2 changes: 1 addition & 1 deletion tests/Fist/regtest-1-2/deca_ala_reftraj.inp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
STEPS 11
&REFTRAJ
TRAJ_FILE_NAME deca_ala3-pos-1.xyz
EVAL_ENERGY_FORCES T
EVAL ENERGY
&END
&END MD
&PRINT
Expand Down
2 changes: 1 addition & 1 deletion tests/Fist/regtest-1-2/deca_ala_reftraj2.inp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
VARIABLE_VOLUME
FIRST_SNAPSHOT 3
LAST_SNAPSHOT 11
EVAL_ENERGY_FORCES T
EVAL ENERGY
&END
&END MD
&PRINT
Expand Down
53 changes: 53 additions & 0 deletions tests/Fist/regtest-1-2/deca_ala_reftraj2_deprecated.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#CPQA DEPENDS deca_ala4.inp

&FORCE_EVAL
METHOD FIST
&MM
&FORCEFIELD
parm_file_name ../sample_pot/deca_ala.pot
parmtype CHM
&END FORCEFIELD
&POISSON
&EWALD
EWALD_TYPE ewald
ALPHA .36
GMAX 29
&END EWALD
&END POISSON
&END MM
&SUBSYS
&CELL
ABC 50.0 50.0 50.0
&END CELL
&TOPOLOGY
CHARGE_BETA
COORD_FILE_NAME ../sample_pdb/deca_ala.pdb
COORDINATE PDB
PARA_RES
&END TOPOLOGY
&END SUBSYS
&END FORCE_EVAL
&GLOBAL
PRINT_LEVEL LOW
PROJECT deca_ala_ref2
RUN_TYPE md
&END GLOBAL
&MOTION
&MD
ENSEMBLE REFTRAJ
STEPS 11
&REFTRAJ
TRAJ_FILE_NAME deca_ala4-pos-1.xyz
CELL_FILE_NAME deca_ala4-1.cell
VARIABLE_VOLUME
FIRST_SNAPSHOT 3
LAST_SNAPSHOT 11
EVAL_ENERGY_FORCES T
&END
&END MD
&PRINT
&TRAJECTORY
FILENAME =reftraj2.xyz
&END
&END
&END MOTION
2 changes: 1 addition & 1 deletion tests/Fist/regtest-1-2/deca_ala_reftraj3.inp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
FIRST_SNAPSHOT 3
LAST_SNAPSHOT 11
STRIDE 3
EVAL_ENERGY_FORCES T
EVAL ENERGY_FORCES
&END
&END MD
&PRINT
Expand Down
54 changes: 54 additions & 0 deletions tests/Fist/regtest-1-2/deca_ala_reftraj3_deprecated.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#CPQA DEPENDS deca_ala4.inp

&FORCE_EVAL
METHOD FIST
&MM
&FORCEFIELD
parm_file_name ../sample_pot/deca_ala.pot
parmtype CHM
&END FORCEFIELD
&POISSON
&EWALD
EWALD_TYPE ewald
ALPHA .36
GMAX 29
&END EWALD
&END POISSON
&END MM
&SUBSYS
&CELL
ABC 50.0 50.0 50.0
&END CELL
&TOPOLOGY
CHARGE_BETA
COORD_FILE_NAME ../sample_pdb/deca_ala.pdb
COORDINATE PDB
PARA_RES
&END TOPOLOGY
&END SUBSYS
&END FORCE_EVAL
&GLOBAL
PRINT_LEVEL LOW
PROJECT deca_ala_ref3
RUN_TYPE md
&END GLOBAL
&MOTION
&MD
ENSEMBLE REFTRAJ
STEPS 11
&REFTRAJ
TRAJ_FILE_NAME deca_ala4-pos-1.xyz
CELL_FILE_NAME deca_ala4-1.cell
VARIABLE_VOLUME
FIRST_SNAPSHOT 3
LAST_SNAPSHOT 11
STRIDE 3
EVAL_FORCES T
&END
&END MD
&PRINT
&TRAJECTORY
FILENAME =reftraj2.xyz
&END
&END
&END MOTION
2 changes: 1 addition & 1 deletion tests/Fist/regtest-4/nh3-meta-ref.inp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
STEPS 51
&REFTRAJ
TRAJ_FILE_NAME NH3-pos-1.xyz
EVAL_ENERGY_FORCES F
EVAL NONE
&END
&END MD
&FREE_ENERGY
Expand Down
2 changes: 1 addition & 1 deletion tests/Fist/regtest-4/nh3-meta-ref2.inp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
STEPS 51
&REFTRAJ
TRAJ_FILE_NAME NH3-pos-1.xyz
EVAL_ENERGY_FORCES F
EVAL NONE
FIRST_SNAPSHOT 10
LAST_SNAPSHOT 20
&END
Expand Down
6 changes: 1 addition & 5 deletions tests/Fist/regtest-7-1/uo2_shell_npt_msd.inp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@
ENSEMBLE REFTRAJ
STEPS 20
&REFTRAJ

TRAJ_FILE_NAME uo2_shell_npt300-pos-1.xyz
CELL_FILE_NAME uo2_shell_npt300-1.cell
VARIABLE_VOLUME
EVAL_ENERGY_FORCES F
EVAL NONE
FIRST_SNAPSHOT 3
LAST_SNAPSHOT 15
STRIDE 2
Expand All @@ -106,10 +105,7 @@
DISPLACED_ATOM
DISPLACEMENT_TOL [angstrom] 0.5
&END


&END

&END MD
&PRINT
&TRAJECTORY OFF
Expand Down
2 changes: 1 addition & 1 deletion tests/QMMM/QS/regtest-1/H2O-qmmm-gauss-force-mixing-1.inp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
ENSEMBLE REFTRAJ
&REFTRAJ
TRAJ_FILE_NAME ../sample_xyz/5H2O_adaptive.xyz
EVAL_ENERGY_FORCES
EVAL ENERGY
&END REFTRAJ
&END MD

Expand Down
2 changes: 1 addition & 1 deletion tests/QMMM/QS/regtest-1/H2O-qmmm-none-force-mixing-1.inp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
ENSEMBLE REFTRAJ
&REFTRAJ
TRAJ_FILE_NAME ../sample_xyz/5H2O_adaptive.xyz
EVAL_ENERGY_FORCES
EVAL ENERGY
&END REFTRAJ
&END MD

Expand Down
2 changes: 1 addition & 1 deletion tests/QS/regtest-sparsity/Ar-ref-1.inp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# next MD step, overlap matrix will be dense
&REFTRAJ
TRAJ_FILE_NAME Ar-ref-1.xyz
EVAL_ENERGY_FORCES T
EVAL ENERGY
&END
&END MD
&END MOTION
Expand Down
2 changes: 1 addition & 1 deletion tests/QS/regtest-sparsity/Ar-ref-2.inp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# next MD step, overlap matrix will be sparse
&REFTRAJ
TRAJ_FILE_NAME Ar-ref-2.xyz
EVAL_ENERGY_FORCES T
EVAL ENERGY
&END
&END MD
&END MOTION
Expand Down
2 changes: 1 addition & 1 deletion tests/QS/regtest-sparsity/Ar-ref-3.inp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
# next MD step, overlap matrix will be sparse
&REFTRAJ
TRAJ_FILE_NAME Ar-ref-1.xyz
EVAL_ENERGY_FORCES T
EVAL ENERGY
&END
&END MD
&END MOTION
Expand Down
2 changes: 1 addition & 1 deletion tests/QS/regtest-sparsity/Ar-ref-4.inp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
# next MD step, overlap matrix will be sparse
&REFTRAJ
TRAJ_FILE_NAME Ar-ref-2.xyz
EVAL_ENERGY_FORCES T
EVAL ENERGY
&END
&END MD
&END MOTION
Expand Down
2 changes: 1 addition & 1 deletion tests/QS/regtest-sparsity/Ar-ref-5.inp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
# next MD step, overlap matrix will be sparse
&REFTRAJ
TRAJ_FILE_NAME Ar-ref-1.xyz
EVAL_ENERGY_FORCES T
EVAL ENERGY
&END
&END MD
&END MOTION
Expand Down
2 changes: 1 addition & 1 deletion tests/QS/regtest-sparsity/Ar-ref-6.inp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
# next MD step, overlap matrix will be sparse
&REFTRAJ
TRAJ_FILE_NAME Ar-ref-2.xyz
EVAL_ENERGY_FORCES T
EVAL ENERGY
&END
&END MD
&END MOTION
Expand Down
3 changes: 1 addition & 2 deletions tests/QS/regtest-sparsity/Ar-ref-7.inp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
# next MD step, overlap matrix will be sparse
&REFTRAJ
TRAJ_FILE_NAME Ar-ref-2.xyz
EVAL_ENERGY_FORCES T
EVAL_FORCES F
EVAL ENERGY
&END
&END MD
&END MOTION
Expand Down

0 comments on commit 96b3c5e

Please sign in to comment.