Skip to content

Commit

Permalink
Use new EMDB API
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Sep 14, 2023
1 parent 33115a9 commit d3bfbf1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
13 changes: 7 additions & 6 deletions ihm/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _get_emdb_info(self):
if self.__emdb_info is not None:
return
req = urllib.request.Request(
'https://www.ebi.ac.uk/pdbe/api/emdb/entry/summary/%s'
'https://www.ebi.ac.uk/emdb/api/entry/admin/%s'
% self.access_code, None, {})
try:
response = urllib.request.urlopen(req, timeout=10)
Expand All @@ -135,15 +135,16 @@ def _get_emdb_info(self):
self.__emdb_info = [None, None]
return
contents = json.load(response)
keys = list(contents.keys())
info = contents[keys[0]][0]['deposition']
info = contents['admin']
# JSON values are always Unicode, but on Python 2 we want non-Unicode
# strings, so convert to ASCII
if sys.version_info[0] < 3: # pragma: no cover
self.__emdb_info = [info['map_release_date'].encode('ascii'),
info['title'].encode('ascii')]
self.__emdb_info = [
info['key_dates']['map_release'].encode('ascii'),
info['title'].encode('ascii')]
else:
self.__emdb_info = [info['map_release_date'], info['title']]
self.__emdb_info = [info['key_dates']['map_release'],
info['title']]

version = property(__get_version, __set_version)
details = property(__get_details, __set_details)
Expand Down
7 changes: 3 additions & 4 deletions test/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ def test_mrc_parser_local_mrc(self):
def test_mrc_parser_emdb_ok(self):
"""Test MRCParser pointing to an MRC in EMDB, no network errors"""
def mock_urlopen(url, timeout=None):
txt = ('{"EMD-1883":[{"deposition":'
'{"map_release_date":"2011-04-21",'
'"title":"test details"}}]}')
return StringIO(txt)
return StringIO(
'{"admin": {"key_dates": {"map_release": "2011-04-21"},'
'"title": "test details"}}')
p = ihm.metadata.MRCParser()
fname = utils.get_input_file_name(TOPDIR, 'emd_1883.map.mrc-header')
d = p.parse_file(fname)
Expand Down

0 comments on commit d3bfbf1

Please sign in to comment.