23 bool found_value =
false;
24 for (
auto it = json.
begin(); it != json.
end(); ++it) {
25 if (it.name() ==
"energy_per_species") {
29 std::cerr <<
"Error reading chemical reference state: " << json
31 throw std::runtime_error(
32 "Error reading chemical reference: Input should not include "
39 std::cerr <<
"Error reading chemical reference state: " << json
41 throw std::runtime_error(
42 "Error reading chemical reference: No 'energy_per_species' found");
109 if (
ref.global_ref_states().empty()) {
110 to_json(
ref.global().transpose(), json[
"global"]);
112 for (
int i = 0; i <
ref.global().size(); ++i) {
116 to_json(
ref.global_ref_states(), json[
"global"]);
119 if (
ref.supercell().size()) {
121 for (
auto it =
ref.supercell().begin(); it !=
ref.supercell().end(); ++it) {
122 auto res =
ref.supercell_ref_states().find(it->first);
123 if (res ==
ref.supercell_ref_states().end()) {
125 for (
int i = 0; i < it->second.size(); ++i) {
126 s_json[it->first].
push_back(it->second(i));
129 to_json(res->second, s_json[it->first]);
134 if (
ref.config().size()) {
136 for (
auto it =
ref.config().begin(); it !=
ref.config().end(); ++it) {
137 auto res =
ref.config_ref_states().find(it->first);
138 if (res ==
ref.config_ref_states().end()) {
140 for (
int i = 0; i < it->second.size(); ++i) {
141 c_json[it->first].
push_back(it->second(i));
144 to_json(res->second, c_json[it->first]);
176 std::pair<Eigen::VectorXd, std::vector<ChemicalReferenceState> >
179 typedef std::pair<Eigen::VectorXd, std::vector<ChemicalReferenceState> >
188 for (
auto it = json.
begin(); it != json.
end(); ++it) {
192 result.second.push_back(r);
197 if (json.
begin()->is_number()) {
198 if (json.
size() != struc_mol_name.size()) {
199 std::cerr <<
"received: " << json << std::endl;
200 std::cerr <<
"expected size: " << struc_mol_name.
size() << std::endl;
201 throw std::runtime_error(
202 "Error in one_chemical_reference_from_json: Size mismatch with "
207 for (
int i = 0; i < json.
size(); ++i) {
208 result.first(i) = json[i].
get<
double>();
220 result.second.push_back(json.get<ChemicalReferenceState>());
248 std::unique_ptr<ChemicalReference>
ref;
252 if (res.second.empty()) {
253 ref = notstd::make_unique<ChemicalReference>(prim, res.first);
255 ref = notstd::make_unique<ChemicalReference>(prim, res.second.begin(),
256 res.second.end(), tol);
259 if (json.
find(
"supercell") != json.
end()) {
260 for (
auto it = json[
"supercell"].begin(); it != json[
"supercell"].
end();
263 if (res.second.empty()) {
264 ref->set_supercell(it.name(), res.first);
266 ref->set_supercell(it.name(), res.second.begin(), res.second.end(),
272 if (json.
find(
"config") != json.
end()) {
273 for (
auto it = json[
"config"].begin(); it != json[
"config"].
end(); ++it) {
275 if (res.second.empty()) {
276 ref->set_config(it.name(), res.first);
278 ref->set_config(it.name(), res.second.begin(), res.second.end(), tol);
283 return std::move(*
ref);
std::function< Eigen::VectorXd(const Configuration &)> InputFunction
Maps a Configuration to a scalar value via a hyperplane.
iterator begin()
Returns const_iterator to beginning of JSON object or JSON array.
iterator end()
Returns iterator to end of JSON object or JSON array.
jsonParser & put_obj()
Puts new empty JSON object.
iterator find(const std::string &name)
Return iterator to JSON object value with 'name'.
jsonParser & put_array()
Puts new empty JSON array.
bool is_obj() const
Check if object type.
BasicStructure specifies the lattice and atomic basis of a crystal.
bool is_vacancy(const std::string &name)
A vacancy is any Specie/Molecule with (name == "VA" || name == "va" || name == "Va")
std::vector< std::string > struc_molecule_name(BasicStructure const &_struc)
Returns an Array of each possible Molecule in this Structure.
jsonParser & push_back(const T &value, Args &&... args)
T get(Args &&... args) const
Get data from json, using one of several alternatives.
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
std::pair< Eigen::VectorXd, std::vector< ChemicalReferenceState > > one_chemical_reference_from_json(xtal::BasicStructure const &prim, jsonParser const &json)
Read chemical reference from one of 3 alternative forms.
void from_json(ClexDescription &desc, const jsonParser &json)
ChemicalReferenceState from_json< ChemicalReferenceState >(const jsonParser &json)
Read ChemicalReferenceState from: '{"A" : X, "B" : X, ..., "energy_per_species" : X }'.
Stores the composition and energy in a single reference state.
std::map< std::string, double > species_num
Map of Molecule name : number of each species in reference state.
double energy_per_species
Energy in this reference state.
static ReturnType from_json(const jsonParser &json)
Default from_json is equivalent to.