CASM  1.1.0
A Clusters Approach to Statistical Mechanics
MonteIO.hh
Go to the documentation of this file.
1 #ifndef CASM_MonteIO_HH
2 #define CASM_MonteIO_HH
3 
4 #include <boost/filesystem/path.hpp>
5 #include <string>
6 
10 
11 namespace CASM {
12 
13 class Log;
14 template <typename ValueType, typename DataObject>
15 class GenericDatumFormatter;
16 template <typename DataObject>
17 class DataFormatter;
18 
19 } // namespace CASM
20 
21 namespace CASM {
22 namespace Monte {
23 
25  public:
27 
29  fs::path output_dir() const { return m_output_dir; }
30 
32  fs::path results_csv() const { return m_output_dir / "results.csv"; }
33 
35  fs::path results_json() const { return m_output_dir / "results.json"; }
36 
38  fs::path conditions_dir(int cond_index) const {
39  return m_output_dir /
40  (std::string("conditions.") + std::to_string(cond_index));
41  }
42 
44  fs::path conditions_json(int cond_index) const {
45  return conditions_dir(cond_index) / "conditions.json";
46  }
47 
49  fs::path observations_csv(int cond_index) const {
50  return conditions_dir(cond_index) / "observations.csv";
51  }
52 
54  fs::path observations_json(int cond_index) const {
55  return conditions_dir(cond_index) / "observations.json";
56  }
57 
59  fs::path trajectory_csv(int cond_index) const {
60  return conditions_dir(cond_index) / "trajectory.csv";
61  }
62 
64  fs::path trajectory_json(int cond_index) const {
65  return conditions_dir(cond_index) / "trajectory.json";
66  }
67 
69  fs::path trajectory_dir(int cond_index) const {
70  return conditions_dir(cond_index) / "trajectory";
71  }
72 
74  fs::path POSCAR_initial(int cond_index) {
75  return trajectory_dir(cond_index) / std::string("POSCAR.initial");
76  }
77 
79  fs::path POSCAR_final(int cond_index) {
80  return trajectory_dir(cond_index) / std::string("POSCAR.final");
81  }
82 
84  fs::path POSCAR_snapshot(int cond_index, size_type sample_index) {
85  return trajectory_dir(cond_index) /
86  (std::string("POSCAR.") + std::to_string(sample_index));
87  }
88 
92  fs::path initial_state_firstruneq_json(int cond_index) const {
93  return conditions_dir(cond_index) / "initial_state_firstruneq.json";
94  }
95 
99  fs::path initial_state_runeq_json(int cond_index) const {
100  return conditions_dir(cond_index) / "initial_state_runeq.json";
101  }
102 
106  fs::path initial_state_json(int cond_index) const {
107  return conditions_dir(cond_index) / "initial_state.json";
108  }
109 
111  fs::path final_state_json(int cond_index) const {
112  return conditions_dir(cond_index) / "final_state.json";
113  }
114 
116  fs::path occupation_key_csv() const {
117  return output_dir() / "occupation_key.csv";
118  }
119 
121  fs::path occupation_key_json() const {
122  return output_dir() / "occupation_key.json";
123  }
124 
125  private:
126  fs::path m_output_dir;
127 };
128 
129 class MonteCarlo;
130 class MonteSettings;
131 
133 typedef const MonteCarlo *ConstMonteCarloPtr;
134 
137  std::string prop_name);
138 
141  std::string prop_name);
142 
144 struct CovEvaluator {
145  CovEvaluator(std::string _prop_name1, std::string _prop_name2)
146  : prop_name1(_prop_name1), prop_name2(_prop_name2) {}
147 
148  double operator()(const ConstMonteCarloPtr &mc);
149 
150  std::string prop_name1;
151  std::string prop_name2;
152 };
153 
156  std::string prop_name1, std::string prop_name2);
157 
162 
166 
168 template <typename MonteType>
170 
172 template <typename MonteType>
174 
176 template <typename MonteType>
178 MonteCarloParamChemPotFormatter(const MonteType &mc, int index);
179 
181 template <typename MonteType>
183  const MonteType &mc, int index);
184 
186 template <typename MonteType>
188  const MonteType &mc, int index);
189 
191 template <typename MonteType>
193  const MonteType &mc, int index);
194 
196 template <typename MonteType>
199 
201 template <typename MonteType>
203  std::string comp_var_i, std::string comp_var_j);
204 
206 template <typename MonteType>
208  std::string species_i, std::string species_j);
209 
211 template <typename MonteType>
213 MonteCarloThermoChemSuscXFormatter(std::string comp_var_i);
214 
216 template <typename MonteType>
218 MonteCarloThermoChemSuscNFormatter(std::string species_i);
219 
224 
228 
232 
236 
239 MonteCarloObservationFormatter(std::string prop_name);
240 
244 
248 
252 
255 template <typename MonteType>
256 void write_results(const MonteSettings &settings, const MonteType &mc,
257  Log &_log);
258 
260 template <typename MonteType>
261 void write_conditions_json(const MonteSettings &settings, const MonteType &mc,
262  size_type cond_index, Log &_log);
263 
266 void write_observations(const MonteSettings &settings, const MonteCarlo &mc,
267  size_type cond_index, Log &_log);
268 
271 void write_trajectory(const MonteSettings &settings, const MonteCarlo &mc,
272  size_type cond_index, Log &_log);
273 
275 void write_POSCAR_initial(const MonteCarlo &mc, size_type cond_index,
276  Log &_log);
277 
279 void write_POSCAR_final(const MonteCarlo &mc, size_type cond_index, Log &_log);
280 
282 void write_POSCAR_trajectory(const MonteCarlo &mc, size_type cond_index,
283  Log &_log);
284 
285 } // namespace Monte
286 } // namespace CASM
287 
288 #endif
Extract data from objects of 'DataObject' class.
A DatumFormatter that returns a value of specified type, via functions that may be specified at runti...
Definition: Log.hh:48
fs::path POSCAR_final(int cond_index)
"output_dir/conditions.cond_index/trajectory/POSCAR.final"
Definition: MonteIO.hh:79
fs::path initial_state_json(int cond_index) const
"output_dir/conditions.cond_index/initial_state.json"
Definition: MonteIO.hh:106
fs::path final_state_json(int cond_index) const
"output_dir/conditions.cond_index/final_state.json"
Definition: MonteIO.hh:111
fs::path output_dir() const
"output_dir/"
Definition: MonteIO.hh:29
fs::path trajectory_dir(int cond_index) const
"output_dir/conditions.cond_index/trajectory"
Definition: MonteIO.hh:69
fs::path results_csv() const
Results summary: "output_dir/results.csv".
Definition: MonteIO.hh:32
fs::path occupation_key_json() const
"output_dir/occupation_key.csv"
Definition: MonteIO.hh:121
fs::path POSCAR_initial(int cond_index)
"output_dir/conditions.cond_index/trajectory/POSCAR.initial"
Definition: MonteIO.hh:74
fs::path results_json() const
Results summary: "output_dir/results.json".
Definition: MonteIO.hh:35
fs::path observations_csv(int cond_index) const
"output_dir/conditions.cond_index/observations.csv"
Definition: MonteIO.hh:49
fs::path initial_state_firstruneq_json(int cond_index) const
"output_dir/conditions.cond_index/initial_state_firstruneq.json"
Definition: MonteIO.hh:92
fs::path trajectory_csv(int cond_index) const
"output_dir/conditions.cond_index/trajectory.csv"
Definition: MonteIO.hh:59
fs::path initial_state_runeq_json(int cond_index) const
"output_dir/conditions.cond_index/final_state.json"
Definition: MonteIO.hh:99
fs::path conditions_json(int cond_index) const
"output_dir/conditions.cond_index/conditions.json"
Definition: MonteIO.hh:44
fs::path trajectory_json(int cond_index) const
"output_dir/conditions.cond_index/trajectory.json"
Definition: MonteIO.hh:64
fs::path occupation_key_csv() const
"output_dir/occupation_key.csv"
Definition: MonteIO.hh:116
fs::path POSCAR_snapshot(int cond_index, size_type sample_index)
"output_dir/conditions.cond_index/trajectory/POSCAR.sample"
Definition: MonteIO.hh:84
MonteCarloDirectoryStructure(fs::path output_dir)
Definition: MonteIO.cc:27
fs::path observations_json(int cond_index) const
"output_dir/conditions.cond_index/observations.json"
Definition: MonteIO.hh:54
fs::path conditions_dir(int cond_index) const
"output_dir/conditions.cond_index/"
Definition: MonteIO.hh:38
Interface base class for all types of Monte Carlo simulations (not meant to be used polymorphically)
Definition: MonteCarlo.hh:44
Settings for Monte Carlo calculations.
std::string to_string(ENUM val)
Return string representation of enum class.
Definition: io_traits.hh:172
GenericDatumFormatter< double, std::pair< ConstMonteCarloPtr, size_type > > MonteCarloObservationFormatter(std::string prop_name)
Print value of observation.
Definition: MonteIO.cc:184
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloPrecFormatter(std::string prop_name)
Print calculated precision of property values: prec(<prop_name>)
Definition: MonteIO.cc:49
void write_observations(const MonteSettings &settings, const MonteCarlo &mc, size_type cond_index, Log &_log)
Will create (and possibly overwrite) new file with all observations from run with conditions....
Definition: MonteIO.cc:260
void write_POSCAR_initial(const MonteCarlo &mc, size_type cond_index, Log &_log)
For the initial state, write a POSCAR file.
Definition: MonteIO.cc:429
const MonteCarlo * ConstMonteCarloPtr
const pointer to const MonteCarlo
Definition: CanonicalIO.hh:14
GenericDatumFormatter< size_type, std::pair< ConstMonteCarloPtr, size_type > > MonteCarloStepFormatter()
Print Step number of observation.
Definition: MonteIO.cc:172
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloSuscXFormatter(std::string comp_var_i, std::string comp_var_j)
Print parametric susceptibility, 'susc_x(a,b)'.
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloParamChemPotFormatter(const MonteType &mc, int index)
Print param_chem_pot(x)
Definition: MonteIO_impl.hh:49
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloChemPotFormatter(const MonteType &mc, int index)
Print chem_pot(N)
Definition: MonteIO_impl.hh:64
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloTFormatter()
Print Temperature.
Definition: MonteIO_impl.hh:24
void write_POSCAR_final(const MonteCarlo &mc, size_type cond_index, Log &_log)
For the final state, write a POSCAR file.
Definition: MonteIO.cc:458
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloMeanFormatter(std::string prop_name)
Print mean property values: <prop_name>
Definition: MonteIO.cc:31
DataFormatter< std::pair< ConstMonteCarloPtr, size_type > > make_observation_formatter(const MonteCarlo &mc)
Make a observation formatter.
Definition: MonteIO.cc:223
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloThermoChemSuscNFormatter(std::string species_i)
Print thermo-chemical susceptibility, 'susc_n(S,A)'.
GenericDatumFormatter< size_type, ConstMonteCarloPtr > MonteCarloNAvgSamplesFormatter()
Print number of samples used in calculating means.
Definition: MonteIO.cc:148
GenericDatumFormatter< bool, ConstMonteCarloPtr > MonteCarloIsConvergedFormatter()
Print if converged.
Definition: MonteIO.cc:125
void write_trajectory(const MonteSettings &settings, const MonteCarlo &mc, size_type cond_index, Log &_log)
Will create (and possibly overwrite) new file with all observations from run with conditions....
Definition: MonteIO.cc:325
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloSuscNFormatter(std::string species_i, std::string species_j)
Print susceptibility, 'susc_n(A,B)'.
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloBetaFormatter()
Print Beta.
Definition: MonteIO_impl.hh:36
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloThermoChemSuscXFormatter(std::string comp_var_i)
Print parametric thermo-chemical susceptibility, 'susc_x(S,a)'.
GenericDatumFormatter< int, std::pair< ConstMonteCarloPtr, size_type > > MonteCarloOccFormatter(size_type occ_index)
Print value of a particular occupation variable.
Definition: MonteIO.cc:198
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloCompNFormatter(const MonteType &mc, int index)
Print comp_n(N)
Definition: MonteIO_impl.hh:96
void write_results(const MonteSettings &settings, const MonteType &mc, Log &_log)
Will create new file or append to existing file results of the latest run.
void write_conditions_json(const MonteSettings &settings, const MonteType &mc, size_type cond_index, Log &_log)
Write conditions to conditions.cond_index directory.
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloHeatCapacityFormatter()
Print heat capacity, 'heat_capacity'.
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloCovFormatter(std::string prop_name1, std::string prop_name2)
Print covariance: cov(prop_name1, prop_name2)
Definition: MonteIO.cc:96
GenericDatumFormatter< bool, ConstMonteCarloPtr > MonteCarloIsEquilibratedFormatter()
Print if equilibrated (not counting explicitly requested equilibration)
Definition: MonteIO.cc:114
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloCompFormatter(const MonteType &mc, int index)
Print comp(x)
Definition: MonteIO_impl.hh:79
GenericDatumFormatter< size_type, ConstMonteCarloPtr > MonteCarloNEquilSamplesFormatter()
Print number of samples used for equilibration (not counting explicitly requested equilibration)
Definition: MonteIO.cc:137
void write_POSCAR_trajectory(const MonteCarlo &mc, size_type cond_index, Log &_log)
For every snapshot taken, write a POSCAR file.
Definition: MonteIO.cc:487
GenericDatumFormatter< size_type, std::pair< ConstMonteCarloPtr, size_type > > MonteCarloPassFormatter()
Print Pass number of observation.
Definition: MonteIO.cc:160
DataFormatter< std::pair< ConstMonteCarloPtr, size_type > > make_trajectory_formatter(const MonteCarlo &mc)
Make a trajectory formatter.
Definition: MonteIO.cc:246
Main CASM namespace.
Definition: APICommand.hh:8
Functor to help evaluate covariance.
Definition: MonteIO.hh:144
double operator()(const ConstMonteCarloPtr &mc)
Definition: MonteIO.cc:66
std::string prop_name2
Definition: MonteIO.hh:151
std::string prop_name1
Definition: MonteIO.hh:150
CovEvaluator(std::string _prop_name1, std::string _prop_name2)
Definition: MonteIO.hh:145