I am writing a function in python to get rms_cur for a peripheral area of a pair of proteins after aligning on a core area. Because my proteins are homologs and not exact matches, I am running align with 0 cycles first, to create an alignment object to pass to rms_cur. I am having trouble with the "object=" argument to cmd.align, which if I understand right is just a name to which align will assign an object it creates so I can use it later (a way to get an object as output). This works fine at the pymol command line, and I get an object named my_align that I can use:
align mobile and periph_sel, target and periph_sel, cycles=0, transform=0, object=my_align
Then I write a python function with the following code:
# align only on core residues
cmd.align('%s and %s'%(mobile, core_sel), '%s and %s'%(target, core_sel))
# without moving proteins, create an alignment object of matching atoms in peripheral areas
cmd.align('%s and %s'%(mobile, periph_sel), '%s and %s'%(target, periph_sel), cycles=0, transform=0, object=my_align)
# use that alignment to get the rms_cur of the peripheral areas
my_rms = cmd.rms_cur('%s and %s'%(mobile, my_align), '%s and %s'%(target, my_align), matchmaker=-1)
When I run the function in pymol, python complains the object is not defined:
cmd.align('%s and %s'%(mobile, periph_sel), '%s and %s'%(target, periph_sel), cycles=0, transform=0, object=my_align)
NameError: name 'my_align' is not defined
How can I use the "object=" argument of align from python so that pymol creates the object and I can then use it from my python code?
In your python version of the code (for the PyMOL API), try adding double-quotes (since you use single quotes already on those lines) around
my_align
in yourcmd.align()
line of code. Note howBLOSUM62
is in quotes in the example under 'PyMOL API' here and those are both shown asstring
type there.I think you won't need
my_align
quoted on themy_rms = cmd.rms_cur()
line as running thecmd.align()
function on the previous line will then have made that object.Thank you for your clear and quick answer! Changing
object=my_align
toobject="my_align"
did indeed get rid of the 'name not defined' error. I also changed the call to cmd.rms_cur to have my_align as part of the string literal passed to pymol (because my_align is a pymol name and not a python name):That call to cmd.rms_cur is now passing the python interpreter and failing in pymol with this message:
However, that is a different problem, so the problem I posted about is solved! Thanks again! [I am looking for the green checkmark to accept Wayne's answer, but can't find it! --ETA this has been resolved.]
ETA: the subsequent atom counts error was actually a related issue: because I was running my code in a python loop, I needed to pass a different string literal as the object name each time through the loop, so that pymol would not try to re-use the same alignment object. Telling pymol to remove the alignment object from memory after using it might also have worked.
I put it as an answer now that you can check put a checkmark then. (They may only have 'solution' checkmark over at Discourse?) I originally posted it just as a comment suggesting it because I hadn't stopped to test it conclusively.