# # DESCRIPTION gromacs-md-all Full computation cycle of molecular dynamics simulations starting from pdb2gmx and up to mdrun # software_usage () { echo_g "GROACS-MD SOFTWARE OPTIONS:" echo_y -e "\t--nomname" echo -e "\t\tforce empty basename for output files" echo -e "\t Job will be submitted for execution from checkpoint if\033[1;31m [base name]_md.cpt\033[0;39m file exists in the working directory." } software_parse_cmd_options () { case $1 in --nomname) EMPTY_MNAME=1 PARSED_BY_MODULE=1 ;; esac } set_software_environment () { # Check runtime specification. Override to GROMACS-4.0 if not specified [ "x${RUNTIME}" == "x" ] && RUNTIME="GROMACS-4.0" # Gromacs flavors if [ "x${RUNTIME:0:11}" == "xGROMACS-4.6" ]; then GMX_VERSION=46 elif [ "x${RUNTIME:0:11}" == "xGROMACS-4.5" ]; then GMX_VERSION=45 elif [ "x${RUNTIME:0:11}" == "xGROMACS-4.0" ]; then GMX_VERSION=40 elif [ "x${RUNTIME:0:11}" == "xGROMACS-5.0" ]; then GMX_VERSION=50 else GMX_VERSION=3 fi # Gromacs 4.x doesn't require -np parameter and now files are independent from cores if [ "x${GMX_VERSION}" == "x3" ]; then NP4="-np ${NPRC}" NP1="-np 1" fi # Get base name from PDB if othervise not specified [ "x${MNAME}" == "x" ] && MNAME=${PDB%%.*} MNAME_="${MNAME}_" [ "x${EMPTY_MNAME}" == "x1" ] && MNAME_="" # Check if checkpoint file exists if [ -f "${MNAME_}md.cpt" ]; then CHECKPOINT="1"; echo_g "Found ${MNAME_}md.cpt checkpoint file. Submitting job to resume MD from checkpoint." fi # Create jobname based on MNAME and date if not overrided in config if [ "x${JOBNAME}" == "x" ]; then export JOBNAME="$MNAME_$(date +%y_%m_%d___%H_%M_%S)" echo "JOBNAME=\"${JOBNAME}\"" >> ${MDS_PARAMS} fi # Log format [ "x${LOGFILENAME_FORMAT=}" == "x" ] && LOGFILENAME_FORMAT="step%s_%p_%n.log" # More Gromacs defaults [ "x${FORCEFIELD}" == "x" ] && FORCEFIELD="amber99sb"; [ "x${IGNH}" == "xno" ] && IGNH="-noignh" || IGNH="-ignh" [ "x${VSITE}" != "x" ] && VSITE="-vsite ${VSITE}"; [ "x${WATER}" == "x" ] && WATER="spc"; [ "x${BOXTYPE}" != "x" ] && BOXTYPE="-bt ${BOXTYPE}"; [ "x${BSDISTANCE}" == "x" ] && BSDISTANCE="1.0"; [ "x${CENTERMOLECULE}" == "x" ] && CENTERMOLECULE="1"; [ "x${CENTERMOLECULE}" == "x1" ] && CENTERMOLECULE="-c"; [ "x${BOXSOLVENT}" == "x" ] && BOXSOLVENT="spc216.gro" [ "x${PNAME}" != "x" ] && PNAME="-pname ${PNAME}" [ "x${NNAME}" != "x" ] && NNAME="-nname ${NNAME}" [ "x${CONCENTRATION}" != "x" ] && CONCENTRATION="-conc ${CONCENTRATION}" [ "x${DLB}" != "x" ] && DLB="-dlb ${DLB}"; if [ "x${MD_NPME}" != "xg_tune_pme" ]; then [ "x${MD_NPME}" != "x" ] && MD_NPME="-npme ${MD_NPME}" fi if [ "x${N_TERMINUS}" != "x" -o "x${C_TERMINUS}" != "x" ]; then PDB_TO_GMX_EXTERNAL="${PDB_TO_GMX_EXTERNAL} -ter " PDB_TO_GMX_ECHO_EXTERNAL="${PDB_TO_GMX_ECHO_EXTERNAL} ${N_TERMINUS} ${C_TERMINUS}" fi # Save inputs [ "x${SAVE_INPUTS_AS_OUTPUTS}" == "x" ] && SAVE_INPUTS_AS_OUTPUTS=0 # Check for SE results upload definition [ "x${DISABLE_AUTO_SE}" == "x1" ] && DISABLE_SE=1 } set_software_grid_environment () { # add software RTE to the list next_idx_var RUNTIME_CONDITION_ RUNTIME_VALUE_ "=" "${RUNTIME}" # Specify non-necesarry grid attributes if exists MEMORY=$(echo $MEMORY | sed 's/[^0-9]//g' ) if [ "x$MEMORY" != "x" ]; then [ $((MEMORY*NPRC/NODES)) -gt 3090 ] && \ echo_r "WARNING! Specified memory requirements is high. It is possible that job will be prevented from being started!" fi [ "x${STDERR}" == "x" ] && STDERR="$JOBNAME.err" [ "x${STDOUT}" == "x" ] && STDOUT="$JOBNAME.out" [ "x${CPUTIME}" != "x" ] && export CPUTIME=$((CPUTIME*NPRC)) # notification flags if [ "x$MAILTO" != "x" ]; then MAILFLAGS=${NOTIFY} MAILFLAGS="$(echo $MAILFLAGS | sed s/[^beqfcd]//g)" [ "x$MAILFLAGS" == "x" ] && MAILFLAGS="e"; fi } software_gen_params () { cat <= 4.5 is -1 (guess) # for <= 4.0 parameter is not specified # Specifying "g_tune_pme" value will enable g_tune_pme execution before final mdrun for Gromacs 4.5.x+ #MD_NPME="g_tune_pme" ### ### Gromacs-md grid requiremenst ################################### ### # Job name. Next format will be used if not specified: # [Base name]_[year]_[mounth]_[date]___[hours]_[minutes]_[seconds] #JOBNAME="Test_Job" # Environment for execution. Type GROMACS-[version] to use. RUNTIME="GROMACS-4.5.7" END } create_executable () { #-->>--if not checkpoint--------------------------------------- if [ "x${CHECKPOINT}" == "x" ]; then PDB_TO_GMX_RESPIPE=0 if [ "x${PDB_TO_GMX_ECHO_EXTERNAL}" != "x" ]; then PDB_TO_GMX_ECHO_EXTERNAL_W=$( echo ${PDB_TO_GMX_ECHO_EXTERNAL} | wc -w ) for i in $(seq ${PDB_TO_GMX_ECHO_EXTERNAL_W}); do PDB_TO_GMX_ECHO_EXTERNAL="${PDB_TO_GMX_ECHO_EXTERNAL} 0" done PDB_TO_GMX_ECHO_EXTERNAL="echo \"${PDB_TO_GMX_ECHO_EXTERNAL}\" | " PDB_TO_GMX_RESPIPE=1 fi #-------------------------------------------------------COMMON cat << END #!/bin/bash # dos2unix input files dos2unix ${PDB} ${GI_MDP} ${EM_MDP} ${PR_MDP} ${MD_MDP} ${EM2_MDP} ${PR2_MDP} END #-------------------------------------------------------GI_MDP if [ "x${GI_MDP}" != "x" ]; then cat <&1 | tee $(gen_log_name "pdb2gmx" "BOX") RVAL="\${PIPESTATUS[${PDB_TO_GMX_RESPIPE}]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi # editconf echo -en "Executing editconf...\t\t" && editconf -f ${MNAME_}pdb2gmx.gro -o ${MNAME_}editconf.gro ${BOXTYPE} -d ${BSDISTANCE} ${CENTERMOLECULE} 2>&1 | tee $(gen_log_name "editconf" "BOX") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi # genbox echo -en "Executing genbox...\t\t" && genbox -cp ${MNAME_}editconf.gro -p ${MNAME_}pdb2gmx.top -cs ${BOXSOLVENT} -o ${MNAME_}genbox.gro -nice 0 2>&1 | tee $(gen_log_name "genbox" BOX) RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi # genbox topology file mv ${MNAME_}pdb2gmx.top ${MNAME_}genbox.top mv "#${MNAME_}pdb2gmx.top.1#" ${MNAME_}pdb2gmx.top #-GI- # grompp echo -en "Executing grompp...\t\t" && grompp -f ${GI_MDP} -c ${MNAME_}genbox.gro -p ${MNAME_}genbox.top -pp ${MNAME_}genion.top -po ${MNAME_}${GI_MDP%%.*}_f.mdp -o ${MNAME_}genion.tpr -v -maxwarn 20 ${NP1} -nice 0 2>&1 | tee $(gen_log_name "grompp" "GI") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi # genion echo -en "Executing genion...\t\t" && echo "SOL" | genion -s ${MNAME_}genion.tpr -g ${MNAME_}genion.log -o ${MNAME_}genion.gro -p ${MNAME_}genion.top ${PNAME} ${NNAME} ${CONCENTRATION} -neutral -nice 0 2>&1 | tee $(gen_log_name "genion" "GI") RVAL="\${PIPESTATUS[1]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi mv "#${MNAME_}genion.top.1#" ${MNAME_}genion_grompp.top END fi #---------------------------------------------------EM_MDP if [ "x${EM_MDP}" != "x" ]; then cat <&1 | tee $(gen_log_name "grompp" "EM") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi # mdrun echo -en "Executing mdrun...\t\t" && \${GMX_MPIRUN} mdrun_mpi -s ${MNAME_}em.tpr -g ${MNAME_}em.log -o ${MNAME_}em.trr -x ${MNAME_}em.xtc -e ${MNAME_}em.edr -c ${MNAME_}em.gro -v ${NP4} -nice 0 2>&1 | tee $(gen_log_name "mdrun_mpi" "EM") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi END fi EM_FOR_PR="em" #--------------------------------------------------EM2_MDP if [ "x${EM2_MDP}" != "x" ]; then EM_FOR_PR="em2" cat << END # -EM2- # grompp echo -en "Executing grompp...\t\t" && grompp -f ${EM2_MDP} -c ${MNAME_}em.gro -p ${MNAME_}genion.top -po ${MNAME_}${EM2_MDP%%.*}_f.mdp -o ${MNAME_}em2.tpr -v -maxwarn 20 ${NP4} -nice 0 2>&1 | tee $(gen_log_name "grompp" "EM2") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi # mdrun echo -en "Executing mdrun...\t\t" && \${GMX_MPIRUN} mdrun_mpi -s ${MNAME_}em2.tpr -g ${MNAME_}em2.log -o ${MNAME_}em2.trr -x ${MNAME_}em2.xtc -e ${MNAME_}em2.edr -c ${MNAME_}em2.gro -v ${NP4} -nice 0 2>&1 | tee $(gen_log_name "mdrun_mpi" "EM2") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi END fi #--------------------------------------------------PR_MDP [ "x${PR_MDP}" != "x" ] && cat <&1 | tee $(gen_log_name "grompp" "PR") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi #mdrun echo -en "Executing mdrun...\t\t" && \${GMX_MPIRUN} mdrun_mpi -s ${MNAME_}pr.tpr -g ${MNAME_}pr.log -o ${MNAME_}pr.trr -x ${MNAME_}pr.xtc -e ${MNAME_}pr.edr -c ${MNAME_}pr.gro -v ${NP4} -nice 0 2>&1 | tee $(gen_log_name "mdrun_mpi" "PR") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi END PR_FOR_MD=${MNAME_}pr #--------------------------------------------------PR2_MDP if [ "x${PR2_MDP}" != "x" ]; then PR_FOR_MD=${MNAME_}pr2 cat <&1 | tee $(gen_log_name "grompp" "PR2") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi #mdrun echo -en "Executing mdrun...\t\t" && \${GMX_MPIRUN} mdrun_mpi -s ${MNAME_}pr2.tpr -g ${MNAME_}pr2.log -o ${MNAME_}pr2.trr -x ${MNAME_}pr2.xtc -e ${MNAME_}pr2.edr -c ${MNAME_}pr2.gro -v ${NP4} -nice 0 2>&1 | tee $(gen_log_name "mdrun_mpi" "PR2") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi END elif [ "x${PR_MDP}" == "x" ]; then if [ -f "${MNAME_}pr2.gro" ]; then PR_FOR_MD=${MNAME_}pr2 fi fi #--------------------------------------------------MD_MDP if [ "x${MD_MDP}" != "x" ]; then cat <&1 | tee $(gen_log_name "grompp" "MD") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi export TPR_FOR_MD="-s ${MNAME_}md.tpr" END # enable g_tune_pme for Gromacs 4.5x if [ "x${MD_NPME}" == "xg_tune_pme" ]; then if [ ${GMX_VERSION} -ge 45 ]; then cat<&1 | tee ${MNAME_}g_tune_pme.log export TPR_FOR_MD=\`cat ${MNAME_}g_tune_pme.log | sed -n '/Best performance was achieved with/,\$p' | grep mdrun | sed "s/mdrun -nt ${NPRC} //"\` echo "Using \"\$TPR_FOR_MD\" parameters to run mdrun" END fi else cat <&1 | tee $(gen_log_name "mdrun_mpi" "MD") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi echo "Congratulations!!! MD simulation finished successfully." exit 0 END fi #-->>-----else-if-checkpoint-----MD-only-----from-ckpt---- else cat << END #!/bin/bash # - Molecular Dynamics - # mdrun resumed from checkpoint mv ${MNAME_}md.cpt ${MNAME_}md_in.cpt echo -en "Executing mdrun after checkpoint...\t\t" && \${GMX_MPIRUN} mdrun_mpi -s ${MNAME_}md.tpr -g ${MNAME_}md.log -o ${MNAME_}md.trr -x ${MNAME_}md.xtc -e ${MNAME_}md.edr -c ${MNAME_}md.gro -cpi ${MNAME_}md_in.cpt -append -cpo ${MNAME_}md.cpt ${DLB} -v ${NP4} -nice 0 2>&1 | tee $(gen_log_name "mdrun_mpi" "CKPT_MD") RVAL="\${PIPESTATUS[0]}" if [ "\$RVAL" == "0" ]; then echo "Done."; else echo "Failed."; exit \$RVAL; fi echo "Congratulations!!! MD simulation finished successfully." exit 0 END fi #--<<-------end-if-checkpoint------------------------------- } # # I/O files # # local helpers gen_log_name () { STEP_COUNT=$((STEP_COUNT+1)) STEP_COUNT_S=$( printf "%02d" ${STEP_COUNT} ) STAGE=${2:-''} LOGFILE=$( echo $LOGFILENAME_FORMAT | sed -e "s:%n:${1}:g" -e "s:%s:${STEP_COUNT_S}:g" -e "s:%p:${MNAME_}:g" -e "s:%t:${STAGE}:g" ) echo ${LOGFILE} } __req_infiles () { for rif in "$@"; do if [ ! -f "$rif" ]; then $COLOR_R 1>&2 echo "File ${rif} is required for job submission but not exists." 1>&2 $COLOR_DEF 1>&2 exit 1 fi done } # input files for software create_input_files_list () { local_files="${MDS_PARAMS} " if [ "x${CHECKPOINT}" != "x" ]; then # --->>---if-ckpt--- local_files="$local_files ${MNAME_}md.trr ${MNAME_}md.tpr ${MNAME_}md.edr ${MNAME_}md.log ${MNAME_}md.cpt" [ -f "${MNAME_}md.gro" ] && local_files="$local_files ${MNAME_}md.gro" [ -f "${MNAME_}md.xtc" ] && local_files="$local_files ${MNAME_}md.xtc" else [ "x${GI_MDP}" != "x" ] && local_files="$local_files ${PDB} ${GI_MDP}" if [ "x${EM_MDP}" != "x" ]; then local_files="$local_files ${EM_MDP}" if [ "x${GI_MDP}" == "x" ]; then __req_infiles "${MNAME_}genion.gro" "${MNAME_}genion.top" local_files="$local_files ${MNAME_}genion.gro ${MNAME_}genion.top" fi fi if [ "x${EM2_MDP}" != "x" ]; then local_files="$local_files ${EM2_MDP}" if [ "x${EM_MDP}" == "x" ]; then __req_infiles "${MNAME_}em.gro" "${MNAME_}genion.top" local_files="$local_files ${MNAME_}em.gro ${MNAME_}genion.top" fi fi if [ "x${PR_MDP}" != "x" ]; then local_files="$local_files ${PR_MDP}" if [ "x${EM2_MDP}" == "x" ]; then if [ "x${EM_MDP}" == "x" ]; then if [ -f "${MNAME_}em2.gro" ]; then __req_infiles "${MNAME_}genion.top" local_files="$local_files ${MNAME_}em2.gro ${MNAME_}genion.top" else __req_infiles "${MNAME_}genion.top" "${MNAME_}em.gro" local_files="$local_files ${MNAME_}em.gro ${MNAME_}genion.top" fi fi fi fi if [ "x${PR2_MDP}" != "x" ]; then local_files="$local_files ${PR2_MDP}" if [ "x${PR_MDP}" == "x" ]; then __req_infiles "${MNAME_}pr.gro" "${MNAME_}genion.top" local_files="$local_files ${MNAME_}pr.gro ${MNAME_}genion.top" fi fi if [ "x${MD_MDP}" != "x" ]; then local_files="$local_files ${MD_MDP}" if [ "x${PR2_MDP}" == "x" ]; then if [ "x${PR_MDP}" == "x" ]; then [ -f "${MNAME_}pr2.gro" ] && IF_PR_FOR_MD="${MNAME_}pr2" || IF_PR_FOR_MD="${MNAME_}pr" __req_infiles "${IF_PR_FOR_MD}.gro" "${MNAME_}genion.top" "${IF_PR_FOR_MD}.trr" "${IF_PR_FOR_MD}.edr" local_files="$local_files ${IF_PR_FOR_MD}.gro ${MNAME_}genion.top ${IF_PR_FOR_MD}.trr ${IF_PR_FOR_MD}.edr" fi fi fi fi inf_idx=0 for inf in ${local_files}; do eval "export INPUT_FILES_NAME_${inf_idx}=$inf" eval "export INPUT_FILES_LOCATION_${inf_idx}=" inf_idx=$((inf_idx+1)) done } # input files for software create_output_files_list () { local output_location=$1 [ "x${EMPTY_MNAME}" == "x1" ] && MNAME_="" || MNAME_="${MNAME}_" mname_files="" o_files="" if [ "x${CHECKPOINT}" == "x" ]; then if [ "x${GI_MDP}" != "x" ]; then mname_files="$mname_files ${GI_MDP%%.*}_f.mdp editconf.gro genbox.gro genbox.top" mname_files="$mname_files genion.gro genion.log genion.top genion.tpr genion_grompp.top" mname_files="$mname_files pdb2gmx.gro pdb2gmx.itp pdb2gmx.ndx pdb2gmx.top pdb2gmx.pdb" fi [ "x${EM_MDP}" != "x" ] && mname_files="$mname_files ${EM_MDP%%.*}_f.mdp em.edr em.gro em.log em.tpr em.trr em.xtc" [ "x${EM2_MDP}" != "x" ] && mname_files="$mname_files ${EM2_MDP%%.*}_f.mdp em2.edr em2.gro em2.log em2.tpr em2.trr em2.xtc" [ "x${PR_MDP}" != "x" ] && mname_files="$mname_files pr.edr pr.gro pr.tpr pr.log pr.xtc pr.trr pr_f.mdp" [ "x${PR2_MDP}" != "x" ] && mname_files="$mname_files pr2.edr pr2.gro pr2.tpr pr2.log pr2.xtc pr2.trr pr2_f.mdp" fi [ "x${MD_MDP}" != "x" ] && mname_files="$mname_files md.xtc md.trr md.tpr md.gro md.edr md.log md.cpt md_f.mdp" [ "x${MD_MDP}" != "x" ] && o_files="$o_files ${MDS_PARAMS}" [ "x${MD_NPME}" == "xg_tune_pme" -a ${GMX_VERSION} -ge 45 ] && mname_files="$mname_files g_tune_pme.log" if [ "x${SAVE_INPUTS_AS_OUTPUTS}" == "x1" ]; then [ "x${MD_MDP}" != "x" ] && o_files="$o_files ${MD_MDP}" [ "x${PR_MDP}" != "x" ] && o_files="$o_files ${PR_MDP}" [ "x${PR2_MDP}" != "x" ] && o_files="$o_files ${PR2_MDP}" [ "x${EM_MDP}" != "x" ] && o_files="$o_files ${EM_MDP}" [ "x${EM2_MDP}" != "x" ] && o_files="$o_files ${EM2_MDP}" [ "x${GI_MDP}" != "x" ] && o_files="$o_files ${GI_MDP} ${PDB}" fi #logs STEP_COUNT=0 logs_f=$( mktemp moldynsub.XXXXXXXX ) echo -n > $logs_f if [ "x${CHECKPOINT}" == "x" ]; then gen_log_name "pdb2gmx" "BOX" >> $logs_f gen_log_name "editconf" "BOX" >> $logs_f gen_log_name "genbox" "BOX" >> $logs_f gen_log_name "grompp" "GI" >> $logs_f gen_log_name "genion" "GI" >> $logs_f gen_log_name "grompp" "EM" >> $logs_f gen_log_name "mdrun_mpi" "EM" >> $logs_f if [ "x${EM2_MDP}" != "x" ]; then gen_log_name "grompp" "EM2" >> $logs_f gen_log_name "mdrun_mpi" "EM2" >> $logs_f fi gen_log_name "grompp" "PR" >> $logs_f gen_log_name "mdrun_mpi" "PR" >> $logs_f gen_log_name "grompp" "MD" >> $logs_f gen_log_name "mdrun_mpi" "MD" >> $logs_f else gen_log_name "mdrun_mpi" "CKPT_MD" >> $logs_f fi o_files="$o_files $( cat $logs_f | sed 's/\n/ /g' )" rm -f $logs_f of_idx=0 for of in ${mname_files}; do eval "export OUTPUT_FILES_NAME_${of_idx}=${MNAME_}$of" eval "export OUTPUT_FILES_LOCATION_${inf_idx}=${output_location}${MNAME_}$of" of_idx=$((of_idx+1)) done for of in ${o_files}; do eval "export OUTPUT_FILES_NAME_${of_idx}=$of" eval "export OUTPUT_FILES_LOCATION_${inf_idx}=${output_location}$of" of_idx=$((of_idx+1)) done }