1 #ifndef CASM_ChemicalReference
2 #define CASM_ChemicalReference
18 struct ChemicalReferenceState {
46 static const std::string
Name;
47 static const std::string
Desc;
76 template<
typename RefStateIterator>
78 RefStateIterator begin,
88 std::unique_ptr<ChemicalReference>
clone()
const {
89 return notstd::make_unique<ChemicalReference>(*this->
_clone());
125 template<
typename RefStateIterator>
127 RefStateIterator end,
149 const std::map<std::string, Eigen::VectorXd> &
supercell()
const {
164 template<
typename RefStateIterator>
166 RefStateIterator begin,
167 RefStateIterator end,
197 const std::map<std::string, Eigen::VectorXd> &
config()
const {
212 template<
typename RefStateIterator>
214 RefStateIterator begin,
215 RefStateIterator end,
224 auto result =
_config().erase(configname);
249 template<
typename RefStateIterator>
251 RefStateIterator begin,
252 RefStateIterator end,
273 std::map<std::string, Eigen::VectorXd> &
_config() {
283 const std::vector<std::string> &struc_mol_name,
315 int _indent_incr = 2) :
339 void print(
const std::string &str) {
340 stream << std::string(indent,
' ') << str <<
"\n";
345 for(
int i = 0; i < plane.size(); ++i) {
347 stream << std::string(indent,
' ') << struc_mol_name[i] <<
"(1): " << plane(i) <<
"\n";
357 void print(
const std::vector<ChemicalReferenceState> &ref_state_vec) {
358 for(
auto it = ref_state_vec.begin(); it != ref_state_vec.end(); ++it) {
362 stream << std::string(indent,
' ');
363 for(
auto it = ref_state.species_num.begin(); it != ref_state.species_num.end(); ++it) {
364 double num = it->second;
369 stream << it->first <<
"(";
380 stream <<
": " << ref_state.energy_per_species <<
"\n";
389 void print(
const std::pair<std::string, Eigen::VectorXd> &_pair) {
390 stream << std::string(indent,
' ') << _pair.first <<
":\n";
401 void print(
const std::pair<std::string, std::vector<ChemicalReferenceState> > &_pair) {
402 stream << std::string(indent,
' ') << _pair.first <<
":\n";
409 print(
"Global chemical reference:");
417 print(
"Supercell specific chemical references:");
428 (res != ref_state_end) ?
print(*res) :
print(*it);
433 print(
"Configuration specific chemical references:");
434 for(
auto it = ref.
config().begin(); it != ref.
config().end(); ++it) {
441 auto it = ref.
config().find(name);
444 (res != ref_state_end) ?
print(*res) :
print(*it);
471 template<
typename RefStateIterator>
473 RefStateIterator begin,
474 RefStateIterator end,
484 for(
auto it = begin; it != end; ++it) {
485 for(
auto mol_it = it->species_num.begin(); mol_it != it->species_num.end(); ++mol_it) {
487 throw std::runtime_error(
"Error in ChemicalReference::hyperplane: Input should not include vacancies");
489 if(!
contains(struc_mol_name, mol_it->first)) {
490 struc_mol_name.push_back(mol_it->first);
501 Eigen::MatrixXd N = Eigen::MatrixXd::Zero(struc_mol_name.size(), std::distance(begin, end));
508 for(
auto it = begin; it != end; ++it, ++index) {
509 E(index) = it->energy_per_species;
510 for(
auto mol_it = it->species_num.begin(); mol_it != it->species_num.end(); ++mol_it) {
511 N(
find_index(struc_mol_name, mol_it->first), index) = mol_it->second;
AtomFrac SpeciesFrac
In the future, AtomFrac will actually be atoms only.
bool almost_zero(const T &val, double tol=TOL)
If T is not integral, use std::abs(val) < tol;.
void set_supercell(const std::string &scelname, RefStateIterator begin, RefStateIterator end, double tol)
Set hyperplane reference specialized for a Supercell.
double energy_per_species
Energy in this reference state.
ChemicalReference auto_chemical_reference(const PrimClex &primclex, double lin_alg_tol)
Automatically set ChemicalReference using calculated Configurations with 'extreme' compositions...
std::unique_ptr< ChemicalReference > clone() const
Clone.
const std::map< std::string, Eigen::VectorXd > & supercell() const
const Access a map of scelname to reference for Supercell specialized references
bool is_vacancy(const std::string &name)
A vacancy is any Specie/Molecule with (name == "VA" || name == "va" || name == "Va") ...
Structure specifies the lattice and atomic basis of a crystal.
RefStateVec m_global_ref_vec
ChemicalReferencePrinter(std::ostream &_stream, const ChemicalReference &_ref, int _indent=0, int _indent_incr=2)
std::vector< ChemicalReferenceState > RefStateVec
void print(const std::pair< std::string, Eigen::VectorXd > &_pair)
const RefStateMap & config_ref_states() const
const Access a map of configname to RefStateVec for Configuration specialized references ...
void print(const std::pair< std::string, std::vector< ChemicalReferenceState > > &_pair)
Index find_index(Iterator begin, Iterator end, const T &value)
Equivalent to std::distance(begin, std::find(begin, end, value))
void print(const std::vector< ChemicalReferenceState > &ref_state_vec)
static const std::string Name
std::map< std::string, double > species_num
Map of Molecule name : number of each species in reference state.
RefStateMap m_supercell_ref_map
static const std::string Desc
void print_supercell(const std::string &name)
ChemicalReference(const Structure &prim, RefStateIterator begin, RefStateIterator end, double tol)
Construct global reference via range ChemicalReferenceState.
std::map< std::string, Eigen::VectorXd > SpecializedRef
std::vector< std::string > get_struc_molecule_name() const
Returns an Array of each possible Molecule in this Structure.
const std::map< std::string, Eigen::VectorXd > & config() const
const Access a map of configname to reference for Configuration specialized references ...
void print_config(const std::string &name)
void set_supercell(const std::string &scelname, const Eigen::VectorXd &ref)
Set hyperplane reference specialized for a Supercell.
RefStateMap m_config_ref_map
size_type erase_config(const std::string &configname)
Erase hyperplane reference specialized for a Configuration.
const std::map< std::string, Eigen::VectorXd > & supercell() const
const Access a map of scelname to reference for Supercell specialized references
void set_config(const std::string &configname, const Eigen::VectorXd &ref)
Set hyperplane reference specialized for a Configuration.
static Eigen::VectorXd _calc_hyperplane(const Structure &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.
EigenIndex Index
For long integer indexing:
Eigen::VectorXd & _global()
Access the global reference.
std::vector< std::string > struc_mol_name
Eigen::CwiseUnaryOp< decltype(std::ptr_fun(boost::math::lround< typename Derived::Scalar >)), const Derived > lround(const Eigen::MatrixBase< Derived > &val)
Round Eigen::MatrixXd to Eigen::MatrixXl.
std::map< std::string, Eigen::VectorXd > & _supercell()
const Access a map of scelname to reference for Supercell specialized references
PrimClex is the top-level data structure for a CASM project.
void set_global(RefStateIterator begin, RefStateIterator end, double tol)
Set global hyperplane reference.
static Eigen::VectorXd hyperplane(const Structure &prim, RefStateIterator begin, RefStateIterator end, double tol)
Convert a set of ChemicalReferenceState to a hyperplane, including checks.
void print(const Eigen::VectorXd &plane)
size_type erase_supercell(const std::string &scelname)
Erase hyperplane reference specialized for a Supercell.
Structure to help print ChemicalReference.
const Eigen::VectorXd & global() const
const Access the global reference
ConfigIO::GenericConfigFormatter< std::string > configname()
Constructs DataFormmaterDictionary containing all Configuration DatumFormatters.
const RefStateVec & global_ref_states() const
const Access a map of configname to RefStateVec for Supercell specialized references ...
void set_global(const Eigen::VectorXd &ref)
Set global hyperplane reference.
Stores the composition and energy in a single reference state.
std::map< std::string, RefStateVec > RefStateMap
const Eigen::VectorXd & global() const
const Access the global reference
const RefStateMap & supercell_ref_states() const
const Access a map of configname to RefStateVec for Supercell specialized references ...
Maps a Configuration to a scalar value via a hyperplane.
std::map< std::string, Eigen::VectorXd > & _config()
const Access a map of configname to reference for Configuration specialized references ...
void print(const std::string &str)
ChemicalReference(const Structure &prim, const Eigen::VectorXd &_global_ref, SpecializedRef _supercell_ref=SpecializedRef(), SpecializedRef _config_ref=SpecializedRef())
Constructor.
const Structure & prim() const
Get primitive Structure.
ConfigIO::GenericConfigFormatter< std::string > scelname()
bool contains(const Container &container, const T &value)
Equivalent to container.end() != std::find(container.begin(), container.end(), value) ...
ChemicalReference * _clone() const
Clone.
const std::map< std::string, Eigen::VectorXd > & config() const
const Access a map of configname to reference for Configuration specialized references ...
void set_config(const std::string &configname, RefStateIterator begin, RefStateIterator end, double tol)
Set hyperplane reference specialized for a Configuration.
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)
A Configuration represents the values of all degrees of freedom in a Supercell.
const ChemicalReference & ref