10 #include "../utils/runtime_error.h" 40 int weights_counter = 0;
44 for (
const auto &abst_bead : item.second)
46 const auto it_end = abst_bead.cend();
47 const auto it_index = abst_bead.find(
"indices-in-mol");
49 if (it_index == it_end)
52 "Mapping to beads must be specified by 'indices-in-mol'");
55 if (abst_bead.find(
"type") != it_end)
60 auto it_weights = abst_bead.find(
"weights");
62 if (it_weights != it_end)
64 if ((*it_index).size() != (*it_weights).size())
67 "The numbers of elements in 'indices-in-mol' and 'weights' " 78 std::pair<bool,bool> have_type_andor_weights = std::make_pair(
false,
false);
80 if (type_counter == counter)
83 have_type_andor_weights.first =
true;
85 else if (type_counter != 0)
90 if (weights_counter == counter)
93 have_type_andor_weights.second =
true;
95 else if (weights_counter != 0)
100 return have_type_andor_weights;
114 el_mols->check_required_keys(
"atom-ids");
116 auto &mols = el_mols->get_data();
120 for (
const auto &mol : mols)
122 auto &atom_ids = mol[
"atom-ids"];
125 for (
const auto &abst_bead : abst_beads)
127 data.push_back({{
"id", ++bead_id}, {
"mol", mol[
"id"]}});
129 auto &back = data.back();
131 auto &ids_ref = back[
"atom-ids"];
133 for (
const int &index : abst_bead[
"indices-in-mol"])
135 ids_ref.push_back(atom_ids.at(index));
138 if (have_type_andor_weights.first)
140 back[
"type"] = abst_bead[
"type"];
143 if (have_type_andor_weights.second)
145 back[
"atom-weights"] = abst_bead[
"weights"];
ShPtr< Element > ElPtr
An alias for a shared pointer of Element class.
StaBeads(const ElPtr &el_mols, const Vec< Json > &scheme)
Constructor of StaBeads class for molecules all of whose type property are 1, or molecules all of whi...
std::function< bool(const Json &)> JsonToBoolFunc
An alias for a function accepts a Json object and returns a bool.
nlohmann::json Json
Json is an alias for nlohmann::json.
This file has a definition of StaBeads class, which is a subclass of Starter class.
ShPtr< Generator > ext_generator
std::vector< T > Vec
Vec is an alias for vector (same as list in Python).
void runtime_error(const Str &msg)
Raise (for Python) and throw (for C++) a runtime error.
virtual void compute_impl(Json &data, JsonToVoidFunc check_required_keys, JsonToBoolFunc check_optional_keys) override
This method overrides Updater::compute_impl.
std::pair< bool, bool > check_mol_type_to_abst_beads()
Map< int, Vec< Json > > mol_type_to_abst_beads
Namespace for utility functions.
std::function< void(const Json &)> JsonToVoidFunc
An alias for a function accepts a Json object.
std::unordered_map< T, U > Map
Map is an alias for unordered map (same as dict in Python).