simple substructure optimization (#9201)

Co-authored-by: = <=>
This commit is contained in:
Greg Landrum
2026-03-24 15:38:13 +01:00
committed by GitHub
parent 9d1b988799
commit cacba34a47
2 changed files with 21 additions and 1 deletions

View File

@@ -482,7 +482,9 @@ std::vector<MatchVectType> SubstructMatch(
const ROMol &mol, const ROMol &query,
const SubstructMatchParameters &params) {
std::vector<MatchVectType> matches;
if (!mol.getNumAtoms() || !query.getNumAtoms()) {
const auto &mNumAtoms = mol.getNumAtoms();
const auto &qNumAtoms = query.getNumAtoms();
if (!mNumAtoms || !qNumAtoms || qNumAtoms > mNumAtoms) {
return matches;
}

View File

@@ -1104,4 +1104,22 @@ TEST_CASE("extra atom and bond queries") {
CHECK(matches[0][1].second == 2);
}
}
}
TEST_CASE("quick return when the query has more atoms than the molecule") {
SECTION("basics") {
SubstructMatchParameters ps;
bool touched = false;
auto atomQuery = [&touched](const Atom &, const Atom &) -> bool {
touched = true;
return true;
};
ps.extraAtomCheck = atomQuery;
auto mol = "CC"_smiles;
REQUIRE(mol);
auto qry = "CCC"_smarts;
REQUIRE(qry);
auto matches = SubstructMatch(*mol, *qry, ps);
CHECK(matches.empty());
CHECK(!touched);
}
}