13 #include "../utils/runtime_error.h" 14 #include "../utils/split.h" 27 bool timestep_matches =
false;
35 while (std::getline(ifs, line))
37 if (line.find(
"ITEM: TIMESTEP") == 0)
39 std::getline(ifs, line);
43 timestep_matches =
true;
46 else if (line.find(
"ITEM: NUMBER OF ATOMS") == 0)
48 std::getline(ifs, line);
49 n_atoms = std::stoi(line);
54 data.get_ref<Json::array_t&>().resize(n_atoms);
57 else if (line.find(
"ITEM: ATOMS") == 0)
62 keys.erase(keys.begin(), keys.begin()+2);
64 std::getline(ifs, line);
71 is_int_vector.push_back(s.find(
".") == Str::npos);
76 auto &d = data.front();
80 for (
int i = 0; i != is_int_vector.size(); ++i)
84 d[keys[i]] = std::stoi(strs[i]);
88 d[keys[i]] = std::stod(strs[i]);
96 for (
int i = 0; i < tuples.size(); ++i)
98 tuples[i] = std::make_tuple(
99 keys[i], is_int_vector[i], i+1 == tuples.size() ?
'\n' :
' ');
102 for (
auto it = data.begin()+1; it != data.end(); ++it)
104 for (
auto jt = tuples.cbegin(); jt != tuples.cend(); ++jt)
110 std::getline(ifs, str, std::get<2>(*jt));
113 if (std::get<1>(*jt))
115 (*it)[std::get<0>(*jt)] = std::stoi(str);
119 (*it)[std::get<0>(*jt)] = std::stod(str);
128 for (
int i = 0; i != n_atoms; ++i)
130 std::getline(ifs, line);
std::function< bool(const Json &)> JsonToBoolFunc
An alias for a function accepts a Json object and returns a bool.
Vec< Str > split(const Str &str, char delim=' ')
Mimicking Python's split.
std::string Str
Str is an alias for string.
nlohmann::json Json
Json is an alias for nlohmann::json.
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.
This file has a definition of StaDumpAtoms class, which is a subclass of Starter class.
Namespace for utility functions.
std::function< void(const Json &)> JsonToVoidFunc
An alias for a function accepts a Json object.