From: Justin Gullingsrud (jgulling_at_mccammon.ucsd.edu)
Date: Tue Sep 30 2003 - 16:48:47 CDT

Hi,

Nice to see all the interest in the Python interface!

First, in order to run VMD through a pipe, you'll have to first source
the VMD startup script to get the environment variables VMD depends on
(or just set the environment variables yourself in your Python script).
  Once that's done, rather than executing the VMD startup script, just
execute the actual binary, which will be in
os.env('VMDDIR')/LINUX/vmd_LINUX or something like that. You can start
VMD by executing
        vmdin = os.popen('/path/to/vmd_LINUX','w')

When VMD starts up, it's in Tcl mode. This is what you want. If you
start VMD in python mode, VMD won't execute your commands until you
close vmdin, which will causes VMD to quit after it's done executing
the script. You can write any Tcl commands to vmdin (don't forget the
newline at the end!) and VMD will execute them after you call flush():

        vmdin.write('mol pdbload 1e79\n')
        vmdin.flush()

If you want to execute a Python script in VMD, use the gopython Tcl
command:

        vmdin.write('gopython script.py\n')
        vmdin.flush()

You might instead want to use the os.popen2 command to collect stdout
from VMD if you don't want it to go straight to your console.

I just tried this and it seems to work; let us know if you have
problems or comments.

Cheers,
Justin

On Tuesday, September 30, 2003, at 11:52 AM, John R. Kitchin wrote:

> Since there has been some traffic on python and vmd, I have been
> inspired
> to ask whether you can open a pipe to vmd and run it by python. I
> haven't
> been able to find any information on how to do this by the manual or by
> Google so far.
>
> The question is actually somewhat related to the recent question on
> visualization of vibrational modes. We use python to run our quantum
> chemistry code, and I have recently written a module that does
> vibrational
> analysis. My present visualization solution generates a python script
> and
> then calls vmd using os.system('vmd -python -e scriptname'). So vmd
> gets
> started up each time a mode is visualized. It would be nice if instead
> I
> could open a pipe to vmd and then tell it what to do from python
> (interactively even).
>
> thanks,
>
> j