Skip to content

Commit

Permalink
fix lattice creators (#50)
Browse files Browse the repository at this point in the history
* Fix bug on bcc lattice

* Fix bug on bcc lattice

* Add fcc lattice
  • Loading branch information
odarbelaeze committed Aug 26, 2024
1 parent 45c5a24 commit 4acff4b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ impl Lattice {

/// Create a body centered cubic lattice with the given size _a_
pub fn bcc(a: f64) -> Self {
let sites = vec![Site::new("A"), Site::new("B")];
let sites = vec![
Site::new("A"),
Site::new("B").with_position((0.5 * a, 0.5 * a, 0.5 * a)),
];
let vertices = vec![
Vertex::new(0, 1, (0, 0, 0)),
Vertex::new(0, 1, (0, -1, 0)),
Expand All @@ -69,6 +72,38 @@ impl Lattice {
}
}

/// Create a face centered cubic lattice with lattice parameter _a_
pub fn fcc(a: f64) -> Self {
let sites = vec![
Site::new("A"),
Site::new("B").with_position((0.5 * a, 0.5 * a, 0.0)),
Site::new("C").with_position((0.5 * a, 0.0, 0.5 * a)),
Site::new("D").with_position((0.0, 0.5 * a, 0.5 * a)),
];
let vertices = vec![
// xy plane
Vertex::new(0, 1, (0, 0, 0)),
Vertex::new(0, 1, (-1, 0, 0)),
Vertex::new(0, 1, (-1, -1, 0)),
Vertex::new(0, 1, (0, -1, 0)),
// xz plane
Vertex::new(0, 2, (0, 0, 0)),
Vertex::new(0, 2, (-1, 0, 0)),
Vertex::new(0, 2, (-1, 0, -1)),
Vertex::new(0, 2, (0, 0, -1)),
// yz plane
Vertex::new(0, 3, (0, 0, 0)),
Vertex::new(0, 3, (0, -1, 0)),
Vertex::new(0, 3, (0, -1, -1)),
Vertex::new(0, 3, (0, 0, -1)),
];
Lattice {
size: (a, a, a),
sites,
vertices,
}
}

/// Get the size of the lattice
pub fn size(&self) -> (f64, f64, f64) {
self.size
Expand Down
18 changes: 18 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ fn main() {
.help("Lattice parameter"),
),
)
.subcommand(
Command::new("fcc")
.about("Face centered cubic lattice")
.arg(
Arg::new("a")
.long("lattice-parameter")
.short('a')
.default_value("1.0")
.value_parser(|s: &str| s.parse::<f64>())
.help("Lattice parameter"),
),
)
.subcommand(
Command::new("check")
.about("Check lattice")
Expand Down Expand Up @@ -293,6 +305,12 @@ fn main() {
write(lattice);
Ok(())
}
Some(("fcc", sub_matches)) => {
let a = sub_matches.get_one::<f64>("a").unwrap();
let lattice = Lattice::fcc(*a);
write(lattice);
Ok(())
}
Some(("check", sub_matches)) => {
let input = sub_matches.get_one::<String>("input").map(|s| s.as_str());
check(input)
Expand Down

0 comments on commit 4acff4b

Please sign in to comment.