votca 2026-dev
Loading...
Searching...
No Matches
stochasticnetworkfit.h
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#pragma once
21#ifndef VOTCA_XTP_STOCHASTICNETWORKFIT_H
22#define VOTCA_XTP_STOCHASTICNETWORKFIT_H
23
24// Standard includes
25#include <cstdint>
26#include <string>
27#include <vector>
28
29// VOTCA includes
31
32// Local VOTCA includes
33#include "eigen.h"
34#include "qmstate.h"
35#include "stochasticnetwork.h"
36#include "topology.h"
37
38namespace votca {
39namespace xtp {
40
83 public:
86 struct TrapInput {
88 std::vector<Index> sites; // deepest first
89 double release_rate = 0.0; // 1/s
90 };
91
92 struct Settings {
93 std::vector<QMStateType> carriers;
94 std::vector<TrapInput> traps;
95 double bin = 0.05 * tools::conv::nm2bohr;
97 double correlation_cutoff = 0.0;
98 std::vector<Index> l_b; // grids
99 std::vector<Index> l_c;
100 Index quantiles = 100; // 0: Gaussian residuals
102 bool fit_points = true;
106 std::uint64_t seed = 1;
107 double candidates = 3.0;
109 };
110
112 struct Data {
113 Eigen::Vector3d box = Eigen::Vector3d::Zero();
114 std::vector<Eigen::Vector3d> positions; // wrapped into the box
115 std::vector<QMStateType> carriers;
116 std::vector<std::vector<double>> energies; // per carrier, Hartree
117 std::vector<double> U_xX_nN; // per carrier, means
118 std::vector<double> U_nX_nN;
119 std::vector<double> U_xN_xX;
120 struct Pair {
123 double dist;
124 std::vector<double> J2; // per carrier, Hartree^2
125 };
126 std::vector<Pair> pairs;
127 };
128 static Data FromTopology(const Topology& top,
129 const std::vector<QMStateType>& carriers);
131 static Data FromNetwork(const StochasticNetwork& net,
132 const std::vector<QMStateType>& carriers,
133 const Eigen::Vector3d& box);
134
136 struct Curve {
137 std::vector<double> r; // bohr
138 std::vector<double> value;
139 std::vector<double> count; // weights (pairs per bin), may be empty
140 };
141
142 struct EnergyFit {
143 double mean = 0.0;
144 double sigma = 0.0; // sample standard deviation
145 double sigma_model = 0.0; // sigma / sqrt(1 - cbar) (see kappa)
146 double cbar = 0.0; // mean correlation over all pairs
149 double w_a = 1.0;
150 double w_b = 0.0;
151 double w_c = 0.0;
152 double rms = 0.0; // rms deviation of the kappa fit
153 Curve kappa; // microscopic (sample mean and variance)
156 bool fitted = false; // false: sigma zero, no correlation fit
159 bool l_b_at_edge = false; // the best l_b / l_c is the end of its grid
160 bool l_c_at_edge = false;
161 };
162
170
171 struct PointFit {
173 double objective = 0.0;
175 Curve D, H, g; // microscopic
176 Curve D_model, H_model, g_model; // model, mean over the realizations
177 };
178
179 struct Result {
182 std::vector<EnergyFit> energies;
183 std::vector<CouplingFit> couplings;
185 };
186
187 StochasticNetworkFit(const Data& data, const Settings& settings);
188 Result Fit() const;
189
190 // statistics, also used for the validation (all distances bohr)
192 static std::vector<double> NearestDistances(
193 const std::vector<Eigen::Vector3d>& points, const Eigen::Vector3d& box);
195 static std::vector<double> ContactDistances(
196 const std::vector<Eigen::Vector3d>& points, const Eigen::Vector3d& box,
197 Index probes, std::uint64_t seed);
199 static Curve Cdf(const std::vector<double>& x, const std::vector<double>& r);
201 static Curve PairCorrelation(const std::vector<Eigen::Vector3d>& points,
202 const Eigen::Vector3d& box, double bin,
203 double rmax);
206 static Curve Correlation(const std::vector<Eigen::Vector3d>& points,
207 const Eigen::Vector3d& box,
208 const std::vector<double>& z, double bin,
209 double rmax, const std::vector<char>& skip = {});
211 static double NormalQuantile(double u);
213 static std::vector<Curve> Overlaps(const std::vector<Eigen::Vector3d>& points,
214 const Eigen::Vector3d& box,
215 const std::vector<Index>& l, double bin,
216 double rmax);
219 static double FitWeights(const Curve& kappa, const Curve& Ob, const Curve& Oc,
220 double& w_b, double& w_c);
222 static Curve PairsPerSite(const Data& data, double bin, double rmax);
224 static Curve MeanLog10J2(const Data& data, Index carrier, double bin,
225 double rmax);
226
227 private:
228 const Data& data_;
230
231 PointFit FitPoints() const;
232 Curve FitConnection() const;
234 std::vector<double>& standardized) const;
235};
236
237} // namespace xtp
238} // namespace votca
239
240#endif // VOTCA_XTP_STOCHASTICNETWORKFIT_H
static Curve PairCorrelation(const std::vector< Eigen::Vector3d > &points, const Eigen::Vector3d &box, double bin, double rmax)
pair correlation function in bins of width bin up to rmax
static Curve Cdf(const std::vector< double > &x, const std::vector< double > &r)
empirical distribution function on a grid
static std::vector< double > NearestDistances(const std::vector< Eigen::Vector3d > &points, const Eigen::Vector3d &box)
nearest neighbour distances
static Curve PairsPerSite(const Data &data, double bin, double rmax)
pairs per site in distance bins (connected pairs of the data)
static double NormalQuantile(double u)
inverse of the standard normal distribution function
static std::vector< double > ContactDistances(const std::vector< Eigen::Vector3d > &points, const Eigen::Vector3d &box, Index probes, std::uint64_t seed)
distances of probes random positions to the nearest point
static Data FromNetwork(const StochasticNetwork &net, const std::vector< QMStateType > &carriers, const Eigen::Vector3d &box)
the same data from a model network (validation)
StochasticNetworkFit(const Data &data, const Settings &settings)
static std::vector< Curve > Overlaps(const std::vector< Eigen::Vector3d > &points, const Eigen::Vector3d &box, const std::vector< Index > &l, double bin, double rmax)
overlap curves O_l(r) for the given l
CouplingFit FitCoupling(Index carrier, std::vector< double > &standardized) const
static double FitWeights(const Curve &kappa, const Curve &Ob, const Curve &Oc, double &w_b, double &w_c)
static Curve MeanLog10J2(const Data &data, Index carrier, double bin, double rmax)
mean of log10(J^2/eV^2) in distance bins
static Curve Correlation(const std::vector< Eigen::Vector3d > &points, const Eigen::Vector3d &box, const std::vector< double > &z, double bin, double rmax, const std::vector< char > &skip={})
static Data FromTopology(const Topology &top, const std::vector< QMStateType > &carriers)
Stochastic network model of a molecular charge transport network (Baumeier, Stenzel,...
Container for segments and box and atoms.
Definition topology.h:41
const double nm2bohr
Definition constants.h:47
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
std::vector< Eigen::Vector3d > positions
std::vector< std::vector< double > > energies
Curve l_c_scan
rms of the best fit for each l_c (r: l_c)
Curve kappa_model
the model on the microscopic sites, in the same (sample) form
double correlation_cutoff
largest distance for kappa(r) and O_l(r); 0: just below half the box
bool fit_points
false: the point process is not fitted but taken from points