CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ProjectBuilder.cc
Go to the documentation of this file.
2 
3 #include <boost/filesystem.hpp>
4 #include <boost/filesystem/fstream.hpp>
5 
9 #include "casm/casm_io/Log.hh"
18 
19 namespace CASM {
20 
21 void build_project(ProjectSettings const &project_settings,
22  Structure const &prim) {
23  ProjectSettings const &set = project_settings;
24 
25  if (!set.has_dir()) {
26  throw std::runtime_error(std::string("Error in build_project:") +
27  " Project settings do not have a root dir.");
28  }
29  auto checkroot = find_casmroot(set.root_dir());
30  if (checkroot == set.root_dir()) {
31  throw std::runtime_error(std::string("Error in build_project:") +
32  " Project already exists at '" +
33  checkroot.string() + "'");
34  }
35  DirectoryStructure const &dir = set.dir();
36 
37  // Create project directories -------------
38  log().indent() << "Creating CASM project directory tree at: "
39  << dir.root_dir() << std::endl;
41 
42  // Write project_settings.json file -------
43  commit(set);
44 
45  // Write prim.json file (into .casm directory) -------------------
46  log().indent() << "Writing prim file: " << dir.prim() << std::endl;
47  write_prim(prim, dir.prim(), FRAC);
48 
49  // Calculate symmetry --------------------
50  SymGroup lattice_point_grp{SymGroup::lattice_point_group(prim.lattice())};
51 
52  // Write symmetry info files
53 
54  // Write lattice point group
55  {
56  fs::ofstream outfile;
57  jsonParser json;
58  outfile.open(dir.lattice_point_group());
59  write_symgroup(lattice_point_grp, json);
60  json.print(outfile);
61  outfile.close();
62  }
63 
64  // Write factor group
65  {
66  fs::ofstream outfile;
67  jsonParser json;
68  outfile.open(dir.factor_group());
69  write_symgroup(prim.factor_group(), json);
70  json.print(outfile);
71  outfile.close();
72  }
73 
74  // Write crystal point group
75  {
76  fs::ofstream outfile;
77  jsonParser json;
78  outfile.open(dir.crystal_point_group());
79  write_symgroup(prim.point_group(), json);
80  json.print(outfile);
81  outfile.close();
82  }
83 
84  // Generate empty composition_axes.json --------------------
86 }
87 
89  std::string project_name) {
90  ProjectSettings settings{project_name};
91  auto W = default_nlist_weight_matrix(prim, settings.crystallography_tol());
92  settings.set_nlist_weight_matrix(W);
93  settings.set_nlist_sublat_indices(default_nlist_sublat_indices(prim));
94  settings.set_default_clex(default_configuration_clex());
95  settings.set_required_properties("Configuration", "default",
96  {"energy"});
97  return settings;
98 }
99 
101  std::string project_name,
102  fs::path root_dir) {
103  ProjectSettings settings = make_default_project_settings(prim, project_name);
104  settings.set_root_dir(root_dir);
105  return settings;
106 }
107 
109  double tol) {
111  10, tol);
112 }
113 
115  std::set<int> sublat_indices;
116  for (int b = 0; b < prim.basis().size(); ++b) {
117  if (prim.basis()[b].occupant_dof().size() >= 2 ||
118  prim.basis()[b].dof_size() > 0) {
119  sublat_indices.insert(b);
120  }
121  }
122  return sublat_indices;
123 }
124 } // namespace CASM
Specification of CASM project directory structure.
fs::path prim() const
Return prim.json path.
fs::path root_dir() const
Return casm project directory path.
fs::path crystal_point_group() const
Return crystal_point_group.json path.
fs::path lattice_point_group() const
Return lattice_point_group.json path.
fs::path composition_axes() const
Return composition axes file path.
fs::path factor_group() const
Return factor_group.json path.
Log & indent()
Definition: Log.hh:289
static Matrix3Type make_weight_matrix(const Eigen::Matrix3d lat_column_mat, Index max_element_value, double tol)
Returns a NeighborList weighting matrix appropriate for a particular lattice.
bool has_dir() const
Check if DirectoryStructure exists.
DirectoryStructure const & dir() const
Access DirectoryStructure object. Throw if not set.
fs::path root_dir() const
Access dir().root_dir(). Throw if not set.
bool set_root_dir(fs::path root)
Set DirectoryStructure.
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
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
BasicStructure specifies the lattice and atomic basis of a crystal.
const Lattice & lattice() const
const std::vector< Site > & basis() const
const Eigen::Matrix3d & lat_column_mat() const
3x3 matrix with lattice vectors as its columne
Definition: Lattice.hh:110
void commit(ProjectSettings const &set)
bool create_all_directories(ProjectSettings const &set)
Main CASM namespace.
Definition: APICommand.hh:8
std::set< int > default_nlist_sublat_indices(xtal::BasicStructure const &prim)
void write_composition_axes(fs::path _filename, CompositionAxes const &composition_axes)
Write CompositionAxes to file.
Log & log()
Definition: Log.hh:424
void write_prim(const xtal::BasicStructure &prim, fs::path filename, COORD_TYPE mode, bool include_va=false)
Write prim.json to file.
Eigen::Matrix3l default_nlist_weight_matrix(xtal::BasicStructure const &prim, double tol)
const COORD_TYPE FRAC
Definition: enum.hh:8
void build_project(ProjectSettings const &project_settings, Structure const &prim)
void write_symgroup(SymGroup const &grp, jsonParser &json)
fs::path find_casmroot(const fs::path &cwd)
ProjectSettings make_default_project_settings(xtal::BasicStructure const &prim, std::string project_name)
ClexDescription default_configuration_clex()
Matrix< long int, 3, 3 > Matrix3l
Definition: eigen.hh:12
DirectoryStructure const & dir
Definition: settings.cc:136
ProjectSettings & set
Definition: settings.cc:137