CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ChemicalReference_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_ChemicalReference_impl
2 #define CASM_ChemicalReference_impl
3 
5 #include "casm/clex/ConfigIO.hh"
7 #include "casm/misc/algorithm.hh"
8 
9 namespace CASM {
10 
13 template <typename RefStateIterator>
15  RefStateIterator begin,
16  RefStateIterator end, double tol)
17  : HyperPlaneReferenceBase(Name, Desc, Eigen::VectorXd::Zero(0),
18  ConfigIO::AtomFrac()),
19  m_prim(&prim) {
20  set_global(begin, end, tol);
21 }
22 
36 template <typename RefStateIterator>
37 void ChemicalReference::set_global(RefStateIterator begin, RefStateIterator end,
38  double tol) {
39  Eigen::VectorXd ref = hyperplane(*m_prim, begin, end, tol);
40  m_global_ref_vec = RefStateVec(begin, end);
41  _global() = ref;
42 }
43 
47 template <typename RefStateIterator>
49  RefStateIterator begin,
50  RefStateIterator end, double tol) {
51  Eigen::VectorXd ref = hyperplane(*m_prim, begin, end, tol);
53  _supercell()[scelname] = ref;
54 }
55 
59 template <typename RefStateIterator>
60 void ChemicalReference::set_config(const std::string &configname,
61  RefStateIterator begin, RefStateIterator end,
62  double tol) {
63  Eigen::VectorXd ref = hyperplane(*m_prim, begin, end, tol);
65  _config()[configname] = ref;
66 }
67 
80 template <typename RefStateIterator>
82  RefStateIterator begin,
83  RefStateIterator end,
84  double tol) {
85  // store Molecule names in vector
86  std::vector<std::string> struc_mol_name = struc_molecule_name(prim);
87 
88  // --- find any Molecule not in the prim, add to end of vector -------------
89 
90  // increase struc_mol_name to include all Molecule names in input
91  // ensure no vacancies included
92  for (auto it = begin; it != end; ++it) {
93  for (auto mol_it = it->species_num.begin(); mol_it != it->species_num.end();
94  ++mol_it) {
95  if (xtal::is_vacancy(mol_it->first)) {
96  throw std::runtime_error(
97  "Error in ChemicalReference::hyperplane: Input should not include "
98  "vacancies");
99  }
100  if (!contains(struc_mol_name, mol_it->first)) {
101  struc_mol_name.push_back(mol_it->first);
102  }
103  }
104  }
105 
106  // --- initialize vectors, matrices ----------------------------------------
107 
108  // reference 'relaxed_energy_per_species'
109  Eigen::VectorXd E = Eigen::VectorXd::Zero(std::distance(begin, end));
110 
111  // column vector matrix of number of each Molecule in each reference state
112  Eigen::MatrixXd N =
113  Eigen::MatrixXd::Zero(struc_mol_name.size(), std::distance(begin, end));
114 
115  // --- get input values ---------------------------------------------------
116 
117  // populate E, N
118  Index index = 0;
119  for (auto it = begin; it != end; ++it, ++index) {
120  E(index) = it->energy_per_species;
121  for (auto mol_it = it->species_num.begin(); mol_it != it->species_num.end();
122  ++mol_it) {
123  N(find_index(struc_mol_name, mol_it->first), index) = mol_it->second;
124  }
125  }
126 
127  // use E, N to calculate hyperplane
128  return _calc_hyperplane(prim, struc_mol_name, N, E, tol);
129 }
130 } // namespace CASM
131 
132 #endif
std::map< std::string, Eigen::VectorXd > & _supercell()
const Access a map of scelname to reference for Supercell specialized references
const BasicStructure * m_prim
static Eigen::VectorXd _calc_hyperplane(const BasicStructure &prim, const std::vector< std::string > &struc_mol_name, Eigen::MatrixXd N, Eigen::VectorXd E, double tol)
Convert a set of ChemicalReferenceState to a hyperplane, including checks.
std::vector< ChemicalReferenceState > RefStateVec
void set_config(const std::string &configname, const Eigen::VectorXd &ref)
Set hyperplane reference specialized for a Configuration.
void set_global(const Eigen::VectorXd &ref)
Set global hyperplane reference.
static Eigen::VectorXd hyperplane(const BasicStructure &prim, RefStateIterator begin, RefStateIterator end, double tol)
Convert a set of ChemicalReferenceState to a hyperplane, including checks.
void set_supercell(const std::string &scelname, const Eigen::VectorXd &ref)
Set hyperplane reference specialized for a Supercell.
std::map< std::string, Eigen::VectorXd > & _config()
const Access a map of configname to reference for Configuration specialized references
ChemicalReference(const BasicStructure &prim, const Eigen::VectorXd &_global_ref, SpecializedRef _supercell_ref=SpecializedRef(), SpecializedRef _config_ref=SpecializedRef())
Constructor.
const BasicStructure & prim() const
Get primitive BasicStructure.
Eigen::VectorXd & _global()
Access the global reference.
Maps a Configuration to a scalar value via a hyperplane.
Definition: Reference.hh:68
BasicStructure specifies the lattice and atomic basis of a crystal.
bool is_vacancy(const std::string &name)
A vacancy is any Specie/Molecule with (name == "VA" || name == "va" || name == "Va")
Definition: Molecule.hh:187
std::vector< std::string > struc_molecule_name(BasicStructure const &_struc)
Returns an Array of each possible Molecule in this Structure.
std::string scelname(const Structure &prim, const Lattice &superlat)
Make supercell name name [deprecated].
Definition: Supercell.cc:497
ConfigIO::GenericConfigFormatter< std::string > configname()
Constructs DataFormmaterDictionary containing all Configuration DatumFormatters.
Definition: ConfigIO.cc:563
Main CASM namespace.
Definition: APICommand.hh:8
Eigen::MatrixXd MatrixXd
Index find_index(Iterator begin, Iterator end, const T &value)
Equivalent to std::distance(begin, std::find(begin, end, value))
Definition: algorithm.hh:24
bool contains(const Container &container, const T &value)
Equivalent to container.end() != std::find(container.begin(), container.end(), value)
Definition: algorithm.hh:83
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Eigen::VectorXd VectorXd
pair_type ref
Definition: settings.cc:144