From 06afc7494c599b66c46545c41366887ffd76ca32 Mon Sep 17 00:00:00 2001 From: Alec <30010253+alec-glisman@users.noreply.github.com> Date: Wed, 13 Mar 2024 09:15:01 -0700 Subject: [PATCH] updated sampling workflow to check for more files and exit properly --- scripts/method/sampling_md.sh | 367 +++++++++++---------- scripts/method/sampling_metadynamics.sh | 403 +++++++++++++----------- scripts/method/sampling_opes_explore.sh | 381 ++++++++++++---------- scripts/method/sampling_opes_one.sh | 190 ++++++----- 4 files changed, 762 insertions(+), 579 deletions(-) diff --git a/scripts/method/sampling_md.sh b/scripts/method/sampling_md.sh index 834fc73..9ed1c9d 100755 --- a/scripts/method/sampling_md.sh +++ b/scripts/method/sampling_md.sh @@ -33,33 +33,18 @@ time_init="$(date +%Y_%m_%d_%H_%M_%S)" cwd_init="$(pwd)" cwd="${cwd_init}/3-sampling-md" log_dir="${cwd}/logs" -log_file="${log_dir}/${time_init}-md.log" # ####################################################################################### # Check for existing files ############################################################## # ####################################################################################### echo "CRITICAL: Starting MD production" +log_file="${log_dir}/${time_init}-md.log" # move to working directory mkdir -p "${cwd}" mkdir -p "${log_dir}" cd "${cwd}" || exit -# check if output gro file already exists -if [[ -f "output/system.gro" ]]; then - echo "WARNING: output/system.gro already exists" - echo "INFO: Exiting script" - exit 0 -fi - -# ####################################################################################### -# Run simulation ######################################################################## -# ####################################################################################### -echo "INFO: Running production MD simulation" -previous_sim_name="prod_eqbm" -previous_archive_dir="${cwd_init}/2-equilibration/4-output" -sim_name="prod_md" - # write header to log file { echo "################################################################################" @@ -72,6 +57,60 @@ sim_name="prod_md" echo "" } >>"${log_file}" 2>&1 +# ####################################################################################### +# Prepare simulation #################################################################### +# ####################################################################################### +previous_sim_name="prod_eqbm" +previous_archive_dir="${cwd_init}/2-equilibration/4-output" +sim_name="prod_md" + +if [[ ! -f "${sim_name}.tpr" ]]; then + echo "INFO: Preparing simulation tpr file" + { + # copy output files from equilibration + cp -np "${previous_archive_dir}/${previous_sim_name}.gro" "${previous_sim_name}.gro" || exit 1 + cp -np "${previous_archive_dir}/topol.top" "topol.top" || exit 1 + cp -np "${previous_archive_dir}/index.ndx" "index.ndx" || exit 1 + + # copy mdp file + cp "${mdp_file}" "${sim_name}.mdp" || exit 1 + sed -i 's/ref-t.*/ref-t = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 + sed -i 's/gen-temp.*/gen-temp = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 + sed -i 's/ref-p.*/ref-p = '"${PRESSURE_BAR} ${PRESSURE_BAR}/g" "${sim_name}.mdp" || exit 1 + # small surfaces have smaller cutoffs + if [[ "${SURFACE_SIZE}" -lt 4 ]]; then + sed -i 's/^rlist.*/rlist = 0.7/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^rcoulomb.*/rcoulomb = 0.7/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^rvdw.*/rvdw = 0.7/g' "${sim_name}.mdp" || exit 1 + fi + # add vacuum parameters to mdp file + if [[ "${VACUUM_HEIGHT}" -gt 0 ]]; then + sed -i 's/^ewald-geometry .*/ewald-geometry = 3dc/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^pbc .*/pbc = xy/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^nwall .*/nwall = 2/g' "${sim_name}.mdp" || exit 1 + fi + + # create tpr file + "${GMX_BIN}" -nocopyright grompp \ + -f "${sim_name}.mdp" \ + -c "${previous_sim_name}.gro" \ + -r "${previous_sim_name}.gro" \ + -n "index.ndx" \ + -p "topol.top" \ + -o "${sim_name}.tpr" + rm "${previous_sim_name}.gro" || exit 1 + } >>"${log_file}" 2>&1 + +else + echo "DEBUG: Using existing tpr file" + +fi + +# ####################################################################################### +# Run simulation ######################################################################## +# ####################################################################################### +echo "INFO: Running production MD simulation" + if [[ -f "completed.txt" ]]; then echo "WARNING: completed.txt already exists" echo "INFO: Skipping production MD simulation" @@ -81,58 +120,39 @@ elif [[ "${FLAG_ARCHIVE}" = true ]]; then echo "INFO: Skipping production MD simulation" else + echo "INFO: Calling mdrun" { - # copy output files from equilibration - cp -np "${previous_archive_dir}/${previous_sim_name}.gro" "${previous_sim_name}.gro" || exit 1 - cp -np "${previous_archive_dir}/topol.top" "topol.top" || exit 1 - cp -np "${previous_archive_dir}/index.ndx" "index.ndx" || exit 1 - - # if tpr file does not exist, create it - if [[ ! -f "${sim_name}.tpr" ]]; then - echo "DEBUG: Creating tpr file" - - # copy mdp file - cp "${mdp_file}" "${sim_name}.mdp" || exit 1 - sed -i 's/ref-t.*/ref-t = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 - sed -i 's/gen-temp.*/gen-temp = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 - sed -i 's/ref-p.*/ref-p = '"${PRESSURE_BAR} ${PRESSURE_BAR}/g" "${sim_name}.mdp" || exit 1 - # small surfaces have smaller cutoffs - if [[ "${SURFACE_SIZE}" -lt 4 ]]; then - sed -i 's/^rlist.*/rlist = 0.7/g' "${sim_name}.mdp" || exit 1 - sed -i 's/^rcoulomb.*/rcoulomb = 0.7/g' "${sim_name}.mdp" || exit 1 - sed -i 's/^rvdw.*/rvdw = 0.7/g' "${sim_name}.mdp" || exit 1 - fi - # add vacuum parameters to mdp file - if [[ "${VACUUM_HEIGHT}" -gt 0 ]]; then - sed -i 's/^ewald-geometry .*/ewald-geometry = 3dc/g' "${sim_name}.mdp" || exit 1 - sed -i 's/^pbc .*/pbc = xy/g' "${sim_name}.mdp" || exit 1 - sed -i 's/^nwall .*/nwall = 2/g' "${sim_name}.mdp" || exit 1 - fi - - # create tpr file - "${GMX_BIN}" -nocopyright grompp \ - -f "${sim_name}.mdp" \ - -c "${previous_sim_name}.gro" \ - -r "${previous_sim_name}.gro" \ - -n "index.ndx" \ - -p "topol.top" \ - -o "${sim_name}.tpr" - rm "${previous_sim_name}.gro" || exit 1 - fi - # shellcheck disable=SC2153,SC2086 "${GMX_BIN}" -nocopyright mdrun -v \ -maxh "${WALLTIME_HOURS}" \ -deffnm "${sim_name}" -cpi "${sim_name}.cpt" \ ${GMX_CPU_ARGS} ${GMX_GPU_ARGS} \ -noappend + } >>"${log_file}" 2>&1 + + # check if gromacs simulation completed or was terminated + echo "INFO: checking if simulation completed successfully" + bool_completed=false + while IFS= read -r line; do + if [[ "${line}" == *"writing final coordinates."* ]]; then + bool_completed=true + fi + done <"${log_file}" + echo "DEBUG: bool_completed = ${bool_completed}" - # make completed simulation text file + # make completed simulation text file if simulation completed successfully + if [[ "${bool_completed}" = true ]]; then + echo "INFO: simulation completed successfully" touch "completed.txt" - # write completed simulation text file echo "completed: $(date)" >"completed.txt" - } >>"${log_file}" 2>&1 + # otherwise, exit script without error + else + echo "WARNING: ${sim_name}.gro does not exist. simulation did not complete successfully" + echo "INFO: exiting script" + exit 0 + fi + fi # ####################################################################################### @@ -155,141 +175,172 @@ log_file="${log_dir}/${time_init}-concatenation.log" # rsync output files to archive directory archive_dir="1-runs" -{ - rsync --archive --verbose --progress --human-readable --itemize-changes \ - "${sim_name}."* "${archive_dir}/" || exit 1 -} >>"${log_file}" 2>&1 +if [[ ! -d "${archive_dir}" ]] || [[ "${FLAG_ARCHIVE}" = true ]]; then + echo "INFO: Archiving simulation" + { + rsync --archive --verbose --progress --human-readable --itemize-changes \ + "${sim_name}."* "${archive_dir}/" || exit 1 + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.data "${archive_dir}/" || exit 1 + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.dat "${archive_dir}/" || exit 1 + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.Kernels* "${archive_dir}/" || exit 1 + } >>"${log_file}" 2>&1 +else + echo "INFO: Skipping archiving simulation" +fi # concatenate files into single trajectory -echo "INFO: Concatenating trajectories" concat_dir="2-concatenated" -{ - mkdir -p "${concat_dir}" - - # concatenate xtc files - "${GMX_BIN}" -nocopyright trjcat \ - -f "${archive_dir}/${sim_name}."*.xtc \ - -o "${concat_dir}/${sim_name}.xtc" || exit 1 - - # concatenate edr files - "${GMX_BIN}" -nocopyright eneconv \ - -f "${archive_dir}/${sim_name}."*.edr \ - -o "${concat_dir}/${sim_name}.edr" || exit 1 - - # copy other files - cp "${archive_dir}/${sim_name}.tpr" "${concat_dir}/${sim_name}.tpr" || exit 1 - - # dump pdb file from last frame - "${GMX_BIN}" -nocopyright trjconv \ - -f "${concat_dir}/${sim_name}.xtc" \ - -s "${concat_dir}/${sim_name}.tpr" \ - -o "${concat_dir}/${sim_name}.pdb" \ - -pbc 'mol' -ur 'compact' -conect \ - -dump "1000000000000" <>"${log_file}" 2>&1 + + # copy plumed files + cp "${archive_dir}/"*.data "${concat_dir}/" || exit 1 + } >>"${log_file}" 2>&1 +else + echo "INFO: Skipping concatenation" +fi # dump trajectory without solvent -echo "INFO: Dumping trajectory without solvent" nosol_dir="3-no-solvent" -{ - mkdir -p "${nosol_dir}" - - # pdb structure - "${GMX_BIN}" trjconv \ - -f "${concat_dir}/${sim_name}.xtc" \ - -s "${concat_dir}/${sim_name}.tpr" \ - -o "${nosol_dir}/${sim_name}.pdb" \ - -pbc 'mol' -ur 'compact' -conect \ - -dump "1000000000000" <>"${log_file}" 2>&1 + # copy *.data files + cp "${concat_dir}/"*.data -t "${nosol_dir}/" || exit 1 + } >>"${log_file}" 2>&1 +else + echo "INFO: Skipping dumping trajectory without solvent" +fi # ####################################################################################### # Analysis ############################################################################## # ####################################################################################### -echo "INFO: Analyzing trajectory" log_file="${log_dir}/${time_init}-analysis.log" -# write header to log file -{ - echo "################################################################################" - echo "Script: ${BASH_SOURCE[0]}" - echo "Date: $(date)" - echo "Host: $(hostname)" - echo "System: ${MONOMER}-${BLOCK}-${CRYSTAL}-${SURFACE}-${SURFACE_SIZE}nm-${BOX_HEIGHT}nm-${N_MONOMER}mon-${N_CHAIN}chain-${N_CARBONATE}co3-${N_SODIUM}na-${N_CALCIUM}ca-${N_CHLORINE}cl" - echo "Ensemble: ${PRODUCTION_ENSEMBLE} ${TEMPERATURE_K}K ${PRESSURE_BAR}bar" - echo "################################################################################" - echo "" -} >>"${log_file}" 2>&1 +if [[ ! -d "png" ]] || [[ "${FLAG_ARCHIVE}" = true ]]; then + echo "INFO: Analyzing trajectory" + # write header to log file + { + echo "################################################################################" + echo "Script: ${BASH_SOURCE[0]}" + echo "Date: $(date)" + echo "Host: $(hostname)" + echo "System: ${MONOMER}-${BLOCK}-${CRYSTAL}-${SURFACE}-${SURFACE_SIZE}nm-${BOX_HEIGHT}nm-${N_MONOMER}mon-${N_CHAIN}chain-${N_CARBONATE}co3-${N_SODIUM}na-${N_CALCIUM}ca-${N_CHLORINE}cl" + echo "Ensemble: ${PRODUCTION_ENSEMBLE} ${TEMPERATURE_K}K ${PRESSURE_BAR}bar" + echo "################################################################################" + echo "" + } >>"${log_file}" 2>&1 -{ - # plot system parameters over time - params=('Potential' 'Kinetic-En.' 'Total-Energy' 'Temperature' 'Pressure') - if [[ "${PRODUCTION_ENSEMBLE^^}" == "NPT" ]]; then - params+=('Density') - fi - echo "DEBUG: Parameters to plot: ${params[*]}" - for param in "${params[@]}"; do - filename="${param,,}" - "${GMX_BIN}" -nocopyright energy \ - -f "${concat_dir}/${sim_name}.edr" \ - -o "${filename}.xvg" <>"${log_file}" 2>&1 - # copy all png files to png directory - mkdir -p "png" - cp -p ./*.png "png/" || exit 1 - rm ./*.png || exit 1 -} >>"${log_file}" 2>&1 +else + echo "INFO: Skipping analysis" +fi # ####################################################################################### # Clean Up ############################################################################## # ####################################################################################### echo "INFO: Cleaning up" -log_file="cleanup.log" +log_file="${log_dir}/${time_init}-cleanup.log" -# iterate over directories and delete backup files -for dir in "${archive_dir}" "${concat_dir}" "${nosol_dir}" "."; do - find "${dir}" -type f -name '#*#' -delete || true -done +{ + # iterate over directories and delete backup files + for dir in "${archive_dir}" "${concat_dir}" "${nosol_dir}" "."; do + find "${dir}" -type f -name '#*#' -delete || true + done -# move to initial working directory -cd "${cwd_init}" || exit 1 + # move to initial working directory + cd "${cwd_init}" || exit 1 +} >>"${log_file}" 2>&1 echo "CRITICAL: Finished MD sampling" diff --git a/scripts/method/sampling_metadynamics.sh b/scripts/method/sampling_metadynamics.sh index cc9a987..4dceba2 100755 --- a/scripts/method/sampling_metadynamics.sh +++ b/scripts/method/sampling_metadynamics.sh @@ -37,21 +37,17 @@ time_init="$(date +%Y_%m_%d_%H_%M_%S)" cwd_init="$(pwd)" cwd="${cwd_init}/3-sampling-metadynamics" log_dir="${cwd}/logs" + +# ####################################################################################### +# Check for existing files ############################################################## +# ####################################################################################### +echo "CRITICAL: Starting Metadynamics production" log_file="${log_dir}/${time_init}-md.log" # move to working directory mkdir -p "${cwd}" cd "${cwd}" || exit mkdir -p "${log_dir}" -echo "CRITICAL: Starting Metadynamics production" - -# ####################################################################################### -# Run simulation ######################################################################## -# ####################################################################################### -echo "INFO: Running production Metadynamics simulation" -previous_sim_name="prod_eqbm" -previous_archive_dir="${cwd_init}/2-equilibration/4-output" -sim_name="prod_opes_explore" # write header to log file { @@ -65,6 +61,79 @@ sim_name="prod_opes_explore" echo "" } >>"${log_file}" 2>&1 +# ####################################################################################### +# Prepare simulation #################################################################### +# ####################################################################################### +previous_sim_name="prod_eqbm" +previous_archive_dir="${cwd_init}/2-equilibration/4-output" +sim_name="prod_opes_explore" + +if [[ ! -f "${sim_name}.tpr" ]]; then + echo "INFO: Preparing simulation tpr file" + { + # copy output files from equilibration + cp -np "${previous_archive_dir}/${previous_sim_name}.gro" "${previous_sim_name}.gro" || exit 1 + cp -np "${previous_archive_dir}/topol.top" "topol.top" || exit 1 + cp -np "${previous_archive_dir}/index.ndx" "index.ndx" || exit 1 + + # copy mdp file + cp "${mdp_file}" "${sim_name}.mdp" || exit 1 + sed -i 's/ref-t.*/ref-t = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 + sed -i 's/gen-temp.*/gen-temp = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 + sed -i 's/ref-p.*/ref-p = '"${PRESSURE_BAR} ${PRESSURE_BAR}/g" "${sim_name}.mdp" || exit 1 + # small surfaces have smaller cutoffs + if [[ "${SURFACE_SIZE}" -lt 4 ]]; then + sed -i 's/^rlist.*/rlist = 0.7/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^rcoulomb.*/rcoulomb = 0.7/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^rvdw.*/rvdw = 0.7/g' "${sim_name}.mdp" || exit 1 + fi + # add vacuum parameters to mdp file + if [[ "${VACUUM_HEIGHT}" -gt 0 ]]; then + sed -i 's/^ewald-geometry .*/ewald-geometry = 3dc/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^pbc .*/pbc = xy/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^nwall .*/nwall = 2/g' "${sim_name}.mdp" || exit 1 + fi + + # copy plumed file + cp "${dat_file}" "plumed.dat" || exit 1 + sed -i 's/{LOWER_WALL_HEIGHT}/'"${PE_WALL_MIN}"'/g' "plumed.dat" || exit 1 + sed -i 's/{UPPER_WALL_HEIGHT}/'"${PE_WALL_MAX}"'/g' "plumed.dat" || exit 1 + sed -i 's/{WALL_OFFSET}/'"${ATOM_OFFSET}"'/g' "plumed.dat" || exit 1 + sed -i 's/{ATOM_REFERENCE}/'"${ATOM_REFERENCE}"'/g' "plumed.dat" || exit 1 + sed -i "s/{METAD_PACE}/${METAD_PACE}/g" 'plumed.dat' || exit 1 + sed -i "s/{METAD_HEIGHT}/${METAD_HEIGHT}/g" 'plumed.dat' || exit 1 + sed -i "s/{METAD_SIGMA}/${METAD_SIGMA}/g" 'plumed.dat' || exit 1 + sed -i "s/{METAD_BIASFACTOR}/${METAD_BIASFACTOR}/g" 'plumed.dat' || exit 1 + sed -i "s/{TEMPERATURE_K}/${TEMPERATURE_K}/g" 'plumed.dat' || exit 1 + sed -i "s/{METAD_GRID_MIN}/${METAD_GRID_MIN}/g" 'plumed.dat' || exit 1 + sed -i "s/{METAD_GRID_MAX}/${METAD_GRID_MAX}/g" 'plumed.dat' || exit 1 + sed -i "s/{METAD_GRID_SPACING}/${METAD_GRID_SPACING}/g" 'plumed.dat' || exit 1 + if [[ "${N_CALCIUM}" -eq '0' ]]; then + sed -i 's/NDX_GROUP=Aqueous_Calcium/NDX_GROUP=Crystal_Top_Surface_Calcium/g' "plumed.dat" || exit 1 + fi + + # create tpr file + "${GMX_BIN}" -nocopyright grompp \ + -f "${sim_name}.mdp" \ + -c "${previous_sim_name}.gro" \ + -r "${previous_sim_name}.gro" \ + -n "index.ndx" \ + -p "topol.top" \ + -o "${sim_name}.tpr" + rm "${previous_sim_name}.gro" || exit 1 + } >>"${log_file}" 2>&1 + +else + echo "DEBUG: Using existing tpr file" + sed -i 's/#RESTART/RESTART/g' "plumed.dat" || exit 1 + +fi + +# ####################################################################################### +# Run simulation ######################################################################## +# ####################################################################################### +echo "INFO: Running production Metadynamics simulation" + if [[ -f "completed.txt" ]]; then echo "WARNING: completed.txt already exists" echo "INFO: Skipping production Metadynamics simulation" @@ -74,68 +143,8 @@ elif [[ "${FLAG_ARCHIVE}" = true ]]; then echo "INFO: Skipping production Metadynamics simulation" else + echo "INFO: Calling mdrun" { - # copy output files from equilibration - cp -np "${previous_archive_dir}/${previous_sim_name}.gro" "${previous_sim_name}.gro" || exit 1 - cp -np "${previous_archive_dir}/topol.top" "topol.top" || exit 1 - cp -np "${previous_archive_dir}/index.ndx" "index.ndx" || exit 1 - - # if tpr file does not exist, create it - if [[ ! -f "${sim_name}.tpr" ]]; then - echo "DEBUG: Creating tpr file" - - # copy mdp file - cp "${mdp_file}" "${sim_name}.mdp" || exit 1 - sed -i 's/ref-t.*/ref-t = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 - sed -i 's/gen-temp.*/gen-temp = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 - sed -i 's/ref-p.*/ref-p = '"${PRESSURE_BAR} ${PRESSURE_BAR}/g" "${sim_name}.mdp" || exit 1 - # small surfaces have smaller cutoffs - if [[ "${SURFACE_SIZE}" -lt 4 ]]; then - sed -i 's/^rlist.*/rlist = 0.7/g' "${sim_name}.mdp" || exit 1 - sed -i 's/^rcoulomb.*/rcoulomb = 0.7/g' "${sim_name}.mdp" || exit 1 - sed -i 's/^rvdw.*/rvdw = 0.7/g' "${sim_name}.mdp" || exit 1 - fi - # add vacuum parameters to mdp file - if [[ "${VACUUM_HEIGHT}" -gt 0 ]]; then - sed -i 's/^ewald-geometry .*/ewald-geometry = 3dc/g' "${sim_name}.mdp" || exit 1 - sed -i 's/^pbc .*/pbc = xy/g' "${sim_name}.mdp" || exit 1 - sed -i 's/^nwall .*/nwall = 2/g' "${sim_name}.mdp" || exit 1 - fi - - # copy plumed file - cp "${dat_file}" "plumed.dat" || exit 1 - if [[ "${N_CALCIUM}" -eq '0' ]]; then - sed -i 's/NDX_GROUP=Aqueous_Calcium/NDX_GROUP=Crystal_Top_Surface_Calcium/g' "plumed.dat" || exit 1 - fi - sed -i 's/{LOWER_WALL_HEIGHT}/'"${PE_WALL_MIN}"'/g' "plumed.dat" || exit 1 - sed -i 's/{UPPER_WALL_HEIGHT}/'"${PE_WALL_MAX}"'/g' "plumed.dat" || exit 1 - sed -i 's/{WALL_OFFSET}/'"${ATOM_OFFSET}"'/g' "plumed.dat" || exit 1 - sed -i 's/{ATOM_REFERENCE}/'"${ATOM_REFERENCE}"'/g' "plumed.dat" || exit 1 - sed -i "s/{METAD_PACE}/${METAD_PACE}/g" 'plumed.dat' || exit 1 - sed -i "s/{METAD_HEIGHT}/${METAD_HEIGHT}/g" 'plumed.dat' || exit 1 - sed -i "s/{METAD_SIGMA}/${METAD_SIGMA}/g" 'plumed.dat' || exit 1 - sed -i "s/{METAD_BIASFACTOR}/${METAD_BIASFACTOR}/g" 'plumed.dat' || exit 1 - sed -i "s/{TEMPERATURE_K}/${TEMPERATURE_K}/g" 'plumed.dat' || exit 1 - sed -i "s/{METAD_GRID_MIN}/${METAD_GRID_MIN}/g" 'plumed.dat' || exit 1 - sed -i "s/{METAD_GRID_MAX}/${METAD_GRID_MAX}/g" 'plumed.dat' || exit 1 - sed -i "s/{METAD_GRID_SPACING}/${METAD_GRID_SPACING}/g" 'plumed.dat' || exit 1 - - # create tpr file - "${GMX_BIN}" -nocopyright grompp \ - -f "${sim_name}.mdp" \ - -c "${previous_sim_name}.gro" \ - -r "${previous_sim_name}.gro" \ - -n "index.ndx" \ - -p "topol.top" \ - -o "${sim_name}.tpr" - rm "${previous_sim_name}.gro" || exit 1 - - else - echo "DEBUG: Using existing tpr file" - # activate restart in plumed file - sed -i 's/#RESTART/RESTART/g' "plumed.dat" || exit 1 - fi - # shellcheck disable=SC2153,SC2086 "${GMX_BIN}" -nocopyright mdrun -v \ -maxh "${WALLTIME_HOURS}" \ @@ -143,15 +152,31 @@ else -plumed "plumed.dat" \ ${GMX_CPU_ARGS} ${GMX_GPU_ARGS} \ -noappend + } >>"${log_file}" 2>&1 - # make completed simulation text file - if [[ -f "${sim_name}.gro" ]]; then - echo "DEBUG: Simulation completed" - touch "${cwd}/completed.txt" - echo "completed: $(date)" >"${cwd}/completed.txt" + # check if gromacs simulation completed or was terminated + echo "INFO: checking if simulation completed successfully" + bool_completed=false + while IFS= read -r line; do + if [[ "${line}" == *"writing final coordinates."* ]]; then + bool_completed=true fi + done <"${log_file}" + echo "DEBUG: bool_completed = ${bool_completed}" + + # make completed simulation text file if simulation completed successfully + if [[ "${bool_completed}" = true ]]; then + echo "INFO: simulation completed successfully" + touch "completed.txt" + echo "completed: $(date)" >"completed.txt" + + # otherwise, exit script without error + else + echo "WARNING: ${sim_name}.gro does not exist. simulation did not complete successfully" + echo "INFO: exiting script" + exit 0 + fi - } >>"${log_file}" 2>&1 fi # ####################################################################################### @@ -174,139 +199,157 @@ log_file="${log_dir}/${time_init}-concatenation.log" # rsync output files to archive directory archive_dir="1-runs" -{ - rsync --archive --verbose --progress --human-readable --itemize-changes \ - "${sim_name}."* "${archive_dir}/" || exit 1 - rsync --archive --verbose --progress --human-readable --itemize-changes \ - ./*.data "${archive_dir}/" || exit 1 - rsync --archive --verbose --progress --human-readable --itemize-changes \ - ./*.dat "${archive_dir}/" || exit 1 - rsync --archive --verbose --progress --human-readable --itemize-changes \ - ./*.Kernels* "${archive_dir}/" || exit 1 -} >>"${log_file}" 2>&1 +if [[ ! -d "${archive_dir}" ]] || [[ "${FLAG_ARCHIVE}" = true ]]; then + echo "INFO: Archiving simulation" + { + rsync --archive --verbose --progress --human-readable --itemize-changes \ + "${sim_name}."* "${archive_dir}/" || exit 1 + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.data "${archive_dir}/" || exit 1 + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.dat "${archive_dir}/" || exit 1 + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.Kernels* "${archive_dir}/" || exit 1 + } >>"${log_file}" 2>&1 +else + echo "INFO: Skipping archiving simulation" +fi # concatenate files into single trajectory -echo "INFO: Concatenating trajectories" concat_dir="2-concatenated" -{ - mkdir -p "${concat_dir}" - - # concatenate xtc files - "${GMX_BIN}" -nocopyright trjcat \ - -f "${archive_dir}/${sim_name}."*.xtc \ - -o "${concat_dir}/${sim_name}.xtc" || exit 1 - - # concatenate edr files - "${GMX_BIN}" -nocopyright eneconv \ - -f "${archive_dir}/${sim_name}."*.edr \ - -o "${concat_dir}/${sim_name}.edr" || exit 1 - - # copy other files - cp "${archive_dir}/${sim_name}.tpr" "${concat_dir}/${sim_name}.tpr" || exit 1 - - # dump pdb file from last frame - "${GMX_BIN}" -nocopyright trjconv \ - -f "${concat_dir}/${sim_name}.xtc" \ - -s "${concat_dir}/${sim_name}.tpr" \ - -o "${concat_dir}/${sim_name}.pdb" \ - -pbc 'mol' -ur 'compact' -conect \ - -dump "1000000000000" <>"${log_file}" 2>&1 + # copy plumed files + cp "${archive_dir}/"*.data "${concat_dir}/" || exit 1 + } >>"${log_file}" 2>&1 +else + echo "INFO: Skipping concatenation" +fi # dump trajectory without solvent -echo "INFO: Dumping trajectory without solvent" nosol_dir="3-no-solvent" -{ - mkdir -p "${nosol_dir}" - - # pdb structure - "${GMX_BIN}" trjconv \ - -f "${concat_dir}/${sim_name}.xtc" \ - -s "${concat_dir}/${sim_name}.tpr" \ - -o "${nosol_dir}/${sim_name}.pdb" \ - -pbc 'mol' -ur 'compact' -conect \ - -dump "1000000000000" <>"${log_file}" 2>&1 + # copy *.data files + cp "${concat_dir}/"*.data -t "${nosol_dir}/" || exit 1 + } >>"${log_file}" 2>&1 +else + echo "INFO: Skipping dumping trajectory without solvent" +fi # ####################################################################################### # Analysis ############################################################################## # ####################################################################################### -echo "INFO: Analyzing trajectory" log_file="${log_dir}/${time_init}-analysis.log" -# write header to log file -{ - echo "################################################################################" - echo "Script: ${BASH_SOURCE[0]}" - echo "Date: $(date)" - echo "Host: $(hostname)" - echo "System: ${MONOMER}-${BLOCK}-${CRYSTAL}-${SURFACE}-${SURFACE_SIZE}nm-${BOX_HEIGHT}nm-${N_MONOMER}mon-${N_CHAIN}chain-${N_CARBONATE}co3-${N_SODIUM}na-${N_CALCIUM}ca-${N_CHLORINE}cl" - echo "Ensemble: ${PRODUCTION_ENSEMBLE} ${TEMPERATURE_K}K ${PRESSURE_BAR}bar" - echo "################################################################################" - echo "" -} >>"${log_file}" 2>&1 +if [[ ! -d "png" ]] || [[ "${FLAG_ARCHIVE}" = true ]]; then + echo "INFO: Analyzing trajectory" + # write header to log file + { + echo "################################################################################" + echo "Script: ${BASH_SOURCE[0]}" + echo "Date: $(date)" + echo "Host: $(hostname)" + echo "System: ${MONOMER}-${BLOCK}-${CRYSTAL}-${SURFACE}-${SURFACE_SIZE}nm-${BOX_HEIGHT}nm-${N_MONOMER}mon-${N_CHAIN}chain-${N_CARBONATE}co3-${N_SODIUM}na-${N_CALCIUM}ca-${N_CHLORINE}cl" + echo "Ensemble: ${PRODUCTION_ENSEMBLE} ${TEMPERATURE_K}K ${PRESSURE_BAR}bar" + echo "################################################################################" + echo "" + } >>"${log_file}" 2>&1 -{ - # plot system parameters over time - params=('Potential' 'Kinetic-En.' 'Total-Energy' 'Temperature' 'Pressure') - if [[ "${PRODUCTION_ENSEMBLE^^}" == "NPT" ]]; then - params+=('Density') - fi - echo "DEBUG: Parameters to plot: ${params[*]}" - for param in "${params[@]}"; do - filename="${param,,}" - "${GMX_BIN}" -nocopyright energy \ - -f "${concat_dir}/${sim_name}.edr" \ - -o "${filename}.xvg" <>"${log_file}" 2>&1 - # copy all png files to png directory - mkdir -p "png" - cp -p ./*.png "png/" || exit 1 - rm ./*.png || exit 1 -} >>"${log_file}" 2>&1 +else + echo "INFO: Skipping analysis" +fi # ####################################################################################### # Clean Up ############################################################################## diff --git a/scripts/method/sampling_opes_explore.sh b/scripts/method/sampling_opes_explore.sh index d14d759..3501105 100755 --- a/scripts/method/sampling_opes_explore.sh +++ b/scripts/method/sampling_opes_explore.sh @@ -37,21 +37,17 @@ time_init="$(date +%Y_%m_%d_%H_%M_%S)" cwd_init="$(pwd)" cwd="${cwd_init}/3-sampling-opes-explore" log_dir="${cwd}/logs" + +# ####################################################################################### +# Check for existing files ############################################################## +# ####################################################################################### +echo "CRITICAL: Starting OPES Explore production" log_file="${log_dir}/${time_init}-md.log" # move to working directory mkdir -p "${cwd}" cd "${cwd}" || exit mkdir -p "${log_dir}" -echo "CRITICAL: Starting OPES Explore production" - -# ####################################################################################### -# Run simulation ######################################################################## -# ####################################################################################### -echo "INFO: Running production OPES Explore simulation" -previous_sim_name="prod_eqbm" -previous_archive_dir="${cwd_init}/2-equilibration/4-output" -sim_name="prod_opes_explore" # write header to log file { @@ -65,6 +61,70 @@ sim_name="prod_opes_explore" echo "" } >>"${log_file}" 2>&1 +# ####################################################################################### +# Prepare simulation #################################################################### +# ####################################################################################### +previous_sim_name="prod_eqbm" +previous_archive_dir="${cwd_init}/2-equilibration/4-output" +sim_name="prod_opes_explore" + +if [[ ! -f "${sim_name}.tpr" ]]; then + echo "INFO: Preparing simulation tpr file" + { + # copy output files from equilibration + cp -np "${previous_archive_dir}/${previous_sim_name}.gro" "${previous_sim_name}.gro" || exit 1 + cp -np "${previous_archive_dir}/topol.top" "topol.top" || exit 1 + cp -np "${previous_archive_dir}/index.ndx" "index.ndx" || exit 1 + + # copy mdp file + cp "${mdp_file}" "${sim_name}.mdp" || exit 1 + sed -i 's/ref-t.*/ref-t = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 + sed -i 's/gen-temp.*/gen-temp = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 + sed -i 's/ref-p.*/ref-p = '"${PRESSURE_BAR} ${PRESSURE_BAR}/g" "${sim_name}.mdp" || exit 1 + # small surfaces have smaller cutoffs + if [[ "${SURFACE_SIZE}" -lt 4 ]]; then + sed -i 's/^rlist.*/rlist = 0.7/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^rcoulomb.*/rcoulomb = 0.7/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^rvdw.*/rvdw = 0.7/g' "${sim_name}.mdp" || exit 1 + fi + # add vacuum parameters to mdp file + if [[ "${VACUUM_HEIGHT}" -gt 0 ]]; then + sed -i 's/^ewald-geometry .*/ewald-geometry = 3dc/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^pbc .*/pbc = xy/g' "${sim_name}.mdp" || exit 1 + sed -i 's/^nwall .*/nwall = 2/g' "${sim_name}.mdp" || exit 1 + fi + + # copy plumed file + cp "${dat_file}" "plumed.dat" || exit 1 + sed -i 's/{LOWER_WALL_HEIGHT}/'"${PE_WALL_MIN}"'/g' "plumed.dat" || exit 1 + sed -i 's/{UPPER_WALL_HEIGHT}/'"${PE_WALL_MAX}"'/g' "plumed.dat" || exit 1 + sed -i 's/{WALL_OFFSET}/'"${ATOM_OFFSET}"'/g' "plumed.dat" || exit 1 + sed -i 's/{ATOM_REFERENCE}/'"${ATOM_REFERENCE}"'/g' "plumed.dat" || exit 1 + if [[ "${N_CALCIUM}" -eq '0' ]]; then + sed -i 's/NDX_GROUP=Aqueous_Calcium/NDX_GROUP=Crystal_Top_Surface_Calcium/g' "plumed.dat" || exit 1 + fi + + # create tpr file + "${GMX_BIN}" -nocopyright grompp \ + -f "${sim_name}.mdp" \ + -c "${previous_sim_name}.gro" \ + -r "${previous_sim_name}.gro" \ + -n "index.ndx" \ + -p "topol.top" \ + -o "${sim_name}.tpr" + rm "${previous_sim_name}.gro" || exit 1 + } >>"${log_file}" 2>&1 + +else + echo "DEBUG: Using existing tpr file" + sed -i 's/#RESTART/RESTART/g' "plumed.dat" || exit 1 + +fi + +# ####################################################################################### +# Run simulation ######################################################################## +# ####################################################################################### +echo "INFO: Running production OPES Explore simulation" if [[ -f "completed.txt" ]]; then echo "WARNING: completed.txt already exists" echo "INFO: Skipping production OPES Explore simulation" @@ -74,54 +134,8 @@ elif [[ "${FLAG_ARCHIVE}" = true ]]; then echo "INFO: Skipping production OPES Explore simulation" else + echo "INFO: Calling mdrun" { - # copy output files from equilibration - cp -np "${previous_archive_dir}/${previous_sim_name}.gro" "${previous_sim_name}.gro" || exit 1 - cp -np "${previous_archive_dir}/topol.top" "topol.top" || exit 1 - cp -np "${previous_archive_dir}/index.ndx" "index.ndx" || exit 1 - - # if tpr file does not exist, create it - if [[ ! -f "${sim_name}.tpr" ]]; then - echo "DEBUG: Creating tpr file" - - # copy mdp file - cp "${mdp_file}" "${sim_name}.mdp" || exit 1 - sed -i 's/ref-t.*/ref-t = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 - sed -i 's/gen-temp.*/gen-temp = '"${TEMPERATURE_K}/g" "${sim_name}.mdp" || exit 1 - sed -i 's/ref-p.*/ref-p = '"${PRESSURE_BAR} ${PRESSURE_BAR}/g" "${sim_name}.mdp" || exit 1 - # add vacuum parameters to mdp file - if [[ "${VACUUM_HEIGHT}" -gt 0 ]]; then - sed -i 's/^ewald-geometry .*/ewald-geometry = 3dc/g' "${sim_name}.mdp" || exit 1 - sed -i 's/^pbc .*/pbc = xy/g' "${sim_name}.mdp" || exit 1 - sed -i 's/^nwall .*/nwall = 2/g' "${sim_name}.mdp" || exit 1 - fi - - # copy plumed file - cp "${dat_file}" "plumed.dat" || exit 1 - sed -i 's/{LOWER_WALL_HEIGHT}/'"${PE_WALL_MIN}"'/g' "plumed.dat" || exit 1 - sed -i 's/{UPPER_WALL_HEIGHT}/'"${PE_WALL_MAX}"'/g' "plumed.dat" || exit 1 - sed -i 's/{WALL_OFFSET}/'"${ATOM_OFFSET}"'/g' "plumed.dat" || exit 1 - sed -i 's/{ATOM_REFERENCE}/'"${ATOM_REFERENCE}"'/g' "plumed.dat" || exit 1 - if [[ "${N_CALCIUM}" -eq '0' ]]; then - sed -i 's/NDX_GROUP=Aqueous_Calcium/NDX_GROUP=Crystal_Top_Surface_Calcium/g' "plumed.dat" || exit 1 - fi - - # create tpr file - "${GMX_BIN}" -nocopyright grompp \ - -f "${sim_name}.mdp" \ - -c "${previous_sim_name}.gro" \ - -r "${previous_sim_name}.gro" \ - -n "index.ndx" \ - -p "topol.top" \ - -o "${sim_name}.tpr" - rm "${previous_sim_name}.gro" || exit 1 - - else - echo "DEBUG: Using existing tpr file" - # activate restart in plumed file - sed -i 's/#RESTART/RESTART/g' "plumed.dat" || exit 1 - fi - # shellcheck disable=SC2153,SC2086 "${GMX_BIN}" -nocopyright mdrun -v \ -maxh "${WALLTIME_HOURS}" \ @@ -129,15 +143,30 @@ else -plumed "plumed.dat" \ ${GMX_CPU_ARGS} ${GMX_GPU_ARGS} \ -noappend + } >>"${log_file}" 2>&1 - # make completed simulation text file - if [[ -f "${sim_name}.gro" ]]; then - echo "DEBUG: Simulation completed" - touch "${cwd}/completed.txt" - echo "completed: $(date)" >"${cwd}/completed.txt" + # check if gromacs simulation completed or was terminated + echo "INFO: checking if simulation completed successfully" + bool_completed=false + while IFS= read -r line; do + if [[ "${line}" == *"writing final coordinates."* ]]; then + bool_completed=true fi - - } >>"${log_file}" 2>&1 + done <"${log_file}" + echo "DEBUG: bool_completed = ${bool_completed}" + + # make completed simulation text file if simulation completed successfully + if [[ "${bool_completed}" = true ]]; then + echo "INFO: simulation completed successfully" + touch "completed.txt" + echo "completed: $(date)" >"completed.txt" + + # otherwise, exit script without error + else + echo "WARNING: ${sim_name}.gro does not exist. simulation did not complete successfully" + echo "INFO: exiting script" + exit 0 + fi fi # ####################################################################################### @@ -160,139 +189,157 @@ log_file="${log_dir}/${time_init}-concatenation.log" # rsync output files to archive directory archive_dir="1-runs" -{ - rsync --archive --verbose --progress --human-readable --itemize-changes \ - "${sim_name}."* "${archive_dir}/" || exit 1 - rsync --archive --verbose --progress --human-readable --itemize-changes \ - ./*.data "${archive_dir}/" || exit 1 - rsync --archive --verbose --progress --human-readable --itemize-changes \ - ./*.dat "${archive_dir}/" || exit 1 - rsync --archive --verbose --progress --human-readable --itemize-changes \ - ./*.Kernels* "${archive_dir}/" || exit 1 -} >>"${log_file}" 2>&1 +if [[ ! -d "${archive_dir}" ]] || [[ "${FLAG_ARCHIVE}" = true ]]; then + echo "INFO: Archiving simulation" + { + rsync --archive --verbose --progress --human-readable --itemize-changes \ + "${sim_name}."* "${archive_dir}/" || exit 1 + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.data "${archive_dir}/" || exit 1 + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.dat "${archive_dir}/" || exit 1 + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.Kernels* "${archive_dir}/" || exit 1 + } >>"${log_file}" 2>&1 +else + echo "INFO: Skipping archiving simulation" +fi # concatenate files into single trajectory -echo "INFO: Concatenating trajectories" concat_dir="2-concatenated" -{ - mkdir -p "${concat_dir}" - - # concatenate xtc files - "${GMX_BIN}" -nocopyright trjcat \ - -f "${archive_dir}/${sim_name}."*.xtc \ - -o "${concat_dir}/${sim_name}.xtc" || exit 1 - - # concatenate edr files - "${GMX_BIN}" -nocopyright eneconv \ - -f "${archive_dir}/${sim_name}."*.edr \ - -o "${concat_dir}/${sim_name}.edr" || exit 1 - - # copy other files - cp "${archive_dir}/${sim_name}.tpr" "${concat_dir}/${sim_name}.tpr" || exit 1 - - # dump pdb file from last frame - "${GMX_BIN}" -nocopyright trjconv \ - -f "${concat_dir}/${sim_name}.xtc" \ - -s "${concat_dir}/${sim_name}.tpr" \ - -o "${concat_dir}/${sim_name}.pdb" \ - -pbc 'mol' -ur 'compact' -conect \ - -dump "1000000000000" <>"${log_file}" 2>&1 + # copy plumed files + cp "${archive_dir}/"*.data "${concat_dir}/" || exit 1 + } >>"${log_file}" 2>&1 +else + echo "INFO: Skipping concatenation" +fi # dump trajectory without solvent -echo "INFO: Dumping trajectory without solvent" nosol_dir="3-no-solvent" -{ - mkdir -p "${nosol_dir}" - - # pdb structure - "${GMX_BIN}" trjconv \ - -f "${concat_dir}/${sim_name}.xtc" \ - -s "${concat_dir}/${sim_name}.tpr" \ - -o "${nosol_dir}/${sim_name}.pdb" \ - -pbc 'mol' -ur 'compact' -conect \ - -dump "1000000000000" <>"${log_file}" 2>&1 + # copy *.data files + cp "${concat_dir}/"*.data -t "${nosol_dir}/" || exit 1 + } >>"${log_file}" 2>&1 +else + echo "INFO: Skipping dumping trajectory without solvent" +fi # ####################################################################################### # Analysis ############################################################################## # ####################################################################################### -echo "INFO: Analyzing trajectory" log_file="${log_dir}/${time_init}-analysis.log" -# write header to log file -{ - echo "################################################################################" - echo "Script: ${BASH_SOURCE[0]}" - echo "Date: $(date)" - echo "Host: $(hostname)" - echo "System: ${MONOMER}-${BLOCK}-${CRYSTAL}-${SURFACE}-${SURFACE_SIZE}nm-${BOX_HEIGHT}nm-${N_MONOMER}mon-${N_CHAIN}chain-${N_CARBONATE}co3-${N_SODIUM}na-${N_CALCIUM}ca-${N_CHLORINE}cl" - echo "Ensemble: ${PRODUCTION_ENSEMBLE} ${TEMPERATURE_K}K ${PRESSURE_BAR}bar" - echo "################################################################################" - echo "" -} >>"${log_file}" 2>&1 +if [[ ! -d "png" ]] || [[ "${FLAG_ARCHIVE}" = true ]]; then + echo "INFO: Analyzing trajectory" + # write header to log file + { + echo "################################################################################" + echo "Script: ${BASH_SOURCE[0]}" + echo "Date: $(date)" + echo "Host: $(hostname)" + echo "System: ${MONOMER}-${BLOCK}-${CRYSTAL}-${SURFACE}-${SURFACE_SIZE}nm-${BOX_HEIGHT}nm-${N_MONOMER}mon-${N_CHAIN}chain-${N_CARBONATE}co3-${N_SODIUM}na-${N_CALCIUM}ca-${N_CHLORINE}cl" + echo "Ensemble: ${PRODUCTION_ENSEMBLE} ${TEMPERATURE_K}K ${PRESSURE_BAR}bar" + echo "################################################################################" + echo "" + } >>"${log_file}" 2>&1 -{ - # plot system parameters over time - params=('Potential' 'Kinetic-En.' 'Total-Energy' 'Temperature' 'Pressure') - if [[ "${PRODUCTION_ENSEMBLE^^}" == "NPT" ]]; then - params+=('Density') - fi - echo "DEBUG: Parameters to plot: ${params[*]}" - for param in "${params[@]}"; do - filename="${param,,}" - "${GMX_BIN}" -nocopyright energy \ - -f "${concat_dir}/${sim_name}.edr" \ - -o "${filename}.xvg" <>"${log_file}" 2>&1 - # copy all png files to png directory - mkdir -p "png" - cp -p ./*.png "png/" || exit 1 - rm ./*.png || exit 1 -} >>"${log_file}" 2>&1 +else + echo "INFO: Skipping analysis" +fi # ####################################################################################### # Clean Up ############################################################################## diff --git a/scripts/method/sampling_opes_one.sh b/scripts/method/sampling_opes_one.sh index a59d076..143110b 100755 --- a/scripts/method/sampling_opes_one.sh +++ b/scripts/method/sampling_opes_one.sh @@ -183,17 +183,18 @@ echo "DEBUG: Number of MPI processes per node: ${ONEOPES_N_SIM_PER_NODE}" echo "DEBUG: Number of threads per MPI process: ${ONEOPES_N_THREAD_PER_SIM}" echo "DEBUG: Using $((ONEOPES_N_SIM_PER_NODE * ONEOPES_N_THREAD_PER_SIM)) threads per node" -{ - if [[ -f "${cwd}/completed.txt" ]]; then - echo "WARNING: completed.txt already exists" - echo "INFO: Skipping production OneOPES simulation" - - elif [[ "${FLAG_ARCHIVE}" = true ]]; then - echo "WARNING: Archive flag is set, mdrun will not be called" - echo "INFO: Skipping production OneOPES simulation" - - else - # call mdrun +if [[ -f "${cwd}/completed.txt" ]]; then + echo "WARNING: completed.txt already exists" + echo "INFO: Skipping production OneOPES simulation" + +elif [[ "${FLAG_ARCHIVE}" = true ]]; then + echo "WARNING: Archive flag is set, mdrun will not be called" + echo "INFO: Skipping production OneOPES simulation" + +else + # call mdrun + echo "INFO: Calling mdrun" + { "${MPI_BIN}" -np "${ONEOPES_N_REPLICA}" \ --map-by "ppr:${ONEOPES_N_SIM_PER_NODE}:node:PE=${ONEOPES_N_THREAD_PER_SIM}" \ --use-hwthread-cpus --bind-to 'hwthread' \ @@ -207,9 +208,36 @@ echo "DEBUG: Using $((ONEOPES_N_SIM_PER_NODE * ONEOPES_N_THREAD_PER_SIM)) thread echo "DEBUG: Simulation completed" touch "${cwd}/completed.txt" echo "completed: $(date)" >"${cwd}/completed.txt" + else + echo "INFO: Simulation did not complete" + exit 0 fi + } >>"${log_file_md}" 2>&1 + + # check if gromacs simulation completed or was terminated + echo "INFO: Checking if simulation completed successfully" + bool_completed=false + while IFS= read -r line; do + if [[ "${line}" == *"Writing final coordinates."* ]]; then + bool_completed=true + fi + done <"${log_file_md}" + echo "DEBUG: bool_completed = ${bool_completed}" + + # make completed simulation text file if simulation completed successfully + if [[ "${bool_completed}" = true ]]; then + echo "INFO: Simulation completed successfully" + touch "completed.txt" + echo "completed: $(date)" >"completed.txt" + + # otherwise, exit script without error + else + echo "WARNING: ${sim_name}.gro does not exist. Simulation did not complete successfully" + echo "INFO: Exiting script" + exit 0 + fi -} >>"${log_file_md}" 2>&1 +fi # ####################################################################################### # Concatenate trajectories ############################################################## @@ -229,89 +257,103 @@ cd "${cwd}/replica_00" || exit } >>"${log_file_concat}" 2>&1 # rsync output files to archive directory -echo "INFO: Archiving simulation for replica_00" archive_dir="1-runs" -{ - rsync --archive --verbose --progress --human-readable --itemize-changes \ - "${sim_name}."* "${archive_dir}/" - rsync --archive --verbose --progress --human-readable --itemize-changes \ - ./*.data "${archive_dir}/" - rsync --archive --verbose --progress --human-readable --itemize-changes \ - ./*.dat "${archive_dir}/" - rsync --archive --verbose --progress --human-readable --itemize-changes \ - ./*.Kernels* "${archive_dir}/" -} >>"${log_file_concat}" 2>&1 +if [[ ! -d "${archive_dir}" ]] || [[ "${FLAG_ARCHIVE}" = true ]]; then + echo "INFO: Archiving simulation for replica_00" + { + rsync --archive --verbose --progress --human-readable --itemize-changes \ + "${sim_name}."* "${archive_dir}/" + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.data "${archive_dir}/" + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.dat "${archive_dir}/" + rsync --archive --verbose --progress --human-readable --itemize-changes \ + ./*.Kernels* "${archive_dir}/" + } >>"${log_file_concat}" 2>&1 +else + echo "INFO: Archive directory for replica_00 already exists. Skipping" +fi # concatenate files into single trajectory echo "INFO: Concatenating files" concat_dir="2-concatenated" -{ - mkdir -p "${concat_dir}" - - # concatenate xtc files - "${GMX_BIN}" -nocopyright trjcat \ - -f "${archive_dir}/${sim_name}."*.xtc \ - -o "${concat_dir}/${sim_name}.xtc" || exit 1 - - # concatenate edr files - "${GMX_BIN}" -nocopyright eneconv \ - -f "${archive_dir}/${sim_name}."*.edr \ - -o "${concat_dir}/${sim_name}.edr" || exit 1 - - # copy other files - cp "${archive_dir}/${sim_name}.tpr" "${concat_dir}/${sim_name}.tpr" || exit 1 - - # dump pdb file from last frame - "${GMX_BIN}" -nocopyright trjconv \ - -f "${concat_dir}/${sim_name}.xtc" \ - -s "${concat_dir}/${sim_name}.tpr" \ - -o "${concat_dir}/${sim_name}.pdb" \ - -pbc 'mol' -ur 'compact' -conect \ - -dump "1000000000000" <>"${log_file_concat}" 2>&1 + # copy plumed files + cp "${archive_dir}/"*.data "${concat_dir}/" || exit 1 + } >>"${log_file_concat}" 2>&1 +else + echo "INFO: Concatenated directory already exists. Skipping" +fi # dump trajectory without solvent echo "INFO: Dumping trajectory without solvent" nosol_dir="3-no-solvent" -{ - mkdir -p "${nosol_dir}" - - # pdb structure - "${GMX_BIN}" trjconv \ - -f "${concat_dir}/${sim_name}.xtc" \ - -s "${concat_dir}/${sim_name}.tpr" \ - -o "${nosol_dir}/${sim_name}.pdb" \ - -pbc 'mol' -ur 'compact' -conect \ - -dump "1000000000000" <>"${log_file_concat}" 2>&1 + # copy *.data files + cp "${concat_dir}/"*.data -t "${nosol_dir}/" || exit 1 + } >>"${log_file_concat}" 2>&1 +else + echo "INFO: No-solvent directory already exists. Skipping" +fi # ####################################################################################### # Clean Up ##############################################################################