CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ConfigMapping.hh
Go to the documentation of this file.
1 #ifndef CASM_ConfigMapping
2 #define CASM_ConfigMapping
3 
9 #include "casm/misc/CASM_math.hh"
10 
11 namespace CASM {
12 namespace xtal {
13 class Lattice;
14 class Site;
15 class BasicStructure;
16 struct MappingNode;
17 class SimpleStructure;
18 class SimpleStrucMapCalculator;
19 class StrucMapper;
20 } // namespace xtal
21 using xtal::BasicStructure;
22 using xtal::Lattice;
23 using xtal::MappingNode;
24 using xtal::SimpleStrucMapCalculator;
25 using xtal::SimpleStructure;
26 using xtal::Site;
27 using xtal::StrucMapper;
28 
29 class Supercell;
30 class PermuteIterator;
31 class PrimClex;
32 class Configuration;
33 class ConfigDoF;
34 class SupercellSymInfo;
35 
36 namespace ConfigMapping {
37 
41 
42 struct Settings {
43  Settings(double _lattice_weight = 0.5, bool _ideal = false,
44  bool _strict = false, bool _robust = false,
45  bool _primitive_only = false, bool _fix_volume = false,
46  bool _fix_lattice = false, Index _k_best = 1,
47  std::vector<std::string> _forced_lattices = {},
48  std::string _filter = "", double _cost_tol = CASM::TOL,
49  double _min_va_frac = 0., double _max_va_frac = 0.5,
50  double _max_vol_change = 0.3)
51  : lattice_weight(_lattice_weight),
52  ideal(_ideal),
53  strict(_strict),
54  robust(_robust),
55  primitive_only(_primitive_only),
56  fix_volume(_fix_volume),
57  fix_lattice(_fix_lattice),
58  k_best(_k_best),
59  forced_lattices(_forced_lattices),
60  filter(_filter),
61  cost_tol(_cost_tol),
62  min_va_frac(_min_va_frac),
63  max_va_frac(_max_va_frac),
64  max_vol_change(_max_vol_change) {}
65 
66  int options() const {
67  int opt = 0;
68  if (robust) opt |= StrucMapper::robust;
69  return opt;
70  }
71 
72  void set_default() { *this = Settings(); }
73 
78 
81  bool ideal;
82 
86  bool strict;
87 
90  bool robust;
91 
96 
99  bool fix_volume;
100 
104 
108 
111  std::vector<std::string> forced_lattices;
112 
115  std::string filter;
116 
118  double cost_tol;
119 
122  double min_va_frac;
123 
126  double max_va_frac;
127 
132 };
133 } // namespace ConfigMapping
134 
137 MappingNode copy_apply(PermuteIterator const &_it, MappingNode const &_node,
138  bool transform_cost_mat = true);
139 
145 std::pair<ConfigDoF, std::set<std::string> > to_configdof(
146  SimpleStructure const &_child_struc, Supercell const &_scel);
147 
149  public:
151  std::vector<xtal::SymOp> const &symgroup = {},
152  SimpleStructure::SpeciesMode _species_mode =
153  SimpleStructure::SpeciesMode::ATOM);
154 
155  private:
159  return new PrimStrucMapCalculator(*this);
160  }
161 
163 };
164 
176  enum class HintStatus {
177  None,
178  Derivative,
179  Equivalent,
180  Identical,
181  NewOcc,
182  NewScel
183  };
184 
185  struct Individual {
186  Individual(Configuration _config, SimpleStructure _resolved_struc,
187  std::set<std::string> _dof_managed_properties,
188  HintStatus _hint_status = HintStatus::None,
189  double _hint_cost = xtal::StrucMapping::big_inf())
190  : config(std::move(_config)),
191  resolved_struc(std::move(_resolved_struc)),
192  dof_managed_properties(std::move(_dof_managed_properties)),
193  hint_status(_hint_status),
194  hint_cost(_hint_cost) {}
195 
197 
198  // Child structure, converted to setting of reference structure (i.e., prim)
199  // It is equivalent to initial child structure, but the following
200  // transformations have been performed:
201  // - Atoms converted to molecules and ordered as in reference structure
202  // - Vacancies explicitly inserted, if any were inferred from mapping
203  // - Sites are translated such that average displacement of child sites
204  // relative to parent sites is 0
205  // - Lattice and coordinates rotated
206  // - Integer combinations of child lattice vectors (Lc) to match parent
207  // lattice vectors (Lp) such that
208  // Lc = U * Lp
209  // where U is symmetric right stretch tensor
210  // - Permutation and rotation also applied to all properties of
211  // resolved_struc
213 
214  // list of properties that are handled by DoFs and are thus not considered
215  // properties
216  std::set<std::string> dof_managed_properties;
217 
219  double hint_cost;
220  };
221 
223 
224  bool success() const { return !maps.empty(); }
225 
226  Index n_optimal(double tol = TOL) const;
227 
231 
233  std::map<MappingNode, Individual> maps;
234 
236  std::string fail_msg;
237 };
238 
247  public:
249 
288  ConfigMapper(PrimClex const &_pclex, ConfigMapping::Settings const &_settings,
289  double _tol = -1.);
290 
291  const PrimClex &primclex() const { return *m_pclex; }
292 
293  ConfigMapping::Settings const &settings() const { return m_settings; }
294 
295  void set_primclex(const PrimClex &_pclex) { m_pclex = &_pclex; }
296 
297  StrucMapper const &struc_mapper() const { return m_struc_mapper; }
298 
299  void add_allowed_lattices(std::vector<std::string> const &_lattice_names);
300 
301  void clear_allowed_lattices();
302 
303  // STEPS:
304  // 0) [If Hint] Do SimpleStructure -> SimpleStructure(Config) mapping =>
305  // HintMapping (Default, HintMapping.cost=inf()) 1) If HintMapping.cost>tol
306  // Do SimpleStructure -> PrimClex mapping => ClexMapping (Default,
307  // ClexMapping.cost=inf()) 2) If HintMapping.cost<ClexMapping.cost, use
308  // HintMapping, else use ClexMapping => BestMapping 3) Convert BestMapping
309  // to ConfigDoF
310  // [a] - BestMapping attributes that define ConfigDoF are mapped 'DoF',
311  // all others mapped 'property' [b] - 'property' attributes are subsumed
312  // into 'relaxation_properties' object
313  // 4) Construct Configuration as ConfigDoF + relation_properties
314 
327  Configuration const *hint_ptr = nullptr,
328  std::vector<DoFKey> const &_hint_dofs = {
329  "occ"}) const;
330 
331  ConfigMapperResult import_structure(SimpleStructure const &_struc, Index k,
332  Configuration const *hint_ptr = nullptr,
333  std::vector<DoFKey> const &_hint_dofs = {
334  "occ"}) const;
335 
336  private:
340 
342 };
343 
344 } // namespace CASM
345 
346 #endif
ConfigMapper(PrimClex const &_pclex, ConfigMapping::Settings const &_settings, double _tol=-1.)
Construct and initialize a ConfigMapper.
StrucMapper const & struc_mapper() const
ConfigMapperResult import_structure(SimpleStructure const &_struc, Configuration const *hint_ptr=nullptr, std::vector< DoFKey > const &_hint_dofs={ "occ"}) const
imports structure specified by '_struc' into primclex()
ConfigMapping::Settings m_settings
const PrimClex & primclex() const
void set_primclex(const PrimClex &_pclex)
const PrimClex * m_pclex
ConfigMapping::Settings const & settings() const
StrucMapper m_struc_mapper
Maps the supercell volume to a vector of Lattices with that volume.
void add_allowed_lattices(std::vector< std::string > const &_lattice_names)
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:55
PrimStrucMapCalculator(BasicStructure const &_prim, std::vector< xtal::SymOp > const &symgroup={}, SimpleStructure::SpeciesMode _species_mode=SimpleStructure::SpeciesMode::ATOM)
StrucMapCalculatorInterface * _clone() const override
Make an exact copy of the calculator (including any initialized members)
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:51
BasicStructure specifies the lattice and atomic basis of a crystal.
Representation of a crystal of molecular and/or atomic occupants, and any additional properties....
StrucMapCalculatorInterface(SimpleStructure _parent, SymOpVector const &_factor_group={SymOp::identity()}, SimpleStructure::SpeciesMode _species_mode=SimpleStructure::SpeciesMode::ATOM, StrucMapping::AllowedSpecies allowed_species={})
SpeciesMode
enum to refer to a particular representation of the occupants (atomic or molecular)
double big_inf()
Very large value used to denote invalid or impossible mapping.
Definition: StrucMapping.hh:35
Main CASM namespace.
Definition: APICommand.hh:8
MappingNode copy_apply(PermuteIterator const &_it, MappingNode const &_node, bool transform_cost_mat=true)
Reorders the permutation and compounds the spatial isometry (rotation.
std::pair< ConfigDoF, std::set< std::string > > to_configdof(SimpleStructure const &_child_struc, Supercell const &_scel)
Initializes configdof of Supercell '_scel' corresponding to an idealized child structure (encoded by ...
const double TOL
Definition: definitions.hh:30
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Definition: stream_io.hh:24
Individual(Configuration _config, SimpleStructure _resolved_struc, std::set< std::string > _dof_managed_properties, HintStatus _hint_status=HintStatus::None, double _hint_cost=xtal::StrucMapping::big_inf())
std::set< std::string > dof_managed_properties
Data structure holding results of ConfigMapper algorithm.
std::string fail_msg
Failure message if could not map to prim.
std::map< MappingNode, Individual > maps
The configurations that the input structure mapped onto.
SimpleStructure structure
Index n_optimal(double tol=TOL) const
Struct with optional parameters for Config Mapping Specifies default parameters for all values,...
Settings(double _lattice_weight=0.5, bool _ideal=false, bool _strict=false, bool _robust=false, bool _primitive_only=false, bool _fix_volume=false, bool _fix_lattice=false, Index _k_best=1, std::vector< std::string > _forced_lattices={}, std::string _filter="", double _cost_tol=CASM::TOL, double _min_va_frac=0., double _max_va_frac=0.5, double _max_vol_change=0.3)
double cost_tol
Tolerance used to determine if two mappings have identical cost.
std::vector< std::string > forced_lattices