[PyMOL] Expose PyMOL API

2011-11-22 Thread Martin Hediger
Dear PyMOL List
It comes up once in a while, is it possible to use PyMOL features from 
outside of PyMOL? An example, the below is a script (inspired by Thomas 
Holder) which saves down to disk all amino acids of a protein structure 
into separate PDB files.

# *
from pymol import cmd
from pymol import stored
from pymol.exporting import _resn_to_aa as one_letter
# *
def seq(state, selection=name ca or resn hoh or resn lig):
 print Generating seqs.
 cmd.select(prot, selection)
 while cmd.pop(_tmp, prot):
 cmd.iterate(_tmp, stored.x=(resn,resv))
 #print stored.x[0], stored.x[1]

 # Special case 1: Waters.
 if stored.x[0] == 'HOH':
 filename = 'seq-x%s-%s.pdb' % (stored.x[1], state)
 # Special case 2: Substrate.
 elif stored.x[0] == 'LIG':
 filename = 'seq-x%s-%s.pdb' % (stored.x[1], state)
 # Other: protein back-bone.
 else:
 filename = 'seq-%s%d-%s.pdb' % (one_letter[stored.x[0]].lower(), 
stored.x[1], state)
 cmd.save(filename, byres _tmp)
 cmd.delete('_tmp prot')

cmd.extend('seq', seq)
# -

Is it possible to somehow include this in a Python script, and running 
it from the command line? If not, why?


Thanks for any feedback.



--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net


Re: [PyMOL] Expose PyMOL API

2011-11-22 Thread Thomas Holder
Hi Martin,

the recommended way is to use PyMOL as your python interpreter, so 
instead of:

   python file.py

do this:

   pymol -cqr file.py


However, launching a PyMOL process from a python terminal as you 
suggested is also possible. Have a look at Example 2 of 
http://pymolwiki.org/index.php/Launching_From_a_Script , the important 
lines are those:

import pymol
pymol.pymol_argv = ['pymol','-qc']
pymol.finish_launching()

Cheers,
   Thomas


Martin Hediger wrote, On 11/22/11 09:26:
 Dear PyMOL List
 It comes up once in a while, is it possible to use PyMOL features from 
 outside of PyMOL? An example, the below is a script (inspired by Thomas 
 Holder) which saves down to disk all amino acids of a protein structure 
 into separate PDB files.
 
 # *
 from pymol import cmd
 from pymol import stored
 from pymol.exporting import _resn_to_aa as one_letter
 # *
 def seq(state, selection=name ca or resn hoh or resn lig):
  print Generating seqs.
  cmd.select(prot, selection)
  while cmd.pop(_tmp, prot):
  cmd.iterate(_tmp, stored.x=(resn,resv))
  #print stored.x[0], stored.x[1]
 
  # Special case 1: Waters.
  if stored.x[0] == 'HOH':
  filename = 'seq-x%s-%s.pdb' % (stored.x[1], state)
  # Special case 2: Substrate.
  elif stored.x[0] == 'LIG':
  filename = 'seq-x%s-%s.pdb' % (stored.x[1], state)
  # Other: protein back-bone.
  else:
  filename = 'seq-%s%d-%s.pdb' % (one_letter[stored.x[0]].lower(), 
 stored.x[1], state)
  cmd.save(filename, byres _tmp)
  cmd.delete('_tmp prot')
 
 cmd.extend('seq', seq)
 # -
 
 Is it possible to somehow include this in a Python script, and running 
 it from the command line? If not, why?
 
 
 Thanks for any feedback.

-- 
Thomas Holder
MPI for Developmental Biology
Spemannstr. 35
D-72076 Tübingen

--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net


Re: [PyMOL] Expose PyMOL API

2011-11-22 Thread Thomas Holder
Hi Martin,

I don't have a Mac so I can't test this, sorry.

I suspect that the _cmd module is built into the MacPyMOL executable. 
This would imply that you cannot use MacPyMOL like in the 
Launching_From_a_Script examples. Maybe someone of the MacPyMOL users 
knows more?

Cheers,
   Thomas

