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 dic2ormwithout--output-dir) needs ablackrun before it is committed
Metadata
Release files for CifQL 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cifql-0.2.0.tar.gz | 346.1 kB | Without provenance | Details for cifql-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cifql-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for cifql-0.2.0-py3-none-any.whl |
Total release size: 642.3 kB
Release files / cifql-0.2.0.tar.gz
| Download URL | cifql-0.2.0.tar.gz |
|---|---|
| Size | 346.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff678d57147ed55726c2ceb569c5e3e36b1a869f81093c8f9a3076db6ec74434
|
|
BLAKE2b-256 checksum How to use checksums |
f828559803c008773fbdc2fba1356defab37dd9be151a55624a440d87d7dc4ca
|
| 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.0-py3-none-any.whl
| Download URL | cifql-0.2.0-py3-none-any.whl |
|---|---|
| Size | 296.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
927c746d9646b45284803b7d9f9dd379c90d46e40a59881c7da5c9544401054c
|
|
BLAKE2b-256 checksum How to use checksums |
05b99f65fda40e7dc9701e2815f38e7d71f7344b8f224bf4de6d807a82d4f3bd
|
| 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.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.