ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
h5md_specification.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2025 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "hdf5_patches.hpp" // must appear first
23
24#include "h5md_core.hpp"
25#include "h5md_dataset.hpp"
27
28#include <h5xx/h5xx.hpp>
29
30#include <hdf5.h>
31
32#include <algorithm>
33#include <string>
34#include <utility>
35
36namespace Writer {
37namespace H5md {
38
39Specification::Specification(unsigned int fields) {
40 auto const add_time_series = [this](Dataset &&dataset, bool link = true) {
41 auto const group = dataset.group;
42 m_datasets.push_back(std::move(dataset));
43 m_datasets.push_back({group, "step", 1, H5T_NATIVE_INT, 1, link});
44 m_datasets.push_back({group, "time", 1, H5T_NATIVE_DOUBLE, 1, link});
45 };
46
47 if (fields & H5MD_OUT_BOX_L) {
48 add_time_series(
49 {"particles/atoms/box/edges", "value", 2, H5T_NATIVE_DOUBLE, 3, false});
50 }
51 if (fields & H5MD_OUT_LE_OFF) {
52 add_time_series({"particles/atoms/lees_edwards/offset", "value", 2,
53 H5T_NATIVE_DOUBLE, 1, false});
54 }
55 if (fields & H5MD_OUT_LE_DIR) {
56 add_time_series({"particles/atoms/lees_edwards/direction", "value", 2,
57 H5T_NATIVE_INT, 1, false});
58 }
59 if (fields & H5MD_OUT_LE_NORMAL) {
60 add_time_series({"particles/atoms/lees_edwards/normal", "value", 2,
61 H5T_NATIVE_INT, 1, false});
62 }
63 if (fields & H5MD_OUT_MASS) {
64 add_time_series(
65 {"particles/atoms/mass", "value", 2, H5T_NATIVE_DOUBLE, 1, false});
66 }
67 if (fields & H5MD_OUT_CHARGE) {
68 add_time_series(
69 {"particles/atoms/charge", "value", 2, H5T_NATIVE_DOUBLE, 1, false});
70 }
71 add_time_series({"particles/atoms/id", "value", 2, H5T_NATIVE_INT, 1, false},
72 false);
73 if (fields & H5MD_OUT_TYPE) {
74 add_time_series(
75 {"particles/atoms/species", "value", 2, H5T_NATIVE_INT, 1, false});
76 }
77 if (fields & H5MD_OUT_POS) {
78 add_time_series(
79 {"particles/atoms/position", "value", 3, H5T_NATIVE_DOUBLE, 3, false});
80 }
81 if (fields & H5MD_OUT_VEL) {
82 add_time_series(
83 {"particles/atoms/velocity", "value", 3, H5T_NATIVE_DOUBLE, 3, false});
84 }
85 if (fields & H5MD_OUT_FORCE) {
86 add_time_series(
87 {"particles/atoms/force", "value", 3, H5T_NATIVE_DOUBLE, 3, false});
88 }
89 if (fields & H5MD_OUT_IMG) {
90 add_time_series(
91 {"particles/atoms/image", "value", 3, H5T_NATIVE_INT, 3, false});
92 }
93 if (fields & H5MD_OUT_BONDS) {
94 add_time_series(
95 {"connectivity/atoms", "value", 3, H5T_NATIVE_INT, 2, false});
96 }
97}
98
99bool Specification::is_compliant(std::string const &filename) const {
100 h5xx::file h5md_file(filename, h5xx::file::in);
101
102 auto const all_groups_exist =
103 std::ranges::all_of(m_datasets, [&h5md_file](auto const &d) {
104 return h5xx::exists_group(h5md_file, d.group);
105 });
106 auto const all_datasets_exist =
107 std::ranges::all_of(m_datasets, [&h5md_file](auto const &d) {
108 return h5xx::exists_dataset(h5md_file, d.path());
109 });
110 return all_groups_exist and all_datasets_exist;
111}
112
113} // namespace H5md
114} // namespace Writer
bool is_compliant(std::string const &filename) const
Specification(unsigned int fields)