Skip to main content

A library for searching the RCSB PDB database

Project description

ci version pypi license commit

pdbsearch is a Python library for searching for PDB structures using the RCSB web services.

Example

>>> import pdbsearch
>>> results = pdbsearch.search(rows=5, chem_comp__name__contains="zinc")
>>> print(results["total_count"])
26
>>> print(results["result_set"])
[{'identifier': '1A0B', 'score': 1.0}, {'identifier': '1A1F', 'score': 1.0},
 {'identifier': '1A1G', 'score': 1.0}, {'identifier': '1A1H', 'score': 1.0},
 {'identifier': '1A1I', 'score': 1.0}]

Installing

pip

pdbsearch can be installed using pip (you may need to use pip3):

$ pip install pdbsearch

If you get permission errors, try using sudo:

$ sudo pip install pdbsearch

Requirements

pdbsearch requires requests.

Testing

To test a local version of pdbsearch, cd to the pdbsearch directory and run:

$ python -m unittest discover tests

You can opt to only run unit tests or integration tests:

$ python -m unittest discover tests.unit $ python -m unittest discover tests.integration

Overview

pdbsearch is a Python library for searching for PDB structures using the RCSB web services.

Nodes and Queries

The pdbsearch.search function is useful for simple queries, but it has some limitations.

  1. If using multiple queries, they will always be combined with an and operator.

  2. You can only provide one value per argument - if you have multiple protein sequences, you can’t search for them all at once.

It can sometimes be useful to access the underlying node system that pdbsearch.search is built on for more complex queries. This solves both of the above limitations.

Nodes

Each of the search services has a function for creating a single search node.

>>> # Full text search node
>>> node = pdbsearch.full_text_node(term="thymidine kinase")
>>>
>>> # Text search node
>>> node = pdbsearch.text_node(pdbx_struct_assembly__details__not__contains="good")
>>>
>>> # Text chem search node
>>> node = pdbsearch.text_chem_node(chem_comp__formula_weight__lt=1000)
>>>
>>> # Sequence search nodes
>>> node = pdbsearch.sequence_node(protein="MALWMRLLPLLALLALWGPDPAAA", identity=0.95, evalue=1e-10)
>>> node = pdbsearch.sequence_node(dna="ATGCATGCATGC", identity=0.95, evalue=1e-10)
>>> node = pdbsearch.sequence_node(rna="AUGCAUGCAUGC", identity=0.95, evalue=1e-10)
>>>
>>> # Sequence motif search node
>>> node = pdbsearch.seqmotif_node(protein="C-X-C-X(2)-[LIVMYFWC]", pattern_type="prosite")
>>>
>>> # Structure search node
>>> node = pdbsearch.structure_node("4HHB-1", operator="relaxed_shape_match")
>>>
>>> # Structure motif search node
>>> node = pdbsearch.strucmotif_node("4HHB", residues=(("A", 10), ("A", 20)), rmsd=0.5, exchanges={("A", 10): ["ASP"], ("A", 20): ["HIS"]})
>>>
>>> # Chemical search nodes
>>> node = pdbsearch.chemical_node(smiles="CC(C)C", match_type="graph-relaxed-stereo")
>>> node = pdbsearch.chemical_node(inchi="InChI=1S/C6H12/c1-2-4-6-5-3-1/h1-6H2", match_type="graph-relaxed-stereo")

You can execute any of these nodes individually using their pdbsearch.query method. These can take a return_type parameter, and all of the request option parameters.

>>> results = node.query("entry", return_all=True, sort="-rcsb_accession_info.deposit_date")

Combining Nodes

All node objects have an and_ and or_ method, which can be used to combine them with other nodes.

>>> node1 = pdbsearch.full_text_node(term="thymidine kinase")
>>> node2 = pdbsearch.text_node(pdbx_struct_assembly__details__not__contains="good")
>>> node3 = pdbsearch.sequence_node(protein="MALWMRLLPLLALLALWGPDPAAA", identity=0.95, evalue=1e-10)
>>> node4 = pdbsearch.sequence_node(dna="ATGC", identity=0.95, evalue=1e-10)
>>> node5 = pdbsearch.sequence_node(rna="AUGC", identity=0.95, evalue=1e-10)
>>> node = node1.and_(node2).or_(node3.and_(node4.or_(node5)))
>>> results = node.query("entry", return_all=True, sort="-rcsb_accession_info.deposit_date")

Schemas

The text and text_chem services have a schema that defines the attributes you can search on. These can be read here and here respectively.

They are also available as JSON schema objects, here and here respectively. This is important as pdbsearch needs to know type information about the attributes in order to know which operator to use sometimes, and it needs to know which parameter names correspond to this service when parsing a pdbsearch.search function call.

For this reason, a simplified form of the schema (all attributes, but only the information about them pdbsearch needs) is hardcoded into the library. To ensure the library always uses the most up to date information, it will try to update its own local copy of the schema from the RCSB API when the library is imported.

This can be disabled by setting the PDBSEARCH_NO_UPDATE environment variable.

You can also download the full schema using a CLI command:

pdbsearch schema > schema.json
pdbsearch schema --chemical --indent 4 > chemical_schema.json

The downloaded schema information will be cached locally, so that it doesn’t fetch the schema every time pdbsearch runs - to delete this local cache, you can run:

pdbsearch clearschema

Changelog

Release 0.5.0

8 Jan 2026

  • Overhauled library for new RCSB search API structure.

Release 0.4.0

24 Jul 2022

  • Updated library for v2 of the RCSB search API.

Release 0.3.0

29 May 2021

  • Added search criteria.

  • Added AND chaining for search criteria.

Release 0.2.0

25 April 2021

  • Added ability to sort results.

  • Created shorthand system for common sort criteria.

Release 0.1.0

2 March 2021

  • Started library.

  • Added ability to fetch all PDB codes.

  • Basic pagination.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdbsearch-0.5.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file pdbsearch-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pdbsearch-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for pdbsearch-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 498938a57c184cea3e16c9e998ab5505a120780cf8077897c7fea75013049368
MD5 797b2a445b80f303fb2f56bac7198821
BLAKE2b-256 b4b3fe5a48f67c337b69a2061c8dda415d15df6a58ad78d3be4220a241e1444b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page