construct3/support/
mod.rs1use lattice_core::Graph;
2use std::path::PathBuf;
3
4pub fn print_graph(graph: &Graph) {
5 println!("dimension = {}", graph.dimension());
6 println!("sites = {}", graph.num_sites());
7 println!("bonds = {}", graph.num_bonds());
8
9 for site in 0..graph.num_sites() {
10 let coordinate = graph.coordinate(site);
11 let coordinate_text = if coordinate.is_empty() {
12 "[]".to_string()
13 } else {
14 let joined = coordinate
15 .iter()
16 .map(|value| format!("{value:.6}"))
17 .collect::<Vec<_>>()
18 .join(", ");
19 format!("[{joined}]")
20 };
21
22 let neighbors = (0..graph.num_neighbors(site))
23 .map(|k| graph.neighbor(site, k).to_string())
24 .collect::<Vec<_>>()
25 .join(", ");
26
27 println!(
28 "site {site}: type={} coord={} neighbors=[{}]",
29 graph.site_type(site),
30 coordinate_text,
31 neighbors
32 );
33 }
34
35 for bond in 0..graph.num_bonds() {
36 println!(
37 "bond {bond}: {} <-> {} type={}",
38 graph.source(bond),
39 graph.target(bond),
40 graph.bond_type(bond)
41 );
42 }
43}
44
45#[allow(dead_code)]
46pub fn resolve_lattices_xml() -> Result<PathBuf, String> {
47 let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
48 let repo_root = manifest_dir
49 .parent()
50 .and_then(|path| path.parent())
51 .ok_or_else(|| "failed to locate repository root from CARGO_MANIFEST_DIR".to_string())?;
52
53 let candidates = [
54 PathBuf::from("cxx/example/lattices.xml"),
55 PathBuf::from("example/lattices.xml"),
56 PathBuf::from("lattices.xml"),
57 repo_root.join("cxx/example/lattices.xml"),
58 ];
59
60 for candidate in candidates {
61 if candidate.exists() {
62 return Ok(candidate);
63 }
64 }
65
66 Err("could not find lattices.xml (tried cxx/example/lattices.xml, example/lattices.xml, and lattices.xml)".to_string())
67}