CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
sym.cc
Go to the documentation of this file.
5 #include "casm/app/AppIO.hh"
7 
9 
10 namespace CASM {
11 
12  namespace Completer {
14 
18  m_desc.add_options()
19  ("lattice-point-group", "Pretty print lattice point group")
20  ("factor-group", "Pretty print factor group")
21  ("crystal-point-group", "Pretty print crystal point group");
22 
23  return;
24  }
25  }
26 
27 
28  // ///////////////////////////////////////
29  // 'sym' function for casm
30  // (add an 'if-else' statement in casm.cpp to call this)
31 
32  int sym_command(const CommandArgs &args) {
33  //std::string name;
34  COORD_TYPE coordtype;
35  po::variables_map vm;
36 
38  Completer::SymOption sym_opt;
39  try {
40  po::store(po::parse_command_line(args.argc, args.argv, sym_opt.desc()), vm); // can throw
41 
44  if(vm.count("help")) {
45  args.log << "\n";
46  args.log << sym_opt.desc() << std::endl;
47 
48  return 0;
49  }
50 
51  if(vm.count("desc")) {
52  args.log << "\n";
53  args.log << sym_opt.desc() << std::endl;
54  args.log << "DESCRIPTION" << std::endl;
55  args.log << " Display symmetry group information.\n";
56 
57  return 0;
58  }
59 
60  po::notify(vm); // throws on error, so do after help in case
61  // there are any problems
62 
63  coordtype = sym_opt.coordtype_enum();
64  }
65  catch(po::error &e) {
66  args.err_log << "ERROR: " << e.what() << std::endl << std::endl;
67  args.err_log << sym_opt.desc() << std::endl;
68  return ERR_INVALID_ARG;
69  }
70  catch(std::exception &e) {
71  args.err_log << "Unhandled Exception reached the top of main: "
72  << e.what() << ", application will now exit" << std::endl;
73  return ERR_UNKNOWN;
74 
75  }
76 
77  COORD_MODE C(coordtype);
78 
79  const fs::path &root = args.root;
80  if(root.empty()) {
81  args.err_log.error("No casm project found");
82  args.err_log << std::endl;
83  return ERR_NO_PROJ;
84  }
85 
86  DirectoryStructure dir(root);
87  ProjectSettings set(root);
88  Structure prim(read_prim(dir.prim()));
89 
90  args.log << "Generating lattice point group. " << std::endl << std::endl;
91  SymGroup prim_pg;
92  prim.lattice().generate_point_group(prim_pg, set.crystallography_tol());
93  prim_pg.character_table();
94 
95 
96  args.log << " Lattice point group size: " << prim_pg.size() << std::endl;
97  args.log << " Lattice point group is: " << prim_pg.get_name() << std::endl << std::endl;
98 
99  args.log << "Generating factor group. " << std::endl << std::endl;
100 
102  prim.set_site_internals();
103 
104  args.log << " Factor group size: " << prim.factor_group().size() << std::endl;
105 
106  args.log << " Crystal point group is: " << prim.point_group().get_name() << std::endl;
107 
108 
109  if(vm.count("lattice-point-group")) {
110  args.log << "\n***************************\n" << std::endl;
111  args.log << "Lattice point group:\n\n" << std::endl;
112  prim_pg.print(args.log, coordtype);
113  }
114 
115  if(vm.count("factor-group")) {
116  args.log << "\n***************************\n" << std::endl;
117  args.log << "Factor group:\n\n" << std::endl;
118  prim.factor_group().print(args.log, coordtype);
119  }
120 
121  if(vm.count("crystal-point-group")) {
122  args.log << "\n***************************\n" << std::endl;
123  args.log << "Crystal point group:\n\n" << std::endl;
124  prim.point_group().print(args.log, coordtype);
125  }
126 
127  // Write symmetry info files
128  set.new_symmetry_dir();
129 
130  // Write lattice point group
131  {
132  fs::ofstream outfile;
133  jsonParser json;
134  outfile.open(dir.lattice_point_group());
135  write_symgroup(prim_pg, json);
136  json.print(outfile);
137  outfile.close();
138  }
139 
140  // Write factor group
141  {
142  fs::ofstream outfile;
143  jsonParser json;
144  outfile.open(dir.factor_group());
145  write_symgroup(prim.factor_group(), json);
146  json.print(outfile);
147  outfile.close();
148  }
149 
150  // Write crystal point group
151  {
152  fs::ofstream outfile;
153  jsonParser json;
154  outfile.open(dir.crystal_point_group());
155  write_symgroup(prim.point_group(), json);
156  json.print(outfile);
157  outfile.close();
158  }
159 
160  args.log << std::endl;
161 
162  return 0;
163 
164  };
165 
166 }
167 
168 
Data structure holding basic CASM command info.
COORD_TYPE coordtype_enum() const
Return the coordinate type recasted as the CASM defined enum.
Definition: Handlers.cc:220
void set_site_internals()
Associate each site with its basis index by setting its internal flags (asym_ind -> -1) ...
#define ERR_UNKNOWN
Index size() const
Definition: Array.hh:145
void generate_point_group(SymGroup &point_group, double pg_tol=TOL) const
Populate.
Definition: Lattice.cc:304
#define ERR_INVALID_ARG
Specification of CASM project directory structure.
const SymGroup & point_group() const
Definition: Structure.cc:101
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:29
void write_symgroup(const SymGroup &grp, jsonParser &json)
Definition: AppIO.cc:183
void add_help_suboption()
Add a plain –help suboption.
Definition: Handlers.cc:276
Main CASM namespace.
Definition: complete.cpp:8
const Lattice & lattice() const
fs::path prim() const
Return prim.json path.
ProjectSettings & set
Definition: settings.cc:103
void print(std::ostream &out, COORD_TYPE mode) const
Print the SymGroup to a stream.
Definition: SymGroup.cc:3431
void generate_factor_group(double map_tol=TOL) const
Definition: Structure.cc:85
BasicStructure< Site > read_prim(fs::path filename)
Definition: AppIO.cc:11
void print(std::ostream &stream, unsigned int indent=2, unsigned int prec=12) const
Print json to stream.
Definition: jsonParser.cc:185
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:33
fs::path crystal_point_group() const
Return crystal_point_group.json path.
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)
const MasterSymGroup & factor_group() const
Definition: Structure.cc:94
Read/modify settings of an already existing CASM project.
const Array< std::complex< double > >::X2 & character_table() const
Definition: SymGroup.cc:3212
bool new_symmetry_dir() const
Create new symmetry directory.
po::options_description m_desc
Boost program options. All the derived classes have them, but will fill them up themselves.
Definition: Handlers.hh:126
void initialize() override
Fill in the options descriptions accordingly.
Definition: sym.cc:15
fs::path lattice_point_group() const
Return lattice_point_group.json path.
void add_coordtype_suboption()
Add a –coord suboption to specify FRAC or CART.
Definition: Handlers.cc:377
DirectoryStructure & dir
Definition: settings.cc:102
int sym_command(const CommandArgs &args)
Definition: sym.cc:32
double crystallography_tol() const
Get current project crystallography tolerance.
void error(const std::string &what)
Definition: Log.hh:86
const std::string & get_name() const
Definition: SymGroup.cc:3220
fs::path factor_group() const
Return factor_group.json path.
#define ERR_NO_PROJ