From: Ryan Woltz (rlwoltz_at_ucdavis.edu)
Date: Sat Jan 21 2023 - 17:26:02 CST

Dear Ashar,

          Thank you for your advice, the main reason I don't write it in
python is I haven't had time to learn it, it's been on my agenda since May.
Regardless, I did identify the error and a solution for future users. First
the error:

If you call a python script inside a bash script and that python script
calls another bash command via subprocess like this:

import subprocess as sp

sp.call(['/bin/bash', '-i', '-c', 'vmd -dispdev text -e quit.tcl'],
stdin=sp.PIPE)

it'll stop and need to be restarted with fg X with X being the job number.
The problem is the "#!/bin/bash" as I replaced vmd with a simple bash print
function and that failed in the same way. There are two solutions to this,
one of which is a slight modification of your code (thank you). NOTE: I
import subprocess as sp to save typing:.

solution 1 (note I needed something a bit more complex than the example I
gave as I need a flexible tcl script name to import eg vmd vmd_cmd_file):

cmd = ['vmd', '-dispdev', 'text', '-e', vmd_cmd_file,]
sp.Popen(cmd, stdin=sp.PIPE)

solution 2 (if your environment NEEDS the /bin/bash to run vmd because your
default is not bash):

sp.run(['/bin/bash', '-i', '-c', 'vmd -dispdev text -e quit.tcl'],
start_new_session=True)

solution 2 will give complaints due to the start_new_session but it should
run.

Major thanks to you Ashar for putting us on the right path.

Good luck,

Ryan
On Sat, Jan 21, 2023 at 3:37 AM Ashar Malik <asharjm_at_gmail.com> wrote:

> Let me simplify from what I have gathered from this.
>
>
> You have say 5 python scripts say s1.py …. s5.py
>
> You want to run them in an automated manner?
>
> Why not make a master python script? And use the ‘os’ or subprocess
> library to trigger the 5 scripts?
> Sorry not a bash person - so will suggest an all Python solution.
>
> My master script would read something like this
>
> import os, subprocess
>
> os.system(‘s1.py’)
> os.system(‘s2.py’)
> os.system(‘s3.py’)
> os.system(‘s4.py’)
> os.system(‘s5.py’)
>
> The above structure will run s2 only when s1 finishes whatever it’s doing.
>
> Also I would structure the VMD command via subprocess like this
>
> subprocess.Popen(“vmd -dispdev text -eofexit < tclscript.tcl”, ….)
>
> The above structure allows you to capture stdout dump from shell using
> subprocess.PIPE - if you don’t want that and you are writing to disk in
> your tcl script you can simply run it through
>
> os.system(“vmd -dispdev text -eofexit < tclscript.tcl > /dev/null 2>&1”)
>
> Not sure if I understood your problem well enough - but the above
> structure works for me and I have opened and closed VMD within one and many
> python scripts using the above structure.
>
> Hope this helps.
> Otherwise write back and someone can also suggest a bash solution. Good
> luck.
>
> On Sat, 21 Jan 2023 at 7:19 PM, Ryan Woltz <rlwoltz_at_ucdavis.edu> wrote:
>
>> Dear community,
>>
>> I'm not exactly sure where to go with this question but
>> hopefully someone can give me some direction. My colleague made multiple
>> python scripts that open vmd and do a series of analysis that take 1-2
>> hours. I'd like to combine them into a single master script and run
>> everything the full analysis for a continuous 24-48 hours instead of
>> micromanaging 20+ analysis which needs to be restarted at staggered
>> intervals, I do not write in python and do most scripting in bash.
>>
>> The problem is when I use a bash master script that calls multiple
>> python scripts that open vmd it'll "stopped" on the second opening of vmd.
>> the error from bash is:
>> [2]+ Stopped # with 2 being the number of times I've run the
>> master script
>>
>> This can be restarted by typing %user:fg 2
>>
>> this reopens vmd and continues the script to the next vmd analysis.
>>
>> I have replicated the error with these three scripts that print lines and
>> call the next script until the tcl scripts quits vmd. It can be saved in
>> the terminal in the same directory and executing quit.sh. also note that I
>> get a stopped error is I A)call vmd twice in the python script or B) call
>> the python script 2 times with the python script only opening vmd 1 time--000000000000f0f1d505f2ce7d52--