CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
FileEnumerator.hh
Go to the documentation of this file.
1 #ifndef CASM_FileEnumerator
2 #define CASM_FileEnumerator
3 
4 #include "casm/clex/PrimClex.hh"
6 
7 
8 namespace CASM {
9 
10  // -- Get lists of files -----------------------------
11 
17 
18  public:
19 
22  const PrimClex &_primclex,
23  bool _all_settings = false,
24  bool _relative = false);
25 
27  template<typename OutputIterator>
28  OutputIterator basic_files(OutputIterator result);
29 
31  template<typename OutputIterator>
32  OutputIterator bset_files(OutputIterator result);
33 
35  template<typename OutputIterator>
36  OutputIterator reference_files(OutputIterator result);
37 
39  template<typename OutputIterator>
40  OutputIterator eci_files(OutputIterator result);
41 
43  template<typename OutputIterator>
44  OutputIterator calc_settings_files(OutputIterator result);
45 
47  template<typename OutputIterator>
48  OutputIterator calc_status_files(OutputIterator result);
49 
51  template<typename OutputIterator>
52  OutputIterator all_calc_files(OutputIterator result);
53 
54 
55  private:
56 
59 
61  template<typename OutputIterator>
62  OutputIterator _if_exists(OutputIterator result, fs::path path);
63 
65  template<typename OutputIterator>
66  OutputIterator _all_that_exist(OutputIterator result, fs::path location);
67 
68 
69 
74  bool m_relative;
75 
76  std::vector<std::string> m_all_bset;
77  std::vector<std::string> m_all_calctype;
78  std::vector<std::string> m_all_property;
79 
80  };
81 
93  const PrimClex &_primclex,
94  bool _all_settings,
95  bool _relative) :
96 
97  m_primclex(_primclex),
98  m_dir(m_primclex.dir()),
99  m_set(m_primclex.settings()),
100  m_all_settings(_all_settings),
101  m_relative(_relative),
102  m_all_bset(m_dir.all_bset()),
103  m_all_calctype(m_dir.all_calctype()),
104  m_all_property(m_dir.all_property()) {}
105 
106 
109  if(m_relative) {
110  auto a = m_primclex.get_path().string().size() + 1;
111  auto b = path.string().size();
112  return fs::path(path.string().substr(a, b));
113  }
114  return path;
115  }
116 
118  template<typename OutputIterator>
119  OutputIterator FileEnumerator::_if_exists(OutputIterator result, fs::path path) {
120  if(fs::exists(path)) {
121  *result++ = _if_relative(path);
122  }
123  return result;
124  }
125 
127  template<typename OutputIterator>
128  OutputIterator FileEnumerator::_all_that_exist(OutputIterator result, fs::path location) {
129  std::vector<fs::path> all;
130  std::string dir;
131 
132  // get all
133  if(!fs::exists(location)) {
134  return result;
135  }
136  fs::directory_iterator it(location);
137  fs::directory_iterator end_it;
138  for(; it != end_it; ++it) {
139  if(fs::is_regular_file(*it)) {
140  *result++ = _if_relative(it->path());
141  }
142  }
143  return result;
144  }
145 
157  template<typename OutputIterator>
158  OutputIterator FileEnumerator::basic_files(OutputIterator result) {
159  std::vector<fs::path> v {
160  m_dir.prim(), m_dir.PRIM(),
163  };
164  for(auto it = v.begin(); it != v.end(); ++it) {
165  result = _if_exists(result, *it);
166  }
167  result = _all_that_exist(result, m_dir.enumerator_plugins());
168  return result;
169  }
170 
177  template<typename OutputIterator>
178  OutputIterator FileEnumerator::bset_files(OutputIterator result) {
179 
180  // bset dependent:
181  for(auto bset : m_all_bset) {
182  if(!m_all_settings && bset != m_set.default_clex().bset) {
183  continue;
184  }
185  result = _if_exists(result, m_dir.bspecs(bset));
186  result = _if_exists(result, m_dir.clust(bset));
187  result = _if_exists(result, m_dir.basis(bset));
188  result = _if_exists(result, m_dir.clexulator_src(m_set.name(), bset));
189  }
190  return result;
191  }
192 
197  template<typename OutputIterator>
198  OutputIterator FileEnumerator::reference_files(OutputIterator result) {
199 
200  // calctype / ref dependent
201  for(auto calctype : m_all_calctype) {
203  continue;
204  }
205  auto all_ref = m_dir.all_ref(calctype);
206  for(auto ref : all_ref) {
207  if(!m_all_settings && ref != m_set.default_clex().ref) {
208  continue;
209  }
210  result = _if_exists(result, m_dir.composition_axes());
211  result = _if_exists(result, m_dir.chemical_reference(calctype, ref));
212  }
213  }
214  return result;
215  }
216 
221  template<typename OutputIterator>
222  OutputIterator FileEnumerator::eci_files(OutputIterator result) {
223 
224  // eci
225  if(!m_all_settings) {
228  }
229  else {
230 
231  for(auto clex : m_all_property) {
232  for(auto calctype : m_all_calctype) {
233  auto all_ref = m_dir.all_ref(calctype);
234  for(auto ref : all_ref) {
235  for(auto bset : m_all_bset) {
236  auto all_eci = m_dir.all_eci(clex, calctype, ref, bset);
237  for(auto eci : all_eci) {
238  result = _if_exists(result, m_dir.eci(clex, calctype, ref, bset, eci));
239  result = _if_exists(result, m_dir.eci_out(clex, calctype, ref, bset, eci));
240  }
241  }
242  }
243  }
244  }
245 
246  }
247  return result;
248  }
249 
253  template<typename OutputIterator>
254  OutputIterator FileEnumerator::calc_settings_files(OutputIterator result) {
255 
256  for(auto calctype : m_all_calctype) {
258  continue;
259  }
260 
261  auto scel_begin = m_primclex.get_supercell_list().begin();
262  auto scel_end = m_primclex.get_supercell_list().end();
263 
264  // calculation settings: global
265  result = _all_that_exist(result, m_dir.calc_settings_dir(calctype));
266 
267  // supercell level
268  for(auto scel_it = scel_begin; scel_it != scel_end; ++scel_it) {
269  result = _all_that_exist(result, m_dir.supercell_calc_settings_dir(scel_it->get_name(), calctype));
270  }
271 
272  auto begin = m_primclex.config_begin();
273  auto end = m_primclex.config_end();
274 
275  // configuration level
276  for(auto it = begin; it != end; ++it) {
277  result = _all_that_exist(result, m_dir.configuration_calc_settings_dir(it->name(), calctype));
278  }
279  }
280  return result;
281  }
282 
286  template<typename OutputIterator>
287  OutputIterator FileEnumerator::calc_status_files(OutputIterator result) {
288 
289  for(auto calctype : m_all_calctype) {
291  continue;
292  }
293 
294  auto begin = m_primclex.config_begin();
295  auto end = m_primclex.config_end();
296 
297  // calculation summaries: properties.calc.json, status.json
298  for(auto it = begin; it != end; ++it) {
299  result = _if_exists(result, m_dir.calculated_properties(it->name(), calctype));
300  result = _if_exists(result, m_dir.calc_status(it->name(), calctype));
301  }
302 
303  }
304  return result;
305  }
306 
310  template<typename OutputIterator>
311  OutputIterator FileEnumerator::all_calc_files(OutputIterator result) {
312 
313  // get all files in 'training_data', recursively
314  fs::recursive_directory_iterator it(m_dir.training_data()), end;
315  std::string pattern = "calctype.";
316  for(; it != end; ++it) {
317 
318  // if not requesting all settings
319  if(!m_all_settings) {
320  // avoid recursing into other calctypes
321  if(fs::is_directory(*it)) {
322  std::string dir = it->path().filename().string();
323  if(dir.substr(0, pattern.size()) == pattern) {
324  if(dir.substr(pattern.size(), dir.size()) != m_set.default_clex().calctype) {
325  it.no_push();
326  }
327  }
328  }
329  }
330 
331  if(fs::is_regular_file(*it)) {
332  *result++ = _if_relative(it->path());
333  }
334  }
335  return result;
336  }
337 
338 }
339 
340 #endif
pair_type eci
Definition: settings.cc:112
fs::path eci(std::string property, std::string calctype, std::string ref, std::string bset, std::string eci) const
Returns path to eci.json.
const PrimClex & m_primclex
boost::container::stable_vector< Supercell > & get_supercell_list()
Access entire supercell_list.
Definition: PrimClex.cc:299
fs::path _if_relative(fs::path path)
make paths relative to m_primclex.get_path() if m_relative
fs::path composition_axes() const
Return composition axes file path.
fs::path SCEL() const
Return SCEL path.
Specification of CASM project directory structure.
fs::path get_path() const
Return casm project directory path.
Definition: PrimClex.cc:202
OutputIterator _all_that_exist(OutputIterator result, fs::path location)
Get all regular files that exist in directory 'location'.
std::vector< std::string > m_all_property
fs::path calculated_properties(std::string configname, std::string calctype) const
Return calculated properties file path.
ProjectSettings m_set
fs::path calc_settings_dir(std::string calctype) const
Return calculation settings directory path, for global settings.
DirectoryStructure m_dir
fs::path supercell_calc_settings_dir(std::string scelname, std::string calctype) const
Return calculation settings directory path, for supercell specific settings.
fs::path configuration_calc_settings_dir(std::string configname, std::string calctype) const
Return calculation settings directory path, for configuration specific settings.
Main CASM namespace.
Definition: complete.cpp:8
fs::path prim() const
Return prim.json path.
std::vector< std::string > all_eci(std::string property, std::string calctype, std::string ref, std::string bset) const
Check filesystem directory structure and return list of all eci names.
config_iterator config_begin()
Configuration iterator: begin.
Definition: PrimClex.cc:371
config_iterator config_end()
Configuration iterator: end.
Definition: PrimClex.cc:379
OutputIterator all_calc_files(OutputIterator result)
Enumerate all training data files.
fs::path enumerator_plugins() const
Return enumerators plugin dir.
OutputIterator calc_settings_files(OutputIterator result)
Enumerate calculation settings files.
pair_type ref
Definition: settings.cc:110
fs::path bspecs(std::string bset) const
Return basis function specs (bspecs.json) file path.
std::string name() const
Get project name.
fs::path crystal_point_group() const
Return crystal_point_group.json path.
std::vector< std::string > m_all_calctype
OutputIterator basic_files(OutputIterator result)
Enumerate all setting independent files.
Read/modify settings of an already existing CASM project.
fs::path project_settings() const
Return project_settings.json path.
OutputIterator calc_status_files(OutputIterator result)
Enumerate calculation status files.
fs::path clust(std::string bset) const
fs::path eci_out(std::string property, std::string calctype, std::string ref, std::string bset, std::string eci) const
Returns path to eci.out.
fs::path clexulator_src(std::string project, std::string bset) const
Returns path to global clexulator source file.
pair_type calctype
Definition: settings.cc:109
OutputIterator eci_files(OutputIterator result)
Enumerate eci files.
fs::path basis(std::string bset) const
fs::path PRIM() const
Return PRIM path.
OutputIterator _if_exists(OutputIterator result, fs::path path)
output path if it exists
OutputIterator reference_files(OutputIterator result)
Enumerate reference files.
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
fs::path calc_status(std::string configname, std::string calctype) const
Return calculation status file path.
fs::path lattice_point_group() const
Return lattice_point_group.json path.
Lists all files in a CASM project, for use with 'casm files' command.
DirectoryStructure & dir
Definition: settings.cc:102
fs::path config_list() const
Return master config_list.json file path.
OutputIterator bset_files(OutputIterator result)
Enumerate bset files.
FileEnumerator(const PrimClex &_primclex, bool _all_settings=false, bool _relative=false)
A CASM project file enumerator.
pair_type bset
Definition: settings.cc:111
fs::path factor_group() const
Return factor_group.json path.
std::vector< std::string > m_all_bset
const ClexDescription & default_clex() const
fs::path chemical_reference(std::string calctype, std::string ref) const
Return chemical reference file path.
std::vector< std::string > all_ref(std::string calctype) const
Check filesystem directory structure and return list of all ref names for a given calctype...
fs::path training_data() const
Return 'training_data' directorty path.