From: Michael L. <mgl...@gm...> - 2007-08-01 19:06:48
|
Hi, I have a script that uses PyMOL to aid with a lot of calculations. So, I run the script like this: pymol -c script.py The script has grown so that it has a lot of options. Right now, I edit the script every time I want to change them. If it were a normal Python script, I'd run it like script.py --do=something --when=now Is there a standard way to do this via PyMOL? Ideally, I'd like to say pymol -qcr script.py --do=something --when=now and have script.py think that sys.argv == ['script.py', '--do=something', '--when=now']. I pawed through pymol.invocation.py, and it looks like PyMOL respects the convention where it won't parse arguments after a '--', so my current workaround is to launch things like pymol -qcr script.py -- -do=something --when=now and then this in my script: argv = sys.argv[sys.argv.index('--') + 1:] ... # parse with optparse options,args = parser.parse_args(args=argv) So, is there a more standard way of doing this? If not, hopefully google will find this for me the next time I have this question :). Thanks, -Michael -- Biophysics Graduate Student Carlson Lab, University of Michigan http://www.umich.edu/~mlerner |
From: Josep M. C. A. <cam...@ub...> - 2008-02-15 15:55:01
|
Hi all, I'd like to execute pymol like: pymol -c script.py arg1 arg2 arg3 arg4. (1) Reading into PyMolWiki http://www.pymolwiki.org/index.php/Scripting, I've learned that I have to type: pymol -c script.py -- arg1 arg2 arg3 arg4 and then add to my script: from sys import argv my_argv =3D argv[argv.index("--"):] print my_argv[1], my_argv[2] But it doesn work! "Traceback (most recent call last): File "/home/campa/SOFTWARE/pymol/modules/pymol/parser.py", line 285, in parse parsing.run_file(exp_path(args[nest][0]),pymol_names,pymol_names) File "/home/campa/SOFTWARE/pymol/modules/pymol/parsing.py", line 407, in run_file execfile(file,global_ns,local_ns) File "rotamermod3.py", line 45 my_argv =3D argv[argv.index("--"):] ^ SyntaxError: invalid syntax" (2) Then I found an alternatively procedure http://sourceforge.net/mailarchive/message.php?msg_id=e4c539ed0708011206nf6dc1a1r257f7311f42aa59e%40mail.gmail.com Identical command: pymol -c script.py -- arg1 arg2 arg3 arg4 But I have to add into my script.py the following: argv = sys.argv[sys.argv.index('--') + 1:] options,args = parser.parse_args(args=argv) But it doesn't work neither: AttributeError: 'module' object has no attribute 'argv' Can someone give a light in how to call arguments in pymol -c script.py? Thanks a lot, Josep Maria Campanera, |
From: Michael L. <mgl...@gm...> - 2008-02-15 16:21:35
|
Hi, First, the initial error you were seeing was a syntax error: > from sys import argv > my_argv =3D argv[argv.index("--"):] > print my_argv[1], my_argv[2] is failing because of the word "3D" Second, that used to fail on Linux systems anyway (it worked on some other systems). I tend to use optparse, which often requires things to live in sys.argv. Here's my current workaround: #argv = sys.argv[sys.argv.index('--') + 1:] try: argv = sys.argv except AttributeError: argv = pymol_argv sys.argv = pymol_argv # this is necessary for optparse to handle the --help option. try: argv = argv[argv.index('--') + 1:] except IndexError: argv = [] options,args = parser.parse_args(args=argv) I haven't re-tested Linux recently, though. It might be that the pymol_argv workaround is not necessary anymore. -michael -- IRTA Postdoctoral Fellow Laboratory of Computational Biology NIH/NHLBI 5635 Fishers Lane, Room T909 http://www.umich.edu/~mlerner |
From: DeLano S. <de...@de...> - 2008-02-15 17:31:36
|
In the current open-source and beta builds (1.1), pymol -c script.py -- arg1 arg2 should give a sys.argv of ['script.py', 'arg1', 'arg2'] paralleling the behavior of Python, given similar inputs: python script.py arg1 arg2 Cheers, Warren PS. the "3D" after the equals sign is annoying mailing list / MIME artifact. -- DeLano Scientific LLC Subscriber Support Services mailto:de...@de... > -----Original Message----- > From: pym...@li... > [mailto:pym...@li...] On Behalf > Of Michael Lerner > Sent: Friday, February 15, 2008 8:22 AM > To: Josep Maria Campanera Alsina > Cc: pym...@li... > Subject: Re: [PyMOL] Command-line arguments when using PyMOL > to launch ascript > > Hi, > > First, the initial error you were seeing was a syntax error: > > > from sys import argv > > my_argv =3D argv[argv.index("--"):] > > print my_argv[1], my_argv[2] > > is failing because of the word "3D" > > Second, that used to fail on Linux systems anyway (it worked > on some other systems). I tend to use optparse, which often > requires things to live in sys.argv. Here's my current workaround: > > #argv = sys.argv[sys.argv.index('--') + 1:] > try: > argv = sys.argv > except AttributeError: > argv = pymol_argv > sys.argv = pymol_argv # this is necessary for > optparse to handle the --help option. > try: > argv = argv[argv.index('--') + 1:] > except IndexError: > argv = [] > > options,args = parser.parse_args(args=argv) > > I haven't re-tested Linux recently, though. It might be that > the pymol_argv workaround is not necessary anymore. > > -michael > > -- > IRTA Postdoctoral Fellow > Laboratory of Computational Biology NIH/NHLBI > 5635 Fishers Lane, Room T909 > http://www.umich.edu/~mlerner > > -------------------------------------------------------------- > ----------- > This SF.net email is sponsored by: Microsoft Defy all > challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > PyMOL-users mailing list > PyM...@li... > https://lists.sourceforge.net/lists/listinfo/pymol-users |