CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
jsonClust.cc
Go to the documentation of this file.
2 
3 namespace CASM {
4 
5  void from_json(SiteClusterJsonHelper clust_helper, const jsonParser &json) {
6  SiteCluster &clust = clust_helper.value();
7  const Structure &struc = clust_helper.struc();
8  UnitCellCoord ucc;
9  // can throw
10  for(Index i = 0; i < json["sites"].size(); i++) {
11  from_json(ucc, json["sites"][i]);
12  clust.push_back(struc.get_site(ucc));
13  }
14 
15  }
16 
17  //*******************************************************************************************
18 
20  const SiteCluster &clust = clust_helper.value();
21  const Structure &struc = clust_helper.struc();
22 
23  json["min_length"] = clust.min_length(); // <-- not used for input, but useful for users
24  json["max_length"] = clust.max_length(); // <-- not used for input, but useful for users
25  json["sites"].put_array();
26  for(Index i = 0; i < clust.size(); i++) {
27  json["sites"].push_back(struc.get_unit_cell_coord(clust[i]));
28  }
29  return json;
30  }
31 
32  //*******************************************************************************************
34  jsonParser &to_json(const ConstSiteOrbitJsonHelper &orbit_helper, jsonParser &json) {
35  const SiteOrbit &orbit = orbit_helper.value();
36  const Structure &struc = orbit_helper.struc();
37 
38  json["prototype"] = jsonHelper(orbit.prototype, struc, orbit_helper.tol());
39  return json;
40 
41  }
42 
43  //*******************************************************************************************
44 
45  void from_json(SiteOrbitBranchJsonHelper branch_helper, const jsonParser &json) {
46  SiteOrbitBranch &branch = branch_helper.value();
47  const Structure &struc = branch_helper.struc();
48 
49  //can throw
50 
51  if(json.contains("pivot")) {
52  SiteCluster new_pivot(branch.pivot.home());
53  from_json(jsonHelper(new_pivot, struc), json["pivot"]);
54  branch.set_pivot(new_pivot);
55  }
56 
57  branch.reserve(json["orbits"].size());
58 
59  for(Index i = 0; i < json["orbits"].size(); i++) {
60  SiteCluster tproto(branch.pivot.home());
61  from_json(jsonHelper(tproto, struc), json["orbits"][i]["prototype"]);
62  tproto.calc_properties();
63  branch.push_back(SiteOrbit(tproto));
64  branch.back().get_equivalent(struc.factor_group(), branch_helper.tol());
65  }
66 
67 
68  }
69 
70  //*******************************************************************************************
71 
73  const SiteOrbitBranch &branch = branch_helper.value();
74  const Structure &struc = branch_helper.struc();
75 
76  if(branch.pivot.size())
77  json["pivot"] = jsonHelper(branch.pivot, struc);
78 
79  json["orbits"].put_array();
80  for(Index i = 0; i < branch.size(); i++) {
81  json["orbits"].push_back(jsonHelper(branch[i], struc, branch_helper.tol()));
82  }
83  return json;
84  }
85 
86  //*******************************************************************************************
87 
88  void from_json(SiteOrbitreeJsonHelper tree_helper, const jsonParser &json) {
89  SiteOrbitree &tree = tree_helper.value();
90  const Structure &struc = tree_helper.struc();
91  //tree.set_name(json["name"].get<std::string>());
92  //tree.set_cspecs(json["cspecs"]);
93  tree.set_lattice(json["lattice"].get<Lattice>(), CART);
94 
95  tree.resize(json["branches"].size());
96  for(Index i = 0; i < json["branches"].size(); i++) {
97  from_json(jsonHelper(tree[i], struc, tree.tol()), json["branches"][i]);
98  }
99  if(json.contains("bspecs")) {
100  tree.set_bspecs(json["bspecs"]);
101  }
102  tree.collect_basis_info(struc);
103  }
104 
105  //*******************************************************************************************
106 
108  const SiteOrbitree &tree = tree_helper.value();
109  const Structure &struc = tree_helper.struc();
110 
111  //json["name"] = tree.name();
112  //json["cspecs"] = tree.cspecs();
113  json["lattice"] = tree.lattice;
114  json["branches"].put_array();
115 
116  for(Index i = 0; i < tree.size(); i++) {
117  json["branches"].push_back(jsonHelper(tree[i], struc, tree.tol()));
118  }
119  json["bspecs"] = tree.bspecs();
120  return json;
121  }
122 
123 }
124 
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
ClustType prototype
Definition: Orbit.hh:47
ClustJsonHelper< ValueType > jsonHelper(ValueType &_value, const Structure &_struc, double tol=TOL)
Definition: jsonClust.hh:62
void from_json(ClexDescription &desc, const jsonParser &json)
Index size() const
Definition: Array.hh:145
void set_lattice(const Lattice &new_lat, COORD_TYPE mode)
sets lattice=new_lat and also updates all OrbitBranches, Orbits, and Clusters
double min_length() const
Definition: Cluster.hh:112
Structure specifies the lattice and atomic basis of a crystal.
Definition: Structure.hh:29
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
Unit Cell Coordinates.
void set_pivot(const ClustType &new_pivot)
Main CASM namespace.
Definition: complete.cpp:8
void push_back(const Site &new_site)
Definition: SiteCluster.cc:11
double tol() const
Definition: jsonClust.hh:30
void push_back(const GenericOrbit< ClustType > &new_orbit)
const MasterSymGroup & factor_group() const
Definition: Structure.cc:94
void resize(Index NP)
Initialize NP orbitbranches in the Orbitree. Any existing orbits get deleted.
void collect_basis_info(const Structure &struc)
EigenIndex Index
For long integer indexing:
ValueType & value()
Definition: jsonClust.hh:20
void set_bspecs(const jsonParser &_bspecs)
Definition: Orbitree.hh:108
GenericOrbit< SiteCluster > SiteOrbit
Definition: Orbit.hh:16
const Structure & struc() const
Definition: jsonClust.hh:26
double tol() const
Access orbitree tolerance.
CoordType get_site(const UnitCellCoord &ucc) const
UnitCellCoord get_unit_cell_coord(const CoordType2 &test_site, double tol=TOL) const
void reserve(Index new_max)
Definition: Array.hh:491
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
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
Definition: jsonParser.cc:500
Index size(Index no) const
How many equivalent clusters are int orbit 'no'.
T & back()
Definition: Array.hh:177
jsonParser & put_array()
Puts new empty JSON array.
Definition: jsonParser.hh:285
Index size(Index np) const
Number of orbits in OrbitBranch 'np'.
const jsonParser & bspecs() const
Definition: Orbitree.hh:104
double max_length() const
Definition: Cluster.hh:108