.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
pdbe.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3 PDBe (Protein Data Bank in Europe)
4"""
5
6from json import loads
7from flask_babel import gettext
8
9# about
10about = {
11 "website": 'https://www.ebi.ac.uk/pdbe',
12 "wikidata_id": 'Q55823905',
13 "official_api_documentation": 'https://www.ebi.ac.uk/pdbe/api/doc/search.html',
14 "use_official_api": True,
15 "require_api_key": False,
16 "results": 'JSON',
17}
18
19categories = ['science']
20
21hide_obsolete = False
22
23# status codes of unpublished entries
24pdb_unpublished_codes = ['HPUB', 'HOLD', 'PROC', 'WAIT', 'AUTH', 'AUCO', 'REPL', 'POLC', 'REFI', 'TRSF', 'WDRN']
25# url for api query
26pdbe_solr_url = 'https://www.ebi.ac.uk/pdbe/search/pdb/select?'
27# base url for results
28pdbe_entry_url = 'https://www.ebi.ac.uk/pdbe/entry/pdb/{pdb_id}'
29# link to preview image of structure
30pdbe_preview_url = 'https://www.ebi.ac.uk/pdbe/static/entry/{pdb_id}_deposited_chain_front_image-200x200.png'
31
32
33def request(query, params):
34
35 params['url'] = pdbe_solr_url
36 params['method'] = 'POST'
37 params['data'] = {'q': query, 'wt': "json"} # request response in parsable format
38 return params
39
40
41def construct_body(result):
42 # set title
43 title = result['title']
44
45 # construct content body
46 content = """{title} - {authors} {journal} ({volume}) {page} ({year})"""
47
48 # replace placeholders with actual content
49 try:
50 if result['journal']:
51 content = content.format(
52 title=result['citation_title'],
53 authors=result['entry_author_list'][0],
54 journal=result['journal'],
55 volume=result['journal_volume'],
56 page=result['journal_page'],
57 year=result['citation_year'],
58 )
59 else:
60 content = content.format(
61 title=result['citation_title'],
62 authors=result['entry_author_list'][0],
63 journal='',
64 volume='',
65 page='',
66 year=result['release_year'],
67 )
68 thumbnail = pdbe_preview_url.format(pdb_id=result['pdb_id'])
69 except KeyError:
70 content = None
71 thumbnail = None
72
73 # construct url for preview image
74 try:
75 thumbnail = pdbe_preview_url.format(pdb_id=result['pdb_id'])
76 except KeyError:
77 thumbnail = None
78
79 return [title, content, thumbnail]
80
81
82def response(resp):
83
84 results = []
85 json = loads(resp.text)['response']['docs']
86
87 # parse results
88 for result in json:
89 # catch obsolete entries and mark them accordingly
90 if result['status'] in pdb_unpublished_codes:
91 continue
92 if hide_obsolete:
93 continue
94 if result['status'] == 'OBS':
95 # expand title to add some sort of warning message
96 title = gettext('{title} (OBSOLETE)').format(title=result['title'])
97 try:
98 superseded_url = pdbe_entry_url.format(pdb_id=result['superseded_by'])
99 except: # pylint: disable=bare-except
100 continue
101
102 # since we can't construct a proper body from the response, we'll make up our own
103 msg_superseded = gettext("This entry has been superseded by")
104 content = '{msg_superseded}: {url} ({pdb_id})'.format(
105 msg_superseded=msg_superseded, url=superseded_url, pdb_id=result['superseded_by']
106 )
107
108 # obsoleted entries don't have preview images
109 thumbnail = None
110 else:
111 title, content, thumbnail = construct_body(result)
112
113 results.append(
114 {
115 'url': pdbe_entry_url.format(pdb_id=result['pdb_id']),
116 'title': title,
117 'content': content,
118 'thumbnail': thumbnail,
119 }
120 )
121
122 return results
construct_body(result)
Definition pdbe.py:41
response(resp)
Definition pdbe.py:82
request(query, params)
Definition pdbe.py:33