18 releases
| 0.1.12 | Jul 24, 2025 |
|---|---|
| 0.1.11 | Mar 1, 2024 |
| 0.1.10 | Jul 3, 2023 |
| 0.1.7 | Mar 18, 2023 |
| 0.0.41 | Mar 10, 2020 |
#95 in Template engine
24 downloads per month
Used in 14 crates
(via gchemol)
175KB
4K
SLoC
gchemol-readwrite
A Rust library for reading and writing chemical file formats, built on top of the gchemol-core molecular manipulation library.
Features
- Support for multiple chemical file formats:
- XYZ (.xyz)
- CIF (.cif)
- MOL2 (.mol2)
- PDB (.pdb)
- POSCAR/CONTCAR (VASP, *.vasp, POSCAR-xx)
- Gaussian (.gjf)
- And more...
- Powerful template engine for custom molecular file format generation using Jinja2-like syntax
- Integration with
gchemol-corefor molecular manipulation and analysis - Extensible architecture for adding new file formats
Supported File Formats
| Format | Extensions | Read | Write |
|---|---|---|---|
| XYZ | .xyz | ✅ | ✅ |
| Extended XYZ | .exyz | ✅ | ✅ |
| CIF | .cif | ✅ | ✅ |
| MOL2 | .mol2 | ✅ | ✅ |
| PDB | .pdb | ✅ | ✅ |
| VASP POSCAR | POSCAR, CONTCAR | ✅ | ✅ |
| Gaussian | .log, .out | ✅ | ❌ |
| SDF | .sdf | ✅ | ✅ |
| CML | .cml | ✅ | ✅ |
| Chemical JSON | .cjson | ✅ | ✅ |
Installation
Add this to your Cargo.toml:
[dependencies]
gchemol-readwrite = "0.1"
Usage
Reading Molecules
use gchemol_readwrite::prelude::*;
use gchemol_core::Molecule;
// Read a molecule from a file
let mol = Molecule::from_file("water.xyz")?;
// Or read from a string
let mol = Molecule::from_str("XYZ STRING HERE", "text/xyz")?;
Writing Molecules
use gchemol_readwrite::prelude::*;
use gchemol_core::Molecule;
// Assuming you have a Molecule object
let mol: Molecule = ...;
// Write to a file
mol.to_file("output.xyz")?;
// Or format as a string
let xyz_string = mol.format_as("text/xyz")?;
Using Templates
The library provides a powerful template engine for generating custom molecular file formats:
use gchemol_readwrite::prelude::*;
use gchemol_core::Molecule;
let mol = Molecule::from_file("structure.cif")?;
// Render using a Jinja2-like template
let rendered = mol.render_with("template.jinja".as_ref())?;
// Save the rendered output
std::fs::write("output.file", rendered)?;
See Template Usage Documentation for more details on the template system.
Template System
This library includes a flexible template engine based on MiniJinja that allows users to create custom molecular file formats. The template system provides access to molecular data structures and includes a built-in format filter for precise numeric formatting.
Templates can be used to generate input files for various computational chemistry programs like:
- Abacus (STRU)
- VASP (POSCAR)
- And many others
For detailed information about the template system, see Template Usage Documentation.
Documentation
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Dependencies
~28–44MB
~755K SLoC