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