CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Cluster.hh
Go to the documentation of this file.
1 #ifndef CLUSTER_HH
2 #define CLUSTER_HH
3 
4 #include <iostream>
5 #include <complex>
6 #include <cmath>
7 
11 
12 namespace CASM {
13 
14  class Lattice;
15  template < typename CoordType >
17 
18  template < typename ClustType >
19  class GenericOrbitree;
20 
21  template < typename CoordType >
23 
24  //Begin Cluster class definition:
27  template < typename CoordType >
28  class GenericCluster : public Array<CoordType> {
29  public:
31  using Array<CoordType> :: at;
33  using Array<CoordType> :: operator[];
36 
37  typedef CoordType WhichCoordType;
38 
39  //GenericCluster() : m_min_length(0.0), m_max_length(0.0), clust_group(LOCAL) {}
40  GenericCluster(const Lattice &init_home);
41 
42  const Lattice &home() const {
43  return *m_lat_ptr;
44  }
45 
46  const SymGroup &clust_group() const {
47  return m_clust_group;
48  }
49 
51  return m_permute_rep;
52  }
53 
54  void set_clust_group(const Array<SymOp> &new_group) {
55  _clust_group() = new_group;
56  }
57 
58  void set_permute_rep(SymGroupRepID perm_rep_ID) {
59  if(clust_group().size() == 0) {
60  std::cerr << "CRITICAL ERROR: In GenericCluster<>::set_permute_rep(), Cluster::clust_group() has not yet been initialized!\n"
61  << " Groups must always be initialized before their representations. Exiting...\n";
62  assert(0);
63  exit(1);
64  }
65  _permute_rep().set_rep(clust_group(), perm_rep_ID);
66  }
67 
68  void set_lattice(const Lattice &new_home, COORD_TYPE mode);
69 
70  void push_back(const CoordType &new_coord);
71 
73  void within(Index pivot_ind = 0);
74 
77  void within(Index pivot_ind, Coordinate &trans);
78 
80  void all_within();
81 
82  void update_data_members(const BasicStructure<CoordType> &ref_struc);
83 
87  bool image_check(const Lattice &cell, int nV = 0) const;
88 
90  GenericCluster &permute(const Array<Index> &perm);
91  GenericCluster &permute(const Permutation &perm);
92 
94  GenericCluster &apply_sym(const SymOp &op);
97 
99  void generate_clust_group(const SymGroup &super_group, std::vector<Permutation> *perm_array_ptr = nullptr, double tol = TOL);
100 
102  std::vector<Permutation> clust_group_permutations(double tol) const;
103 
105  void calc_properties(); //Alex do this
106  void calc_properties(GenericCluster<CoordType> phenom_clust);
107 
108  double max_length() const {
109  return m_max_length;
110  }
111 
112  double min_length() const {
113  return m_min_length;
114  }
115 
118 
121 
123  bool contains(const GenericCluster &test_cluster) const;
124 
126  bool contains_periodic(const CoordType &test_coord, double tol) const;
127 
130  Index find(const CoordType &test_elem, double tol) const;
131 
135  bool find(const GenericCluster &test_cluster, Array<Index> &index, double tol) const;
136 
139  bool map_onto_subcluster(const GenericCluster &pivot, double tol = TOL);
140  bool map_onto_subcluster(const GenericCluster &pivot, int num_maps, double tol = TOL);
141 
143  void collect_basis_info(const Array<CoordType> &basis);
146  void collect_basis_info(const Array<CoordType> &basis, const Coordinate &shift);
147 
148 
149  void read(std::istream &stream, int num_sites, COORD_TYPE mode, bool SD_is_on);
151  void read(std::istream &stream, COORD_TYPE mode); //Modified by Ivy
152 
153  void print(std::ostream &stream, char delim = '\n', COORD_TYPE mode = COORD_DEFAULT) const;
154  void print_shifted(std::ostream &stream, const Coordinate &shift, char delim = '\n', COORD_TYPE mode = COORD_DEFAULT) const;
155  void print_sites(std::ostream &stream, int space, char delim = '\n', COORD_TYPE mode = COORD_DEFAULT) const;
156  void print_basis_info(std::ostream &stream, int space, char delim = '\n', COORD_TYPE mode = COORD_DEFAULT) const;
157  void print_decorated_sites(std::ostream &stream, int space, char delim = '\n', COORD_TYPE mode = COORD_DEFAULT) const;
158 
160  void merge(const GenericCluster &RHS);
162  void merge(const CoordType &RHS);
163 
165  GenericCluster &operator+=(const Coordinate &RHS);
166  GenericCluster &operator-=(const Coordinate &RHS);
167 
170 
172  bool operator==(const GenericCluster &RHS) const;
173 
175  bool is_equivalent(const GenericCluster &test_clust) const;
176 
179  bool is_equivalent(const GenericCluster &test_clust, Coordinate &trans) const;
180 
182  bool map_onto(const GenericCluster &test_clust, double tol);
183 
186  bool map_onto(const GenericCluster &test_clust, Coordinate &trans, double tol);
187 
189  jsonParser &to_json(jsonParser &json) const;
190  void from_json(const jsonParser &json);
191 
192  protected:
194  return m_clust_group;
195  }
196 
198  return m_permute_rep;
199  }
200 
201  private:
206  };
207 
209  template <typename CoordType>
211 
213  template <typename CoordType>
215 
217  template <typename CoordType>
219 
220  template <typename CoordType>
221  bool almost_equal(const GenericCluster<CoordType> &LHS, const GenericCluster<CoordType> &RHS, double tol);
222 
223 
224 
226  template<typename CoordType>
228 
229  json.put_obj();
230 
231  // members not included:
232  // Lattice const *m_lat_ptr;
233 
234 
235  // inherits: public Array<CoordType>
236  const Array<CoordType> &coord_array_ref = *this;
237  // std::cout << "coord_array_ref:" << coord_array_ref.size() << std::endl;
238  // std::cout << coord_array_ref << std::endl;
239  json["coordtype"] = coord_array_ref;
240 
241  // members included:
242 
243  // double m_min_length, m_max_length;
244  json["min_length"] = m_min_length;
245  json["max_length"] = m_max_length;
246 
247  //Turning off the printing of cluster symmetry
248  //TODO: Come up with some way of enabling this
249  // // SymGroup clust_group;
250  // if(clust_group.size() > 0)
251  // json["clust_group"] = clust_group;
252 
253  return json;
254  }
255 
256  // Read from json. Lattice must be set previously. Assumes CoordType::CoordType(Lattice) exists.
257  template<typename CoordType>
259  try {
260 
261  // members not read:
262  // Lattice const *m_lat_ptr;
263 
264  // inherits: public Array<CoordType>
265 
266  //std::cout<<"Number of coordinates: "<<json["coordtype"].size()<<std::endl;
267  //this->resize(json["coordtype"].size(), coord);
268  for(int i = 0; i < json["coordtype"].size(); i++) {
269  CoordType coord(home());
270  CASM::from_json(coord, json["coordtype"][i]);
271  (*this).push_back(coord);
272  }
273  //std::cout<<"Read in the coordinates"<<std::endl;
274 
275  // double m_min_length, m_max_length;
276  // Read these, because if local clusters they were generated from phenom_clust
277  CASM::from_json(m_min_length, json["min_length"]);
278  CASM::from_json(m_max_length, json["max_length"]);
279  //std::cout<<"Read in the min and max lengths"<<std::endl;
280 
281 
282  // // SymGroup clust_group;
283  // //This is a hack to initialize the appropriate SymOp
284  // Coordinate temp_coord(Vector3<double>(0.0,0.0,0.0),home());
285  // SymOp temp_symOp(temp_coord);
286  // if(clust_group.size()!=0)
287  // std::cerr<<"WARNING in Cluster::from_json. Your clust_group "
288  // <<"is not empty. Clearing anyways"<<std::endl;
289  // clust_group.clear();
290  // clust_group.push_back(temp_symOp);
291  // //std::cout<<"Reading the clust_group"<<std::endl;
292  // if(json.contains("clust_group"))
293  // CASM::from_json(clust_group, json["clust_group"]);
294 
295  }
296  catch(...) {
298  throw;
299  }
300  }
301 
302 
303  template<typename T>
305  return clust.to_json(json);
306  }
307 
308  template<typename T>
309  void from_json(GenericCluster<T> &clust, const jsonParser &json) {
310  clust.from_json(json);
311  }
312 
313 };
314 
316 
317 #endif
void set_permute_rep(SymGroupRepID perm_rep_ID)
Definition: Cluster.hh:58
void print_basis_info(std::ostream &stream, int space, char delim= '\n', COORD_TYPE mode=COORD_DEFAULT) const
size_type size() const
Returns array size if *this is a JSON array, object size if *this is a JSON object, 1 otherwise.
Definition: jsonParser.cc:430
void from_json(ClexDescription &desc, const jsonParser &json)
Index size() const
Definition: Array.hh:145
Type-safe ID object for communicating and accessing Symmetry representation info. ...
double min_length() const
Definition: Cluster.hh:112
jsonParser & to_json(jsonParser &json) const
Write GenericCluster to json. Does not write lattice.
Definition: Cluster.hh:227
void push_back(const CoordType &new_coord)
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
const SymGroupRep::RemoteHandle & permute_rep() const
Definition: Cluster.hh:50
BasicStructure specifies the lattice and atomic basis of a crystal.
Definition: Cluster.hh:16
Main CASM namespace.
Definition: complete.cpp:8
*bool image_check(const Lattice &cell, int nV=0) const
Checks to see if cluster is "compact" relative to (Lattice cell) in other words, period images of the...
bool contains_periodic(const CoordType &test_coord, double tol) const
Like Array::contains(), but takes periodicity mode into account.
void set_clust_group(const Array< SymOp > &new_group)
Definition: Cluster.hh:54
const double TOL
void collect_basis_info(const Array< CoordType > &basis)
Figure out which basis atoms in basis correspond to the points in cluster (*this) ...
const SymGroup & clust_group() const
Definition: Cluster.hh:46
void print_sites(std::ostream &stream, int space, char delim= '\n', COORD_TYPE mode=COORD_DEFAULT) const
void from_json(const jsonParser &json)
Definition: Cluster.hh:258
GenericCluster< CoordType > operator+(const GenericCluster< CoordType > &LHS, const Coordinate &RHS)
create translated cluster
GenericCluster & operator-=(const Coordinate &RHS)
GenericCluster< CoordType > operator-(const GenericCluster< CoordType > &LHS, const Coordinate &RHS)
create translated cluster
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:33
GenericCluster(const Lattice &init_home)
Definition: Cluster_impl.hh:9
void set_lattice(const Lattice &new_home, COORD_TYPE mode)
Definition: Cluster_impl.hh:21
GenericCluster & permute(const Array< Index > &perm)
permute sites of the cluster, and everything that depends on the site order
Definition: Cluster_impl.hh:55
double tol
void print_shifted(std::ostream &stream, const Coordinate &shift, char delim= '\n', COORD_TYPE mode=COORD_DEFAULT) const
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
BasisSet operator*(const SymOp &LHS, const BasisSet &RHS)
Definition: BasisSet.cc:1154
void calc_properties()
gets max_length and min_length
Represents cartesian and fractional coordinates.
Definition: Coordinate.hh:34
GenericCluster & apply_sym_no_trans(const SymOp &op)
apply symmetry to all points of the cluster without translation
Definition: Cluster_impl.hh:85
SymGroup m_clust_group
Definition: Cluster.hh:204
EigenIndex Index
For long integer indexing:
GenericCluster operator+(const GenericCluster &RHS)
create translated cluster
std::vector< Permutation > clust_group_permutations(double tol) const
Finds the Permutation corresponding to each element of clust_group.
Coordinate geometric_center() const
Returns the geometric center of "mass" of a cluster (treats all sites as having equal mass) ...
GenericCluster & operator+=(const Coordinate &RHS)
in=place translation of a cluster
CoordType & at(Index ind)
Definition: Array.hh:157
SymGroup & _clust_group()
Definition: Cluster.hh:193
void update_data_members(const BasicStructure< CoordType > &ref_struc)
Definition: Cluster_impl.hh:33
void all_within()
Map every point of cluster inside unit cell.
CoordType WhichCoordType
Definition: Cluster.hh:37
bool is_equivalent(const GenericCluster &test_clust) const
are two clusters identical, to within permutation and translation
const Lattice & home() const
Definition: Cluster.hh:42
jsonParser & put_obj()
Puts new empty JSON object.
Definition: jsonParser.hh:276
void set_rep(const SymGroup &head_group, SymGroupRepID symrep_ID)
Definition: SymGroupRep.hh:261
SymGroupRep::RemoteHandle & _permute_rep()
Definition: Cluster.hh:197
GenericCluster & apply_sym(const SymOp &op)
apply symmetry to all points of the cluster
Definition: Cluster_impl.hh:74
Lattice const * m_lat_ptr
Definition: Cluster.hh:202
void generate_clust_group(const SymGroup &super_group, std::vector< Permutation > *perm_array_ptr=nullptr, double tol=TOL)
Finds the sub_group of super_group that is the point group of the cluster.
void read(std::istream &stream, int num_sites, COORD_TYPE mode, bool SD_is_on)
bool map_onto_subcluster(const GenericCluster &pivot, double tol=TOL)
void print_decorated_sites(std::ostream &stream, int space, char delim= '\n', COORD_TYPE mode=COORD_DEFAULT) const
void merge(const GenericCluster &RHS)
adds unique points of 'RHS' to (*this)
CoordType & back()
Definition: Array.hh:177
void within(Index pivot_ind=0)
Translate entire cluster so that point at(pivot_ind) is inside unit cell.
Basic std::vector like container (deprecated)
Index find(const CoordType &test_elem, double tol) const
is test_cluster a subcluster of (*this), and how do the indices map points of test_cluster ...
SymGroupRep::RemoteHandle m_permute_rep
Definition: Cluster.hh:205
bool operator==(const GenericCluster &RHS) const
are two clusters identical, to within a permutation
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)
void prepare_prototype()
Performs preparatory steps on prototype before doing Orbit::get_equivalent()
Definition: Cluster.hh:120
bool map_onto(const GenericCluster &test_clust, double tol)
if is_equivalent(test_clust) is true, return true and map (*this) onto test_clust ...
void print(std::ostream &stream, char delim= '\n', COORD_TYPE mode=COORD_DEFAULT) const
double max_length() const
Definition: Cluster.hh:108
bool contains(const GenericCluster &test_cluster) const
is test_cluster a subcluster of (*this)