Loading...
Searching...
No Matches
topo_fingerprint.hpp
Go to the documentation of this file.
1//-----------------------------------------------------------------------------------
2// d-SEAMS - Deferred Structural Elucidation Analysis for Molecular Simulations
3// SPDX-License-Identifier: MIT
4//-----------------------------------------------------------------------------------
5#ifndef SEAMS_TOPO_FINGERPRINT_H_
6#define SEAMS_TOPO_FINGERPRINT_H_
7
8#include <cstdint>
9#include <map>
10#include <string>
11#include <utility>
12#include <vector>
13
34namespace topo {
35
38using Rows = std::vector<std::vector<int>>;
39
40struct LocalKey {
41 std::string key;
42 std::string method;
43 int vertices = 0;
44 int edges = 0;
45};
46
48 std::string key;
49 std::string method;
50 std::vector<std::string> atomKeys;
51 std::map<std::string, int> classes;
52 std::vector<int> ringCensus;
53 std::vector<std::uint64_t> wlAtom;
54 int hops = 0;
55 bool coloured = false;
56};
57
60std::vector<int> hopNeighbourhood(const Rows &rows, int atom, int hops);
61
66std::uint64_t wlHash(const std::vector<std::vector<int>> &adjacency, int root,
67 int rounds, const std::vector<int> &colours = {});
68
72LocalKey localKey(const Rows &rows, int atom, int hops,
73 const std::vector<int> &colours = {});
74
77FrameFingerprint fingerprint(const Rows &rows, int hops = 2, int maxRingSize = 7,
78 const std::vector<int> &colours = {});
79
84 const Rows &rows,
85 const std::vector<int> &dirtyAtoms,
86 int hops, int maxRingSize = 7,
87 const std::vector<int> &colours = {});
88
90std::string hex(std::uint64_t value);
91
97struct KeyLibrary {
98 std::string method;
99 int hops = 0;
100 bool coloured = false;
101 std::map<std::string, std::string> labelOf;
102};
103
106void addToLibrary(KeyLibrary &lib, const FrameFingerprint &fp, const std::string &label);
107
110std::string writeLibrary(const KeyLibrary &lib);
111KeyLibrary readLibrary(const std::string &text);
112
114 std::vector<std::string> labels;
115 std::map<std::string, int> counts;
116 std::vector<int> depth;
117 int matched = 0;
118};
119
123
131LibraryMatch matchLibraries(const Rows &rows, const std::vector<KeyLibrary> &libs,
132 int maxRingSize = 7, const std::vector<int> &colours = {});
133
134} // namespace topo
135
136#endif // SEAMS_TOPO_FINGERPRINT_H_
FrameFingerprint fingerprint(const Rows &rows, int hops=2, int maxRingSize=7, const std::vector< int > &colours={})
Keys of every atom, their histogram, the ring census up to maxRingSize, and the frame key.
std::uint64_t wlHash(const std::vector< std::vector< int > > &adjacency, int root, int rounds, const std::vector< int > &colours={})
Weisfeiler-Lehman refinement hash of a graph given by local adjacency lists; root (or -1) starts in i...
LibraryMatch matchLibraries(const Rows &rows, const std::vector< KeyLibrary > &libs, int maxRingSize=7, const std::vector< int > &colours={})
Match against libraries at several depths: an atom takes the label of the deepest library that holds ...
LocalKey localKey(const Rows &rows, int atom, int hops, const std::vector< int > &colours={})
Key of the rooted neighbourhood of atom.
std::string writeLibrary(const KeyLibrary &lib)
Text form: a header line # method M hops H colours C (C is 0 or 1; a header without it means uncolour...
FrameFingerprint incrementalFingerprint(const FrameFingerprint &prev, const Rows &rows, const std::vector< int > &dirtyAtoms, int hops, int maxRingSize=7, const std::vector< int > &colours={})
Recompute local keys only for the hop-ball of dirtyAtoms and keep the rest of prev.
std::string hex(std::uint64_t value)
Hex string of a 64-bit hash.
LibraryMatch matchLibrary(const FrameFingerprint &fp, const KeyLibrary &lib)
Look every atom key of fp up in lib.
std::vector< std::vector< int > > Rows
Neighbour rows by index, each row leading with the atom itself, as nneigh::neighbourListByIndex retur...
void addToLibrary(KeyLibrary &lib, const FrameFingerprint &fp, const std::string &label)
Add every distinct key of fp under label; a key already present under other labels carries all of the...
std::vector< int > hopNeighbourhood(const Rows &rows, int atom, int hops)
Atoms within hops bonds of atom, the atom itself first, then in breadth-first order.
KeyLibrary readLibrary(const std::string &text)
std::vector< std::uint64_t > wlAtom
per-atom WL hash used in the frame key
std::string method
method of the local keys
std::vector< std::string > atomKeys
one local key per atom
std::map< std::string, int > classes
local key -> number of atoms carrying it
bool coloured
keys carry vertex colours
std::string key
hash of the sorted local keys and the ring census
std::vector< int > ringCensus
ringCensus[s] = primitive rings of size s
A dictionary from local keys to labels: the keys of reference structures (a polymorph library),...
std::map< std::string, std::string > labelOf
key -> label
std::string method
"nauty" or "wl"
bool coloured
keys were computed with vertex colours
std::map< std::string, int > counts
label -> atoms, "" for unmatched
std::vector< std::string > labels
per atom; "" when no key matches
std::vector< int > depth
per atom: hops of the library that named it, 0 when none
int edges
bonds among them
std::string method
"nauty" or "wl"
int vertices
atoms in the neighbourhood, centre included
std::string key
canonical certificate or refinement hash