CASM  1.1.0
A Clusters Approach to Statistical Mechanics
HamiltonianModules_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_HamiltonianModules_impl
2 #define CASM_HamiltonianModules_impl
3 
4 #include <boost/filesystem.hpp>
5 
10 
11 namespace CASM {
13 template <typename DoFDictInserter, typename RuntimeLibInserter>
14 std::pair<DoFDictInserter, RuntimeLibInserter> load_dof_plugins(
15  const ProjectSettings &set, DoFDictInserter dict_it,
16  RuntimeLibInserter lib_it) {
17  typedef DoFType::Traits *traits_ptr;
18  typedef traits_ptr(signature)();
19 
20  const DirectoryStructure &dir = set.dir();
21 
22  if (dir.root_dir().empty()) {
23  return std::make_pair(dict_it, lib_it);
24  }
25 
26  if (fs::is_directory(dir.dof_plugins())) {
27  // loop over custom query files *.cc
28  for (auto &entry : boost::make_iterator_range(
29  fs::directory_iterator(dir.dof_plugins()), {})) {
30  fs::path p = entry.path();
31  std::string p_s = p.string();
32  auto p_size = p_s.size();
33 
34  if (fs::is_regular_file(p) &&
35  p_s.compare(p_size - 3, p_size, ".cc") == 0) {
36  fs::path f = p.filename();
37  std::string f_s = f.string();
38  auto f_size = f_s.size();
39 
40  std::string msg = "Compiling new custom DoFTraits for DoF: " +
41  f_s.substr(0, f_size - 3);
42 
43  auto lib_ptr = log_make_shared_runtime_lib(
44  p_s.substr(0, p_size - 3),
46  set.so_options() + " -lcasm ", msg);
47 
48  auto make_dof = lib_ptr->template get_function<signature>(
49  "make_" + f_s.substr(0, f_size - 3) + "_dof");
50 
51  std::unique_ptr<DoFType::Traits> ptr(make_dof());
52 
53  // will clone on insert
54  *dict_it++ = *ptr;
55  *lib_it++ = std::make_pair(ptr->name(), lib_ptr);
56  }
57  }
58  }
59 
60  return std::make_pair(dict_it, lib_it);
61 }
62 
64 template <typename SymRepBuilderDictInserter, typename RuntimeLibInserter>
65 std::pair<SymRepBuilderDictInserter, RuntimeLibInserter>
67  SymRepBuilderDictInserter dict_it,
68  RuntimeLibInserter lib_it) {
69  typedef SymRepBuilderInterface *bldr_ptr;
70  typedef bldr_ptr(signature)();
71 
72  const DirectoryStructure &dir = set.dir();
73 
74  if (dir.root_dir().empty()) {
75  return std::make_pair(dict_it, lib_it);
76  }
77 
78  if (fs::is_directory(dir.symrep_builder_plugins())) {
79  // loop over custom query files *.cc
80  for (auto &entry : boost::make_iterator_range(
81  fs::directory_iterator(dir.symrep_builder_plugins()), {})) {
82  fs::path p = entry.path();
83  std::string p_s = p.string();
84  auto p_size = p_s.size();
85 
86  if (fs::is_regular_file(p) &&
87  p_s.compare(p_size - 3, p_size, ".cc") == 0) {
88  fs::path f = p.filename();
89  std::string f_s = f.string();
90  auto f_size = f_s.size();
91 
92  std::string msg = "Compiling new custom SymRepBuilderInterface: " +
93  f_s.substr(0, f_size - 3);
94 
95  // '-L$CASM_PREFIX/.libs' is a hack so 'make check' works
96  auto lib_ptr = log_make_shared_runtime_lib(
97  p_s.substr(0, p_size - 3),
98  set.compile_options() + " " +
100  set.so_options() + " -lcasm ", msg);
101 
102  auto make_traits = lib_ptr->template get_function<signature>(
103  "make_" + f_s.substr(0, f_size - 3) + "_symrep_builder");
104 
105  std::unique_ptr<SymRepBuilderInterface> ptr(make_traits());
106  // will clone on insert
107  *dict_it++ = *ptr;
108  *lib_it++ = std::make_pair(ptr->name(), lib_ptr);
109  }
110  }
111  }
112 
113  return std::make_pair(dict_it, lib_it);
114 }
115 } // namespace CASM
116 
117 #endif
Specification of CASM project directory structure.
fs::path root_dir() const
Return casm project directory path.
fs::path symrep_builder_plugins() const
Return SymrepBuilder plugin dir.
fs::path dof_plugins() const
Return DoF plugin dir.
Collection of all the traits specific to a DoF type.
Definition: DoFTraits.hh:59
DirectoryStructure const & dir() const
Access DirectoryStructure object. Throw if not set.
std::string compile_options() const
std::string so_options() const
Abstract base class that provides interface for converting cartesian isometry to specialized transfor...
Main CASM namespace.
Definition: APICommand.hh:8
std::shared_ptr< RuntimeLibrary > log_make_shared_runtime_lib(std::string filename_base, std::string compile_options, std::string so_options, std::string compile_msg)
Make shared_ptr<RuntimeLibrary>, logging progress and errors.
std::string include_path(const fs::path &dir)
std::pair< SymRepBuilderDictInserter, RuntimeLibInserter > load_symrep_builder_plugins(const ProjectSettings &set, SymRepBuilderDictInserter dict_it, RuntimeLibInserter lib_it)
Load SymRepBuilder plugins from a CASM project.
std::pair< DoFDictInserter, RuntimeLibInserter > load_dof_plugins(const ProjectSettings &set, DoFDictInserter dict_it, RuntimeLibInserter lib_it)
Load DoF plugins from a CASM project.
DirectoryStructure const & dir
Definition: settings.cc:136
ProjectSettings & set
Definition: settings.cc:137