2021-01-13 11:31:25 +01:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2016-09-13 00:53:53 +02:00
|
|
|
"""
|
|
|
|
PDBe (Protein Data Bank in Europe)
|
|
|
|
"""
|
|
|
|
|
|
|
|
from json import loads
|
|
|
|
from flask_babel import gettext
|
|
|
|
|
2021-01-13 11:31:25 +01:00
|
|
|
# about
|
|
|
|
about = {
|
|
|
|
"website": 'https://www.ebi.ac.uk/pdbe',
|
|
|
|
"wikidata_id": 'Q55823905',
|
|
|
|
"official_api_documentation": 'https://www.ebi.ac.uk/pdbe/api/doc/search.html',
|
|
|
|
"use_official_api": True,
|
|
|
|
"require_api_key": False,
|
|
|
|
"results": 'JSON',
|
|
|
|
}
|
|
|
|
|
2016-09-13 00:53:53 +02:00
|
|
|
categories = ['science']
|
|
|
|
|
|
|
|
hide_obsolete = False
|
|
|
|
|
|
|
|
# status codes of unpublished entries
|
|
|
|
pdb_unpublished_codes = ['HPUB', 'HOLD', 'PROC', 'WAIT', 'AUTH', 'AUCO', 'REPL', 'POLC', 'REFI', 'TRSF', 'WDRN']
|
|
|
|
# url for api query
|
|
|
|
pdbe_solr_url = 'https://www.ebi.ac.uk/pdbe/search/pdb/select?'
|
|
|
|
# base url for results
|
|
|
|
pdbe_entry_url = 'https://www.ebi.ac.uk/pdbe/entry/pdb/{pdb_id}'
|
|
|
|
# link to preview image of structure
|
|
|
|
pdbe_preview_url = 'https://www.ebi.ac.uk/pdbe/static/entry/{pdb_id}_deposited_chain_front_image-200x200.png'
|
|
|
|
|
|
|
|
|
|
|
|
def request(query, params):
|
|
|
|
|
|
|
|
params['url'] = pdbe_solr_url
|
|
|
|
params['method'] = 'POST'
|
2021-12-27 09:26:22 +01:00
|
|
|
params['data'] = {'q': query, 'wt': "json"} # request response in parsable format
|
2016-09-13 00:53:53 +02:00
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
def construct_body(result):
|
|
|
|
# set title
|
|
|
|
title = result['title']
|
|
|
|
|
|
|
|
# construct content body
|
2017-12-01 20:46:28 +01:00
|
|
|
content = """{title} - {authors} {journal} ({volume}) {page} ({year})"""
|
2016-09-13 00:53:53 +02:00
|
|
|
|
|
|
|
# replace placeholders with actual content
|
|
|
|
try:
|
|
|
|
if result['journal']:
|
|
|
|
content = content.format(
|
|
|
|
title=result['citation_title'],
|
2021-12-27 09:26:22 +01:00
|
|
|
authors=result['entry_author_list'][0],
|
|
|
|
journal=result['journal'],
|
|
|
|
volume=result['journal_volume'],
|
|
|
|
page=result['journal_page'],
|
|
|
|
year=result['citation_year'],
|
|
|
|
)
|
2016-09-13 00:53:53 +02:00
|
|
|
else:
|
|
|
|
content = content.format(
|
|
|
|
title=result['citation_title'],
|
2021-12-27 09:26:22 +01:00
|
|
|
authors=result['entry_author_list'][0],
|
|
|
|
journal='',
|
|
|
|
volume='',
|
|
|
|
page='',
|
|
|
|
year=result['release_year'],
|
|
|
|
)
|
2016-09-13 00:53:53 +02:00
|
|
|
img_src = pdbe_preview_url.format(pdb_id=result['pdb_id'])
|
2024-03-08 18:22:31 +01:00
|
|
|
except KeyError:
|
2016-09-13 00:53:53 +02:00
|
|
|
content = None
|
|
|
|
img_src = None
|
|
|
|
|
|
|
|
# construct url for preview image
|
|
|
|
try:
|
|
|
|
img_src = pdbe_preview_url.format(pdb_id=result['pdb_id'])
|
2024-03-08 18:22:31 +01:00
|
|
|
except KeyError:
|
2016-09-13 00:53:53 +02:00
|
|
|
img_src = None
|
|
|
|
|
|
|
|
return [title, content, img_src]
|
|
|
|
|
|
|
|
|
|
|
|
def response(resp):
|
|
|
|
|
|
|
|
results = []
|
|
|
|
json = loads(resp.text)['response']['docs']
|
|
|
|
|
|
|
|
# parse results
|
|
|
|
for result in json:
|
|
|
|
# catch obsolete entries and mark them accordingly
|
|
|
|
if result['status'] in pdb_unpublished_codes:
|
|
|
|
continue
|
|
|
|
if hide_obsolete:
|
|
|
|
continue
|
|
|
|
if result['status'] == 'OBS':
|
|
|
|
# expand title to add some sort of warning message
|
2017-12-01 20:46:28 +01:00
|
|
|
title = gettext('{title} (OBSOLETE)').format(title=result['title'])
|
|
|
|
try:
|
|
|
|
superseded_url = pdbe_entry_url.format(pdb_id=result['superseded_by'])
|
|
|
|
except:
|
|
|
|
continue
|
2016-09-13 00:53:53 +02:00
|
|
|
|
|
|
|
# since we can't construct a proper body from the response, we'll make up our own
|
|
|
|
msg_superseded = gettext("This entry has been superseded by")
|
2017-12-01 20:46:28 +01:00
|
|
|
content = '{msg_superseded}: {url} ({pdb_id})'.format(
|
2021-12-27 09:26:22 +01:00
|
|
|
msg_superseded=msg_superseded, url=superseded_url, pdb_id=result['superseded_by']
|
|
|
|
)
|
2016-09-13 00:53:53 +02:00
|
|
|
|
|
|
|
# obsoleted entries don't have preview images
|
|
|
|
img_src = None
|
|
|
|
else:
|
|
|
|
title, content, img_src = construct_body(result)
|
|
|
|
|
2021-12-27 09:26:22 +01:00
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
'url': pdbe_entry_url.format(pdb_id=result['pdb_id']),
|
|
|
|
'title': title,
|
|
|
|
'content': content,
|
|
|
|
'img_src': img_src,
|
|
|
|
}
|
|
|
|
)
|
2016-09-13 00:53:53 +02:00
|
|
|
|
|
|
|
return results
|