-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.py
More file actions
80 lines (66 loc) · 2.24 KB
/
Copy pathio.py
File metadata and controls
80 lines (66 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import requests
import pandas as pd
from datetime import datetime
def download_metadata_from_RCSB(pdb_id):
"""(GPT generated docstring! Code written by hand)
Download and extract selected metadata for a protein
structure from the RCSB PDB.
Parameters
----------
pdb_id : str
The four-character Protein Data Bank identifier for the
structure of interest,
such as "3F3A".
Returns
-------
dict
A dictionary containing selected metadata fields
for the requested PDB entry.
Keys include:
- rcsb_id : str
- deposit_date : datetime.date
- experimental_method : str
- resolution : str
- title : str
- pubmed : str
- doi : str
Raises
------
requests.HTTPError
If the RCSB API request returns an unsuccessful HTTP status code.
requests.RequestException
If a network-related error occurs while contacting the RCSB API.
KeyError
If an expected metadata field is missing from the API response.
ValueError
If the deposit date cannot be parsed as an ISO-formatted date.
Notes
-----
This function queries the RCSB REST API core entry endpoint,
normalizes the JSON response into a pandas DataFrame, and
extracts commonly used structure metadata.
"""
metadata = {}
r = requests.get(f"https://data.rcsb.org/rest/v1/core/entry/{pdb_id}")
r.raise_for_status()
df = pd.json_normalize(r.json())
metadata["rcsb_id"] = df[
"rcsb_entry_container_identifiers.rcsb_id"
].to_string(index=False)
metadata["experimental_method"] = df[
"rcsb_entry_info.experimental_method"
].to_string(index=False)
metadata["resolution"] = df[
"rcsb_entry_info.resolution_combined"
].to_string(index=False)
metadata["deposit_date"] = datetime.fromisoformat(
df["rcsb_accession_info.deposit_date"].to_string(index=False)
).date()
metadata["title"] = str(df.at[0, "struct.title"])
metadata["pubmed"] = df[
"rcsb_primary_citation.pdbx_database_id_PubMed"
].to_string(index=False)
metadata["doi"] = df[
"rcsb_primary_citation.pdbx_database_id_DOI"
].to_string(index=False)
return metadata