CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ParamComposition.hh
Go to the documentation of this file.
1 #ifndef PARAMCOMPOSITION_HH
2 #define PARAMCOMPOSITION_HH
3 
4 #include "casm/external/boost.hh"
5 using boost::property_tree::ptree;
6 
9 
10 namespace CASM {
11 
12  class Structure;
13 
14  //defines the enum type used in composition.
16 
18  // holds the transformation matrix to go from NUMBER_ATOMS to
19  // PARAM_COMP and vice versa
21 
22  // hold the list of allowed components, based on the PRIM
24 
25  // The origin of the composition space
27 
28  //the number of variables you need to define to give the position
29  //in this space
31 
32  // The prim that we are considering compositions of
34 
35  //holds the list of end members as defined in this space by the
36  //comp and origin matrices
38 
39  // holds the list of all allowed end_members in the PRIM
40  // each row is an end_member
42 
43  // gives the sublattices that components[i] can be allowed on [component][sublat] (0/1)
44  Eigen::MatrixXi sublattice_map;
45 
46  // the list of possible composition axes that have positive
47  // composition axes as computed by generate_composition_axes
49  public:
50  //*************************************************************
51  //CONSTRUCTORS
52  ParamComposition() : prim_end_members(0, 0), sublattice_map(0, 0) {
53  std::cerr << "WARNING in ParamComposition, you have not initialized a PrimClex. Things could go horribly wrong if you dont. I hope you know what you are doing." << std::endl;
54  comp.resize(2);
55  rank_of_space = -1;
56  comp[0].resize(0, 0);
57  comp[1].resize(0, 0);
58  origin.resize(0);
59  return;
60  };
61 
62  ParamComposition(const Structure &_prim) : prim_end_members(0, 0), sublattice_map(0, 0) {
63  comp.resize(2);
64  comp[0].resize(0, 0);
65  comp[1].resize(0, 0);
66  origin.resize(0);
67  prim_struc = &_prim;
68  rank_of_space = -1;
69  }
70 
71  ParamComposition(const Array< std::string > &_components, const Eigen::MatrixXd &transf_mat, const Eigen::VectorXd &_origin, const int &_rank_of_space, const Structure &_prim, const int &COMP_TYPE) {
72  rank_of_space = _rank_of_space;
73  components = _components;
74  origin = _origin;
75  prim_struc = &_prim;
76  comp.resize(2);
77  if(COMP_TYPE == PARAM_COMP) {
78  comp[PARAM_COMP] = transf_mat;
79  comp[NUMBER_ATOMS] = comp[PARAM_COMP].inverse();
80  }
81  else if(COMP_TYPE == NUMBER_ATOMS) {
82  comp[NUMBER_ATOMS] = transf_mat;
83  comp[PARAM_COMP] = comp[NUMBER_ATOMS].inverse();
84  }
86 
87  };
88 
89 
90  // Add in the primclex pointer
91  ParamComposition(const std::string &json_filename, const Structure &_prim) {
92  prim_struc = &_prim;
93  comp.resize(2);
94  comp[0].resize(0, 0);
95  comp[1].resize(0, 0);
96  origin.resize(0);
97  std::ifstream comp_json_file;
98  comp_json_file.open(json_filename.c_str());
99  if(!comp_json_file) {
100  std::cout << "ERROR\n";
101  return;
102  }
103  read(comp_json_file);
104  return;
105  };
106 
107  ParamComposition(ptree comp_ptree, const Structure &_prim) {
108  prim_struc = &_prim;
109  comp.resize(2);
110  comp[0].resize(0, 0);
111  comp[1].resize(0, 0);
112  origin.resize(0);
113  read(comp_ptree);
114  }
115 
116  //*************************************************************
117  //GENERATE Routines
118  void generate_components();
120  //void generate_composition_axes();
123  void generate_composition_space(bool verbose = false);
124 
125  //*************************************************************
126  //CALC Routines
128  Eigen::VectorXd calc(const Eigen::VectorXd &tcomp, const int &MODE);
129  ptree calc_composition_ptree() const; //returns a ptree object with all the data from this composition object
132 
133  Eigen::VectorXd calc_param_composition(const Eigen::VectorXd &num_atoms_per_prim) const;
134  Eigen::VectorXd calc_num_atoms(const Eigen::VectorXd &param_composition) const;
135 
136  // Lists components (species) of crystal whose compositions are fixed (i.e., are not involved in alloying)
137  // each pair gives (species_name, #in_prim)
138  std::vector<std::pair<std::string, Index> > fixed_components();
139  //*************************************************************
140  //PRINT Routines
141 
142  void print(std::ostream &stream, bool print_comp_axes_flag = false) const {
143  if(print_comp_axes_flag) {
144  stream << "/*" << std::endl;
145  print_composition_axes(stream);
146  stream << "*/" << std::endl;
147  }
148  ptree comp_ptree = calc_composition_ptree();
149  write_json(stream, comp_ptree);
150  }
151 
152  void print_sublattice_map(std::ostream &stream) const {
153  stream << "SUBLATTICE MAP" << std::endl << "-------------" << std::endl;
154  stream << sublattice_map << std::endl;
155  }
156  void print_prim_end_members(std::ostream &stream) const {
157  stream << "Number of end members: " << prim_end_members.rows() << std::endl;
158  stream << components << std::endl << "------" << std::endl;
159  stream << prim_end_members << std::endl;
160  }
161  void print_components(std::ostream &stream) const {
162  stream << "Components: " << components << std::endl;
163  };
164 
165  void print_composition_axes(std::ostream &stream) const;
166  void print_curr_composition_axes(std::ostream &stream) const;
167  void print_end_member_formula(const int &end_member_index, std::ostream &stream, const int &stream_width) const;
168  void print_member_formula(const Eigen::VectorXd &member, std::ostream &stream, const int &stream_width) const;
169  void print_origin_formula(std::ostream &stream, const int &stream_width) const;
170  void print_composition_formula(std::ostream &stream, const int &stream_width) const;
171 
172  void print_composition_matrices(std::ostream &stream) const {
173  stream << "components: ";
174  print_components(stream);
175  stream << "comp[PARAM_COMP] " << comp[PARAM_COMP] << std::endl;
176  stream << "comp[NUMBER_ATOMS] " << comp[NUMBER_ATOMS] << std::endl;
177  stream << "origin: " << origin << std::endl;
178  }
179 
180  //*************************************************************
181  //READ
182  void read(const std::string &comp_filename);
183  void read(std::istream &stream);
184  void read(ptree comp_ptree);
185 
186  //*************************************************************
187  //MISCELLANEOUS
188  void max_out(const int &component_index, Eigen::MatrixXi &sublat_comp) const;
189  void select_composition_axes(const Index &choice);
190 
191  //*************************************************************
192  //ACCESSORS
193 
194  const Structure &get_prim() const {
195  return *prim_struc;
196  }
197 
199  return spanning_end_members;
200  };
201 
204  return prim_end_members;
205  }
206 
208  return comp;
209  };
210 
211  const Eigen::VectorXd &get_origin() const {
212  return origin;
213  };
214 
215  const int &get_rank_of_space() const {
216  return rank_of_space;
217  };
218 
219  const int &get_number_of_references() const {
220  return rank_of_space;
221  };
222 
225  return components;
226  };
227 
228  std::string get_composition_formula() const;
229 
231  return allowed_list;
232  }
233 
234  //*************************************************************
235  //TEST FUNCTIONS
236 
237  //A ParamComposition is defined as 'set' if origin is non-empty, the
238  //prim pointer does not point to nullptr, rank_of_space is greater
239  //than 0, the comp matrices are non-empty and have their matrices
240  //such that they are square
241  bool is_set() const {
242  if(rank_of_space <= 0 || components.size() == 0 || origin.size() != components.size()) {
243  return false;
244  }
245  if(comp.size() == 2) {
246  return (comp[0].rows() == components.size() && comp[0].cols() == components.size() &&
247  comp[1].rows() == components.size() && comp[1].cols() == components.size());
248  }
249  else {
250  return false;
251  }
252  return true;
253  };
254  };
255 
256 }
257 #endif
Eigen::MatrixXd MatrixXd
ParamComposition calc_composition_object(const Eigen::VectorXd &torigin, const Array< Eigen::VectorXd > tspanning)
Array< ParamComposition > allowed_list
void read(const std::string &comp_filename)
Index size() const
Definition: Array.hh:145
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:29
Eigen::MatrixXd prim_end_members
void resize(Index new_N)
Definition: Array.hh:468
void print(std::ostream &stream, bool print_comp_axes_flag=false) const
const Structure * prim_struc
void print_composition_matrices(std::ostream &stream) const
const Array< ParamComposition > & get_allowed_list() const
Main CASM namespace.
Definition: complete.cpp:8
Array< Eigen::VectorXd > spanning_end_members
std::string get_composition_formula() const
ParamComposition(const Array< std::string > &_components, const Eigen::MatrixXd &transf_mat, const Eigen::VectorXd &_origin, const int &_rank_of_space, const Structure &_prim, const int &COMP_TYPE)
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
const int & get_rank_of_space() const
void print_composition_formula(std::ostream &stream, const int &stream_width) const
Eigen::MatrixXi sublattice_map
Eigen::VectorXd calc_param_composition(const Eigen::VectorXd &num_atoms_per_prim) const
EigenIndex Index
For long integer indexing:
ptree calc_composition_ptree() const
ParamComposition(const std::string &json_filename, const Structure &_prim)
Eigen::VectorXd VectorXd
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 print_curr_composition_axes(std::ostream &stream) const
ParamComposition(ptree comp_ptree, const Structure &_prim)
const int & get_number_of_references() const
void print_sublattice_map(std::ostream &stream) const
void print_origin_formula(std::ostream &stream, const int &stream_width) const
void max_out(const int &component_index, Eigen::MatrixXi &sublat_comp) const
void generate_composition_transf()
const Eigen::VectorXd & get_origin() const
Array< std::string > components
void print_prim_end_members(std::ostream &stream) const
const Structure & get_prim() const
void print_end_member_formula(const int &end_member_index, std::ostream &stream, const int &stream_width) const
Eigen::MatrixXd get_prim_end_members() const
Return all possible end members as row matrix.
const Array< Eigen::MatrixXd > & get_comp() const
ParamComposition(const Structure &_prim)
void print_components(std::ostream &stream) const
Eigen::VectorXd calc_num_atoms(const Eigen::VectorXd &param_composition) const
const Array< std::string > & get_components() const
Components are ordered as in Structure::get_struc_molecule.
Array< Eigen::MatrixXd > comp