14 json[
"chemical_reference"][
"global"] = json_ref;
18 primclex.
log() <<
"Initializing the chemical reference to: \n\n";
32 if(input.second.empty()) {
36 chem_ref.
set_global(input.second.begin(), input.second.end(), lin_alg_tol);
39 primclex.
log() <<
"Updating the project-wide chemical reference to: \n";
52 if(!fs::exists(chem_ref_path)) {
53 primclex.
err_log() <<
"Error using 'casm ref --set --configname': No reference found.\n";
54 primclex.
err_log() <<
" Expected file at: " << chem_ref_path <<
"\n";
55 primclex.
err_log() <<
"Use 'casm ref --set' or 'casm ref --set-auto' to set a project-wide reference first.\n";
66 primclex.
err_log() <<
"Error using 'casm ref --set --configname': \n"
67 " Could not find configuration with name: " << configname <<
"\n";
72 if(input.second.empty()) {
76 chem_ref.
set_config(configname, input.second.begin(), input.second.end(), lin_alg_tol);
79 primclex.
log() <<
"Updating the " << configname <<
" specialized reference to: \n";
93 if(!fs::exists(chem_ref_path)) {
94 primclex.
err_log() <<
"Error using 'casm ref --set --scelname': No reference found.\n";
95 primclex.
err_log() <<
" Expected file at: " << chem_ref_path <<
"\n";
96 primclex.
err_log() <<
"Use 'casm ref --set' or 'casm ref --set-auto' to set a project-wide reference first.\n";
107 primclex.
err_log() <<
"Error using 'casm ref --set --scelname': \n"
108 " Could not find supercell with name: " << scelname <<
"\n";
113 if(input.second.empty()) {
117 chem_ref.
set_supercell(scelname, input.second.begin(), input.second.end(), lin_alg_tol);
120 primclex.
log() <<
"Updating the " << scelname <<
" specialized reference to: \n";
130 namespace Completer {
144 (
"display,d",
"Display current reference states")
145 (
"set-auto",
"Automatically set project level reference states using DFT results")
146 (
"set", po::value<std::string>(&
m_set_str),
147 "Set reference states using user specified compositions and energies "
148 "(Default: set project-wide references). \n"
149 "See examples below for the form of expected input.")
150 (
"erase",
"Erase reference states (Default: clear project-wide references).")
151 (
"clex", po::value<std::string>(),
"Name of the cluster expansion using the reference");
163 po::variables_map vm;
165 std::string species_order_string =
"\n\n";
169 std::stringstream ss;
173 ss <<
" For this project, the expected order is:\n"
176 for(
int i = 0; i < names.size(); i++) {
178 if(i != names.size() - 1) {
184 species_order_string = ss.str();
191 po::store(po::parse_command_line(args.
argc, args.
argv, ref_opt.
desc()), vm);
193 bool call_help =
false;
196 if(!vm.count(
"help") && !vm.count(
"desc")) {
197 if(vm.count(
"set") + vm.count(
"display") + vm.count(
"erase") + vm.count(
"set-auto") != 1) {
198 args.
log <<
"Error in 'casm ref'. Please select one of --display, \n";
199 args.
log <<
"--set, --set-auto, or --erase to use this option." << std::endl;
204 if(vm.count(
"set")) {
205 if(vm.count(
"scelname") + vm.count(
"configname") > 1) {
206 args.
err_log <<
"Error in 'casm ref --set'. Please select only one of --scelname, --configname \n";
212 if(vm.count(
"erase")) {
213 if(vm.count(
"scelname") + vm.count(
"configname") > 1) {
214 args.
err_log <<
"Error in 'casm ref --erase'. Please select only one of --scelname, --configname \n";
223 if(vm.count(
"help") || call_help) {
224 args.
log << std::endl;
225 args.
log << ref_opt.
desc() << std::endl;
230 if(vm.count(
"desc")) {
232 args.
log << ref_opt.
desc() << std::endl;
234 args.
log <<
"DESCRIPTION" << std::endl;
235 args.
log <<
" The chemical reference determines the value of the formation energy \n"
236 " and chemical potentials calculated by CASM. \n\n"
238 " Chemical references states are set by specifying a hyperplane in \n"
239 " energy/atom - composition (as atom_frac) space. This may be done by \n"
240 " specifying the hyperplane explicitly, or by specifying several \n"
241 " reference states with energy/atom and composition (as atom_frac) for \n"
242 " enough states to span the composition space of the allowed occupants \n"
243 " specified in the prim. For consistency with other CASM projects, \n"
244 " additional reference states extending to other compositional \n"
245 " dimensions may be included also. The pure Va reference is always 0. \n\n";
247 args.
log <<
" The input to '--set' can be one of three forms: \n\n"
249 " 1) Input the energy_per_species for pure states: \n" <<
250 R
"( '{"A": X, "B": X, "C": X}')" << "\n\n" <<
252 " 2) Input reference state composition and energy_per_species: \n" <<
254 R
"( {"A": 3.4, "C": 2.0, "energy_per_species": 2.0},)" << "\n" <<
255 R
"( {"B": 2.0, "energy_per_species": 4.0}, )" << "\n" <<
256 R
"( {"C": 1.0, "energy_per_species": 3.0} )" << "\n" <<
257 R
"( ]')" << "\n\n" <<
259 " 3) Input an array of energy_per_species, for each species in prim, \n"
260 " including 0.0 for vacancy: \n"
262 << species_order_string;
264 args.
log <<
" When using '--set' it is also possible to specialize the chemical \n"
265 " reference at the supercell or configuration level by adding the \n"
266 " --scelname or --configname option. \n\n";
270 args.
log <<
" Examples:\n";
275 args.
log <<
" casm ref --display \n";
276 args.
log <<
" - Print chemical reference\n";
278 args.
log <<
" casm ref --set-auto\n";
279 args.
log <<
" - set all reference states using DFT results for configurations with\n";
280 args.
log <<
" extreme compositions.\n";
281 args.
log <<
" - set reference for compositions outside range of this project to 0.0\n";
283 args.
log <<
" casm ref --set \n"
284 " '[{\"Zr\":1, \"energy_per_species\":-8.546979385}, \n"
285 " {\"Zr\":1, \"O\":1, \"energy_per_species\":-9.090697345}]'\n"
286 " - set Zr and ZrO, with given energy per species, as reference states\n\n";
288 args.
log <<
" casm ref --scelname SCEL3_3_1_1_0_2_2 --set \n"
289 " '[{\"Zr\":1, \"energy_per_species\":-8.546979385}, \n"
290 " {\"Zr\":1, \"O\":1, \"energy_per_species\":-9.090697345}]'\n"
291 " - set reference states as specified for configurations in supercell SCEL3_3_1_1_0_2_2\n\n";
293 args.
log <<
" casm ref --configname SCEL3_3_1_1_0_2_2/2 --set \n"
294 " '[{\"Zr\":1, \"energy_per_species\":-8.546979385}, \n"
295 " {\"Zr\":1, \"O\":1, \"energy_per_species\":-9.090697345}]'\n"
296 " - set reference states as specified for configuration SCEL3_3_1_1_0_2_2/2\n\n";
298 args.
log <<
" casm ref --scelname SCEL3_3_1_1_0_2_2 --erase \n"
299 " - erase specialized reference states for configurations in supercell SCEL3_3_1_1_0_2_2\n\n";
301 args.
log <<
" casm ref --configname SCEL3_3_1_1_0_2_2/2 --erase \n"
302 " - erase specialized reference states for configuration SCEL3_3_1_1_0_2_2/2\n\n";
317 catch(po::error &e) {
318 args.
err_log <<
"ERROR: " << e.what() << std::endl << std::endl;
322 catch(std::exception &e) {
323 args.
err_log <<
"Unhandled Exception reached the top of main: "
324 << e.what() <<
", application will now exit" << std::endl;
338 std::unique_ptr<PrimClex> uniq_primclex;
344 if(!vm.count(
"clex")) {
351 args.
err_log << vm[
"clex"].as<std::string>() <<
" not found.";
354 clex_desc = it->second;
358 std::string
ref = clex_desc.
ref;
362 if(vm.count(
"display")) {
364 args.
err_log <<
"Error using 'casm ref --display': No reference found.\n";
365 args.
err_log <<
" Expected file at: " << chem_ref_path <<
"\n";
366 args.
err_log <<
"Use 'casm ref --set' or 'casm ref --set-auto' to set a reference\n";
375 else if(vm.count(
"set-auto")) {
377 args.
log <<
" Set reference states automatically.\n\n" << std::endl;
384 catch(std::exception &e) {
385 args.
err_log <<
"Error setting reference states automatically.\n\n";
386 args.
err_log << e.what() << std::endl;
390 else if(vm.count(
"set")) {
392 using namespace ref_impl;
398 catch(std::exception &e) {
399 args.
err_log <<
"Error parsing JSON input for 'casm ref --set ' with: \n"
400 << set_str << std::endl;
401 args.
err_log << e.what() << std::endl;
407 if(!(vm.count(
"scelname") + vm.count(
"configname"))) {
409 if(!fs::exists(chem_ref_path)) {
415 result_code =
update_global(chem_ref_path, primclex, json_ref, lin_alg_tol);
421 else if(vm.count(
"configname")) {
423 result_code =
update_config(configname, chem_ref_path, primclex, json_ref, lin_alg_tol);
430 result_code =
update_supercell(scelname, chem_ref_path, primclex, json_ref, lin_alg_tol);
435 else if(vm.count(
"erase")) {
439 if(!(vm.count(
"scelname") + vm.count(
"configname"))) {
441 if(!fs::exists(chem_ref_path)) {
442 args.
err_log <<
"No chemical reference found. \n";
446 fs::remove(chem_ref_path);
447 args.
log <<
"Erased chemical reference" << std::endl;
455 if(vm.count(
"configname")) {
457 args.
err_log <<
"No " << configname <<
" specialized reference found. \n";
461 args.
log <<
"Erased specialized reference for " << configname << std::endl;
470 args.
err_log <<
"No " << scelname <<
" specialized reference found. \n";
474 args.
log <<
"Erased specialized reference for " << scelname << std::endl;
Data structure holding basic CASM command info.
int update_global(fs::path chem_ref_path, const PrimClex &primclex, const jsonParser &json_ref, double lin_alg_tol)
Specifies a particular cluster expansion.
ChemicalReference auto_chemical_reference(const PrimClex &primclex, double lin_alg_tol)
Automatically set ChemicalReference using calculated Configurations with 'extreme' compositions...
Specification of CASM project directory structure.
const DirectoryStructure & dir() const
void initialize() override
Fill in the options descriptions accordingly.
Structure specifies the lattice and atomic basis of a crystal.
const std::string & config_str() const
Returns the name of the supercell for add_configname_suboption(), for when multiple=false.
void add_help_suboption()
Add a plain –help suboption.
void add_configname_suboption()
Add a –configname suboption.
void refresh(bool read_settings=false, bool read_composition=false, bool read_chem_ref=false, bool read_configs=false, bool clear_clex=false)
Reload PrimClex data from settings.
void write_chemical_reference(const ChemicalReference &chem_ref, fs::path filename)
int update_supercell(std::string scelname, fs::path chem_ref_path, const PrimClex &primclex, const jsonParser &json_ref, double lin_alg_tol)
fs::path prim() const
Return prim.json path.
Represents a supercell of the primitive parent crystal structure.
BasicStructure< Site > read_prim(fs::path filename)
std::vector< std::string > get_struc_molecule_name() const
Returns an Array of each possible Molecule in this Structure.
bool has_chemical_reference() const
check if ChemicalReference object initialized
int update_config(std::string configname, fs::path chem_ref_path, const PrimClex &primclex, const jsonParser &json_ref, double lin_alg_tol)
void set_supercell(const std::string &scelname, const Eigen::VectorXd &ref)
Set hyperplane reference specialized for a Supercell.
size_type erase_config(const std::string &configname)
Erase hyperplane reference specialized for a Configuration.
const po::options_description & desc()
Get the program options, filled with the initialized values.
Read/modify settings of an already existing CASM project.
void set_config(const std::string &configname, const Eigen::VectorXd &ref)
Set hyperplane reference specialized for a Configuration.
std::pair< Eigen::VectorXd, std::vector< ChemicalReferenceState > > one_chemical_reference_from_json(const Structure &prim, const jsonParser &json)
Read chemical reference from one of 3 alternative forms.
po::options_description m_desc
Boost program options. All the derived classes have them, but will fill them up themselves.
ProjectSettings & settings()
PrimClex is the top-level data structure for a CASM project.
const std::string & supercell_str() const
Returns the name of the supercell for add_scelname_suboption()
int ref_command(const CommandArgs &args)
ChemicalReference read_chemical_reference(fs::path filename, const Structure &prim, double tol)
Read chemical reference states from JSON file.
size_type erase_supercell(const std::string &scelname)
Erase hyperplane reference specialized for a Supercell.
const ChemicalReference & chemical_reference() const
const Access ChemicalReference object
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") ...
Structure to help print ChemicalReference.
const std::map< std::string, ClexDescription > & cluster_expansions() const
ConfigIO::GenericConfigFormatter< std::string > configname()
Constructs DataFormmaterDictionary containing all Configuration DatumFormatters.
void add_scelname_suboption()
Add a –scelname suboption.
void set_global(const Eigen::VectorXd &ref)
Set global hyperplane reference.
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...
static jsonParser parse(const std::string &str)
Construct a jsonParser from a string containing JSON data.
const Supercell & get_supercell(Index i) const
const Access supercell by index
int initialize_global(fs::path chem_ref_path, const PrimClex &primclex, const jsonParser &json_ref, double lin_alg_tol)
void error(const std::string &what)
ConfigIO::GenericConfigFormatter< std::string > scelname()
static jsonParser object()
Returns an empty json object.
#define ERR_MISSING_INPUT_FILE
const ClexDescription & default_clex() const
fs::path chemical_reference(std::string calctype, std::string ref) const
Return chemical reference file path.
const std::string & set_str() const
A Configuration represents the values of all degrees of freedom in a Supercell.
const Structure & get_prim() const
const Access to primitive Structure
double lin_alg_tol() const
Get current project linear algebra tolerance.