63 if (coordinate_mode ==
FRAC) {
67 if (json.
contains(
"relaxed_energy")) {
71 if (json.
contains(
"relaxed_forces")) {
78 std::vector<Index> atoms_per_type =
79 json[
"atoms_per_type"].
get<std::vector<Index> >();
80 std::vector<std::string> atom_type =
81 json[
"atom_type"].
get<std::vector<std::string> >();
82 for (
Index i = 0; i < atoms_per_type.size(); ++i) {
83 for (
Index j = 0; j < atoms_per_type[i]; ++j) {
93 }
catch (
const std::exception &ex) {
95 ss <<
"Error parsing SimpleStructure from (legacy) JSON object. "
96 <<
"One or more tags were improperly specified:\n"
107 static jsonParser &_types_to_json(std::vector<std::string>
const &names,
109 std::set<std::string>
const &excluded_species,
110 std::vector<Index> &permute) {
112 for (
Index i = 0; i < names.size(); ++i) {
113 if (excluded_species.count(names[i]))
continue;
126 std::vector<Index>
const &permute,
129 for (
Index i : permute) {
130 tjson.
push_back(to_coord_mode_matrix * coords.col(i),
142 std::string field_name, std::vector<Index>
const &permute) {
145 for (
Index i : permute) {
153 static void _types_from_json(std::vector<std::string> &names,
154 jsonParser const &json, std::string field_name) {
162 std::string field_name,
165 coords = to_cartesian_matrix *
171 static void _properties_from_json(
173 std::set<std::string> allowed_field_names) {
174 for (std::string
const &field : allowed_field_names) {
175 auto it = json.
find(field);
176 if (it != json.
end()) {
177 for (
auto it2 = it->begin(); it2 != it->end(); ++it2) {
201 to_cartesian_matrix.setIdentity();
202 if (coordinate_mode ==
FRAC) {
207 ::_properties_from_json(simple_structure.
properties, json,
208 {
"global_dofs",
"global_vals"});
211 auto &atom_info = simple_structure.
atom_info;
212 ::_types_from_json(atom_info.names, json,
"atom_type");
213 ::_coords_from_json(atom_info.coords, json,
"atom_coords",
214 to_cartesian_matrix);
215 ::_properties_from_json(atom_info.properties, json,
216 {
"atom_dofs",
"atom_vals"});
219 auto &mol_info = simple_structure.
mol_info;
220 ::_types_from_json(mol_info.names, json,
"mol_type");
221 ::_coords_from_json(mol_info.coords, json,
"mol_coords", to_cartesian_matrix);
222 ::_properties_from_json(mol_info.properties, json, {
"mol_dofs",
"mol_vals"});
229 std::string info_type) {
231 std::stringstream ss;
232 ss << info_type <<
".coords.cols(): " << info.
coords.cols()
233 <<
" != " << info_type <<
".names.size(): " << info.
names.size();
237 for (
auto const &property_pair : info.
properties) {
238 if (info.
names.size() != property_pair.second.cols()) {
239 std::stringstream ss;
240 ss << info_type <<
".properties[" << property_pair.first
241 <<
"\"].cols(): " << property_pair.second.cols() <<
" != " << info_type
242 <<
".names.size(): " << info.
names.size();
327 std::set<std::string>
const &excluded_species,
331 if (coordinate_mode ==
FRAC) {
332 json[
"coord_mode"] =
"Direct";
335 json[
"coord_mode"] =
"Cartesian";
341 for (
auto const &dof : simple_structure.
properties) {
342 to_json_array(dof.second, json[
"global_dofs"][dof.first][
"value"]);
352 auto const &atom_info = simple_structure.
atom_info;
353 std::vector<Index> atom_permute;
354 ::_types_to_json(atom_info.names, json,
"atom_type", excluded_species,
356 ::_coords_to_json(atom_info.coords, json,
"atom_coords", atom_permute,
357 to_coord_mode_matrix);
358 ::_properties_to_json(atom_info.properties, json,
"atom_dofs", atom_permute);
361 auto const &mol_info = simple_structure.
mol_info;
362 std::vector<Index> mol_permute;
363 ::_types_to_json(atom_info.names, json,
"mol_type", excluded_species,
365 ::_coords_to_json(mol_info.coords, json,
"mol_coords", mol_permute,
366 to_coord_mode_matrix);
367 ::_properties_to_json(mol_info.properties, json,
"mol_dofs", mol_permute);
391 if (json.
contains(
"atoms_per_type")) {
392 ::_from_json_legacy(simple_structure, json);
394 ::_from_json_current(simple_structure, json);
398 ::_check_sizes(simple_structure.
atom_info,
"atom_info");
399 ::_check_sizes(simple_structure.
mol_info,
"mol_info");
401 }
catch (
const std::exception &ex) {
402 std::stringstream ss;
403 ss <<
"Error parsing SimpleStructure from JSON object. "
404 <<
"One or more tags were improperly specified:\n"
406 throw std::runtime_error(ss.str());
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
iterator end()
Returns iterator to end of JSON object or JSON array.
iterator find(const std::string &name)
Return iterator to JSON object value with 'name'.
jsonParser & put_array()
Puts new empty JSON array.
Representation of a crystal of molecular and/or atomic occupants, and any additional properties....
std::map< std::string, Eigen::MatrixXd > properties
Eigen::Matrix3d lat_column_mat
CASM::jsonParser & to_json_array(const Eigen::MatrixBase< Derived > &value, CASM::jsonParser &json)
Write Eigen Matrix with 1 row or 1 column to JSON array.
jsonParser & push_back(const T &value, Args &&... args)
T get(Args &&... args) const
Get data from json, using one of several alternatives.
ConfigIO::GenericConfigFormatter< jsonParser > properties()
IdentitySymRepBuilder Identity()
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
void from_json(ClexDescription &desc, const jsonParser &json)
INDEX_TYPE Index
For long integer indexing:
Struct to encode all information about the crystal basis Info may describe the basis in a atomic cont...
Eigen::MatrixXd coords
(3 x names.size()) matrix of coordinates. coords.col(i) is Cartesian coordinate of site 'i'
std::vector< std::string > names
names[i] is name of species that occupies sites 'i'
std::map< std::string, Eigen::MatrixXd > properties
map of [property name, (m x names.size()) matrix] for all numerical site properties properties are as...