votca 2026-dev
Loading...
Searching...
No Matches
stochasticnetwork.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_STOCHASTICNETWORK_H
22#define VOTCA_XTP_STOCHASTICNETWORK_H
23
24// Standard includes
25#include <array>
26#include <cstdint>
27#include <functional>
28#include <random>
29#include <string>
30#include <vector>
31
32// Local VOTCA includes
33#include "eigen.h"
34#include "qmstate.h"
35#include "topology.h"
36
37namespace votca {
38namespace tools {
39class Property;
40}
41} // namespace votca
42
43namespace votca {
44namespace xtp {
45
52 public:
54 ModelRandom(std::uint64_t seed, std::uint64_t stream);
56 double Uniform() {
57 return (double(engine_() >> 11) + 1.0) * (1.0 / 9007199254740992.0);
58 }
59 double Normal();
61 Index Poisson(double mean);
64
65 private:
66 std::mt19937_64 engine_;
67 bool has_spare_ = false;
68 double spare_ = 0.0;
69};
70
75 public:
77 PeriodicCells(const Eigen::Vector3d& box, double radius,
78 const std::vector<Eigen::Vector3d>& points);
80 Eigen::Vector3d Connection(const Eigen::Vector3d& r1,
81 const Eigen::Vector3d& r2) const;
84 void Within(const Eigen::Vector3d& p, double radius,
85 const std::function<void(Index, const Eigen::Vector3d&, double)>&
86 f) const;
89 std::vector<Index> Nearest(Index i, Index l) const;
91 std::vector<Index> NearestTo(const Eigen::Vector3d& p, Index l) const;
92 Index NumberOfPoints() const { return Index(points_.size()); }
93
94 private:
95 Eigen::Vector3d box_;
96 std::array<Index, 3> n_;
97 Eigen::Vector3d cell_;
98 const std::vector<Eigen::Vector3d>& points_;
99 std::vector<Index> start_;
100 std::vector<Index> members_;
101 Index CellIndex(const Eigen::Vector3d& p, std::array<Index, 3>& c) const;
102 template <class F>
103 void Shell(const std::array<Index, 3>& c, Index s, F&& f) const;
104};
105
143 public:
145 double hard_core = 0.0; // r_h
146 double radius_mean = 0.0; // mean of X
147 double radius_variance = 0.0; // variance of X (0: X = mean)
149 double candidates = 3.0;
151 };
152
153 struct EnergyModel {
154 double mean = 0.0;
155 double sigma = 0.0; // 0: all sites at mean
156 double w_a = 1.0;
157 double w_b = 0.0;
160 };
161
163 // log10(J^2/eV^2) mean = mean_offset + mean_slope r[nm]
164 double mean_offset = -6.0;
165 double mean_slope = 0.0;
166 // variance = var_offset + var_slope r[nm] (clipped at 0)
167 double var_offset = 1.0;
168 double var_slope = 0.0;
171 std::vector<double> residual_quantiles;
172 };
173
174 struct Carrier {
178 double U_xX_nN = 0.0; // internal energy
179 double U_nX_nN = 0.0; // reorganization parts
180 double U_xN_xX = 0.0;
181 };
182
185 struct Trap {
186 Index carrier = 0; // the carrier it traps (index into carriers)
187 double density = 0.0; // traps of this kind per site
189 std::vector<std::vector<double>> offsets;
190 double release_rate = 0.0; // microscopic release rate (1/s, information)
191 };
192
193 struct Options {
194 Eigen::Vector3d box = Eigen::Vector3d::Zero(); // orthorhombic, bohr
198 std::vector<double> connection_r;
199 std::vector<double> connection_p;
200 std::vector<Carrier> carriers;
203 double energy_correlation = 0.0;
205 std::uint64_t seed = 1;
206 std::string segment_name = "site";
208 std::vector<Trap> traps;
210 double trap_factor = 1.0;
211 };
212
213 explicit StochasticNetwork(const Options& opt);
214
215 Index NumberOfSites() const { return Index(positions_.size()); }
216 const std::vector<Eigen::Vector3d>& Positions() const { return positions_; }
218 const std::vector<double>& Radii() const { return radii_; }
222 std::vector<Index> sites;
223 };
224 const std::vector<InsertedTrap>& Traps() const { return inserted_; }
226 const std::vector<double>& SiteEnergies(Index c) const {
227 return energies_[c];
228 }
229 struct Pair {
232 Eigen::Vector3d R; // shortest connection from i to j
233 std::vector<double> J2; // per carrier, Hartree^2
234 };
235 const std::vector<Pair>& Pairs() const { return pairs_; }
237 Index Iterations() const { return iterations_; }
238
240 void BuildTopology(Topology& top) const;
241
244 static Options FromProperty(const tools::Property& p);
246 static std::string ToXML(const Options& opt);
247
250 static std::vector<double> MovingAverage(const PeriodicCells& cells,
251 const EnergyModel& m, Index sites,
252 const std::vector<double>& A,
253 const std::vector<double>& Bf,
254 const std::vector<double>& C);
257 static Index SamplePoints(const PointProcess& pp, const Eigen::Vector3d& box,
258 Index sites, ModelRandom& random,
259 std::vector<Eigen::Vector3d>& positions,
260 std::vector<double>& radii);
262 double Connection(double r) const;
264 static double Residual(const CouplingModel& m, double g);
266 static double Log10J2(const CouplingModel& m, double r, double g);
267
268 private:
270 std::vector<Eigen::Vector3d> positions_;
271 std::vector<double> radii_;
272 std::vector<std::vector<double>> energies_;
273 std::vector<Pair> pairs_;
275 std::vector<InsertedTrap> inserted_;
276
277 void Check() const;
278 void GenerateEnergies(ModelRandom& random);
279 void GeneratePairs(ModelRandom& random);
280 void InsertTraps(ModelRandom& random);
281};
282
283} // namespace xtp
284} // namespace votca
285
286#endif // VOTCA_XTP_STOCHASTICNETWORK_H
class to manage program options with xml serialization functionality
Definition property.h:55
Platform independent random numbers for the stochastic models: mt19937_64 with self-written transform...
Index Poisson(double mean)
Poisson distributed count.
Index Integer(Index n)
integer in [0, n)
ModelRandom(std::uint64_t seed, std::uint64_t stream)
independent streams for the same seed (points, energies, pairs)
Periodic orthorhombic cell list for neighbour searches.
std::array< Index, 3 > n_
PeriodicCells(const Eigen::Vector3d &box, double radius, const std::vector< Eigen::Vector3d > &points)
box lengths and the largest search radius used with Within()
std::vector< Index > NearestTo(const Eigen::Vector3d &p, Index l) const
indices of the l points nearest to any position p
Index CellIndex(const Eigen::Vector3d &p, std::array< Index, 3 > &c) const
std::vector< Index > start_
std::vector< Index > members_
void Shell(const std::array< Index, 3 > &c, Index s, F &&f) const
Eigen::Vector3d Connection(const Eigen::Vector3d &r1, const Eigen::Vector3d &r2) const
shortest periodic connection r2 - r1
void Within(const Eigen::Vector3d &p, double radius, const std::function< void(Index, const Eigen::Vector3d &, double)> &f) const
std::vector< Index > Nearest(Index i, Index l) const
const std::vector< Eigen::Vector3d > & points_
StochasticNetwork(const Options &opt)
static Index SamplePoints(const PointProcess &pp, const Eigen::Vector3d &box, Index sites, ModelRandom &random, std::vector< Eigen::Vector3d > &positions, std::vector< double > &radii)
void BuildTopology(Topology &top) const
fill an empty topology (segments with one pseudo atom, box, pairs)
const std::vector< double > & Radii() const
radii of the point process (r_h + X)
std::vector< InsertedTrap > inserted_
std::vector< std::vector< double > > energies_
std::vector< Eigen::Vector3d > positions_
void GenerateEnergies(ModelRandom &random)
static std::vector< double > MovingAverage(const PeriodicCells &cells, const EnergyModel &m, Index sites, const std::vector< double > &A, const std::vector< double > &Bf, const std::vector< double > &C)
double Connection(double r) const
connection probability at distance r (bohr)
const std::vector< double > & SiteEnergies(Index c) const
site energies of carrier c (index into Options::carriers)
static double Log10J2(const CouplingModel &m, double r, double g)
log10(J^2/eV^2) for distance r (bohr) and standard normal g
Index Iterations() const
iterations the point process needed
static std::string ToXML(const Options &opt)
the parameter file (root element "stochasticnetwork")
const std::vector< Eigen::Vector3d > & Positions() const
void InsertTraps(ModelRandom &random)
const std::vector< InsertedTrap > & Traps() const
const std::vector< Pair > & Pairs() const
static double Residual(const CouplingModel &m, double g)
standardized residual for a standard normal g
void GeneratePairs(ModelRandom &random)
static Options FromProperty(const tools::Property &p)
Container for segments and box and atoms.
Definition topology.h:41
Charge transport classes.
Definition ERIs.h:28
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
inserted traps: template index and sites (deepest first)
std::vector< Trap > traps
trap templates, inserted after the Gaussian energies
std::vector< double > connection_r
connection probability table: f at distances r (ascending, bohr)
double trap_factor
multiplies all trap densities (0: no traps)
double candidates
candidates per iteration in units of the number of sites
std::vector< std::vector< double > > offsets
offsets[k][c]: site k (deepest first), carrier c, Hartree