Skip to main content

mmCIF parser written in Nim with Python bindings

Project description

nim-mmcif

Fast mmCIF (Macromolecular Crystallographic Information File) parser written in Nim with Python bindings via nimporter.

The goal of this repository is to experiment with vibe coding while building something useful for bioinformatics community, to see how much of a cross platform library can be driven to completion by transformers

Features

  • 🚀 High-performance parsing of mmCIF files using Nim
  • 🐍 Seamless Python integration via nimporter
  • 🌍 Cross-platform support (Linux, macOS, Windows)
  • 🏗️ Automatic compilation on import
  • 📦 Easy installation via pip

Installation

Prerequisites

From PyPI (when available)

pip install nim-mmcif

From Source

# Install Nim (platform-specific, see below)
# macOS: brew install nim
# Linux: curl https://nim-lang.org/choosenim/init.sh -sSf | sh
# Windows: scoop install nim

# Install the package
git clone https://github.com/lucidrains/nim-mmcif
cd nim-mmcif
pip install -e .

For detailed platform-specific instructions, see CROSS_PLATFORM.md.

Quick Start

import nim_mmcif

# Parse an mmCIF file
data = nim_mmcif.parse_mmcif("path/to/file.mmcif")
print(f"Found {len(data['atoms'])} atoms")

# Get atom count directly
count = nim_mmcif.get_atom_count("path/to/file.mmcif")
print(f"File contains {count} atoms")

# Get all atoms with their properties
atoms = nim_mmcif.get_atoms("path/to/file.mmcif")
for atom in atoms[:5]:  # Print first 5 atoms
    print(f"Atom {atom['id']}: {atom['label_atom_id']} at ({atom['x']}, {atom['y']}, {atom['z']})")

# Get just the 3D coordinates
positions = nim_mmcif.get_atom_positions("path/to/file.mmcif")
for i, (x, y, z) in enumerate(positions[:5]):
    print(f"Position {i}: ({x:.3f}, {y:.3f}, {z:.3f})")

API Reference

Functions

parse_mmcif(filepath: str) -> dict

Parse an mmCIF file and return a dictionary with parsed data.

get_atom_count(filepath: str) -> int

Get the number of atoms in an mmCIF file.

get_atoms(filepath: str) -> list[dict]

Get all atoms from an mmCIF file as a list of dictionaries.

get_atom_positions(filepath: str) -> list[tuple[float, float, float]]

Get 3D coordinates of all atoms as a list of (x, y, z) tuples.

Atom Properties

Each atom dictionary contains:

  • type: Record type (ATOM or HETATM)
  • id: Atom serial number
  • label_atom_id: Atom name
  • label_comp_id: Residue name
  • label_asym_id: Chain identifier
  • label_seq_id: Residue sequence number
  • x, y, z: 3D coordinates (aliases for Cartn_x, Cartn_y, Cartn_z)
  • occupancy: Occupancy factor
  • B_iso_or_equiv: B-factor
  • And more...

Platform Support

Platform Architecture Python Status
Linux x64, ARM64 3.8-3.12
macOS x64, ARM64 3.8-3.12
Windows x64 3.8-3.12

Building from Source

Automatic Build

python build_nim.py

Manual Build

cd nim_mmcif
nim c --app:lib --out:nim_mmcif.so nim_mmcif.nim  # Linux/macOS
nim c --app:lib --out:nim_mmcif.pyd nim_mmcif.nim  # Windows

Development

Running Tests

pip install pytest
pytest tests/ -v

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests
  5. Submit a pull request

Documentation

Performance

The Nim implementation provides significant performance improvements over pure Python parsers, especially for large mmCIF files commonly used in structural biology.

License

MIT License - see LICENSE file for details.

Acknowledgments

  • Built with Nim for high performance
  • Python integration via nimporter and nimpy
  • mmCIF format specification from wwPDB

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

nim_mmcif-0.0.11.tar.gz (14.4 kB view details)

Uploaded Source

Built Distributions

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

