Selecting Conserved Residues In Protein Using Pymol Script By Importing Residue List From A Text File
1
0
Entering edit mode
12.0 years ago
sayonidas03 ▴ 100

Hi,

I wanted to select certain highly conserved residues in a protein (computed by a scoring mechanism and listed in a text file - each residue in a single line) using a PyMol script. The PyMol script below that I am using is not working. I will be very grateful to you if someone could help me out.

Parts of the script work perfectly fine when run separately - the Pymol script when a residue number is mentioned in the script without importing the list from the text file and just the python script for loading numbers from a file into an array also works fine when run separately. But the problem is seen when it is combined as in my script below - when residue number needs to be taken from the array as I after importing the list from the text file. Any help is appreciated. Thanks!

#!/usr/bin/python
from pymol import cmd
import string
cmd.load("/home/xyz/proteinA.pdb", 'protein')
cmd.hide()
cmd.bg_color("white")
cmd.show("mesh")
cmd.color("blue")

f=open('/home/xyz/residuedata.txt','r')
array = []
filecontents = f.read().split()
for val in filecontents:
            array.append(int(val))
f.close()
for I in array:
        cmd.select("residuedata", "resi i")
        cmd.show('sphere', "residuedata")
        cmd.color ('red', "residuedata")
pymol python • 6.8k views
ADD COMMENT
1
Entering edit mode

I've never actually used a script interface to PyMol so don't know about the cmd functions you're using, but cmd.select("residuedata", "resi i") isn't using the integer stored in i - it's just passing the string "resi i". I guess instead you want "resi " + str(i)

ADD REPLY
0
Entering edit mode

Thank you Ben. That was a very important clue for me.

ADD REPLY
0
Entering edit mode
12.0 years ago
sayonidas03 ▴ 100

It works now: by changing it like this

for i in range(len(array)):
    cmd.select('scorecons', 'resi %s' % array[i])
ADD COMMENT
1
Entering edit mode

You could also write:

for i in array:
    cmd.select('scorecons', 'resi %s' % i)

For loops in Python behave like foreach loops in other languages.

ADD REPLY

Login before adding your answer.

Traffic: 2505 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6