Loading multiple pdb files in pymol
1
1
Entering edit mode
8.1 years ago
underoath006 ▴ 10

I want to use the code from example 4 here to iterate over many files:

https://pymolwiki.org/index.php/Get_Area

I tried to look up some documentation about pymol, I think maybe "glob" could be used but idon't really understand it. I found this post here, but couldn't really conenct the two codes together:

https://sourceforge.net/p/pymol/mailman/message/27805952/

I would appreciate if someone could help. P.s. I'm new to both pymol and python.

pymol python • 9.6k views
ADD COMMENT
1
Entering edit mode
8.1 years ago
cschu181 ★ 2.8k

Assuming you call your script with

python <scriptname> <path-to-pdb-files>

then this might do it:

import glob
import sys
import os
for _file in glob.glob(os.path.join(sys.argv[1], '*.pdb')):
    cmd.load(_file)  # use the name of your pdb file
    # rest of code-block
ADD COMMENT
0
Entering edit mode

didn't quite work and I can't debug it because I'm not entirely sure what glob does! can I message you? please email me at underoath006 at gmail.

ADD REPLY
0
Entering edit mode

Communicating via email is not encouraged, this discussion could be beneficial for everyone.

Glob searches for files matching a pattern, in this case files in the directory specified by sys.argv[1] which end in .pdf.

ADD REPLY
0
Entering edit mode

*end in .pdb, not .pdf :P

@underoath006: What is the error you're getting?

ADD REPLY
0
Entering edit mode

Gha close enough ;)

ADD REPLY
0
Entering edit mode

But still no cigar :)

ADD REPLY
0
Entering edit mode
Area-Error: Selection must be within a single object.
Traceback (most recent call last):
  File "pymol_sa.py", line 29, in <module>
    sasa_per_residue.append(cmd.get_area('resi %s' % i))
  File "C:\Users\Ahmad\Anaconda3\lib\site-packages\pymol\querying.py", line 1174
, in get_area
    if _self._raising(): raise pymol.CmdException
pymol.CmdException:  Error:

this is the error Iget, how can I post the entire script for you to look at?

ADD REPLY
0
Entering edit mode

You can put your script on GitHub (gist) and then post the link for public gist in a post here. Biostars understands GitHub and will load the code from the gist automatically.

ADD REPLY
0
Entering edit mode

This code works if I type in the name of the pdb file, it calculates the accessible surface area of each residue in a pdb file and returns a dictionary that could be saved using json dump. I want to iterate this process over many pdb file. The problem with pymol is that it needs to be restarted between runs for some reasons. :(

ADD REPLY
0
Entering edit mode

Currently everything from line 18 on is not covered by the for-loop, so that block would have to be indented. Is there a cmd.unload() or something that you could use at the end of the for-loop?

The easiest way could be to run this script once for each file, e.g. via a bash loop.

ADD REPLY
0
Entering edit mode

sorry my bad, but I get the same error. Can you elaborate what you mean by a bash loop? I found this, now how can we use it?

https://pymolwiki.org/index.php/Reinitialize

ADD REPLY
0
Entering edit mode

Insert a cmd.reinitialize() before line 16 and try if that works.

Concerning the bash loop, that would be a way to run the script for multiple files using the Unix shell. There's also a way to do that on the Windows command line, but I don't know the syntax for it.

ADD REPLY

Login before adding your answer.

Traffic: 2016 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