nim_mmcif-0.0.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (143.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

nim_mmcif-0.0.11-cp312-cp312-macosx_11_0_arm64.whl (82.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nim_mmcif-0.0.11-cp312-cp312-macosx_10_9_x86_64.whl (87.0 kB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

nim_mmcif-0.0.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (143.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

nim_mmcif-0.0.11-cp311-cp311-macosx_11_0_arm64.whl (82.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

nim_mmcif-0.0.11-cp311-cp311-macosx_10_9_x86_64.whl (87.0 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

nim_mmcif-0.0.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (143.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

nim_mmcif-0.0.11-cp310-cp310-macosx_11_0_arm64.whl (82.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

nim_mmcif-0.0.11-cp310-cp310-macosx_10_9_x86_64.whl (87.0 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

nim_mmcif-0.0.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (143.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

nim_mmcif-0.0.11-cp39-cp39-macosx_11_0_arm64.whl (82.3 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

nim_mmcif-0.0.11-cp39-cp39-macosx_10_9_x86_64.whl (87.0 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

nim_mmcif-0.0.11-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (16.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

nim_mmcif-0.0.11-cp38-cp38-macosx_11_0_arm64.whl (11.3 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

nim_mmcif-0.0.11-cp38-cp38-macosx_10_9_x86_64.whl (11.0 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

File details

Details for the file nim_mmcif-0.0.11.tar.gz.

File metadata

  • Download URL: nim_mmcif-0.0.11.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nim_mmcif-0.0.11.tar.gz
Algorithm Hash digest
SHA256 affd67d5c666d5e06f75d17b2a2f2a1b25865840daa2798ea1d705e93e127045
MD5 a51d1ffde44fb6ec7505f5b6b7911d0f
BLAKE2b-256 1279e7aba55db25cab11ca722496d095798ddbde5dfd72217ccda75aca2df0e9

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b76cc754f3c70cf6a3271ff227bfc6ea03ca9586133a739905d5e06e13735b27
MD5 9f88ccea70188f5394b20600e0d04f56
BLAKE2b-256 2c6de252fc4290600f693c2465b8c44b8497156d2664f574f59572693824d02d

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 86d74182b166e4bc2f5af36ad0654137185af22a99c0b377a3db6b66ee57bf77
MD5 59e9c36d0b607a138a01ee6068e074e5
BLAKE2b-256 8db1dd7b01265cfddaac67559ac0a689ef3518e5b21af0ff7334dbd49fe01c1f

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 824ef710d957ee7898ef0dd7adbf0f5e5b6854eb26efe61f0ca40d34f33fe8fa
MD5 20eaf97049eab63a1166fd029eb77494
BLAKE2b-256 3e195b6863d561f0363a025ae0d6bc88b7fb6918e30410c03bb923ee6e714960

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a1c8b061c893cb4a108364e6d2b18e32f6ebcec38d9b9153d74da81d35582956
MD5 65bbab97b920f4490d39dbef8533f54a
BLAKE2b-256 ee3de0945da6555917d8006aba4caa690bc19babdaed83187e900b1607e42888

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ada99e7623696e4ef897a1b7c5eac96bc52de4c34d44f912d25e3a4fb6e24a97
MD5 1cb8cefb09c9b643d93539947213d4be
BLAKE2b-256 204869de6966c77af177f994701e30807a8930210256ebbd1109117b6caba1eb

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f3246ed59777c37657ae6c08bcdbdeca08a015c8c97fa542924a895de90dbe4e
MD5 d4b38d2c2fd94f846ee3657f72baff0d
BLAKE2b-256 c4f12aba3d7d6c2ff21cb9925c098b6ff862863e83d5a0002286dea62d965412

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3a1ff3704d9304cbe4a95a913333971d28ddfd93ca783383490840a0a7de6480
MD5 ce19d691caa18249eaa558100fc5c1e4
BLAKE2b-256 7040973462f9deac7a797ff240a68ae12e13b42cc59753e4ed9a542ad784d65e

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 41a67f2e2102d7daed56ea13f319cb54c3a1cfa160d05bdec89f01e81d7906c8
MD5 42073517d267f4d74a703907cc56e455
BLAKE2b-256 9f83eabac80153ad49431dc6e466e501fcc6a1a4618bb433713526309f50bfa3

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e306388e42dedcb23b57ee08db14929714c7b23534435c12f0f3b2679309fa24
MD5 bda5053603fef5c771fe7205709eb77b
BLAKE2b-256 05d9d6f331e3f86490bab384fd071d1d3dbd7606892c1d8e7d7f310d21de0dbb

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2379fc85fc5ebf5173ca9d8db6b53db2448ed357e105999c6988c4e1553534b0
MD5 789428f301d668d6654b16c41a026b96
BLAKE2b-256 aa9f1d7a46fb188c687833ce471ab3edee7fea04c2d4fff3e7611f59b776b044

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 981c463f9049c32c20de1047463909b893243834b1105259deb022024e75c210
MD5 ef73c69cd77c043838785498d71fafb0
BLAKE2b-256 cd45dbc51daf098ea5f76b017d6ed998b4c2a1fff29e512127bc4de466340633

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 89bc837f38937792d862cd296bccb196e9cf6079d625e3c7822496b786925f82
MD5 a300fc190ee90f0d7ed2772dd65c2eda
BLAKE2b-256 6c82a1a81c2faa5473362c95b9f54bfc0ccecb4ece8e451cac2cd1273f7b1773

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 82d0372ea66cd0bc9cb160837492fdf0c29b083a162be2b7253e872707a000d4
MD5 22c59c077698f5c210715ba54e6b27bf
BLAKE2b-256 aa7a010f8adeab00e9cd43e626929b694e83da8daa3e1a70b4cab95b4b9d155e

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3fbf9ea138449eb5add8743e54e7b93fbd9688b5e18e79d81e264b1037f5334a
MD5 6a6e72236758efb73fb5ba82b1f4984c
BLAKE2b-256 6cbb67fa06b309065c1ef7bc63a07fe7370a676464fae8934efb3b51aa632beb

See more details on using hashes here.

File details

Details for the file nim_mmcif-0.0.11-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for nim_mmcif-0.0.11-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ed68637583c7d7cdece6aa6454c95b636223be710c13a0880a2c9a80b579da82
MD5 217924e260fa6fe58e9b4139023f538e
BLAKE2b-256 60291fe2d57d90535422aab9401c7358ee894210453eaa91c796052369f146a0

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