Martin Hediger wrote, On 11/22/11 13:14:
 Thanks Thomas for the reply. I tried it under Mac OS X 10.5.8.
 
 me @ ~/PROG_TEST $ python
 Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55)
 [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
 Type help, copyright, credits or license for more information.
 imported numpy
 from PyQt4.QtGui imported *
 from PyQt4.QtCore imported *
  import os, sys
  import readline
  import rlcompleter
  readline.parse_and_bind('tab: complete')
  moddir='/Applications/PyMOLX11Hybrid.app/pymol/modules'
  sys.path.insert(0, moddir)
  os.environ['PYMOL_PATH'] = os.path.join(moddir, 'pymol/pymol_path')
  import pymol
 Traceback (most recent call last):
   File stdin, line 1, inmodule
   File 
 /Applications/PyMOLX11Hybrid.app/pymol/modules/pymol/__init__.py, line 
 472, inmodule
 import _cmd
 ImportError: No module named _cmd
  import pymol
 
 
 What could be the problem? Could it be that the 'pymol/pymol_path' call 
 is not exactly right? In the modules/pymol directory, there is a module 
 'pymol/launch_pymol', but I have a similar error (No module named 
 _cmd) when I try to import it.
 Martin
 
 
 
 
 
 
 Am 22.11.11 09:47, schrieb Thomas Holder:
 Hi Martin,

 the recommended way is to use PyMOL as your python interpreter, so 
 instead of:

   python file.py

 do this:

   pymol -cqr file.py


 However, launching a PyMOL process from a python terminal as you 
 suggested is also possible. Have a look at Example 2 of 
 http://pymolwiki.org/index.php/Launching_From_a_Script , the important 
 lines are those:

 import pymol
 pymol.pymol_argv = ['pymol','-qc']
 pymol.finish_launching()

 Cheers,
   Thomas


 Martin Hediger wrote, On 11/22/11 09:26:
 Dear PyMOL List
 It comes up once in a while, is it possible to use PyMOL features 
 from outside of PyMOL? An example, the below is a script (inspired by 
 Thomas Holder) which saves down to disk all amino acids of a protein 
 structure into separate PDB files.

 # *
 from pymol import cmd
 from pymol import stored
 from pymol.exporting import _resn_to_aa as one_letter
 # *
 def seq(state, selection=name ca or resn hoh or resn lig):
  print Generating seqs.
  cmd.select(prot, selection)
  while cmd.pop(_tmp, prot):
  cmd.iterate(_tmp, stored.x=(resn,resv))
  #print stored.x[0], stored.x[1]

  # Special case 1: Waters.
  if stored.x[0] == 'HOH':
  filename = 'seq-x%s-%s.pdb' % (stored.x[1], state)
  # Special case 2: Substrate.
  elif stored.x[0] == 'LIG':
  filename = 'seq-x%s-%s.pdb' % (stored.x[1], state)
  # Other: protein back-bone.
  else:
  filename = 'seq-%s%d-%s.pdb' % 
 (one_letter[stored.x[0]].lower(), stored.x[1], state)
  cmd.save(filename, byres _tmp)
  cmd.delete('_tmp prot')

 cmd.extend('seq', seq)
 # -

 Is it possible to somehow include this in a Python script, and 
 running it from the command line? If not, why?


 Thanks for any feedback.

-- 
Thomas Holder
MPI for Developmental Biology
Spemannstr. 35
D-72076 Tübingen

--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net


Re: [PyMOL] Expose PyMOL API

2011-11-22 Thread Jason Vertrees
Martin,

The _cmd module is indeed statically linked into MacPyMOL. But, if you
built from open-source it's dumped into site-packages/pymol. Also,
view the files inside pymol/examples/launching. There are plenty of
examples. If you're using a pre-built package from elsewhere, then
please contact the package maintainer to see how it's built.

Last, I prefer the newer pymol2 strategy where you get a handle to a
PyMOL cmd instance:

from pymol2 import PyMOL
cmd=PyMOL().cmd

Cheers,

-- Jason

On Tue, Nov 22, 2011 at 8:19 AM, Thomas Holder
spel...@users.sourceforge.net wrote:
 Hi Martin,

 I don't have a Mac so I can't test this, sorry.

 I suspect that the _cmd module is built into the MacPyMOL executable.
 This would imply that you cannot use MacPyMOL like in the
 Launching_From_a_Script examples. Maybe someone of the MacPyMOL users
 knows more?

 Cheers,
   Thomas

 Martin Hediger wrote, On 11/22/11 13:14:
 Thanks Thomas for the reply. I tried it under Mac OS X 10.5.8.

 me @ ~/PROG_TEST $ python
 Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55)
 [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
 Type help, copyright, credits or license for more information.
 imported numpy
 from PyQt4.QtGui imported *
 from PyQt4.QtCore imported *
  import os, sys
  import readline
  import rlcompleter
  readline.parse_and_bind('tab: complete')
  moddir='/Applications/PyMOLX11Hybrid.app/pymol/modules'
  sys.path.insert(0, moddir)
  os.environ['PYMOL_PATH'] = os.path.join(moddir, 'pymol/pymol_path')
  import pymol
 Traceback (most recent call last):
   File stdin, line 1, inmodule
   File
 /Applications/PyMOLX11Hybrid.app/pymol/modules/pymol/__init__.py, line
 472, inmodule
     import _cmd
 ImportError: No module named _cmd
  import pymol


 What could be the problem? Could it be that the 'pymol/pymol_path' call
 is not exactly right? In the modules/pymol directory, there is a module
 'pymol/launch_pymol', but I have a similar error (No module named
 _cmd) when I try to import it.
 Martin






 Am 22.11.11 09:47, schrieb Thomas Holder:
 Hi Martin,

 the recommended way is to use PyMOL as your python interpreter, so
 instead of:

   python file.py

 do this:

   pymol -cqr file.py


 However, launching a PyMOL process from a python terminal as you
 suggested is also possible. Have a look at Example 2 of
 http://pymolwiki.org/index.php/Launching_From_a_Script , the important
 lines are those:

 import pymol
 pymol.pymol_argv = ['pymol','-qc']
 pymol.finish_launching()

 Cheers,
   Thomas


 Martin Hediger wrote, On 11/22/11 09:26:
 Dear PyMOL List
 It comes up once in a while, is it possible to use PyMOL features
 from outside of PyMOL? An example, the below is a script (inspired by
 Thomas Holder) which saves down to disk all amino acids of a protein
 structure into separate PDB files.

 # *
 from pymol import cmd
 from pymol import stored
 from pymol.exporting import _resn_to_aa as one_letter
 # *
 def seq(state, selection=name ca or resn hoh or resn lig):
      print Generating seqs.
      cmd.select(prot, selection)
      while cmd.pop(_tmp, prot):
          cmd.iterate(_tmp, stored.x=(resn,resv))
          #print stored.x[0], stored.x[1]

          # Special case 1: Waters.
          if stored.x[0] == 'HOH':
              filename = 'seq-x%s-%s.pdb' % (stored.x[1], state)
          # Special case 2: Substrate.
          elif stored.x[0] == 'LIG':
              filename = 'seq-x%s-%s.pdb' % (stored.x[1], state)
          # Other: protein back-bone.
          else:
              filename = 'seq-%s%d-%s.pdb' %
 (one_letter[stored.x[0]].lower(), stored.x[1], state)
          cmd.save(filename, byres _tmp)
      cmd.delete('_tmp prot')

 cmd.extend('seq', seq)
 # -

 Is it possible to somehow include this in a Python script, and
 running it from the command line? If not, why?


 Thanks for any feedback.

 --
 Thomas Holder
 MPI for Developmental Biology
 Spemannstr. 35
 D-72076 Tübingen

 --
 All the data continuously generated in your IT infrastructure
 contains a definitive record of customers, application performance,
 security threats, fraudulent activity, and more. Splunk takes this
 data and makes sense of it. IT sense. And common sense.
 http://p.sf.net/sfu/splunk-novd2d
 ___
 PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
 Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
 Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net




-- 
Jason Vertrees, PhD
PyMOL Product Manager
Schrodinger, LLC

(e) jason.vertr...@schrodinger.com
(o) +1 (603) 374-7120

--
All the data continuously generated 

Re: [PyMOL] Expose PyMOL API

2011-11-22 Thread Martin Hediger
Thanks for the answers. I'll be trying to get it compile on a linux box, 
if I could access some of the PyMOL features there, that's fine as well. 
A friend tried to compile PyMOL on Mac and had quite some trouble, so 
I'll be first trying the Linux option.
Martin







Am 22.11.11 15:56, schrieb Jason Vertrees:
 Martin,

 The _cmd module is indeed statically linked into MacPyMOL. But, if you
 built from open-source it's dumped into site-packages/pymol. Also,
 view the files inside pymol/examples/launching. There are plenty of
 examples. If you're using a pre-built package from elsewhere, then
 please contact the package maintainer to see how it's built.

 Last, I prefer the newer pymol2 strategy where you get a handle to a
 PyMOL cmd instance:

 from pymol2 import PyMOL
 cmd=PyMOL().cmd

 Cheers,

 -- Jason

 On Tue, Nov 22, 2011 at 8:19 AM, Thomas Holder
 spel...@users.sourceforge.net  wrote:
 Hi Martin,

 I don't have a Mac so I can't test this, sorry.

 I suspect that the _cmd module is built into the MacPyMOL executable.
 This would imply that you cannot use MacPyMOL like in the
 Launching_From_a_Script examples. Maybe someone of the MacPyMOL users
 knows more?

 Cheers,
Thomas

 Martin Hediger wrote, On 11/22/11 13:14:
 Thanks Thomas for the reply. I tried it under Mac OS X 10.5.8.

 me @ ~/PROG_TEST $ python
 Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55)
 [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
 Type help, copyright, credits or license for more information.
 imported numpy
 from PyQt4.QtGui imported *
 from PyQt4.QtCore imported *
   import os, sys
   import readline
   import rlcompleter
   readline.parse_and_bind('tab: complete')
   moddir='/Applications/PyMOLX11Hybrid.app/pymol/modules'
   sys.path.insert(0, moddir)
   os.environ['PYMOL_PATH'] = os.path.join(moddir, 'pymol/pymol_path')
   import pymol
 Traceback (most recent call last):
File stdin, line 1, inmodule
File
 /Applications/PyMOLX11Hybrid.app/pymol/modules/pymol/__init__.py, line
 472, inmodule
  import _cmd
 ImportError: No module named _cmd
   import pymol

 What could be the problem? Could it be that the 'pymol/pymol_path' call
 is not exactly right? In the modules/pymol directory, there is a module
 'pymol/launch_pymol', but I have a similar error (No module named
 _cmd) when I try to import it.
 Martin






 Am 22.11.11 09:47, schrieb Thomas Holder:
 Hi Martin,

 the recommended way is to use PyMOL as your python interpreter, so
 instead of:

python file.py

 do this:

pymol -cqr file.py


 However, launching a PyMOL process from a python terminal as you
 suggested is also possible. Have a look at Example 2 of
 http://pymolwiki.org/index.php/Launching_From_a_Script , the important
 lines are those:

 import pymol
 pymol.pymol_argv = ['pymol','-qc']
 pymol.finish_launching()

 Cheers,
Thomas


 Martin Hediger wrote, On 11/22/11 09:26:
 Dear PyMOL List
 It comes up once in a while, is it possible to use PyMOL features
 from outside of PyMOL? An example, the below is a script (inspired by
 Thomas Holder) which saves down to disk all amino acids of a protein
 structure into separate PDB files.

 # *
 from pymol import cmd
 from pymol import stored
 from pymol.exporting import _resn_to_aa as one_letter
 # *
 def seq(state, selection=name ca or resn hoh or resn lig):
   print Generating seqs.
   cmd.select(prot, selection)
   while cmd.pop(_tmp, prot):
   cmd.iterate(_tmp, stored.x=(resn,resv))
   #print stored.x[0], stored.x[1]

   # Special case 1: Waters.
   if stored.x[0] == 'HOH':
   filename = 'seq-x%s-%s.pdb' % (stored.x[1], state)
   # Special case 2: Substrate.
   elif stored.x[0] == 'LIG':
   filename = 'seq-x%s-%s.pdb' % (stored.x[1], state)
   # Other: protein back-bone.
   else:
   filename = 'seq-%s%d-%s.pdb' %
 (one_letter[stored.x[0]].lower(), stored.x[1], state)
   cmd.save(filename, byres _tmp)
   cmd.delete('_tmp prot')

 cmd.extend('seq', seq)
 # -

 Is it possible to somehow include this in a Python script, and
 running it from the command line? If not, why?


 Thanks for any feedback.
 --
 Thomas Holder
 MPI for Developmental Biology
 Spemannstr. 35
 D-72076 Tübingen

 --
 All the data continuously generated in your IT infrastructure
 contains a definitive record of customers, application performance,
 security threats, fraudulent activity, and more. Splunk takes this
 data and makes sense of it. IT sense. And common sense.
 http://p.sf.net/sfu/splunk-novd2d
 ___
 PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
 Info Page: