[][src]Crate pdbtbx

pdbtbx (PDB Toolbox)

A library to work with crystallographic Protein DataBank files. It can parse the main part of the PDB format (it is actively in development so more will follow). After parsing the structure is accessible with an API loosely based on CCTBX. The resulting structures can be saved in a valid PDB file for use in other software.

Goals

This library is designed to be a dependable, safe, stable and fast way of handling PDB files in idiomatic Rust. It is the goal to be very community driven, to make it into a project that is as useful to everyone as possible, while keeping true to its core principles.

Why

As Rust is a very recent language there is not a lot of support for scientific work in Rust in comparison to languages that are used much longer (see Python). I think that using Rust would have huge benefits over other languages (especially Python) in bigger scientific projects. Writing a library that makes more scientific work with Rust possible makes it easier for scientists to start using Rust, which I want to support.

How to use it

The following example opens a pdb file (1ubq.pdb). Removes all H atoms. Calculates the average B factor (or temperature factor) and prints that. It also saves the resulting PDB to a file.

use pdbtbx;
let (mut pdb, _errors) = pdbtbx::open("example-pdbs/1ubq.pdb", pdbtbx::StrictnessLevel::Loose).unwrap();
pdb.remove_atoms_by(|atom| atom.element() == "H"); // Remove all H atoms

let mut avg_b_factor = 0.0;
for atom in pdb.atoms() { // Iterate over all atoms in the structure (not the HETATMs)
    avg_b_factor += atom.b_factor();
}
avg_b_factor /= pdb.atom_count() as f64;

println!("The average B factor of the protein is: {}", avg_b_factor);
pdbtbx::save(pdb, "dump/1ubq.pdb", pdbtbx::StrictnessLevel::Loose);

Structs

Atom

A struct to represent a single Atom in a protein

Chain

A Chain containing multiple Residues

Model

A Model containing multiple Chains

MtriX

A transformation expressing non-crystallographic symmetry, used when transformations are required to generate the whole asymmetric subunit

OrigX

A transformation of the orthogonal coordinates to submitted

PDB

A PDB file containing the 3D coordinates of many atoms making up the 3D structure of a protein, but it can also be used for other molecules.

PDBError

An error surfacing while handling a PDB

Residue

A Residue containing multiple atoms

Scale

A scale transformation of a crystal, to get from standard orthogonal coordinates to fractional coordinates

Symmetry

A Space group of a crystal

TransformationMatrix

A 3D affine transformation matrix

UnitCell

A unit cell of a crystal, containing its dimensions and angles

Enums

Context

A struct to define the context of an error message

ErrorLevel

This indicates the level of the error, to handle it differently based on the level of the raised error.

StrictnessLevel

The strictness to operate in, this defines at which ErrorLevel the program should stop execution upon finding an error.

Functions

open

Parse the given file into a PDB struct. Returns an PDBError when it found a BreakingError. Otherwise it returns the PDB with all errors/warnings found while parsing it.

parse

Parse the input stream into a PDB struct. To allow for direct streaming from sources, like from RCSB.org. Returns an PDBError when it found a BreakingError. Otherwise it returns the PDB with all errors/warnings found while parsing it.

save

Save the given PDB struct to the given file. It validates and renumbers the PDB. It fails if the validation fails with the given level. If validation or renumbering gives rise to problems use the save_raw function.

save_raw

Save the given PDB struct to the given BufWriter. It does not validate or renumber the PDB, so if that is needed that needs to be done in preparation.

validate

Validate a given PDB file in terms of invariants that should be held up. It returns PDBErrors with the warning messages.