Re: [chimera-dev] [Chimera-users] error: from DockPrep import prep

Dear sir: Thanks for the detailed reply! When the following code was added to the start of sciprt: import chimeraInit chimeraInit.init(nogui=True, silent=True) The interpreter print the following confused error: --------------------------------------------- Traceback (most recent call last): File "./xx.py", line 5, in <module> chimeraInit.init(nogui=True, silent=True) TypeError: init() takes at least 1 argument (2 given) ----------------------------------------------- it's really easy and convenient to running python script with chimera. The reason for i want to run python script independently is that i want add some custom command option. However, if i run python script with chimera, it's hard for me to add some custom command option and handle it in the script though getopt module. For example, when i run some command like this: chimera –nogui test.py -t test test.py ################### #!/usr/bin/python t=None try: opts, args = getopt.getopt(sys.argv[1:], "t:") except getopt.GetoptError, err: pass finally: for arg_k, arg_v in opts: if (arg_k =="-t"): t=arg_v #################################### This will raise running exception! is there a way for me to add the coustom option to python script and run the script with chimera? the exception message as follow: ------------------------------------------------- Executing test.py... Traceback (most recent call last): File "/home/wascm/chimera/share/chimeraInit.py", line 588, in init chimera.openModels.open(a, prefixableType=1) File "/home/wascm/chimera/share/chimera/__init__.py", line 1537, in open models = func(filename, *args, **kw) File "/home/wascm/chimera/share/chimera/__init__.py", line 972, in _openPython loadFunc(sandboxName, fileName, f) File "test.py", line 10, in <module> for arg_k, arg_v in opts: NameError: name 'opts' is not defined Error while processing test.py: NameError: name 'opts' is not defined File "test.py", line 10, in <module> for arg_k, arg_v in opts: See reply log for Python traceback. Traceback (most recent call last): File "/home/wascm/chimera/share/chimeraInit.py", line 588, in init chimera.openModels.open(a, prefixableType=1) File "/home/wascm/chimera/share/chimera/__init__.py", line 1503, in open raise ValueError, "Unknown model type" ValueError: Unknown model type Error while processing -t: ValueError: Unknown model type File "/home/wascm/chimera/share/chimera/__init__.py", line 1503, in open raise ValueError, "Unknown model type" See reply log for Python traceback. Traceback (most recent call last): File "/home/wascm/chimera/share/chimeraInit.py", line 588, in init chimera.openModels.open(a, prefixableType=1) File "/home/wascm/chimera/share/chimera/__init__.py", line 1503, in open raise ValueError, "Unknown model type" ValueError: Unknown model type Error while processing test: ValueError: Unknown model type File "/home/wascm/chimera/share/chimera/__init__.py", line 1503, in open raise ValueError, "Unknown model type" See reply log for Python traceback. ---------------------------------------------------------- At 2011-03-15 09:02:09,"Greg Couch" <gregc@cgl.ucsf.edu> wrote: (This is really achimera-dev@cgl.ucsf.edu mailing list question.) My guess is that your problem is that chimeraInit.init() was never called, so the chimera internals were never set up. So in the beginning of your Python script, add: import chimeraInit chimeraInit.init(nogui=True, silent=True) before using chimera's modules. But, in general, you would be better off running those python scripts with chimera. For example: % chimera --nogui --silent script.py That would set up the the appropriate environment for chimera, execute the python script, and exit. And you would be protected against any future changes in how chimera is initialized. If you want to use other Python modules with chimera, set your CHIMERAPATH environment variable with a list of directories that hold the Python modules (same syntax as PYTHONPATH, but just for chimera). If you want to install other Python packages into chimera's Python that have a setup.py file, use: % chimera --nogui --silent setup.py install It is also possible to make easy_install work with chimera by temporarily putting chimera's bin directory on your path and running the appropriate egg (seehttp://pypi.python.org/pypi/setuptools for details). Right now, chimera is using Python 2.7. HTH, Greg

On Mar 15, 2011, at 5:37 AM, wascm wrote:
Dear sir:
Thanks for the detailed reply!
When the following code was added to the start of sciprt:
import chimeraInit chimeraInit.init(nogui=True, silent=True)
The interpreter print the following confused error:
--------------------------------------------- Traceback (most recent call last): File "./xx.py", line 5, in <module> chimeraInit.init(nogui=True, silent=True) TypeError: init() takes at least 1 argument (2 given)
There was an oversight in the code Greg provided: chimeraInit.init takes a mandatory "argv" argument, which is exactly like sys.argv.
-----------------------------------------------
it's really easy and convenient to running python script with chimera. The reason for i want to run python script independently is that i want add some custom command option. However, if i run python script with chimera, it's hard for me to add some custom command option and handle it in the script though getopt module.
For example, when i run some command like this:
chimera –nogui test.py -t test
test.py ################### #!/usr/bin/python
t=None
try: opts, args = getopt.getopt(sys.argv[1:], "t:") except getopt.GetoptError, err: pass finally: for arg_k, arg_v in opts: if (arg_k =="-t"): t=arg_v ####################################
This will raise running exception!
is there a way for me to add the coustom option to python script and run the script with chimera?
Yes. Use a --script argument, like this: chimera --nogui --script "test.py -t test" --Eric

See the Chimera Programmer's FAQ, question #3, http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/faq.html#q3, for how to write a shell script wrapper around a chimera script to hide the fact that chimera is running the script instead of python and use getopt everywhere. -- Greg On 03/15/2011 02:12 PM, Eric Pettersen wrote:
On Mar 15, 2011, at 5:37 AM, wascm wrote:
Dear sir:
Thanks for the detailed reply!
When the following code was added to the start of sciprt:
/import chimeraInit chimeraInit.init(nogui=True, silent=True)/
The interpreter print the following confused error:
--------------------------------------------- /Traceback (most recent call last): File "./xx.py", line 5, in <module> chimeraInit.init(nogui=True, silent=True) TypeError: init() takes at least 1 argument (2 given)/
There was an oversight in the code Greg provided: chimeraInit.init takes a mandatory "argv" argument, which is exactly like sys.argv.
-----------------------------------------------
it's really easy and convenient to running python script with chimera. The reason for i want to run python script independently is that i want add some custom command option. However, if i run python script with chimera, it's hard for me to add some custom command option and handle it in the script though getopt module.
For example, when i run some command like this:
chimera –nogui test.py -t test
test.py ################### #!/usr/bin/python
t=None
try: opts, args = getopt.getopt(sys.argv[1:], "t:") except getopt.GetoptError, err: pass finally: for arg_k, arg_v in opts: if (arg_k =="-t"): t=arg_v ####################################
This will raise running exception!
is there a way for me to add the coustom option to python script and run the script with chimera?
Yes. Use a --script argument, like this:
chimera --nogui --script "test.py -t test"
--Eric
_______________________________________________ Chimera-dev mailing list Chimera-dev@cgl.ucsf.edu http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-dev
participants (3)
-
Eric Pettersen
-
Greg Couch
-
wascm