16 template<
bool IsConst >
29 std::cerr <<
"WARNING: Attempting to populate a const Structure/BasicStructure from a JSON object. This is not allowed.\n";
39 template<
bool IsConst >
42 json[
"coord_mode"] =
"direct";
44 json[
"coord_mode"] =
"cartesian";
46 StrucType &struc(*m_struc_ptr);
47 std::map<std::string, std::vector<Site> > site_map;
48 for(
Index i = 0; i < struc.basis.size(); i++)
49 site_map[struc.basis[i].occ_name()].push_back(struc.basis[i]);
54 json[m_prefix +
"lattice"] = struc.lattice();
55 auto it = site_map.
cbegin(), end_it = site_map.cend();
56 for(; it != end_it; ++it) {
57 json[
"atoms_per_type"].
push_back(it->second.size());
59 auto it2 = it->second.
cbegin(), end_it2 = it->second.cend();
60 for(; it2 != end_it2; ++it2)
61 json[m_prefix +
"basis"].push_back(*it2);
66 template<
bool IsConst >
75 if(tstr ==
"direct" || tstr ==
"Direct")
84 for(
Index i = 0; i < json[
"atoms_per_type"].
size(); i++) {
86 for(
Index j = 0; j < json[
"atoms_per_type"][i].
get<
Index>(); j++) {
92 catch(
const std::exception &ex) {
93 throw std::runtime_error(std::string(
"Unable to parse Structure/BasicStructure from JSON object. One or more tags were improperly specified:\n") + ex.what());
99 template<
bool IsConst >
104 template<
bool IsConst >
size_type size() const
Returns array size if *this is a JSON array, object size if *this is a JSON object, 1 otherwise.
typename std::conditional< IsConst, const T, T >::type ConstSwitch
void from_json(ClexDescription &desc, const jsonParser &json)
void push_back(const T &toPush)
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
const Lattice & lattice() const
void set_lattice(const Lattice &lattice, COORD_TYPE mode)
T get(Args...args) const
Get data from json, using one of several alternatives.
Represents cartesian and fractional coordinates.
EigenIndex Index
For long integer indexing:
Array< CoordType > basis
Lattice vectors that specifies periodicity of the crystal.
static bool IS_FRAC()
Static method to check if mode is FRAC (call using COORD_MODE::IS_FRAC() )
SimpleJSonSiteStructure< true > simple_json(const BasicStructure< Site > &struc, const std::string &prefix)
void from_json(const jsonParser &json) const
CASM_TMP::ConstSwitch< IsConst, BasicStructure< Site > > StrucType
SimpleJSonSiteStructure(StrucType &_struc, const std::string &_prefix=std::string())
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...
void _from_json(const BasicStructure< Site > &struc, const jsonParser &json) const
const_iterator cbegin() const
Returns const_iterator to beginning of JSON object or JSON array.
jsonParser & put_array()
Puts new empty JSON array.
jsonParser & to_json(jsonParser &json) const