CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ConfigMapping.hh
Go to the documentation of this file.
1 #ifndef CONFIGMAPPING_HH
2 #define CONFIGMAPPING_HH
4 #include <vector>
5 namespace CASM {
6  class Supercell;
7  class Lattice;
8  class SymGroup;
9  class PrimClex;
10  class Configuration;
11  class ConfigDoF;
12 
18  class ConfigMapper {
19  public:
21  enum Options {none = 0,
22  rotate = (1u << 0),
23  strict = (1u << 1),
24  robust = (1u << 2)
25  };
26 
29  m_pclex(nullptr),
30  m_lattice_weight(0.5),
32  m_min_va_frac(0.),
33  m_max_va_frac(1.) {
34  }
35 
63  ConfigMapper(PrimClex &_pclex,
64  double _lattice_weight,
65  double _max_volume_change = 0.5,
66  int _options = robust, // this should actually be a bitwise-OR of ConfigMapper::Options
67  double _tol = TOL);
68 
69 
70  PrimClex &primclex() const {
71  return *m_pclex;
72  }
73 
74  void set_primclex(PrimClex &_pclex) {
75  m_pclex = &_pclex;
76  }
77 
78  double lattice_weight() const {
79  return m_lattice_weight;
80  }
81 
82  void set_lattice_weight(double _lw) {
83  m_lattice_weight = max(min(_lw, 1.0), 1e-9);
84  }
85 
86  double min_va_frac() const {
87  return m_min_va_frac;
88  }
89 
90  void set_min_va_frac(double _min_va) {
91  m_min_va_frac = max(_min_va, 0.);
92  }
93 
94  double max_va_frac() const {
95  return m_max_va_frac;
96  }
97 
98  void set_max_va_frac(double _max_va) {
99  m_max_va_frac = min(_max_va, 1.);
100  }
101 
102 
116  bool import_structure_occupation(const fs::path &pos_path,
117  std::string &imported_name,
118  jsonParser &relaxation_properties,
119  std::vector<Index> &best_assignment,
120  Eigen::Matrix3d &cart_op) const;
121 
126  std::string &imported_name,
127  jsonParser &relaxation_properties,
128  std::vector<Index> &best_assignment,
129  Eigen::Matrix3d &cart_op,
130  bool update_struc = false) const;
131 
143  const Configuration *hint_ptr,
144  std::string &imported_name,
145  jsonParser &relaxation_properties,
146  std::vector<Index> &best_assignment,
147  Eigen::Matrix3d &cart_op,
148  bool update_struc = false) const;
149 
150 
180  bool import_structure(const fs::path &pos_path,
181  std::string &imported_name,
182  jsonParser &relaxation_properties,
183  std::vector<Index> &best_assignment,
184  Eigen::Matrix3d &cart_op) const;
185 
188  bool import_structure(const BasicStructure<Site> &_struc,
189  std::string &imported_name,
190  jsonParser &relaxation_properties,
191  std::vector<Index> &best_assignment,
192  Eigen::Matrix3d &cart_op) const;
193 
197  bool struc_to_configdof(const BasicStructure<Site> &_struc,
198  ConfigDoF &mapped_configdof,
199  Lattice &mapped_lat) const;
200 
210  bool struc_to_configdof(const BasicStructure<Site> &_struc,
211  ConfigDoF &mapped_configdof,
212  Lattice &mapped_lat,
213  std::vector<Index> &best_assignment,
214  Eigen::Matrix3d &cart_op,
215  double best_cost = 1e20) const;
216 
217 
227  ConfigDoF &mapped_config_dof,
228  Lattice &mapped_lat,
229  std::vector<Index> &best_assignment,
230  Eigen::Matrix3d &cart_op) const;
231 
232 
243  ConfigDoF &mapped_config_dof,
244  Lattice &mapped_lat,
245  std::vector<Index> &best_assignment,
246  Eigen::Matrix3d &cart_op,
247  double best_cost = 1e20) const;
248 
260  const Lattice &imposed_lat,
261  double &best_cost,
262  ConfigDoF &mapped_configdof,
263  Lattice &mapped_lat,
264  std::vector<Index> &best_assignment,
265  Eigen::Matrix3d &cart_op) const;
266 
267  private:
269  mutable std::map<Index, std::vector<Lattice> > m_superlat_map;
275  double m_tol;
276  std::vector<std::pair<std::string, Index> > m_fixed_components;
277  const std::vector<Lattice> &_lattices_of_vol(Index prim_vol) const;
278  };
279 
280  namespace ConfigMap_impl {
281 
282  // Assignment Problem Routines
283  // Find cost matrix for displacements between ideal crystal and relaxed structure ('rstruc').
284  // Returns false if 'rstruc' is incompatible with 'scel'
285  bool calc_cost_matrix(const Supercell &scel,
286  const BasicStructure<Site> &rstruc,
287  const Coordinate &trans,
288  const Eigen::Matrix3d &metric,
289  Eigen::MatrixXd &cost_matrix);
290 
291  // Assignment Problem Routines
292  // Find cost matrix for displacements between ideal configuration and a relaxed structure ('rstruc').
293  // Returns false if 'rstruc' is incompatible with 'scel'
294  bool calc_cost_matrix(const Configuration &config,
295  const BasicStructure<Site> &rstruc,
296  const Coordinate &trans,
297  const Eigen::Matrix3d &metric,
298  Eigen::MatrixXd &cost_matrix);
299 
300  //\JSB
301 
302 
303 
304  // mapping routine. Return an ideal configuration corresponding to a relaxed structure.
305  // Return false if 'rstruc' is incompatible with supercell (can happen frequently when vacancies are allowed)
306  // Options:
307  // TRANSLATE = true -> rigid-translations are removed. (typically this option should be used, especially if you care about vacancies)
308  //
309  // TRANSLATE = false -> rigid translations are not considered. (less robust but more efficient -- use only if you know rigid translations are small or zero)
310 
311  bool struc_to_configdof(const Supercell &scel,
312  BasicStructure<Site> rstruc,
313  ConfigDoF &config_dof,
314  std::vector<Index> &best_assignment,
315  const bool translate_flag,
316  const double _tol);
317 
320  const BasicStructure<Site> &rstruc,
321  const Eigen::Matrix3d &deformation,
322  ConfigDoF &config_dof,
323  std::vector<Index> &best_assignment,
324  const bool translate_flag,
325  const double _tol);
326 
327  bool struc_to_configdof(const Configuration &config,
328  BasicStructure<Site> rstruc,
329  ConfigDoF &config_dof,
330  std::vector<Index> &best_assignment,
331  const bool translate_flag,
332  const double _tol);
333 
336  const BasicStructure<Site> &rstruc,
337  const Eigen::Matrix3d &deformation,
338  ConfigDoF &config_dof,
339  std::vector<Index> &best_assignment,
340  const bool translate_flag,
341  const double _tol);
342 
343 
344  }
345 
346  namespace ConfigMapping {
349  double strain_cost(const Lattice &relaxed_lat, const ConfigDoF &_dof, Index Nsites);
350 
353  double basis_cost(const ConfigDoF &_dof, Index Nsites);
354 
355 
357  const Lattice &relaxed_lat,
358  const SymGroup &sym_group,
359  Eigen::Matrix3d &trans_mat,
360  Eigen::Matrix3d &deformation,
361  double &best_cost,
362  Index min_vol,
363  Index max_vol,
364  double _tol);
365 
367  const Lattice &relaxed_lat,
368  const SymGroup &sym_group,
369  Eigen::Matrix3d &trans_mat,
370  Eigen::Matrix3d &deformation,
371  double &best_cost,
372  const std::vector<Lattice> &from_range,
373  double _tol);
374 
375 
376  }
377 
378 
379 }
380 
381 #endif
Eigen::MatrixXd MatrixXd
bool deformed_struc_to_configdof_of_lattice(const BasicStructure< Site > &struc, const Lattice &imposed_lat, double &best_cost, ConfigDoF &mapped_configdof, Lattice &mapped_lat, std::vector< Index > &best_assignment, Eigen::Matrix3d &cart_op) const
Low-level routine to map a structure onto a ConfigDof assuming a specific Lattice, without assuming structure is ideal Will only identify mappings better than best_cost, and best_cost is updated to reflect cost of best mapping identified.
ConfigMapper(NullInitializer)
Default construction not allowed – this constructor provides an override.
bool struc_to_configdof(const BasicStructure< Site > &_struc, ConfigDoF &mapped_configdof, Lattice &mapped_lat) const
Low-level routine to map a structure onto a ConfigDof.
double max_va_frac() const
const std::vector< Lattice > & _lattices_of_vol(Index prim_vol) const
bool import_structure(const fs::path &pos_path, std::string &imported_name, jsonParser &relaxation_properties, std::vector< Index > &best_assignment, Eigen::Matrix3d &cart_op) const
imports structure specified by 'pos_path' into primclex() by finding optimal mapping unlike import_st...
bool preconditioned_struc_to_configdof(const Configuration &config, const BasicStructure< Site > &rstruc, const Eigen::Matrix3d &deformation, ConfigDoF &config_dof, std::vector< Index > &best_assignment, const bool translate_flag, const double _tol)
Same as struc_to_configdof, except 'rstruc' is de-rotated and de-strained. Any deformation is instead...
Main CASM namespace.
Definition: complete.cpp:8
bool deformed_struc_to_configdof(const BasicStructure< Site > &_struc, ConfigDoF &mapped_config_dof, Lattice &mapped_lat, std::vector< Index > &best_assignment, Eigen::Matrix3d &cart_op, double best_cost=1e20) const
Low-level routine to map a structure onto a ConfigDof. Does not assume structure is ideal...
const double TOL
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:37
bool ideal_struc_to_configdof(const BasicStructure< Site > &struc, ConfigDoF &mapped_config_dof, Lattice &mapped_lat, std::vector< Index > &best_assignment, Eigen::Matrix3d &cart_op) const
Low-level routine to map a structure onto a ConfigDof if it is known to be ideal. ...
PrimClex & primclex() const
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:33
Represents cartesian and fractional coordinates.
Definition: Coordinate.hh:34
bool calc_cost_matrix(const Configuration &config, const BasicStructure< Site > &rstruc, const Coordinate &trans, const Eigen::Matrix3d &metric, Eigen::MatrixXd &cost_matrix)
void set_min_va_frac(double _min_va)
EigenIndex Index
For long integer indexing:
std::map< Index, std::vector< Lattice > > m_superlat_map
A container class for the different degrees of freedom a Configuration might have.
Definition: ConfigDoF.hh:27
double lattice_weight() const
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
Lattice find_nearest_super_lattice(const Lattice &prim_lat, const Lattice &relaxed_lat, const SymGroup &sym_group, Eigen::Matrix3d &trans_mat, Eigen::Matrix3d &deformation, double &best_cost, const std::vector< Lattice > &from_range, double _tol)
T max(const T &A, const T &B)
Definition: CASM_math.hh:32
T min(const T &A, const T &B)
Definition: CASM_math.hh:25
void set_max_va_frac(double _max_va)
Eigen::Matrix3d Matrix3d
double basis_cost(const ConfigDoF &_dof, Index Nsites)
Calculate the basis cost function of a ConfigDoF as the mean-square displacement of its atoms...
double min_va_frac() const
void set_lattice_weight(double _lw)
std::vector< std::pair< std::string, Index > > m_fixed_components
void set_primclex(PrimClex &_pclex)
A Configuration represents the values of all degrees of freedom in a Supercell.
bool import_structure_occupation(const fs::path &pos_path, std::string &imported_name, jsonParser &relaxation_properties, std::vector< Index > &best_assignment, Eigen::Matrix3d &cart_op) const
imports structure specified by 'pos_path' into primclex() by finding optimal mapping and then setting...
double strain_cost(const Lattice &relaxed_lat, const ConfigDoF &_dof, Index Nsites)
Calculate the strain cost function of a ConfigDoF using LatticeMap::calc_strain_cost() ...