CASM  1.1.0
A Clusters Approach to Statistical Mechanics
write_prim_symmetry.cc
Go to the documentation of this file.
2 
3 #include <boost/filesystem/fstream.hpp>
4 
5 #include "casm/app/APICommand.hh"
7 #include "casm/app/io/json_io.hh"
8 #include "casm/casm_io/Log.hh"
10 #include "casm/clex/PrimClex.hh"
14 #include "casm/symmetry/SymInfo.hh"
15 #include "casm/symmetry/json_io.hh"
16 
17 namespace CASM {
18 
19 class DirectoryStructure;
20 class Structure;
21 
41  DirectoryStructure const &dir,
42  COORD_TYPE coordtype, bool brief, Log &log,
43  bool print_lattice_point_group,
44  bool print_factor_group,
45  bool print_crystal_point_group) {
46  // Selects coordinate printing mode (CART vs FRAC) == coordtype until "C" goes
47  // out of scope
48  xtal::COORD_MODE C(coordtype);
50 
51  if (!print_lattice_point_group && !print_factor_group &&
52  !print_crystal_point_group) {
53  log << " Lattice point group size: " << lattice_pg.size() << std::endl;
54  log << " Lattice point group is: " << lattice_pg.get_name() << std::endl
55  << std::endl;
56 
57  log << " Factor group size: " << prim.factor_group().size() << std::endl;
58  log << " Crystal point group is: " << prim.point_group().get_name()
59  << std::endl;
60  }
61 
62  auto print_group = [&](std::string name, SymGroup const &group) {
63  if (brief) {
64  log << name << ": (" << xtal::COORD_MODE::NAME(coordtype)
65  << " representation)" << std::endl;
66  SymInfoOptions opt{coordtype};
67  brief_description(log, group, prim.lattice(), opt);
68  } else {
69  log << name << ":" << std::endl;
70  group.print(log, coordtype);
71  }
72  };
73 
74  if (print_lattice_point_group) {
75  print_group("Lattice point group", lattice_pg);
76  }
77 
78  if (print_factor_group) {
79  print_group("Factor group", prim.factor_group());
80  }
81 
82  if (print_crystal_point_group) {
83  print_group("Crystal point group", prim.point_group());
84  }
85 
86  // Write symmetry info files
88 
89  auto write_group = [&](fs::path path, SymGroup const &group) {
90  fs::ofstream outfile;
91  jsonParser json;
92  outfile.open(path);
93  write_symgroup(group, json);
94  json.print(outfile);
95  outfile.close();
96  };
97 
98  write_group(dir.lattice_point_group(), lattice_pg);
99  write_group(dir.factor_group(), prim.factor_group());
100  write_group(dir.crystal_point_group(), prim.point_group());
101 }
102 
105  std::string description =
106 
107  "Write / print prim symmetry information (default behavior): "
108  " \n\n"
109 
110  " The default `casm sym` action writes the following symmetry files: "
111  " \n"
112  " - Lattice point group: <root>/symmetry/lattice_point_group.json "
113  " \n"
114  " - Crystal factor group: <root>/symmetry/factor_group.json "
115  " \n"
116  " - Crystal point group: <root>/symmetry/crystal_point_group.json "
117  " \n\n"
118 
119  " Optionally, it also prints symmetry information: "
120  " \n"
121  " - Print lattice point group with --lattice-point-group "
122  " \n"
123  " - Print crystal factor group with --print-factor-group "
124  " \n"
125  " - Print crystal point group with --print-crystal-point-group "
126  " \n"
127  " - Print brief symmetry operation descriptions with --brief "
128  " \n"
129  " - Control coordinate printing mode (FRAC vs CART) with --coord "
130  " \n\n"
131 
132  " Use cases: "
133  " \n"
134  " - Use this method to print symmetry info to screen "
135  " \n"
136  " - Use this method to write symmetry files if they have been deleted "
137  " \n"
138  " - Use this method to write symmetry files if the crystallography "
139  " \n"
140  " tolerance in project settings is modified "
141  " \n\n\n";
142 
143  return description;
144 }
145 
147 void write_prim_symmetry(PrimClex &primclex, jsonParser const &json_options,
148  jsonParser const &cli_options_as_json) {
149  jsonParser json_combined{json_options};
150  std::map<std::string, std::string> cli_to_combined_keys{
151  {"print_lattice_point_group",
152  "print_lattice_point_group"}, // --lattice-point-group
153  {"print_factor_group", "print_factor_group"}, // --factor-group
154  {"print_crystal_point_group",
155  "print_crystal_point_group"}, // --crystal-point-group
156  {"coordinate_mode", "coordinate_mode"}, // --coord
157  {"brief", "brief"} // --brief
158  };
159  combine_json_options(cli_to_combined_keys, cli_options_as_json,
160  json_combined);
161 
162  ParentInputParser parser{json_combined};
163 
164  bool print_lattice_point_group;
165  bool print_factor_group;
166  bool print_crystal_point_group;
167  COORD_TYPE coordtype;
168  bool brief;
169 
170  parser.optional_else(print_lattice_point_group, "print_lattice_point_group",
171  false);
172  parser.optional_else(print_factor_group, "print_factor_group", false);
173  parser.optional_else(print_crystal_point_group, "print_crystal_point_group",
174  false);
175  parser.optional_else(coordtype, "coordinate_mode", FRAC);
176  std::runtime_error error_if_invalid{"Error reading `casm sym` input"};
177  report_and_throw_if_invalid(parser, log(), error_if_invalid);
178 
179  parser.optional_else(brief, "brief", false);
180 
181  write_prim_symmetry_impl(primclex.prim(), primclex.dir(), coordtype, brief,
182  log(), print_lattice_point_group, print_factor_group,
183  print_crystal_point_group);
184 }
185 
186 } // namespace CASM
Specification of CASM project directory structure.
fs::path crystal_point_group() const
Return crystal_point_group.json path.
fs::path lattice_point_group() const
Return lattice_point_group.json path.
bool new_symmetry_dir() const
Create new symmetry directory.
fs::path factor_group() const
Return factor_group.json path.
RequiredType optional_else(fs::path option, const RequiredType &_default, Args &&... args)
Definition: Log.hh:48
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:55
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:30
const SymGroup & point_group() const
Definition: Structure.cc:110
const Lattice & lattice() const
Definition: Structure.hh:100
const MasterSymGroup & factor_group() const
Definition: Structure.cc:107
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:42
const std::string & get_name() const
Definition: SymGroup.cc:1668
static SymGroup lattice_point_group(Lattice const &_lat)
Definition: SymGroup.cc:779
void print(std::ostream &stream, unsigned int indent=2, unsigned int prec=12) const
Print json to stream.
Definition: jsonParser.cc:188
COORD_MODE specifies the current coordinate mode (Fractional or Cartesian)
static std::string NAME()
get a string with the name of the active mode
const DirectoryStructure & dir() const
Access DirectoryStructure object. Throw if not set.
Definition: PrimClex.cc:230
const PrimType & prim() const
const Access to primitive Structure
Definition: PrimClex.cc:262
Main CASM namespace.
Definition: APICommand.hh:8
std::string write_prim_symmetry_desc()
Describe the default casm sym option.
std::string description(const SymOp &op, const xtal::Lattice &lat, SymInfoOptions opt=SymInfoOptions())
Print SymInfo to string.
COORD_TYPE
Definition: enum.hh:6
void write_prim_symmetry_impl(Structure const &prim, DirectoryStructure const &dir, COORD_TYPE coordtype, bool brief, Log &log, bool print_lattice_point_group, bool print_factor_group, bool print_crystal_point_group)
Log & log()
Definition: Log.hh:424
std::string brief_description(const SymOp &op, const xtal::Lattice &lat, SymInfoOptions opt=SymInfoOptions())
Print SymInfo to brief string.
const COORD_TYPE FRAC
Definition: enum.hh:8
GenericDatumFormatter< std::string, DataObject > name()
void write_symgroup(SymGroup const &grp, jsonParser &json)
jsonParser & combine_json_options(std::map< std::string, std::string > const &source_to_combined_keys, jsonParser const &json_source, jsonParser &json_combined)
Copy from json_source to json_combined
Definition: json_io.cc:8
void write_prim_symmetry(PrimClex &primclex, jsonParser const &json_options, jsonParser const &cli_options_as_json)
Write/print prim symmetry.
void report_and_throw_if_invalid(KwargsParser const &parser, Log &log, ErrorType error)
PrimClex * primclex
Definition: settings.cc:135
DirectoryStructure const & dir
Definition: settings.cc:136
Options for printing SymInfo.