Loading...
Searching...
No Matches
gpr::priors::PopulationPrior Class Reference

#include <gpr/prior/PopulationPrior.h>

Public Member Functions

bool empty () const noexcept
std::size_t size () const noexcept
void clear ()
void add (PopulationPairPrior prior)
const PopulationPairPrior * find (int element_a, int element_b) const noexcept
 The entry of an element pair, in either order; null when unseen.
bool read (std::istream &input)
std::vector< const PopulationPairPrior * > perPairtype (const AtomsConfiguration &conf) const

Detailed Description

Definition at line 38 of file PopulationPrior.h.

Member Function Documentation

◆ add()

void gpr::priors::PopulationPrior::add ( PopulationPairPrior prior)
inline

Definition at line 52 of file PopulationPrior.h.

53 {
54 if (prior.element_a > prior.element_b)
55 std::swap(prior.element_a, prior.element_b);
56 for (auto& existing: pairs_) {
57 if (existing.element_a == prior.element_a &&
58 existing.element_b == prior.element_b) {
59 existing = prior;
60 return;
61 }
62 }
63 pairs_.push_back(prior);
64 }

◆ clear()

void gpr::priors::PopulationPrior::clear ( )
inline

Definition at line 48 of file PopulationPrior.h.

49 {
50 pairs_.clear();
51 }

◆ empty()

bool gpr::priors::PopulationPrior::empty ( ) const
inlinenodiscardnoexcept

Definition at line 40 of file PopulationPrior.h.

41 {
42 return pairs_.empty();
43 }

◆ find()

const PopulationPairPrior * gpr::priors::PopulationPrior::find ( int element_a,
int element_b ) const
inlinenodiscardnoexcept

The entry of an element pair, in either order; null when unseen.

Definition at line 66 of file PopulationPrior.h.

68 {
69 if (element_a > element_b) std::swap(element_a, element_b);
70 for (const auto& prior: pairs_)
71 if (prior.element_a == element_a && prior.element_b == element_b)
72 return &prior;
73 return nullptr;
74 }

◆ perPairtype()

std::vector< const PopulationPairPrior * > gpr::priors::PopulationPrior::perPairtype ( const AtomsConfiguration & conf) const
inlinenodiscard

The entry of each active pair type of a configuration (null for a pair type whose element pair the population has not seen), by the same walk of the type table the covalent prior uses.

Definition at line 99 of file PopulationPrior.h.

101 {
102 std::vector<const PopulationPairPrior*> entries(
103 static_cast<std::size_t>(conf.n_pt), nullptr);
104 if (pairs_.empty() || conf.n_pt <= 0) return entries;
105 const Eigen::Index n_types = conf.pairtype.rows();
106 std::vector<int> type_to_Z(static_cast<std::size_t>(n_types), -1);
107 const auto& types = conf.type.size() == conf.atomicNrs.size()
108 ? conf.type
109 : conf.atoms_mov.type;
110 const Eigen::Index count =
111 std::min(types.size(), conf.atomicNrs.size());
112 for (Eigen::Index atom = 0; atom < count; ++atom) {
113 const auto type = static_cast<Eigen::Index>(types.data()[atom]);
114 if (type < 0 || type >= n_types) continue;
115 if (type_to_Z[static_cast<std::size_t>(type)] == -1)
116 type_to_Z[static_cast<std::size_t>(type)] =
117 conf.atomicNrs.data()[atom];
118 }
119 for (Eigen::Index ti = 0; ti < n_types; ++ti) {
120 for (Eigen::Index tj = ti; tj < n_types; ++tj) {
121 if (ti >= conf.pairtype.rows() || tj >= conf.pairtype.cols())
122 continue;
123 const auto k = static_cast<Eigen::Index>(conf.pairtype(ti, tj));
124 if (k < 0 || k >= conf.n_pt) continue;
125 const int za = type_to_Z[static_cast<std::size_t>(ti)];
126 const int zb = type_to_Z[static_cast<std::size_t>(tj)];
127 if (za < 0 || zb < 0) continue;
128 if (entries[static_cast<std::size_t>(k)] == nullptr)
129 entries[static_cast<std::size_t>(k)] = find(za, zb);
130 }
131 }
132 return entries;
133 }
const PopulationPairPrior * find(int element_a, int element_b) const noexcept
The entry of an element pair, in either order; null when unseen.

◆ read()

bool gpr::priors::PopulationPrior::read ( std::istream & input)
inline

Table rows "Za Zb cells log_length_mu log_length_sigma"; '#' starts a comment. False on a malformed row.

Definition at line 77 of file PopulationPrior.h.

78 {
79 std::string line;
80 while (std::getline(input, line)) {
81 const auto hash = line.find('#');
82 if (hash != std::string::npos) line.erase(hash);
83 std::istringstream row(line);
84 PopulationPairPrior prior;
85 if (!(row >> prior.element_a)) continue;
86 if (!(row >> prior.element_b >> prior.cells >>
87 prior.log_length_mu >> prior.log_length_sigma) ||
88 !std::isfinite(prior.log_length_mu) ||
89 !std::isfinite(prior.log_length_sigma) ||
90 prior.log_length_sigma < 0.0)
91 return false;
92 add(prior);
93 }
94 return true;
95 }
void add(PopulationPairPrior prior)
std::string line(const std::string &topic, const std::vector< Field > &fields)

◆ size()

std::size_t gpr::priors::PopulationPrior::size ( ) const
inlinenodiscardnoexcept

Definition at line 44 of file PopulationPrior.h.

45 {
46 return pairs_.size();
47 }

The documentation for this class was generated from the following file: