From: Axel Kohlmeyer (
Date: Wed Apr 22 2009 - 10:42:58 CDT

On Wed, 2009-04-22 at 10:50 +0200, Michael Kreim wrote:
> Dear VMD users,
> I observed a strange behaviour in VMD/python using command line arguments.
> My program expects two file names and one atomselection string as
> parameters. Everything goes well as long as my atomselection does not
> contain any spaces. This leads to an error message I don't understand.

you cannot use arguments with quoted spaces. this is a deficiency
of the c-shell script language that is used in the vmd launch script.
before we start the usual flame war about why c-shell scripting is
bad for your health (it just is!), i would like point out that you
have two options to work around this: 1) use a bourne shell launch
script. the latest vmd alpha/beta versions have it and it is used
whenever there is no /bin/csh available (getting more common these
days). 2) use environment variables. env VMDMYSELECTIONTEXT="xxx with
blanks" vmd -dispdev text ... and so on will work.

due to the fact that the quoted string is broken into words, you have
an odd number of arguments, your python script code seems to be failing
on one of the sys.argv[i+1]. the whole loop code looks a bit sloppy
to me anyways... ;)

> To make it short. My script:
> # vmd -dispdev text -python -e test.vmdpy -args -i input.pdb -o
> output.pdb -s "all"
> import sys
> for i in range(len(sys.argv)):
> if sys.argv[i]=="-s":
> atomselection=sys.argv[i+1]
> elif sys.argv[i]=="-i":
> inputpdb=sys.argv[i+1]
> elif sys.argv[i]=="-o":
> outputpdb=sys.argv[i+1]
> print "atomselction:",atomselection
> print "inputpdb: ",inputpdb
> print "outputpdb: ",outputpdb
> sys.exit()
> # --- EOF ---
> This shows this behaviour:
> $ vmd -dispdev text -python -e test.vmdpy -args -i input.pdb -o
> output.pdb -s "all"
> Info) VMD for LINUXAMD64, version 1.8.6 (April 6, 2007)
> Info)
> Info) Email questions and bug reports to
> Info) Please include this reference in published work using VMD:
> Info) Humphrey, W., Dalke, A. and Schulten, K., `VMD - Visual
> Info) Molecular Dynamics', J. Molec. Graphics 1996, 14.1, 33-38.
> Info) -------------------------------------------------------------
> Info) Multithreading available, 4 CPUs detected.
> Info) Free system memory: 1486MB (38%)
> /home/mkreim/bin/python/python-2.2.3/
> Info) Starting Python...
> Info) Text interpreter now Python
> atomselction: all
> inputpdb: input.pdb
> outputpdb: output.pdb
> $ vmd -dispdev text -python -e test.vmdpy -args -i input.pdb -o
> output.pdb -s "all and not water"
> argv: Index nicht im gültigen Bereich.

o, and _please_ change your locale to "C" before quoting error
messages. i guess that more than 90% of the people subscribed
here would have to respond to this mail with "i don't understand
this error message either, because i don't speak any german".

in general, i'd like to remind you that using native language
support when using scientific software can be leading to all
sorts of weird problems, starting with the difference between
decimal point and decimal comma in german and english.
caveat emptor.


> I tested this also with the python 2.5.1 installation of my linux
> distribution and with the python2.2 binary of VMD:
> $python2.2 test.vmdpy -o out -i in -s "all but not water"
> atomselction: all but not water
> inputpdb: in
> outputpdb: out
> As you can see, if I run the program without VMD everything goes well
> but VMD leads to this strange "argv: Index nicht im gültigen Bereich."
> message.
> What am I doing wrong? How can I pass my atomselection strings to
> VMD/python-scripts via command line?
> Thanking you in anticipation.
> With best regards,
> Michael Kreim

Axel Kohlmeyer
   Center for Molecular Modeling   --   University of Pennsylvania
Department of Chemistry, 231 S.34th Street, Philadelphia, PA 19104-6323
tel: 1-215-898-1582,  fax: 1-215-573-6233,  office-tel: 1-215-898-5425
If you make something idiot-proof, the universe creates a better idiot.