1mod auxiliary;
2mod error;
3mod export;
4mod root;
5mod seed;
6
7pub use crate::root::RootJobs;
8pub use error::SeedingErrors;
9pub use seed::parse_cell_doc_from_path;
10pub use seed::seed_folder::SeedFolder;
11pub use seed::seed_setup::{CellBuilding, ParamBuilding};
12
13#[cfg(test)]
14mod test {
15 use crate::CellBuilding;
17 use crate::ParamBuilding;
18 use castep_cell_io::cell_document::{CellDocument, KpointQuality};
19 use castep_param_io::param::CastepParam;
20 use std::path::{Path, PathBuf};
21
22 use crate::{
23 seed::{parse_cell_doc_from_path, seed_folder::SeedFolder},
24 RootJobs, SeedingErrors,
25 };
26
27 struct RootFolder {
28 path: PathBuf,
29 }
30
31 impl RootFolder {
32 fn new<P: AsRef<Path>>(path: P) -> Self {
33 Self {
34 path: path.as_ref().into(),
35 }
36 }
37 }
38
39 struct Seed<P: AsRef<Path>> {
40 cell_path: P,
41 cell_doc: CellDocument,
42 }
43
44 impl<P: AsRef<Path>> Seed<P> {
45 fn from_cell_path(cell_path: P) -> Result<Self, SeedingErrors> {
46 let cell_doc = parse_cell_doc_from_path(&cell_path)?;
47 Ok(Self {
48 cell_path,
49 cell_doc,
50 })
51 }
52 }
53
54 impl<P> SeedFolder for Seed<P>
55 where
56 P: AsRef<Path> + std::marker::Send,
57 {
58 fn seed_name(&self) -> &str {
59 self.cell_path
60 .as_ref()
61 .file_stem()
62 .unwrap()
63 .to_str()
64 .unwrap()
65 }
66
67 fn root_dir(&self) -> impl AsRef<Path> {
68 self.cell_path.as_ref().parent().unwrap()
69 }
70
71 fn cell_template(&self) -> &CellDocument {
72 &self.cell_doc
73 }
74 }
75
76 impl RootJobs for RootFolder {
77 fn root_path(&self) -> impl AsRef<Path> {
78 &self.path
79 }
80
81 fn generate_seed_folders(&self) -> Result<Vec<impl SeedFolder>, crate::SeedingErrors> {
82 self.get_cell_paths()?
83 .into_iter()
84 .map(Seed::from_cell_path)
85 .collect()
86 }
87 }
88
89 struct Configurator {
90 use_edft: bool,
91 kpoint_quality: KpointQuality,
92 potentials_loc: PathBuf,
93 }
94
95 impl Configurator {
96 fn new<P: AsRef<Path>>(
97 use_edft: bool,
98 kpoint_quality: KpointQuality,
99 potentials_loc: P,
100 ) -> Self {
101 Self {
102 use_edft,
103 kpoint_quality,
104 potentials_loc: potentials_loc.as_ref().into(),
105 }
106 }
107 }
108
109 impl CellBuilding for Configurator {}
110
111 impl ParamBuilding for Configurator {
112 fn build_param_for_task(
113 &self,
114 template_cell: &CellDocument,
115 castep_task: castep_cell_io::CastepTask,
116 ) -> Result<CastepParam, SeedingErrors> {
117 match castep_task {
118 castep_cell_io::CastepTask::BandStructure => self.dos_param_template(
119 template_cell,
120 castep_cell_io::EnergyCutoff::Ultrafine,
121 self.use_edft,
122 &self.potentials_loc,
123 ),
124 castep_cell_io::CastepTask::GeometryOptimization => self.geom_opt_param_template(
125 template_cell,
126 castep_cell_io::EnergyCutoff::Ultrafine,
127 self.use_edft,
128 &self.potentials_loc,
129 ),
130 }
131 }
132 }
133
134 #[test]
135 fn execution() {
136 let test_folder = RootFolder::new("test/Bi2Te3_001_Fe_2.2");
137 let potentials_loc = "/Users/tonywu/Downloads/Potentials";
138 let config = Configurator::new(true, KpointQuality::Coarse, potentials_loc);
139 match test_folder.build_all(&config, &config, potentials_loc) {
140 Ok(()) => {
141 println!("Success")
142 }
143 Err(e) => println!("{e}"),
144 }
145 }
146}