CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Molecule.cc
Go to the documentation of this file.
2 
3 #include "casm/symmetry/SymOp.hh"
4 
6 
7 namespace CASM {
8 
9 
10  jsonParser &to_json(const Specie &specie, jsonParser &json) {
11  json.put_obj();
12  json["name"] = specie.name;
13  json["mass"] = specie.mass;
14  json["magmom"] = specie.magmom;
15  json["U"] = specie.U;
16  json["J"] = specie.J;
17  return json;
18  }
19 
20  void from_json(Specie &specie, const jsonParser &json) {
21  try {
22  from_json(specie.name, json["name"]);
23  from_json(specie.mass, json["mass"]);
24  from_json(specie.magmom, json["magmom"]);
25  from_json(specie.U, json["U"]);
26  from_json(specie.J, json["J"]);
27  }
28  catch(...) {
30  throw;
31  }
32  }
33 
34  //****************************************************
35 
36  //****************************************************
40  //****************************************************
41 
42  bool AtomPosition::operator==(const AtomPosition &RHS) const {
43  return specie == RHS.specie && Coordinate::operator==(RHS);
44 
45 
46  }
47 
48  //****************************************************
52  //****************************************************
53 
54  void AtomPosition::print(std::ostream &stream, const Coordinate &trans, int spaces, bool SD_is_on) const {
55  for(int i = 0; i < spaces; i++) {
56  stream << ' ';
57  }
58 
59  (Coordinate(*this) + trans).print(stream);
60 
61  if(SD_is_on) {
62  for(int i = 0; i < 3; i++) {
63  if(SD_flag[i]) stream << " T";
64  else stream << " F";
65  }
66  }
67 
68  stream << " " << specie.name; // << '\n';
69 
70  return;
71  }
72 
73  //****************************************************
77  //****************************************************
78 
81  return *this;
82  }
83 
84  //****************************************************
88  //****************************************************
89 
92  return *this;
93  }
94 
95 
96  jsonParser &to_json(const AtomPosition &apos, jsonParser &json) {
97  json.put_obj();
98  json["coordinate"].put<Coordinate>(apos);
99  json["specie"] = apos.specie;
100  json["SD_flag"] = apos.SD_flag;
101  return json;
102  }
103 
104  // Lattice must be set separately
105  void from_json(AtomPosition &apos, const jsonParser &json) {
106  try {
107  Coordinate &coord_ref = apos;
108  from_json(coord_ref, json["coordinate"]);
109  from_json(apos.specie, json["specie"]);
110  from_json(apos.SD_flag, json["SD_flag"]);
111  }
112  catch(...) {
114  throw;
115  }
116  }
117 
118 
119 
120  //****************************************************
126  //****************************************************
127 
129  // TODO: Is this the right way to apply_sym?
130 
131  center.apply_sym(op);
132  for(Index i = 0; i < size(); i++) {
133  //using apply_sym from Atomposition
134  //since AtomPosition inherits from Coordinate
135  at(i).apply_sym(op);
136  }
137  return *this;
138  }
139 
140  //****************************************************
146  //****************************************************
147 
149  // TODO: Is this the right way to apply_sym?
150 
152 
153  for(Index i = 0; i < size(); i++) {
154  //using apply_sym from Coordinate
155  //since AtomPosition inherits from Coordinate
156  at(i).apply_sym_no_trans(op);
157  }
158  return *this;
159  }
160 
161 
162  //****************************************************
166  //****************************************************
167 
168  void Molecule::set_lattice(const Lattice &new_lat, COORD_TYPE invariant_mode) {
169  m_home = &new_lat;
170  center.set_lattice(new_lat, invariant_mode);
171 
172  for(Index i = 0; i < size(); i++) {
173  at(i).set_lattice(new_lat, invariant_mode);
174  }
175  };
176 
177  //****************************************************
181  //****************************************************
182  //TODO:
183  bool Molecule::operator==(const Molecule &RHS) const {
184 
185  Index i, j;
186  if(center != RHS.center)
187  return false;
188 
189  for(i = 0; i < RHS.size(); i++) {
190 
191  for(j = 0; j < size(); j++) {
192  if(RHS.at(i) == at(j))
193  break;
194  }
195 
196  if(j == size())
197  return false;
198  }
199  return true;
200  }
201 
202  //****************************************************
206  //****************************************************
207  bool Molecule::contains(const std::string &name) const {
208  for(Index i = 0; i < size(); i++)
209  if(at(i).specie.name == name)
210  return true;
211  return false;
212  }
213 
214  //****************************************************
218  //****************************************************
219 
220  void Molecule::print(std::ostream &stream, const Coordinate &trans, int spaces, char delim, bool SD_is_on) const {
221  for(Index i = 0; i < size(); i++) {
222  at(i).print(stream, trans, spaces, SD_is_on);
223  stream << delim;
224  }
225  return;
226  }
227 
228  //****************************************************
232  //****************************************************
233 
235  json.put_obj();
236  const Array<AtomPosition> &apos_array_ref = (*this);
237  json["atomposition"] = apos_array_ref;
238  if(point_group.size() > 0) {
239  json["point_group"] = point_group;
240  }
241  json["center"] = center;
242  json["name"] = name;
243  return json;
244  }
245 
246  //****************************************************
250  //****************************************************
251 
252  void Molecule::from_json(const jsonParser &json) {
253 
254  try {
255 
256  AtomPosition apos(*home());
257  for(int i = 0; i < json["atomposition"].size(); i++) {
258  CASM::from_json(apos, json["atomposition"][i]);
259  push_back(apos);
260  }
261 
262  point_group.clear();
263  if(json.contains("point_group")) {
264  for(int i = 0; i < json["point_group"].size(); i++) {
265  point_group.push_back(json["point_group"][i].get<SymOp>());
266  }
267  }
268  CASM::from_json(center, json["center"]);
269  CASM::from_json(name, json["name"]);
270  }
271  catch(...) {
273  throw;
274  }
275  }
276 
277 
279  Molecule make_atom(std::string atom_name, const Lattice &lat) {
280  Molecule atom(lat);
281  atom.name = atom_name;
282  atom.push_back(AtomPosition(0.0, 0.0, 0.0, atom.name, lat, CART));
283  return atom;
284  }
285 
288  return make_atom("Va", lat);
289  }
290 
298  bool is_molecule_name(const Molecule &mol, std::string name) {
299  return (is_vacancy(mol.name) && is_vacancy(name)) || (mol.name == name);
300  }
301 
302  jsonParser &to_json(const Molecule &mol, jsonParser &json) {
303  return mol.to_json(json);
304  }
305 
306  // Lattice must be set separately
307  void from_json(Molecule &mol, const jsonParser &json) {
308  try {
309  mol.from_json(json);
310  }
311  catch(...) {
313  throw;
314  }
315  }
316 
317 };
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
Molecule & apply_sym(const SymOp &op)
Definition: Molecule.cc:128
double U
Definition: Molecule.hh:34
void from_json(ClexDescription &desc, const jsonParser &json)
Index size() const
Definition: Array.hh:145
Molecule & apply_sym_no_trans(const SymOp &op)
Definition: Molecule.cc:148
AtomPosition & apply_sym_no_trans(const SymOp &op)
Definition: Molecule.cc:90
double mass
Definition: Molecule.hh:34
bool is_vacancy(const std::string &name)
A vacancy is any Specie/Molecule with (name == "VA" || name == "va" || name == "Va") ...
Definition: Molecule.hh:27
bool operator==(const AtomPosition &RHS) const
Definition: Molecule.cc:42
void push_back(const AtomPosition &toPush)
void set_lattice(const Lattice &new_lat, COORD_TYPE invariant_mode)
Definition: Molecule.cc:168
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
Array< SymOp > point_group
Definition: Molecule.hh:104
bool is_molecule_name(const Molecule &mol, std::string name)
Return true if Molecule name matches 'name', including Va checks.
Definition: Molecule.cc:298
Main CASM namespace.
Definition: complete.cpp:8
Coordinate & apply_sym(const SymOp &op)
Transform coordinate by symmetry operation (including translation)
Definition: Coordinate.cc:216
void print(std::ostream &stream, const Coordinate &trans, int spaces, char delim, bool SD_is_on=false) const
Definition: Molecule.cc:220
Molecule make_atom(std::string atom_name, const Lattice &lat)
Return an atomic Molecule with specified name and Lattice.
Definition: Molecule.cc:279
bool contains(const std::string &name) const
Definition: Molecule.cc:207
double magmom
Definition: Molecule.hh:34
void clear()
Definition: Array.hh:216
void print(std::ostream &stream, const Coordinate &trans, int spaces, bool SD_is_on=false) const
Definition: Molecule.cc:54
jsonParser & to_json(jsonParser &json) const
Definition: Molecule.cc:234
double J
Definition: Molecule.hh:34
bool operator==(const Coordinate &RHS) const
Definition: Coordinate.cc:59
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
Represents cartesian and fractional coordinates.
Definition: Coordinate.hh:34
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:
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
AtomPosition & at(Index ind)
Definition: Array.hh:157
Lattice const * home() const
Definition: Molecule.hh:116
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
Return true if JSON object contains 'name'.
Definition: jsonParser.cc:500
bool operator==(const Molecule &RHS) const
Definition: Molecule.cc:183
Lattice const * m_home
Definition: Molecule.hh:102
Molecule make_vacancy(const Lattice &lat)
Return an vacancy Molecule with specified Lattice.
Definition: Molecule.cc:287
void from_json(const jsonParser &json)
Definition: Molecule.cc:252
std::string name
Definition: Molecule.hh:112
std::string name
Definition: Molecule.hh:33
Coordinate center
Definition: Molecule.hh:111
Coordinate(const Lattice &_home)
Minimal constructor only takes a lattice.
Definition: Coordinate.hh:46
AtomPosition & apply_sym(const SymOp &op)
Definition: Molecule.cc:79