This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Problem in compiling a modified Pymol plugin

I am trying to use a part of the fitting.py plugin available here. Fitting.py uses a trick to try and align structures that are very different from one another. It does this by temporarily modifying the resname of one structure to match the other and then aligning these structures with same name.

I am using the same trick to generate two structures with same resname. I upload the plugin and try to proceed normally, however, I get two errors-one is while parsing the file and other while saving it.

I am posting the plugin along with the errors:

from pymol import cmd

def alter(obj1,select1,obj2,select2):
    list_m = []
    list_n = []

    calpha = 'name ca'
    select1 = '%s & %s' % (selection1,calpha)
    select2 = '%s & %s' % (selection2,calpha)
    m=cmd.get_model("%s & %s" % (obj1,select1))
    n=cmd.get_model("%s & %s" % (obj2,select2))
    for at in m.atom:
        list_m.append((at.id,at.chain,at.resn,at.resi,at.name,at.segi, at.alt))
    for at in n.atom:
        list_n.append((at.id,at.chain,at.resn,at.resi,at.name,at.segi, at.alt))

    if len(m.atom) <= len(n.atom):
        total = len(m.atom)
    else:
        total = len(n.atom)

    for I in range(total):
        cmd.do("alter %s & id %s, chain='%s'" % (obj1,list_m[i][0],list_n[i][1]))
        cmd.do("alter %s & id %s, resn='%s'" % (obj1,list_m[i][0],list_n[i][2]))
        cmd.do("alter %s & id %s, resi=%s" % (obj1,list_m[i][0],list_n[i][3]))
        cmd.do("alter %s & id %s, alt='%s'" % (obj1,list_m[i][0],list_n[i][6]))

    cmd.save(file1, obj1, 0, pdb)
    cmd.save(file2, obj2, 0, pdb)

cmd.extend("alter",alter)

Error-

Parsing-Error: missing required argument in function  alter  : select1
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymol/parser.py", line 256, in parse
    self.result=apply(layer.kw[0],layer.args,layer.kw_args)
  File "/Users/reload/.pymol/startup/alter.py", line 28, in alter
    cmd.save(obj1, obj1, 0, pdb)
NameError: global name 'pdb' is not defined
protein rmsd pymol structure fitting

Your code does not compile when I try to run it. Please check in the lines starting with `list_m.append`; you're missing brackets here.

The NameError at the end is thrown because you do not define `pdb` anywhere in your script.

What about the select1 and select2 arguments parsed to the function? Why are they required but then redefined without the user's input being used?

0 answers

No answers yet.

Log in to answer this question.