CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
GrandCanonicalSettings.cc
Go to the documentation of this file.
4 #include "casm/app/AppIO.hh"
5 
6 namespace CASM {
7 
8  std::string _help() {
9  std::string s =
10  "For GrandCanonicalConditions, expect a JSON object of form:\n"
11  " {\n"
12  " \"param_chem_pot\": {\n"
13  " \"a\" : -1.0,\n"
14  " ...\n"
15  " },\n"
16  " \"temperature\" : 350.0,\n"
17  " \"tolerance\" : 0.001\n"
18  " }\n";
19  return s;
20  }
21 
24  EquilibriumMonteSettings(_primclex, read_path) {
25 
26  if(!_primclex.has_composition_axes()) {
27  throw std::runtime_error("No composition axes selected.");
28  }
29 
30  }
31 
32  // --- GrandCanonicalConditions settings ---------------------
33 
37  return _conditions("initial_conditions");
38  }
40  return custom_conditions()[0];
41  }
42  else {
43  throw std::runtime_error("ERROR: Invalid drive mode.");
44  }
45  }
46 
49  return _conditions("final_conditions");
50  }
51 
54  return _conditions("incremental_conditions");
55  }
56 
58  std::vector<GrandCanonicalConditions> GrandCanonicalSettings::custom_conditions() const {
59  std::string level1 = "driver";
60  std::string level2 = "custom_conditions";
61 
62  try {
63  std::vector<GrandCanonicalConditions> cond;
64  const jsonParser &json = (*this)[level1][level2];
65  for(auto it = json.begin(); it != json.end(); ++it) {
66  cond.push_back(_conditions(*it));
67  }
68  return cond;
69  }
70  catch(std::runtime_error &e) {
72  err_log.error<Log::standard>("Reading Monte Carlo settings");
73  err_log << "Tried to read an array of GrandCanonicalConditions from [\"" << level1 << "\"][\"" << level2 << "\"]" << std::endl;
74  err_log << _help() << std::endl;
75  throw e;
76  }
77  }
78 
79  // --- Project settings ---------------------
80 
83  const ProjectSettings &set = primclex.settings();
84  std::string level1 = "model";
85  // deprecated
86  if(_is_setting(level1, "clex")) {
87 
88  // expect "clex" is "formation_energy"
89 
90  std::vector<std::string> var {"clex", "calctype", "ref", "bset", "eci"};
91  std::vector<std::string> help {
92  "string\n Names the cluster expansion to be used.\n",
93  "string\n Names the calctype to be used.\n",
94  "string\n Names the reference to be used.\n",
95  "string\n Names the basis set to be used.\n",
96  "string\n Names the ECI to be used.\n"
97  };
98 
99  return ClexDescription(
100  _get_setting<std::string>(level1, var[0], help[0]),
101  _get_setting<std::string>(level1, var[0], help[0]),
102  _get_setting<std::string>(level1, var[1], help[1]),
103  _get_setting<std::string>(level1, var[2], help[2]),
104  _get_setting<std::string>(level1, var[3], help[3]),
105  _get_setting<std::string>(level1, var[4], help[4]));
106  }
107 
108  std::string help = "(string, default='formation_energy')\n"
109  " Names the formation_energy cluster expansion to be used.\n";
110 
111  std::string formation_energy = "formation_energy";
112  if(_is_setting(level1, "formation_energy")) {
113  formation_energy = _get_setting<std::string>(level1, "formation_energy", help);
114  }
115 
116  if(!set.has_clex(formation_energy)) {
118  err_log.error<Log::standard>("Reading Monte Carlo settings");
119  err_log << "Error reading [\"model\"][\"formation_energy\"]\n";
120  err_log << "[\"model\"][\"formation_energy\"]: (string, optional, default='formation_energy')\n";
121  err_log << " Names the cluster expansion to be used for calculating formation_energy.\n";
122  err_log << "No cluster expansion named: '" << formation_energy << "' exists.\n";
123  }
124  return set.clex(formation_energy);
125  }
126 
127  // --- Sampler settings ---------------------
128 
131  if(method() == Monte::METHOD::LTE1) { //hack
132  return false;
133  }
134  std::string level1 = "data";
135  std::string level2 = "measurements";
136  try {
137  const jsonParser &json = (*this)[level1][level2];
138  for(auto it = json.cbegin(); it != json.cend(); ++it) {
139  if(it->contains("quantity") && (*it)["quantity"].get<std::string>() == "all_correlations") {
140  return true;
141  }
142  }
143  return false;
144  }
145  catch(std::runtime_error &e) {
147  err_log.error<Log::standard>("Reading Monte Carlo settings");
148  err_log << "Error checking if 'all_correlations' should be sampled.\n";
149  err_log << "Error reading settings at [\"" << level1 << "\"][\"" << level2 << "\"]\n";
150  err_log << "See 'casm format --monte' for help.\n" << std::endl;
151  throw e;
152  }
153 
154  }
155 
157 
158  std::string level1 = "driver";
159  std::string level2 = name;
160  try {
161  return _conditions((*this)[level1][level2]);
162  }
163  catch(std::runtime_error &e) {
165  err_log.error<Log::standard>("Reading Monte Carlo settings");
166  err_log << "Error reading: " << name << std::endl;
167  err_log << "Tried to construct GrandCanonicalCondtions from [\"" << level1 << "\"][\"" << level2 << "\"]" << std::endl;
168  err_log << _help() << std::endl;
169  throw e;
170  }
171  }
172 
175  from_json(result, primclex(), json);
176  return result;
177  }
178 
179 }
180 
Specifies a particular cluster expansion.
GrandCanonicalConditions _conditions(std::string name) const
GrandCanonicalConditions incremental_conditions() const
Expects incremental_conditions.
void from_json(ClexDescription &desc, const jsonParser &json)
iterator end()
Returns iterator to end of JSON object or JSON array.
Definition: jsonParser.cc:465
std::string help()
Print help message describing recognized strings for allowed enum values.
Definition: EnumIO.hh:38
const PrimClex & primclex() const
PrimClex * primclex
Definition: settings.cc:101
std::vector< GrandCanonicalConditions > custom_conditions() const
Expects custom_conditions.
bool has_composition_axes() const
check if CompositionConverter object initialized
Definition: PrimClex.cc:231
GrandCanonicalConditions final_conditions() const
Expects final_conditions.
Main CASM namespace.
Definition: complete.cpp:8
iterator begin()
Returns const_iterator to beginning of JSON object or JSON array.
Definition: jsonParser.cc:440
const_iterator cend() const
Returns const_iterator to end of JSON object or JSON array.
Definition: jsonParser.cc:480
ProjectSettings & set
Definition: settings.cc:103
GrandCanonicalSettings()
Default constructor.
bool all_correlations() const
Return true if all correlations should be sampled.
const ClexDescription & clex(std::string name) const
static const int standard
Definition: Log.hh:15
Read/modify settings of an already existing CASM project.
ProjectSettings & settings()
Definition: PrimClex.hh:116
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
bool has_clex(std::string name) const
ClexDescription formation_energy(const PrimClex &primclex) const
Get formation energy cluster expansion.
bool _is_setting(std::string level1, std::string level2) const
Returns true if (*this)[level1].contains(level2)
virtual const Monte::DRIVE_MODE drive_mode() const
Given a settings jsonParser figure out the drive mode. Expects drive_mode/incremental,custom.
jsonParser & push_back(const T &value)
Puts new valued element at end of array of any type T for which 'jsonParser& to_json( const T &value...
Definition: jsonParser.hh:696
std::string _help()
GrandCanonicalConditions initial_conditions() const
Expects initial_conditions.
Monte::METHOD method() const
Return type of Monte Carlo method.
Log & err_log
Definition: settings.cc:106
Log & default_err_log()
Definition: Log.hh:206
void error(const std::string &what)
Definition: Log.hh:86
Definition: Log.hh:9
const_iterator cbegin() const
Returns const_iterator to beginning of JSON object or JSON array.
Definition: jsonParser.cc:455