void MangoExact::calculateHash (Molecule &mol, Hash &hash) { hash.clear(); QS_DEF(Molecule, mol_without_h); QS_DEF(Array<int>, vertices); int i; vertices.clear(); for (i = mol.vertexBegin(); i != mol.vertexEnd(); i = mol.vertexNext(i)) if (mol.getAtomNumber(i) != ELEM_H) vertices.push(i); mol_without_h.makeSubmolecule(mol, vertices, 0); // Decompose into connected components int n_comp = mol_without_h.countComponents(); QS_DEF(Molecule, component); QS_DEF(Array<int>, vertex_codes); for (int i = 0; i < n_comp; i++) { Filter filter(mol_without_h.getDecomposition().ptr(), Filter::EQ, i); component.makeSubmolecule(mol_without_h, filter, 0, 0); SubgraphHash hh(component); vertex_codes.clear_resize(component.vertexEnd()); for (int v = component.vertexBegin(); v != component.vertexEnd(); v = component.vertexNext(v)) vertex_codes[v] = component.atomCode(v); hh.vertex_codes = &vertex_codes; hh.max_iterations = (component.edgeCount() + 1) / 2; dword component_hash = hh.getHash(); // Find component hash in all hashes bool found = false; for (int j = 0; j < hash.size(); j++) if (hash[j].hash == component_hash) { hash[j].count++; found = true; break; } if (!found) { HashElement &hash_element = hash.push(); hash_element.count = 1; hash_element.hash = component_hash; } } }