CASM  1.1.0
A Clusters Approach to Statistical Mechanics
Canonical.cc
Go to the documentation of this file.
1 
3 
7 #include "casm/misc/algorithm.hh"
13 
14 namespace CASM {
15 namespace Monte {
16 
17 template MonteCarlo::MonteCarlo(const PrimClex &primclex,
18  const CanonicalSettings &settings, Log &_log);
19 template MonteCarloEnum::MonteCarloEnum(const PrimClex &primclex,
20  const CanonicalSettings &settings,
21  Log &log, Canonical &mc);
22 
24 
25 // note: the construction process needs refactoring
26 Clex make_clex(PrimClex const &primclex, CanonicalSettings const &settings) {
27  ClexDescription const &clex_desc = settings.formation_energy(primclex);
28  return Clex{primclex.clexulator(clex_desc.bset), primclex.eci(clex_desc)};
29 }
30 
36  const CanonicalSettings &settings, Log &log)
37  : MonteCarlo(primclex, settings, log),
38  m_formation_energy_clex(make_clex(primclex, settings)),
39  m_convert(_supercell()),
40  m_cand(m_convert),
41  m_all_correlations(settings.all_correlations()),
42  m_occ_loc(m_convert, m_cand),
43  m_event(primclex.composition_axes().components().size(),
44  _clexulator().corr_size()) {
45  const auto &desc = settings.formation_energy(primclex);
46 
47  // set the SuperNeighborList...
48  set_nlist();
49 
50  // If the simulation is big enough, use delta cluster functions;
51  // else, calculate all cluster functions
53 
54  _log().construct("Canonical Monte Carlo");
55  _log() << "project: " << this->primclex().dir().root_dir() << "\n";
56  _log() << "formation_energy cluster expansion: " << desc.name << "\n";
57  _log() << std::setw(16) << "property: " << desc.property << "\n";
58  _log() << std::setw(16) << "calctype: " << desc.calctype << "\n";
59  _log() << std::setw(16) << "ref: " << desc.ref << "\n";
60  _log() << std::setw(16) << "bset: " << desc.bset << "\n";
61  _log() << std::setw(16) << "eci: " << desc.eci << "\n";
62  _log() << "supercell: \n" << supercell().transf_mat() << "\n";
63  _log() << "use_deltas: " << std::boolalpha << m_use_deltas << "\n";
64  _log() << "\nSampling: \n";
65  _log() << std::setw(24) << "quantity" << std::setw(24)
66  << "requested_precision"
67  << "\n";
68  for (auto it = samplers().begin(); it != samplers().end(); ++it) {
69  _log() << std::setw(24) << it->first;
70  if (it->second->must_converge()) {
71  _log() << std::setw(24) << it->second->requested_precision() << std::endl;
72  } else {
73  _log() << std::setw(24) << "none" << std::endl;
74  }
75  }
76  _log() << "\nautomatic convergence mode?: " << std::boolalpha
77  << must_converge() << std::endl;
78  _log() << std::endl;
79 
80  _log() << std::pair<const OccCandidateList &, const Conversions &>(m_cand,
81  m_convert)
82  << std::endl;
83 }
84 
88 
91 
93 void Canonical::set_conditions(const CanonicalConditions &new_conditions) {
94  _log().set("Conditions");
95  _log() << new_conditions << std::endl << std::endl;
96 
97  m_condition = new_conditions;
98 
101 
102  return;
103 }
104 
106 void Canonical::set_configdof(const ConfigDoF &configdof,
107  const std::string &msg) {
108  _log().set("DoF");
109  if (!msg.empty()) {
110  _log() << msg << "\n";
111  }
112  _log() << std::endl;
113 
116 }
117 
122 std::pair<ConfigDoF, std::string> Canonical::set_state(
123  const CanonicalConditions &new_conditions,
124  const CanonicalSettings &settings) {
125  _log().set("Conditions");
126  _log() << new_conditions << std::endl;
127 
128  m_condition = new_conditions;
129 
131 
132  std::string configname;
133 
136 
137  if (configname == "default") {
138  // configdof = _default_motif();
139  } else if (configname == "auto") {
140  std::tie(configdof, configname) = _auto_motif(new_conditions);
141  } else if (configname == "restricted_auto") {
142  std::tie(configdof, configname) = _restricted_auto_motif(new_conditions);
143  } else {
145  }
146 
147  } else if (settings.is_motif_configdof()) {
148  _log().set("DoF");
149  _log() << "motif configdof: " << settings.motif_configdof_path() << "\n";
150  _log() << "using configdof: " << settings.motif_configdof_path() << "\n"
151  << std::endl;
154  } else {
155  throw std::runtime_error(
156  "Error: Must specify motif \"configname\" or \"configdof\"");
157  }
158 
161 
162  return std::make_pair(configdof, configname);
163 }
164 
166 void Canonical::set_state(const CanonicalConditions &new_conditions,
167  const ConfigDoF &configdof, const std::string &msg) {
168  _log().set("Conditions");
169  _log() << new_conditions << std::endl << std::endl;
170 
171  m_condition = new_conditions;
172 
173  _log().set("DoF");
174  if (!msg.empty()) {
175  _log() << msg << "\n";
176  }
177  _log() << std::endl;
178 
181 
182  return;
183 }
184 
194  _mtrand());
196  return m_event;
197 }
198 
201 bool Canonical::check(const CanonicalEvent &event) {
202  if (event.dEpot() < 0.0) {
203  if (debug()) {
204  _log().custom("Check event");
205  _log() << "Probability to accept: 1.0\n" << std::endl;
206  }
207  return true;
208  }
209 
210  double rand = _mtrand().rand53();
211  double prob = exp(-event.dEpot() * m_condition.beta());
212 
213  if (debug()) {
214  _log().custom("Check event");
215  _log() << "Probability to accept: " << prob << "\n"
216  << "Random number: " << rand << "\n"
217  << std::endl;
218  }
219 
220  return rand < prob;
221 }
222 
231 void Canonical::accept(const EventType &event) {
232  if (debug()) {
233  _log().custom("Accept Event");
234  _log() << std::endl;
235  }
236 
237  // Apply occ mods && update occ locations table
238  m_occ_loc.apply(event.occ_event(), _configdof());
239 
240  // Next update all properties that changed from the event
241  _formation_energy() += event.dEf() / supercell().volume();
242  _potential_energy() += event.dEpot() / supercell().volume();
243  _corr() += event.dCorr() / supercell().volume();
244  _comp_n() += event.dN().cast<double>() / supercell().volume();
245 
246  return;
247 }
248 
250 void Canonical::reject(const EventType &event) {
251  if (debug()) {
252  _log().custom("Reject Event");
253  _log() << std::endl;
254  }
255  return;
256 }
257 
259 void Canonical::write_results(Index cond_index) const {
261  write_conditions_json(settings(), *this, cond_index, _log());
262  write_observations(settings(), *this, cond_index, _log());
263  write_trajectory(settings(), *this, cond_index, _log());
264  // write_pos_trajectory(settings(), *this, cond_index);
265 }
266 
272  // if(&config == &this->config()) { return potential_energy(); }
273 
274  auto corr = correlations(config, _clexulator());
275  return _eci() * corr.data();
276 }
277 
279  Eigen::VectorXd &dCorr_comp) const {
280  int sublat = _config().sublat(l);
281  int curr_occ = _configdof().occ(l);
282 
283  // Calculate the change in correlations due to this event
284  if (m_use_deltas) {
285  if (m_all_correlations) {
287  _configdof(), nlist().sites(nlist().unitcell_index(l)).data(),
288  end_ptr(nlist().sites(nlist().unitcell_index(l))), sublat, curr_occ,
289  new_occ, dCorr_comp.data(), end_ptr(dCorr_comp));
290  } else {
291  auto begin = _eci().index().data();
292  auto end = begin + _eci().index().size();
294  _configdof(), nlist().sites(nlist().unitcell_index(l)).data(),
295  end_ptr(nlist().sites(nlist().unitcell_index(l))), sublat, curr_occ,
296  new_occ, dCorr_comp.data(), end_ptr(dCorr_comp), begin, end);
297  }
298  } else {
299  Eigen::VectorXd before{Eigen::VectorXd::Zero(dCorr_comp.size())};
300  Eigen::VectorXd after{Eigen::VectorXd::Zero(dCorr_comp.size())};
301 
302  // Calculate the change in points correlations due to this event
303  if (m_all_correlations) {
304  // Calculate before
306  _configdof(), nlist().sites(nlist().unitcell_index(l)).data(),
307  end_ptr(nlist().sites(nlist().unitcell_index(l))), sublat,
308  before.data(), end_ptr(before));
309 
310  // Apply change
311  _configdof().occ(l) = new_occ;
312 
313  // Calculate after
315  _configdof(), nlist().sites(nlist().unitcell_index(l)).data(),
316  end_ptr(nlist().sites(nlist().unitcell_index(l))), sublat,
317  after.data(), end_ptr(after));
318  } else {
319  auto begin = _eci().index().data();
320  auto end = begin + _eci().index().size();
321 
322  // Calculate before
324  _configdof(), nlist().sites(nlist().unitcell_index(l)).data(),
325  end_ptr(nlist().sites(nlist().unitcell_index(l))), sublat,
326  before.data(), end_ptr(before), begin, end);
327 
328  // Apply change
329  _configdof().occ(l) = new_occ;
330 
331  // Calculate after
333  _configdof(), nlist().sites(nlist().unitcell_index(l)).data(),
334  end_ptr(nlist().sites(nlist().unitcell_index(l))), sublat,
335  after.data(), end_ptr(after), begin, end);
336  }
337  dCorr_comp = after - before;
338 
339  // Unapply changes
340  _configdof().occ(l) = curr_occ;
341  }
342 }
343 
346  const OccEvent &e = event.occ_event();
347  const OccTransform &f_a = e.occ_transform[0];
348  const OccTransform &f_b = e.occ_transform[1];
349 
350  int curr_occ_a = _configdof().occ(f_a.l);
351  Index new_occ_a = m_convert.occ_index(f_a.asym, f_a.to_species);
352  Index new_occ_b = m_convert.occ_index(f_b.asym, f_b.to_species);
353 
354  Eigen::VectorXd dCorr_comp{Eigen::VectorXd::Zero(event.dCorr().size())};
355 
356  // calc dCorr for first site
357  _calc_delta_point_corr(f_a.l, new_occ_a, event.dCorr());
358 
359  // change occ on first site
360  _configdof().occ(f_a.l) = new_occ_a;
361 
362  // calc dCorr for second site
363  _calc_delta_point_corr(f_b.l, new_occ_b, dCorr_comp);
364  event.dCorr() += dCorr_comp;
365 
366  // unchange occ on first site
367  _configdof().occ(f_a.l) = curr_occ_a;
368 
369  if (debug()) {
370  _print_correlations(event.dCorr(), "delta correlations", "dCorr",
372  }
373 }
374 
377  std::string title, std::string colheader,
378  bool all_correlations) const {
379  _log().calculate(title);
380  _log() << std::setw(12) << "i" << std::setw(16) << "ECI" << std::setw(16)
381  << colheader << std::endl;
382 
383  for (int i = 0; i < corr.size(); ++i) {
384  double eci = 0.0;
385  bool calculated = true;
386  Index index = find_index(_eci().index(), i);
387  if (index != _eci().index().size()) {
388  eci = _eci().value()[index];
389  }
390  if (!all_correlations && index == _eci().index().size()) {
391  calculated = false;
392  }
393 
394  _log() << std::setw(12) << i << std::setw(16) << std::setprecision(8)
395  << eci;
396  if (calculated) {
397  _log() << std::setw(16) << std::setprecision(8) << corr[i];
398  } else {
399  _log() << std::setw(16) << "unknown";
400  }
401  _log() << std::endl;
402  }
403  _log() << std::endl;
404 }
405 
408  // ---- set dcorr --------------
409  _set_dCorr(event);
410 
411  // ---- set dformation_energy --------------
412  event.set_dEf(_eci() * event.dCorr().data());
413 }
414 
417  // initialize properties and store pointers to the data strucures
418  _vector_properties()["corr"] =
420  m_corr = &_vector_property("corr");
421 
423  m_comp_n = &_vector_property("comp_n");
424 
425  _scalar_properties()["formation_energy"] = _eci() * corr().data();
426  m_formation_energy = &_scalar_property("formation_energy");
427 
428  _scalar_properties()["potential_energy"] = formation_energy();
429  m_potential_energy = &_scalar_property("potential_energy");
430 
431  if (debug()) {
432  _print_correlations(corr(), "correlations", "corr", m_all_correlations);
433 
434  auto origin = primclex().composition_axes().origin();
435  auto comp_x = primclex().composition_axes().param_composition(comp_n());
436  auto M = primclex().composition_axes().dmol_dparam();
437 
438  _log().custom("Calculate properties");
439  _log() << "Canonical ensemble: \n"
440  << " Thermodynamic potential (per unitcell), phi = -kT*ln(Z)/N \n"
441  << " Partition function, Z = sum_i exp(-N*potential_energy_i/kT) \n"
442  << " composition, comp_n = origin + M * comp_x \n"
443  << " potential_energy (per unitcell) = formation_energy \n\n"
444 
445  << "components: "
446  << jsonParser(primclex().composition_axes().components()) << "\n"
447  << "M:\n"
448  << M << "\n"
449  << "origin: " << origin.transpose() << "\n"
450  << "comp_n: " << comp_n().transpose() << "\n"
451  << "comp_x: " << comp_x.transpose() << "\n"
452  << "formation_energy: " << formation_energy() << "\n"
453  << "potential_energy: " << potential_energy() << "\n"
454  << std::endl;
455  }
456 }
457 
460  _log().set("DoF");
461  _log() << "motif configname: default\n";
462  _log() << "using configuration with default occupation...\n" << std::endl;
463 
465 }
466 
470 std::pair<ConfigDoF, std::string> Canonical::_auto_motif(
471  const CanonicalConditions &cond) const {
472  throw std::runtime_error(
473  "Canonical Monte Carlo 'auto' motif is not implemented yet");
474 }
475 
477 std::pair<ConfigDoF, std::string> Canonical::_restricted_auto_motif(
478  const CanonicalConditions &cond) const {
479  throw std::runtime_error(
480  "Canonical Monte Carlo 'restricted_auto' motif is not implemented yet");
481 }
482 
485  _log().set("DoF");
486  _log() << "motif configname: " << configname << "\n";
487  _log() << "using configation: " << configname << "\n" << std::endl;
488 
491 }
492 
500 std::vector<OccSwap>::const_iterator Canonical::_find_grand_canonical_swap(
501  const Configuration &config, std::vector<OccSwap>::const_iterator begin,
502  std::vector<OccSwap>::const_iterator end) {
503  double dn = 1. / supercell().volume();
504  Eigen::VectorXd target_comp_n = conditions().mol_composition();
506 
507  typedef std::vector<OccSwap>::const_iterator it_type;
508  std::vector<std::pair<it_type, double> > best;
509  double best_dist = (comp_n - target_comp_n).norm();
510  double tol = primclex().settings().lin_alg_tol();
511 
512  for (auto it = begin; it != end; ++it) {
513  if (m_occ_loc.cand_size(it->cand_a)) {
514  Eigen::VectorXd tcomp_n = comp_n;
515  tcomp_n[it->cand_a.species_index] -= dn;
516  tcomp_n[it->cand_b.species_index] += dn;
517 
518  double dist = (tcomp_n - target_comp_n).norm();
519  if (dist < best_dist - tol) {
520  best.clear();
521  best.push_back({it, m_occ_loc.cand_size(it->cand_a)});
522  best_dist = dist;
523  } else if (dist < best_dist + tol) {
524  best.push_back({it, m_occ_loc.cand_size(it->cand_a)});
525  }
526  }
527  }
528 
529  if (!best.size()) {
530  return end;
531  }
532 
533  // break ties randomly, weighted by number of candidates
534  double sum = 0.0;
535  for (const auto &val : best) {
536  sum += val.second;
537  }
538 
539  double rand = _mtrand().randExc(sum);
540  sum = 0.0;
541  int count = 0;
542  for (const auto &val : best) {
543  sum += val.second;
544  if (rand < sum) {
545  return val.first;
546  }
547  ++count;
548  }
549  throw std::runtime_error("Error enforcing composition");
550 }
551 
558  _log().custom("Enforce composition");
559  Configuration tconfig(_supercell(), configdof);
560  m_occ_loc.initialize(tconfig);
561  jsonParser json;
562 
563  _log() << " initial comp: " << to_json_array(CASM::comp(tconfig), json)
564  << std::endl;
565  _log() << " initial comp_n: " << to_json_array(CASM::comp_n(tconfig), json)
566  << std::endl;
567 
568  Eigen::VectorXd target_comp_n = conditions().mol_composition();
569  _log() << " target comp_n: " << to_json_array(target_comp_n, json)
570  << std::endl;
571 
572  int count = 0;
573  OccEvent e;
574  ConfigDoF &tconfigdof = tconfig.configdof();
575  while (true) {
576  auto begin = m_cand.grand_canonical_swap().begin();
577  auto end = m_cand.grand_canonical_swap().end();
578  auto it = _find_grand_canonical_swap(tconfig, begin, end);
579 
580  if (it == end) {
581  _log() << " applied swaps: " << count << std::endl;
582  break;
583  }
584 
587  m_occ_loc.apply(e, tconfigdof);
588 
589  ++count;
590  }
591 
592  _log() << " final comp: " << to_json_array(CASM::comp(tconfig), json)
593  << std::endl;
594  _log() << " final comp_n: " << to_json_array(CASM::comp_n(tconfig), json)
595  << std::endl
596  << std::endl;
597 
598  return tconfig.configdof();
599 }
600 
601 } // namespace Monte
602 } // namespace CASM
Index count
void calc_restricted_point_corr(ConfigDoF const &_input_configdof, long int const *_nlist_begin, long int const *_nlist_end, int neighbor_ind, double *_corr_begin, double *_corr_end, size_type const *_corr_ind_begin, size_type const *_corr_ind_end) const
Calculate select point correlations about basis site 'neighbor_ind'.
Definition: Clexulator.hh:651
void calc_restricted_delta_point_corr(ConfigDoF const &_input_configdof, long int const *_nlist_begin, long int const *_nlist_end, int neighbor_ind, int occ_i, int occ_f, double *_corr_begin, double *_corr_end, size_type const *_corr_ind_begin, size_type const *_corr_ind_end) const
Calculate the change in select point correlations due to changing an occupant.
Definition: Clexulator.hh:716
void calc_point_corr(ConfigDoF const &_input_configdof, long int const *_nlist_begin, long int const *_nlist_end, int neighbor_ind, double *_corr_begin, double *_corr_end) const
Calculate point correlations about basis site 'neighbor_ind'.
Definition: Clexulator.hh:626
void calc_delta_point_corr(ConfigDoF const &_input_configdof, long int const *_nlist_begin, long int const *_nlist_end, int neighbor_ind, int occ_i, int occ_f, double *_corr_begin, double *_corr_end) const
Calculate the change in point correlations due to changing an occupant.
Definition: Clexulator.hh:679
Eigen::VectorXd param_composition(const Eigen::VectorXd &n) const
Convert number of mol per prim, 'n' to parametric composition 'x'.
Eigen::VectorXd origin() const
The mol composition of the parameteric composition axes origin.
Eigen::MatrixXd dmol_dparam() const
Return the matrix Mij = dn_i/dx_j.
int & occ(Index i)
Reference occupation value on site i.
Definition: ConfigDoF.cc:34
const ConfigDoF & configdof() const
const Access the DoF
static Configuration zeros(const std::shared_ptr< Supercell const > &_supercell_ptr)
int sublat(Index site_l) const
Get the basis site index for a given linear linear site index.
fs::path root_dir() const
Return casm project directory path.
const std::vector< size_type > & index() const
const Access orbit indices of ECI values
Definition: ECIContainer.hh:44
const std::vector< double > & value() const
const Access ECI values
Definition: ECIContainer.hh:41
Definition: Log.hh:48
void custom(const std::string &what)
Definition: Log.hh:139
void set(const std::string &what)
Definition: Log.hh:89
void calculate(const std::string &what)
Definition: Log.hh:74
void construct(const std::string &what)
Definition: Log.hh:79
Eigen::VectorXd mol_composition() const
mol composition: comp_n
Data structure for storing information regarding a proposed grand canonical Monte Carlo event.
double dEpot() const
Return change in (extensive) potential energy, dEpot = dEf.
double dEf() const
Return change in (extensive) formation energy associated with this event.
void set_dEf(double dE)
Set the change in (extensive) formation energy associated with this event.
Eigen::VectorXd & dCorr()
Access the changes in (extensive) correlations associated with this event.
OccEvent & occ_event()
Access the data describing this event.
const Eigen::VectorXl & dN() const
const Access change in number of species per supercell. Zeros, size of CompositionConverter::componen...
const CondType & conditions() const
Return current conditions.
Definition: Canonical.cc:90
void _calc_delta_point_corr(size_type l, int new_occ, Eigen::VectorXd &dCorr_comp) const
Definition: Canonical.cc:278
CanonicalConditions m_condition
Definition: Canonical.hh:183
void accept(const EventType &event)
Accept proposed event. Change configuration accordingly and update energies etc.
Definition: Canonical.cc:231
ConfigDoF _default_motif() const
Generate supercell filling ConfigDoF from default configuration.
Definition: Canonical.cc:459
CanonicalEvent m_event
Event to propose, check, accept/reject:
Definition: Canonical.hh:186
Eigen::VectorXd & _comp_n()
Number of atoms of each type, normalized per primitive cell.
Definition: Canonical.hh:109
void write_results(size_type cond_index) const
Write results to files.
Definition: Canonical.cc:259
const Eigen::VectorXd & corr() const
Correlations, normalized per primitive cell.
Definition: Canonical.hh:90
const Eigen::VectorXd & comp_n() const
Number of atoms of each type, normalized per primitive cell.
Definition: Canonical.hh:93
void _update_properties()
Calculate properties given current conditions.
Definition: Canonical.cc:416
std::pair< ConfigDoF, std::string > set_state(const CanonicalConditions &new_conditions, const CanonicalSettings &settings)
Set configdof and conditions and clear previously collected data.
Definition: Canonical.cc:122
ConfigDoF _configname_motif(const std::string &configname) const
Generate supercell filling ConfigDoF from configuration.
Definition: Canonical.cc:484
size_type steps_per_pass() const
Return number of steps per pass. Equals number of sites with variable occupation.
Definition: Canonical.cc:87
const double & formation_energy() const
Formation energy, normalized per primitive cell.
Definition: Canonical.hh:84
void reject(const EventType &event)
Nothing needs to be done to reject a CanonicalEvent.
Definition: Canonical.cc:250
Eigen::VectorXd & _corr()
Correlations, normalized per primitive cell.
Definition: Canonical.hh:106
Conversions m_convert
Convert sublat/asym_unit and species/occ index.
Definition: Canonical.hh:165
ConfigDoF _enforce_conditions(const ConfigDoF &configdof)
Enforce composition by repeatedly applying grand canonical events.
Definition: Canonical.cc:557
void set_configdof(const ConfigDoF &configdof, const std::string &msg="")
Set configdof and clear previously collected data.
Definition: Canonical.cc:106
Eigen::VectorXd * m_corr
Correlations, normalized per primitive cell.
Definition: Canonical.hh:197
void set_conditions(const CondType &new_conditions)
Set conditions and clear previously collected data.
Definition: Canonical.cc:93
double * m_potential_energy
Potential energy, normalized per primitive cell.
Definition: Canonical.hh:194
std::pair< ConfigDoF, std::string > _restricted_auto_motif(const CanonicalConditions &cond) const
Generate minimum potential energy ConfigDoF for this supercell.
Definition: Canonical.cc:477
bool check(const EventType &event)
Based on a random number, decide if the change in energy from the proposed event is low enough to be ...
Definition: Canonical.cc:201
std::vector< OccSwap >::const_iterator _find_grand_canonical_swap(const Configuration &config, std::vector< OccSwap >::const_iterator begin, std::vector< OccSwap >::const_iterator end)
Find a OccSwap to help enforce composition.
Definition: Canonical.cc:500
void _update_deltas(CanonicalEvent &event) const
Calculate delta properties for an event and update the event with those properties.
Definition: Canonical.cc:407
static const ENSEMBLE ensemble
Definition: Canonical.hh:34
Canonical(const PrimClex &primclex, const SettingsType &settings, Log &_log)
Constructs a Canonical object and prepares it for running based on Settings.
Definition: Canonical.cc:35
const double & potential_energy() const
Potential energy, normalized per primitive cell.
Definition: Canonical.hh:87
const ECIContainer & _eci() const
Definition: Canonical.hh:115
double * m_formation_energy
Formation energy, normalized per primitive cell.
Definition: Canonical.hh:191
OccCandidateList m_cand
Convert sublat/asym_unit and species/occ index.
Definition: Canonical.hh:168
double & _formation_energy()
Formation energy, normalized per primitive cell.
Definition: Canonical.hh:100
double & _potential_energy()
Potential energy, normalized per primitive cell.
Definition: Canonical.hh:103
const EventType & propose()
Propose a new event, calculate delta properties, and return reference to it.
Definition: Canonical.cc:192
std::pair< ConfigDoF, std::string > _auto_motif(const CanonicalConditions &cond) const
Generate minimum potential energy ConfigDoF.
Definition: Canonical.cc:470
void _print_correlations(const Eigen::VectorXd &corr, std::string title, std::string colheader, bool all_correlations) const
Print correlations to _log()
Definition: Canonical.cc:376
OccLocation m_occ_loc
Keeps track of what sites have which occupants.
Definition: Canonical.hh:179
bool m_use_deltas
If the supercell is large enough, calculate delta correlations directly.
Definition: Canonical.hh:176
Eigen::VectorXd * m_comp_n
Number of atoms of each type, normalized per primitive cell.
Definition: Canonical.hh:200
Clexulator const & _clexulator() const
Definition: Canonical.hh:111
void _set_dCorr(CanonicalEvent &event) const
Calculate delta correlations for an event.
Definition: Canonical.cc:345
ClexDescription formation_energy(const PrimClex &primclex) const
Get formation energy cluster expansion.
Index occ_index(Index asym, Index species_index) const
Definition: Conversions.cc:129
MonteCarloEnum(const PrimClex &primclex, const MonteTypeSettings &settings, Log &log, MonteCarloType &mc)
Interface base class for all types of Monte Carlo simulations (not meant to be used polymorphically)
Definition: MonteCarlo.hh:44
double & _scalar_property(std::string property_name)
Access a particular scalar property.
Definition: MonteCarlo.hh:197
VectorPropertyMap & _vector_properties()
const Access vector properties map
Definition: MonteCarlo.hh:202
ConfigDoF & _configdof() const
Access current microstate.
Definition: MonteCarlo.hh:187
const Supercell & _supercell() const
Access the Supercell that *this is based on.
Definition: MonteCarlo.hh:175
void set_nlist()
Set a pointer to the SuperNeighborList once it is ready.
Definition: MonteCarlo.hh:83
const SuperNeighborList & nlist() const
const Access the SuperNeighborList via pointer stored by 'set_nlist'
Definition: MonteCarlo.hh:87
ScalarPropertyMap & _scalar_properties()
Access scalar properties map.
Definition: MonteCarlo.hh:194
const Supercell & supercell() const
const Access the Supercell that *this is based on
Definition: MonteCarlo.hh:80
const MonteSettings & settings() const
const Access settings used for construction
Definition: MonteCarlo.hh:74
void reset(const ConfigDoF &dof)
Set current microstate and clear samplers.
Definition: MonteCarlo.hh:98
const Configuration & config() const
const Access current microstate
Definition: MonteCarlo.hh:90
const PrimClex & primclex() const
const Access the PrimClex that *this is based on
Definition: MonteCarlo.hh:77
Configuration & _config() const
Access current microstate.
Definition: MonteCarlo.hh:181
Eigen::VectorXd & _vector_property(std::string property_name)
const Access a particular vector property
Definition: MonteCarlo.hh:205
MonteCarlo(const PrimClex &primclex, const MonteTypeSettings &settings, Log &_log)
Construct with a starting ConfigDoF as specified the given MonteSettings and prepare data samplers.
const ConfigDoF & configdof() const
const Access current microstate
Definition: MonteCarlo.hh:93
bool debug() const
return true if running in debug mode
Definition: MonteCarlo.hh:162
const SamplerMap & samplers() const
const Access sampler map
Definition: MonteCarlo.hh:149
bool must_converge() const
Return true if convergence is requested.
Definition: MonteCarlo.hh:135
bool is_motif_configdof() const
Returns true if path to ConfigDoF file to use as starting motif has been specified.
std::string motif_configname() const
Configname of configuration to use as starting motif.
bool is_motif_configname() const
Returns true if configname of configuration to use as starting motif has been specified.
ConfigDoF motif_configdof(Index supercell_volume) const
ConfigDoF to use as starting motif.
fs::path motif_configdof_path() const
Path to ConfigDoF file to use as starting motif.
const std::vector< OccSwap > & canonical_swap() const
const std::vector< OccSwap > & grand_canonical_swap() const
size_type cand_size(Index cand_index) const
Total number of mutating sites, of OccCandidate type, specified by index.
Definition: OccLocation.cc:80
OccEvent & propose_grand_canonical(OccEvent &e, const OccSwap &swap, MTRand &mtrand) const
Propose grand canonical OccEvent.
Definition: OccLocation.cc:128
void apply(const OccEvent &e, ConfigDoF &configdof)
Update configdof and this to reflect that event 'e' occurred.
Definition: OccLocation.cc:147
size_type size() const
Total number of mutating sites.
Definition: OccLocation.cc:73
OccEvent & propose_canonical(OccEvent &e, const std::vector< OccSwap > &canonical_swap, MTRand &mtrand) const
Propose canonical OccEvent.
Definition: OccLocation.cc:103
void initialize(const Configuration &config)
Fill tables with occupation info.
Definition: OccLocation.cc:16
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:55
double lin_alg_tol() const
Get current project linear algebra tolerance.
bool overlaps() const
Returns true if periodic images of the neighbor list overlap.
Eigen::Matrix3l transf_mat() const
Definition: Supercell.cc:235
Index volume() const
Return number of primitive cells that fit inside of *this.
Definition: Supercell.cc:227
Eigen::VectorXd correlations(const Configuration &config, Clexulator const &clexulator)
Returns correlations using 'clexulator'.
Eigen::VectorXd comp(const Configuration &config)
Returns parametric composition, as calculated using PrimClex::param_comp.
Eigen::VectorXd comp_n(const Configuration &config)
Returns the composition, as number of each species per unit cell.
DB::Database< T > & db() const
Definition: PrimClex.cc:302
ProjectSettings & settings()
Definition: PrimClex.cc:224
const DirectoryStructure & dir() const
Access DirectoryStructure object. Throw if not set.
Definition: PrimClex.cc:230
const CompositionConverter & composition_axes() const
const Access CompositionConverter object
Definition: PrimClex.cc:243
T norm(const Tensor< T > &ttens)
Definition: Tensor.hh:932
CASM::jsonParser & to_json_array(const Eigen::MatrixBase< Derived > &value, CASM::jsonParser &json)
Write Eigen Matrix with 1 row or 1 column to JSON array.
Definition: json_io.hh:313
ConfigIO::GenericConfigFormatter< jsonParser > config()
Definition: ConfigIO.cc:777
ConfigIO::GenericConfigFormatter< std::string > configname()
Constructs DataFormmaterDictionary containing all Configuration DatumFormatters.
Definition: ConfigIO.cc:563
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_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
Clex make_clex(PrimClex const &primclex, CanonicalSettings const &settings)
Definition: Canonical.cc:26
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.
ENSEMBLE
Monte Carlo ensemble type.
GenericScelFormatter< double > volume()
Definition: SupercellIO.cc:258
Main CASM namespace.
Definition: APICommand.hh:8
Configuration fill_supercell(Configuration const &motif, std::shared_ptr< Supercell const > const &shared_supercell)
Log & log()
Definition: Log.hh:424
Index find_index(Iterator begin, Iterator end, const T &value)
Equivalent to std::distance(begin, std::find(begin, end, value))
Definition: algorithm.hh:24
Container::value_type sum(const Container &container, typename Container::value_type init_val=0)
Definition: algorithm.hh:131
Iterator find(Iterator begin, Iterator end, const T &value, BinaryCompare q)
Equivalent to std::find(begin, end, value), but with custom comparison.
Definition: algorithm.hh:16
T * end_ptr(std::vector< T > &container)
Return pointer one past end of vector. Equivalent to convainer.data()+container.size()
Definition: algorithm.hh:142
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Eigen::VectorXd VectorXd
pair_type eci
Definition: settings.cc:146
PrimClex * primclex
Definition: settings.cc:135
ClexDescription & desc
Definition: settings.cc:138
Specifies a particular cluster expansion.
Pair of Clexulator and ECIContainer.
Definition: Clex.hh:16
std::vector< OccTransform > occ_transform
Definition: OccLocation.hh:70
Index asym
Asym index.
Definition: OccLocation.hh:53
Index l
Config occupant that is being transformed.
Definition: OccLocation.hh:51
Index to_species
Species index after transformation.
Definition: OccLocation.hh:55