|
From: Zhou, Y. <yin...@no...> - 2024-05-29 02:46:29
|
Here is the solution. Wonder if someone can help explain why the line below gives an error about print is not defined:
out=x.cmd.do("iterate mysel and name CA, print(resi)")
Thanks!
~~~~
import pymol2
x=pymol2.PyMOL()
x.start()
x.cmd.do("fetch 1crn; select mysel, /1crn//A/10-20")
out=[]
def f(chain, resi): out.append((chain,resi))
myspace={'f':f}
x.cmd.iterate("mysel and name CA", "f(chain, resi)", space=myspace)
print(out)
From: Zhou, Yingyao
Sent: Tuesday, May 28, 2024 3:57 PM
To: pym...@li...
Subject: How to obtain a PyMOL selection within Python
Hi,
In the example code below, there is a selection object "myself" within PyMOL, I try to obtain the selected residues within Python.
The "out=x.cmd.do" prints the selection to stdout, but the variable out remains None. What would be a good way to get the selection without going through disk I/O?
import pymol2
x=pymol2.PyMOL()
x.start()
x.cmd.do("fetch 1crn; select mysel, /1crn//A/10-20")
out=x.cmd.do("iterate mysel and name CA, (resi)")
print(out)
A separate question, when I run the following line of Python, I got an error (however the command works using PyMOL's command interface):
out=x.cmd.do("iterate mysel and name CA, print(resi)")
I got an error:
return _cmd.alter(_self._COb, selection, expression, True,
File "", line 1, in <module>
NameError: name 'print' is not defined
What's the syntax error in this line?
Thank you,
Yingyao
|