Registry / serialization / pycifrw

pycifrw

JSON →
library5.0.1pypypi✓ verified 86d ago

PyCIFRW provides support for reading and writing CIF (Crystallographic Information File) and STAR files in Python. Version 5.0.1 is the latest stable release, with a focus on bugfixes and dropping Python 2 support. The library is maintained with occasional releases.

pip install pycifrw
INSTALL
IMPORT
SIG · PYCIFRW
P
pycifrw
serializationpythonv5.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ReadCif
from CifFile import ReadCif
from pycifrw import ReadCif
Common mistake: users try to import from the top-level package name.
CifFile
from CifFile import CifFile
from pycifrw import CifFile
Import path is CifFile, not pycifrw.
StarFile
from StarFile import StarFile

Read a CIF file and print the top-level keys. Note: the input CIF must exist. For demo, we write a minimal CIF first.

from CifFile import ReadCif # Replace with an actual CIF file path or content cif_content = """data_test _audit_creation_method 'manually created' """ with open('test.cif', 'w') as f: f.write(cif_content) ast = ReadCif('test.cif') print(ast.keys()) # Clean up import os os.remove('test.cif')
Debug
Known issues
breakingVersion 5.0 dropped Python 2 support entirely. Code written for Python 2 will not run.
fix
Upgrade to Python 3, or pin to pycifrw==4.4.6 if stuck on Python 2.
affects: >=5.0
deprecatedThe function `ReadCif` still works but `ReadCifWithError` is recommended for more robust parsing.
fix
Use `from CifFile import ReadCifWithError` and handle returned parse info.
affects: >=5.0
gotchaImporting from `pycifrw` directly fails. The correct import path is `CifFile`, `StarFile`, etc.
fix
Use `from CifFile import ReadCif` instead of `from pycifrw import ReadCif`.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pycifrw'
Trying to `import pycifrw` or `from pycifrw import ...`. The top-level module is not 'pycifrw'—the actual modules are CifFile, StarFile, etc.
fix
Install with `pip install pycifrw` but import from 'CifFile' (e.g., `from CifFile import ReadCif`).
SyntaxError: invalid syntax (for print statements, etc.)
Running Python 2 code on Python 3. PyCIFRW 5+ requires Python 3.
fix
Ensure Python 3 interpreter is used (python3). If stuck on Python 2, install pycifrw==4.4.6.
AttributeError: 'CifFile' object has no attribute 'keys'
Reading a CIF file with errors; the object may be incomplete. Or using wrong method to access data.
fix
Use `ReadCifWithError` to get partial results, or check the CIF syntax. Access data via `ast.first_loop()['_tag']` or convert to dict: `dict(ast.items())`.
Upgrade
Version history
5.0.1latest on PyPI · released Mar 24, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
pycifrw — pip install pycifrw · libregistry