CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
OccCandidate.cc
Go to the documentation of this file.
5 #include "casm/clex/Supercell.hh"
6 
7 namespace CASM {
8 
9  namespace Monte {
10 
11  jsonParser &to_json(const OccCandidate &cand, const Conversions &convert, jsonParser &json) {
12  json.put_obj();
13  json["asym"] = cand.asym;
14  json["spec"] = convert.species_name(cand.species_index);
15  return json;
16  }
17  }
18 
20  return Monte::OccCandidate(
21  json["asym"].get<Index>(),
22  convert.species_index(json["spec"].get<std::string>()));
23  }
24 
25  namespace Monte {
26 
27  std::ostream &operator<<(std::ostream &sout, std::pair<const OccCandidate &, const Conversions &> value) {
28  sout << "(" << value.second.species_name(value.first.species_index) << ", "
29  << value.first.asym << ")";
30  return sout;
31  }
32 
33  jsonParser &to_json(const OccSwap &swap, const Conversions &convert, jsonParser &json) {
34  jsonParser tmp;
35  json.put_array();
36  json.push_back(to_json(swap.cand_a, convert, tmp));
37  json.push_back(to_json(swap.cand_b, convert, tmp));
38  return json;
39  }
40  }
41 
43  return Monte::OccSwap(
46  }
47 
48  namespace Monte {
49 
50  std::ostream &operator<<(std::ostream &sout, std::pair<const OccSwap &, const Conversions &> value) {
51  sout << std::pair<const OccCandidate &, const Conversions &>(value.first.cand_a, value.second)
52  << " <-> " << std::pair<const OccCandidate &, const Conversions &>(value.first.cand_b, value.second);
53  return sout;
54  }
55 
56 
58 
59  // create set of 'candidate' asym / species pairs
60  m_candidate.clear();
61  for(Index asym = 0; asym < convert.asym_size(); ++asym) {
62 
63  // hard code allowed sublattices: >1 allowed occupant
64  if(convert.occ_size(asym) < 2) {
65  continue;
66  }
67 
68  // add candidates
69  for(Index i = 0; i < convert.occ_size(asym); ++i) {
70  m_candidate.push_back(OccCandidate(asym, convert.species_index(asym, i)));
71  }
72  }
73 
74  // create lookup table of asym, species_index -> candidate index,
75  // will return {Nasym, Nspecies} if {asym, species_index} not allowed
76  Index Nspecies = convert.species_size();
77  Index Nasym = convert.asym_size();
78  m_end = m_candidate.size();
79  std::vector<Index> unallowed(Nspecies, m_end);
80  m_species_to_cand_index = std::vector<std::vector<Index> >(Nasym, unallowed);
81 
82  Index index = 0;
83  for(const auto &cand : m_candidate) {
84  m_species_to_cand_index[cand.asym][cand.species_index] = index;
85  ++index;
86  }
87 
88  // make canonical and grand canonical swaps
89  _make_possible_swaps(convert);
90  }
91 
96 
97  // construct canonical and grand canonical swaps
98  m_canonical_swap.clear();
99  m_grand_canonical_swap.clear();
100 
101  // check that species are different and allowed on both sites
102  auto allowed_canonical_swap = [&](OccCandidate cand_a, OccCandidate cand_b) {
103  return cand_a.species_index != cand_b.species_index &&
104  convert.species_allowed(cand_a.asym, cand_b.species_index) &&
105  convert.species_allowed(cand_b.asym, cand_a.species_index);
106  };
107 
108  // check that asym is the same and species_index is different
109  auto allowed_grand_canonical_swap = [&](OccCandidate cand_a, OccCandidate cand_b) {
110  return cand_a.asym == cand_b.asym &&
111  cand_a.species_index != cand_b.species_index;
112  };
113 
114  // for each pair of candidates, check if they are allowed to swap
115  for(const auto &cand_a : m_candidate) {
116  for(const auto &cand_b : m_candidate) {
117 
118  // don't repeat a->b, b->a
119  // and check that cand_b's species is allowed on cand_a's sublat && vice versa
120  if(cand_a < cand_b && allowed_canonical_swap(cand_a, cand_b)) {
121  m_canonical_swap.push_back(OccSwap(cand_a, cand_b));
122  }
123 
124  // allow a->b, b->a
125  // check that asym is the same and species_index is different
126  if(allowed_grand_canonical_swap(cand_a, cand_b)) {
127  m_grand_canonical_swap.push_back(OccSwap(cand_a, cand_b));
128  }
129  }
130  }
131  }
132 
133  jsonParser &to_json(const OccCandidateList &list, const Conversions &convert, jsonParser &json) {
134  jsonParser tmp;
135 
136  json.put_obj();
137 
138  json["candidate"].put_array();
139  for(auto it = list.begin(); it != list.end(); ++it) {
140  json["candidate"].push_back(to_json(*it, convert, tmp));
141  }
142 
143  json["canonical_swap"].put_array();
144  for(auto it = list.canonical_swap().begin(); it != list.canonical_swap().end(); ++it) {
145  json["candidate_swap"].push_back(to_json(*it, convert, tmp));
146  }
147 
148  json["grand_canonical_swap"].put_array();
149  for(auto it = list.canonical_swap().begin(); it != list.canonical_swap().end(); ++it) {
150  json["grand_candidate_swap"].push_back(to_json(*it, convert, tmp));
151  }
152 
153  return json;
154  }
155 
156  std::ostream &operator<<(std::ostream &sout, std::pair<const OccCandidateList &, const Conversions &> value) {
157 
158  typedef std::pair<const OccCandidate &, const Conversions &> cand_pair;
159  typedef std::pair<const OccSwap &, const Conversions &> swap_pair;
160  const Conversions &convert = value.second;
161  const OccCandidateList &list = value.first;
162 
163  sout << "Unit cell for determining equivalent swaps: \n" <<
164  convert.unit_scel().get_transf_mat() << "\n\n";
165 
166  sout << "Asymmetric Unit: " << std::endl;
167  for(Index asym = 0; asym != convert.asym_size(); ++asym) {
168  sout << " " << asym << ": ";
169  for(Index i = 0; i != convert.occ_size(asym); ++i) {
170  sout << convert.species_name(convert.species_index(asym, i)) << " ";
171  }
172  sout << "\n";
173 
174  const auto &set = convert.asym_to_unitl(asym);
175  for(auto it = set.begin(); it != set.end(); ++it) {
176  sout << " " << convert.unitl_to_bijk(*it) << "\n";
177  }
178  }
179  sout << "\n";
180 
181  sout << "Candidates: (Species, AsymUnit)" << std::endl;
182  for(auto it = list.begin(); it != list.end(); ++it) {
183  sout << " " << cand_pair(*it, convert) << "\n";
184  }
185  sout << "\n";
186 
187  sout << "Canonical swaps: " << std::endl;
188  for(auto it = list.canonical_swap().begin(); it != list.canonical_swap().end(); ++it) {
189  sout << " " << swap_pair(*it, convert) << "\n";
190  }
191  sout << "\n";
192 
193  sout << "Grand canonical swaps: " << std::endl;
194  for(auto it = list.grand_canonical_swap().begin(); it != list.grand_canonical_swap().end(); ++it) {
195  sout << " " << cand_pair(it->cand_a, convert) << " -> " << cand_pair(it->cand_b, convert) << "\n";
196  }
197  sout << "\n";
198  return sout;
199  }
200 
201  }
202 
203 }
std::vector< OccSwap > m_grand_canonical_swap
vector of allowed grand canonical swaps
Index asym_size() const
Definition: Conversions.cc:107
const std::set< Index > & asym_to_unitl(Index asym) const
Definition: Conversions.cc:113
const_iterator begin() const
bool species_allowed(Index asym, Index species_index) const
Definition: Conversions.cc:134
void _make_possible_swaps(const Conversions &convert)
Construct m_canonical_swaps, m_grand_canonical_swaps.
Definition: OccCandidate.cc:95
const std::string & species_name(Index species_index) const
Definition: Conversions.cc:147
const std::vector< OccSwap > & canonical_swap() const
std::vector< OccSwap > m_canonical_swap
vector of allowed canonical swaps
OccCandidate cand_b
Definition: OccCandidate.hh:60
jsonParser & to_json(const CanonicalConditions &conditions, jsonParser &json)
Store CanonicalConditions in JSON format.
Definition: CanonicalIO.cc:102
Index species_size() const
Definition: Conversions.cc:138
Main CASM namespace.
Definition: complete.cpp:8
OccCandidate cand_a
Definition: OccCandidate.hh:59
std::vector< OccCandidate > m_candidate
ProjectSettings & set
Definition: settings.cc:103
T get(Args...args) const
Get data from json, using one of several alternatives.
Definition: jsonParser.hh:729
const_iterator end() const
void swap(ConfigDoF &A, ConfigDoF &B)
Definition: ConfigDoF.cc:195
EigenIndex Index
For long integer indexing:
Store swap type, mutating sites, and info for keeping OccLocation up-to-date.
Definition: OccCandidate.hh:51
static ReturnType from_json(const jsonParser &json)
Default from_json is equivalent to.
Definition: jsonParser.hh:489
UnitCellCoord unitl_to_bijk(Index unitl) const
Definition: Conversions.cc:100
List of asym / species_index pairs indicating allowed variable occupation dof.
Index m_end
Number of allowed candidates, what is returned if a candidate is not allowed.
Helper struct for constructing objects that need additional data.
Definition: jsonParser.hh:486
jsonParser & put_obj()
Puts new empty JSON object.
Definition: jsonParser.hh:276
jsonParser & push_back(const T &value)
Puts new valued element at end of array of any type T for which 'jsonParser& to_json( const T &value...
Definition: jsonParser.hh:696
Index index(const OccCandidate &cand) const
Return index into std::vector, or _candidate.size() if not allowed. ...
Index species_index(Index asym, Index occ_index) const
Definition: Conversions.cc:127
const Eigen::Matrix3i & get_transf_mat() const
Definition: Supercell.hh:263
std::vector< std::vector< Index > > m_species_to_cand_index
m_converter[asym][species_index] -> candidate_index
const Supercell & unit_scel() const
Definition: Conversions.cc:117
Index occ_size(Index asym) const
Definition: Conversions.cc:124
jsonParser & put_array()
Puts new empty JSON array.
Definition: jsonParser.hh:285
const std::vector< OccSwap > & grand_canonical_swap() const