Commit a991e13e by Peter Eastman

Displayed residue numbers match the ones in the PDB file. User can select what…

Displayed residue numbers match the ones in the PDB file.  User can select what amino acid to convert nonstandard ones to
parent d1c0f578
This PDB file contains non-standard residues. Do you want to convert them to the corresponding standard residues? This PDB file contains non-standard residues. Do you want to convert them to standard residues?
<p> <p>
<form method="post" action="/"> <form method="post" action="/">
<table border="1" id="table"> <table border="1" id="table">
......
...@@ -98,7 +98,7 @@ class PDBFixer(object): ...@@ -98,7 +98,7 @@ class PDBFixer(object):
self.topology = self.pdb.topology self.topology = self.pdb.topology
self.positions = self.pdb.positions self.positions = self.pdb.positions
self.centroid = unit.sum(self.positions)/len(self.positions) self.centroid = unit.sum(self.positions)/len(self.positions)
self._structureChains = list(self.structure.iter_chains()) self.structureChains = list(self.structure.iter_chains())
# Load the templates. # Load the templates.
...@@ -248,10 +248,10 @@ class PDBFixer(object): ...@@ -248,10 +248,10 @@ class PDBFixer(object):
modeller.delete(allChains[i] for i in chainIndices) modeller.delete(allChains[i] for i in chainIndices)
self.topology = modeller.topology self.topology = modeller.topology
self.positions = modeller.positions self.positions = modeller.positions
self._structureChains = [self._structureChains[i] for i in range(len(self._structureChains)) if i not in chainIndices] self.structureChains = [self.structureChains[i] for i in range(len(self.structureChains)) if i not in chainIndices]
def findNonstandardResidues(self): def findNonstandardResidues(self):
self.nonstandardResidues = [r for r in self.topology.residues() if r.name in substitutions] self.nonstandardResidues = [(r, substitutions[r.name]) for r in self.topology.residues() if r.name in substitutions]
def replaceNonstandardResidues(self): def replaceNonstandardResidues(self):
if len(self.nonstandardResidues) > 0: if len(self.nonstandardResidues) > 0:
...@@ -259,9 +259,9 @@ class PDBFixer(object): ...@@ -259,9 +259,9 @@ class PDBFixer(object):
# Find atoms that should be deleted. # Find atoms that should be deleted.
for residue in self.nonstandardResidues: for residue, replaceWith in self.nonstandardResidues:
residue.name = substitutions[residue.name] residue.name = replaceWith
template = self.templates[residue.name] template = self.templates[replaceWith]
standardAtoms = set(atom.name for atom in template.topology.atoms()) standardAtoms = set(atom.name for atom in template.topology.atoms())
for atom in residue.atoms(): for atom in residue.atoms():
if atom.element in (None, hydrogen) or atom.name not in standardAtoms: if atom.element in (None, hydrogen) or atom.name not in standardAtoms:
...@@ -275,7 +275,7 @@ class PDBFixer(object): ...@@ -275,7 +275,7 @@ class PDBFixer(object):
self.positions = modeller.positions self.positions = modeller.positions
def findMissingResidues(self): def findMissingResidues(self):
chains = [c for c in self._structureChains if any(atom.record_name == 'ATOM' for atom in c.iter_atoms())] chains = [c for c in self.structureChains if any(atom.record_name == 'ATOM' for atom in c.iter_atoms())]
chainWithGaps = {} chainWithGaps = {}
# Find the sequence of each chain, with gaps for missing residues. # Find the sequence of each chain, with gaps for missing residues.
...@@ -309,7 +309,7 @@ class PDBFixer(object): ...@@ -309,7 +309,7 @@ class PDBFixer(object):
# Now build the list of residues to add. # Now build the list of residues to add.
self.missingResidues = {} self.missingResidues = {}
for structChain, topChain in zip(self._structureChains, self.pdb.topology.chains()): for structChain, topChain in zip(self.structureChains, self.topology.chains()):
if structChain in chainSequence: if structChain in chainSequence:
offset = chainOffset[structChain] offset = chainOffset[structChain]
sequence = chainSequence[structChain].residues sequence = chainSequence[structChain].residues
......
...@@ -6,6 +6,10 @@ import webbrowser ...@@ -6,6 +6,10 @@ import webbrowser
import os.path import os.path
from cStringIO import StringIO from cStringIO import StringIO
proteinResidues = ['ALA', 'ASN', 'CYS', 'GLU', 'HIS', 'LEU', 'MET', 'PRO', 'THR', 'TYR', 'ARG', 'ASP', 'GLN', 'GLY', 'ILE', 'LYS', 'PHE', 'SER', 'TRP', 'VAL']
rnaResidues = ['A', 'G', 'C', 'U']
dnaResidues = ['DA', 'DG', 'DC', 'DT']
def loadHtmlFile(name): def loadHtmlFile(name):
htmlPath = os.path.join(os.path.dirname(__file__), 'html') htmlPath = os.path.join(os.path.dirname(__file__), 'html')
file = os.path.join(htmlPath, name) file = os.path.join(htmlPath, name)
...@@ -39,7 +43,9 @@ def addResiduesPageCallback(parameters, handler): ...@@ -39,7 +43,9 @@ def addResiduesPageCallback(parameters, handler):
displayMissingAtomsPage() displayMissingAtomsPage()
def convertResiduesPageCallback(parameters, handler): def convertResiduesPageCallback(parameters, handler):
fixer.nonstandardResidues = [residue for i, residue in enumerate(fixer.nonstandardResidues) if 'convert'+str(i) in parameters] for i in range(len(fixer.nonstandardResidues)):
if 'convert'+str(i) in parameters:
fixer.nonstandardResidues[i] = (fixer.nonstandardResidues[i][0], parameters.getfirst('residue'+str(i)))
fixer.replaceNonstandardResidues() fixer.replaceNonstandardResidues()
displayMissingAtomsPage() displayMissingAtomsPage()
...@@ -72,9 +78,6 @@ def displayDeleteChainsPage(): ...@@ -72,9 +78,6 @@ def displayDeleteChainsPage():
displayAddResiduesPage() displayAddResiduesPage()
return return
table = "" table = ""
proteinResidues = ['ALA', 'ASN', 'CYS', 'GLU', 'HIS', 'LEU', 'MET', 'PRO', 'THR', 'TYR.pdb ARG', 'ASP', 'GLN', 'GLY', 'ILE', 'LYS', 'PHE', 'SER', 'TRP', 'VAL']
rnaResidues = ['A', 'G', 'C', 'U']
dnaResidues = ['DA', 'DG', 'DC', 'DT']
for i, chain in enumerate(fixer.topology.chains()): for i, chain in enumerate(fixer.topology.chains()):
residues = list(r.name for r in chain.residues()) residues = list(r.name for r in chain.residues())
if any(r in proteinResidues for r in residues): if any(r in proteinResidues for r in residues):
...@@ -97,7 +100,12 @@ def displayAddResiduesPage(): ...@@ -97,7 +100,12 @@ def displayAddResiduesPage():
table = "" table = ""
for i, key in enumerate(sorted(fixer.missingResidues)): for i, key in enumerate(sorted(fixer.missingResidues)):
residues = fixer.missingResidues[key] residues = fixer.missingResidues[key]
table += ' <tr><td>%d</td><td>%d to %d</td><td>%s</td><td><input type="checkbox" name="add%d" checked></td></tr>\n' % (key[0]+1, key[1]+1, key[1]+len(residues), ', '.join(residues), i) chain = fixer.structureChains[key[0]]
if key[1] < len(chain.residues):
offset = chain.residues[key[1]].number-len(residues)-1
else:
offset = chain.residues[-1].number
table += ' <tr><td>%d</td><td>%d to %d</td><td>%s</td><td><input type="checkbox" name="add%d" checked></td></tr>\n' % (key[0]+1, offset+1, offset+len(residues), ', '.join(residues), i)
uiserver.setContent(header+loadHtmlFile("addResidues.html") % table) uiserver.setContent(header+loadHtmlFile("addResidues.html") % table)
def displayConvertResiduesPage(): def displayConvertResiduesPage():
...@@ -107,12 +115,19 @@ def displayConvertResiduesPage(): ...@@ -107,12 +115,19 @@ def displayConvertResiduesPage():
displayMissingAtomsPage() displayMissingAtomsPage()
return return
indexInChain = {} indexInChain = {}
for chain in fixer.topology.chains(): for structChain, topChain in zip(fixer.structureChains, fixer.topology.chains()):
for i, residue in enumerate(chain.residues()): for structResidue, topResidue in zip(structChain.iter_residues(), topChain.residues()):
indexInChain[residue] = i+1 indexInChain[topResidue] = structResidue.number
table = "" table = ''
for i, residue in enumerate(fixer.nonstandardResidues): for i in range(len(fixer.nonstandardResidues)):
table += ' <tr><td>%d</td><td>%s %d</td><td>%s</td><td><input type="checkbox" name="convert%d" checked></td></tr>\n' % (residue.chain.index+1, residue.name, indexInChain[residue], substitutions[residue.name], i) residue, replaceWith = fixer.nonstandardResidues[i]
options = ''
for res in proteinResidues:
selected = ''
if res == replaceWith:
selected = ' selected'
options += '<option value="%s"%s>%s</option>' % (res, selected, res)
table += ' <tr><td>%d</td><td>%s %d</td><td><select name="residue%d">%s</select></td><td><input type="checkbox" name="convert%d" checked></td></tr>\n' % (residue.chain.index+1, residue.name, indexInChain[residue], i, options, i)
uiserver.setContent(header+loadHtmlFile("convertResidues.html") % table) uiserver.setContent(header+loadHtmlFile("convertResidues.html") % table)
def displayMissingAtomsPage(): def displayMissingAtomsPage():
...@@ -124,9 +139,9 @@ def displayMissingAtomsPage(): ...@@ -124,9 +139,9 @@ def displayMissingAtomsPage():
displayAddHydrogensPage() displayAddHydrogensPage()
return return
indexInChain = {} indexInChain = {}
for chain in fixer.topology.chains(): for structChain, topChain in zip(fixer.structureChains, fixer.topology.chains()):
for i, residue in enumerate(chain.residues()): for structResidue, topResidue in zip(structChain.iter_residues(), topChain.residues()):
indexInChain[residue] = i+1 indexInChain[topResidue] = structResidue.number
table = "" table = ""
for residue in allResidues: for residue in allResidues:
atoms = [] atoms = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment