24 return std::string(1, (
char)(i + (
int)
'a'));
101 std::stringstream tstr;
106 bool first_char =
true;
119 for(
int j = 0; j <
m_to_n.cols(); j++) {
127 if(!first_char &&
m_to_n(i, j) > 0)
134 tstr << std::abs(
m_to_n(i, j));
154 std::stringstream tstr;
161 bool first_char =
true;
174 for(
int j = 0; j <
m_to_x.cols(); j++) {
176 double coeff =
m_to_x(i, j);
225 std::stringstream ss;
227 auto comp_x_str = [&]() {
231 auto comp_n_str = [&](
int j) {
235 auto delta_str = [&](
int j) {
236 std::stringstream tss;
239 tss <<
"(" << comp_n_str(j) <<
" - " <<
m_origin(j) <<
")";
243 tss << comp_n_str(j);
248 ss << comp_x_str() <<
" = ";
249 bool first_term =
true;
250 for(
int j = 0; j <
m_to_x.cols(); ++j) {
252 double coeff =
m_to_x(i, j);
262 ss <<
" - " << -coeff <<
"*" << delta_str(j);
265 ss << coeff <<
"*" << delta_str(j);
272 ss <<
" + " << coeff <<
"*" << delta_str(j);
275 ss << coeff <<
"*" << delta_str(j);
292 std::stringstream ss;
294 auto comp_x_str = [&](
int j) {
298 auto comp_n_str = [&](
int j) {
302 ss << comp_n_str(i) <<
" = ";
303 bool first_term =
true;
310 for(
int j = 0; j <
m_to_n.cols(); ++j) {
312 double coeff =
m_to_n(i, j);
322 ss <<
" - " << -coeff <<
"*" << comp_x_str(j);
325 ss << coeff <<
"*" << comp_x_str(j);
332 ss <<
" + " << coeff <<
"*" << comp_x_str(j);
335 ss << coeff <<
"*" << comp_x_str(j);
355 std::stringstream ss;
357 auto print_chem_pot = [&](
int j) {
361 ss <<
"param_chem_pot(" <<
comp_var(i) <<
") = ";
363 bool first_term =
true;
364 for(
int j = 0; j < Mt.cols(); ++j) {
366 double coeff = Mt(i, j);
378 ss << print_chem_pot(j);
383 ss <<
"- " << print_chem_pot(j);
391 ss << coeff <<
"*" << print_chem_pot(j);
396 ss << coeff <<
"*" << print_chem_pot(j);
427 tmp.col(c) = _end_member;
434 throw std::runtime_error(
435 std::string(
"Error in CompositionConverter: origin or end member vector size does not match components size."));
455 for(
int i = 0; i < c; i++) {
476 std::stringstream tstr;
479 for(
int i = 0; i < vec.size(); i++) {
503 if(map.size() == 0) {
509 stream << std::setw(10) <<
"KEY" <<
" ";
510 stream << std::setw(10) <<
"ORIGIN" <<
" ";
511 for(
int i = 0; i < map.begin()->second.independent_compositions(); i++) {
512 stream << std::setw(10) << comp_var(i) <<
" ";
515 stream <<
"GENERAL FORMULA";
518 stream << std::setw(10) <<
" ---" <<
" ";
519 stream << std::setw(10) <<
" ---" <<
" ";
520 for(
int i = 0; i < map.begin()->second.independent_compositions(); i++) {
521 stream << std::setw(10) <<
" ---" <<
" ";
524 stream <<
"---" << std::endl;
526 for(
auto it = map.cbegin(); it != map.cend(); ++it) {
527 stream << std::setw(10) << it->first <<
" ";
528 stream << std::setw(10) << it->second.origin_formula() <<
" ";
529 for(
int i = 0; i < it->second.independent_compositions(); ++i) {
530 stream << std::setw(10) << it->second.end_member_formula(i) <<
" ";
533 stream << std::setw(10) << it->second.mol_formula() <<
"\n";
548 stream << std::string(indent,
' ') << f.
comp_formula(i) <<
"\n";
563 for(
int i = 0; i < f.
components().size(); ++i) {
564 stream << std::string(indent,
' ') << f.
comp_n_formula(i) <<
"\n";
591 json[
"origin"] = f.
origin();
606 std::vector<std::string> components;
609 int independent_compositions;
611 from_json(components, json[
"components"]);
614 from_json(independent_compositions, json[
"independent_compositions"]);
617 for(
int i = 0; i < independent_compositions; i++) {
655 bool has_Va = (Va_index != struc_mol_name.size());
660 E.row(Va_index) = Eigen::VectorXd::Zero(E.cols());
662 for(
int i = 0; i < E.cols(); i++) {
663 E.col(i) /= E.col(i).sum();
668 for(
int i = 0; i < M.cols(); ++i) {
669 M.col(i) = E.col(i + 1) - E.col(0);
684 Qr.setThreshold(tol);
685 auto Q = Qr.matrixQ();
686 return Q.leftCols(Qr.rank());
699 Qr.setThreshold(tol);
700 auto Q = Qr.matrixQ();
701 return Q.rightCols(Q.cols() - Qr.rank());
Eigen::VectorXd mol_composition(const Eigen::VectorXd &x) const
Convert parametric composition, 'x', to number of mol per prim, 'n'.
Eigen::MatrixXd dparam_dmol() const
Return the matrix Mij = dx_i/dn_j.
void display_comp_n(std::ostream &stream, const CompositionConverter &f, int indent=0)
Pretty-print comp_n in terms of comp.
bool almost_zero(const T &val, double tol=TOL)
If T is not integral, use std::abs(val) < tol;.
void display_composition_axes(std::ostream &stream, const std::map< std::string, CompositionConverter > &map)
Pretty-print map of name/CompositionConverter pairs.
Eigen::MatrixXd composition_space(const Structure &prim, double tol=1e-14)
Return the composition space of a Structure.
void from_json(ClexDescription &desc, const jsonParser &json)
Eigen::MatrixXd dmol_dparam() const
Return the matrix Mij = dn_i/dx_j.
Eigen::VectorXd origin() const
The mol composition of the parameteric composition axes origin.
Eigen::VectorXd param_composition(const Eigen::VectorXd &n) const
Convert number of mol per prim, 'n' to parametric composition 'x'.
bool is_vacancy(const std::string &name)
A vacancy is any Specie/Molecule with (name == "VA" || name == "va" || name == "Va") ...
std::string param_chem_pot_formula(size_type i) const
Return formula for param_chem_pot(i) in terms of chem_pot(A), chem_pot(B), ...
Structure specifies the lattice and atomic basis of a crystal.
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
std::vector< std::string > m_components
List of all allowed components names in the prim, position in vector is reference for origin and end_...
void _calc_conversion_matrices()
Calculate conversion matrices m_to_n and m_to_x.
void display_param_chem_pot(std::ostream &stream, const CompositionConverter &f, int indent=0)
Pretty-print param_chem_pot in terms of chem_pot.
std::string end_member_formula(size_type i) const
Return formula for end member.
std::string mol_formula() const
Return formula for x->n.
Eigen::VectorXd dmol_composition(const Eigen::VectorXd &dx) const
Convert change in parametric composition, 'dx', to change in number of mol per prim, 'dn'.
Index find_index_if(Iterator begin, Iterator end, UnaryPredicate p)
Equivalent to std::distance(begin, std::find_if(begin, end, p))
Eigen::VectorXd chem_pot(const Eigen::VectorXd param_chem_pot) const
Convert dG/dx to dG/dn.
void _add_end_member(Eigen::VectorXd _end_member)
Helps make variadic template constructor possible.
std::vector< std::string > get_struc_molecule_name() const
Returns an Array of each possible Molecule in this Structure.
std::vector< std::string > components() const
The order of components in mol composition vectors.
static std::string comp_var(size_type i)
Composition variable names: "a", "b", ...
Eigen::VectorXd param_chem_pot(const Eigen::VectorXd chem_pot) const
Convert dG/dn to dG/dx.
std::string comp_formula(size_type i) const
Return formula for comp(i) in terms of comp_n(A), comp_n(B), ...
EigenIndex Index
For long integer indexing:
Eigen::MatrixXd m_to_n
Conversion matrix: n = origin + m_to_n*x.
Eigen::Matrix< typename Derived::Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime > inverse(const Eigen::MatrixBase< Derived > &M)
Return the integer inverse matrix of an invertible integer matrix.
void _check_size(const Eigen::VectorXd &vec) const
Check that origin and end member vectors have same size as the number of components.
Eigen::MatrixXd m_end_members
Column vector matrix, rows == m_components.size(), cols == rank of parametric composition space...
size_type independent_compositions() const
The dimensionality of the composition space.
Eigen::VectorXd m_origin
Vector, size == m_components.size(), specifying the num_mols_per_prim of each component at the origin...
std::string origin_formula() const
Return formula for origin.
void generate_prim_end_members()
Eigen::MatrixXd _composition_space(const Structure &prim, double tol)
Non-orthogonal composition space.
Eigen::MatrixXd m_to_x
Conversion matrix: x = m_to_x*(n - origin)
void generate_sublattice_map()
void generate_components()
std::string comp_n_formula(size_type i) const
Return formula for comp_n(components()[i]) in terms of comp(a), comp(b), ...
Eigen::MatrixXd end_members(const Structure &prim)
Generate a column matrix containing all the possible molecular end members.
Convert between number of species per unit cell and parametric composition.
std::string param_formula() const
Return formula for n->x.
void display_comp(std::ostream &stream, const CompositionConverter &f, int indent=0)
Pretty-print comp in terms of comp_n.
Eigen::VectorXd dparam_composition(const Eigen::VectorXd &dn) const
Convert change in number of atoms per prim, 'dn' to change in parametric composition 'dx'...
Eigen::MatrixXd get_prim_end_members() const
Return all possible end members as row matrix.
std::string _n_formula(const Eigen::VectorXd &vec) const
Return formula for 'n'.
Eigen::VectorXd end_member(size_type i) const
The mol composition of the parameteric composition axes end members.
static jsonParser object()
Returns an empty json object.
Eigen::MatrixXd null_composition_space(const Structure &prim, double tol=1e-14)
Return the null composition space of a Structure.
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)