Skip to main content

Sequence-based programmatic access to the AlphaFold Protein Structure Database

Project description

afdb-query

Sequence-based programmatic access to the AlphaFold Protein Structure Database (AFDB). Query a protein by its amino-acid sequence, then pull per-residue pLDDT — including "the first n values" — without hand-rolling URL derivation and JSON fetching.

Install

pip install afdb-query

Quickstart

from afdb_query import AlphaFold

with AlphaFold() as af:
    hits = af.search(sequence)        # Tier 1: list[Structure], in AFDB's returned order
    s = hits[0]

    s.global_plddt        # mean pLDDT for the model (cheap, from the summary)
    s.sequence_identity   # always 1.0 — the sequence endpoint is an exact (MD5) lookup
    s.uniprot_accession   # e.g. "P12345", or None

    p = s.plddt()         # Tier 2: per-residue pLDDT (fetched once, then cached)
    p.scores              # full per-residue list[float]
    p.first(50)           # first 50 values — or all of them if the model is shorter

search raises InvalidSequenceError for sequences that cannot be queried (internal stop *, shorter than 20 residues, or non-standard amino acids), and returns [] when AFDB has no entry for a valid sequence.

Results come back in AFDB's returned order (ranked by sequence identity). Note that hits[0] is not guaranteed to be the canonical AF-<accession>-F1 model — for some sequences a multi-chain or AB-INITIO model ranks first — so pick the hit whose model_identifier you want if you need a specific entry.

Batch lookups

search_many runs many sequences concurrently with resumable on-disk caching:

report = af.search_many(
    [{"id": "rec1", "sequence": seq1}, {"id": "rec2", "sequence": seq2}],
    out_dir="afdb_cache",
    concurrency=6,
    plddt_first_n=50,   # optional: also save the first 50 per-residue pLDDT per hit
)
# report -> {"total":..., "hits":..., "misses":..., "errors":..., "skipped":..., ...}
  • You supply a generic id per sequence; it keys the cache file and maps back to your own records.
  • out_dir/summaries/{id}.json stores each hit (a 404 miss stores {"structures": []}); existing files are left untouched, so re-runs resume.
  • With plddt_first_n set, out_dir/plddt/{id}.json stores the raw first-n per-residue pLDDT array for the selected structure.
  • Real HTTP errors are counted but not saved, so they retry on the next run.

Picking the right structure (full_length=True)

By default search_many caches pLDDT for structures[0] — whatever AFDB ranks first. That is not always the canonical single-chain model: for some sequences a multi-chain or AB-INITIO model (e.g. twice the residue count) ranks first, so structures[0] would give you the wrong per-residue array.

Pass full_length=True to require that the cached structure has sequence_identity == 1.0 and a per-residue length equal to your query length:

report = af.search_many(
    [{"id": "rec1", "sequence": seq1, "accession": "P12345"}],  # accession optional
    out_dir="afdb_cache",
    plddt_first_n=9999999,   # store the whole array; slice locally later
    full_length=True,
)
  • Among exact-length, exact-sequence hits the optional per-record accession wins (AF-<accession>-F1); otherwise selection falls back to canonical -F1 over numeric models, then highest global_plddt, deterministically.

  • A record whose hits include no exact-length match is counted under no_full_length (its summary is still written, so re-runs resume) and no pLDDT is cached.

  • A hit chosen by fallback while more than one exact-sequence model matched is counted under ambiguous — distinct sequences can be identical across organisms yet have different pLDDT, so supply accession when the specific model matters.

  • Because the residue count is only knowable from the confidence JSON, this mode fetches confidence (and may fetch more than one model) per record.

    Note: resumability keys on the summary file. If you run once without plddt_first_n and again with it, already-cached records are skipped and their pLDDT is not back-filled.

Not (yet) supported

  • UniProt-accession lookup (sequence-only for now)
  • PAE (Predicted Aligned Error)
  • No statistics helpers — the package returns raw values; downstream math is yours.

Project details


Download files

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

Source Distribution

afdb_query-0.2.1.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

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

afdb_query-0.2.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file afdb_query-0.2.1.tar.gz.

File metadata

  • Download URL: afdb_query-0.2.1.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for afdb_query-0.2.1.tar.gz
Algorithm Hash digest
SHA256 84e3f8a005159c0a8c991f0fb6d7eabaa0edca57e7a076f38c8c4e3e9942fb56
MD5 d0a0cac9797f8474bd959fe44fbf33ae
BLAKE2b-256 868581e42474d702efee409331cc65ea2e22f7d52862be171cc6e79f44f255af

See more details on using hashes here.

File details

Details for the file afdb_query-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: afdb_query-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for afdb_query-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c4f87803aac0d49ddc5a4da7863990ec9126f18d6c344ef927c6cb18af2964f
MD5 c44fadad4d89553b1766b0583bb19a05
BLAKE2b-256 40aa1ea9f087706d67b62db86477fa35d08e52bd56d7ee4944fdc34654a020ea

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