# Restart python script for MD simulation

**URL:** <https://gromacs.bioexcel.eu/t/restart-python-script-for-md-simulation/3559>\
**Category:** User discussions\
**Created:** [January 28, 2022, 5:06am UTC](https://gromacs.bioexcel.eu/t/restart-python-script-for-md-simulation/3559 "2022-01-28T05:06:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akki](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/akki/32/958_2.png) [@Akki](https://gromacs.bioexcel.eu/u/Akki)\
**Post date:** [January 28, 2022, 5:06am UTC](https://gromacs.bioexcel.eu/t/restart-python-script-for-md-simulation/3559/1 "2022-01-28T05:06:18Z")

</div>

Hello All  
Can anyone please help me on how to restart MD simulation using python script, if it get killed in between due to power cut. The script i am using is named as **md.sh** and the command that i used to start MD is:  
chmod +x md.sh  
./md.sh

---

<div class="post-metadata">

**Author:** ![jalemkul](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/jalemkul/32/18_2.png) [@jalemkul](https://gromacs.bioexcel.eu/u/jalemkul)\
**Post date:** [January 28, 2022, 11:28am UTC](https://gromacs.bioexcel.eu/t/restart-python-script-for-md-simulation/3559/2 "2022-01-28T11:28:04Z")

</div>

What you are showing is the execution of a shell script, which presumably contains an actual GROMACS command within; that would be the relevant information to look at. `mdrun` can resume a previously stopped run by loading a checkpoint file. Just add `-cpi -append` to whatever your previous command was. No Python required.

---

<div class="post-metadata">

**Author:** ![Akki](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/akki/32/958_2.png) [@Akki](https://gromacs.bioexcel.eu/u/Akki)\
**Post date:** [January 28, 2022, 11:50am UTC](https://gromacs.bioexcel.eu/t/restart-python-script-for-md-simulation/3559/3 "2022-01-28T11:50:57Z")

</div>

Actually sir… the script I am using, is for generating replicas… So, can I use **-cpi -append** along with it…

---

<div class="post-metadata">

**Author:** ![jalemkul](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/jalemkul/32/18_2.png) [@jalemkul](https://gromacs.bioexcel.eu/u/jalemkul)\
**Post date:** [January 28, 2022, 1:50pm UTC](https://gromacs.bioexcel.eu/t/restart-python-script-for-md-simulation/3559/4 "2022-01-28T13:50:41Z")

</div>

You need to provide the actual content of your script. You initially asked how to restart a simulation that got stopped. Doing so is trivial by adding the options I indicated to your `mdrun` command. If you are running multiple processes or doing something else, you need to be more specific about what you are doing. Right now, we don’t have the necessary details to help you.

---

<div class="post-metadata">

**Author:** ![Akki](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/akki/32/958_2.png) [@Akki](https://gromacs.bioexcel.eu/u/Akki)\
**Post date:** [January 28, 2022, 4:55pm UTC](https://gromacs.bioexcel.eu/t/restart-python-script-for-md-simulation/3559/5 "2022-01-28T16:55:22Z")

</div>

The content of my script is as follows:

```auto
#!/bin/bash

#################################################
# get_distances.sh
#
# Script iteratively calls gmx distance and
# assembles a series of COM distance values
# indexed by frame number, for use in
# preparing umbrella sampling windows.
#
# Written by: Justin A. Lemkul, Ph.D.
# Contact: jalemkul@vt.edu
#
#################################################

# compute distances
for (( i = 0; i<11; i++ ))
do
      gmx grompp -f smd.mdp -c 0308_npt_50.gro -p 0308.top -r 0308_npt_50.gro -n 0308_index.ndx -t 0308_npt_50.cpt -o 0308_5_pull${i}.tpr
      gmx mdrun -v -deffnm 0308_5_pull${i} -pf 0308_5_pullf${i}.xvg -px 0308_5_pullx${i}.xvg -nb gpu
done
      gmx mdrun -v -s 0308_5_pull0.tpr -cpi 0308_5_pull1.cpt -deffnm 0308_5_pull1 -pf 0308_5_pullf1.xvg -px 0308_5_pullx1.xvg -append -nb gpu

exit

```

---

<div class="post-metadata">

**Author:** ![Akki](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/akki/32/958_2.png) [@Akki](https://gromacs.bioexcel.eu/u/Akki)\
**Post date:** [January 28, 2022, 4:56pm UTC](https://gromacs.bioexcel.eu/t/restart-python-script-for-md-simulation/3559/6 "2022-01-28T16:56:56Z")

</div>

Should i add **-cpi -append** in this script itself??

---

<div class="post-metadata">

**Author:** ![jalemkul](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/jalemkul/32/18_2.png) [@jalemkul](https://gromacs.bioexcel.eu/u/jalemkul)\
**Post date:** [January 28, 2022, 6:41pm UTC](https://gromacs.bioexcel.eu/t/restart-python-script-for-md-simulation/3559/7 "2022-01-28T18:41:49Z")

</div>

Disregard that initial message. I was responding to your claim that you simply had a simulation stop due to a power outage. That statement was inaccurate and therefore my response is not relevant. Please make sure to always accurately and completely describe your problem to save everyone time and confusion.

See which intervals completed and simply start the next one; that is, change the initial value of `i` in the for-loop and re-execute the script.

---

<div class="post-metadata">

**Author:** ![Akki](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/akki/32/958_2.png) [@Akki](https://gromacs.bioexcel.eu/u/Akki)\
**Post date:** [January 28, 2022, 6:56pm UTC](https://gromacs.bioexcel.eu/t/restart-python-script-for-md-simulation/3559/8 "2022-01-28T18:56:18Z")

</div>

Okk sir… Thank you… I will be more specific about my questions…
