votca 2026-dev
Loading...
Searching...
No Matches
hdf5_dump.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20// Dev/debug tool: NOT part of the production xtp_* tool set (no --help,
21// manpage, or sphinx-doc infrastructure). Dumps an EwaldRegistry HDF5
22// checkpoint (as written by EwaldBackground) as a CSV, one row per site,
23// one row per site. The schema was originally shared with ptop_dump, the
24// matching dumper for the legacy xtp/ewald/ PolarTop, so that the two
25// could be diffed directly; that tool went with the code it read, and
26// this one remains as the way to inspect a background checkpoint.
27//
28// Positions, permanent field, and induced dipoles are already in this
29// tool's own native units (bohr, atomic-unit-style) -- no conversion
30// needed, unlike the nm->bohr/field conversion the legacy dumper did.
31//
32// The permanent-field columns (FPx/FPy/FPz) read out PolarSite's own V()
33// accumulator. This only holds anything meaningful because
34// EwaldBackground::Evaluate() now explicitly writes the permanent field
35// (b) back into every site's V() right before the checkpoint write --
36// neither of its own two code paths (the PCG solve, or the
37// induce=false skip) otherwise leaves V() holding it at that point (see
38// EwaldBackground's own comment at that write for the full trace). If
39// you're reading this from a checkpoint written by an older version of
40// EwaldBackground that predates that write-back, these columns will
41// silently be zero instead of a real error -- worth checking the
42// EwaldBackground version/log if these numbers look suspiciously flat.
43//
44// Usage: hdf5_dump <input.hdf5> <output.csv>
45
46// Standard includes
47#include <fstream>
48#include <iostream>
49
50// Local VOTCA includes
53
54using namespace votca;
55using namespace votca::xtp;
56
57int main(int argc, char** argv) {
58 if (argc != 3) {
59 std::cerr << "Usage: " << argv[0] << " <input.hdf5> <output.csv>"
60 << std::endl;
61 return 1;
62 }
63
66
67 EwaldRegistry registry;
68 registry.ReadFromCpt(r);
69
70 std::ofstream out(argv[2]);
71 if (!out) {
72 std::cerr << "Could not open output file: " << argv[2] << std::endl;
73 return 1;
74 }
75 out << "segment_id,site_id,x_bohr,y_bohr,z_bohr,"
76 << "FPx_au,FPy_au,FPz_au,U1x_au,U1y_au,U1z_au\n";
77
78 std::size_t n_sites = 0;
79 std::size_t n_segments = 0;
80 for (Index id : registry.AllIds()) {
81 if (!registry.Has(id, EwaldChargeState::Neutral)) {
82 continue;
83 }
84 const PolarSegment& segment = registry.Get(id, EwaldChargeState::Neutral);
85 ++n_segments;
86 for (const PolarSite& site : segment) {
87 const Eigen::Vector3d& pos = site.getPos();
88 const Eigen::Vector3d& fp = site.V();
89 const Eigen::Vector3d& u1 = site.getInducedDipole();
90 out << id << "," << site.getId() << "," << pos.x() << "," << pos.y()
91 << "," << pos.z() << "," << fp.x() << "," << fp.y() << "," << fp.z()
92 << "," << u1.x() << "," << u1.y() << "," << u1.z() << "\n";
93 ++n_sites;
94 }
95 }
96
97 std::cout << "Wrote " << n_sites << " sites from " << n_segments
98 << " segments to " << argv[2] << std::endl;
99
100 return 0;
101}
CheckpointReader getReader()
bool Has(Index id, EwaldChargeState state) const
std::vector< Index > AllIds() const
const PolarSegment & Get(Index id, EwaldChargeState state) const
void ReadFromCpt(CheckpointReader &r)
Class to represent Atom/Site in electrostatic+polarization.
Definition polarsite.h:36
int main(int argc, char **argv)
Definition hdf5_dump.cc:57
Charge transport classes.
Definition ERIs.h:28
ClassicalSegment< PolarSite > PolarSegment
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26