CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
settings.cc
Go to the documentation of this file.
4 #include "casm/clex/PrimClex.hh"
5 
7 
8 #include <functional>
9 
10 namespace CASM {
11 
12  struct ClexDescription;
13  bool clex_exists(const DirectoryStructure &dir, const ClexDescription &desc);
14 
15  namespace {
16  std::string _wdefaultval(std::string name, std::pair<std::string, std::string> val) {
17  return name + ": '" + val.first + "' (" + val.second + ")\n";
18  }
19 
20  std::string _wdefaultval(std::string name, std::pair<fs::path, std::string> val) {
21  return _wdefaultval(name, std::make_pair(val.first.string(), val.second));
22  }
23  }
24 
25  namespace Completer {
27 
28  const std::string &SettingsOption::input_str() const {
29  return m_input_str;
30  }
31 
32  const std::vector<std::string> &SettingsOption::input_vec() const {
33  return m_input_vec;
34  }
35 
38 
39  m_desc.add_options()
40  ("list,l", "List project settings")
41  ("new-property", po::value<std::string>(&m_input_str), "Create cluster expansions for a new property")
42  ("new-bset", po::value<std::string>(&m_input_str), "Create a new basis set")
43  ("new-calctype", po::value<std::string>(&m_input_str), "Create a new calculation type")
44  ("new-ref", po::value<std::string>(&m_input_str), "Create a new calculation reference")
45  ("new-eci", po::value<std::string>(&m_input_str), "Create a new set of effective cluster interactions (ECI)")
46  ("set-formation-energy", po::value<std::string>(&m_input_str), "Specify the cluster expansion to use for formation energy")
47  ("new-clex", po::value<std::string>(&m_input_str), "Create a new cluster expansion")
48  ("set-default-clex", po::value<std::string>(&m_input_str), "Set the cluster expansion that CASM uses or acts on by default")
49  ("erase-clex", po::value<std::string>(&m_input_str), "Erase the specified cluster expansion. Does not erase underlying bset, eci, etc.")
50  ("clex", po::value<std::string>(), "The cluster expansion for which to set property, bset, calctype, ref, or eci")
51  ("set-property", po::value<std::string>(&m_input_str), "Set the current basis set")
52  ("set-bset", po::value<std::string>(&m_input_str), "Set the basis set")
53  ("set-calctype", po::value<std::string>(&m_input_str), "Set the calculation type")
54  ("set-ref", po::value<std::string>(&m_input_str), "Set the calculation reference")
55  ("set-eci", po::value<std::string>(&m_input_str), "Set the effective cluster interactions (ECI)")
56  ("set-all", po::value<std::vector<std::string> >(&m_input_vec)->multitoken(), "Set the current property, calctype, ref, bset, and eci all at once.")
57  ("set-view-command", po::value<std::string>(&m_input_str), "Set the command used by 'casm view'.")
58  ("set-cxx", po::value<std::string>(&m_input_str), "Set the c++ compiler. Use '' to revert to default.")
59  ("set-cxxflags", po::value<std::string>(&m_input_str), "Set the c++ compiler options. Use '' to revert to default.")
60  ("set-soflags", po::value<std::string>(&m_input_str), "Set the shared library compilation options. Use '' to revert to default.")
61  ("set-casm-prefix", po::value<std::string>(&m_input_str), "Set the casm prefix. Use '' to revert to default.")
62  ("set-casm-includedir", po::value<std::string>(&m_input_str), "Set the casm includedir. Use '' to revert to default.")
63  ("set-casm-libdir", po::value<std::string>(&m_input_str), "Set the casm libdir. Use '' to revert to default.")
64  ("set-boost-prefix", po::value<std::string>(&m_input_str), "Set the boost prefix. Use '' to revert to default.")
65  ("set-boost-includedir", po::value<std::string>(&m_input_str), "Set the boost includedir. Use '' to revert to default.")
66  ("set-boost-libdir", po::value<std::string>(&m_input_str), "Set the boost libdir. Use '' to revert to default.");
67  return;
68  }
69 
70  }
71 
72  namespace {
73 
76  enum create_mode {create, do_not_create};
77 
79  struct Data {
80 
81  typedef std::pair<std::string, create_mode> pair_type;
82 
83  Data(PrimClex *_primclex,
84  DirectoryStructure &_dir,
85  ProjectSettings &_set,
86  ClexDescription &_desc,
87  Log &_log,
88  Log &_err_log) :
89  primclex(_primclex),
90  dir(_dir),
91  set(_set),
92  desc(_desc),
93  log(_log),
94  err_log(_err_log),
95  property(pair_type(desc.property, do_not_create)),
96  calctype(pair_type(desc.calctype, do_not_create)),
97  ref(pair_type(desc.ref, do_not_create)),
98  bset(pair_type(desc.bset, do_not_create)),
99  eci(pair_type(desc.eci, do_not_create)) {}
100 
101  PrimClex *primclex;
102  DirectoryStructure &dir;
103  ProjectSettings &set;
104  ClexDescription &desc;
105  Log &log;
106  Log &err_log;
107 
108  pair_type property;
109  pair_type calctype;
110  pair_type ref;
111  pair_type bset;
112  pair_type eci;
113 
114  int update() {
115 
116  // the resulting clex if successful
117  ClexDescription tdesc(desc.name, property.first, calctype.first, ref.first, bset.first, eci.first);
118 
119  bool res = try_new("property", property,
120  [&]() {
121  return contains(dir.all_property(), tdesc.property);
122  },
123  [&]() {
124  return set.new_clex_dir(tdesc.property);
125  }) &&
126  try_new("calctype", calctype,
127  [&]() {
128  return contains(dir.all_calctype(), tdesc.calctype);
129  },
130  [&]() {
131  return set.new_calc_settings_dir(tdesc.calctype);
132  }) &&
133  try_new("ref", ref,
134  [&]() {
135  return contains(dir.all_ref(tdesc.calctype), tdesc.ref);
136  },
137  [&]() {
138  return set.new_ref_dir(tdesc.calctype, tdesc.ref);
139  }) &&
140  try_new("bset", bset,
141  [&]() {
142  return contains(dir.all_bset(), tdesc.bset);
143  },
144  [&]() {
145  return set.new_bset_dir(tdesc.bset);
146  }) &&
147  try_new("eci", eci,
148  [&]() {
149  return contains(dir.all_eci(tdesc.property, tdesc.calctype, tdesc.ref, tdesc.bset), tdesc.eci);
150  },
151  [&]() {
152  return set.new_eci_dir(tdesc.property, tdesc.calctype, tdesc.ref, tdesc.bset, tdesc.eci);
153  });
154 
155  // If could not create settings directories
156  if(!res) {
157  return 1;
158  }
159 
160  if(clex_exists(dir, tdesc) && set.set_default_clex(tdesc)) {
161  set.commit();
162 
163  bool read_settings = true;
164  bool read_composition = false;
165 
166  bool read_chem_ref = false;
167  bool read_configs = false;
168  if((desc.property != tdesc.property) ||
169  (desc.calctype != tdesc.calctype) ||
170  (desc.ref != tdesc.ref)) {
171  read_chem_ref = true;
172  read_configs = true;
173  }
174 
175  bool clear_clex = false;
176  if((desc.property != tdesc.property) ||
177  (desc.bset != tdesc.bset) ||
178  (desc.eci != tdesc.eci)) {
179  clear_clex = true;
180  }
181 
182  desc = tdesc;
183  log << "Updated default settings:\n";
184  bool is_default = true;
185  int indent = 0;
186  desc.print(log, is_default, indent);
187 
188  if(primclex) {
189  primclex->refresh(read_settings, read_composition, read_chem_ref, read_configs, clear_clex);
190  }
191  return 0;
192  }
193  else {
194  err_log << "Unknown error: Could not switch settings." << std::endl;
195  err_log << "Tried to switch to:\n";
196  tdesc.print(err_log, false, 0);
197  return 1;
198  }
199  }
200 
216  bool try_new(std::string set_name, pair_type set, std::function<bool ()> check_f, std::function<bool ()> new_f) {
217 
218  create_mode _cmode = set.second;
219 
220  if(_cmode == create && check_f()) {
221  return true;
222  }
223  if(_cmode == create && !check_f()) {
224  bool res = new_f();
225  if(res) {
226  log << "Created new " << set_name << ": '" << set.first << "'\n";
227 
228  }
229  else {
230  err_log << "Could not create new " << set_name << ": '" << set.first << "'\n";
231  }
232  return res;
233  }
234 
235  if(_cmode == do_not_create && !check_f()) {
236  err_log << "Error: The " << set_name << " named '" << set.first << "' does not exist.\n";
237  err_log << " Check your input or use --new-" << set_name << " to create it first.\n";
238 
239  return false;
240  }
241 
242  if(_cmode == do_not_create && check_f()) {
243  return true;
244  }
245 
246  // shouldn't be able to get here
247  throw std::runtime_error("Unknown error updating CASM settings");
248  }
249  };
250  }
251 
252 
253  // ///////////////////////////////////////
254  // 'settings' function for casm
255  // (add an 'if-else' statement in casm.cpp to call this)
256 
257  int settings_command(const CommandArgs &args) {
258 
259 
260  std::string single_input;
261  std::vector<std::string> multi_input;
262  po::variables_map vm;
263 
264 
265  try {
267  Completer::SettingsOption settings_opt;
268  const po::options_description &desc = settings_opt.desc(); //I'm tired of fixing merge conflicts, this is ugly and should not stay like this.
269 
270  try {
271  po::store(po::parse_command_line(args.argc, args.argv, desc), vm); // can throw
272 
273  bool call_help = false;
274 
275  std::vector<std::string> all_opt = {"list", "desc",
276  "new-property", "new-bset", "new-calctype", "new-ref", "new-eci",
277  "new-clex", "set-formation-energy", "erase-clex",
278  "set-default-clex", "set-property", "set-bset", "set-calctype", "set-ref", "set-eci", "set-all",
279  "set-cxx", "set-cxxflags", "set-soflags",
280  "set-casm-prefix", "set-casm-includedir", "set-casm-libdir",
281  "set-boost-prefix", "set-boost-includedir", "set-boost-libdir",
282  "set-view-command"
283  };
284  int option_count = 0;
285  for(int i = 0; i < all_opt.size(); i++) {
286  option_count += vm.count(all_opt[i]);
287  }
288 
289  // must call one and only one option at a time:
290  if(!vm.count("help")) {
291  if(option_count == 0) {
292  args.log << "Error in 'casm settings'. No option selected." << std::endl;
293  call_help = true;
294  }
295  else if(option_count > 1) {
296  args.log << "Error in 'casm settings'. Use one option (other than --clex) at a time." << std::endl;
297  call_help = true;
298  }
299  }
300 
301  // --help option
302  if(vm.count("help") || call_help) {
303  args.log << "\n";
304  args.log << desc << std::endl;
305 
306  return 0;
307  }
308 
309  if(vm.count("desc")) {
310  args.log << "\n";
311  args.log << desc << std::endl;
312  args.log << "DESCRIPTION" << std::endl;
313  args.log << "\n";
314  args.log << " Often it is useful to try multiple different basis sets, \n" <<
315  " calculation settings, references, or ECI fits in a single\n" <<
316  " project. The 'casm settings' option helps to organize \n" <<
317  " these within a project and quickly switch between \n" <<
318  " different settings. \n";
319  args.log << "\n";
320  args.log << " Examples:\n";
321  args.log << " \n" <<
322  " casm settings --list \n" <<
323  " - List all settings, with '*' for current settings \n\n" <<
324 
325  " casm settings --new-clex 'my_newclex' \n" <<
326  " casm settings --set-default-clex 'other_clex' \n" <<
327  " - Creates a new group of settings for a cluster \n" <<
328  " expansion \n" <<
329  " - Includes property, calctype, ref, bset, and eci \n" <<
330  " - Can be used in Monte Carlo input files, and as \n" <<
331  " arguments to 'casm select' and 'casm query' \n" <<
332  " properties such as 'clex' and 'corr' to specify which\n" <<
333  " basis functions and eci to use. \n\n" <<
334 
335  " casm settings --set-formation-energy 'other_clex' \n" <<
336  " - The cluster expansion 'other_clex' is copied to one \n" <<
337  " named 'formation_energy' which is used as the default\n" <<
338  " for grand canoncial Monte Carlo calculations and \n" <<
339  " cluster expansion convex hull calculations. \n\n" <<
340 
341  " casm settings --new-property 'my_new_property' \n" <<
342  " casm settings --new-bset 'my_new_bset' \n" <<
343  " casm settings --new-calctype 'my_new_calctype' \n" <<
344  " casm settings --new-ref 'my_new_ref' \n" <<
345  " casm settings --new-eci 'my_new_eci' \n" <<
346  " - Creates new settings directories with appropriate \n" <<
347  " names \n" <<
348  " - For --new-property, new 'default' calctype, ref, and \n" <<
349  " eci are created. \n" <<
350  " - For --new-calctype, a new 'default' ref is created. \n" <<
351  " - For --new-ref, a new reference is created for the \n" <<
352  " current calctype \n" <<
353  " - For --new-eci, a new eci directory is created for the\n" <<
354  " current clex, calctype and ref. \n\n" <<
355 
356  " casm settings --set-property 'other_property' \n" <<
357  " casm settings --set-bset 'other_bset' \n" <<
358  " casm settings --set-calctype 'other_calctype' \n" <<
359  " casm settings --set-ref 'other_ref' \n" <<
360  " casm settings --set-eci 'other_eci' \n" <<
361  " casm settings --set-all 'property' 'calctype', 'ref', 'bset', 'eci'\n" <<
362  " - Switch the current settings \n" <<
363  " - For --set-property, standard options are: \n" <<
364  " - 'formation_energy' (the only standard option for now)\n" <<
365  " After switching, the 'default' calctype, ref, bset, \n" <<
366  " and eci are used"
367  " - For --set-calctype, the current property and bset are\n" <<
368  " maintained, and the 'default' ref, and eci are used. \n" <<
369  " - For --set-ref, the current property, calctype, and \n" <<
370  " bset are maintained, and the 'default' eci is used. \n" <<
371  " - For --set-bset, the current property, calctype, and \n" <<
372  " ref are maintained, and the 'default' eci is used. \n" <<
373  " - For --set-eci, the current property, calctype, ref, \n" <<
374  " and bset are maintained. \n" <<
375  " - For --set-all, all settings are switched at once. \n\n" <<
376 
377  " casm settings --set-cxx 'cxx' \n" <<
378  " - Specifies compiler to use. In order of priority: \n"
379  " 1) User specified by 'casm settings --set-cxx' \n"
380  " (use '' to clear) \n"
381  " 2) $CASM_CXX \n"
382  " 3) $CXX \n"
383  " 4) \"g++\" \n\n"
384 
385  " casm settings --set-cxxflags 'cxxflags' \n"
386  " - Specifies compiler options. In order of priority: \n"
387  " 1) User specified by 'casm settings --set-cxxflags' \n"
388  " (use '' to clear) \n"
389  " 2) $CASM_CXXFLAGS \n"
390  " 3) \"-O3 -Wall -fPIC --std=c++11\" \n\n"
391 
392  " casm settings --set-soflags 'soflags' \n"
393  " - Specifies shared object construction flags. In order \n"
394  " of priority: \n"
395  " 1) User specified by 'casm settings --set-soflags' \n"
396  " (use '' to clear) \n"
397  " 2) $CASM_SOFLAGS \n"
398  " 3) \"-shared -lboost_system\" \n\n"
399 
400  " casm settings --set-casm-prefix 'casm_prefix' \n"
401  " casm settings --set-casm-includedir 'casm_includedir' \n"
402  " casm settings --set-casm-libdir 'casm_libdir' \n"
403  " - Specifies location to find CASM header files and shared\n"
404  " libraries for runtime compilation and linking. \n"
405  " In order of priority: \n"
406  " 1) User specified by via 'casm settings' (use '' to clear) \n"
407  " 2) $CASM_INCLUDEDIR and $CASM_LIBDIR \n"
408  " 3) $CASM_PREFIX/include and $CASM_PREFIX/lib \n"
409  " 4) (default search paths) \n\n"
410 
411  " casm settings --set-boost-prefix 'boost_prefix' \n"
412  " casm settings --set-boost-includedir 'boost_includedir' \n"
413  " casm settings --set-boost-libdir 'boost_libdir' \n"
414  " - Specifies location to find boost header files and shared\n"
415  " libraries for runtime compilation and linking. \n"
416  " In order of priority: \n"
417  " 1) User specified by via 'casm settings' (use '' to clear) \n"
418  " 2) $CASM_BOOST_INCLUDEDIR and $CASM_BOOST_LIBDIR \n"
419  " 3) $CASM_BOOST_PREFIX/include and $CASM_BOOST_PREFIX/lib \n"
420  " 4) (default search paths) \n\n"
421 
422  " casm settings --set-view-command 'casm.view \"open -a /Applications/VESTA/VESTA.app\"'\n" <<
423  " - Sets the command used by 'casm view' to open \n" <<
424  " visualization software. \n" <<
425  " - Will be executed with '/path/to/POSCAR' as an \n" <<
426  " argument, the location of a POSCAR for a configuration\n" <<
427  " selected for visualization. \n" <<
428  "\n";
429 
430  if(call_help)
431  return 1;
432 
433  return 0;
434  }
435 
436  po::notify(vm); // throws on error, so do after help in case
437  // there are any problems
438 
439  single_input = settings_opt.input_str();
440  multi_input = settings_opt.input_vec();
441 
442  }
443  catch(po::error &e) {
444  args.err_log << "ERROR: " << e.what() << std::endl << std::endl;
445  args.err_log << desc << std::endl;
446  return 1;
447  }
448  }
449  catch(std::exception &e) {
450  args.err_log << "Unhandled Exception reached the top of main: "
451  << e.what() << ", application will now exit" << std::endl;
452  return 1;
453 
454  }
455 
456  const fs::path &root = args.root;
457  if(root.empty()) {
458  args.err_log.error("No casm project found");
459  args.err_log << "current_path: " << fs::current_path() << std::endl;
460  args.err_log << std::endl;
461  return ERR_NO_PROJ;
462  }
463 
464  DirectoryStructure dir(root);
465  ProjectSettings set(root);
466  ClexDescription clex_desc = set.default_clex();
467 
468  if(vm.count("clex")) {
469  auto it = set.cluster_expansions().find(vm["clex"].as<std::string>());
470  if(it == set.cluster_expansions().end()) {
471  args.err_log.error("Invalid --clex value");
472  args.err_log << vm["clex"].as<std::string>() << " not found. expected basis set specifications file at: " << dir.bspecs(clex_desc.bset) << "\n" << std::endl;
473  return ERR_INVALID_ARG;
474  }
475  clex_desc = it->second;
476  }
477 
478  Data d(args.primclex, dir, set, clex_desc, args.log, args.err_log);
479 
480  typedef Data::pair_type pair_type;
481 
482  // disply all settings
483  if(vm.count("list")) {
484  set.print_summary(args.log);
485  return 0;
486  }
487 
488  // create new cluster_expansions/clex.property directory and sub-directories
489  else if(vm.count("new-property")) {
490 
491  d.property = pair_type(single_input, create);
492  d.calctype = pair_type("default", create);
493  d.ref = pair_type("default", create);
494  d.bset = pair_type("default", create);
495  d.eci = pair_type("default", create);
496 
497  return d.update();
498  }
499 
500  // create new bset, and default eci for current calctype and ref
501  else if(vm.count("new-bset")) {
502 
503  d.bset = pair_type(single_input, create);
504  d.eci = pair_type("default", create);
505 
506  return d.update();
507  }
508 
509  // create new calctype, and ref (either as specified, or default)
510  else if(vm.count("new-calctype")) {
511 
512  d.calctype = pair_type(single_input, create);
513  d.ref = pair_type("default", create);
514  d.eci = pair_type("default", create);
515 
516  return d.update();
517  }
518 
519  // create new ref for current calctype
520  else if(vm.count("new-ref")) {
521 
522  d.ref = pair_type(single_input, create);
523  d.eci = pair_type("default", create);
524 
525  return d.update();
526  }
527 
528  // create new eci directory
529  else if(vm.count("new-eci")) {
530 
531  d.eci = pair_type(single_input, create);
532 
533  return d.update();
534  }
535 
536  // create new cluster expansion settings group
537  else if(vm.count("new-clex")) {
538  clex_desc.name = single_input;
539  if(set.new_clex(clex_desc)) {
540  args.log << "Created new cluster expansion named '" << single_input << "'\n\n";
541  }
542  else {
543  args.log << "Could not create new cluster expansion named '" << single_input << "'.\n\n";
544  return 1;
545  }
546 
547  if(clex_exists(dir, clex_desc) && set.set_default_clex(clex_desc)) {
548  set.commit();
549  if(args.primclex) {
550  args.primclex->refresh(true, false, true, true, true);
551  }
552  args.log << "Set '" << clex_desc.name << "' as default cluster expansion.\n\n";
553  return 0;
554  }
555  else {
556  args.log << "Could not set '" << clex_desc.name << "' as default cluster expansion.\n\n";
557  return 1;
558  }
559  }
560 
561  // erase cluster expansion settings group
562  else if(vm.count("erase-clex")) {
563  if(set.default_clex().name == single_input) {
564  args.log << "Coult not erase the cluster expansion named '" << single_input << "' "
565  << "because it is the default cluster expansion.\n\n";
566  return 1;
567  }
568 
569  if(set.cluster_expansions().size() == 1) {
570  args.log << "Could not erase the cluster expansion named '" << single_input << "' "
571  << "because it is the only cluster expansion.\n\n";
572  return 1;
573  }
574 
575  if(set.erase_clex(set.clex(single_input))) {
576  set.commit();
577  if(args.primclex) {
578  args.primclex->refresh(true, false, true, true, true);
579  }
580  args.log << "Erased cluster expansion named '" << single_input << "'\n\n";
581  return 0;
582  }
583  else {
584  args.log << "Could not erase cluster expansion named '" << single_input << "'.\n\n";
585  return 1;
586  }
587  }
588 
589  // set clex to use by default for formation energy
590  else if(vm.count("set-formation-energy")) {
591 
592  if(clex_desc.property != "formation_energy") {
593  args.err_log << "Attempting to use cluster expansion '" << clex_desc.name
594  << "' for formation_energy, but it has 'property' value '"
595  << clex_desc.property << "'.\n\n";
596  return ERR_INVALID_ARG;
597  }
598 
599  auto it = set.cluster_expansions().find("formation_energy");
600  if(it != set.cluster_expansions().end()) {
601  set.erase_clex(it->second);
602  }
603  clex_desc.name = "formation_energy";
604  if(set.new_clex(clex_desc)) {
605  set.commit();
606  if(args.primclex) {
607  args.primclex->refresh(true, false, true, true, true);
608  }
609  args.log << "Now using cluster expansion '" << single_input
610  << "' as the default for formation_energy.\n\n";
611  return 0;
612  }
613  else {
614  args.log << "Could not use cluster expansion '" << single_input
615  << "' as the default for formation_energy.\n\n";
616  return 1;
617  }
618  }
619 
620  // set default clex
621  else if(vm.count("set-default-clex")) {
622  if(set.set_default_clex(single_input)) {
623  set.commit();
624  if(args.primclex) {
625  args.primclex->refresh(true, false, true, true, true);
626  }
627  args.log << "Switched to cluster expansion '" << single_input << "'.\n\n";
628  return 0;
629  }
630  else {
631  args.log << "Could not switch to cluster expansion '" << single_input << "'.\n\n";
632  return 1;
633  }
634  }
635 
636  // set property
637  else if(vm.count("set-property")) {
638 
639  d.property = pair_type(single_input, do_not_create);
640  d.calctype = pair_type("default", do_not_create);
641  d.ref = pair_type("default", do_not_create);
642  d.bset = pair_type("default", do_not_create);
643  d.eci = pair_type("default", create);
644 
645  return d.update();
646  }
647 
648  // set bset
649  else if(vm.count("set-bset")) {
650 
651  d.bset = pair_type(single_input, do_not_create);
652  d.eci = pair_type("default", create);
653 
654  return d.update();
655  }
656 
657  // set calctype
658  else if(vm.count("set-calctype")) {
659 
660  d.calctype = pair_type(single_input, do_not_create);
661  d.ref = pair_type("default", do_not_create);
662  d.eci = pair_type("default", create);
663 
664  return d.update();
665  }
666 
667  // set ref
668  else if(vm.count("set-ref")) {
669 
670  d.ref = pair_type(single_input, do_not_create);
671  d.eci = pair_type("default", create);
672 
673  return d.update();
674  }
675 
676  // set eci
677  else if(vm.count("set-eci")) {
678 
679  d.eci = pair_type(single_input, do_not_create);
680 
681  return d.update();
682  }
683 
684  // set all
685  else if(vm.count("set-all")) {
686 
687  if(multi_input.size() != 5) {
688  args.log << "Error using --set-all: Expected 5 arguments: 'property' 'calctype' 'ref' 'bset' 'eci'" << std::endl;
689  return ERR_INVALID_ARG;
690  }
691 
692  d.property = pair_type(multi_input[0], do_not_create);
693  d.calctype = pair_type(multi_input[1], do_not_create);
694  d.ref = pair_type(multi_input[2], do_not_create);
695  d.bset = pair_type(multi_input[3], do_not_create);
696  d.eci = pair_type(multi_input[4], create);
697 
698  return d.update();
699  }
700 
701  // set cxx
702  else if(vm.count("set-cxx")) {
703  set.set_cxx(single_input);
704  set.commit();
705  if(args.primclex) {
706  args.primclex->refresh(true, false, false, false, true);
707  }
708 
709  args.log << "Set " << _wdefaultval("cxx", set.cxx());
710  args.log << "Compile command is now: '" << set.compile_options() << "'\n\n";
711  args.log << "Shared object compile command is now: '" << set.so_options() << "'\n\n";
712 
713  return 0;
714  }
715 
716  // set cxxflags
717  else if(vm.count("set-cxxflags")) {
718  set.set_cxxflags(single_input);
719  set.commit();
720  if(args.primclex) {
721  args.primclex->refresh(true, false, false, false, true);
722  }
723 
724  args.log << "Set " << _wdefaultval("cxxflags", set.cxxflags());
725  args.log << "Compile command is now: '" << set.compile_options() << "'\n\n";
726 
727  return 0;
728  }
729 
730  // set soflags
731  else if(vm.count("set-soflags")) {
732  set.set_soflags(single_input);
733  set.commit();
734  if(args.primclex) {
735  args.primclex->refresh(true, false, false, false, true);
736  }
737 
738  args.log << "Set " << _wdefaultval("soflags", set.soflags());
739  args.log << "Shared object compile command is now: '" << set.so_options() << "'\n\n";
740 
741  return 0;
742  }
743 
744  // set casm prefix
745  else if(vm.count("set-casm-prefix")) {
746  set.set_casm_prefix(single_input);
747  set.commit();
748  if(args.primclex) {
749  args.primclex->refresh(true, false, false, false, true);
750  }
751 
752  args.log << "Set " << _wdefaultval("casm_includedir", set.casm_includedir());
753  args.log << "Set " << _wdefaultval("casm_libdir", set.casm_libdir());
754  args.log << "Compile command is now: '" << set.compile_options() << "'\n\n";
755  args.log << "Shared object compile command is now: '" << set.so_options() << "'\n\n";
756 
757  return 0;
758  }
759 
760  // set casm includedir
761  else if(vm.count("set-casm-includedir")) {
762  set.set_casm_includedir(single_input);
763  set.commit();
764  if(args.primclex) {
765  args.primclex->refresh(true, false, false, false, true);
766  }
767 
768  args.log << "Set " << _wdefaultval("casm_includedir", set.casm_includedir());
769  args.log << "Compile command is now: '" << set.compile_options() << "'\n\n";
770  args.log << "Shared object compile command is now: '" << set.so_options() << "'\n\n";
771 
772  return 0;
773  }
774 
775  // set casm libdir
776  else if(vm.count("set-casm-libdir")) {
777  set.set_casm_libdir(single_input);
778  set.commit();
779  if(args.primclex) {
780  args.primclex->refresh(true, false, false, false, true);
781  }
782 
783  args.log << "Set " << _wdefaultval("casm_libdir", set.casm_libdir());
784  args.log << "Compile command is now: '" << set.compile_options() << "'\n\n";
785  args.log << "Shared object compile command is now: '" << set.so_options() << "'\n\n";
786 
787  return 0;
788  }
789 
790  // set boost prefix
791  else if(vm.count("set-boost-prefix")) {
792  set.set_boost_prefix(single_input);
793  set.commit();
794  if(args.primclex) {
795  args.primclex->refresh(true, false, false, false, true);
796  }
797 
798  args.log << "Set " << _wdefaultval("boost_includedir", set.boost_includedir());
799  args.log << "Set " << _wdefaultval("boost_libdir", set.boost_libdir());
800  args.log << "Compile command is now: '" << set.compile_options() << "'\n\n";
801  args.log << "Shared object compile command is now: '" << set.so_options() << "'\n\n";
802 
803  return 0;
804  }
805 
806  // set boost includedir
807  else if(vm.count("set-boost-includedir")) {
808  set.set_boost_includedir(single_input);
809  set.commit();
810  if(args.primclex) {
811  args.primclex->refresh(true, false, false, false, true);
812  }
813 
814  args.log << "Set " << _wdefaultval("boost_includedir", set.boost_includedir());
815  args.log << "Compile command is now: '" << set.compile_options() << "'\n\n";
816  args.log << "Shared object compile command is now: '" << set.so_options() << "'\n\n";
817 
818  return 0;
819  }
820 
821  // set boost libdir
822  else if(vm.count("set-boost-libdir")) {
823  set.set_boost_libdir(single_input);
824  set.commit();
825  if(args.primclex) {
826  args.primclex->refresh(true, false, false, false, true);
827  }
828 
829  args.log << "Set " << _wdefaultval("boost_libdir", set.boost_libdir());
830  args.log << "Compile command is now: '" << set.compile_options() << "'\n\n";
831  args.log << "Shared object compile command is now: '" << set.so_options() << "'\n\n";
832 
833  return 0;
834  }
835 
836  // set 'casm view' command
837  else if(vm.count("set-view-command")) {
838  set.set_view_command(single_input);
839  set.commit();
840  if(args.primclex) {
841  args.primclex->refresh(true, false, false, false, false);
842  }
843 
844  args.log << "Set view command to: '" << set.view_command() << "'\n\n";
845 
846  return 0;
847  }
848 
849  args.log << std::endl;
850 
851  return 0;
852  };
853 
854 
855 }
Data structure holding basic CASM command info.
pair_type eci
Definition: settings.cc:112
ClexDescription & desc
Definition: settings.cc:104
const std::vector< std::string > & input_vec() const
Definition: settings.cc:32
Specifies a particular cluster expansion.
void commit() const
Save settings to project settings file.
std::pair< std::string, std::string > cxxflags() const
Get c++ compiler options.
std::vector< std::string > m_input_vec
Definition: Handlers.hh:635
bool set_casm_prefix(fs::path dir)
Set casm prefix (empty string to use default)
std::pair< fs::path, std::string > boost_includedir() const
Get boost includedir.
#define ERR_INVALID_ARG
Specification of CASM project directory structure.
PrimClex * primclex
Definition: settings.cc:101
const std::string & input_str() const
Definition: settings.cc:28
void add_help_suboption()
Add a plain –help suboption.
Definition: Handlers.cc:276
std::string so_options() const
Get current shared library options string.
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.
Definition: PrimClex.cc:90
bool set_default_clex(const std::string &clex_name)
Main CASM namespace.
Definition: complete.cpp:8
Log & log
Definition: settings.cc:105
void initialize() override
Fill in the options descriptions accordingly.
Definition: settings.cc:36
void print_summary(Log &log) const
Print summary of ProjectSettings, as for 'casm settings -l'.
bool set_view_command(std::string opt)
Set command used by 'casm view'.
ProjectSettings & set
Definition: settings.cc:103
bool set_cxx(std::string opt)
Set c++ compiler (empty string to use default)
bool clex_exists(const DirectoryStructure &dir, const ClexDescription &desc)
pair_type ref
Definition: settings.cc:110
fs::path bspecs(std::string bset) const
Return basis function specs (bspecs.json) file path.
const ClexDescription & clex(std::string name) const
const po::options_description & desc()
Get the program options, filled with the initialized values.
Definition: Handlers.cc:160
Read/modify settings of an already existing CASM project.
pair_type property
Definition: settings.cc:108
std::pair< fs::path, std::string > casm_libdir() const
Get casm libdir.
std::pair< fs::path, std::string > casm_includedir() const
Get casm includedir.
bool set_boost_prefix(fs::path dir)
Set boost prefix (empty string to use default)
pair_type calctype
Definition: settings.cc:109
bool set_boost_libdir(fs::path dir)
Set boost libdir (empty string to use default)
po::options_description m_desc
Boost program options. All the derived classes have them, but will fill them up themselves.
Definition: Handlers.hh:126
std::string compile_options() const
Get current compilation options string.
bool set_casm_libdir(fs::path dir)
Set casm libdir (empty string to use default)
bool set_soflags(std::string opt)
Set shared object options (empty string to use default)
const std::map< std::string, ClexDescription > & cluster_expansions() const
DirectoryStructure & dir
Definition: settings.cc:102
bool set_casm_includedir(fs::path dir)
Set casm includedir (empty string to use default)
bool erase_clex(const ClexDescription &desc)
Log & err_log
Definition: settings.cc:106
void error(const std::string &what)
Definition: Log.hh:86
std::pair< fs::path, std::string > boost_libdir() const
Get boost libdir.
bool new_clex(const ClexDescription &desc)
std::string view_command() const
Get current command used by 'casm view'.
pair_type bset
Definition: settings.cc:111
std::tuple< fs::path, jsonParser, std::string, std::pair< bool, double > > Data
Definition: import.cc:17
bool contains(const Container &container, const T &value)
Equivalent to container.end() != std::find(container.begin(), container.end(), value) ...
Definition: algorithm.hh:66
std::pair< std::string, std::string > soflags() const
Get shared object options.
std::pair< std::string, std::string > cxx() const
Get c++ compiler.
int settings_command(const CommandArgs &args)
Definition: settings.cc:257
const ClexDescription & default_clex() const
bool set_boost_includedir(fs::path dir)
Set boost includedir (empty string to use default)
bool set_cxxflags(std::string opt)
Set c++ compiler options (empty string to use default)
#define ERR_NO_PROJ