Example: Water dimer dissociation
*********************************

This example demonstrates a basic InfRETIS path sampling calculation
for the dissociation of a water dimer using the Amber force field
(GAFF).


Files
=====

The example files are located in
"$AMSHOME/examples/infretis/water_dimer/":

* "water_dimer.run" (main run script)

* "infretis.toml" (InfRETIS configuration)

* "ams_inp/ams.inp" (AMS engine input)


Run script
==========

   #!/bin/sh

   cp -r "$AMSHOME/examples/infretis/water_dimer/ams_inp" .
   cp    "$AMSHOME/examples/infretis/water_dimer/infretis.toml" .

   export NSCM=1 # MPI ranks per infretis worker
   export OMP_NUM_THREADS=1 # OpenMP threads per MPI rank

   # The following retry loop is only needed for regression testing purposes,
   # ordinary simulations need just the few lines between "BEGIN infretis run" and
   # "END infretis run"
   i=0
   retry_limit=4
   while true; do
   # BEGIN infretis run
      cp -r "$AMSHOME/examples/infretis/water_dimer/load" .
      $AMSBIN/uv_scm run infretis exec infretisrun -i infretis.toml
      # -nskip 10 is only needed to make wham work for this extremely short run
      $AMSBIN/uv_scm run infretis exec inft wham -nskip 10
   # END infretis run

   # What follows is purely regression testing logic
      if awk 'BEGIN { max_Pcross = 0.25; } END { exit(!($2 != 0 && $2 <= max_Pcross && $3 != 0 && $3 <= max_Pcross && $4 != 0 && $4 <= max_Pcross)); }' wham/Pcross.txt; then
         # All Pcross are nonzero => WHAM successfull
         # We also check that Pcross aren't too large, which does happen randomly
         # and would just trigger a spurious diff, so we just retry in that case
         # to see if the diff goes away.
         break
      fi
      if [[ ! -s wham/Pcross.txt ]]; then
         # Something went badly wrong, bail out
         exit 1
      elif ((i++ < retry_limit)); then
         echo "WHAM failed, retrying..."
         rm -rf load/ wham/ worker*/ amsworker_*/ restart.toml infretis_data.txt *.log
      else
         echo "Giving up after $i attempts"
         exit 2
      fi
   done
   echo "Success, had to retry $i times"

   echo "BEGIN pathlengths.txt"
   # skip [0-] as that is the least well-defined one
   grep -v '^-1' wham/pathlengths.txt
   echo "END pathlengths.txt"

   for f in wham/{ploc_unscaled,Pcross}.txt; do
      echo "BEGIN ${f#*/}"
      cat "$f"
      echo "END ${f#*/}"
   done

   echo "BEGIN overall Pcross"
   tail -n 1 wham/Pcross.txt
   echo "END overall Pcross"


InfRETIS configuration (infretis.toml)
======================================

   # infretis config

   [runner]
   workers = 2
   wmdrun = [1,1]

   [simulation]
   interfaces = [ 0.30, 0.35 , 0.40, 0.45, 0.50 ]
   steps = 100
   seed = 0
   load_dir = 'load'
   shooting_moves = ['sh', 'sh', 'wf', 'wf', 'wf']


   [simulation.tis_set]
   maxlength = 20000
   aimless = true
   allowmaxlength = false
   zero_momentum = true # momentum true
   temperature = 300


   [engine]
   class = 'ams'
   engine = 'ams' 
   timestep = 0.001
   input_path = 'ams_inp'
   subcycles = 5

   [orderparameter]
   class = 'Distance'
   index = [ 0, 3]
   periodic = false

   [output]
   backup = 'backup'
   data_dir = "./"
   order-file = 1
   energy-file = 1
   trajectory-file = -1
   screen = 1
   pattern = false
   delete_old = true



AMS engine input (ams_inp/ams.inp)
==================================

   MolecularDynamics
       TimeStep 1.0
       Preserve CenterofMass=Yes Momentum=No AngularMomentum=No
       Thermostat Type=none
       InitialVelocities Type=Random Temperature=300 RandomVelocitiesMethod=Exact
   End

   System
       Charge 0.0
       Atoms [A]
           O 49.91002560 49.72051620 50.63497066 ForceField.Type=OW ForceField.Charge=-0.834
           H 49.91043091 50.30117035 49.87400055 ForceField.Type=HW ForceField.Charge=0.417
           H 50.39500713 48.94715309 50.34698963 ForceField.Type=HW ForceField.Charge=0.417
           O 50.09613991 51.82065487 48.74695301 ForceField.Type=OW ForceField.Charge=-0.834
           H 49.73316669 52.70631790 48.73785973 ForceField.Type=HW ForceField.Charge=0.417
           H 50.76516151 51.82843685 48.06241989 ForceField.Type=HW ForceField.Charge=0.417
       End
       BondOrders
           1 2 1.0
           1 3 1.0
           4 5 1.0
           4 6 1.0
       End
   End

   Engine ForceField
       Type GAFF
       NonBondedCutoff 999.0
   EndEngine


Description
===========

This example simulates the dissociation of a water dimer using the
distance between the two oxygen atoms as the order parameter. The
RETIS interfaces are placed at distances of 0.30, 0.35, 0.40, 0.45,
and 0.50 nm.

Key features of this setup:

* **Engine**: ForceField (GAFF) with 1.0 fs timestep

* **Order Parameter**: Oxygen-oxygen distance (atoms 0 and 3)

* **Trajectory Length**: Maximum 20,000 steps

* **Workers**: 2 parallel workers

* **Shooting Moves**: Standard shooting (sh) for the first two
  ensembles, Wire Fencing (wf) for the others

The initial reactive paths in the "load/" directory are required to
start the simulation. These can be generated using biased MD or the
InfInit tool.

After running, the analysis is performed with the "inft wham" command
to compute crossing probabilities and rate constants.
