Skip to main content

construct_xml/
construct_xml.rs

1use lattice_core::{read_basis_from_file, read_unitcell_from_file, Boundary, ExtentVector, Graph};
2
3#[path = "support/mod.rs"]
4mod support;
5
6fn main() {
7    let args = std::env::args().collect::<Vec<_>>();
8
9    let mut file = support::resolve_lattices_xml().unwrap_or_else(|message| {
10        eprintln!("Error: {message}");
11        std::process::exit(127);
12    });
13    let mut basis_name = "square lattice".to_string();
14    let mut cell_name = "simple2d".to_string();
15    let mut length: usize = 4;
16
17    if args.len() > 1 {
18        if args.len() == 4 || args.len() == 5 {
19            file = std::path::PathBuf::from(&args[1]);
20            basis_name = args[2].clone();
21            cell_name = args[3].clone();
22            if args.len() == 5 {
23                length = args[4].parse::<usize>().unwrap_or_else(|_| {
24                    eprintln!("Error: invalid length: {}", args[4]);
25                    std::process::exit(127);
26                });
27            }
28        } else {
29            eprintln!("Error: {} xmlfile basis cell [length]", args[0]);
30            std::process::exit(127);
31        }
32    }
33
34    let basis = read_basis_from_file(&file, &basis_name).unwrap_or_else(|error| {
35        eprintln!("Failed to read basis XML entry '{basis_name}': {error}");
36        std::process::exit(127);
37    });
38
39    let cell = read_unitcell_from_file(&file, &cell_name).unwrap_or_else(|error| {
40        eprintln!("Failed to read unitcell XML entry '{cell_name}': {error}");
41        std::process::exit(127);
42    });
43
44    let extent = ExtentVector::from_element(cell.dimension(), length as i64);
45    let boundary = vec![Boundary::Periodic; cell.dimension()];
46    let graph = Graph::from_basis_unitcell_extent(&basis, &cell, &extent, &boundary);
47
48    support::print_graph(&graph);
49}