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