CASM  1.1.0
A Clusters Approach to Statistical Mechanics
StrucMapCalculatorInterface.hh
Go to the documentation of this file.
1 #ifndef CASM_StrucMapCalculatorInterface
2 #define CASM_StrucMapCalculatorInterface
3 
4 #include <iostream>
5 #include <unordered_set>
6 #include <vector>
7 
13 #include "casm/misc/CASM_math.hh"
14 
15 namespace CASM {
16 namespace xtal {
17 class SimpleStructure;
18 
19 // In this file:
20 struct MappingNode;
21 class StrucMapCalculatorInterface;
22 
23 namespace StrucMapping {
24 
25 // Denotes (name, number composition) of any species whose number-composition is
26 // fixed for the parent primitive cell
27 using FixedSpecies = std::map<std::string, Index>;
28 
29 // List of species allowed at each site of primitive
30 using AllowedSpecies = std::vector<std::vector<std::string>>;
31 
32 } // namespace StrucMapping
33 
35  public:
37  SimpleStructure _parent,
38  SymOpVector const &_factor_group = {SymOp::identity()},
39  SimpleStructure::SpeciesMode _species_mode =
40  SimpleStructure::SpeciesMode::ATOM,
41  StrucMapping::AllowedSpecies allowed_species = {})
42  : m_parent(std::move(_parent)), m_species_mode(_species_mode) {
43  this->_set_sym_info(_factor_group);
44 
45  if (allowed_species.empty()) {
46  auto const &p_info(this->struc_info(parent()));
47  allowed_species.resize(p_info.size());
48  for (Index i = 0; i < p_info.size(); ++i) {
49  allowed_species[i].push_back(p_info.names[i]);
50  }
51  }
52  _set_allowed_species(allowed_species);
53  }
54 
55  SimpleStructure::Info const &struc_info(SimpleStructure const &_struc) const {
56  return _struc.info(m_species_mode);
57  }
58 
60  return _struc.info(m_species_mode);
61  }
62 
63  SimpleStructure const &parent() const { return m_parent; }
64 
66  double xtal_tol() const { return TOL; }
67 
70  SymOpVector const &point_group() const { return m_point_group; }
71 
73  std::vector<Eigen::Vector3d> const &internal_translations() const {
75  }
76 
77  std::unordered_set<Index> const &va_allowed() const { return m_va_allowed; }
78 
80  return m_fixed_species;
81  }
82 
85  const std::vector<Eigen::MatrixXd> &_sym_invariant_displacement_modes) {
86  m_sym_invariant_displacement_modes = _sym_invariant_displacement_modes;
87  }
88 
89  const std::vector<Eigen::MatrixXd> &sym_invariant_displacement_modes() const {
91  };
92 
95  Index max_n_va() const { return va_allowed().size(); }
96 
98 
100  virtual std::vector<Eigen::Vector3d> translations(
101  MappingNode const &_node, SimpleStructure const &child_struc) const = 0;
102 
106  MappingNode const &_node, SimpleStructure const &_child_struc) const = 0;
107 
109  virtual void finalize(MappingNode &_node, SimpleStructure const &child_struc,
110  bool const &symmetrize_atomic_cost = false) const = 0;
111 
112  virtual bool populate_cost_mat(MappingNode &_node,
113  SimpleStructure const &child_struc) const = 0;
114 
117  std::unique_ptr<StrucMapCalculatorInterface> clone() const {
118  return std::unique_ptr<StrucMapCalculatorInterface>(this->_clone());
119  }
120 
123  std::unique_ptr<StrucMapCalculatorInterface> quasi_clone(
124  SimpleStructure _parent,
125  SymOpVector const &_factor_group = {SymOp::identity()},
126  SimpleStructure::SpeciesMode _species_mode =
127  SimpleStructure::SpeciesMode::ATOM,
129  return std::unique_ptr<StrucMapCalculatorInterface>(
130  this->_quasi_clone(std::move(_parent), _factor_group, _species_mode,
131  std::move(_allowed_species)));
132  }
133 
134  template <typename ExternSymOpVector>
135  std::unique_ptr<StrucMapCalculatorInterface> quasi_clone(
136  SimpleStructure _parent,
137  ExternSymOpVector const &_factor_group = {SymOp::identity()},
138  SimpleStructure::SpeciesMode _species_mode =
139  SimpleStructure::SpeciesMode::ATOM,
141  return this->quasi_clone(
142  _parent,
144  _species_mode, _allowed_species);
145  }
146 
147  protected:
149  m_allowed_species = std::move(allowed_species);
150 
151  // Analyze allowed_species:
152  for (Index i = 0; i < m_allowed_species.size(); ++i) {
153  for (std::string &sp : m_allowed_species[i]) {
154  if (sp == "Va" || sp == ("VA") || sp == "va") {
155  // Is vacancy
156  sp = "Va";
157  m_va_allowed.insert(i);
158  } else if (m_allowed_species[i].size() > 1) {
159  // Not vacancy, but variable species
160  m_fixed_species[sp] = 0;
161  } else {
162  // potentially fixed species
163  auto it = m_fixed_species.find(sp);
164  if (it == m_fixed_species.end())
165  m_fixed_species[sp] = 1;
166  else if ((it->second) > 0)
167  ++(it->second);
168  }
169  if (!m_max_n_species.count(sp)) m_max_n_species[sp] = 0;
170  ++m_max_n_species[sp];
171  }
172  }
173 
174  for (auto it = m_fixed_species.begin(); it != m_fixed_species.end();) {
175  auto curr = it;
176  ++it;
177  if ((curr->second) == 0) m_fixed_species.erase(curr);
178  }
179  }
180 
184  void _set_sym_info(SymOpVector const &_factor_group) {
185  m_point_group.clear();
186  m_internal_translations.clear();
187 
188  // Internal translations are any translation associated with identity
189  m_point_group.push_back(SymOp::identity());
190 
191  for (SymOp const &op : _factor_group) {
192  if (get_matrix(op).isIdentity(TOL) && !get_time_reversal(op)) {
194  }
196  TOL) ||
198  m_point_group.push_back(op);
199  m_point_group.back().translation.setZero();
200  }
201  }
202  }
203 
205  return m_allowed_species;
206  }
207 
209  return m_fixed_species;
210  }
211 
212  bool _sublat_allows_va(Index b) const { return m_va_allowed.count(b); }
213 
215  std::map<std::string, Index> const &_max_n_species() const {
216  return m_max_n_species;
217  }
218 
219  private:
221 
222  // Point group of parent crystal, must contain at least Identity
224 
225  // internal translations that map parent crystal onto itself, must contain at
226  // least (0,0,0)
227  std::vector<Eigen::Vector3d> m_internal_translations;
228 
230 
232 
234 
236  std::map<std::string, Index> m_max_n_species;
237 
238  std::unordered_set<Index> m_va_allowed;
239 
242  std::vector<Eigen::MatrixXd> m_sym_invariant_displacement_modes;
243 
246  virtual StrucMapCalculatorInterface *_clone() const = 0;
247 
251  SimpleStructure _parent,
252  SymOpVector const &_factor_group = {SymOp::identity()},
253  SimpleStructure::SpeciesMode _species_mode =
254  SimpleStructure::SpeciesMode::ATOM,
256 };
257 } // namespace xtal
258 } // namespace CASM
259 
260 #endif
Representation of a crystal of molecular and/or atomic occupants, and any additional properties....
Info & info(SpeciesMode _mode)
Info of specified context (atomic/molecular)
std::map< std::string, Index > const & _max_n_species() const
maximum allowed number of each species
virtual void finalize(MappingNode &_node, SimpleStructure const &child_struc, bool const &symmetrize_atomic_cost=false) const =0
Calculates final mapping score and sets _node.is_valid.
virtual StrucMapCalculatorInterface * _quasi_clone(SimpleStructure _parent, SymOpVector const &_factor_group={SymOp::identity()}, SimpleStructure::SpeciesMode _species_mode=SimpleStructure::SpeciesMode::ATOM, StrucMapping::AllowedSpecies _allowed_species={}) const =0
Make an exact copy of the calculator (including any initialized members)
void _set_sym_info(SymOpVector const &_factor_group)
Sets point_group and internal_translations by breaking factor group into pure translations and rotati...
StrucMapping::FixedSpecies const & _fixed_species() const
Index max_n_va() const
Return maximum possible number of vacancies in underlying primitive structure.
virtual std::vector< Eigen::Vector3d > translations(MappingNode const &_node, SimpleStructure const &child_struc) const =0
construct list of prospective mapping translations
StrucMapCalculatorInterface(SimpleStructure _parent, SymOpVector const &_factor_group={SymOp::identity()}, SimpleStructure::SpeciesMode _species_mode=SimpleStructure::SpeciesMode::ATOM, StrucMapping::AllowedSpecies allowed_species={})
SimpleStructure::Info & struc_info(SimpleStructure &_struc) const
const std::vector< Eigen::MatrixXd > & sym_invariant_displacement_modes() const
virtual bool populate_cost_mat(MappingNode &_node, SimpleStructure const &child_struc) const =0
std::map< std::string, Index > m_max_n_species
maximum allowed number of each species
virtual StrucMapCalculatorInterface * _clone() const =0
Make an exact copy of the calculator (including any initialized members)
std::vector< Eigen::MatrixXd > m_sym_invariant_displacement_modes
vector of symmetry invariant displacement modes in the parent structure
void set_sym_invariant_displacement_modes(const std::vector< Eigen::MatrixXd > &_sym_invariant_displacement_modes)
Sets the sym_invariant_modes.
std::unique_ptr< StrucMapCalculatorInterface > clone() const
Make an exact copy of the calculator (including any initialized members)
std::vector< Eigen::Vector3d > m_internal_translations
void _set_allowed_species(StrucMapping::AllowedSpecies allowed_species)
StrucMapping::AllowedSpecies const & _allowed_species() const
std::unique_ptr< StrucMapCalculatorInterface > quasi_clone(SimpleStructure _parent, ExternSymOpVector const &_factor_group={SymOp::identity()}, SimpleStructure::SpeciesMode _species_mode=SimpleStructure::SpeciesMode::ATOM, StrucMapping::AllowedSpecies _allowed_species={}) const
SimpleStructure::Info const & struc_info(SimpleStructure const &_struc) const
std::unique_ptr< StrucMapCalculatorInterface > quasi_clone(SimpleStructure _parent, SymOpVector const &_factor_group={SymOp::identity()}, SimpleStructure::SpeciesMode _species_mode=SimpleStructure::SpeciesMode::ATOM, StrucMapping::AllowedSpecies _allowed_species={}) const
Make an exact copy of the calculator (including any initialized members)
SymOpVector const & point_group() const
List of point group operations that map parent onto itself (neglecting internal translation)
std::vector< Eigen::Vector3d > const & internal_translations() const
List of internal translations that map parent onto itself.
StrucMapping::FixedSpecies const & fixed_species() const
double xtal_tol() const
Crystallographic tolerance, for now just return CASM::TOL.
virtual SimpleStructure resolve_setting(MappingNode const &_node, SimpleStructure const &_child_struc) const =0
Creates copy of _child_struc by applying isometry, lattice transformation, translation,...
std::unordered_set< Index > const & va_allowed() const
SpeciesMode
enum to refer to a particular representation of the occupants (atomic or molecular)
std::map< std::string, Index > FixedSpecies
std::vector< std::vector< std::string > > AllowedSpecies
Eigen::Vector3d const & get_translation(MappingNode const &_node)
External accessor for translation, to provide xtal::SymOp adaptability.
bool get_time_reversal(MappingNode const &_node)
External accessor for time_reversal, to provide xtal::SymOp adaptability.
Eigen::Matrix3d const & get_matrix(MappingNode const &_node)
External accessor for isometry, to provide xtal::SymOp adaptability.
std::vector< SymOp > SymOpVector
Main CASM namespace.
Definition: APICommand.hh:8
bool almost_equal(ClusterInvariants const &A, ClusterInvariants const &B, double tol)
Check if ClusterInvariants are equal.
const double TOL
Definition: definitions.hh:30
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Struct to encode all information about the crystal basis Info may describe the basis in a atomic cont...
static SymOp identity()
Definition: SymType.hh:29