2

I am trying to draw a protein structure from a pdb file using pymol.

However, when I try to run the script below, a pymol window opens but it is just pitch black. Also, bizarrely, the pdb file is outputted to the shell.

Here is my code:

bioservices_pdb_obj = PDB()
pdb_file = bioservices_pdb_obj.getFile(results[str(Brick.part_attrib(self,'uniprot_id'))][detail-1],'pdb')
pdb_name = str(Brick.part_attrib(self,'uniprot_id'))
pymol.finish_launching()                
pymol.cmd.load(pdb_file, pdb_name)
pymol.cmd.disable("all")
pymol.cmd.enable(pdb_name)
pymol.cmd.png("my_pdb.png")
pymol.cmd.quit()

Does anyone know what is going on here?

The .png file 'my_pdb' is dumped into the working directory, but that's just black as well.

seaotternerd
  • 6,298
  • 2
  • 47
  • 58
Charon
  • 2,344
  • 6
  • 25
  • 44

1 Answers1

0

Does this also happen with any other PDB file? If yes, you can try a workaround using the cmd.mpng() function. You can use this function also in other contexts if the cmd.png() function doesn't work, e.g. when using PyMOL in command-line mode.

import pymol
from pymol import cmd
import os
pymol.finish_launching()                
cmd.set('ray_trace_frames', 1)  # Frames are raytraced before saving an image.

def pnghack(filepath, width=1024, height=768):
"""Workaround if cmd.png() doesn't work"""
    cmd.viewport(width, height)  # Set resolution
    cmd.mpng(filepath, 1, 1)  # Use batch png mode with 1 frame only
    cmd.mplay()  # cmd.mpng needs the animation to 'run'

cmd.load(pdb_file, pdb_name)
cmd.disable("all")
cmd.enable(pdb_name)
pnghack("my_pdb.png")
cmd.quit()

Note that the resulting png file is named "my_pdb0001.png" as the cmd.mpng() function always adds the framenumber.

ssalentin
  • 11
  • 1