Load CIF files in a jiffy
Project description
Overview
ciffy is a fast CIF file parser for molecular structures, with a C backend and Python interface. It supports both NumPy and PyTorch backends for array operations.
Performance
ciffy is 50-90x faster than BioPython and Biotite for parsing CIF files:
| Structure | Atoms | ciffy | BioPython | Biotite |
|---|---|---|---|---|
| 3SKW | 2,874 | 0.47 ms | 31 ms (66x) | 28 ms (59x) |
| 9GCM | 4,466 | 0.71 ms | 40 ms (56x) | 36 ms (51x) |
| 9MDS | 102,216 | 14 ms | 1266 ms (93x) | 911 ms (67x) |
Benchmarked on Apple M1 Max. Run python tests/profile.py to reproduce.
Installation
From PyPI
pip install ciffy
From Source
git clone https://github.com/hmblair/ciffy.git
cd ciffy
pip install -r requirements.txt
pip install -e .
Backends
ciffy supports two array backends:
- NumPy: Lightweight, no additional dependencies required
- PyTorch: For GPU support and integration with deep learning workflows
Specify the backend when loading structures:
import ciffy
# Load with NumPy backend (recommended for general use)
polymer = ciffy.load("structure.cif", backend="numpy")
# Load with PyTorch backend (for deep learning workflows)
polymer = ciffy.load("structure.cif", backend="torch")
Polymers can be converted between backends:
# Convert to PyTorch tensors
torch_polymer = polymer.torch()
# Convert to NumPy arrays
numpy_polymer = polymer.numpy()
Note: The default backend is "numpy" as of v0.6.0. Specify the backend explicitly for clarity.
Usage
import ciffy
# Load a structure from a CIF file
polymer = ciffy.load("structure.cif", backend="numpy")
# Basic information
print(polymer) # Summary of chains, residues, atoms
# Access coordinates and properties
coords = polymer.coordinates # (N, 3) array/tensor
atoms = polymer.atoms # (N,) array/tensor of atom types
sequence = polymer.str() # Sequence string
# Geometric operations
centered, means = polymer.center(ciffy.MOLECULE)
aligned, Q = polymer.align(ciffy.CHAIN)
distances = polymer.pd(ciffy.RESIDUE)
# Selection
rna_chains = polymer.subset(ciffy.RNA)
backbone = polymer.backbone()
# Iterate over chains
for chain in polymer.chains(ciffy.RNA):
print(chain.id(), chain.str())
# Compute RMSD between structures
rmsd = ciffy.rmsd(polymer1, polymer2, ciffy.MOLECULE)
Saving Structures
# Save to CIF format (supports all molecule types)
polymer.write("output.cif")
# Save only polymer atoms (excludes water, ions, ligands)
polymer.poly().write("polymer_only.cif")
Module Structure
ciffy/
├── backend/ # NumPy/PyTorch abstraction layer
├── types/ # Scale, Molecule enums
├── biochemistry/ # Element, Residue, nucleotide definitions
├── operations/ # Reduction, alignment operations
├── io/ # File loading and writing
└── utils/ # Helper functions and base classes
Testing
pip install pytest
pytest tests/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ciffy-0.7.2.tar.gz.
File metadata
- Download URL: ciffy-0.7.2.tar.gz
- Upload date:
- Size: 91.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b36db516acd60cf91ef856bbb567f6766d5b7ff20691af03bfdf55a9861218eb
|
|
| MD5 |
f1ba44a21e7cb82fc7937ac1f29027c4
|
|
| BLAKE2b-256 |
b502ff5cc19b341392426623544f49165da0572713961e920dfcc3fc1713d462
|
Provenance
The following attestation bundles were made for ciffy-0.7.2.tar.gz:
Publisher:
pypi.yml on hmblair/ciffy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ciffy-0.7.2.tar.gz -
Subject digest:
b36db516acd60cf91ef856bbb567f6766d5b7ff20691af03bfdf55a9861218eb - Sigstore transparency entry: 759740592
- Sigstore integration time:
-
Permalink:
hmblair/ciffy@1f9bef7cc3f11ec9769ff5e42a754b0db725f8bf -
Branch / Tag:
refs/tags/v0.7.2 - Owner: https://github.com/hmblair
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@1f9bef7cc3f11ec9769ff5e42a754b0db725f8bf -
Trigger Event:
push
-
Statement type: