Bio Files: Read and write common biology file formats
This Rust and Python library contains functionality to load and save data in common biology file formats. It operates on data structures that are specific to each file format; you will need to convert to and from the structures used by your application. The API docs, and examples below are sufficient to get started.
Note: Install the pip version with pip install biology-files due to a name conflict.
Supported formats:
- mmCIF (Protein atom, residue, chain, and related data like secondary structure)
- mmCIF (structure factors / 2fo-fc: Electron density data, raw)
- Mol2 (Small molecules, e.g. ligands)
- SDF (Small molecules, e.g. ligands)
- PDBQT (Small molecules, e.g. ligands. Includes docking-specific fields.)
- Map (Electron density, e.g. from crystallography, Cryo EM. Processed using Fourier transforms)
- AB1 (Sequence tracing)
- DAT (Amber force field data for small molecules)
- FRCMOD (Amber force field patch data for small molecules)
- Amber .lib files, e.g. with charge data for amino acids and proteins.
- GRO (Gromacs molecules)
- TOP (Gromacs topology) - WIP
- ORCA Input and output files (quantum chemistry; HF, DFT etc)
- XYZ (Minimal atom coordinate format)
Planned:
- MTZ (Exists in Daedalus; needs to be decoupled)
- DNA (Exists in PlasCAD; needs to be decoupled)
Generic data types
This library includes a number of relatively generic data types which are returned by various load functions, and required to save data. These may be used in your application directly, or converted into a more specific format. Examples:
For Genbank, we recommend gb-io. We do not plan to support this format, due to this high quality library.
Each module represents a file format, and most have dedicated structs dedicated to operating on that format.
It operates using structs with public fields, which you can explore
using the API docs, or your IDE. These structs generally include these three methods: new(),
save() and load(). new() accepts &str for text files, and a R: Read + Seek for binary. save() and
load() accept &Path.
The Force Field formats use load_dat, save_frcmod instead, as they use the same structs for both formats.
Serial numbers
Serial numbers for atoms, residues, secondary structure, and chains are generally pulled directly from atom data files
(mmCIF, Mol2 etc). These lists reference atoms, or residues, stored as Vec<u32>, with the u32 being the serial number.
In your application, you may wish to adapt these generic types to custom ones that use index lookups
instead of serial numbers. We use SNs here because they're more robust, and match the input files directly;
add optimizations downstream, like converting to indices, and/or applying back-references. (e.g. the index of the residue
an atom's in, in your derived Atom struct).
Orca interface
This library provides an interface to building Orca inputs, executing commands, and parsing outputs. It uses Rust data structures to contrain input choices into valid ones when possible, and allows you to integrate Orca into Rust programs and libraries. For example, Daedalus uses it to minimize energy on organic molecules, and augment traditional MD technique with quantum mechanics.
ORCA support in this library is limited to Rust only. If you wish to use Orca with Python, use OPI, the official FACCTS library.
Note: Orca support is currently limited to a subset of features. We plan to gradually expand this. If you're looking for specific functionality, please open an Issue or PR on Github.
Can generate and run ORCA commands, and parse the result. Example:
let mut orca_inp = OrcaInput ;
orca_inp.keywords = vec!;
println!;
// Save to disk if desired:
orca_inp.save?;
println!;
let orca_out = orca_inp.run?;
println!;
Example use
Small molecule save and load, Python.
=
#AtomGeneric { serial_number: 1, posit: Vec3 { x: 2.3974, y: 1.1259, z: 2.5289 }, element: Chlorine,
: None, : None, : None, : None, : }
.
# [2.3974, 1.1259, 2.5289]
=
# Load molecules from databases using identifiers:
=
=
=
=
=
# (See the Rust examples and API docs for more functionality; most
# is exposed in Python as well)
Small molecule save and load, Rust.
use ;
// ...
let sdf_data = load?;
sdf_data.atoms; // (as above)
sdf_data.atoms.posit; // (as above, but lin_alg::Vec3))
sdf_data.save?;
let mol2_data: Mol2 = sdf_data.into;
mol2_data.save?;
let xyz_data = load?;
// Loading Force field parameters:
let p = new
let params = load_dat?;
// Load electron density structure factors data, to be processed with a FFT:
let path = new;
let data = new_from_path?;
// These functions aren't included; an example of turning loaded structure factor data
// into a density map.
let mut fft_planner = new;
let dm = density_map_from_mmcif?;
// Or if you have a Map file:
let p = new;
let dm = load?;
// Load molecules from databases using identifiers:
let mol = load_drugbank?;
let mol = load_pubchem?;
let mol = load_pdbe?;
let mol = load_amber_geostd?;
let peptide = load_rcsb?;
You can use similar syntax for mmCIF protein files.
Amber force fields
Reference the Amber 2025 Reference Manual, section 15 for details on how we parse its files, and how to use the results. In some cases, we change the format from the raw Amber data. For example, we store angles as radians (vice degrees), and σ vice R_min for Van der Waals parameters. Structs and fields are documented with reference manual references.
The Amber forcefield parameter format has fields which each contain a Vec of a certain type of data. (Bond stretching parameters,
angle between 3 atoms, torsion/dihedral angles etc.) You may wish to parse these into a format that has faster lookups
for your application.
Note that the above examples expect that your application has a struct representing the molecule that has
From<Mol2>, and to_mol2(&self) (etc) methods. The details of these depend on the application. For example:
A practical example of parsing a molecule from a mmCIF as parsed from bio_files into an application-specific format:
A protein loading and prep example:
Python:
::;
=
=
=
=
# Or, instead of loading atoms and mol-specific params separately:
# mol, lig_specific = load_prmtop("my_mol.prmtop")
# Add Hydrogens, force field type, and partial charge to atoms in the protein; these usually aren't
# included from RSCB PDB. You can also call `populate_hydrogens_dihedrals()`, and
# `populate_peptide_ff_and_q() separately. Add bonds.
, =
Rust:
use ;
use Path;
Note: The Python version is currently missing support for some formats, and not all fields are exposed.