def displayMissingAtomsPage(): uiserver.setCallback(missingAtomsPageCallback) fixer.findMissingAtoms() allResidues = list( set(fixer.missingAtoms.keys()).union(fixer.missingTerminals.keys())) allResidues.sort(key=lambda x: x.index) if len(allResidues) == 0: fixer.addMissingAtoms() displayAddHydrogensPage() return indexInChain = {} 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 = [] if residue in fixer.missingAtoms: atoms.extend(atom.name for atom in fixer.missingAtoms[residue]) if residue in fixer.missingTerminals: atoms.extend(atom for atom in fixer.missingTerminals[residue]) table += ' <tr><td>%d</td><td>%s %d</td><td>%s</td></tr>\n' % ( residue.chain.index + 1, residue.name, indexInChain[residue], ', '.join(atoms)) uiserver.setContent(header + loadHtmlFile("addHeavyAtoms.html") % table)
def launchUI(): global header header = loadHtmlFile("header.html") uiserver.beginServing() uiserver.setCallback(controlsCallback, "/controls") displayStartPage() webbrowser.open('http://localhost:'+str(uiserver.server.server_address[1]))
def displayConvertResiduesPage(): uiserver.setCallback(convertResiduesPageCallback) fixer.findNonstandardResidues() if len(fixer.nonstandardResidues) == 0: displayMissingAtomsPage() return indexInChain = {} 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 = '' nucleotides = ['DA', 'DC', 'DG', 'DT', 'A', 'C', 'G', 'T'] for i in range(len(fixer.nonstandardResidues)): residue, replaceWith = fixer.nonstandardResidues[i] if replaceWith in proteinResidues: replacements = proteinResidues else: replacements = nucleotides options = '' for res in replacements: 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 displayAddHydrogensPage(): uiserver.setCallback(addHydrogensPageCallback) dimensions = "" if fixer.topology.getUnitCellDimensions() is not None: dimensions = "<tr><td>Crystallographic unit cell:</td><td>%.3f</td><td>%.3f</td><td>%.3f</td></tr>" % fixer.topology.getUnitCellDimensions().value_in_unit(unit.nanometer) sizeRange = tuple(max((pos[i] for pos in fixer.positions))-min((pos[i] for pos in fixer.positions)) for i in range(3)) dimensions += "<tr><td>Box containing all atoms:</td><td>%.3f</td><td>%.3f</td><td>%.3f</td></tr>" % tuple(x.value_in_unit(unit.nanometer) for x in sizeRange) uiserver.setContent(header+loadHtmlFile("addHydrogens.html") % dimensions)
def launchUI(): global header header = loadHtmlFile("header.html") uiserver.beginServing() uiserver.setCallback(controlsCallback, "/controls") displayStartPage() webbrowser.open('http://localhost:' + str(uiserver.server.server_address[1]))
def displayAddResiduesPage(): uiserver.setCallback(addResiduesPageCallback) fixer.findMissingResidues() if len(fixer.missingResidues) == 0: displayConvertResiduesPage() return table = "" for i, key in enumerate(sorted(fixer.missingResidues)): residues = fixer.missingResidues[key] 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 launchUI(): global header header = loadHtmlFile("header.html") uiserver.beginServing() uiserver.setCallback(controlsCallback, "/controls") displayStartPage() url = 'http://localhost:'+str(uiserver.server.server_address[1]) print("PDBFixer running: %s " % url) webbrowser.open(url) # the uiserver is running in a background daemon thread that dies whenever # the main thread exits. So, to keep the whole process alive, we just sleep # here in the main thread. When Control-C is called, the main thread shuts # down and then the uiserver exits. Without this daemon/sleep combo, the # process cannot be killed with Control-C. Reference stack overflow link: # http://stackoverflow.com/a/11816038/1079728 while True: time.sleep(0.5)
def displayDeleteChainsPage(): uiserver.setCallback(deleteChainsPageCallback) numChains = len(list(fixer.topology.chains())) if numChains < 2: displayAddResiduesPage() return table = "" 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): content = "Protein" elif any(r in rnaResidues for r in residues): content = "RNA" elif any(r in dnaResidues for r in residues): content = "DNA" else: content = ', '.join(set(residues)) table += ' <tr><td>%d</td><td>%d</td><td>%s</td><td><input type="checkbox" name="include%d" checked></td></tr>\n' % (chain.index+1, len(residues), content, i) uiserver.setContent(header+loadHtmlFile("removeChains.html") % (numChains, table))
def launchUI(): global header header = loadHtmlFile("header.html") uiserver.beginServing() uiserver.setCallback(controlsCallback, "/controls") displayStartPage() url = 'http://localhost:' + str(uiserver.server.server_address[1]) print("PDBFixer running: %s " % url) webbrowser.open(url) # the uiserver is running in a background daemon thread that dies whenever # the main thread exits. So, to keep the whole process alive, we just sleep # here in the main thread. When Control-C is called, the main thread shuts # down and then the uiserver exits. Without this daemon/sleep combo, the # process cannot be killed with Control-C. Reference stack overflow link: # http://stackoverflow.com/a/11816038/1079728 global uiIsRunning uiIsRunning = True while uiIsRunning: time.sleep(0.5)
def displayMissingAtomsPage(): uiserver.setCallback(missingAtomsPageCallback) fixer.findMissingAtoms() allResidues = list(set(fixer.missingAtoms.keys()).union(fixer.missingTerminals.keys())) allResidues.sort(key=lambda x: x.index) if len(allResidues) == 0: fixer.addMissingAtoms() displayAddHydrogensPage() return indexInChain = {} 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 = [] if residue in fixer.missingAtoms: atoms.extend(atom.name for atom in fixer.missingAtoms[residue]) if residue in fixer.missingTerminals: atoms.extend(atom for atom in fixer.missingTerminals[residue]) table += ' <tr><td>%d</td><td>%s %d</td><td>%s</td></tr>\n' % (residue.chain.index+1, residue.name, indexInChain[residue], ', '.join(atoms)) uiserver.setContent(header+loadHtmlFile("addHeavyAtoms.html") % table)
def displayStartPage(): uiserver.setCallback(startPageCallback) uiserver.setContent(header+loadHtmlFile("start.html"))
def displaySaveFilePage(): uiserver.setCallback(saveFilePageCallback) uiserver.setContent(header+loadHtmlFile("saveFile.html"))