CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ClusterSpecs.cc
Go to the documentation of this file.
11 
12 namespace CASM {
13 
14 std::string ClusterSpecs::name() const { return this->_name(); }
15 
17  return this->_periodicity_type();
18 }
19 
21  IntegralClusterVec const &generating_elements) const {
22  return this->_make_periodic_orbits(generating_elements);
23 }
24 
26  std::ostream &status) const {
27  return this->_make_periodic_orbits(status);
28 }
29 
31  IntegralClusterVec const &generating_elements) const {
32  return this->_make_local_orbits(generating_elements);
33 }
34 
36  std::ostream &status) const {
37  return this->_make_local_orbits(status);
38 }
39 
41  IntegralClusterVec const &generating_elements) const {
42  throw std::runtime_error(
43  "Error: make_periodic_orbits from generating elements not implemented "
44  "for '" +
45  name() + "'");
46 }
47 
49  std::ostream &status) const {
50  throw std::runtime_error("Error: make_periodic_orbits not implemented for '" +
51  name() + "'");
52 }
53 
55  IntegralClusterVec const &generating_elements) const {
56  throw std::runtime_error(
57  "Error: make_local_orbits from generating elements not implemented for "
58  "'" +
59  name() + "'");
60 }
61 
63  std::ostream &status) const {
64  throw std::runtime_error("Error: make_local_orbits not implemented for '" +
65  name() + "'");
66 }
67 
69  "periodic_max_length";
70 
72  std::shared_ptr<Structure const> _shared_prim,
73  SymGroup const &_generating_group, SiteFilterFunction const &_site_filter,
74  std::vector<double> const &_max_length,
75  std::vector<IntegralClusterOrbitGenerator> const &_custom_generators)
76  : shared_prim(_shared_prim),
77  generating_group(_generating_group),
78  sym_compare(shared_prim, shared_prim->lattice().tol()),
79  site_filter(_site_filter),
80  max_length(_max_length),
81  custom_generators(_custom_generators) {
82  if (max_length.size() == 0) {
84  "Error in PeriodicMaxLengthClusterSpecs: max_length.size() == 0 (must "
85  "be greater than 0).");
86  }
87 }
88 
89 std::string PeriodicMaxLengthClusterSpecs::_name() const { return method_name; }
90 
92  const {
94 };
95 
98  IntegralClusterVec const &generating_elements) const {
99  return generate_orbits(generating_elements, generating_group, sym_compare);
100 }
101 
104  std::ostream &status) const {
105  typedef PrimPeriodicOrbit<IntegralCluster> orbit_type;
106  std::vector<OrbitBranchSpecs<orbit_type> > specs;
107 
108  for (int branch = 0; branch < max_length.size(); ++branch) {
109  std::vector<xtal::UnitCellCoord> candidate_sites;
111  if (branch == 0) {
112  f = empty_neighborhood();
113  } else if (branch == 1) {
114  f = origin_neighborhood();
115  } else {
116  f = max_length_neighborhood(max_length[branch]);
117  }
118  candidate_sites = f(*shared_prim, site_filter);
119 
120  ClusterFilterFunction cluster_filter;
121  if (branch <= 1) {
122  cluster_filter = all_clusters_filter();
123  } else {
124  cluster_filter = max_length_cluster_filter(max_length[branch]);
125  }
126 
127  specs.emplace_back(*shared_prim, candidate_sites.begin(),
128  candidate_sites.end(), generating_group, cluster_filter,
129  sym_compare);
130  }
131 
132  // now generate orbits
133  PeriodicOrbitVec orbits;
134  make_orbits(specs.begin(), specs.end(), custom_generators,
135  std::back_inserter(orbits), status);
136  return orbits;
137 }
138 
139 std::string const LocalMaxLengthClusterSpecs::method_name = "local_max_length";
140 
142  std::shared_ptr<Structure const> _shared_prim,
143  SymGroup const &_generating_group, IntegralCluster const &_phenomenal,
144  SiteFilterFunction const &_site_filter,
145  std::vector<double> const &_max_length,
146  std::vector<double> const &_cutoff_radius, bool _include_phenomenal_sites,
147  std::vector<IntegralClusterOrbitGenerator> const &_custom_generators)
148  : shared_prim(_shared_prim),
149  generating_group(_generating_group),
150  sym_compare(shared_prim, shared_prim->lattice().tol()),
151  phenomenal(_phenomenal),
152  site_filter(_site_filter),
153  max_length(_max_length),
154  cutoff_radius(_cutoff_radius),
155  include_phenomenal_sites(_include_phenomenal_sites),
156  custom_generators(_custom_generators) {
157  if (max_length.size() == 0) {
158  throw libcasm_runtime_error(
159  "Error in LocalMaxLengthClusterSpecs: max_length.size() == 0 (must be "
160  "greater than 0).");
161  }
162  if (max_length.size() != cutoff_radius.size()) {
163  throw libcasm_runtime_error(
164  "Error in LocalMaxLengthClusterSpecs: max_length.size() != "
165  "cutoff_radius.size() (must be equal).");
166  }
167 }
168 
169 std::string LocalMaxLengthClusterSpecs::_name() const { return method_name; }
170 
173 };
174 
176  IntegralClusterVec const &generating_elements) const {
177  return generate_orbits(generating_elements, generating_group, sym_compare);
178 }
179 
181  std::ostream &status) const {
182  typedef LocalOrbit<IntegralCluster> orbit_type;
183  std::vector<OrbitBranchSpecs<orbit_type> > specs;
184 
185  for (int branch = 0; branch < max_length.size(); ++branch) {
186  std::vector<xtal::UnitCellCoord> candidate_sites;
188  if (branch == 0) {
189  f = empty_neighborhood();
190  } else {
193  }
194  candidate_sites = f(*shared_prim, site_filter);
195 
196  ClusterFilterFunction cluster_filter;
197  if (branch <= 1) {
198  cluster_filter = all_clusters_filter();
199  } else {
200  cluster_filter = max_length_cluster_filter(max_length[branch]);
201  }
202 
203  specs.emplace_back(*shared_prim, candidate_sites.begin(),
204  candidate_sites.end(), generating_group, cluster_filter,
205  sym_compare);
206  }
207 
208  // now generate orbits
209  LocalOrbitVec orbits;
210  make_orbits(specs.begin(), specs.end(), custom_generators,
211  std::back_inserter(orbits), status);
212  return orbits;
213 }
214 
216  std::string _method_name, std::shared_ptr<Structure const> _shared_prim,
217  SymGroup const &_generating_group, SymCompareType const &_sym_compare,
218  SiteFilterFunction _site_filter,
219  std::vector<ClusterFilterFunction> _cluster_filter,
220  std::vector<CandidateSitesFunction> _candidate_sites,
221  std::vector<IntegralClusterOrbitGenerator> _custom_generators)
222  : shared_prim(_shared_prim),
223  generating_group(_generating_group),
224  sym_compare(_sym_compare),
225  site_filter(_site_filter),
226  cluster_filter(_cluster_filter),
227  candidate_sites(_candidate_sites),
228  custom_generators(_custom_generators),
229  m_method_name(_method_name) {
230  if (candidate_sites.size() == 0) {
231  throw libcasm_runtime_error(
232  "Error in GenericPeriodicClusterSpecs: candidate_sites.size() == 0 "
233  "(must be greater than 0).");
234  }
235 }
236 
237 std::string GenericPeriodicClusterSpecs::_name() const { return m_method_name; }
238 
240  const {
242 }
243 
246  IntegralClusterVec const &generating_elements) const {
247  return generate_orbits(generating_elements, generating_group, sym_compare);
248 }
249 
252  if (cluster_filter.size() != candidate_sites.size()) {
253  throw std::runtime_error(
254  "Error in GenericPeriodicClusterSpecs::_make_periodic_orbits: "
255  "cluster_filter.size() != candidate_sites.size()");
256  }
257  typedef PrimPeriodicOrbit<IntegralCluster> OrbitType;
258  std::vector<OrbitBranchSpecs<OrbitType> > specs;
259 
260  for (int branch = 0; branch < cluster_filter.size(); ++branch) {
261  std::vector<xtal::UnitCellCoord> tmp;
262  tmp = candidate_sites[branch](*shared_prim, site_filter);
263 
264  specs.emplace_back(*shared_prim, tmp.begin(), tmp.end(), generating_group,
265  cluster_filter[branch], sym_compare);
266  }
267 
268  // now generate orbits
269  PeriodicOrbitVec orbits;
270  make_orbits(specs.begin(), specs.end(), custom_generators,
271  std::back_inserter(orbits), status);
272  return orbits;
273 }
274 
276  std::string _method_name, std::shared_ptr<Structure const> _shared_prim,
277  SymGroup const &_generating_group, SymCompareType const &_sym_compare,
278  SiteFilterFunction _site_filter,
279  std::vector<ClusterFilterFunction> _cluster_filter,
280  std::vector<CandidateSitesFunction> _candidate_sites,
281  std::vector<IntegralClusterOrbitGenerator> _custom_generators)
282  : shared_prim(_shared_prim),
283  generating_group(_generating_group),
284  sym_compare(_sym_compare),
285  site_filter(_site_filter),
286  cluster_filter(_cluster_filter),
287  candidate_sites(_candidate_sites),
288  custom_generators(_custom_generators),
289  m_method_name(_method_name) {
290  if (candidate_sites.size() == 0) {
291  throw libcasm_runtime_error(
292  "Error in GenericLocalClusterSpecs: candidate_sites.size() == 0 (must "
293  "be greater than 0).");
294  }
295  if (candidate_sites.size() != cluster_filter.size()) {
296  throw libcasm_runtime_error(
297  "Error in GenericLocalClusterSpecs: candidate_sites.size() != "
298  "cluster_filter.size() (must be equal).");
299  }
300 }
301 
302 std::string GenericLocalClusterSpecs::_name() const { return m_method_name; }
303 
306 }
307 
309  IntegralClusterVec const &generating_elements) const {
310  return generate_orbits(generating_elements, generating_group, sym_compare);
311 }
312 
314  std::ostream &status) const {
315  if (cluster_filter.size() != candidate_sites.size()) {
316  throw std::runtime_error(
317  "Error in GenericLocalClusterSpecs::_make_local_orbits: "
318  "candidate_sites.size() != cluster_filter.size()");
319  }
320  typedef LocalOrbit<IntegralCluster> OrbitType;
321  std::vector<OrbitBranchSpecs<OrbitType> > specs;
322 
323  for (int branch = 0; branch < cluster_filter.size(); ++branch) {
324  std::vector<xtal::UnitCellCoord> tmp;
325  tmp = candidate_sites[branch](*shared_prim, site_filter);
326 
327  specs.emplace_back(*shared_prim, tmp.begin(), tmp.end(), generating_group,
328  cluster_filter[branch], sym_compare);
329  }
330 
331  // now generate orbits
332  LocalOrbitVec orbits;
333  make_orbits(specs.begin(), specs.end(), custom_generators,
334  std::back_inserter(orbits), status);
335  return orbits;
336 }
337 
338 namespace ClusterSpecs_impl {
339 
341  public:
342  DoFSitesFilter(std::vector<DoFKey> const &_dofs) : dofs(_dofs) {}
343 
344  bool operator()(xtal::Site const &site) {
345  if (dofs.empty() &&
346  (site.dof_size() != 0 || site.occupant_dof().size() > 1)) {
347  return true;
348  }
349  for (DoFKey const &dof : dofs) {
350  if (site.has_dof(dof)) {
351  return true;
352  } else if (dof == "occ" && site.occupant_dof().size() > 1) {
353  return true;
354  }
355  }
356  return false;
357  }
358 
359  std::vector<DoFKey> dofs;
360 };
361 
362 class AllClusters {
363  public:
364  bool operator()(IntegralCluster const &clust) { return true; }
365 };
366 
368  public:
369  MaxLengthClusterFilter(double _max_length) : max_length(_max_length) {}
370 
371  bool operator()(IntegralCluster const &clust) {
372  if (clust.size() <= 1) {
373  return true;
374  }
375  ClusterInvariants invariants{clust};
376  return invariants.displacement().back() < max_length;
377  }
378 
379  private:
380  double max_length;
381 };
382 
384  public:
385  std::vector<xtal::UnitCellCoord> operator()(Structure const &prim,
386  SiteFilterFunction site_filter) {
387  return std::vector<xtal::UnitCellCoord>{};
388  }
389 };
390 
392  public:
393  std::vector<xtal::UnitCellCoord> operator()(Structure const &prim,
394  SiteFilterFunction site_filter) {
395  std::vector<xtal::UnitCellCoord> result;
396  for (int i = 0; i < prim.basis().size(); ++i) {
397  if (site_filter(prim.basis()[i])) {
398  result.emplace_back(i, 0, 0, 0);
399  }
400  }
401  return result;
402  }
403 };
404 
406  public:
407  MaxLengthNeighborhood(double _max_length) : max_length(_max_length){};
408 
409  std::vector<xtal::UnitCellCoord> operator()(Structure const &prim,
410  SiteFilterFunction site_filter) {
411  std::vector<xtal::UnitCellCoord> result;
412  double xtal_tol = prim.lattice().tol();
413  neighborhood(prim, max_length, site_filter, std::back_inserter(result),
414  xtal_tol);
415  return result;
416  }
417 
418  private:
419  double max_length;
420 };
421 
422 // class ScelNeighborhood {
423 // public:
424 // ScelNeighborhood(Eigen::Matrix3l const &supercell_matrix):
425 // lattice_points(xtal::make_lattice_points(supercell_matrix)) {}
426 //
427 // std::vector<xtal::UnitCellCoord> operator()(Structure const &prim,
428 // SiteFilterFunction site_filter) {
429 // std::vector<xtal::UnitCellCoord> result;
430 // int b = 0;
431 // for(auto const &site : prim.basis()) {
432 // if(site_filter(site)) {
433 // for(auto const &lattice_point : lattice_points) {
434 // result.emplace_back(b, lattice_point);
435 // }
436 // }
437 // ++b;
438 // }
439 // return result;
440 // }
441 //
442 // private:
443 // std::vector<xtal::UnitCell> lattice_points;
444 // };
445 
449  public:
451  double _cutoff_radius,
452  bool _include_phenomenal_sites)
453  : phenomenal(_phenomenal),
454  cutoff_radius(_cutoff_radius),
455  include_phenomenal_sites(_include_phenomenal_sites){};
456 
457  std::vector<xtal::UnitCellCoord> operator()(Structure const &prim,
458  SiteFilterFunction site_filter) {
459  std::vector<xtal::UnitCellCoord> result;
460  double xtal_tol = prim.lattice().tol();
461  neighborhood(phenomenal, cutoff_radius, site_filter,
462  include_phenomenal_sites, std::back_inserter(result),
463  xtal_tol);
464  return result;
465  }
466 
467  private:
471 };
472 
473 } // namespace ClusterSpecs_impl
474 
476 bool all_sites_filter(xtal::Site const &site) { return true; }
477 
479 bool alloy_sites_filter(xtal::Site const &site) {
480  return site.occupant_dof().size() > 1;
481 }
482 
488 SiteFilterFunction dof_sites_filter(std::vector<DoFKey> const &dofs) {
490 }
491 
495 }
496 
500 }
501 
505 }
506 
510 }
511 
515  return ClusterSpecs_impl::MaxLengthNeighborhood{max_length};
516 }
517 
520  IntegralCluster const &phenomenal, double cutoff_radius,
521  bool include_phenomenal_sites) {
522  return ClusterSpecs_impl::CutoffRadiusNeighborhood{phenomenal, cutoff_radius,
523  include_phenomenal_sites};
524 }
525 
526 } // namespace CASM
std::shared_ptr< Structure const > shared_prim
Template class to be specialized for comparisons with aperiodic symmetry.
Stores cluster invariants: number of sites and site distances.
bool operator()(IntegralCluster const &clust)
CutoffRadiusNeighborhood(IntegralCluster const &_phenomenal, double _cutoff_radius, bool _include_phenomenal_sites)
std::vector< xtal::UnitCellCoord > operator()(Structure const &prim, SiteFilterFunction site_filter)
bool operator()(xtal::Site const &site)
DoFSitesFilter(std::vector< DoFKey > const &_dofs)
std::vector< xtal::UnitCellCoord > operator()(Structure const &prim, SiteFilterFunction site_filter)
bool operator()(IntegralCluster const &clust)
std::vector< xtal::UnitCellCoord > operator()(Structure const &prim, SiteFilterFunction site_filter)
std::vector< xtal::UnitCellCoord > operator()(Structure const &prim, SiteFilterFunction site_filter)
CLUSTER_PERIODICITY_TYPE periodicity_type() const
Definition: ClusterSpecs.cc:16
virtual CLUSTER_PERIODICITY_TYPE _periodicity_type() const =0
std::vector< PrimPeriodicOrbit< IntegralCluster > > PeriodicOrbitVec
Definition: ClusterSpecs.hh:38
std::vector< IntegralCluster > IntegralClusterVec
Definition: ClusterSpecs.hh:37
virtual LocalOrbitVec _make_local_orbits(IntegralClusterVec const &generating_elements) const
Definition: ClusterSpecs.cc:54
std::vector< LocalOrbit< IntegralCluster > > LocalOrbitVec
Definition: ClusterSpecs.hh:39
PeriodicOrbitVec make_periodic_orbits(IntegralClusterVec const &generating_elements) const
Definition: ClusterSpecs.cc:20
std::string name() const
This is the orbit generation method name.
Definition: ClusterSpecs.cc:14
LocalOrbitVec make_local_orbits(IntegralClusterVec const &generating_elements) const
Definition: ClusterSpecs.cc:30
virtual PeriodicOrbitVec _make_periodic_orbits(IntegralClusterVec const &generating_elements) const
Definition: ClusterSpecs.cc:40
virtual std::string _name() const =0
size_type size() const
Number of elements in the cluster.
SymGroup generating_group
The orbit generating group.
std::string _name() const override
SiteFilterFunction site_filter
std::vector< ClusterFilterFunction > cluster_filter
GenericLocalClusterSpecs(std::string _method_name, std::shared_ptr< Structure const > _shared_prim, SymGroup const &_generating_group, SymCompareType const &_sym_compare, SiteFilterFunction _site_filter, std::vector< ClusterFilterFunction > _cluster_filter, std::vector< CandidateSitesFunction > _candidate_sites, std::vector< IntegralClusterOrbitGenerator > _custom_generators)
std::vector< IntegralClusterOrbitGenerator > custom_generators
Specifies particular clusters that should be used to generate orbits.
std::shared_ptr< Structure const > shared_prim
The prim.
LocalOrbitVec _make_local_orbits(IntegralClusterVec const &generating_elements) const override
std::vector< CandidateSitesFunction > candidate_sites
CLUSTER_PERIODICITY_TYPE _periodicity_type() const override
SymCompareType sym_compare
The comparisons used for orbit generation.
SymCompareType sym_compare
The comparisons used for orbit generation.
std::vector< ClusterFilterFunction > cluster_filter
GenericPeriodicClusterSpecs(std::string _method_name, std::shared_ptr< Structure const > _shared_prim, SymGroup const &_generating_group, SymCompareType const &_sym_compare, SiteFilterFunction _site_filter, std::vector< ClusterFilterFunction > _cluster_filter, std::vector< CandidateSitesFunction > _candidate_sites, std::vector< IntegralClusterOrbitGenerator > _custom_generators)
PeriodicOrbitVec _make_periodic_orbits(IntegralClusterVec const &generating_elements) const override
std::shared_ptr< Structure const > shared_prim
The prim.
std::vector< CandidateSitesFunction > candidate_sites
std::string _name() const override
SymGroup generating_group
The orbit generating group.
CLUSTER_PERIODICITY_TYPE _periodicity_type() const override
std::vector< IntegralClusterOrbitGenerator > custom_generators
Specifies particular clusters that should be used to generate orbits.
LocalMaxLengthClusterSpecs(std::shared_ptr< Structure const > _shared_prim, SymGroup const &_generating_group, IntegralCluster const &_phenomenal, SiteFilterFunction const &_site_filter, std::vector< double > const &_max_length, std::vector< double > const &_cutoff_radius, bool _include_phenomenal_sites, std::vector< IntegralClusterOrbitGenerator > const &_custom_generators={})
static std::string const method_name
std::vector< double > max_length
std::vector< IntegralClusterOrbitGenerator > custom_generators
Specifies particular clusters that should be used to generate orbits.
IntegralCluster phenomenal
Phenomenal cluster, used to find local neighborhood.
CLUSTER_PERIODICITY_TYPE _periodicity_type() const override
LocalSymCompare< IntegralCluster > sym_compare
The comparisons used for orbit generation.
std::shared_ptr< Structure const > shared_prim
The prim.
std::string _name() const override
std::vector< double > cutoff_radius
LocalOrbitVec _make_local_orbits(IntegralClusterVec const &generating_elements) const override
An Orbit of Element.
Definition: Orbit.hh:43
PrimPeriodicSymCompare< IntegralCluster > sym_compare
The comparisons used for orbit generation.
static std::string const method_name
PeriodicMaxLengthClusterSpecs(std::shared_ptr< Structure const > _shared_prim, SymGroup const &_generating_group, SiteFilterFunction const &_site_filter, std::vector< double > const &_max_length, std::vector< IntegralClusterOrbitGenerator > const &_custom_generators={})
Constructor.
Definition: ClusterSpecs.cc:71
std::vector< double > max_length
std::string _name() const override
Definition: ClusterSpecs.cc:89
std::shared_ptr< Structure const > shared_prim
The prim.
PeriodicOrbitVec _make_periodic_orbits(IntegralClusterVec const &generating_elements) const override
Definition: ClusterSpecs.cc:97
std::vector< IntegralClusterOrbitGenerator > custom_generators
Specifies particular clusters that should be used to generate orbits.
CLUSTER_PERIODICITY_TYPE _periodicity_type() const override
Definition: ClusterSpecs.cc:91
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:30
const Lattice & lattice() const
Definition: Structure.hh:100
const std::vector< xtal::Site > & basis() const
Definition: Structure.hh:102
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:42
double tol() const
Definition: Lattice.hh:195
Index dof_size() const
Definition: Site.cc:74
bool has_dof(std::string const &_dof_type) const
Definition: Site.cc:90
const std::vector< Molecule > & occupant_dof() const
Definition: Site.cc:68
OutputIterator neighborhood(Structure const &unit, double max_radius, SiteFilterFunction site_filter, OutputIterator result, double xtal_tol)
Output the neighborhood of UnitCellCoord within max_radius of any sites in unit cell.
GenericVectorXdScelFormatter lattice()
Definition: SupercellIO.cc:266
Main CASM namespace.
Definition: APICommand.hh:8
OrbitOutputIterator make_orbits(OrbitBranchSpecsIterator begin, OrbitBranchSpecsIterator end, const std::vector< IntegralClusterOrbitGenerator > &custom_generators, OrbitOutputIterator result, std::ostream &status)
Generate orbits of IntegralCluster using OrbitBranchSpecs.
std::function< bool(xtal::Site)> SiteFilterFunction
std::string DoFKey
Definition: DoFDecl.hh:7
bool alloy_sites_filter(const xtal::Site &site)
Generate clusters using Site with site_occupant.size() > 1.
std::vector< Orbit< SymCompareType > > generate_orbits(std::vector< typename SymCompareType::Element > const &generating_elements, SymGroup const &generating_group, SymCompareType const &sym_compare)
Construct orbits from a vector of generating elements.
bool all_sites_filter(const xtal::Site &site)
Generate clusters using all Site.
std::function< std::vector< xtal::UnitCellCoord >Structure const &, SiteFilterFunction)> CandidateSitesFunction
CandidateSitesFunction origin_neighborhood()
Only sites in the origin unit cell {b, 0, 0, 0}.
ClusterFilterFunction all_clusters_filter()
Accept all clusters.
SiteFilterFunction dof_sites_filter(const std::vector< DoFKey > &dofs={})
Generate clusters using Site with specified DoF.
CandidateSitesFunction empty_neighborhood()
No sites (for null orbit, or global dof only)
CandidateSitesFunction cutoff_radius_neighborhood(IntegralCluster const &phenomenal, double cutoff_radius, bool include_phenomenal_sites=false)
Sites within cutoff_radius distance to any site in the phenomenal cluster.
CandidateSitesFunction max_length_neighborhood(double max_length)
ClusterFilterFunction max_length_cluster_filter(double max_length)
Accept clusters with max pair distance less than max_length.
std::function< bool(IntegralCluster)> ClusterFilterFunction