CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Orbitree.hh
Go to the documentation of this file.
1 #ifndef ORBITREE_HH
2 #define ORBITREE_HH
3 
4 #include <iostream>
5 #include <fstream>
6 #include <complex>
7 
12 
13 namespace CASM {
14 
15  using Eigen::MatrixXcd;
16 
17 
18  //Orbitree is an (outer) array of N (inner) arrays of Orbit, where N-1 is the maximum number of sites of any cluster
19  //The n^th (inner) Array of Orbitree has all clusters that contain 'n' sites
20 
21  class Configuration;
22 
23  class Supercell;
24 
25  template<typename ClustType>
26  class GenericOrbitree;
27 
28  class SiteCluster;
29  typedef GenericOrbitree<SiteCluster> SiteOrbitree;
30 
31  class HopCluster;
32  typedef GenericOrbitree<HopCluster> HopOrbitree;
33 
34  template<typename ClustType>
35  class GenericOrbitree : public Array< GenericOrbitBranch<ClustType> > {
36  public:
37  using Array< GenericOrbitBranch<ClustType> > :: size;
38  using Array< GenericOrbitBranch<ClustType> > :: at;
39  using Array< GenericOrbitBranch<ClustType> > :: back;
40  using Array< GenericOrbitBranch<ClustType> > :: operator[];
41 
43 
44  double m_tol;
45  //generative properties of Orbitree
46 
48 
54  double min_length;
57 
64  mutable Index Norbits; // Brian: set this in get_index()
65 
69 
73  // ClustType phenom_clust;
74 
75  //BEGIN METHODS OF ORBITREE:
76 
77  GenericOrbitree<ClustType>(const Lattice &t_lat, double _tol) : lattice(t_lat), m_tol(_tol), min_length(TOL), m_asym_unit(lattice) { };
78  //John G 011013 COPY CONSTRUCTOR
80 
82  double tol() const;
83 
86  const GenericOrbit<ClustType> &orbit(Index np, Index no) const;
87 
89  const ClustType &prototype(Index np, Index no) const;
90  ClustType &prototype(Index np, Index no);
91 
93  const ClustType &equiv(Index np, Index no, Index ne) const;
94  ClustType &equiv(Index np, Index no, Index ne);
95 
97  Index size(Index np) const;
99  Index size(Index np, Index no) const;
100 
102  Index basis_set_size() const;
103 
104  const jsonParser &bspecs()const {
105  return m_bspecs;
106  }
107 
108  void set_bspecs(const jsonParser &_bspecs) {
109  m_bspecs = _bspecs;
110  }
111 
113  void resize(Index NP);
114 
117  void push_back(const GenericOrbit<ClustType> &new_orbit);
118 
120  void push_back(const GenericOrbitBranch<ClustType> &new_branch);
121 
123  void set_lattice(const Lattice &new_lat, COORD_TYPE mode);
124 
126  void get_index() const; //Done - Alex
127 
129  void sort(); //Done - Alex
131  void sort(Index np); //Done - Alex
132 
135  //void collect_basis_info(const Structure &struc, const Coordinate &shift);
136  void collect_basis_info(const Structure &struc);
137 
139  void get_s2s_vec();
140 
142  void generate_clust_bases(std::vector<BasisSet const *> const &global_args, Index max_poly_order = -1);
143  void generate_clust_bases(Index max_poly_order = -1);
144 
145  // Alex do these (there's already a placeholder for the first one):
147  Index find(const ClustType &test_clust) const;
148  Index find(const GenericOrbit<ClustType> &test_orbit) const;
149  Index find(const ClustType &test_clust, Index nb) const;
150 
152  bool contains(const ClustType &test_clust);
154  bool contains(const GenericOrbit<ClustType> &test_orbit);
155  //bool tmp_contains(const ClustType &test_clust);
156 
157  //Finds all the clusters of a structure, based on the generative properties
158  void generate_orbitree(const Structure &prim, bool verbose = false); //John
159  void generate_orbitree_TB(const Structure &prim); //AAB
160  void generate_orbitree(const Structure &prim, const int maxClust); //Anirudh
161  void generate_orbitree_neighbour(const Structure &prim, const Array<int> maxNeighbour); //Anirudh
162 
163  void generate_decorated_orbitree(const GenericOrbitree<ClustType> &in_tree, const SymGroup &symgroup, PERIODICITY_TYPE ptype, bool full_decor = false); //Brian
164  void generate_hop_orbitree(const GenericOrbitree<SiteCluster> &in_tree, const Structure &prim); //Brian
165 
166  void generate_orbitree_from_proto_file(std::string filename, const SymGroup &sym_group, PERIODICITY_TYPE ptype);
167 
168  //Finds the shortest non-overlapping clusters within a supercell
169  void generate_in_cell(const Structure &prim, const Lattice &cell, int num_images = 0); //John
170 
171  //Finds all the clusters around a phenomenal cluster
172  //void generate_local_orbitree(const ClustType &phenomenal_clust, const Structure &prim); //John
173 
174  //Get clusters of size 'num_sites' radiating from each site in the basis
175  void get_clusters_by_site(const GenericOrbitree<ClustType> &in_tree, GenericOrbitree<ClustType> &out_tree, int num_sites);
176 
177 
178  //finds the subclusters of a given cluster
179  void get_hierarchy() const; //Ivy
180 
181  void read(std::istream &stream, int num_sites, COORD_TYPE mode);
182  void read(std::istream &stream, COORD_TYPE mode);
183 
184  void read_CSPECS(std::istream &stream); //Added by Ivy -- temporary?
185 
186 
187  void print(std::ostream &stream) const;
188 
189  void write_full_clust(std::string file) const;
190  void write_proto_clust(std::string file) const;
191  void write_full_decorated_clust(std::string file) const;
192  void write_proto_decorated_clust(std::string file) const;
193 
194  void print_full_clust(std::ostream &out) const;
195  void print_full_basis_info(std::ostream &out) const;
196  void print_proto_clust(std::ostream &out) const;
197  void print_proto_clust_funcs(std::ostream &out) const;
198  void print_full_decorated_clust(std::ostream &out) const;
199  void print_proto_decorated_clust(std::ostream &out) const;
200 
201  void write_eci_in(std::string filename) const;
202  void print_eci_in(std::ostream &out) const;
203 
204  //Array <double> calc_correlations(Supercell super_calc);
205 
206  void get_dynamical_matrix(MatrixXcd &dmat, const Coordinate &k, Index bands_per_site);
207 
208  void apply_sym(const SymOp &op);
209  template<class PhenomType> void generate_local_orbitree(const Structure &prim, const PhenomType &tmp_phenom_clust, bool include_phenom_clust_sites);
210 
211  void trans_and_expand(const Array<Coordinate> &prim_grid, bool override = 0);
212 
214 
215 
216  //jsonParser &to_json(jsonParser &json) const;
217 
218  void from_json(const jsonParser &json);
219  void read_orbitree_from_json(const std::string &json_file_name, const SymGroup &sym_group, const Structure &ref_struc);
221  const Structure &struc,
222  const SymGroup &sym_group,
223  bool verbose = false);
224 
225  void add_subclusters(const ClustType &big_clust, const Structure &prim, bool verbose = false);
226 
228  return m_asym_unit;
229  }
230 
231  private:
232  void _generate_asym_unit(const Structure &prim);
233  void _populate_site_bases();
235  return m_asym_unit;
236  }
237 
238  // Asymmetric unit
240 
241  // m_asym_unit[m_b2asym[b][0]] gives the orbit that contains basis site 'b'
242  // m_asym_unit[m_b2asym[b][0]][m_b2asym[b][1]] gives the equivalent cluster that contains basis site 'b'
244 
245  // BSPECS.JSON used to generate this orbitree
247  };
248 
249  template<typename ClustType>
250  std::ostream &operator<< (std::ostream &stream, const GenericOrbitree<ClustType> &orbitree);
251 
252  /*
253  template<typename ClustType>
254  jsonParser &to_json(const GenericOrbitree<ClustType> &tree, jsonParser &json) {
255  return tree.to_json(json);
256  }
257  */
258 
260  template<typename ClustType>
262  tree.from_json(json);
263  }
264 
278  template<typename OutputIterator, typename TreeType, typename StrucType>
279  OutputIterator orbit_neighborhood(OutputIterator result, const TreeType &tree, const StrucType &struc, Index nb, Index no, double tol) {
280  // create a neighborhood of all UnitCellCoord that an Orbitree touches
281  for(int nc = 0; nc < tree[nb][no].size(); ++nc) {
282  const auto &clust = tree[nb][no][nc];
283 
284  // UnitCellCoord for sites in cluster
285  std::vector<UnitCellCoord> coord;
286  for(int ns_i = 0; ns_i < clust.size(); ++ns_i) {
287  coord.emplace_back(clust[ns_i], struc, tol);
288  }
289  // UnitCellCoord for 'flowertree': all clusters that touch origin unitcell
290  // (includes translationally equivalent clusters)
291  for(int ns_i = 0; ns_i < coord.size(); ++ns_i) {
292  for(int ns_j = 0; ns_j < coord.size(); ++ns_j) {
293  *result++ = UnitCellCoord(coord[ns_j].sublat(), coord[ns_j].unitcell() - coord[ns_i].unitcell());
294  }
295  }
296  }
297  return result;
298  }
299 
313  template<typename OutputIterator, typename TreeType, typename StrucType>
314  OutputIterator neighborhood(OutputIterator result, const TreeType &tree, const StrucType &struc, double tol) {
315  // create a neighborhood of all UnitCellCoord that an Orbitree touches
316  for(int nb = 0; nb < tree.size(); ++nb) {
317  for(int no = 0; no < tree[nb].size(); ++no) {
318  result = orbit_neighborhood(result, tree, struc, nb, no, tol);
319  }
320  }
321  return result;
322  }
323 
324 };
326 #endif
void print_eci_in(std::ostream &out) const
Array< Array< int > > index
Definition: Orbitree.hh:63
Array< Array< int > > subcluster
Definition: Orbitree.hh:68
void generate_decorated_orbitree(const GenericOrbitree< ClustType > &in_tree, const SymGroup &symgroup, PERIODICITY_TYPE ptype, bool full_decor=false)
void apply_sym(const SymOp &op)
void from_json(ClexDescription &desc, const jsonParser &json)
void generate_in_cell(const Structure &prim, const Lattice &cell, int num_images=0)
void write_proto_clust(std::string file) const
Array< int > index_to_row
Definition: Orbitree.hh:62
void set_lattice(const Lattice &new_lat, COORD_TYPE mode)
sets lattice=new_lat and also updates all OrbitBranches, Orbits, and Clusters
void get_clusters_by_site(const GenericOrbitree< ClustType > &in_tree, GenericOrbitree< ClustType > &out_tree, int num_sites)
void read(std::istream &stream, int num_sites, COORD_TYPE mode)
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:29
void generate_orbitree_neighbour(const Structure &prim, const Array< int > maxNeighbour)
Unit Cell Coordinates.
void read_CSPECS(std::istream &stream)
void generate_hop_orbitree(const GenericOrbitree< SiteCluster > &in_tree, const Structure &prim)
Main CASM namespace.
Definition: complete.cpp:8
GenericOrbitree< ClustType > & operator=(const GenericOrbitree< ClustType > &RHS)
void write_full_clust(std::string file) const
Index find(const ClustType &test_clust) const
If cluster/orbit exists in current orbitree, return its linear index; else, return number of orbits i...
const double TOL
void push_back(const GenericOrbit< ClustType > &new_orbit)
void generate_local_orbitree(const Structure &prim, const PhenomType &tmp_phenom_clust, bool include_phenom_clust_sites)
Constructs a local orbitree about a Phenom Cluster, given a Structure.
void get_index() const
Populates 'index', 'index_to_row' and 'index_to_column' Arrays.
void print_proto_clust_funcs(std::ostream &out) const
Array< Array< Index > > m_b2asym
Definition: Orbitree.hh:243
void get_dynamical_matrix(MatrixXcd &dmat, const Coordinate &k, Index bands_per_site)
Index basis_set_size() const
Count number of basis functions at each orbit and sum result.
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:33
double tol
jsonParser m_bspecs
Definition: Orbitree.hh:246
GenericOrbitree< SiteCluster > SiteOrbitree
Definition: Clex.hh:14
bool read_custom_clusters_from_json(const jsonParser &json, const Structure &struc, const SymGroup &sym_group, bool verbose=false)
Add more orbits to Orbitree based on JSON input.
void print_proto_clust(std::ostream &out) const
const GenericOrbitBranch< ClustType > & _asym_unit() const
Definition: Orbitree.hh:234
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
void resize(Index NP)
Initialize NP orbitbranches in the Orbitree. Any existing orbits get deleted.
void write_full_decorated_clust(std::string file) const
Represents cartesian and fractional coordinates.
Definition: Coordinate.hh:34
void collect_basis_info(const Structure &struc)
EigenIndex Index
For long integer indexing:
GenericOrbitBranch< ClustType > m_asym_unit
Definition: Orbitree.hh:239
OutputIterator neighborhood(OutputIterator result, const TreeType &tree, const StrucType &struc, double tol)
Iterate over all sites in an orbitree and insert a UnitCellCoord.
Definition: Orbitree.hh:314
void print_full_basis_info(std::ostream &out) const
void set_bspecs(const jsonParser &_bspecs)
Definition: Orbitree.hh:108
Array< int > num_clusts
we don't use num_clusts yet. It might be a better way to specify how many clusters to enumerate ...
Definition: Orbitree.hh:56
void print_proto_decorated_clust(std::ostream &out) const
void get_s2s_vec()
Call get_s2s_vec on all clusters in orbitree.
void write_eci_in(std::string filename) const
Array< int > index_to_column
Definition: Orbitree.hh:62
GenericOrbitBranch< ClustType > & at(Index ind)
Definition: Array.hh:157
double tol() const
Access orbitree tolerance.
void generate_orbitree_from_proto_file(std::string filename, const SymGroup &sym_group, PERIODICITY_TYPE ptype)
void print_full_clust(std::ostream &out) const
void _generate_asym_unit(const Structure &prim)
void sort()
Calls 'sort()' on each OrbitBranch to sort Orbits by lengthscale.
void generate_orbitree(const Structure &prim, bool verbose=false)
const ClustType & prototype(Index np, Index no) const
Access prototype of orbit (np, no)
const ClustType & equiv(Index np, Index no, Index ne) const
Access equivalent cluster 'ne' of orbit (np, no)
void read_orbitree_from_json(const std::string &json_file_name, const SymGroup &sym_group, const Structure &ref_struc)
void generate_orbitree_TB(const Structure &prim)
void from_json(const jsonParser &json)
Assumes the pivot lattice is already set.
Array< double > max_length
Definition: Orbitree.hh:51
void write_proto_decorated_clust(std::string file) const
GenericOrbit< ClustType > & orbit(Index np, Index no)
Access orbits using 2-D indexing.
void print_full_decorated_clust(std::ostream &out) const
void trans_and_expand(const Array< Coordinate > &prim_grid, bool override=0)
void get_hierarchy() const
void generate_clust_bases(std::vector< BasisSet const * > const &global_args, Index max_poly_order=-1)
get clust_basis for all equivalent clusters
GenericOrbitBranch< ClustType > & back()
Definition: Array.hh:177
OutputIterator orbit_neighborhood(OutputIterator result, const TreeType &tree, const StrucType &struc, Index nb, Index no, double tol)
Iterate over all sites in an orbit and insert a UnitCellCoord.
Definition: Orbitree.hh:279
GenericOrbitree< HopCluster > HopOrbitree
bool contains(const ClustType &test_clust)
If cluster exists in current orbitree, return true.
void print(std::ostream &stream) const
const GenericOrbitBranch< ClustType > & asym_unit() const
Definition: Orbitree.hh:227
void add_subclusters(const ClustType &big_clust, const Structure &prim, bool verbose=false)
Adding in subclusters of a specific cluster into *this Orbitree.
const jsonParser & bspecs() const
Definition: Orbitree.hh:104