Commit 93663581 by John Chodera (MSKCC)

Merge remote-tracking branch 'upstream/master'

parents 94084151 db272571
language: c language: c
env:
matrix:
- CONDA_PY=2.7
- CONDA_PY=3.3
- CONDA_PY=3.4
install: install:
- sudo apt-get update -qq - sudo apt-get update -qq
- sudo apt-get install -qq python-dev python-pip python-yaml g++ ftp - sudo apt-get install -qq python-dev python-pip python-yaml g++ ftp
- sudo pip install conda eventlet - sudo pip install conda eventlet
- sudo conda init - sudo conda init
- conda config --add channels http://conda.binstar.org/omnia - conda config --add channels http://conda.binstar.org/omnia
- conda create --yes --name test nose setuptools numpy biopython pyflakes openmm - conda create --yes --name test nose setuptools numpy biopython pyflakes openmm-dev
- export PATH="$HOME/envs/test/bin/:$PATH" - export PATH="$HOME/envs/test/bin/:$PATH"
script: script:
......
from pdbfixer import PDBFixer from __future__ import absolute_import
from .pdbfixer import PDBFixer
...@@ -6,7 +6,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of ...@@ -6,7 +6,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of
Biological Structures at Stanford, funded under the NIH Roadmap for Biological Structures at Stanford, funded under the NIH Roadmap for
Medical Research, grant U54 GM072970. See https://simtk.org. Medical Research, grant U54 GM072970. See https://simtk.org.
Portions copyright (c) 2013-2014 Stanford University and the Authors. Portions copyright (c) 2013-2015 Stanford University and the Authors.
Authors: Peter Eastman Authors: Peter Eastman
Contributors: Contributors:
...@@ -28,6 +28,7 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR ...@@ -28,6 +28,7 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE. USE OR OTHER DEALINGS IN THE SOFTWARE.
""" """
from __future__ import absolute_import
__author__ = "Peter Eastman" __author__ = "Peter Eastman"
__version__ = "1.1" __version__ = "1.1"
...@@ -207,7 +208,7 @@ class PDBFixer(object): ...@@ -207,7 +208,7 @@ class PDBFixer(object):
self.source = url self.source = url
file = urlopen(url) file = urlopen(url)
# Read contents all at once and split into lines, since urlopen doesn't like it when we read one line at a time over the network. # Read contents all at once and split into lines, since urlopen doesn't like it when we read one line at a time over the network.
contents = file.read() contents = file.read().decode('utf-8')
lines = contents.split('\n') lines = contents.split('\n')
file.close() file.close()
structure = PdbStructure(lines) structure = PdbStructure(lines)
...@@ -221,7 +222,6 @@ class PDBFixer(object): ...@@ -221,7 +222,6 @@ class PDBFixer(object):
self.pdb = app.PDBFile(structure) self.pdb = app.PDBFile(structure)
self.topology = self.pdb.topology self.topology = self.pdb.topology
self.positions = self.pdb.positions self.positions = self.pdb.positions
self.structureChains = list(self.structure.iter_chains())
# Load the templates. # Load the templates.
...@@ -462,7 +462,6 @@ class PDBFixer(object): ...@@ -462,7 +462,6 @@ 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]
return return
...@@ -481,17 +480,17 @@ class PDBFixer(object): ...@@ -481,17 +480,17 @@ class PDBFixer(object):
>>> missing_residues = fixer.missingResidues >>> missing_residues = fixer.missingResidues
""" """
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.topology.chains() if len(list(c.residues())) > 0]
chainWithGaps = {} chainWithGaps = {}
# Find the sequence of each chain, with gaps for missing residues. # Find the sequence of each chain, with gaps for missing residues.
for chain in chains: for chain in chains:
minResidue = min(r.number for r in chain.iter_residues()) minResidue = min(int(r.id) for r in chain.residues())
maxResidue = max(r.number for r in chain.iter_residues()) maxResidue = max(int(r.id) for r in chain.residues())
residues = [None]*(maxResidue-minResidue+1) residues = [None]*(maxResidue-minResidue+1)
for r in chain.iter_residues(): for r in chain.residues():
residues[r.number-minResidue] = r.get_name() residues[int(r.id)-minResidue] = r.name
chainWithGaps[chain] = residues chainWithGaps[chain] = residues
# Try to find the chain that matches each sequence. # Try to find the chain that matches each sequence.
...@@ -500,7 +499,7 @@ class PDBFixer(object): ...@@ -500,7 +499,7 @@ class PDBFixer(object):
chainOffset = {} chainOffset = {}
for sequence in self.structure.sequences: for sequence in self.structure.sequences:
for chain in chains: for chain in chains:
if chain.chain_id != sequence.chain_id: if chain.id != sequence.chain_id:
continue continue
if chain in chainSequence: if chain in chainSequence:
continue continue
...@@ -515,15 +514,15 @@ class PDBFixer(object): ...@@ -515,15 +514,15 @@ 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.topology.chains()): for chain in self.topology.chains():
if structChain in chainSequence: if chain in chainSequence:
offset = chainOffset[structChain] offset = chainOffset[chain]
sequence = chainSequence[structChain].residues sequence = chainSequence[chain].residues
gappedSequence = chainWithGaps[structChain] gappedSequence = chainWithGaps[chain]
index = 0 index = 0
for i in range(len(sequence)): for i in range(len(sequence)):
if i < offset or i >= len(gappedSequence)+offset or gappedSequence[i-offset] is None: if i < offset or i >= len(gappedSequence)+offset or gappedSequence[i-offset] is None:
key = (topChain.index, index) key = (chain.index, index)
if key not in self.missingResidues: if key not in self.missingResidues:
self.missingResidues[key] = [] self.missingResidues[key] = []
residueName = sequence[i] residueName = sequence[i]
...@@ -556,16 +555,16 @@ class PDBFixer(object): ...@@ -556,16 +555,16 @@ class PDBFixer(object):
# Now add ones based on MODRES records. # Now add ones based on MODRES records.
modres = dict(((m.chain_id, m.number, m.residue_name), m.standard_name) for m in self.structure.modified_residues) modres = dict(((m.chain_id, str(m.number), m.residue_name), m.standard_name) for m in self.structure.modified_residues)
for structChain, topChain in zip(self.structureChains, self.topology.chains()): for chain in self.topology.chains():
for structResidue, topResidue in zip(structChain.iter_residues(), topChain.residues()): for residue in chain.residues():
key = (structChain.chain_id, structResidue.number, structResidue.name) key = (chain.id, residue.id, residue.name)
if key in modres: if key in modres:
replacement = modres[key] replacement = modres[key]
if replacement == 'DU': if replacement == 'DU':
replacement = 'DT' replacement = 'DT'
if replacement in self.templates: if replacement in self.templates:
nonstandard[topResidue] = replacement nonstandard[residue] = replacement
self.nonstandardResidues = [(r, nonstandard[r]) for r in sorted(nonstandard, key=lambda r: r.index)] self.nonstandardResidues = [(r, nonstandard[r]) for r in sorted(nonstandard, key=lambda r: r.index)]
def replaceNonstandardResidues(self): def replaceNonstandardResidues(self):
...@@ -1027,8 +1026,7 @@ class PDBFixer(object): ...@@ -1027,8 +1026,7 @@ class PDBFixer(object):
def main(): def main():
if len(sys.argv) < 2: if len(sys.argv) < 2:
# Display the UI. # Display the UI.
from . import ui
import ui
ui.launchUI() ui.launchUI()
else: else:
# Run in command line mode. # Run in command line mode.
......
import simtk.openmm.app as app from __future__ import absolute_import
from simtk.openmm.app.internal.pdbstructure import PdbStructure
import simtk.unit as unit
from pdbfixer import PDBFixer, substitutions, proteinResidues, dnaResidues, rnaResidues
import uiserver
import webbrowser import webbrowser
import os.path import os.path
import gzip
import time import time
from io import BytesIO
import simtk.openmm.app as app
import simtk.unit as unit
from .pdbfixer import PDBFixer, proteinResidues, dnaResidues, rnaResidues
from . import uiserver
try: try:
from urllib.request import urlopen from urllib.request import urlopen
from io import StringIO from io import StringIO
...@@ -27,7 +29,7 @@ def loadImageFile(name): ...@@ -27,7 +29,7 @@ def loadImageFile(name):
if name not in cachedImages: if name not in cachedImages:
imagePath = os.path.join(os.path.dirname(__file__), 'images') imagePath = os.path.join(os.path.dirname(__file__), 'images')
file = os.path.join(imagePath, name) file = os.path.join(imagePath, name)
cachedImages[name] = open(file).read() cachedImages[name] = open(file, 'rb').read()
return cachedImages[name] return cachedImages[name]
def controlsCallback(parameters, handler): def controlsCallback(parameters, handler):
...@@ -53,13 +55,21 @@ def startPageCallback(parameters, handler): ...@@ -53,13 +55,21 @@ def startPageCallback(parameters, handler):
global fixer global fixer
if 'type' in parameters: if 'type' in parameters:
if parameters.getfirst('type') == 'local': if parameters.getfirst('type') == 'local':
fixer = PDBFixer(file=parameters['pdbfile'].value.decode().splitlines()) fixer = PDBFixer(pdbfile=parameters['pdbfile'].value.decode().splitlines())
fixer.source = parameters['pdbfile'].filename
else: else:
id = parameters.getfirst('pdbid') id = parameters.getfirst('pdbid')
try: try:
fixer = PDBFixer(pdbid=id) fixer = PDBFixer(pdbid=id)
except: except Exception as e:
handler.sendResponse(header+"Unable to download the PDB file. This may indicate an invalid PDB identifier, or an error in network connectivity."+loadHtmlFile("error.html")) import traceback
print(traceback.format_exc())
handler.sendResponse(
header + "<p>Unable to download the PDB file. " +
"This may indicate an invalid PDB identifier, " +
"or an error in network connectivity.</p>" +
"<p>{}</p>".format(e) +
loadHtmlFile("error.html"))
displayDeleteChainsPage() displayDeleteChainsPage()
def deleteChainsPageCallback(parameters, handler): def deleteChainsPageCallback(parameters, handler):
...@@ -73,7 +83,7 @@ def addResiduesPageCallback(parameters, handler): ...@@ -73,7 +83,7 @@ def addResiduesPageCallback(parameters, handler):
for i, key in enumerate(keys): for i, key in enumerate(keys):
if 'add'+str(i) not in parameters: if 'add'+str(i) not in parameters:
del fixer.missingResidues[key] del fixer.missingResidues[key]
displayMissingAtomsPage() displayConvertResiduesPage()
def convertResiduesPageCallback(parameters, handler): def convertResiduesPageCallback(parameters, handler):
for i in range(len(fixer.nonstandardResidues)): for i in range(len(fixer.nonstandardResidues)):
...@@ -134,7 +144,7 @@ def displayDeleteChainsPage(): ...@@ -134,7 +144,7 @@ def displayDeleteChainsPage():
content = "DNA" content = "DNA"
else: else:
content = ', '.join(set(residues)) 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) table += ' <tr><td>%s</td><td>%d</td><td>%s</td><td><input type="checkbox" name="include%d" checked></td></tr>\n' % (chain.id, len(residues), content, i)
uiserver.setContent(header+loadHtmlFile("removeChains.html") % (numChains, table)) uiserver.setContent(header+loadHtmlFile("removeChains.html") % (numChains, table))
def displayAddResiduesPage(): def displayAddResiduesPage():
...@@ -144,14 +154,16 @@ def displayAddResiduesPage(): ...@@ -144,14 +154,16 @@ def displayAddResiduesPage():
displayConvertResiduesPage() displayConvertResiduesPage()
return return
table = "" table = ""
chains = list(fixer.topology.chains())
for i, key in enumerate(sorted(fixer.missingResidues)): for i, key in enumerate(sorted(fixer.missingResidues)):
residues = fixer.missingResidues[key] residues = fixer.missingResidues[key]
chain = fixer.structureChains[key[0]] chain = chains[key[0]]
if key[1] < len(chain.residues): chainResidues = list(chain.residues())
offset = chain.residues[key[1]].number-len(residues)-1 if key[1] < len(chainResidues):
offset = int(chainResidues[key[1]].id)-len(residues)-1
else: else:
offset = chain.residues[-1].number offset = int(chainResidues[-1].id)
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) table += ' <tr><td>%s</td><td>%d to %d</td><td>%s</td><td><input type="checkbox" name="add%d" checked></td></tr>\n' % (chain.id, 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():
...@@ -160,10 +172,6 @@ def displayConvertResiduesPage(): ...@@ -160,10 +172,6 @@ def displayConvertResiduesPage():
if len(fixer.nonstandardResidues) == 0: if len(fixer.nonstandardResidues) == 0:
displayMissingAtomsPage() displayMissingAtomsPage()
return 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 = '' table = ''
nucleotides = ['DA', 'DC', 'DG', 'DT', 'A', 'C', 'G', 'T'] nucleotides = ['DA', 'DC', 'DG', 'DT', 'A', 'C', 'G', 'T']
for i in range(len(fixer.nonstandardResidues)): for i in range(len(fixer.nonstandardResidues)):
...@@ -178,7 +186,7 @@ def displayConvertResiduesPage(): ...@@ -178,7 +186,7 @@ def displayConvertResiduesPage():
if res == replaceWith: if res == replaceWith:
selected = ' selected' selected = ' selected'
options += '<option value="%s"%s>%s</option>' % (res, selected, res) 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) table += ' <tr><td>%s</td><td>%s %s</td><td><select name="residue%d">%s</select></td><td><input type="checkbox" name="convert%d" checked></td></tr>\n' % (residue.chain.id, residue.name, residue.id, i, options, i)
uiserver.setContent(header+loadHtmlFile("convertResidues.html") % table) uiserver.setContent(header+loadHtmlFile("convertResidues.html") % table)
def displayMissingAtomsPage(): def displayMissingAtomsPage():
...@@ -190,10 +198,6 @@ def displayMissingAtomsPage(): ...@@ -190,10 +198,6 @@ def displayMissingAtomsPage():
fixer.addMissingAtoms() fixer.addMissingAtoms()
displayAddHydrogensPage() displayAddHydrogensPage()
return 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 = "" table = ""
for residue in allResidues: for residue in allResidues:
atoms = [] atoms = []
...@@ -201,7 +205,7 @@ def displayMissingAtomsPage(): ...@@ -201,7 +205,7 @@ def displayMissingAtomsPage():
atoms.extend(atom.name for atom in fixer.missingAtoms[residue]) atoms.extend(atom.name for atom in fixer.missingAtoms[residue])
if residue in fixer.missingTerminals: if residue in fixer.missingTerminals:
atoms.extend(atom for atom in fixer.missingTerminals[residue]) 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)) table += ' <tr><td>%s</td><td>%s %s</td><td>%s</td></tr>\n' % (residue.chain.id, residue.name, residue.id, ', '.join(atoms))
uiserver.setContent(header+loadHtmlFile("addHeavyAtoms.html") % table) uiserver.setContent(header+loadHtmlFile("addHeavyAtoms.html") % table)
def displayAddHydrogensPage(): def displayAddHydrogensPage():
......
...@@ -46,7 +46,7 @@ class _Handler(BaseHTTPRequestHandler): ...@@ -46,7 +46,7 @@ class _Handler(BaseHTTPRequestHandler):
self.send_header("Content-type", type) self.send_header("Content-type", type)
self.send_header("Content-length", str(len(response))) self.send_header("Content-length", str(len(response)))
self.end_headers() self.end_headers()
if sys.version_info.major > 2: if sys.version_info.major > 2 and isinstance(response, str):
response = bytes(response, 'UTF-8') response = bytes(response, 'UTF-8')
self.wfile.write(response) self.wfile.write(response)
......
from __future__ import print_function
import pdbfixer import pdbfixer
import simtk.openmm import simtk.openmm
...@@ -79,7 +80,7 @@ def simulate(pdbcode, pdb_filename): ...@@ -79,7 +80,7 @@ def simulate(pdbcode, pdb_filename):
del context, integrator del context, integrator
print "Simulation completed: potential = %.3f kcal/mol" % potential print("Simulation completed: potential = %.3f kcal/mol" % potential)
return return
...@@ -105,8 +106,8 @@ def test_build_and_simulate(): ...@@ -105,8 +106,8 @@ def test_build_and_simulate():
failures = list() failures = list()
for pdbcode in pdbcodes_to_build: for pdbcode in pdbcodes_to_build:
print "------------------------------------------------" print("------------------------------------------------")
print pdbcode print(pdbcode)
output_pdb_filename = 'output.pdb' output_pdb_filename = 'output.pdb'
...@@ -152,14 +153,14 @@ def test_build_and_simulate(): ...@@ -152,14 +153,14 @@ def test_build_and_simulate():
except Watchdog: except Watchdog:
message = "timed out in stage %s" % stage message = "timed out in stage %s" % stage
print message print(message)
failures.append((pdbcode, Exception(message))) failures.append((pdbcode, Exception(message)))
except Exception as e: except Exception as e:
print "EXCEPTION DURING BUILD" print("EXCEPTION DURING BUILD")
#import traceback #import traceback
#print traceback.print_exc() #print traceback.print_exc()
print str(e) print(str(e))
failures.append((pdbcode, e)) failures.append((pdbcode, e))
watchdog.stop() watchdog.stop()
...@@ -173,14 +174,14 @@ def test_build_and_simulate(): ...@@ -173,14 +174,14 @@ def test_build_and_simulate():
except Watchdog: except Watchdog:
message = "timed out in simulation" message = "timed out in simulation"
print message print(message)
failures.append((pdbcode, Exception(message))) failures.append((pdbcode, Exception(message)))
except Exception as e: except Exception as e:
print "EXCEPTION DURING SIMULATE" print("EXCEPTION DURING SIMULATE")
#import traceback #import traceback
#print traceback.print_exc() #print traceback.print_exc()
print str(e) print(str(e))
failures.append((pdbcode, e)) failures.append((pdbcode, e))
watchdog.stop() watchdog.stop()
...@@ -189,21 +190,21 @@ def test_build_and_simulate(): ...@@ -189,21 +190,21 @@ def test_build_and_simulate():
# Clean up. # Clean up.
os.remove(output_pdb_filename) os.remove(output_pdb_filename)
print "------------------------------------------------" print("------------------------------------------------")
if len(failures) != 0: if len(failures) != 0:
print "" print("")
print "SUMMARY OF FAILURES:" print("SUMMARY OF FAILURES:")
print "" print("")
for failure in failures: for failure in failures:
(pdbcode, exception) = failure (pdbcode, exception) = failure
print "%6s : %s" % (pdbcode, str(exception)) print("%6s : %s" % (pdbcode, str(exception)))
print "" print("")
raise Exception("Build test failed on one or more PDB files.") raise Exception("Build test failed on one or more PDB files.")
else: else:
print "All tests succeeded." print("All tests succeeded.")
if __name__ == '__main__': if __name__ == '__main__':
test_build_and_simulate() test_build_and_simulate()
...@@ -9,7 +9,7 @@ def remove_chain_ids_and_verify(pdbid, chain_ids_to_remove, expected_chain_ids_r ...@@ -9,7 +9,7 @@ def remove_chain_ids_and_verify(pdbid, chain_ids_to_remove, expected_chain_ids_r
# Remove specified chains. # Remove specified chains.
fixer.removeChains(chainIds=chain_ids_to_remove) fixer.removeChains(chainIds=chain_ids_to_remove)
# Check to make sure asserted chains remain. # Check to make sure asserted chains remain.
chain_ids_remaining = [c.chain_id for c in fixer.structureChains] chain_ids_remaining = [c.id for c in fixer.topology.chains()]
assert_items_equal(chain_ids_remaining, expected_chain_ids_remaining) assert_items_equal(chain_ids_remaining, expected_chain_ids_remaining)
def test_removechain_ids(): def test_removechain_ids():
...@@ -25,7 +25,7 @@ def remove_chain_indices_and_verify(pdbid, chain_indices_to_remove, expected_cha ...@@ -25,7 +25,7 @@ def remove_chain_indices_and_verify(pdbid, chain_indices_to_remove, expected_cha
# Remove specified chains. # Remove specified chains.
fixer.removeChains(chainIndices=chain_indices_to_remove) fixer.removeChains(chainIndices=chain_indices_to_remove)
# Check to make sure asserted chains remain. # Check to make sure asserted chains remain.
chain_ids_remaining = [c.chain_id for c in fixer.structureChains] chain_ids_remaining = [c.id for c in fixer.topology.chains()]
assert_items_equal(chain_ids_remaining, expected_chain_ids_remaining) assert_items_equal(chain_ids_remaining, expected_chain_ids_remaining)
def test_removechain_indices(): def test_removechain_indices():
......
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