9 releases

0.1.7 Jul 3, 2023
0.1.6 Jun 24, 2023
0.1.4 Feb 12, 2023
0.1.1 Dec 8, 2022
0.0.40 Feb 25, 2020

#147 in Science

Download history 15/week @ 2024-06-15 26/week @ 2024-06-22 4/week @ 2024-06-29 1/week @ 2024-07-06 22/week @ 2024-07-13 13/week @ 2024-07-20 106/week @ 2024-07-27 17/week @ 2024-08-03 13/week @ 2024-08-10 11/week @ 2024-08-17 13/week @ 2024-08-24 10/week @ 2024-08-31 7/week @ 2024-09-07 7/week @ 2024-09-14 40/week @ 2024-09-21 15/week @ 2024-09-28

69 downloads per month
Used in 13 crates (6 directly)

GPL-3.0 license

69KB
51 lines

gchemol

gchemol is a graph-based chemical object library implemented in Rust programming language. This project is still in early development.

Crates.io

Features

  • Fast and safe codes empowered by Rust.
  • Static build without external dependencies: easy to deploy in HPC environment.
  • Core graph data structure using petgraph
  • Read/write molecules in common chemcial file formats.
  • Linear algebra backed by nalgebra
  • Render molecule in user defined formats by templating with handlebars and tera

How to use

Setup

follow the official guide:

add gchemol dependency to your Cargo.toml:

[dependencies]
gchemol = "0.1"

Atom

use gchemol::Atom;

// construct from element and position
let a = Atom::new("C", [0.0, 0.0, 0.0]);
let b = Atom::new("C", [1.2, 1.2, 1.2]);

or simply convert from a string:

let a: Atom = "C 1.0 1.0 0.2"
    .parse()
    .expect("atom from string");

Molecule

  1. Creating a molecule manually

    use gchemol::Molecule;
    
    let atoms = [
        Atom::new("C", [ 0.000000,   0.000000,  0.000000]),
        Atom::new("C", [ 0.000000,   0.000000,  1.089000]),
        Atom::new("C", [ 1.026719,   0.000000, -0.363000]),
        Atom::new("C", [-0.513360,  -0.889165, -0.363000]),
        Atom::new("C", [-0.513360,   0.889165, -0.363000])];
    
    // create a molecule from these atoms
    let mut mol = Molecule::from_atoms(atoms);
    
  2. Reading and writing molecules

    use gchemol::io;
    use gchemol::prelude::*;
    use gchemol::Molecule;
    
    // Read an xyz file and write to a Gaussian Input file.
    let mol = Molecule::from_file("path/to/file.xyz")?;
    mol.to_file("methane.gjf")?;
    
    // get the total number of atoms
    let na = mol.natoms();
    // get the total number of bonds
    let nb = mol.nbonds();
    
    // read multiple molecules (trajectory) from a chemical file
    // the number of atoms in different frame could be different
    let mols = io::read("path/to/trajectory.xyz")?;
    

Related projects

References

Dependencies

~28–40MB
~694K SLoC