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>
<form method="post" action="/">
<table border="1" id="table">
......
......@@ -98,7 +98,7 @@ class PDBFixer(object):
self.topology = self.pdb.topology
self.positions = self.pdb.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.
......@@ -248,10 +248,10 @@ class PDBFixer(object):
modeller.delete(allChains[i] for i in chainIndices)
self.topology = modeller.topology
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):
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):
if len(self.nonstandardResidues) > 0:
......@@ -259,9 +259,9 @@ class PDBFixer(object):
# Find atoms that should be deleted.
for residue in self.nonstandardResidues:
residue.name = substitutions[residue.name]
template = self.templates[residue.name]
for residue, replaceWith in self.nonstandardResidues:
residue.name = replaceWith
template = self.templates[replaceWith]
standardAtoms = set(atom.name for atom in template.topology.atoms())
for atom in residue.atoms():
if atom.element in (None, hydrogen) or atom.name not in standardAtoms:
......@@ -275,7 +275,7 @@ class PDBFixer(object):
self.positions = modeller.positions
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 = {}
# Find the sequence of each chain, with gaps for missing residues.
......@@ -309,7 +309,7 @@ class PDBFixer(object):
# Now build the list of residues to add.
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:
offset = chainOffset[structChain]
sequence = chainSequence[structChain].residues
......
......@@ -6,6 +6,10 @@ import webbrowser
import os.path
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):
htmlPath = os.path.join(os.path.dirname(__file__), 'html')
file = os.path.join(htmlPath, name)
......@@ -39,7 +43,9 @@ def addResiduesPageCallback(parameters, handler):
displayMissingAtomsPage()
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()
displayMissingAtomsPage()
......@@ -72,9 +78,6 @@ def displayDeleteChainsPage():
displayAddResiduesPage()
return
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()):
residues = list(r.name for r in chain.residues())
if any(r in proteinResidues for r in residues):
......@@ -97,7 +100,12 @@ def displayAddResiduesPage():
table = ""
for i, key in enumerate(sorted(fixer.missingResidues)):
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)
def displayConvertResiduesPage():
......@@ -107,12 +115,19 @@ def displayConvertResiduesPage():
displayMissingAtomsPage()
return
indexInChain = {}
for chain in fixer.topology.chains():
for i, residue in enumerate(chain.residues()):
indexInChain[residue] = i+1
table = ""
for i, residue in enumerate(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)
for structChain, topChain in zip(fixer.structureChains, fixer.topology.chains()):
for structResidue, topResidue in zip(structChain.iter_residues(), topChain.residues()):
indexInChain[topResidue] = structResidue.number
table = ''
for i in range(len(fixer.nonstandardResidues)):
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)
def displayMissingAtomsPage():
......@@ -124,9 +139,9 @@ def displayMissingAtomsPage():
displayAddHydrogensPage()
return
indexInChain = {}
for chain in fixer.topology.chains():
for i, residue in enumerate(chain.residues()):
indexInChain[residue] = i+1
for structChain, topChain in zip(fixer.structureChains, fixer.topology.chains()):
for structResidue, topResidue in zip(structChain.iter_residues(), topChain.residues()):
indexInChain[topResidue] = structResidue.number
table = ""
for residue in allResidues:
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