28 std::cerr <<
"WARNING in ParamComposition::generate_components(), the components data member in the class";
29 std::cerr <<
" is not empty. Clearing it anyways.\n";
34 for(
auto it = struc_molecule.begin(); it != struc_molecule.end(); ++it) {
76 for(
Index j = 0; j < tocc[i].
size(); j++) {
79 std::cerr <<
"ERROR:Your component matrix has been initialized badly. Quitting\n";
114 Eigen::MatrixXi tend;
119 for(
Index i = 0; i < priority_index.
size(); i++) {
120 priority_index[i] = i;
133 for(
Index i = 0; i < priority_index.
size(); i++) {
134 tend(0, priority_index[i]) = tsublat_comp.row(priority_index[i]).sum();
136 max_out(priority_index[i], tsublat_comp);
140 bool is_unique =
true;
141 for(
Index i = 0; i < tend_members.
size(); i++) {
142 if(tend == tend_members[i]) {
156 for(
Index i = 0; i < tend_members.
size(); i++) {
202 std::cerr <<
"WARNING in ParamComposition::generate_composition_space, your allowed_list is non-empty. If you are not careful,you may end up with repeats of allowed composition axes" << std::endl;
209 std::cout <<
"Rank of space : " <<
rank_of_space << std::endl;
222 binary_choose[binary_choose.size() - 1 - i] = 1;
225 std::cout <<
"Binary choose: " << binary_choose << std::endl;
228 std::cout <<
"Computing the possible composition axes ... " << std::endl;
235 std::cout <<
"The origin is: " << torigin << std::endl;
252 std::cout <<
"The end members being considered: " << std::endl;
254 for(
Index j = 0; j < tbinary_choose.
size(); j++) {
255 if(tbinary_choose[j] == 1) {
264 std::cout <<
"---" << std::endl;
272 std::cout <<
"Calculated compositions:" << std::endl;
281 for(
EigenIndex k = 0; k < test_comp.size(); k++) {
286 if((test_comp(k) < 0 && !
almost_zero(test_comp(k))) || std::isnan(test_comp(k))) {
313 int composition_var = (int)
'a';
314 std::stringstream tstr;
316 bool first_char =
true;
328 tstr << (char)(composition_var + j);
332 tstr <<
'+' << (char)(composition_var + j);
336 tstr <<
'-' << (char)(composition_var + j);
347 stream << tstr.str().c_str();
355 std::stringstream tstr;
356 for(
EigenIndex i = 0; i < member.size(); i++) {
367 stream << std::setw(stream_width) << tstr.str().c_str();
379 stream <<
"Number of choices of composition axes: " <<
allowed_list.size() << std::endl;
382 stream << std::setw(10) <<
"INDEX";
383 stream << std::setw(10) <<
"ORIGIN";
385 stream << std::setw(10) << (char)((
int)
'a' + i);
388 stream <<
"GENERAL FORMULA";
391 stream << std::setw(10) <<
" ---";
392 stream << std::setw(10) <<
" ---";
393 for(
int i = 0; i < (rank_of_space - 1); i++) {
394 stream << std::setw(10) <<
" ---";
397 stream <<
"---" << std::endl;
400 stream << std::setw(10) << i;
403 allowed_spanning_end_members =
allowed_list[i].get_spanning_end_members();
404 for(
Index j = 0; j < allowed_spanning_end_members.
size(); j++) {
423 stream << std::setw(20) <<
"ORIGIN";
425 stream << std::setw(10) << (char)((
int)
'a' + i);
428 stream <<
"GENERAL FORMULA";
431 stream << std::setw(20) <<
" ---";
433 stream << std::setw(10) <<
" ---";
436 stream <<
"---" << std::endl;
441 for(
int j = 0; j < allowed_spanning_end_members.
size(); j++) {
495 std::vector<std::pair<std::string, Index> > tcompon;
500 for(
Index i = 1; i < end_members.cols(); i++) {
501 sum_vec += ((end_members.col(i) - end_members.col(0)).array().abs()).matrix();
503 for(
Index i = 0; i < sum_vec.size(); i++) {
518 std::cerr <<
"ERROR in ParamComposition::calc_composition_object the spanning vectors are not as long as the number of ";
519 std::cerr <<
"components in this system. I'm confused and recommend you quit and try again. However, not going to force quit\n";
523 for(
Index i = 0; i < tspanning.
size(); i++) {
524 tmat.col(i) = tspanning[i];
529 Eigen::FullPivHouseholderQR<Eigen::MatrixXd> qr(tmat.leftCols(tspanning.
size()));
566 std::string root(
"");
570 std::stringstream strs;
571 strs << root <<
"allowed_axes.";
573 comp_ptree.put_child(strs.str().c_str(),
allowed_list[i].calc_composition_ptree());
580 std::string root(
"");
581 root.append(
"components");
582 std::string components_string;
585 components_string.append(
" ");
587 boost::algorithm::trim(components_string);
588 comp_ptree.put(root, components_string.c_str());
593 std::string root(
"");
594 root.append(
"origin");
595 std::stringstream origin_strs;
597 std::string origin_str;
598 origin_str = origin_strs.str();
599 boost::replace_all(origin_str,
"\n",
" ");
600 comp_ptree.put(root, origin_str.c_str());
605 std::string root(
"");
606 root.append(
"end_members");
610 std::stringstream tspan_strs;
612 std::string tspan_str = tspan_strs.str();
613 boost::replace_all(tspan_str,
"\n",
" ");
615 std::stringstream tname;
616 tname << root <<
".";
617 tname << char(
'a' + i);
618 comp_ptree.put(tname.str().c_str(), tspan_str.c_str());
624 std::string root(
"");
625 root.append(
"rank_of_space");
626 std::stringstream rank_strs;
628 comp_ptree.put(root.c_str(), rank_strs.str().c_str());
646 std::cerr <<
"WARNING something is wrong in ParamComposition::spanning_end_members. The rank_of_space in the ParamComposition object is <=0. I do not know how to calculate the end_members in such a space" << std::endl;
660 std::ifstream in_comp;
661 in_comp.open(comp_filename.c_str());
663 std::cerr <<
"ERROR in ParamComposition::read. Could not read the file: " << comp_filename.c_str() << std::endl;
664 std::cerr <<
"Continuing anyways. However, things could go horribly wrong. I recommend you quit." << std::endl;
673 read_json(stream, comp_ptree);
682 const ptree &allowed_axes_ptree = comp_ptree.get_child(
"allowed_axes");
684 int allowed_axes_num = 0;
687 std::stringstream tstr;
688 tstr << allowed_axes_num;
692 catch(std::exception
const &e) {
699 catch(std::exception
const &e) {
706 std::cerr <<
"WARNING in ParamComposition::read. your components matrix is not empty. Clearing that array and any other non-empty data members" << std::endl;
711 std::string tcomp = comp_ptree.get<std::string>(
"components");
712 boost::char_separator< char > sep(
" ");
713 boost::tokenizer< boost::char_separator< char > > tokens(tcomp, sep);
714 BOOST_FOREACH(
const std::string & t, tokens) {
723 catch(std::exception
const &e) {
729 std::string tcomp = comp_ptree.get<std::string>(
"origin");
731 std::cerr <<
"ERROR in ParamComposition::read. You are trying to set an origin without specifying the components. This is dangerous, and not allowed. QUITTING." << std::endl;
736 catch(std::exception
const &e) {
742 const ptree &end_members_ptree = comp_ptree.get_child(
"end_members");
743 std::string comp_axis(1,
'a');
746 std::string span_string = end_members_ptree.get< std::string > (comp_axis.c_str());
749 catch(std::exception
const &e) {
758 catch(std::exception
const &e) {
764 std::string trank_str = comp_ptree.get<std::string>(
"rank_of_space");
767 catch(std::exception
const &e) {
791 for(
EigenIndex i = 0; i < sublat_comp.cols(); i++) {
792 if(sublat_comp(component_index, i) > 0) {
793 for(
EigenIndex j = 0; j < sublat_comp.rows(); j++) {
794 sublat_comp(j, i) = 0;
807 std::cerr <<
"ERROR in ParamComposition::select_composition_axes. Your value of choice is outside the range of allowed_list" << std::endl;
823 std::stringstream ss;
ParamComposition calc_composition_object(const Eigen::VectorXd &torigin, const Array< Eigen::VectorXd > tspanning)
Array< ParamComposition > allowed_list
bool almost_zero(const T &val, double tol=TOL)
If T is not integral, use std::abs(val) < tol;.
void read(const std::string &comp_filename)
bool contains(const T &test_elem) const
Eigen::VectorXd eigen_vector_from_string(const std::string &tstr, const int &size)
void push_back(const T &toPush)
Eigen::MatrixXd prim_end_members
std::vector< Molecule > get_struc_molecule() const
Returns an Array of each possible Molecule in this Structure.
const Structure * prim_struc
Array< Eigen::VectorXd > spanning_end_members
std::string get_composition_formula() const
void select_composition_axes(const Index &choice)
void print_member_formula(const Eigen::VectorXd &member, std::ostream &stream, const int &stream_width) const
std::vector< std::pair< std::string, Index > > fixed_components()
void print_composition_axes(std::ostream &stream) const
Eigen::MatrixXd::Index EigenIndex
For integer indexing:
void print_composition_formula(std::ostream &stream, const int &stream_width) const
void calc_spanning_end_members()
Eigen::MatrixXi sublattice_map
Eigen::VectorXd calc_param_composition(const Eigen::VectorXd &num_atoms_per_prim) const
void calc_transformation_matrices()
EigenIndex Index
For long integer indexing:
ptree calc_composition_ptree() const
Array< CoordType > basis
Lattice vectors that specifies periodicity of the crystal.
const Array< Eigen::VectorXd > & get_spanning_end_members() const
Eigen::VectorXd calc(const Eigen::VectorXd &tcomp, const int &MODE)
void generate_composition_space(bool verbose=false)
void generate_prim_end_members()
void print_curr_composition_axes(std::ostream &stream) const
Index find(const T &test_elem) const
void generate_sublattice_map()
void generate_components()
Eigen::MatrixXd end_members(const Structure &prim)
Generate a column matrix containing all the possible molecular end members.
void print_origin_formula(std::ostream &stream, const int &stream_width) const
void max_out(const int &component_index, Eigen::MatrixXi &sublat_comp) const
Array< std::string > components
Basic std::vector like container (deprecated)
Eigen::VectorXd calc_num_atoms(const Eigen::VectorXd ¶m_composition) const
Array< Eigen::MatrixXd > comp