18 const CanonicalSettings &settings, Log &_log);
20 const CanonicalSettings &settings,
21 Log &
log, Canonical &mc);
39 m_convert(_supercell()),
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()) {
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";
64 _log() <<
"\nSampling: \n";
65 _log() << std::setw(24) <<
"quantity" << std::setw(24)
66 <<
"requested_precision"
69 _log() << std::setw(24) << it->first;
70 if (it->second->must_converge()) {
71 _log() << std::setw(24) << it->second->requested_precision() << std::endl;
73 _log() << std::setw(24) <<
"none" << std::endl;
76 _log() <<
"\nautomatic convergence mode?: " << std::boolalpha
80 _log() << std::pair<const OccCandidateList &, const Conversions &>(
m_cand,
95 _log() << new_conditions << std::endl << std::endl;
107 const std::string &msg) {
110 _log() << msg <<
"\n";
126 _log() << new_conditions << std::endl;
155 throw std::runtime_error(
156 "Error: Must specify motif \"configname\" or \"configdof\"");
167 const ConfigDoF &configdof,
const std::string &msg) {
169 _log() << new_conditions << std::endl << std::endl;
175 _log() << msg <<
"\n";
202 if (event.
dEpot() < 0.0) {
205 _log() <<
"Probability to accept: 1.0\n" << std::endl;
210 double rand =
_mtrand().rand53();
215 _log() <<
"Probability to accept: " << prob <<
"\n"
216 <<
"Random number: " << rand <<
"\n"
289 new_occ, dCorr_comp.data(),
end_ptr(dCorr_comp));
292 auto end = begin +
_eci().
index().size();
296 new_occ, dCorr_comp.data(),
end_ptr(dCorr_comp), begin, end);
308 before.data(),
end_ptr(before));
320 auto end = begin +
_eci().
index().size();
326 before.data(),
end_ptr(before), begin, end);
335 after.data(),
end_ptr(after), begin, end);
337 dCorr_comp = after - before;
364 event.
dCorr() += dCorr_comp;
377 std::string title, std::string colheader,
378 bool all_correlations)
const {
380 _log() << std::setw(12) <<
"i" << std::setw(16) <<
"ECI" << std::setw(16)
381 << colheader << std::endl;
383 for (
int i = 0; i <
corr.size(); ++i) {
385 bool calculated =
true;
387 if (index !=
_eci().index().size()) {
390 if (!all_correlations && index ==
_eci().index().size()) {
394 _log() << std::setw(12) << i << std::setw(16) << std::setprecision(8)
397 _log() << std::setw(16) << std::setprecision(8) <<
corr[i];
399 _log() << std::setw(16) <<
"unknown";
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"
449 <<
"origin: " << origin.transpose() <<
"\n"
450 <<
"comp_n: " <<
comp_n().transpose() <<
"\n"
451 <<
"comp_x: " << comp_x.transpose() <<
"\n"
461 _log() <<
"motif configname: default\n";
462 _log() <<
"using configuration with default occupation...\n" << std::endl;
472 throw std::runtime_error(
473 "Canonical Monte Carlo 'auto' motif is not implemented yet");
479 throw std::runtime_error(
480 "Canonical Monte Carlo 'restricted_auto' motif is not implemented yet");
487 _log() <<
"using configation: " <<
configname <<
"\n" << std::endl;
502 std::vector<OccSwap>::const_iterator end) {
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();
512 for (
auto it = begin; it != end; ++it) {
515 tcomp_n[it->cand_a.species_index] -= dn;
516 tcomp_n[it->cand_b.species_index] += dn;
518 double dist = (tcomp_n - target_comp_n).
norm();
519 if (dist < best_dist - tol) {
523 }
else if (dist < best_dist + tol) {
535 for (
const auto &val : best) {
542 for (
const auto &val : best) {
549 throw std::runtime_error(
"Error enforcing composition");
581 _log() <<
" applied swaps: " <<
count << std::endl;
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'.
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.
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'.
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.
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.
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
const std::vector< double > & value() const
const Access ECI values
void custom(const std::string &what)
void set(const std::string &what)
void calculate(const std::string &what)
void construct(const std::string &what)
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.
void _calc_delta_point_corr(size_type l, int new_occ, Eigen::VectorXd &dCorr_comp) const
CanonicalConditions m_condition
void accept(const EventType &event)
Accept proposed event. Change configuration accordingly and update energies etc.
ConfigDoF _default_motif() const
Generate supercell filling ConfigDoF from default configuration.
CanonicalEvent m_event
Event to propose, check, accept/reject:
Eigen::VectorXd & _comp_n()
Number of atoms of each type, normalized per primitive cell.
void write_results(size_type cond_index) const
Write results to files.
const Eigen::VectorXd & corr() const
Correlations, normalized per primitive cell.
const Eigen::VectorXd & comp_n() const
Number of atoms of each type, normalized per primitive cell.
void _update_properties()
Calculate properties given current conditions.
std::pair< ConfigDoF, std::string > set_state(const CanonicalConditions &new_conditions, const CanonicalSettings &settings)
Set configdof and conditions and clear previously collected data.
ConfigDoF _configname_motif(const std::string &configname) const
Generate supercell filling ConfigDoF from configuration.
size_type steps_per_pass() const
Return number of steps per pass. Equals number of sites with variable occupation.
const double & formation_energy() const
Formation energy, normalized per primitive cell.
void reject(const EventType &event)
Nothing needs to be done to reject a CanonicalEvent.
Eigen::VectorXd & _corr()
Correlations, normalized per primitive cell.
Conversions m_convert
Convert sublat/asym_unit and species/occ index.
ConfigDoF _enforce_conditions(const ConfigDoF &configdof)
Enforce composition by repeatedly applying grand canonical events.
void set_configdof(const ConfigDoF &configdof, const std::string &msg="")
Set configdof and clear previously collected data.
Eigen::VectorXd * m_corr
Correlations, normalized per primitive cell.
void set_conditions(const CondType &new_conditions)
Set conditions and clear previously collected data.
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.
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 ...
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 _update_deltas(CanonicalEvent &event) const
Calculate delta properties for an event and update the event with those properties.
static const ENSEMBLE ensemble
Canonical(const PrimClex &primclex, const SettingsType &settings, Log &_log)
Constructs a Canonical object and prepares it for running based on Settings.
const double & potential_energy() const
Potential energy, normalized per primitive cell.
const ECIContainer & _eci() const
double * m_formation_energy
Formation energy, normalized per primitive cell.
OccCandidateList m_cand
Convert sublat/asym_unit and species/occ index.
double & _formation_energy()
Formation energy, normalized per primitive cell.
double & _potential_energy()
Potential energy, normalized per primitive cell.
const EventType & propose()
Propose a new event, calculate delta properties, and return reference to it.
std::pair< ConfigDoF, std::string > _auto_motif(const CanonicalConditions &cond) const
Generate minimum potential energy ConfigDoF.
void _print_correlations(const Eigen::VectorXd &corr, std::string title, std::string colheader, bool all_correlations) const
Print correlations to _log()
OccLocation m_occ_loc
Keeps track of what sites have which occupants.
bool m_use_deltas
If the supercell is large enough, calculate delta correlations directly.
Eigen::VectorXd * m_comp_n
Number of atoms of each type, normalized per primitive cell.
Clexulator const & _clexulator() const
void _set_dCorr(CanonicalEvent &event) const
Calculate delta correlations for an event.
ClexDescription formation_energy(const PrimClex &primclex) const
Get formation energy cluster expansion.
Index occ_index(Index asym, Index species_index) const
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)
double & _scalar_property(std::string property_name)
Access a particular scalar property.
VectorPropertyMap & _vector_properties()
const Access vector properties map
ConfigDoF & _configdof() const
Access current microstate.
const Supercell & _supercell() const
Access the Supercell that *this is based on.
void set_nlist()
Set a pointer to the SuperNeighborList once it is ready.
const SuperNeighborList & nlist() const
const Access the SuperNeighborList via pointer stored by 'set_nlist'
ScalarPropertyMap & _scalar_properties()
Access scalar properties map.
const Supercell & supercell() const
const Access the Supercell that *this is based on
const MonteSettings & settings() const
const Access settings used for construction
void reset(const ConfigDoF &dof)
Set current microstate and clear samplers.
const Configuration & config() const
const Access current microstate
const PrimClex & primclex() const
const Access the PrimClex that *this is based on
Configuration & _config() const
Access current microstate.
Eigen::VectorXd & _vector_property(std::string property_name)
const Access a particular vector property
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
bool debug() const
return true if running in debug mode
const SamplerMap & samplers() const
const Access sampler map
bool must_converge() const
Return true if convergence is requested.
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.
OccEvent & propose_grand_canonical(OccEvent &e, const OccSwap &swap, MTRand &mtrand) const
Propose grand canonical OccEvent.
void apply(const OccEvent &e, ConfigDoF &configdof)
Update configdof and this to reflect that event 'e' occurred.
size_type size() const
Total number of mutating sites.
OccEvent & propose_canonical(OccEvent &e, const std::vector< OccSwap > &canonical_swap, MTRand &mtrand) const
Propose canonical OccEvent.
void initialize(const Configuration &config)
Fill tables with occupation info.
PrimClex is the top-level data structure for a CASM project.
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
Index volume() const
Return number of primitive cells that fit inside of *this.
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
ProjectSettings & settings()
const DirectoryStructure & dir() const
Access DirectoryStructure object. Throw if not set.
const CompositionConverter & composition_axes() const
const Access CompositionConverter object
T norm(const Tensor< T > &ttens)
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.
ConfigIO::GenericConfigFormatter< jsonParser > config()
ConfigIO::GenericConfigFormatter< std::string > configname()
Constructs DataFormmaterDictionary containing all Configuration DatumFormatters.
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....
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....
Clex make_clex(PrimClex const &primclex, CanonicalSettings const &settings)
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()
Configuration fill_supercell(Configuration const &motif, std::shared_ptr< Supercell const > const &shared_supercell)
Index find_index(Iterator begin, Iterator end, const T &value)
Equivalent to std::distance(begin, std::find(begin, end, value))
Container::value_type sum(const Container &container, typename Container::value_type init_val=0)
Iterator find(Iterator begin, Iterator end, const T &value, BinaryCompare q)
Equivalent to std::find(begin, end, value), but with custom comparison.
T * end_ptr(std::vector< T > &container)
Return pointer one past end of vector. Equivalent to convainer.data()+container.size()
INDEX_TYPE Index
For long integer indexing:
Specifies a particular cluster expansion.
Pair of Clexulator and ECIContainer.
std::vector< OccTransform > occ_transform