22 bool found_value =
false;
23 for(
auto it = json.
begin(); it != json.
end(); ++it) {
24 if(it.name() ==
"energy_per_species") {
29 std::cerr <<
"Error reading chemical reference state: " << json << std::endl;
30 throw std::runtime_error(
"Error reading chemical reference: Input should not include vacancies");
37 std::cerr <<
"Error reading chemical reference state: " << json << std::endl;
38 throw std::runtime_error(
"Error reading chemical reference: No 'energy_per_species' found");
112 for(
int i = 0; i < ref.
global().size(); ++i) {
126 for(
int i = 0; i < it->second.size(); ++i) {
127 s_json[it->first].
push_back(it->second(i));
131 to_json(res->second, s_json[it->first]);
138 for(
auto it = ref.
config().begin(); it != ref.
config().end(); ++it) {
142 for(
int i = 0; i < it->second.size(); ++i) {
143 c_json[it->first].
push_back(it->second(i));
147 to_json(res->second, c_json[it->first]);
179 std::pair<Eigen::VectorXd, std::vector<ChemicalReferenceState> >
183 typedef std::pair<Eigen::VectorXd, std::vector<ChemicalReferenceState> > ReturnType;
191 for(
auto it = json.
begin(); it != json.
end(); ++it) {
195 result.second.push_back(r);
202 if(json.
begin()->is_number() || json.
begin()->is_int()) {
204 if(json.
size() != struc_mol_name.size()) {
205 std::cerr <<
"received: " << json << std::endl;
206 std::cerr <<
"expected size: " << struc_mol_name.
size() << std::endl;
207 throw std::runtime_error(
"Error in one_chemical_reference_from_json: Size mismatch with vector input.");
211 for(
int i = 0; i < json.
size(); ++i) {
212 result.first(i) = json[i].
get<
double>();
223 std::for_each(json.
begin(),
257 std::unique_ptr<ChemicalReference>
ref;
261 if(res.second.empty()) {
262 ref = notstd::make_unique<ChemicalReference>(prim, res.first);
265 ref = notstd::make_unique<ChemicalReference>(prim, res.second.begin(), res.second.end(),
tol);
268 if(json.
find(
"supercell") != json.
end()) {
269 for(
auto it = json[
"supercell"].begin(); it != json[
"supercell"].
end(); ++it) {
271 if(res.second.empty()) {
272 ref->set_supercell(it.name(), res.first);
275 ref->set_supercell(it.name(), res.second.begin(), res.second.end(),
tol);
280 if(json.
find(
"config") != json.
end()) {
281 for(
auto it = json[
"config"].begin(); it != json[
"config"].
end(); ++it) {
283 if(res.second.empty()) {
284 ref->set_config(it.name(), res.first);
287 ref->set_config(it.name(), res.second.begin(), res.second.end(),
tol);
292 return std::move(*ref);
size_type size() const
Returns array size if *this is a JSON array, object size if *this is a JSON object, 1 otherwise.
std::function< Eigen::VectorXd(const Configuration &)> InputFunction
double energy_per_species
Energy in this reference state.
void from_json(ClexDescription &desc, const jsonParser &json)
iterator end()
Returns iterator to end of JSON object or JSON array.
const std::map< std::string, Eigen::VectorXd > & supercell() const
const Access a map of scelname to reference for Supercell specialized references
bool is_vacancy(const std::string &name)
A vacancy is any Specie/Molecule with (name == "VA" || name == "va" || name == "Va") ...
Structure specifies the lattice and atomic basis of a crystal.
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
const RefStateMap & config_ref_states() const
const Access a map of configname to RefStateVec for Configuration specialized references ...
std::map< std::string, double > species_num
Map of Molecule name : number of each species in reference state.
iterator begin()
Returns const_iterator to beginning of JSON object or JSON array.
T get(Args...args) const
Get data from json, using one of several alternatives.
bool is_obj() const
Check if object type.
std::vector< std::string > get_struc_molecule_name() const
Returns an Array of each possible Molecule in this Structure.
const std::map< std::string, Eigen::VectorXd > & config() const
const Access a map of configname to reference for Configuration specialized references ...
std::pair< Eigen::VectorXd, std::vector< ChemicalReferenceState > > one_chemical_reference_from_json(const Structure &prim, const jsonParser &json)
Read chemical reference from one of 3 alternative forms.
Eigen::VectorXd & global()
Access the global reference.
static ReturnType from_json(const jsonParser &json)
Default from_json is equivalent to.
const Eigen::VectorXd & global() const
const Access the global reference
const RefStateVec & global_ref_states() const
const Access a map of configname to RefStateVec for Supercell specialized references ...
iterator find(const std::string &name)
Return iterator to JSON object value with 'name'.
jsonParser & put_obj()
Puts new empty JSON object.
Stores the composition and energy in a single reference state.
std::map< std::string, Eigen::VectorXd > & supercell()
Access a map of scelname to reference for Supercell specialized references.
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...
ChemicalReferenceState from_json< ChemicalReferenceState >(const jsonParser &json)
Read ChemicalReferenceState from: '{"A" : X, "B" : X, ..., "energy_per_species" : X }'...
const RefStateMap & supercell_ref_states() const
const Access a map of configname to RefStateVec for Supercell specialized references ...
std::map< std::string, Eigen::VectorXd > & config()
Access a map of configname to reference for Configuration specialized references. ...
const Structure & prim() const
Get primitive Structure.
jsonParser & put_array()
Puts new empty JSON array.
Maps a Configuration to a scalar value via a hyperplane.