21 using xtal::BasicStructure;
22 using xtal::COORD_MODE;
23 using xtal::Coordinate;
28 template <
bool IsConst>
33 const std::string &_prefix = std::string())
44 <<
"WARNING: Attempting to populate a const Structure/BasicStructure "
45 "from a JSON object. This is not allowed.\n";
54 template <
bool IsConst>
57 json[
"coord_mode"] =
"direct";
59 json[
"coord_mode"] =
"cartesian";
62 std::map<std::string, std::vector<Site> > site_map;
63 for (
Index i = 0; i < struc.basis().size(); i++)
64 site_map[struc.basis()[i].occ_name()].push_back(struc.basis()[i]);
69 json[m_prefix +
"lattice"] = struc.lattice();
70 auto it = site_map.
cbegin(), end_it = site_map.cend();
71 for (; it != end_it; ++it) {
72 json[
"atoms_per_type"].
push_back(it->second.size());
74 auto it2 = it->second.
cbegin(), end_it2 = it->second.cend();
75 for (; it2 != end_it2; ++it2) json[m_prefix +
"basis"].push_back(*it2);
80 template <
bool IsConst>
83 struc.
set_basis(std::vector<xtal::Site>());
89 if (tstr ==
"direct" || tstr ==
"Direct") mode =
FRAC;
97 for (
Index i = 0; i < json[
"atoms_per_type"].
size(); i++) {
99 for (
Index j = 0; j < json[
"atoms_per_type"][i].
get<
Index>(); j++) {
104 }
catch (
const std::exception &ex) {
105 throw std::runtime_error(
106 std::string(
"Unable to parse Structure/BasicStructure from JSON "
107 "object. One or more tags were improperly specified:\n") +
113 template <
bool IsConst>
119 template <
bool IsConst>
126 const std::string &prefix) {
131 const std::string &prefix) {
Used to construct a BasicStructure from a 'properties.calc.json' object.
CASM_TMP::ConstSwitch< IsConst, BasicStructure > StrucType
SimpleJSonSiteStructure(StrucType &_struc, const std::string &_prefix=std::string())
void from_json(const jsonParser &json) const
jsonParser & to_json(jsonParser &json) const
void _from_json(const BasicStructure &struc, const jsonParser &json) const
jsonParser & put_array()
Puts new empty JSON array.
const_iterator cbegin() const
Returns const_iterator to beginning of JSON object or JSON array.
BasicStructure specifies the lattice and atomic basis of a crystal.
void set_lattice(const Lattice &lattice, COORD_TYPE mode)
std::vector< Site > & set_basis()
const Lattice & lattice() const
void push_back(Site const &_site, COORD_TYPE mode=CART)
Manually set the basis sites.
static bool IS_FRAC()
Static method to check if mode is FRAC (call using COORD_MODE::IS_FRAC() )
Represents cartesian and fractional coordinates.
jsonParser & push_back(const T &value, Args &&... args)
T get(Args &&... args) const
Get data from json, using one of several alternatives.
typename std::conditional< IsConst, const T, T >::type ConstSwitch
SimpleJSonSiteStructure< true > simple_json(const BasicStructure &struc, const std::string &prefix)
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
void from_json(ClexDescription &desc, const jsonParser &json)
INDEX_TYPE Index
For long integer indexing: