protein

Crates.ioprotein
lib.rsprotein
version0.0.5
sourcesrc
created_at2020-10-18 02:40:25.408466
updated_at2020-10-20 10:07:09.328164
descriptionWorking with protein structures
homepage
repositoryhttps://github.com/TianyiShi2001/protein
max_upload_size
id301788
size2,093,706
Tianyi Shi (TianyiShi2001)

documentation

README

protein

Structural Biology in Rust

Example

Let's read a protein structure from a PDB file and draw a Ramachandran plot!

use csv::Writer; // the crate `csv` is required if you want to output csv
use protein::{
    io::pdb::Parser, // the PDB parser that parses PDB file into a `Structure`
    analysis::ModelAnalysis // `Structure` alone only stores data.
                              // Functions for analysing the `Structure` are provided by separate traits
 };
use std::fs;

fn main() {
    let data = fs::read("assets/4f7i.pdb").unwrap();
    let (_, structure) = Parser::parse(&data).unwrap();
    let (phis, psis) = structure.models[0].ramachandran(); 
    // the `.ramachandran()` function is provided by the `ModelAnalysis` trait

    let mut wtr = Writer::from_path("examples/ramachandran.csv").unwrap();
    wtr.write_record(&["phi", "psi"]).unwrap();
    for (&phi, &psi) in phis.iter().zip(psis.iter()) {
        wtr.write_record(&[phi.to_string(), psi.to_string()])
            .unwrap()
    }
    wtr.flush().unwrap();
}

This will produce a csv file containing two columns representing phi and psi angles. Then we can read the csv file in R and plot it (unfortunately I am not of any graphing libraries in Rust):

ramachandran plot

You can directly run the above example using cargo run:

cargo run --example ramachandran
Commit count: 27

cargo fmt