Skip to main content

CifQL - mmCIF and ModelCIF files as one queryable relational database

CifQL reads many mmCIF or ModelCIF files into one relational database, one table per CIF category, so that questions across a whole archive become database queries: "which entries have a heme group bound", "which human proteins are there as kinases".

The database schema is not designed manually. cifql dic2orm generates it from the CIF dictionary itself, as Django models, with keys, links between categories, types, enumerations and descriptions taken from the dictionary. Django then creates and manages the database. CifQL runs on SQLite so far, PostgreSQL is planned.

CifQL holds what describes a structure, not its atoms: atom coordinates, polymer sequences and per-residue data are left out on purpose.

Installation

pip install CifQL
# with the MCP server for language models
pip install "CifQL[mcp]"

CifQL needs Python 3.12 or newer. The ORM for PDBx/mmCIF 5.417 comes with the package.

Configuration

The database connection is a YAML file in Django's DATABASES format:

DATABASES:
  default:
    ENGINE: django.db.backends.sqlite3
    NAME: /data/pdb.sqlite3

The tools read the file given by --config, else the one in $CIFQL_CONFIG_YAML, else ~/.cifqlconfig.yaml.

Usage

Read files into the database, a directory is searched for .cif and .cif.gz:

cifql cif2db --config pdb.yaml --dic mmcif_pdbx/v5_417 --source PDB \
    --entry-link 'https://www.rcsb.org/structure/{ID}' /data/pdb/mmCIF/

cifql cif2db --list-dics lists the ORMs available. For an archive of another layout, --loader takes a Python file that walks it, see cifql.loader. A run started again skips files already loaded. Every record is validated against the dictionary while reading, --no-validate skips that and saves some time.

On SQLite, cifql cif2db also builds a full-text index over titles, descriptions, names and organisms. This needs an SQLite with FTS5, without one cifql cif2db stops before the first file.

Querying

The database is plain SQL, reading it needs neither CifQL nor Django. Tables are named <ORM version>_<category>, with the underscores of the category dropped (_chem_comp is v5_417_chemcomp):

SELECT d.name, e.pdbx_description
FROM v5_417_entity e
JOIN v5_417_datablock d ON d.id = e.datablock_id
WHERE e.pdbx_description LIKE '%hexokinase%';

Language models (MCP)

cifql mcp hands the database to a language model as tools: search the dictionary, describe a category, query with filters across linked categories (full-text search included) and plain SQL. It serves streamable HTTP on 127.0.0.1:8000/mcp, or talks over stdin/stdout with --stdio:

cifql mcp --config pdb.yaml --dic mmcif_pdbx/v5_417 --port 8765
claude mcp add --transport http cifql http://localhost:8765/mcp

Other dictionaries

cifql dic2orm generates the ORM for another dictionary or version. cifql dic-usage --dump-json counts which categories a set of files actually uses and writes the unused ones as an exclusion list for cifql dic2orm --exclude-json:

cifql dic2json --dump-json mmcif_ma.json mmcif_ma.dic
cifql dic-usage --dump-json exclude.json mmcif_ma.json /data/models/
mkdir -p /data/orms/my_orm
cifql dic2orm --exclude-json exclude.json --output-dir /data/orms/my_orm \
    mmcif_ma.dic
cifql cif2db --config models.yaml --dic /data/orms/my_orm /data/models/

cifql dic-usage reads the dictionary as JSON, as cifql dic2json dumps it.

Tab completion

In Bash, Tab completes sub-commands, options and file names after this:

eval "$(cifql completion bash)"

Development

pip install -e ".[dev]"
black --check cifql doc/source tests
pylint --disable=fixme cifql doc/source tests
pytest --cov=cifql
  • tools go in as their own Python file
  • once per clone, activate the release tag check of hooks/pre-push: git config core.hooksPath hooks
  • an ORM generated into the package (cifql dic2orm without --output-dir) needs a black run before it is committed

Metadata

Release files for CifQL 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CifQL 0.2.1
File Size Uploaded Provenance Actions
cifql-0.2.1.tar.gz 348.7 kB Without provenance Details for cifql-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for CifQL 0.2.1
File Interpreter ABI Platform Actions
cifql-0.2.1-py3-none-any.whl Python 3 none any Details for cifql-0.2.1-py3-none-any.whl

Total release size: 645.9 kB

Release files / cifql-0.2.1.tar.gz

Download URL cifql-0.2.1.tar.gz
Size 348.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3db29aaef27b361012c59e66a84902efa8c638f59dc3b7dfe09d340624335e9d
BLAKE2b-256 checksum
How to use checksums
09f7ccc46537e7b53f348b9e57d6d612f3af8b394dbe1e8c26f164a960023171
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / cifql-0.2.1-py3-none-any.whl

Download URL cifql-0.2.1-py3-none-any.whl
Size 297.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0edc59b10ebf11236b1fa4c382b301e652409e027d32a9d4cbc5a68c394974d5
BLAKE2b-256 checksum
How to use checksums
00fec1c79ffe117d925a5f26d77f486dac8084069b590e40a334e690a957f721
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for CifQL 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page