CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Canonical.cc
Go to the documentation of this file.
1 
4 #include "casm/clex/PrimClex.hh"
6 #include "casm/clex/Norm.hh"
9 
10 namespace CASM {
11  namespace Monte {
12 
14 
19  MonteCarlo(primclex, settings, log),
20  m_formation_energy_clex(primclex, settings.formation_energy(primclex)),
21  m_convert(_supercell()),
22  m_cand(m_convert),
23  m_all_correlations(settings.all_correlations()),
24  m_occ_loc(m_convert, m_cand),
25  m_event(primclex.composition_axes().components().size(), _clexulator().corr_size()) {
26 
27  const auto &desc = m_formation_energy_clex.desc();
28 
29  // set the SuperNeighborList...
30  set_nlist();
31 
32  // If the simulation is big enough, use delta cluster functions;
33  // else, calculate all cluster functions
35 
36  _log().construct("Canonical Monte Carlo");
37  _log() << "project: " << this->primclex().get_path() << "\n";
38  _log() << "formation_energy cluster expansion: " << desc.name << "\n";
39  _log() << std::setw(16) << "property: " << desc.property << "\n";
40  _log() << std::setw(16) << "calctype: " << desc.calctype << "\n";
41  _log() << std::setw(16) << "ref: " << desc.ref << "\n";
42  _log() << std::setw(16) << "bset: " << desc.bset << "\n";
43  _log() << std::setw(16) << "eci: " << desc.eci << "\n";
44  _log() << "supercell: \n" << supercell().get_transf_mat() << "\n";
45  _log() << "use_deltas: " << std::boolalpha << m_use_deltas << "\n";
46  _log() << "\nSampling: \n";
47  _log() << std::setw(24) << "quantity" << std::setw(24) << "requested_precision" << "\n";
48  for(auto it = samplers().begin(); it != samplers().end(); ++it) {
49  _log() << std::setw(24) << it->first;
50  if(it->second->must_converge()) {
51  _log() << std::setw(24) << it->second->requested_precision() << std::endl;
52  }
53  else {
54  _log() << std::setw(24) << "none" << std::endl;
55  }
56  }
57  _log() << "\nautomatic convergence mode?: " << std::boolalpha << must_converge() << std::endl;
58  _log() << std::endl;
59 
60  _log() << std::pair<const OccCandidateList &, const Conversions &>(m_cand, m_convert) << std::endl;
61 
62  }
63 
66  return m_occ_loc.size();
67  }
68 
69 
72  return m_condition;
73  }
74 
75 
77  void Canonical::set_conditions(const CanonicalConditions &new_conditions) {
78  _log().set("Conditions");
79  _log() << new_conditions << std::endl << std::endl;
80 
81  m_condition = new_conditions;
82 
85 
86  return;
87  }
88 
90  void Canonical::set_configdof(const ConfigDoF &configdof, const std::string &msg) {
91  _log().set("DoF");
92  if(!msg.empty()) {
93  _log() << msg << "\n";
94  }
95  _log() << std::endl;
96 
97  reset(_enforce_conditions(configdof));
99  }
100 
105  std::pair<ConfigDoF, std::string> Canonical::set_state(
106  const CanonicalConditions &new_conditions,
107  const CanonicalSettings &settings) {
108 
109  _log().set("Conditions");
110  _log() << new_conditions << std::endl;
111 
112  m_condition = new_conditions;
113 
115  std::string configname;
116 
117  if(settings.is_motif_configname()) {
118 
119  configname = settings.motif_configname();
120 
121  if(configname == "default") {
122  configdof = _default_motif();
123  }
124  else if(configname == "auto") {
125  std::tie(configdof, configname) = _auto_motif(new_conditions);
126  }
127  else if(configname == "restricted_auto") {
128  std::tie(configdof, configname) = _restricted_auto_motif(new_conditions);
129  }
130  else {
131  configdof = _configname_motif(configname);
132  }
133 
134  }
135  else if(settings.is_motif_configdof()) {
136  _log().set("DoF");
137  _log() << "motif configdof: " << settings.motif_configdof_path() << "\n";
138  _log() << "using configdof: " << settings.motif_configdof_path() << "\n" << std::endl;
139  configdof = settings.motif_configdof();
140  configname = settings.motif_configdof_path().string();
141  }
142  else {
143  throw std::runtime_error("Error: Must specify motif \"configname\" or \"configdof\"");
144  }
145 
146  reset(_enforce_conditions(configdof));
148 
149  return std::make_pair(configdof, configname);
150  }
151 
153  void Canonical::set_state(const CanonicalConditions &new_conditions,
154  const ConfigDoF &configdof,
155  const std::string &msg) {
156  _log().set("Conditions");
157  _log() << new_conditions << std::endl << std::endl;
158 
159  m_condition = new_conditions;
160 
161  _log().set("DoF");
162  if(!msg.empty()) {
163  _log() << msg << "\n";
164  }
165  _log() << std::endl;
166 
167  reset(_enforce_conditions(configdof));
169 
170  return;
171  }
172 
173 
182  return m_event;
183  }
184 
186  bool Canonical::check(const CanonicalEvent &event) {
187 
188  if(event.dEpot() < 0.0) {
189 
190  if(debug()) {
191  _log().custom("Check event");
192  _log() << "Probability to accept: 1.0\n" << std::endl;
193  }
194  return true;
195  }
196 
197  double rand = _mtrand().rand53();
198  double prob = exp(-event.dEpot() * m_condition.beta());
199 
200  if(debug()) {
201  _log().custom("Check event");
202  _log() << "Probability to accept: " << prob << "\n"
203  << "Random number: " << rand << "\n" << std::endl;
204  }
205 
206  return rand < prob;
207  }
208 
215  void Canonical::accept(const EventType &event) {
216 
217  if(debug()) {
218  _log().custom("Accept Event");
219  _log() << std::endl;
220  }
221 
222  // Apply occ mods && update occ locations table
223  m_occ_loc.apply(event.occ_event(), _configdof());
224 
225  // Next update all properties that changed from the event
226  _formation_energy() += event.dEf() / supercell().volume();
227  _potential_energy() += event.dEpot() / supercell().volume();
228  _corr() += event.dCorr() / supercell().volume();
229  _comp_n() += event.dN().cast<double>() / supercell().volume();
230 
231  return;
232  }
233 
235  void Canonical::reject(const EventType &event) {
236  if(debug()) {
237  _log().custom("Reject Event");
238  _log() << std::endl;
239  }
240  return;
241  }
242 
244  void Canonical::write_results(Index cond_index) const {
245  CASM::write_results(settings(), *this, _log());
246  write_conditions_json(settings(), *this, cond_index, _log());
247  write_observations(settings(), *this, cond_index, _log());
248  write_trajectory(settings(), *this, cond_index, _log());
249  //write_pos_trajectory(settings(), *this, cond_index);
250  }
251 
256  double Canonical::potential_energy(const Configuration &config) const {
257  //if(&config == &this->config()) { return potential_energy(); }
258 
259  auto corr = correlations(config, _clexulator());
260  return _eci() * corr.data();
261  }
262 
263  void Canonical::_set_nlist(Index l) const {
264  _clexulator().set_nlist(nlist().sites(nlist().unitcell_index(l)).data());
265  };
266 
267  void Canonical::_calc_delta_point_corr(Index l, int new_occ, Eigen::VectorXd &dCorr_comp) const {
268 
269  int sublat = _config().get_b(l);
270  int curr_occ = _configdof().occ(l);
271  _set_nlist(l);
272 
273  // Calculate the change in correlations due to this event
274  if(m_use_deltas) {
275  if(m_all_correlations) {
277  curr_occ,
278  new_occ,
279  dCorr_comp.data());
280  }
281  else {
282  auto begin = _eci().index().data();
283  auto end = begin + _eci().index().size();
285  curr_occ,
286  new_occ,
287  dCorr_comp.data(),
288  begin,
289  end);
290  }
291  }
292  else {
293  Eigen::VectorXd before { Eigen::VectorXd::Zero(dCorr_comp.size()) };
294  Eigen::VectorXd after { Eigen::VectorXd::Zero(dCorr_comp.size()) };
295 
296  // Calculate the change in points correlations due to this event
297  if(m_all_correlations) {
298 
299  // Calculate before
300  _clexulator().calc_point_corr(sublat, before.data());
301 
302  // Apply change
303  _configdof().occ(l) = new_occ;
304 
305  // Calculate after
306  _clexulator().calc_point_corr(sublat, after.data());
307  }
308  else {
309  auto begin = _eci().index().data();
310  auto end = begin + _eci().index().size();
311 
312  // Calculate before
313  _clexulator().calc_restricted_point_corr(sublat, before.data(), begin, end);
314 
315  // Apply change
316  _configdof().occ(l) = new_occ;
317 
318  // Calculate after
319  _clexulator().calc_restricted_point_corr(sublat, after.data(), begin, end);
320 
321  }
322  dCorr_comp = after - before;
323 
324  // Unapply changes
325  _configdof().occ(l) = curr_occ;
326  }
327  }
328 
331 
332  const OccEvent &e = event.occ_event();
333  const OccTransform &f_a = e.occ_transform[0];
334  const OccTransform &f_b = e.occ_transform[1];
335 
336  int curr_occ_a = _configdof().occ(f_a.l);
337  Index new_occ_a = m_convert.occ_index(f_a.asym, f_a.to_species);
338  Index new_occ_b = m_convert.occ_index(f_b.asym, f_b.to_species);
339 
340  Eigen::VectorXd dCorr_comp { Eigen::VectorXd::Zero(event.dCorr().size()) };
341 
342 
343  // Point the Clexulator to the right neighborhood and right ConfigDoF
344  _clexulator().set_config_occ(_configdof().occupation().begin());
345 
346  // calc dCorr for first site
347  _calc_delta_point_corr(f_a.l, new_occ_a, event.dCorr());
348 
349  // change occ on first site
350  _configdof().occ(f_a.l) = new_occ_a;
351 
352  // calc dCorr for second site
353  _calc_delta_point_corr(f_b.l, new_occ_b, dCorr_comp);
354  event.dCorr() += dCorr_comp;
355 
356  // unchange occ on first site
357  _configdof().occ(f_a.l) = curr_occ_a;
358 
359  if(debug()) {
360  _print_correlations(event.dCorr(), "delta correlations", "dCorr", m_all_correlations);
361  }
362  }
363 
366  const Eigen::VectorXd &corr,
367  std::string title,
368  std::string colheader,
369  bool all_correlations) const {
370 
371  _log().calculate(title);
372  _log() << std::setw(12) << "i"
373  << std::setw(16) << "ECI"
374  << std::setw(16) << colheader
375  << std::endl;
376 
377  for(int i = 0; i < corr.size(); ++i) {
378 
379  double eci = 0.0;
380  bool calculated = true;
381  Index index = find_index(_eci().index(), i);
382  if(index != _eci().index().size()) {
383  eci = _eci().value()[index];
384  }
385  if(!all_correlations && index == _eci().index().size()) {
386  calculated = false;
387  }
388 
389  _log() << std::setw(12) << i
390  << std::setw(16) << std::setprecision(8) << eci;
391  if(calculated) {
392  _log() << std::setw(16) << std::setprecision(8) << corr[i];
393  }
394  else {
395  _log() << std::setw(16) << "unknown";
396  }
397  _log() << std::endl;
398 
399  }
400  _log() << std::endl;
401  }
402 
405 
406  // ---- set dcorr --------------
407  _set_dCorr(event);
408 
409  // ---- set dformation_energy --------------
410  event.set_dEf(_eci() * event.dCorr().data());
411  }
412 
415 
416  // initialize properties and store pointers to the data strucures
418  m_corr = &_vector_property("corr");
419 
421  m_comp_n = &_vector_property("comp_n");
422 
423  _scalar_properties()["formation_energy"] = _eci() * corr().data();
424  m_formation_energy = &_scalar_property("formation_energy");
425 
426  _scalar_properties()["potential_energy"] = formation_energy();
427  m_potential_energy = &_scalar_property("potential_energy");
428 
429  if(debug()) {
430 
431  _print_correlations(corr(), "correlations", "corr", m_all_correlations);
432 
433  auto origin = primclex().composition_axes().origin();
434  auto comp_x = primclex().composition_axes().param_composition(comp_n());
435  auto M = primclex().composition_axes().dmol_dparam();
436 
437  _log().custom("Calculate properties");
438  _log() << "Canonical ensemble: \n"
439  << " Thermodynamic potential (per unitcell), phi = -kT*ln(Z)/N \n"
440  << " Partition function, Z = sum_i exp(-N*potential_energy_i/kT) \n"
441  << " composition, comp_n = origin + M * comp_x \n"
442  << " potential_energy (per unitcell) = formation_energy \n\n"
443 
444  << "components: " << jsonParser(primclex().composition_axes().components()) << "\n"
445  << "M:\n" << M << "\n"
446  << "origin: " << origin.transpose() << "\n"
447  << "comp_n: " << comp_n().transpose() << "\n"
448  << "comp_x: " << comp_x.transpose() << "\n"
449  << "formation_energy: " << formation_energy() << "\n"
450  << "potential_energy: " << potential_energy() << "\n" << std::endl;
451  }
452 
453  }
454 
457  _log().set("DoF");
458  _log() << "motif configname: default\n";
459  _log() << "using configuration with default occupation...\n" << std::endl;
460  return Configuration(_supercell(), jsonParser(), Array<int>(_supercell().num_sites(), 0)).configdof();
461  }
462 
466  std::pair<ConfigDoF, std::string> Canonical::_auto_motif(const CanonicalConditions &cond) const {
467  throw std::runtime_error("Canonical Monte Carlo 'auto' motif is not implemented yet");
468  }
469 
471  std::pair<ConfigDoF, std::string> Canonical::_restricted_auto_motif(const CanonicalConditions &cond) const {
472  throw std::runtime_error("Canonical Monte Carlo 'restricted_auto' motif is not implemented yet");
473  }
474 
477 
478  _log().set("DoF");
479  _log() << "motif configname: " << configname << "\n";
480  _log() << "using configation: " << configname << "\n" << std::endl;
481 
482  const Configuration &config = primclex().configuration(configname);
483  const SymGroup &g = primclex().get_prim().factor_group();
484  return config.fill_supercell(_supercell(), g).configdof();
485  }
486 
494  std::vector<OccSwap>::const_iterator
496  const Configuration &config,
497  std::vector<OccSwap>::const_iterator begin,
498  std::vector<OccSwap>::const_iterator end) {
499 
500  double dn = 1. / supercell().volume();
501  Eigen::VectorXd target_comp_n = conditions().mol_composition();
503 
504  typedef std::vector<OccSwap>::const_iterator it_type;
505  std::vector<std::pair<it_type, double> > best;
506  double best_dist = (comp_n - target_comp_n).norm();
507  double tol = primclex().settings().lin_alg_tol();
508 
509  for(auto it = begin; it != end; ++it) {
510  if(m_occ_loc.cand_size(it->cand_a)) {
511  Eigen::VectorXd tcomp_n = comp_n;
512  tcomp_n[it->cand_a.species_index] -= dn;
513  tcomp_n[it->cand_b.species_index] += dn;
514 
515  double dist = (tcomp_n - target_comp_n).norm();
516  if(dist < best_dist - tol) {
517  best.clear();
518  best.push_back({it, m_occ_loc.cand_size(it->cand_a)});
519  best_dist = dist;
520  }
521  else if(dist < best_dist + tol) {
522  best.push_back({it, m_occ_loc.cand_size(it->cand_a)});
523  }
524  }
525  }
526 
527  if(!best.size()) {
528  return end;
529  }
530 
531  // break ties randomly, weighted by number of candidates
532  double sum = 0.0;
533  for(const auto &val : best) {
534  sum += val.second;
535  }
536 
537  double rand = _mtrand().randExc(sum);
538  sum = 0.0;
539  int count = 0;
540  for(const auto &val : best) {
541  sum += val.second;
542  if(rand < sum) {
543  return val.first;
544  }
545  ++count;
546  }
547  throw std::runtime_error("Error enforcing composition");
548  }
549 
556 
557  _log().custom("Enforce composition");
558  Configuration tconfig(_supercell(), jsonParser(), configdof);
559  m_occ_loc.initialize(tconfig);
560  jsonParser json;
561 
562  _log() << " initial comp: " << to_json_array(CASM::comp(tconfig), json) << std::endl;
563  _log() << " initial comp_n: " << to_json_array(CASM::comp_n(tconfig), json) << std::endl;
564 
565  Eigen::VectorXd target_comp_n = conditions().mol_composition();
566  _log() << " target comp_n: " << to_json_array(target_comp_n, json) << std::endl;
567 
568  int count = 0;
569  OccEvent e;
570  ConfigDoF &tconfigdof = tconfig.configdof();
571  while(true) {
572  auto begin = m_cand.grand_canonical_swap().begin();
573  auto end = m_cand.grand_canonical_swap().end();
574  auto it = _find_grand_canonical_swap(tconfig, begin, end);
575 
576  if(it == end) {
577  _log() << " applied swaps: " << count << std::endl;
578  break;
579  }
580 
583  m_occ_loc.apply(e, tconfigdof);
584 
585  ++count;
586  }
587 
588  _log() << " final comp: " << to_json_array(CASM::comp(tconfig), json) << std::endl;
589  _log() << " final comp_n: " << to_json_array(CASM::comp_n(tconfig), json) << std::endl << std::endl;
590 
591  return tconfig.configdof();
592  }
593  }
594 }
void _print_correlations(const Eigen::VectorXd &corr, std::string title, std::string colheader, bool all_correlations) const
Print correlations to _log()
Definition: Canonical.cc:365
CanonicalEvent m_event
Event to propose, check, accept/reject:
Definition: Canonical.hh:214
pair_type eci
Definition: settings.cc:112
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.
ConfigDoF _enforce_conditions(const ConfigDoF &configdof)
Enforce composition by repeatedly applying grand canonical events.
Definition: Canonical.cc:555
ClexDescription & desc
Definition: settings.cc:104
Configuration fill_supercell(Supercell &scel, const SymOp &op) const
Fills supercell 'scel' with reoriented configuration, as if by apply(op,*this)
const SuperNeighborList & nlist() const
const Access the SuperNeighborList via pointer stored by 'set_nlist'
Definition: MonteCarlo.hh:83
Index l
Config occupant that is being transformed.
Definition: OccLocation.hh:43
CanonicalConditions m_condition
Conditions (T, mu). Initially determined by m_settings, but can be changed halfway through the run...
Definition: Canonical.hh:211
void initialize(const Configuration &config)
Fill tables with occupation info.
Definition: OccLocation.cc:18
int & occ(Index i)
Definition: ConfigDoF.hh:61
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:105
void write_conditions_json(const MonteSettings &settings, const MonteType &mc, Index cond_index, Log &_log)
Write conditions to conditions.cond_index directory.
void _update_deltas(CanonicalEvent &event) const
Calculate delta properties for an event and update the event with those properties.
Definition: Canonical.cc:404
VectorPropertyMap & _vector_properties()
const Access vector properties map
Definition: MonteCarlo.hh:227
void set_conditions(const CondType &new_conditions)
Set conditions and clear previously collected data.
Definition: Canonical.cc:77
Eigen::MatrixXd dmol_dparam() const
Return the matrix Mij = dn_i/dx_j.
Eigen::VectorXd origin() const
The mol composition of the parameteric composition axes origin.
Eigen::VectorXd param_composition(const Eigen::VectorXd &n) const
Convert number of mol per prim, 'n' to parametric composition 'x'.
ConfigDoF & _configdof() const
Access current microstate.
Definition: MonteCarlo.hh:204
fs::path get_path() const
Return casm project directory path.
Definition: PrimClex.cc:202
const Eigen::VectorXd & comp_n() const
Number of atoms of each type, normalized per primitive cell.
Definition: Canonical.hh:109
PrimClex * primclex
Definition: settings.cc:101
const std::vector< OccSwap > & canonical_swap() const
void set_configdof(const ConfigDoF &configdof, const std::string &msg="")
Set configdof and clear previously collected data.
Definition: Canonical.cc:90
Eigen::VectorXd & _corr()
Correlations, normalized per primitive cell.
Definition: Canonical.hh:130
const Configuration & config() const
const Access current microstate
Definition: MonteCarlo.hh:88
Eigen::VectorXd * m_corr
Correlations, normalized per primitive cell.
Definition: Canonical.hh:226
Correlation correlations(const ConfigDoF &configdof, const Supercell &scel, Clexulator &clexulator)
Returns correlations using 'clexulator'. Supercell needs a correctly populated neighbor list...
Definition: ConfigDoF.cc:200
const ConfigDoF & configdof() const
const Access the DoF
OccEvent & propose_grand_canonical(OccEvent &e, const OccSwap &swap, MTRand &mtrand) const
Propose grand canonical OccEvent.
Definition: OccLocation.cc:143
Index find_index(Iterator begin, Iterator end, const T &value)
Equivalent to std::distance(begin, std::find(begin, end, value))
Definition: algorithm.hh:16
Index asym
Asym index.
Definition: OccLocation.hh:45
ENSEMBLE
Monte Carlo ensemble type.
const ConfigDoF & configdof() const
const Access current microstate
Definition: MonteCarlo.hh:93
int get_b(Index site_l) const
Get the basis site index for a given linear linear site index.
const ClexDescription & desc() const
Definition: Clex.cc:12
void reset(const ConfigDoF &dof)
Set current microstate and clear samplers.
Definition: MonteCarlo.hh:101
Main CASM namespace.
Definition: complete.cpp:8
OccLocation m_occ_loc
Keeps track of what sites have which occupants.
Definition: Canonical.hh:208
Log & log
Definition: settings.cc:105
Eigen::VectorXd comp(const Configuration &config)
Returns parametric composition, as calculated using PrimClex::param_comp.
bool m_use_deltas
If the supercell is large enough, calculate delta correlations directly.
Definition: Canonical.hh:205
const double & potential_energy() const
Potential energy, normalized per primitive cell.
Definition: Canonical.hh:99
double dEpot() const
Return change in (extensive) potential energy, dEpot = dEf.
std::vector< OccTransform > occ_transform
Definition: OccLocation.hh:62
void set(const std::string &what)
Definition: Log.hh:46
std::pair< ConfigDoF, std::string > _auto_motif(const CanonicalConditions &cond) const
Generate minimum potential energy ConfigDoF.
Definition: Canonical.cc:466
bool debug() const
return true if running in debug mode
Definition: MonteCarlo.hh:171
double * m_potential_energy
Potential energy, normalized per primitive cell.
Definition: Canonical.hh:223
std::pair< ConfigDoF, std::string > _restricted_auto_motif(const CanonicalConditions &cond) const
Generate minimum potential energy ConfigDoF for this supercell.
Definition: Canonical.cc:471
void write_results(Index cond_index) const
Write results to files.
Definition: Canonical.cc:244
void calc_point_corr(int b_index, double *corr_begin) const
Calculate point correlations about basis site 'b_index'.
Definition: Clexulator.hh:467
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:186
size_type cand_size(Index cand_index) const
Total number of mutating sites, of OccCandidate type, specified by index.
Definition: OccLocation.cc:91
const std::vector< double > & value() const
const Access ECI values
Definition: ECIContainer.hh:44
Configuration & _config() const
Access current microstate.
Definition: MonteCarlo.hh:196
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:33
Eigen::VectorXd comp_n(const ConfigDoF &configdof, const Supercell &scel)
Returns comp_n, the number of each molecule per primitive cell, ordered as Structure::get_struc_molec...
Definition: ConfigDoF.cc:312
double tol
void construct(const std::string &what)
Definition: Log.hh:36
void custom(const std::string &what)
Definition: Log.hh:96
Log & _log() const
Definition: MonteCarlo.hh:208
double * m_formation_energy
Formation energy, normalized per primitive cell.
Definition: Canonical.hh:220
double formation_energy(const Configuration &config)
Returns the formation energy, normalized per unit cell.
void set_config_occ(const int *_occ_ptr)
Set pointer to data structure containing occupation variables.
Definition: Clexulator.hh:400
bool m_all_correlations
If true, calculate all correlations; if false, calculate correlations with non-zero eci...
Definition: Canonical.hh:201
bool is_motif_configname() const
Returns true if configname of configuration to use as starting motif has been specified.
std::string motif_configname() const
Configname of configuration to use as starting motif.
const MasterSymGroup & factor_group() const
Definition: Structure.cc:94
void set_nlist()
Set a pointer to the SuperNeighborList once it is ready.
Definition: MonteCarlo.hh:78
bool is_motif_configdof() const
Returns true if path to ConfigDoF file to use as starting motif has been specified.
const Supercell & supercell() const
const Access the Supercell that *this is based on
Definition: MonteCarlo.hh:73
void write_trajectory(const MonteSettings &settings, const MonteCarlo &mc, Index cond_index, Log &_log)
Will create (and possibly overwrite) new file with all observations from run with conditions...
Definition: MonteIO.cc:269
OccEvent & occ_event()
Access the data describing this event.
Eigen::VectorXd & dCorr()
Access the changes in (extensive) correlations associated with this event.
void calc_delta_point_corr(int b_index, int occ_i, int occ_f, double *corr_begin) const
Calculate the change in point correlations due to changing an occupant.
Definition: Clexulator.hh:507
T norm(const Tensor< T > &ttens)
Definition: Tensor.hh:968
EigenIndex Index
For long integer indexing:
Index volume() const
Return number of primitive cells that fit inside of *this.
Definition: Supercell.hh:212
Canonical(PrimClex &primclex, const SettingsType &settings, Log &_log)
Constructs a Canonical object and prepares it for running based on MonteSettings. ...
Definition: Canonical.cc:18
A container class for the different degrees of freedom a Configuration might have.
Definition: ConfigDoF.hh:27
void calculate(const std::string &what)
Definition: Log.hh:31
Eigen::VectorXd & _comp_n()
Number of atoms of each type, normalized per primitive cell.
Definition: Canonical.hh:135
Eigen::VectorXd mol_composition() const
mol composition: comp_n
void apply(const OccEvent &e, ConfigDoF &configdof)
Update configdof and this to reflect that event 'e' occurred.
Definition: OccLocation.cc:161
const PrimClex & primclex() const
const Access the PrimClex that *this is based on
Definition: MonteCarlo.hh:68
ProjectSettings & settings()
Definition: PrimClex.hh:116
Clex m_formation_energy_clex
Holds Clexulator and ECI references.
Definition: Canonical.hh:192
Eigen::VectorXd & _vector_property(std::string property_name)
const Access a particular vector property
Definition: MonteCarlo.hh:232
Eigen::VectorXd VectorXd
void accept(const EventType &event)
Accept proposed event. Change configuration accordingly and update energies etc.
Definition: Canonical.cc:215
const std::vector< size_type > & index() const
const Access orbit indices of ECI values
Definition: ECIContainer.hh:49
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
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:495
void write_observations(const MonteSettings &settings, const MonteCarlo &mc, Index cond_index, Log &_log)
Will create (and possibly overwrite) new file with all observations from run with conditions...
Definition: MonteIO.cc:213
const CompositionConverter & composition_axes() const
const Access CompositionConverter object
Definition: PrimClex.cc:237
Data structure for storing information regarding a proposed grand canonical Monte Carlo event...
void calc_restricted_point_corr(int b_index, double *corr_begin, size_type const *ind_list_begin, size_type const *ind_list_end) const
Calculate select point correlations about basis site 'b_index'.
Definition: Clexulator.hh:487
double & _formation_energy()
Formation energy, normalized per primitive cell.
Definition: Canonical.hh:120
Index occ_index(Index asym, Index species_index) const
Definition: Conversions.cc:130
const Configuration & configuration(const std::string &configname) const
access configuration by name (of the form "scellname/[NUMBER]", e.g., ("SCEL1_1_1_1_0_0_0/0") ...
Definition: PrimClex.cc:347
const Eigen::VectorXd & corr() const
Correlations, normalized per primitive cell.
Definition: Canonical.hh:104
Conversions m_convert
Convert sublat/asym_unit and species/occ index.
Definition: Canonical.hh:195
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: container.hh:191
void calc_restricted_delta_point_corr(int b_index, int occ_i, int occ_f, double *corr_begin, size_type const *ind_list_begin, size_type const *ind_list_end) const
Calculate the change in select point correlations due to changing an occupant.
Definition: Clexulator.hh:529
ConfigIO::GenericConfigFormatter< std::string > configname()
Constructs DataFormmaterDictionary containing all Configuration DatumFormatters.
Definition: ConfigIO.cc:340
OccEvent & propose_canonical(OccEvent &e, const std::vector< OccSwap > &canonical_swap, MTRand &mtrand) const
Propose canonical OccEvent.
Definition: OccLocation.cc:116
Interface base class for all types of Monte Carlo simulations (not meant to be used polymorphically) ...
Definition: MonteCarlo.hh:32
const EventType & propose()
Propose a new event, calculate delta properties, and return reference to it.
Definition: Canonical.cc:179
const CondType & conditions() const
Return current conditions.
Definition: Canonical.cc:71
Eigen::VectorXd * m_comp_n
Number of atoms of each type, normalized per primitive cell.
Definition: Canonical.hh:229
ConfigDoF motif_configdof() const
ConfigDoF to use as starting motif.
Supercell & _supercell() const
Access the Supercell that *this is based on.
Definition: MonteCarlo.hh:188
Index to_species
Species index after transformation.
Definition: OccLocation.hh:47
OccCandidateList m_cand
Convert sublat/asym_unit and species/occ index.
Definition: Canonical.hh:198
Index steps_per_pass() const
Return number of steps per pass. Equals number of sites with variable occupation. ...
Definition: Canonical.cc:65
bool overlaps() const
Returns true if periodic images of the neighbor list overlap.
bool must_converge() const
Return true if convergence is requested.
Definition: MonteCarlo.hh:139
double & _potential_energy()
Potential energy, normalized per primitive cell.
Definition: Canonical.hh:125
void _calc_delta_point_corr(Index l, int new_occ, Eigen::VectorXd &dCorr_comp) const
Definition: Canonical.cc:267
double & _scalar_property(std::string property_name)
Access a particular scalar property.
Definition: MonteCarlo.hh:222
ConfigDoF _configname_motif(const std::string &configname) const
Generate supercell filling ConfigDoF from configuration.
Definition: Canonical.cc:476
size_type size() const
Total number of mutating sites.
Definition: OccLocation.cc:78
void set_nlist(const long int *_nlist_ptr)
Set pointer to neighbor list.
Definition: Clexulator.hh:413
void _set_nlist(Index l) const
Definition: Canonical.cc:263
void reject(const EventType &event)
Nothing needs to be done to reject a CanonicalEvent.
Definition: Canonical.cc:235
ConfigDoF _default_motif() const
Generate supercell filling ConfigDoF from default configuration.
Definition: Canonical.cc:456
Definition: Log.hh:9
MTRand & _mtrand()
Definition: MonteCarlo.hh:212
const Eigen::Matrix3i & get_transf_mat() const
Definition: Supercell.hh:263
ScalarPropertyMap & _scalar_properties()
Access scalar properties map.
Definition: MonteCarlo.hh:217
static const Monte::ENSEMBLE ensemble
Definition: Canonical.hh:38
const ECIContainer & _eci() const
Definition: Canonical.hh:143
Clexulator & _clexulator() const
Definition: Canonical.hh:139
void _update_properties()
Calculate properties given current conditions.
Definition: Canonical.cc:414
Eigen::VectorXd correlations_vec(const ConfigDoF &configdof, const Supercell &scel, Clexulator &clexulator)
Returns correlations using 'clexulator'. Supercell needs a correctly populated neighbor list...
Definition: ConfigDoF.cc:242
const SamplerMap & samplers() const
const Access sampler map
Definition: MonteCarlo.hh:153
fs::path motif_configdof_path() const
Path to ConfigDoF file to use as starting motif.
const MonteSettings & settings() const
const Access settings used for construction
Definition: MonteCarlo.hh:63
const std::vector< OccSwap > & grand_canonical_swap() const
A Configuration represents the values of all degrees of freedom in a Supercell.
const double & formation_energy() const
Formation energy, normalized per primitive cell.
Definition: Canonical.hh:94
const Structure & get_prim() const
const Access to primitive Structure
Definition: PrimClex.cc:260
void _set_dCorr(CanonicalEvent &event) const
Calculate delta correlations for an event.
Definition: Canonical.cc:330
double lin_alg_tol() const
Get current project linear algebra tolerance.