This is a read-only mirror of pymolwiki.org

Difference between revisions of "Launching From a Script"

From PyMOL Wiki
Jump to navigation Jump to search
(/* Launching From a Script /*)
 
(example 2)
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
You can also script your launch.  Here is an example script that launches PyMol for stereo viewing on a [http://www.visbox.com/boxMain.html VisBox].  It runs PyMol fullscreen stereo, and disables the internal gui.
+
You can also script your launch.
  
  #!/usr/bin/env python
+
== Example 1 ==
 +
 
 +
Here is an example script that launches PyMol for stereo viewing on a [http://www.visbox.com/boxMain.html VisBox]. It runs PyMol fullscreen stereo, and disables the internal gui.
 +
The environment (PYTHON_PATH and PYMOL_PATH) must already be set up for this example to work (see [[#Example 2|Example 2]] below for how to setup within the script).
 +
 
 +
<source lang="python">
 +
#!/usr/bin/env python
 
   
 
   
# Tell PyMOL we don't want any GUI features.
+
# Tell PyMOL we don't want any GUI features.
import __main__
+
import __main__
__main__.pymol_argv = [ 'pymol', '-Gi' ]
+
__main__.pymol_argv = [ 'pymol', '-qei' ]
 
   
 
   
# Importing the PyMOL module will create the window.
+
# Importing the PyMOL module will create the window.
 +
import pymol
 
   
 
   
import pymol
+
# Call the function below before using any PyMOL modules.
 +
pymol.finish_launching()
 
   
 
   
# Call the function below before using any PyMOL modules.
+
from pymol import cmd
+
cmd.stereo('walleye')
pymol.finish_launching()
+
cmd.set('stereo_shift', 0.23)
+
cmd.set('stereo_angle', 1.0)
from pymol import cmd
+
</source>
cmd.stereo('walleye')
+
 
cmd.set('stereo_shift', 0.23)
+
== Example 2 ==
cmd.set('stereo_angle', 1.0)
+
 
 +
This script launches PyMOL without any GUI for scripting only. It enables tab-completion on the python command line and does the PyMOL environment setup (you need to adjust the '''moddir''' variable!). ''Hint: You may save this as "pymol-cli" executable.''
 +
 
 +
<source lang="python">
 +
#!/usr/bin/python2.6 -i
 +
 
 +
import sys, os
 +
 
 +
# autocompletion
 +
import readline
 +
import rlcompleter
 +
readline.parse_and_bind('tab: complete')
 +
 
 +
# pymol environment
 +
moddir='/opt/pymol-svn/modules'
 +
sys.path.insert(0, moddir)
 +
os.environ['PYMOL_PATH'] = os.path.join(moddir, 'pymol/pymol_path')
 +
 
 +
# pymol launching
 +
import pymol
 +
pymol.pymol_argv = ['pymol','-qc'] + sys.argv[1:]
 +
pymol.finish_launching()
 +
cmd = pymol.cmd
 +
</source>
 +
 
 +
== See Also ==
 +
 
 +
* [[Command Line Options]]
 +
 
 +
[[Category:Launching]]
 +
[[Category:Script_Library]]

Revision as of 08:11, 17 October 2011

You can also script your launch.

Example 1

Here is an example script that launches PyMol for stereo viewing on a VisBox. It runs PyMol fullscreen stereo, and disables the internal gui. The environment (PYTHON_PATH and PYMOL_PATH) must already be set up for this example to work (see Example 2 below for how to setup within the script).

#!/usr/bin/env python
 
# Tell PyMOL we don't want any GUI features.
import __main__
__main__.pymol_argv = [ 'pymol', '-qei' ]
 
# Importing the PyMOL module will create the window.
import pymol
 
# Call the function below before using any PyMOL modules.
pymol.finish_launching()
 
from pymol import cmd
cmd.stereo('walleye')
cmd.set('stereo_shift', 0.23)
cmd.set('stereo_angle', 1.0)

Example 2

This script launches PyMOL without any GUI for scripting only. It enables tab-completion on the python command line and does the PyMOL environment setup (you need to adjust the moddir variable!). Hint: You may save this as "pymol-cli" executable.

#!/usr/bin/python2.6 -i

import sys, os

# autocompletion
import readline
import rlcompleter
readline.parse_and_bind('tab: complete')

# pymol environment
moddir='/opt/pymol-svn/modules'
sys.path.insert(0, moddir)
os.environ['PYMOL_PATH'] = os.path.join(moddir, 'pymol/pymol_path')

# pymol launching
import pymol
pymol.pymol_argv = ['pymol','-qc'] + sys.argv[1:]
pymol.finish_launching()
cmd = pymol.cmd

See Also