CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ProjectBuilder.cc
Go to the documentation of this file.
3 
4 namespace CASM {
5 
14  void ProjectBuilder::build() const {
15 
16  try {
17 
18  fs::path test_root = find_casmroot(m_root);
19  if(test_root == m_root) {
20  std::cerr << "Attempting to create a casm project here: " << m_root << std::endl;
21  std::cerr << "Found existing casm project here: " << test_root << std::endl;
22  throw std::runtime_error(
23  std::string("Error in 'ProjectBuilder::build()'.\n") +
24  " Already in a casm project: " + test_root.string());
25  }
26 
28 
29  // check for a prim.json
30  if(!fs::is_regular_file(dir.prim())) {
31  throw std::runtime_error(
32  std::string("Error in 'ProjectBuilder::build()'.\n") +
33  " No prim.json file found at: " + dir.prim().string());
34  }
35 
37 
38  // create basic directories
39  set.new_casm_dir();
40  set.new_symmetry_dir();
41  set.new_bset_dir("default");
42  set.new_calc_settings_dir("default");
43  set.new_ref_dir("default", "default");
44  set.new_eci_dir(m_property, "default", "default", "default", "default");
45 
46  // set project settings
47 
48  auto exc = [ = ](std::string type) {
49  throw std::runtime_error(
50  std::string("Error in 'ProjectBuilder::build()'.\n") +
51  " Could not set " + type);
52  };
53 
54  set.properties() = m_properties;
55 
56  ClexDescription desc("formation_energy", "formation_energy", "default", "default", "default", "default");
57  set.new_clex(desc);
58  set.set_default_clex(desc.name);
59 
61  exc("crystallography_tol");
62  }
63  if(!set.set_lin_alg_tol(m_lin_alg_tol)) {
64  exc("lin_alg_tol");
65  }
66 
67  set.commit();
68 
69 
70  // Read prim
71  Structure prim;
72  fs::ifstream primfile(dir.prim());
73  prim = Structure(read_prim(jsonParser(primfile)));
74  primfile.close();
75 
76 
77  // Calculate symmetry --------------------
78  // get lattice point group and character table
79  SymGroup lattice_point_grp;
80  prim.lattice().generate_point_group(lattice_point_grp, m_crystallography_tol);
81  lattice_point_grp.character_table();
82 
83  // get factor group
84  prim.generate_factor_group(m_crystallography_tol);
85  prim.set_site_internals();
86 
87  // Write symmetry info files
88 
89  // Write lattice point group
90  {
91  fs::ofstream outfile;
92  jsonParser json;
93  outfile.open(dir.lattice_point_group());
94  write_symgroup(lattice_point_grp, json);
95  json.print(outfile);
96  outfile.close();
97  }
98 
99  // Write factor group
100  {
101  fs::ofstream outfile;
102  jsonParser json;
103  outfile.open(dir.factor_group());
104  write_symgroup(prim.factor_group(), json);
105  json.print(outfile);
106  outfile.close();
107  }
108 
109  // Write crystal point group
110  {
111  fs::ofstream outfile;
112  jsonParser json;
113  outfile.open(dir.crystal_point_group());
114  write_symgroup(prim.point_group(), json);
115  json.print(outfile);
116  outfile.close();
117  }
118 
119 
120  // Generate standard composition axes --------------------
121  CompositionAxes opt;
122 
123  opt.standard.clear();
124  std::vector<CompositionConverter> v;
125  standard_composition_axes(prim, std::back_inserter(v));
126  for(int i = 0; i < v.size(); i++) {
127  opt.standard[std::to_string(i)] = v[i];
128  }
129 
130  opt.write(dir.composition_axes());
131 
132  }
133  catch(...) {
134  std::cerr << "Uncaught exception in ProjectBuilder::build()" << std::endl;
136  throw;
137  }
138  }
139 }
140 
ClexDescription & desc
Definition: settings.cc:104
Specifies a particular cluster expansion.
void commit() const
Save settings to project settings file.
std::map< std::string, CompositionConverter > standard
Definition: AppIO.hh:91
fs::path composition_axes() const
Return composition axes file path.
void generate_point_group(SymGroup &point_group, double pg_tol=TOL) const
Populate.
Definition: Lattice.cc:304
Specification of CASM project directory structure.
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
bool set_default_clex(const std::string &clex_name)
Main CASM namespace.
Definition: complete.cpp:8
std::string to_string(ENUM val)
Return string representation of enum class.
Definition: EnumIO.hh:83
bool new_eci_dir(std::string clex, std::string calctype, std::string ref, std::string bset, std::string eci) const
Add an eci directory.
fs::path prim() const
Return prim.json path.
bool new_casm_dir() const
Create new project data directory.
bool new_ref_dir(std::string calctype, std::string ref) const
Add a ref directory.
ProjectSettings & set
Definition: settings.cc:103
fs::path find_casmroot(const fs::path &cwd)
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.
bool set_crystallography_tol(double _tol)
Set crystallography tolerance.
const std::vector< std::string > & properties() const
Get current properties.
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.
bool new_bset_dir(std::string bset) const
Add a basis set directory.
void build() const
Builds a new CASM project.
fs::path lattice_point_group() const
Return lattice_point_group.json path.
const Lattice & lattice() const
Definition: SymGroup.cc:940
bool set_lin_alg_tol(double _tol)
Set linear algebra tolerance.
OutputIterator standard_composition_axes(const Structure &prim, OutputIterator result)
Generate CompositionConverter specifying standard composition axes for a prim Structure.
DirectoryStructure & dir
Definition: settings.cc:102
bool new_calc_settings_dir(std::string calctype) const
Add calculation settings directory path.
void write(fs::path _filename)
Write CompositionAxes to file.
Definition: AppIO.cc:339
bool new_clex(const ClexDescription &desc)
fs::path factor_group() const
Return factor_group.json path.