Commit 39f81e3b by peastman

Merge branch 'master' of https://github.com/SimTk/pdbfixer

Conflicts:
	pdbfixer/ui.py
parents 4ea8b0bf 06591a81
language: c
env:
matrix:
- CONDA_PY=2.7
- CONDA_PY=3.3
- CONDA_PY=3.4
install:
- sudo apt-get update -qq
- sudo apt-get install -qq python-dev python-pip python-yaml g++ ftp
......
from pdbfixer import PDBFixer
from __future__ import absolute_import
from .pdbfixer import PDBFixer
......@@ -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
USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from __future__ import absolute_import
__author__ = "Peter Eastman"
__version__ = "1.1"
......@@ -207,7 +208,7 @@ class PDBFixer(object):
self.source = 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.
contents = file.read()
contents = file.read().decode('utf-8')
lines = contents.split('\n')
file.close()
structure = PdbStructure(lines)
......@@ -1025,8 +1026,7 @@ class PDBFixer(object):
def main():
if len(sys.argv) < 2:
# Display the UI.
import ui
from . import ui
ui.launchUI()
else:
# Run in command line mode.
......
import simtk.openmm.app as app
import simtk.unit as unit
from pdbfixer import PDBFixer, substitutions, proteinResidues, dnaResidues, rnaResidues
import uiserver
from __future__ import absolute_import
import webbrowser
import os.path
import gzip
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:
from urllib.request import urlopen
from io import StringIO
......@@ -26,7 +29,7 @@ def loadImageFile(name):
if name not in cachedImages:
imagePath = os.path.join(os.path.dirname(__file__), 'images')
file = os.path.join(imagePath, name)
cachedImages[name] = open(file).read()
cachedImages[name] = open(file, 'rb').read()
return cachedImages[name]
def controlsCallback(parameters, handler):
......@@ -58,8 +61,15 @@ def startPageCallback(parameters, handler):
id = parameters.getfirst('pdbid')
try:
fixer = PDBFixer(pdbid=id)
except:
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"))
except Exception as e:
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()
def deleteChainsPageCallback(parameters, handler):
......
......@@ -46,7 +46,7 @@ class _Handler(BaseHTTPRequestHandler):
self.send_header("Content-type", type)
self.send_header("Content-length", str(len(response)))
self.end_headers()
if sys.version_info.major > 2:
if sys.version_info.major > 2 and isinstance(response, str):
response = bytes(response, 'UTF-8')
self.wfile.write(response)
......
from __future__ import print_function
import pdbfixer
import simtk.openmm
......@@ -79,7 +80,7 @@ def simulate(pdbcode, pdb_filename):
del context, integrator
print "Simulation completed: potential = %.3f kcal/mol" % potential
print("Simulation completed: potential = %.3f kcal/mol" % potential)
return
......@@ -105,8 +106,8 @@ def test_build_and_simulate():
failures = list()
for pdbcode in pdbcodes_to_build:
print "------------------------------------------------"
print pdbcode
print("------------------------------------------------")
print(pdbcode)
output_pdb_filename = 'output.pdb'
......@@ -152,14 +153,14 @@ def test_build_and_simulate():
except Watchdog:
message = "timed out in stage %s" % stage
print message
print(message)
failures.append((pdbcode, Exception(message)))
except Exception as e:
print "EXCEPTION DURING BUILD"
print("EXCEPTION DURING BUILD")
#import traceback
#print traceback.print_exc()
print str(e)
print(str(e))
failures.append((pdbcode, e))
watchdog.stop()
......@@ -173,14 +174,14 @@ def test_build_and_simulate():
except Watchdog:
message = "timed out in simulation"
print message
print(message)
failures.append((pdbcode, Exception(message)))
except Exception as e:
print "EXCEPTION DURING SIMULATE"
print("EXCEPTION DURING SIMULATE")
#import traceback
#print traceback.print_exc()
print str(e)
print(str(e))
failures.append((pdbcode, e))
watchdog.stop()
......@@ -189,21 +190,21 @@ def test_build_and_simulate():
# Clean up.
os.remove(output_pdb_filename)
print "------------------------------------------------"
print("------------------------------------------------")
if len(failures) != 0:
print ""
print "SUMMARY OF FAILURES:"
print ""
print("")
print("SUMMARY OF FAILURES:")
print("")
for failure in failures:
(pdbcode, exception) = failure
print "%6s : %s" % (pdbcode, str(exception))
print ""
print("%6s : %s" % (pdbcode, str(exception)))
print("")
raise Exception("Build test failed on one or more PDB files.")
else:
print "All tests succeeded."
print("All tests succeeded.")
if __name__ == '__main__':
test_build_and_simulate()
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