CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
perturb.cc
Go to the documentation of this file.
5 
6 namespace CASM {
7 
8  namespace Completer {
10 
12  return m_cspecs_path;
13  }
14 
18  m_desc.add_options()
19  ("occ", "Perturb occupations")
20  ("cspecs", po::value<fs::path>(&m_cspecs_path)->value_name(ArgHandler::path()), "Cluster specifications file defining perturbation");
21  //("strain,s", "Generate strain perturbations")
22  //("gridsize", po::value<std::vector<Index> > (&subgrids)->multitoken(), "Size of grid for each subspace")
23  //("mag", po::value<std::vector<double> > (&mags)->multitoken(), "Magnitude of grid")
24  //("poly-order", po::value<Index> (&poly_order)->default_value(6), "Max order of strain polynomials")
25  //("strainmode", po::value<std::string> (&strain_mode)->default_value("GL"), "Strain mode name");
26  return;
27  }
28  }
29 
30 
31  // ///////////////////////////////////////
32  // 'perturb' function for casm
33  // (add an 'if-else' statement in casm.cpp to call this)
34 
35  int perturb_command(const CommandArgs &args) {
36 
37  double tol = CASM::TOL;
38  fs::path cspecs_path, abs_cspecs_path;
39  fs::path selection;
40  COORD_TYPE coordtype = CASM::FRAC;
41  po::variables_map vm;
42  std::vector<Index> subgrids;
43  std::vector<double> mags;
44  std::string strain_mode;
45  //Index poly_order;
46 
48  Completer::PerturbOption perturb_opt;
49 
50  try {
51  po::store(po::parse_command_line(args.argc, args.argv, perturb_opt.desc()), vm); // can throw
52 
55  if(vm.count("help")) {
56  args.log << "\n";
57  args.log << perturb_opt.desc() << std::endl;
58 
59  return 0;
60  }
61 
62  if(vm.count("desc")) {
63  args.log << "\n";
64  args.log << perturb_opt.desc() << std::endl;
65 
66  args.log << "DESCRIPTION" << std::endl;
67  args.log << " Generate supercells that are perturbations of a reference\n";
68  args.log << " configuration. \n";
69  args.log << " - using the --cspecs option, a bspecs.json type file is \n";
70  args.log << " required to determine the extent of the perturbations. \n";
71  args.log << " Currently only 'orbit_branch_specs' are supported. \n";
72  args.log << " - perturbations are generated about selected reference \n";
73  args.log << " configurations \n";
74  args.log << std::endl;
75 
76  return 0;
77  }
78 
79  po::notify(vm); // throws on error, so do after help in case
80  // there are any problems
81 
82  cspecs_path = perturb_opt.cspecs_path();
83  selection = perturb_opt.selection_path();
84  }
85  catch(po::error &e) {
86  args.err_log << "ERROR: " << e.what() << std::endl << std::endl;
87  args.err_log << perturb_opt.desc() << std::endl;
88  return 1;
89  }
90  catch(std::exception &e) {
91  args.err_log << "Unhandled Exception reached the top of main: "
92  << e.what() << ", application will now exit" << std::endl;
93  return 1;
94 
95  }
96 
97  COORD_MODE C(coordtype);
98 
99  const fs::path &root = args.root;
100  if(root.empty()) {
101  args.err_log.error("No casm project found");
102  args.err_log << std::endl;
103  return ERR_NO_PROJ;
104  }
105 
106  // If 'args.primclex', use that, else construct PrimClex in 'uniq_primclex'
107  // Then whichever exists, store reference in 'primclex'
108  std::unique_ptr<PrimClex> uniq_primclex;
109  PrimClex &primclex = make_primclex_if_not(args, uniq_primclex);
110 
111  DirectoryStructure dir(root);
112  ProjectSettings set(root);
113 
114  // if(vm.count("strain")) {
115  // StrainConverter sconvert(strain_mode);
116  // sconvert.set_symmetrized_sop(primclex.get_prim().point_group());
117  //
118  // Eigen::MatrixXd axes = sconvert.sop_transf_mat();
119  // std::vector<Index> mult;
120  // std::vector<Eigen::MatrixXd> wedges = sconvert.irreducible_wedges(primclex.get_prim().point_group(), mult);
121  //
122  // Index num_sub = wedges.size();
123  //
124  // BasisSet strain_vars;
125  // Array<ContinuousDoF> tvars;
126  // for(Index i = 1; i <= 6; i++) {
127  // tvars.push_back(ContinuousDoF("E", i, -1e+15, 1e+15));
128  // tvars.back().lock_ID();
129  // }
130  // strain_vars.set_variable_basis(tvars, sconvert.symrep_ID());
131  // Eigen::MatrixXd trans_mat(2, 6);
132  // trans_mat << 0, 1, 0, 0, 0, 0,
133  // 0, 0, 1, 0, 0, 0;
134  // BasisSet sub_vars(strain_vars.transform_copy(trans_mat));
135  // BasisSet poly;
136  // for(Index i = 0; i <= poly_order; i++) {
137  // BasisSet tmono;
138  // tmono.construct_invariant_polynomials(Array<BasisSet const *>(1, &strain_vars), primclex.get_prim().point_group(), i);
139  // poly.append(tmono);
140  // }
141  //
142  // poly.accept(VariableLabeler("E(:,%n)"));
143  // fs::ofstream mfile(root / "poly.m");
144  // mfile << "corr =[\n";
145  // for(Index i = 0; i < poly.size(); i++) {
146  // mfile << " " << poly[i]->formula();
147  // if(i + 1 < poly.size())
148  // mfile << ",...";
149  // mfile << "\n";
150  // }
151  // mfile << "];\n";
152  // mfile.close();
153  // if(num_sub != subgrids.size() || num_sub != mags.size()) {
154  // args.log << "Option --strain selected. Based on crystal symmetry, strains can be independently enumerated in the following subspaces:\n";
155  //
156  // static_cast<std::ostream &>(args.log).precision(8);
157  // static_cast<std::ostream &>(args.log).flags(std::ios::showpoint | std::ios::fixed | std::ios::right);
158  // for(Index i = 0; i < num_sub; i++) {
159  // args.log << " Subspace " << i + 1 << ":\n";
160  // args.log << wedges[i].transpose() << "\n\n";
161  // }
162  // args.log << "To proceed, you must specify " << num_sub << " values for both '--mag' and '--subgrids'\n";
163  // return 1;
164  // }
165  //
166  // ConfigSelection<false> config_select;
167  // if(!vm.count("config") || selection == "MASTER") {
168  // config_select = ConfigSelection<false>(primclex);
169  // }
170  // else {
171  // config_select = ConfigSelection<false>(primclex, selection);
172  // }
173  //
174  // args.log << "\n***************************\n" << std::endl;
175  //
176  // args.log << "Generating perturbations about configurations " << std::endl << std::endl;
177  //
178  // //bool verbose = false;
179  // //bool print = true;
180  // for(auto it = config_select.selected_config_begin(); it != config_select.selected_config_end(); ++it) {
181  // Index num_before = (it->get_supercell()).get_config_list().size();
182  // ConfigEnumStrain enumerator(it->get_supercell(), *it, subgrids, mags, strain_mode);
183  // (it->get_supercell()).add_unique_canon_configs(enumerator.begin(), enumerator.end());
184  // args.log << "Enumerated " << (it->get_supercell()).get_config_list().size() - num_before << " deformations.\n";
185  // }
186  // }
187  // else
188  if(vm.count("occ")) {
189  // want absolute paths
190  abs_cspecs_path = fs::absolute(cspecs_path);
191 
192 
193 
194  ConfigSelection<false> config_select;
195  if(!vm.count("config") || selection == "MASTER") {
196  config_select = ConfigSelection<false>(primclex);
197  }
198  else {
199  config_select = ConfigSelection<false>(primclex, selection);
200  }
201 
202  args.log << "\n***************************\n" << std::endl;
203 
204  args.log << "Generating perturbations about configurations " << std::endl << std::endl;
205 
206  bool verbose = false;
207  bool print = true;
208  for(auto it = config_select.selected_config_begin(); it != config_select.selected_config_end(); ++it) {
209  args.log << " " << it->get_supercell().get_name() << "/" << it->get_id() << std::endl;
210  it->get_supercell().enumerate_perturb_configurations(*it, abs_cspecs_path, tol, verbose, print);
211  }
212  }
213  else {
214  args.log << "\n";
215  args.log << perturb_opt.desc() << std::endl;
216 
217  args.log << "DESCRIPTION" << std::endl;
218  args.log << " Generate supercells that are perturbations of a reference\n";
219  args.log << " configuration. \n";
220  args.log << " - using the --cspecs option, a bspecs.json type file is \n";
221  args.log << " required to determine the extent of the perturbations. \n";
222  args.log << " Currently only 'orbit_branch_specs' are supported. \n";
223  args.log << " - perturbations are generated about selected reference \n";
224  args.log << " configurations \n";
225  args.log << std::endl;
226 
227  return 1;
228  }
229 
230  args.log << std::endl << " DONE." << std::endl << std::endl;
231 
232  args.log << "Writing config_list..." << std::endl;
233  primclex.write_config_list();
234  args.log << " DONE" << std::endl;
235 
236  args.log << std::endl;
237 
238  return 0;
239  };
240 
241 }
Data structure holding basic CASM command info.
void write_config_list(std::set< std::string > scel_to_delete={})
Definition: PrimClex.cc:450
Specification of CASM project directory structure.
void initialize() override
Fill in the options descriptions accordingly.
Definition: perturb.cc:15
PrimClex * primclex
Definition: settings.cc:101
void add_help_suboption()
Add a plain –help suboption.
Definition: Handlers.cc:276
iterator selected_config_begin()
void add_configlist_suboption(const fs::path &_default="MASTER")
Add –config suboption (defaults to MASTER)
Definition: Handlers.cc:238
Main CASM namespace.
Definition: complete.cpp:8
const double TOL
const fs::path & selection_path() const
Returns the string corresponding to add_config_suboption()
Definition: Handlers.cc:168
static std::string path()
Get value_type string for path completion.
Definition: Handlers.cc:39
ProjectSettings & set
Definition: settings.cc:103
double tol
const po::options_description & desc()
Get the program options, filled with the initialized values.
Definition: Handlers.cc:160
COORD_MODE specifies the current coordinate mode (Fractional or Cartesian)
Read/modify settings of an already existing CASM project.
po::options_description m_desc
Boost program options. All the derived classes have them, but will fill them up themselves.
Definition: Handlers.hh:126
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
int perturb_command(const CommandArgs &args)
Definition: perturb.cc:35
DirectoryStructure & dir
Definition: settings.cc:102
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...
void error(const std::string &what)
Definition: Log.hh:86
const fs::path & cspecs_path() const
Definition: perturb.cc:11
#define ERR_NO_PROJ