21 m_convert(_supercell()),
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()) {
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";
46 _log() <<
"\nSampling: \n";
47 _log() << std::setw(24) <<
"quantity" << std::setw(24) <<
"requested_precision" <<
"\n";
49 _log() << std::setw(24) << it->first;
50 if(it->second->must_converge()) {
51 _log() << std::setw(24) << it->second->requested_precision() << std::endl;
54 _log() << std::setw(24) <<
"none" << std::endl;
57 _log() <<
"\nautomatic convergence mode?: " << std::boolalpha <<
must_converge() << std::endl;
60 _log() << std::pair<const OccCandidateList &, const Conversions &>(
m_cand,
m_convert) << std::endl;
79 _log() << new_conditions << std::endl << std::endl;
93 _log() << msg <<
"\n";
110 _log() << new_conditions << std::endl;
121 if(configname ==
"default") {
124 else if(configname ==
"auto") {
125 std::tie(configdof, configname) =
_auto_motif(new_conditions);
127 else if(configname ==
"restricted_auto") {
143 throw std::runtime_error(
"Error: Must specify motif \"configname\" or \"configdof\"");
149 return std::make_pair(configdof, configname);
155 const std::string &msg) {
157 _log() << new_conditions << std::endl << std::endl;
163 _log() << msg <<
"\n";
188 if(event.
dEpot() < 0.0) {
192 _log() <<
"Probability to accept: 1.0\n" << std::endl;
197 double rand =
_mtrand().rand53();
202 _log() <<
"Probability to accept: " << prob <<
"\n"
203 <<
"Random number: " << rand <<
"\n" << std::endl;
283 auto end = begin +
_eci().
index().size();
310 auto end = begin +
_eci().
index().size();
322 dCorr_comp = after - before;
332 const OccEvent &e =
event.occ_event();
354 event.dCorr() += dCorr_comp;
368 std::string colheader,
369 bool all_correlations)
const {
372 _log() << std::setw(12) <<
"i"
373 << std::setw(16) <<
"ECI"
374 << std::setw(16) << colheader
377 for(
int i = 0; i < corr.size(); ++i) {
380 bool calculated =
true;
382 if(index !=
_eci().index().size()) {
385 if(!all_correlations && index ==
_eci().index().size()) {
389 _log() << std::setw(12) << i
390 << std::setw(16) << std::setprecision(8) <<
eci;
392 _log() << std::setw(16) << std::setprecision(8) << corr[i];
395 _log() << std::setw(16) <<
"unknown";
410 event.set_dEf(
_eci() * event.
dCorr().data());
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"
445 <<
"M:\n" << M <<
"\n"
446 <<
"origin: " << origin.transpose() <<
"\n"
447 <<
"comp_n: " <<
comp_n().transpose() <<
"\n"
448 <<
"comp_x: " << comp_x.transpose() <<
"\n"
458 _log() <<
"motif configname: default\n";
459 _log() <<
"using configuration with default occupation...\n" << std::endl;
467 throw std::runtime_error(
"Canonical Monte Carlo 'auto' motif is not implemented yet");
472 throw std::runtime_error(
"Canonical Monte Carlo 'restricted_auto' motif is not implemented yet");
479 _log() <<
"motif configname: " << configname <<
"\n";
480 _log() <<
"using configation: " << configname <<
"\n" << std::endl;
494 std::vector<OccSwap>::const_iterator
497 std::vector<OccSwap>::const_iterator begin,
498 std::vector<OccSwap>::const_iterator end) {
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();
509 for(
auto it = begin; it != end; ++it) {
512 tcomp_n[it->cand_a.species_index] -= dn;
513 tcomp_n[it->cand_b.species_index] += dn;
515 double dist = (tcomp_n - target_comp_n).
norm();
516 if(dist < best_dist - tol) {
521 else if(dist < best_dist + tol) {
533 for(
const auto &val : best) {
537 double rand =
_mtrand().randExc(sum);
540 for(
const auto &val : best) {
547 throw std::runtime_error(
"Error enforcing composition");
577 _log() <<
" applied swaps: " << count << std::endl;
void _print_correlations(const Eigen::VectorXd &corr, std::string title, std::string colheader, bool all_correlations) const
Print correlations to _log()
CanonicalEvent m_event
Event to propose, check, accept/reject:
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.
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'
CanonicalConditions m_condition
Conditions (T, mu). Initially determined by m_settings, but can be changed halfway through the run...
void initialize(const Configuration &config)
Fill tables with occupation info.
std::pair< ConfigDoF, std::string > set_state(const CanonicalConditions &new_conditions, const CanonicalSettings &settings)
Set configdof and conditions and clear previously collected data.
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.
VectorPropertyMap & _vector_properties()
const Access vector properties map
void set_conditions(const CondType &new_conditions)
Set conditions and clear previously collected data.
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.
fs::path get_path() const
Return casm project directory path.
const Eigen::VectorXd & comp_n() const
Number of atoms of each type, normalized per primitive cell.
const std::vector< OccSwap > & canonical_swap() const
void set_configdof(const ConfigDoF &configdof, const std::string &msg="")
Set configdof and clear previously collected data.
Eigen::VectorXd & _corr()
Correlations, normalized per primitive cell.
const Configuration & config() const
const Access current microstate
Eigen::VectorXd * m_corr
Correlations, normalized per primitive cell.
Correlation correlations(const ConfigDoF &configdof, const Supercell &scel, Clexulator &clexulator)
Returns correlations using 'clexulator'. Supercell needs a correctly populated neighbor list...
const ConfigDoF & configdof() const
const Access the DoF
OccEvent & propose_grand_canonical(OccEvent &e, const OccSwap &swap, MTRand &mtrand) const
Propose grand canonical OccEvent.
Index find_index(Iterator begin, Iterator end, const T &value)
Equivalent to std::distance(begin, std::find(begin, end, value))
ENSEMBLE
Monte Carlo ensemble type.
const ConfigDoF & configdof() const
const Access current microstate
int get_b(Index site_l) const
Get the basis site index for a given linear linear site index.
const ClexDescription & desc() const
void reset(const ConfigDoF &dof)
Set current microstate and clear samplers.
OccLocation m_occ_loc
Keeps track of what sites have which occupants.
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.
const double & potential_energy() const
Potential energy, normalized per primitive cell.
double dEpot() const
Return change in (extensive) potential energy, dEpot = dEf.
std::vector< OccTransform > occ_transform
void set(const std::string &what)
std::pair< ConfigDoF, std::string > _auto_motif(const CanonicalConditions &cond) const
Generate minimum potential energy ConfigDoF.
bool debug() const
return true if running in debug mode
double * m_potential_energy
Potential energy, normalized per primitive cell.
std::pair< ConfigDoF, std::string > _restricted_auto_motif(const CanonicalConditions &cond) const
Generate minimum potential energy ConfigDoF for this supercell.
void write_results(Index cond_index) const
Write results to files.
void calc_point_corr(int b_index, double *corr_begin) const
Calculate point correlations about basis site 'b_index'.
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 ...
size_type cand_size(Index cand_index) const
Total number of mutating sites, of OccCandidate type, specified by index.
const std::vector< double > & value() const
const Access ECI values
Configuration & _config() const
Access current microstate.
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
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...
void construct(const std::string &what)
void custom(const std::string &what)
double * m_formation_energy
Formation energy, normalized per primitive cell.
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.
bool m_all_correlations
If true, calculate all correlations; if false, calculate correlations with non-zero eci...
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
void set_nlist()
Set a pointer to the SuperNeighborList once it is ready.
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
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...
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.
T norm(const Tensor< T > &ttens)
EigenIndex Index
For long integer indexing:
Index volume() const
Return number of primitive cells that fit inside of *this.
Canonical(PrimClex &primclex, const SettingsType &settings, Log &_log)
Constructs a Canonical object and prepares it for running based on MonteSettings. ...
A container class for the different degrees of freedom a Configuration might have.
void calculate(const std::string &what)
Eigen::VectorXd & _comp_n()
Number of atoms of each type, normalized per primitive cell.
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.
const PrimClex & primclex() const
const Access the PrimClex that *this is based on
ProjectSettings & settings()
Clex m_formation_energy_clex
Holds Clexulator and ECI references.
Eigen::VectorXd & _vector_property(std::string property_name)
const Access a particular vector property
void accept(const EventType &event)
Accept proposed event. Change configuration accordingly and update energies etc.
const std::vector< size_type > & index() const
const Access orbit indices of ECI values
PrimClex is the top-level data structure for a CASM project.
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.
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...
const CompositionConverter & composition_axes() const
const Access CompositionConverter object
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'.
double & _formation_energy()
Formation energy, normalized per primitive cell.
Index occ_index(Index asym, Index species_index) const
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") ...
const Eigen::VectorXd & corr() const
Correlations, normalized per primitive cell.
Conversions m_convert
Convert sublat/asym_unit and species/occ index.
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.
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.
ConfigIO::GenericConfigFormatter< std::string > configname()
Constructs DataFormmaterDictionary containing all Configuration DatumFormatters.
OccEvent & propose_canonical(OccEvent &e, const std::vector< OccSwap > &canonical_swap, MTRand &mtrand) const
Propose canonical OccEvent.
Interface base class for all types of Monte Carlo simulations (not meant to be used polymorphically) ...
const EventType & propose()
Propose a new event, calculate delta properties, and return reference to it.
const CondType & conditions() const
Return current conditions.
Eigen::VectorXd * m_comp_n
Number of atoms of each type, normalized per primitive cell.
ConfigDoF motif_configdof() const
ConfigDoF to use as starting motif.
Supercell & _supercell() const
Access the Supercell that *this is based on.
OccCandidateList m_cand
Convert sublat/asym_unit and species/occ index.
Index steps_per_pass() const
Return number of steps per pass. Equals number of sites with variable occupation. ...
bool overlaps() const
Returns true if periodic images of the neighbor list overlap.
bool must_converge() const
Return true if convergence is requested.
double & _potential_energy()
Potential energy, normalized per primitive cell.
void _calc_delta_point_corr(Index l, int new_occ, Eigen::VectorXd &dCorr_comp) const
double & _scalar_property(std::string property_name)
Access a particular scalar property.
ConfigDoF _configname_motif(const std::string &configname) const
Generate supercell filling ConfigDoF from configuration.
size_type size() const
Total number of mutating sites.
void set_nlist(const long int *_nlist_ptr)
Set pointer to neighbor list.
void _set_nlist(Index l) const
void reject(const EventType &event)
Nothing needs to be done to reject a CanonicalEvent.
ConfigDoF _default_motif() const
Generate supercell filling ConfigDoF from default configuration.
const Eigen::Matrix3i & get_transf_mat() const
ScalarPropertyMap & _scalar_properties()
Access scalar properties map.
static const Monte::ENSEMBLE ensemble
const ECIContainer & _eci() const
Clexulator & _clexulator() const
void _update_properties()
Calculate properties given current conditions.
Eigen::VectorXd correlations_vec(const ConfigDoF &configdof, const Supercell &scel, Clexulator &clexulator)
Returns correlations using 'clexulator'. Supercell needs a correctly populated neighbor list...
const SamplerMap & samplers() const
const Access sampler map
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
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.
const Structure & get_prim() const
const Access to primitive Structure
void _set_dCorr(CanonicalEvent &event) const
Calculate delta correlations for an event.
double lin_alg_tol() const
Get current project linear algebra tolerance.