CASM  1.1.0
A Clusters Approach to Statistical Mechanics
DatabaseTypes.cc
Go to the documentation of this file.
1 #include <boost/range/iterator_range.hpp>
2 
5 
6 namespace CASM {
7 
8 namespace DB {
9 namespace {
10 
11 // --- helpers -------------------------------------
12 
13 struct insert_name {
14  insert_name(std::set<std::string> &_s) : s(_s) {}
15  std::set<std::string> &s;
16  template <typename T>
17  void eval() {
18  s.insert(traits<T>::name);
19  }
20 };
21 
22 struct insert_short_name {
23  insert_short_name(std::set<std::string> &_s) : s(_s) {}
24  std::set<std::string> &s;
25  template <typename T>
26  void eval() {
27  s.insert(traits<T>::short_name);
28  }
29 };
30 
31 struct ConfigCountImplBase {
32  ConfigCountImplBase(std::string _scelname, const PrimClex &_primclex)
33  : count(0), scelname(_scelname), primclex(_primclex) {}
34 
36  std::string scelname;
37  const PrimClex &primclex;
38 };
39 
40 struct ConfigCountImpl : public ConfigCountImplBase {
41  using ConfigCountImplBase::ConfigCountImplBase;
42 
43  template <typename T>
44  void eval() {
45  count += primclex.db<T>().scel_range_size(scelname);
46  }
47 };
48 
49 struct ConfigCalculatedCountImpl : public ConfigCountImplBase {
50  using ConfigCountImplBase::ConfigCountImplBase;
51 
52  template <typename T>
53  void eval() {
54  for (const auto &config : primclex.db<T>().scel_range(scelname)) {
55  if (is_calculated(config)) {
56  count += 1;
57  }
58  }
59  }
60 };
61 
62 struct ConfigDataCountImpl : public ConfigCountImplBase {
63  using ConfigCountImplBase::ConfigCountImplBase;
64 
65  template <typename T>
66  void eval() {
67  ConfigData data(primclex, TypeTag<T>());
68  auto it = primclex.db<T>().scel_range(scelname).begin();
69  auto end = primclex.db<T>().scel_range(scelname).end();
70  for (; it != end; ++it) {
71  if (data.has_existing_data_or_files(it.name())) {
72  count += 1;
73  }
74  }
75  }
76 };
77 
78 } // namespace
79 
80 const std::set<std::string> &types() {
81  static std::set<std::string> _types;
82  if (!_types.size()) {
83  for_each_type(insert_name(_types));
84  }
85  return _types;
86 };
87 
88 const std::set<std::string> &types_short() {
89  static std::set<std::string> _types_short;
90  if (!_types_short.size()) {
91  for_each_type(insert_short_name(_types_short));
92  }
93  return _types_short;
94 };
95 
96 const std::set<std::string> &config_types() {
97  static std::set<std::string> _config_types;
98  if (!_config_types.size()) {
99  for_each_config_type(insert_name(_config_types));
100  }
101  return _config_types;
102 };
103 
104 const std::set<std::string> &config_types_short() {
105  static std::set<std::string> _config_types_short;
106  if (!_config_types_short.size()) {
107  for_each_config_type(insert_short_name(_config_types_short));
108  }
109  return _config_types_short;
110 };
111 
114  ConfigCountImpl f(scelname, primclex);
115  if (primclex.db<Supercell>().count(scelname)) {
117  }
118  return f.count;
119 }
120 
122 Index config_count(std::string configtype, std::string scelname,
123  const PrimClex &primclex) {
124  ConfigCountImpl f(scelname, primclex);
125  if (primclex.db<Supercell>().count(scelname)) {
126  for_config_type_short(configtype, f);
127  }
128  return f.count;
129 }
130 
133  ConfigCalculatedCountImpl f(scelname, primclex);
134  if (primclex.db<Supercell>().count(scelname)) {
136  }
137  return f.count;
138 }
139 
141 Index config_calculated_count(std::string configtype, std::string scelname,
142  const PrimClex &primclex) {
143  ConfigCalculatedCountImpl f(scelname, primclex);
144  if (primclex.db<Supercell>().count(scelname)) {
145  for_config_type_short(configtype, f);
146  }
147  return f.count;
148 }
149 
152  ConfigDataCountImpl f(scelname, primclex);
153  if (primclex.db<Supercell>().count(scelname)) {
155  }
156  return f.count;
157 }
158 
160 Index config_data_count(std::string configtype, std::string scelname,
161  const PrimClex &primclex) {
162  ConfigDataCountImpl f(scelname, primclex);
163  if (primclex.db<Supercell>().count(scelname)) {
164  for_config_type_short(configtype, f);
165  }
166  return f.count;
167 }
168 
169 } // namespace DB
170 } // namespace CASM
const PrimClex & primclex
std::set< std::string > & s
Index count
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:55
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:51
std::string scelname(const Structure &prim, const Lattice &superlat)
Make supercell name name [deprecated].
Definition: Supercell.cc:497
GenericDatumFormatter< std::string, ConfigEnumDataType > name()
ConfigIO::GenericConfigFormatter< jsonParser > config()
Definition: ConfigIO.cc:777
Index config_count(std::string scelname, const PrimClex &primclex)
Total number of configs of all types in a supercell.
const std::set< std::string > & types()
std::set of all QueryTraits<DataObject>::name
Index config_data_count(std::string scelname, const PrimClex &primclex)
Total number of configs w/ data or files of all types in a supercell.
const std::set< std::string > & config_types()
std::set of all QueryTraits<ConfigType>::name
void for_config_type_short(std::string short_name, F f)
void for_each_type(F f)
const std::set< std::string > & types_short()
std::set of all QueryTraits<DataObject>::short_name
const std::set< std::string > & config_types_short()
std::set of all QueryTraits<ConfigType>::short_name
void for_each_config_type(F f)
Index config_calculated_count(std::string scelname, const PrimClex &primclex)
Total number of calculated configs of all types in a supercell.
Main CASM namespace.
Definition: APICommand.hh:8
bool is_calculated(const ConfigType &config, std::string calctype="")
Return true if all required properties have been been calculated for the configuration.
Definition: Calculable.cc:137
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39