Loading
PDBj
MenuPDBj@FacebookPDBj@TwitterPDBj@YouTubewwPDB FoundationwwPDB
RCSB PDBPDBeBMRBAdv. SearchSearch help

Rest interface examples

This page is also available in: 日本語

Example of curl

An example of the curl command used in UNIX like systems to get structural data file of HEM chemical component in the mmCIF format.

$ curl -F "id=HEM" -F "format=mmcif" https://pdbj.org/rest/downloadCOMPfile > HEM.cif.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4703  101  4463  120   240  22121   1189 --:--:-- --:--:-- --:--:--  207k

$ zcat HEM.cif.gz | head
data_HEM
# 
_chem_comp.id                                    HEM 
_chem_comp.name                                  "PROTOPORPHYRIN IX CONTAINING FE" 
_chem_comp.type                                  NON-POLYMER 
_chem_comp.pdbx_type                             HETAIN 
_chem_comp.formula                               "C34 H32 Fe N4 O4" 
_chem_comp.mon_nstd_parent_comp_id               ? 
_chem_comp.pdbx_synonyms                         HEME 
_chem_comp.pdbx_formal_charge                    0

Python example

The following example is an advanced search which also has an equivalent page within the client side interface. The script searches for all x-ray entries released since 2014-01-01 with a resolution of less than 1.8 A. The query fetches the pdbid, structure title and resolution and finally sorts the results by resolution.

import urllib, json

url = "https://pdbj.org/rest/newweb/search/pdb"
params = "rdate_after=2014-01-01&method=1&res_max=1.8&sortBy=8"

json_data = urllib.request.urlopen(url+"?"+params).read()
data = json.loads(json_data)

total = data["total"]
results = data["results"]
print("Total number of results:", total)
print("Printing the first 10 results:")
for i in range(10): print(results[i][0], results[i][1], results[i][13])
The above code fetches the results for the query (line 9) and loads the results using a JSON decoder (line 10). After the data has been loaded by the JSON decoder, the data will be accessible as native Python objects (see e.g. line 19 and 20). Finally the script outputs the total number of results and the first ten results (to the screen).

Perl example

The following example is a status search which also has an equivalent page within the client side interface. The script searches for all entries waiting for publication (HPUB) which have been deposited before 2021-01-01. The query fetches all fields (pdbid, author_list, title, status_code, author_release_sequence, date_hold_coordinates, initial_deposition_date) and finally sorts the results by deposition date (asc).

use LWP::Simple;
use JSON qw(decode_json);

$url = "https://pdbj.org/rest/newweb/search/status";
$params = "status_code=HPUB&ddate_before=2021-01-01&sortBy=4";

$json_data = get($url . "?" . $params);
$data = decode_json($json_data);

$total = $data->{"total"};
my @results = @{$data->{"results"}};

print "Total number of results: " . $total . "\n";
print "Printing the first 10 results:\n";

foreach my $r (@results[0..10]) {
  foreach my $i (@$r) {
    print $i . ",";
  }
  print "\n";
}
The above code fetches the results for the query (line 7) and loads the results using a JSON decoder (line 8). After the data has been loaded by the JSON decoder, the data will be accessible as native Perl objects (see e.g. line 13 and 14). Finally the script outputs the total number of results and the first ten results (to the screen).

The above code requires a json parser (JSON), which can be installed via the CPAN repository.

R example

The following example is a mine 2 sql search which also has an equivalent page within the client side interface. Furthermore, PDBj's chemie service also use the exact same query for the Related PDB entries tab. The script searches for all related PDB entries for a given chem_comp id, in this case "K". The query fetches a selection of the columns from the brief_summary table (pdbid, struct_title, deposit_author, citation_title_pri, citation_journal_pri, citation_year_pri, citation_volume_pri, db_pubmed, db_doi, deposition_date, release_date, modification_date, exptl_method, resolution, pdbx_descriptor).

library(RCurl)
library(rjson)

url <- "https://pdbj.org/rest/newweb/search/sql"
params <- "q=select%20distinct%20on%20(chem_comp.pdbid)%20brief_summary.pdbid%2C%20struct_title%2C%20deposit_author%2C%20citation_title_pri%2C%20citation_journal_pri%2C%20citation_year_pri%2C%20citation_volume_pri%2C%20db_pubmed%2C%20db_doi%2C%20deposition_date%2C%20release_date%2C%20modification_date%2C%20exptl_method%2C%20resolution%2C%20pdbx_descriptor%20from%20brief_summary%20inner%20join%20chem_comp%20on%20chem_comp.pdbid%20%3D%20brief_summary.pdbid%20where%20chem_comp.id%3D%27K%27"

json_data <- getURLContent(paste(url,params, sep="?"))
data <- fromJSON(json_data)

total <- data["total"]
results <- data["results"][[1]]

print(paste("total number of results:", total))
print("Printing the first 10 results:")

for (r in head(results, 10)) {
  print(paste(r[[1]], r[[2]], sep=" - "))
}
The above code fetches the results for the query (line 7) and loads the results using a JSON decoder (line 8). After the data has been loaded by the JSON decoder, the data will be accessible as native R objects (see e.g. line 13 and 14). Finally the script outputs the total number of results and the first ten results (to the screen).

The above code requires a json parser (rjson) and a HTTP fetch module (RCurl), which can both be downloaded via the CRAN repository.

Created: 2017-08-16 (last edited: more than 1 year ago)2017-08-16

218500

PDB entries from 2024-04-17

PDB statisticsPDBj update infoContact PDBjnumon