40 const std::vector<unsigned int> &queryAtomLabels,
41 const std::vector<unsigned int> &queryBondLabels) {
42 computeMorganCodeHash(seed, queryAtomLabels, queryBondLabels);
46 void computeMorganCodeHash(
47 const Seed &seed,
const std::vector<unsigned int> &queryAtomLabels,
48 const std::vector<unsigned int> &queryBondLabels) {
49 size_t nv = seed.getNumAtoms();
50 size_t ne = seed.getNumBonds();
51 std::vector<unsigned long> currCodes(nv);
52 std::vector<unsigned long> prevCodes(nv);
53 size_t nIterations = seed.getNumBonds();
54 if (nIterations > 5) {
58 for (
unsigned int seedAtomIdx = 0; seedAtomIdx < seed.getNumAtoms();
60 currCodes[seedAtomIdx] = queryAtomLabels.at(
61 seed.MoleculeFragment.Atoms.at(seedAtomIdx)->getIdx());
64 for (
size_t iter = 0; iter < nIterations; ++iter) {
65 for (
size_t i = 0; i < nv; ++i) {
66 prevCodes[i] = currCodes[i];
69 for (
size_t seedBondIdx = 0; seedBondIdx < ne; ++seedBondIdx) {
70 const Bond *bond = seed.MoleculeFragment.Bonds[seedBondIdx];
71 unsigned int order = queryBondLabels.at(
72 seed.MoleculeFragment.Bonds.at(seedBondIdx)->getIdx());
73 unsigned int atom1 = seed.MoleculeFragment.SeedAtomIdxMap
74 .find(bond->getBeginAtomIdx())
77 seed.MoleculeFragment.SeedAtomIdxMap.find(bond->getEndAtomIdx())
79 unsigned int v1 = prevCodes[atom1];
80 unsigned int v2 = prevCodes[atom2];
82 currCodes[atom1] += v2 * v2 + (v2 + 23) * (order + 1721);
83 currCodes[atom2] += v1 * v1 + (v1 + 23) * (order + 1721);
87 KeyNumericMetrics::TValue result = 0;
88 for (
unsigned int seedAtomIdx = 0; seedAtomIdx < nv; ++seedAtomIdx) {
89 unsigned long code = currCodes[seedAtomIdx];
90 result += code * (code + 6849) + 29;
93 NumericMetrics.
Value = result;
125 const std::vector<unsigned int> &queryAtomLabels,
126 const std::vector<unsigned int> &queryBondLabels,
128 key.
computeKey(seed, queryAtomLabels, queryBondLabels);
130 if (NumericIndex.end() != entryit) {
131 return &ValueStorage[entryit->second];