Skip to content

Instantly share code, notes, and snippets.

@jbellamycarter
Created June 2, 2020 11:40
Show Gist options
  • Save jbellamycarter/150fc6b75dc7a9f764c121a6b0b77351 to your computer and use it in GitHub Desktop.
Save jbellamycarter/150fc6b75dc7a9f764c121a6b0b77351 to your computer and use it in GitHub Desktop.
PyMol Tkinter plugin that splits difficult multimolecule PDBs, such as those generated by SwissDock or CHARMM simulations.
"""
PyMol plugin that splits difficult multimolecule PDBs, such as those generated
by SwissDock or CHARMM simulations.
Writes a new file that treats each 'molecule' as a model which can then be parsed
by Pymol as 'states'.
Copyright 2018 Jedd Bellamy-Carter
Released under the terms of the MIT License (https://opensource.org/licenses/MIT)
"""
from Tkinter import *
import tkFileDialog
from pymol import cmd
def __init__(self):
self.menuBar.addmenuitem('File', 'command',
'Multimolecule PDB Splitter',
label = 'Multimolecule PDB Splitter',
command = lambda s=self : fileDialog(s))
def fileDialog(self):
"""Opens a file dialog and reads data from the PDB into a list"""
filename = tkFileDialog.askopenfilename(title='Choose PDB containing multiple molecules',
filetypes=[('Protein Data Bank','.pdb'),('All files','.*'),])
if not filename:
return
with open(filename, 'r') as infile:
lines = infile.readlines()
fill = []
for i, line in enumerate(lines):
if line.startswith('TER'):
fill.append(i)
for i, e in enumerate(fill):
lines.insert(i+e+1, 'ENDMDL\n')
newfilename = filename.replace('.pdb', '_split.pdb')
with open(newfilename, 'w') as outfile:
outfile.writelines(lines)
cmd.load(newfilename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment