CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Site.cc
Go to the documentation of this file.
2 
4 
6 
7 namespace CASM {
8 
9 
10  Site::Site(const Lattice &init_home) :
11  Coordinate(init_home), m_nlist_ind(-1), m_type_ID(-1), m_site_occupant(Array<Molecule>()) {
12  //site_occupant.set_value(0);
13  }
14 
15  //****************************************************
16 
17  Site::Site(const Coordinate &init_pos, const std::string &occ_name) :
18  Coordinate(init_pos), m_nlist_ind(-1), m_type_ID(-1), m_site_occupant(Array<Molecule>()) {
19 
20  Molecule tMol(home());
21  tMol.name = occ_name;
22  tMol.push_back(AtomPosition(0, 0, 0, occ_name, home(), CART));
23 
24  Array<Molecule> tocc;
25  tocc.push_back(tMol);
28 
29  return;
30  }
31 
33  Site::Site(const Coordinate &init_pos, std::initializer_list<Molecule> site_occ) :
34  Coordinate(init_pos), m_nlist_ind(-1), m_type_ID(-1) {
36  }
37 
38 
39  //****************************************************
40 
41  bool Site::is_vacant()const {
42  return site_occupant().is_specified()
44  }
45 
46  //****************************************************
47 
49  return m_nlist_ind;
50  };
51 
52  //****************************************************
53 
54  std::string Site::occ_name() const {
55  if(!site_occupant().is_specified())
56  return "?";
57  else
58  return site_occupant().get_occ().name;
59  }
60 
61  //****************************************************
62 
63  const Molecule &Site::occ() const {
64  return site_occupant().get_occ();
65  };
66 
67  //****************************************************
71  //****************************************************
72 
73  Site &Site::apply_sym(const SymOp &op) {
75  for(Index i = 0; i < site_occupant().size(); i++) {
76  m_site_occupant[i].apply_sym_no_trans(op);
77  }
78 
79  return *this;
80  }
81 
82  //****************************************************
86  //****************************************************
87 
90  for(Index i = 0; i < site_occupant().size(); i++) {
91  m_site_occupant[i].apply_sym_no_trans(op);
92  }
93 
94  return *this;
95  }
96 
97  //****************************************************
101  //****************************************************
102 
103  Site &Site::operator+=(const Coordinate &translation) {
104  Coordinate::operator += (translation);
105  return *this;
106  }
107 
108  //****************************************************
112  //****************************************************
113 
114  Site &Site::operator-=(const Coordinate &translation) {
115  Coordinate::operator -= (translation);
116  return *this;
117  }
118 
119  //*******************************************************************************************
123  //*******************************************************************************************
124 
125  bool Site::compare(const Coordinate &test_coord, double compare_tol) const {
126  return (min_dist(test_coord) < compare_tol);
127  }
128 
129  //*******************************************************************************************
133  //*******************************************************************************************
134 
135  bool Site::compare(const Site &test_site, double compare_tol) const {
136  return (compare_type(test_site) && min_dist(test_site) < compare_tol);
137  }
138 
139  //*******************************************************************************************
144  //*******************************************************************************************
145 
146  bool Site::compare(const Site &test_site, const Coordinate &shift, double compare_tol) const {
147 
148  return (compare_type(test_site)) && (min_dist(test_site + shift) < compare_tol);
149 
150  }
151 
152  //*******************************************************************************************
156  //*******************************************************************************************
157 
158  bool Site::compare_type(const Site &test_site) const {
159  assert(((site_occupant().size() <= 1 || test_site.site_occupant().size() <= 1)
160  || ((site_occupant().is_specified() && test_site.site_occupant().is_specified())
161  || (!site_occupant().is_specified() && !test_site.site_occupant().is_specified())))
162  && "In Site::compare_type() comparing initialized occupant to uninitialized occupant! This isn't a good idea!");
163 
164  return (_type_ID() == test_site._type_ID()) && site_occupant().value() == test_site.site_occupant().value();
165  }
166 
167  //*******************************************************************************************
168 
169  bool Site::operator==(const Site &test_site) const {
170  return (compare_type(test_site) && Coordinate::operator==(test_site));
171  }
172 
173  //*******************************************************************************************
174 
175  bool Site::almost_equal(const Site &test_site, double tol) const {
176  return (compare_type(test_site) && dist(test_site) < tol);
177  }
178 
179  //****************************************************
180 
181  bool Site::contains(const std::string &name) const {
182  for(Index i = 0; i < site_occupant().size(); i++)
183  if(site_occupant()[i].contains(name)) {
184  return true;
185  }
186  return false;
187  }
188 
189  //****************************************************
190 
191  bool Site::contains(const std::string &name, int &index) const {
192  for(Index i = 0; i < site_occupant().size(); i++)
193  if(site_occupant()[i].contains(name)) {
194  index = i;
195  return true;
196  }
197  return false;
198  }
199 
200  //****************************************************
201  //John G. This is to use with set_lattice from Coordinate
202  void Site::set_lattice(const Lattice &new_lat, COORD_TYPE invariant_mode) {
203  Coordinate::set_lattice(new_lat, invariant_mode);
204  for(Index i = 0; i < site_occupant().size(); i++) {
205  m_site_occupant[i].set_lattice(new_lat, invariant_mode);
206  }
207  return;
208  }
209 
210  //****************************************************
211 
213  Array<std::string> occ_list;
214  for(Index i = 0; i < site_occupant().size(); i++) {
215  occ_list.push_back(site_occupant()[i].name);
216  }
217  return occ_list;
218  }
219 
220  //****************************************************
221 
222  void Site::set_basis_ind(Index new_ind) {
223  Coordinate::set_basis_ind(new_ind);
224  }
225 
226  //****************************************************
227 
228  void Site::set_nlist_ind(Index new_ind) {
229  if(new_ind == m_nlist_ind)
230  return;
231 
232  m_site_occupant.set_ID(new_ind);
233 
234  //for(Index i = 0; i < displacement.size(); i++) {
235  //displacement[i].set_ID(new_ind);
236  //}
237  m_nlist_ind = new_ind;
238  return;
239  }
240 
241  //****************************************************
242  // read site, including all possible occupants
243  void Site::read(std::istream &stream, bool SD_is_on) {
244  char ch;
245 
246  Molecule tMol(home());
247  AtomPosition::sd_type SD_flag;
248 
250  if(SD_is_on) {
251  for(int i = 0; i < 3; i++) {
252  stream >> ch;
253  if(ch == 'T') {
254  SD_flag[i] = true;
255  }
256  else if(ch == 'F') {
257  SD_flag[i] = false;
258  }
259  }
260  }
261 
262  Array<Molecule> tocc;
263 
264  ch = stream.peek();
265  // while(ch != '\n' && !stream.eof()) {
266  while(ch != '\n' && ch != ':' && !stream.eof()) {
267  // while((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && ch != '\n' && !stream.eof()) {
268  while((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && ch != '\n' && ch != ':' && !stream.eof()) {
269  stream.ignore();
270  ch = stream.peek();
271  }
272  if(ch != '\n' && ch != ':' && !stream.eof()) {
273  //Need to change this part for real molecules
274  tMol.clear();
275  stream >> tMol.name;
276 
277 
278  tMol.push_back(AtomPosition(0, 0, 0, tMol.name, home(), CART, SD_flag));
279  tocc.push_back(tMol);
280  }
281  ch = stream.peek();
282  }
283 
284  if(ch == ':') {
285  stream.ignore();
286  stream.ignore();
287 
288  tMol.clear();
289  stream >> tMol.name;
290  tMol.push_back(AtomPosition(0, 0, 0, tMol.name, home(), CART, SD_flag));
291 
292  if(tocc.size()) {
294  Index index = tocc.size();
295  for(Index i = 0; i < tocc.size(); i++)
296  if(tocc[i].name == tMol.name) {
297  index = i;
298  break;
299  }
300  if(index == tocc.size()) {
301  std::cerr << "ERROR in Site::read(). Occupying molecule not listed in possible occupants" << std::endl;
302  std::cout << " occupying molecule name: " << tMol.name << " index: " << index << std::endl;
303  std::cout << " possible occupants: ";
304  for(Index i = 0; i < tocc.size(); i++)
305  std::cout << tocc[i].name << " ";
306  std::cout << " " << std::endl;
307  exit(1);
308  }
309  else
310  m_site_occupant.set_value(index);
311 
312  }
313  else {
314  std::cerr << "WARNING: Trying to read Site info, but no valid input was received." << std::endl;
315  }
316  m_type_ID = -1;
317  return;
318  }
319 
320  if(tocc.size()) {
322  }
323  else {
324  std::cerr << "WARNING: Trying to read Site info, but no valid input was received." << std::endl;
325  }
326  stream.ignore(1000, '\n');
327 
328  m_type_ID = -1;
329  return;
330  }
331 
332  //****************************************************
333  // read site, using 'elem' as site occupant domain
334  void Site::read(std::istream &stream, std::string &elem, bool SD_is_on) {
335  char ch;
336 
337  Molecule tMol(home());
338  AtomPosition::sd_type SD_flag;
339 
341  if(SD_is_on) {
342  for(int i = 0; i < 3; i++) {
343  stream >> ch;
344  if(ch == 'T') {
345  SD_flag[i] = true;
346  }
347  else if(ch == 'F') {
348  SD_flag[i] = false;
349  }
350  }
351  }
352 
353  Array<Molecule> tocc;
354 
355  tMol.clear();
356  tMol.name = elem;
357  tMol.push_back(AtomPosition(0, 0, 0, tMol.name, home(), CART, SD_flag));
358  tocc.push_back(tMol);
359 
360  if(tocc.size()) {
362  }
363  else {
364  std::cerr << "WARNING: Trying to read Site info, but no valid input was received." << std::endl;
365  }
366  stream.ignore(1000, '\n');
367 
368  m_type_ID = -1;
369  return;
370  }
371 
372 
373  //****************************************************
377  //****************************************************
378 
379  void Site::print(std::ostream &stream) const {
380  //site_occupant().get_occ().print(stream, *this, SD_is_on);
381  Coordinate::print(stream);
382  stream << " ";
383  site_occupant().print(stream);
384  stream << std::flush;
385 
386  return;
387  }
388 
389  //****************************************************
392  //****************************************************
393 
394  void Site::print_occ(std::ostream &stream) const {
395  //site_occupant().get_occ().print(stream, *this, SD_is_on);
396  Site::print(stream);
397  stream << " :: ";
398  site_occupant().print_occ(stream);
399  stream << std::flush;
400 
401  return;
402  }
403 
404  //****************************************************
408  //****************************************************
409 
410  void Site::print_mol(std::ostream &stream, int spaces, char delim, bool SD_is_on) const {
411  site_occupant().get_occ().print(stream, *this, spaces, delim, SD_is_on);
412  return;
413  }
414 
415  //****************************************************
416 
417  std::ostream &operator<< (std::ostream &stream, const Site &site) {
418  site.print(stream);
419  return stream;
420  }
421 
422  //\John G 011013
423 
424  void Site::update_data_members(const Site &_ref_site) {
425  // std::cout<<"Updating data members"<<std::endl;
426  m_site_occupant = _ref_site.site_occupant();
427  //displacement = _ref_site.displacement;
428 
430  //for(Index i = 0; i < displacement.size(); i++) {
431  //displacement[i].set_ID(m_nlist_ind);
432  //}
433  m_type_ID = -1;
434  return;
435  }
436 
437  //****************************************************
438 
440  json.put_obj();
441 
442  // class Site : public Coordinate
443  const Coordinate &coord = *this;
444  json["coordinate"].put(coord);
445 
446  // MoleculeOccupant site_occupant;
447  json["site_occupant"] = site_occupant();
448 
449  // int m_nlist_ind;
450  json["m_nlist_ind"] = m_nlist_ind;
451 
452 
453  return json;
454  }
455 
456  //****************************************************
457 
458  void Site::from_json(const jsonParser &json) {
459  try {
460 
461  // class Site : public Coordinate
462  Coordinate &coord = *this;
463  //std::cout<<"Trying to read in the Site"<<std::endl;
464  //std::cout<<"Reading in the Coordinate"<<std::endl;
465  CASM::from_json(coord, json["coordinate"]);
466 
467  Array<Molecule> temp_mol_array(1, Molecule(home()));
468  m_site_occupant.set_domain(temp_mol_array);
469  //std::cout<<"Reading in site_occupant"<<std::endl;
470  // MoleculeOccupant site_occupant;
471  CASM::from_json(m_site_occupant, json["site_occupant"]);
472 
473  //std::cout<<"Reading in m_list_ind"<<std::endl;
474  // int m_nlist_ind;
475  CASM::from_json(m_nlist_ind, json["m_nlist_ind"]);
476 
477  //std::cout<<"Finished Site::from_json"<<std::endl;
478 
479  }
480  catch(...) {
482  throw;
483  }
484  m_type_ID = -1;
485  };
486 
487  jsonParser &to_json(const Site &site, jsonParser &json) {
488  return site.to_json(json);
489  }
490 
491  void from_json(Site &site, const jsonParser &json) {
492  site.from_json(json);
493  }
494 
495  //*******************************************************************************************
496 
497  bool Site::_compare_type_no_ID(const Site &test_site) const {
498  //compare domain but not value
499  return site_occupant().compare(test_site.site_occupant(), false);
500  }
501 
502  //*******************************************************************************************
503 
505  if(!valid_index(m_type_ID)) {
506  for(m_type_ID = 0; m_type_ID < _type_prototypes().size(); m_type_ID++) {
508  return m_type_ID;
509  }
510  //std::cout << "NEW TYPE PROTOTYPE!\n";
511  //print_occ(std::cout);
512  //std::cout << " : TYPE_ID-> " << m_type_ID << "\n";
513  _type_prototypes().push_back(*this);
514  }
515  return m_type_ID;
516  }
517 
518  //****************************************************
519 
520  Site operator*(const SymOp &LHS, const Site &RHS) {
521  return Site(RHS).apply_sym(LHS);
522  }
523 
524  //****************************************************
525 
526  Site operator+(const Site &LHS, const Coordinate &RHS) {
527  return Site(LHS) += RHS;
528  }
529 
530  //****************************************************
531 
532  Site operator+(const Coordinate &LHS, const Site &RHS) {
533  return Site(RHS) += LHS;
534  }
535 
536 
537 
538 };
std::string occ_name() const
Name of current occupant (name of molecule, but for single atom, molecule name is species name) ...
Definition: Site.cc:54
void read(std::istream &stream, bool SD_is_on=false)
Definition: Site.cc:243
Coordinate & operator-=(const Coordinate &RHS)
Negative translation of this coordinate by RHS.cart()
Definition: Coordinate.cc:45
Index m_nlist_ind
Definition: Site.hh:107
Index m_type_ID
Definition: Site.hh:108
void set_domain(const Array< T > &new_dom)
Definition: DoF.hh:276
void set_ID(Index new_ID)
Definition: DoF.hh:75
Index _type_ID() const
Definition: Site.cc:504
void set_basis_ind(Index _basis_ind)
Set basis Index.
Definition: Coordinate.hh:185
void set_value(int new_state) override
Definition: DoF.hh:236
void from_json(ClexDescription &desc, const jsonParser &json)
jsonParser & to_json(jsonParser &json) const
Definition: Site.cc:439
Index size() const
Definition: Array.hh:145
bool is_specified() const
Definition: DoF.hh:140
bool almost_equal(const Site &test_site, double tol) const
Definition: Site.cc:175
void push_back(const T &toPush)
Definition: Array.hh:513
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
double dist(const Coordinate &neighbor) const
distance (in Angstr) of neighbor from *this
Definition: Coordinate.cc:146
const MoleculeOccupant & site_occupant() const
Definition: Site.hh:24
OccupantDoF< Molecule > MoleculeOccupant
Definition: Molecule.hh:22
void from_json(const jsonParser &json)
Definition: Site.cc:458
void set_lattice(const Lattice &new_lat, COORD_TYPE mode)
Definition: Site.cc:202
Main CASM namespace.
Definition: complete.cpp:8
Coordinate & apply_sym(const SymOp &op)
Transform coordinate by symmetry operation (including translation)
Definition: Coordinate.cc:216
bool _compare_type_no_ID(const Site &test_site) const
Definition: Site.cc:497
void print(std::ostream &stream, const Coordinate &trans, int spaces, char delim, bool SD_is_on=false) const
Definition: Molecule.cc:220
void print_occ(std::ostream &out) const
Definition: DoF.hh:310
Array< std::string > allowed_occupants() const
Definition: Site.cc:212
GenericCluster< CoordType > operator+(const GenericCluster< CoordType > &LHS, const Coordinate &RHS)
create translated cluster
bool compare(const Coordinate &test_coord, double compare_tol=TOL) const
Definition: Site.cc:125
const Molecule & occ() const
Definition: Site.cc:63
void set_basis_ind(Index)
set basis_ind of site and its occupant functions
Definition: Site.cc:222
double tol
Site & operator+=(const Coordinate &translation)
Definition: Site.cc:103
void clear()
Definition: Array.hh:216
void print(std::ostream &stream) const
Definition: Site.cc:379
double min_dist(const Coordinate &neighbor) const
Returns distance (in Angstr) to nearest periodic image of neighbor.
Definition: Coordinate.cc:155
std::ostream & operator<<(std::ostream &_stream, const FormattedPrintable &_formatted)
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
static Array< Site > & _type_prototypes()
Definition: Site.hh:101
BasisSet operator*(const SymOp &LHS, const BasisSet &RHS)
Definition: BasisSet.cc:1154
void print(std::ostream &out) const
Definition: DoF.hh:301
Represents cartesian and fractional coordinates.
Definition: Coordinate.hh:34
Index nlist_ind() const
access m_nlist_ind
Definition: Site.cc:48
MoleculeOccupant m_site_occupant
Definition: Site.hh:117
Coordinate & apply_sym_no_trans(const SymOp &op)
Transform coordinate by symmetry operation (without translation)
Definition: Coordinate.cc:226
EigenIndex Index
For long integer indexing:
bool compare_type(const Site &test_site) const
Definition: Site.cc:158
bool is_vacant() const
Checks if current occupant is a vacancy.
Definition: Site.cc:41
void print(std::ostream &stream, COORD_TYPE mode, char term=0, int prec=7, int pad=5) const
Definition: Coordinate.cc:112
void print_occ(std::ostream &stream) const
Definition: Site.cc:394
Coordinate & operator+=(const Coordinate &RHS)
Positive translation of this coordinate by RHS.cart()
Definition: Coordinate.cc:38
Index size() const override
Definition: DoF.hh:297
void read(std::istream &stream, COORD_TYPE mode)
Definition: Coordinate.cc:92
void set_lattice(const Lattice &new_lat, COORD_TYPE mode)
Change the home lattice of the coordinate, selecting one representation (either CART or FRAC) that re...
Definition: Coordinate.cc:245
int value() const
Definition: DoF.hh:149
void set_nlist_ind(Index)
set m_nlist_ind of Site and its DoFs
Definition: Site.cc:228
Site & apply_sym_no_trans(const SymOp &op)
Definition: Site.cc:88
bool operator==(const Site &test_site) const
Definition: Site.cc:169
const T & get_occ() const
Definition: DoF.hh:225
Site(const Lattice &init_home)
Definition: Site.cc:10
std::array< bool, 3 > sd_type
Definition: Molecule.hh:58
jsonParser & put_obj()
Puts new empty JSON object.
Definition: jsonParser.hh:276
jsonParser & put(const T &value)
Puts data of any type T for which 'jsonParser& to_json( const T &value, jsonParser &json)' is defined (same as 'o...
Definition: jsonParser.hh:761
bool contains(const std::string &name) const
Definition: Site.cc:181
bool is_vacancy() const
Definition: Molecule.hh:124
void print_mol(std::ostream &stream, int spaces, char delim, bool SD_is_on=false) const
Definition: Site.cc:410
void set_site_occupant(const MoleculeOccupant &new_dof)
Definition: Site.hh:61
Site & apply_sym(const SymOp &op)
Definition: Site.cc:73
const Lattice & home() const
Access the home lattice of the coordinate.
Definition: Coordinate.hh:195
std::string name
Definition: Molecule.hh:112
void update_data_members(const Site &_ref_site)
Definition: Site.cc:424
Basic std::vector like container (deprecated)
Site & operator-=(const Coordinate &translation)
Definition: Site.cc:114
bool compare(const OccupantDoF &RHS, bool compare_value) const
Definition: DoF.hh:257
bool valid_index(Index i)
static COORD_TYPE CHECK()
get the current mode (call using COORD_MODE::CHECK())