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. 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:

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

cif2db --list-dics lists the ORMs available. Every record is validated against the dictionary while reading, --no-validate skips that and is about 3.5 times faster.

Optionally, build a full-text index over titles, descriptions, names and organisms. This needs an SQLite with FTS5:

cifql-text-index --config pdb.yaml --dic mmcif_pdbx/v5_417

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

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

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

dic2json dumps a dictionary as JSON.

Development

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

Metadata

Release files for CifQL 0.1.0

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.1.0
File Size Uploaded Provenance Actions
cifql-0.1.0.tar.gz 316.8 kB Without provenance Details for cifql-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 593.2 kB

Release files / cifql-0.1.0.tar.gz

Download URL cifql-0.1.0.tar.gz
Size 316.8 kB
Tags Source
SHA-256 checksum
How to use checksums
183cd563c9eee4cfc583af6668260d30ba240cd07c340000c6031c0e7a5aea80
BLAKE2b-256 checksum
How to use checksums
ffe91999f01586856d431171aa9aa2fd294adc01da3663b795bf8087c1d1f1fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

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

Download URL cifql-0.1.0-py3-none-any.whl
Size 276.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7797bb284434d3cc2a033f646c21a98994ebe8fff9497078f2bb9e8d31643fb4
BLAKE2b-256 checksum
How to use checksums
9e8c345d9dd5975b613683bb402bc58c249406bb9f6eb096bb192e49debb19ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for CifQL 0.1.0

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