Skip to content

Commit ef1f73e

Browse files
committed
PdbDownloader().download() now downloads in binary rather than text (since text files are just binary files with special encoding
1 parent cc4398f commit ef1f73e

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

package/MDAnalysis/web/downloaders.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _open_file(self, cache_path):
6868

6969
# create temporary file to save pdb file
7070
if cache_path is None:
71-
self._file = tempfile.NamedTemporaryFile(mode='w+t')
71+
self._file = tempfile.NamedTemporaryFile(mode='wb')
7272
self._download = True
7373

7474
# Create/Parse download cache
@@ -77,11 +77,11 @@ def _open_file(self, cache_path):
7777

7878
# Found Cache, so don't download anything and open existing file
7979
if named_file_path.exists() and named_file_path.is_file():
80-
self._file = open(named_file_path,"r")
80+
self._file = open(named_file_path, 'r')
8181
self._download = False
8282

8383
else: # No cache found, so create Cache
84-
self._file = open(named_file_path, 'w+t')
84+
self._file = open(named_file_path, 'wb')
8585
self._download = True
8686

8787

@@ -97,7 +97,7 @@ def download(self, cache_path=None, timeout=None):
9797
r = requests.get(f"https://files.rcsb.org/download/{self.id}.{self.file_format}",
9898
timeout=timeout)
9999
r.raise_for_status()
100-
self._file.write(r.text)
100+
self._file.write(r.content)
101101
except requests.HTTPError:
102102
# This also deletes the undownloaded file since write() hasn't been called yet
103103
raise FileDownloadPDBError

testsuite/MDAnalysisTests/web/test_web.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import MDAnalysis as mda
22
import filecmp
33

4-
54
import pytest
65
import requests
76

8-
9-
107
working_PDB_ID = '1DPX' # egg white lysozyme
118
file_format = "pdb"
129

0 commit comments

Comments
 (0)