ppap4lmp  0.7.2
sta_molecules.cpp
Go to the documentation of this file.
1 
9 #include "sta_molecules.h"
10 
11 /* ------------------------------------------------------------------ */
12 
14  const ElPtr &el_atoms)
15 {
16  ext_generator = el_atoms;
17 }
18 
19 /* ------------------------------------------------------------------ */
20 
22  Json &data,
23  JsonToVoidFunc check_required_keys,
24  JsonToBoolFunc check_optional_keys)
25 {
26  auto el_atoms = ext_generator->get_element();
27 
28  el_atoms->check_required_keys({"mol", "id"});
29 
30  auto &atoms = el_atoms->get_data();
31 
32  Map<int,int> id2index;
33 
34  int max_index = 0;
35 
36  for (const auto &atom : atoms)
37  {
38  int molid = atom["mol"];
39 
40  if (id2index.find(molid) == id2index.cend())
41  {
42  data[max_index]["id"] = molid;
43  id2index[molid] = max_index++;
44  }
45 
46  data[id2index[molid]]["atom-ids"].push_back(atom["id"]);
47  }
48 }
ShPtr< Element > ElPtr
An alias for a shared pointer of Element class.
Definition: element.h:378
std::function< bool(const Json &)> JsonToBoolFunc
An alias for a function accepts a Json object and returns a bool.
Definition: updater.h:20
virtual void compute_impl(Json &data, JsonToVoidFunc check_required_keys, JsonToBoolFunc check_optional_keys) override
This method overrides Updater::compute_impl.
nlohmann::json Json
Json is an alias for nlohmann::json.
Definition: json.h:22
ShPtr< Generator > ext_generator
Definition: updater.h:64
This file has a definition of StaMolecules class, which is a subclass of Starter class.
StaMolecules(const ElPtr &el_atoms)
Constructor of StaMolecules class.
std::function< void(const Json &)> JsonToVoidFunc
An alias for a function accepts a Json object.
Definition: updater.h:18
std::unordered_map< T, U > Map
Map is an alias for unordered map (same as dict in Python).
Definition: std.h:38