Skip to content

Commit

Permalink
Merge pull request #9 from seatonullberg/dev
Browse files Browse the repository at this point in the history
v0.3.0
  • Loading branch information
seatonullberg authored Dec 19, 2020
2 parents e109a73 + bc550c6 commit 15fbddf
Show file tree
Hide file tree
Showing 222 changed files with 22,511 additions and 447 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.0] - 2020-12-18

### Fixed

* Bug in loading `Cell` from POSCAR data.

### Added

* Additional benchmark tests.
* HDF5 output support.
* Round-trip serialization for `Simulation`.
* User defined `Configuration`.
* `Propagator` interface.
* `prelude` module.
* CLI tool to convert POSCAR data to the internal data format.

## [0.2.1] - 2020-12-15

### Fixed
Expand Down
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "velvet"
version = "0.2.1"
version = "0.3.0"
authors = ["Seaton Ullberg <[email protected]>"]
edition = "2018"
repository = "https://github.com/seatonullberg/velvet"
Expand All @@ -19,17 +19,18 @@ categories = [

[workspace]
members = [
"crates/app",
"crates/cli",
"crates/convert",
"crates/core",
"crates/test-utils",
]

[dependencies]
velvet-convert = { path = "crates/convert", version = "0.1.0" }
velvet-core = { path = "crates/core", version = "0.2.1" }
velvet-convert = { path = "crates/convert", version = "0.1.2" }
velvet-core = { path = "crates/core", version = "0.3.1" }

[dev-dependencies]
indicatif = "0.15"
hdf5 = "0.7"
log = "0.4"
plotters = "0.3.0"
pretty_env_logger = "0.4"
pretty_env_logger = "0.4"
Binary file modified assets/nve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/nvt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions crates/app/src/main.rs

This file was deleted.

18 changes: 18 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "velvet-cli"
version = "0.1.1"
authors = ["Seaton Ullberg <[email protected]>"]
description = "Command line tool built on top of the Velvet API"
license = "MIT"
repository = "https://github.com/seatonullberg/velvet"
edition = "2018"

[dependencies]
clap = "2.33"
ron = "0.6"
velvet-convert = { path = "../convert", version = "0.1.2" }
velvet-core = { path = "../core", version = "0.3.0" }

[[bin]]
name = "velvet"
path = "src/main.rs"
66 changes: 66 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;

use clap::{arg_enum, value_t, App, Arg, ArgMatches, SubCommand};
use ron::ser::{to_string_pretty, PrettyConfig};

use velvet_convert::poscar::load_poscar;

arg_enum! {
#[derive(PartialEq, Debug)]
pub enum FileFormat {
Poscar,
}
}

fn main() {
let matches = App::new("Velvet CLI")
.version("0.1.0")
.author("Seaton Ullberg <[email protected]>")
.about("Command line tool built on top of the Velvet API")
.subcommand(
SubCommand::with_name("convert")
.about("convert external data formats into Velvet's internal format")
.arg(
Arg::with_name("src")
.index(1)
.takes_value(true)
.required(true)
.help("source filepath"),
)
.arg(
Arg::with_name("dst")
.index(2)
.takes_value(true)
.required(true)
.help("destination filepath"),
)
.arg(
Arg::with_name("format")
.short("f")
.long("format")
.takes_value(true)
.possible_values(&FileFormat::variants())
.case_insensitive(true),
),
)
.get_matches();

if let Some(matches) = matches.subcommand_matches("convert") {
handle_convert(matches)
}
}

fn handle_convert(matches: &ArgMatches) {
let file = File::open(matches.value_of("src").unwrap()).unwrap();
let buf = BufReader::new(file);
let fmt = value_t!(matches, "format", FileFormat).unwrap();
let system = match fmt {
FileFormat::Poscar => load_poscar(buf),
};
let pretty = PrettyConfig::new().with_decimal_floats(true);
let res = to_string_pretty(&system, pretty).unwrap();
let mut file = File::create(matches.value_of("dst").unwrap()).unwrap();
file.write_all(res.as_bytes()).unwrap();
}
4 changes: 2 additions & 2 deletions crates/convert/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "velvet-convert"
version = "0.1.0"
version = "0.1.2"
authors = ["Seaton Ullberg <[email protected]>"]
description = "Convert external file formats into Velvet data structures."
license = "MIT"
Expand All @@ -10,4 +10,4 @@ edition = "2018"
[dependencies]
nalgebra = "0.23"
vasp-poscar = "0.3.2"
velvet-core = { path = "../core", version = "0.2.1" }
velvet-core = { path = "../core", version = "0.3.0" }
16 changes: 14 additions & 2 deletions crates/convert/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
//! Convert external file formats into Velvet data structures.
mod poscar;
pub use poscar::load_poscar;
pub mod poscar;

pub mod prelude {
pub use super::poscar::*;
}

#[allow(dead_code)]
fn test_resources_path(filename: &str) -> String {
format!(
"{}/../../resources/test/{}",
env!("CARGO_MANIFEST_DIR"),
filename
)
}
61 changes: 34 additions & 27 deletions crates/convert/src/poscar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use std::str::FromStr;
use nalgebra::{Matrix3, Vector3};
use vasp_poscar::Poscar;

use velvet_core::system::cell::Cell;
use velvet_core::system::elements::Element;
use velvet_core::system::{System, SystemBuilder};
use velvet_core::prelude::*;

/// Returns a [`System`](velvet_core::system::System) object initialized from POSCAR formatted data.
///
Expand All @@ -19,7 +17,7 @@ use velvet_core::system::{System, SystemBuilder};
///
/// ```
/// use velvet_core::system::System;
/// use velvet_convert::load_poscar;
/// use velvet_convert::poscar::load_poscar;
///
/// let system = load_poscar("\
/// Cubic BN
Expand All @@ -40,78 +38,87 @@ pub fn load_poscar<R>(reader: R) -> System
where
R: BufRead,
{
// load the poscar file
// Load the poscar file from a reader.
let poscar = Poscar::from_reader(reader).unwrap();

// system size alias
// Alias for the system size.
let size = poscar.num_sites();

// initialize the system builder
let mut builder = SystemBuilder::new(size);

// set system cell
// Set system cell.
let vecs = poscar.scaled_lattice_vectors();
let matrix: Matrix3<f32> = Matrix3::new(
vecs[0][0] as f32,
vecs[1][0] as f32,
vecs[2][0] as f32,
vecs[0][1] as f32,
vecs[1][1] as f32,
vecs[1][1] as f32,
vecs[2][1] as f32,
vecs[0][2] as f32,
vecs[1][2] as f32,
vecs[2][2] as f32,
);
let cell = Cell::from_matrix(matrix);
builder.with_cell(cell);
builder = builder.with_cell(cell);

// set system elements if they exist
// Set system elements if they exist.
// Panic if they do not exist.
//
// TODO: change this panic to a result.
match poscar.site_symbols() {
Some(symbols) => {
let elements: Vec<Element> =
Vec::from_iter(symbols.map(|x| Element::from_str(x).unwrap()));
builder.with_elements(elements);
builder = builder.with_elements(elements)
}
None => panic!("POSCAR file is missing site symbols"),
}

// set the system positions
// Set system positions.
let positions: Vec<Vector3<f32>> = Vec::from_iter(
poscar
.scaled_cart_positions()
.iter()
.map(|x| Vector3::new(x[0] as f32, x[1] as f32, x[2] as f32)),
);
builder.with_positions(positions);
builder = builder.with_positions(positions);

// set the system velocities if they exist
match poscar.cart_velocities() {
Some(vels) => {
let velocities: Vec<Vector3<f32>> = Vec::from_iter(
vels.iter()
.map(|x| Vector3::new(x[0] as f32, x[1] as f32, x[2] as f32)),
);
builder.with_velocities(velocities);
}
None => {}
// Set system velocities if they exist.
if let Some(vels) = poscar.cart_velocities() {
let velocities: Vec<Vector3<f32>> = Vec::from_iter(
vels.iter()
.map(|x| Vector3::new(x[0] as f32, x[1] as f32, x[2] as f32)),
);
builder = builder.with_velocities(velocities);
};

// finish building and return the system
// Finish building and return the system.
builder.finish()
}

#[cfg(test)]
mod tests {
use super::load_poscar;
use crate::test_resources_path;
use std::fs::File;
use std::io::BufReader;
use velvet_core::utils::test_path;

#[test]
fn argon() {
let file = File::open(test_path("argon.poscar")).unwrap();
let file = File::open(test_resources_path("argon.poscar")).unwrap();
let reader = BufReader::new(file);
let sys = load_poscar(reader);

println!("{:?}", sys.cell);

let a0 = 21.152895;
assert_eq!(sys.size(), 108);
assert_eq!(sys.cell.a(), a0);
assert_eq!(sys.cell.b(), a0);
assert_eq!(sys.cell.c(), a0);
assert_eq!(sys.cell.alpha(), 90.0);
assert_eq!(sys.cell.beta(), 90.0);
assert_eq!(sys.cell.gamma(), 90.0);
}
}
20 changes: 15 additions & 5 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
[package]
name = "velvet-core"
version = "0.2.1"
version = "0.3.1"
authors = ["Seaton Ullberg <[email protected]>"]
description = "Core feature library for the Velvet simulation engine."
license = "MIT"
repository = "https://github.com/seatonullberg/velvet"
edition = "2018"

[dependencies]
hdf5 = "0.7"
indicatif = "0.15"
log = "0.4"
nalgebra = {version = "0.23", features = ["serde-serialize"]}
rand = "0.7"
pretty_env_logger = "0.4"
rand = {version = "0.7", features = ["serde1"] }
rand_distr = "0.3"
ron = "0.6"
serde = {version = "1.0", features = ["derive"]}
strum = "0.20"
strum_macros = "0.20"
Expand All @@ -20,7 +23,9 @@ typetag = "0.1.6"
[dev-dependencies]
approx = "0.4"
criterion = "0.3"
velvet-convert = { path = "../convert" }
ron = "0.6"
test-utils = { path = "../test-utils" }
velvet-convert = { path = "../convert", version = "0.1.2" }

[[bench]]
name = "integrator-benchmarks"
Expand All @@ -35,4 +40,9 @@ harness = false
[[bench]]
name = "thermostat-benchmarks"
path = "benches/thermostats.rs"
harness = false
harness = false

[[bench]]
name = "pair-potential-benchmarks"
path = "benches/potentials/pair.rs"
harness = false
20 changes: 15 additions & 5 deletions crates/core/benches/integrators.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
use criterion::{criterion_group, criterion_main, Criterion};
use std::fs::File;
use std::io::BufReader;
use velvet_convert::load_poscar;
use velvet_convert::poscar::load_poscar;
use velvet_core::distributions::{Boltzmann, VelocityDistribution};
use velvet_core::integrators::{Integrator, VelocityVerlet};
use velvet_core::utils::{load_test_potentials, test_path};
use velvet_core::potentials::Potentials;
use test_utils::test_resources_path;

pub fn velocity_verlet_benchmark(c: &mut Criterion) {
let file = File::open(test_path("argon.poscar")).unwrap();
let file = File::open(test_resources_path("argon.poscar")).unwrap();
let reader = BufReader::new(file);
let mut sys = load_poscar(reader);
let pots = load_test_potentials("argon");

let target = 100 as f32;
let boltz = Boltzmann::new(target);
boltz.apply(&mut sys);

// load potentials
let path = test_resources_path("argon.pot.velvet");
let file = File::open(&path).unwrap();
let pots: Potentials = ron::de::from_reader(file).unwrap();

let mut vv = VelocityVerlet::new(1.0);
vv.setup(&sys, &pots);

c.bench_function("velocity verlet argon", |b| {
c.bench_function("velocity_verlet", |b| {
b.iter(|| vv.integrate(&mut sys, &pots))
});
}
Expand Down
Loading

0 comments on commit 15fbddf

Please sign in to comment.