Hello, hoomd-rs!
You don’t need to install anything other than Rust to use hoomd-rs.
Rust comes packaged with Cargo. Use Cargo to create a
hello-hoomd-rs crate:
$ cargo new hello-hoomd-rs
$ cd hello-hoomd-rs
This example uses the hoomd-interaction crate. Add it to your
dependencies with:
$ cargo add hoomd-interaction
Cargo creates a “Hello, world” application by default.
Replace src/main.rs with:
use hoomd_interaction::univariate::{LennardJones, UnivariateEnergy};
fn main() {
let lennard_jones: LennardJones = LennardJones::default();
println!("lennard_jones(1.5): {}", lennard_jones.energy(1.5));
}
Compile and run the code:
$ cargo run
You should see a number of compiling… messages and then:
lennard_jones(1.5): -0.32033659427857464
Congratulations for making it this far! You have successfully compiled hoomd-rs and used it to compute the Lennard-Jones potential at a given r value. Read the following tutorials to learn how to perform Monte Carlo and molecular dynamics simulations using hoomd-rs.
Tip
cargo runbuilds in debug mode by default. Debug builds make it easier to troubleshoot problems with your code, but they run very slowly. When your code is working, build in release mode and it will run much faster:$ cargo run --release
Note
On HPC platforms, you should run (preferably in an interactive compute job):
$ cargo build --releaseYou can then use the executable placed in the
target/releasedirectory in your submitted job scripts. For more details, see the workflow tutorial.Unlike scripting languages (e.g. Python), saving changes to
main.rswill NOT take effect until you runcargo build --releaseagain.
Development of hoomd-rs is led by the Glotzer Group at the University of Michigan.
Copyright © 2024-2026 The Regents of the University of Michigan.