18 sout << desc << std::endl;
23 sout << desc << std::endl;
25 sout <<
"DESCRIPTION\n" <<
26 " Perform Monte Carlo calculations. \n\n" <<
28 " casm monte --settings input_file.json \n" <<
29 " - Run Monte Carlo calculations given the input file \n" <<
31 " - See 'casm format --monte' for a description of the \n" <<
32 " Monte Carlo input file. \n\n" <<
34 " casm monte --settings input_file.json --initial-POSCAR 3 \n" <<
35 " - Write a POSCAR.initial file containing the initial state of\n" <<
36 " the Monte Carlo calculation. The argument is a condition\n" <<
37 " index specifying which run is being requested.\n" <<
38 " - Written at: output_directory/conditions.3/trajectory/POSCAR.initial\n\n" <<
40 " casm monte --settings input_file.json --final-POSCAR 3 \n" <<
41 " - Write a POSCAR.final file containing the final state of\n" <<
42 " the Monte Carlo calculation. The argument is a condition\n" <<
43 " index specifying which run is being requested.\n" <<
44 " - Written at: output_directory/conditions.3/trajectory/POSCAR.final\n\n" <<
46 " casm monte --settings input_file.json --traj-POSCAR 5 \n" <<
47 " - Write the Monte Carlo calculation trajectory as a \n" <<
48 " series of POSCAR files containing the state of the \n" <<
49 " Monte Carlo calculation every time a sample was taken.\n" <<
50 " The argument is a condition index specifying which run\n" <<
51 " is being requested. \n" <<
52 " - The trajectory file must exist. This is generated when\n" <<
53 " using input option \"data\"/\"storage\"/\"write_trajectory\" = true \n" <<
54 " - Written at: output_directory/conditions.5/trajectory/POSCAR.i,\n" <<
55 " where i is the sample index. \n\n";
69 (
"initial-POSCAR", po::value<Index>(&
m_condition_index),
"Given the condition index, print a POSCAR for the initial state of a monte carlo run.")
70 (
"final-POSCAR", po::value<Index>(&
m_condition_index),
"Given the condition index, print a POSCAR for the final state of a monte carlo run.")
71 (
"traj-POSCAR", po::value<Index>(&
m_condition_index),
"Given the condition index, print POSCARs for the state at every sample of monte carlo run. Requires an existing trajectory file.");
81 template<
typename MCType>
84 template<
typename MCType>
87 template<
typename MCType>
90 template<
typename MCType>
109 std::string verbosity_str;
113 po::variables_map &vm = monte_opt.
vm();
116 po::store(po::parse_command_line(args.
argc, args.
argv, monte_opt.
desc()), vm);
120 if(vm.count(
"help")) {
125 if(vm.count(
"desc")) {
136 if(vm.count(
"verbosity")) {
140 args.
err_log <<
"Expected: 'none', 'quiet', 'standard', 'verbose', "
141 "'debug', or an integer 0-100 (0: none, 100: all)" <<
"\n" << std::endl;
148 catch(po::error &e) {
149 args.
err_log <<
"ERROR: " << e.what() << std::endl << std::endl;
153 catch(std::exception &e) {
154 args.
err_log <<
"Unhandled Exception reached the top of main: "
155 << e.what() <<
", application will now exit" << std::endl;
169 std::unique_ptr<PrimClex> uniq_primclex;
175 settings_path = fs::absolute(settings_path);
185 log.
read(
"Monte Carlo settings");
186 log <<
"from: " << settings_path <<
"\n";
188 log <<
"ensemble: " << monte_settings.
ensemble() <<
"\n";
189 log <<
"method: " << monte_settings.
method() <<
"\n";
193 if(monte_settings.
debug()) {
194 log <<
"debug: " << monte_settings.
debug() <<
"\n";
199 catch(std::exception &e) {
200 args.
err_log <<
"ERROR reading Monte Carlo settings.\n\n";
201 args.
err_log << e.what() << std::endl;
216 template<
typename MCType>
219 typename MCType::SettingsType mc_settings(primclex, monte_opt.
settings_path());
220 const MCType mc(primclex, mc_settings, args.
log);
224 args.
log << std::endl;
227 catch(std::exception &e) {
229 " Monte Carlo initial snapshot for condition: " << monte_opt.
condition_index() <<
"\n\n";
230 args.
err_log << e.what() << std::endl;
235 template<
typename MCType>
238 typename MCType::SettingsType mc_settings(primclex, monte_opt.
settings_path());
239 const MCType mc(primclex, mc_settings, args.
log);
243 args.
log << std::endl;
246 catch(std::exception &e) {
248 " Monte Carlo initial snapshot for condition: " << monte_opt.
condition_index() <<
"\n\n";
249 args.
err_log << e.what() << std::endl;
254 template<
typename MCType>
257 typename MCType::SettingsType mc_settings(primclex, monte_opt.
settings_path());
258 const MCType mc(primclex, mc_settings, args.
log);
260 args.
log.
write(
"Trajectory POSCAR");
262 args.
log << std::endl;
265 catch(std::exception &e) {
267 " Monte Carlo path snapshots for condition: " << monte_opt.
condition_index() <<
"\n\n";
268 args.
err_log << e.what() << std::endl;
273 template<
typename MCType>
276 typename MCType::SettingsType mc_settings(primclex, monte_opt.
settings_path());
281 catch(std::exception &e) {
282 args.
err_log <<
"ERROR running " <<
to_string(MCType::ensemble) <<
" Monte Carlo.\n\n";
283 args.
err_log << e.what() << std::endl;
295 const po::variables_map &vm = monte_opt.
vm();
297 if(vm.count(
"initial-POSCAR")) {
298 return _initial_POSCAR<MCType>(
primclex, args, monte_opt);
300 else if(vm.count(
"final-POSCAR")) {
301 return _final_POSCAR<MCType>(
primclex, args, monte_opt);
303 else if(vm.count(
"traj-POSCAR")) {
304 return _traj_POSCAR<MCType>(
primclex, args, monte_opt);
312 if(gc_settings.dependent_runs()) {
313 throw std::invalid_argument(
"ERROR in LTE1 calculation: dependents_runs must be false");
317 if(gc_settings.is_motif_configname() &&
318 (gc_settings.motif_configname() ==
"auto" ||
319 gc_settings.motif_configname() ==
"restricted_auto")) {
324 throw std::invalid_argument(
"ERROR in LTE1 calculation: must use one of\n"
325 " \"driver\"/\"motif\"/\"configname\": \"auto\"\n"
326 " \"driver\"/\"motif\"/\"configname\": \"restricted_auto\"");
330 if(gc_settings.write_csv()) {
331 if(fs::exists(
dir.results_csv())) {
332 args.
err_log <<
"Existing file at: " <<
dir.results_csv() << std::endl;
333 args.
err_log <<
" Exiting..." << std::endl;
337 if(gc_settings.write_json()) {
338 if(fs::exists(
dir.results_json())) {
339 args.
err_log <<
"Existing file at: " <<
dir.results_json() << std::endl;
340 args.
err_log <<
" Exiting..." << std::endl;
349 args.
log <<
"Phi_LTE(1) = potential_energy_gs - kT*ln(Z'(1))/N" << std::endl;
350 args.
log <<
"Z'(1) = sum_i(exp(-dPE_i/kT), summing over ground state and single spin flips" << std::endl;
351 args.
log <<
"dPE_i: (potential_energy_i - potential_energy_gs)*N" <<
"\n\n" << std::endl;
353 auto init = gc_settings.initial_conditions();
355 int num_conditions = 1;
359 incr = gc_settings.incremental_conditions();
360 auto final = gc_settings.final_conditions();
361 num_conditions = (
final - init) / incr + 1;
367 for(
int index = 0; index < num_conditions; ++index) {
369 configname = gc.
set_state(cond, gc_settings).second;
373 args.
log <<
"formation_energy: " << std::setprecision(12) << gc.
formation_energy() << std::endl;
375 args.
log <<
" comp_n: " << gc.
comp_n().transpose() << std::endl;
377 args.
log <<
" comp_x: " << comp_converter.param_composition(gc.
comp_n()).transpose() << std::endl;
378 args.
log <<
"potential energy: " << std::setprecision(12) << gc.
potential_energy() << std::endl << std::endl;
385 args.
log << std::endl;
388 args.
log << std::endl;
394 catch(std::exception &e) {
395 args.
err_log <<
"ERROR calculating single spin flip LTE grand canonical potential.\n\n";
396 args.
err_log << e.what() << std::endl;
401 return _driver<GrandCanonical>(
primclex, args, monte_opt);
416 const po::variables_map &vm = monte_opt.
vm();
418 if(vm.count(
"initial-POSCAR")) {
419 return _initial_POSCAR<MCType>(
primclex, args, monte_opt);
421 else if(vm.count(
"final-POSCAR")) {
422 return _final_POSCAR<MCType>(
primclex, args, monte_opt);
424 else if(vm.count(
"traj-POSCAR")) {
425 return _traj_POSCAR<MCType>(
primclex, args, monte_opt);
428 return _driver<MCType>(
primclex, args, monte_opt);
Data structure holding basic CASM command info.
void add_verbosity_suboption()
Add a –verbosity suboption. Default "standard" of "none", "quiet", "standard", "verbose", "debug" or an int 0-100.
Eigen::VectorXd param_chem_pot() const
parametric chemical potential: dg/dcomp_x
void write_POSCAR_trajectory(const MonteCarlo &mc, Index cond_index, Log &_log)
For every snapshot taken, write a POSCAR file.
int _run_GrandCanonical(PrimClex &primclex, const MonteSettings &monte_settings, const CommandArgs &args, const Completer::MonteOption &monte_opt)
void write_lte_results(const MonteSettings &settings, const GrandCanonical &mc, const double &phi_LTE1, const std::string &configname, Log &_log)
Will create new file or append to existing results file the results of the latest run...
void write(const std::string &what)
const fs::path settings_path() const
Returns the path corresponding to add_settings_suboption.
void add_help_suboption()
Add a plain –help suboption.
void add_settings_suboption(bool required=true)
Add a –settings suboption. Expects a corresponding casm format to go with it.
const Eigen::VectorXd & comp_n() const
Number of atoms of each type, normalized per primitive cell.
std::string to_string(ENUM val)
Return string representation of enum class.
const std::string & verbosity_str() const
Returns the string corresponding to add_verbosity_suboption()
void read(const std::string &what)
bool debug() const
return true if running in debug mode
static std::pair< bool, int > verbosity_level(std::string s)
Read verbosity level from a string.
void print_monte_help(std::ostream &sout, const po::options_description &desc)
std::vector< std::string > components() const
The order of components in mol composition vectors.
void custom(const std::string &what)
int _traj_POSCAR(PrimClex &primclex, const CommandArgs &args, const Completer::MonteOption &monte_opt)
double lte_grand_canonical_free_energy() const
Calculate the single spin flip low temperature expansion of the grand canonical potential.
const po::options_description & desc()
Get the program options, filled with the initialized values.
const double & potential_energy() const
Potential energy, normalized per primitive cell.
void write_POSCAR_initial(const MonteCarlo &mc, Index cond_index, Log &_log)
For the initial state, write a POSCAR file.
EigenIndex Index
For long integer indexing:
Index condition_index() const
int _initial_POSCAR(PrimClex &primclex, const CommandArgs &args, const Completer::MonteOption &monte_opt)
const PrimClex & primclex() const
const Access the PrimClex that *this is based on
po::options_description m_desc
Boost program options. All the derived classes have them, but will fill them up themselves.
PrimClex is the top-level data structure for a CASM project.
int monte_command(const CommandArgs &args)
void set_debug(bool _debug)
Set debug mode.
const CompositionConverter & composition_axes() const
const Access CompositionConverter object
ConfigIO::GenericConfigFormatter< std::string > configname()
Constructs DataFormmaterDictionary containing all Configuration DatumFormatters.
po::variables_map & vm()
Get the variables map.
std::pair< ConfigDoF, std::string > set_state(const GrandCanonicalConditions &new_conditions, const GrandCanonicalSettings &settings)
Set configdof and conditions and clear previously collected data.
PrimClex & make_primclex_if_not(const CommandArgs &args, std::unique_ptr< PrimClex > &uniq_primclex)
If !_primclex, construct new PrimClex stored in uniq_primclex, then return reference to existing or c...
virtual const Monte::DRIVE_MODE drive_mode() const
Given a settings jsonParser figure out the drive mode. Expects drive_mode/incremental,custom.
bool debug() const
Run in debug mode?
const double & formation_energy() const
Formation energy, normalized per primitive cell.
void write_POSCAR_final(const MonteCarlo &mc, Index cond_index, Log &_log)
For the final state, write a POSCAR file.
void set_verbosity(int _verbosity)
Monte::ENSEMBLE ensemble() const
Return type of Monte Carlo ensemble.
const CondType & conditions() const
Return current conditions.
static const Monte::ENSEMBLE ensemble
void print_monte_desc(std::ostream &sout, const po::options_description &desc)
Monte::METHOD method() const
Return type of Monte Carlo method.
void initialize() override
Fill in the options descriptions accordingly.
void error(const std::string &what)
int _run_Canonical(PrimClex &primclex, const MonteSettings &monte_settings, const CommandArgs &args, const Completer::MonteOption &monte_opt)
Settings for Monte Carlo calculations.
int _final_POSCAR(PrimClex &primclex, const CommandArgs &args, const Completer::MonteOption &monte_opt)
#define ERR_EXISTING_FILE
int _driver(PrimClex &primclex, const CommandArgs &args, const Completer::MonteOption &monte_opt)
static const Monte::ENSEMBLE ensemble
#define ERR_INVALID_INPUT_FILE