1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
|
//
// Copyright (C) 2021 Greg Landrum
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
// Tests of handling generics in substructure searching
//
#include <catch2/catch_all.hpp>
#include <tuple>
#include <utility>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/SmilesParse/SmilesWrite.h>
#include <GraphMol/Substruct/SubstructMatch.h>
#include <GraphMol/GenericGroups/GenericGroups.h>
#include <GraphMol/FileParsers/FileParsers.h>
#include <GraphMol/MarvinParse/MarvinParser.h>
using namespace RDKit;
class _IsSubstructOf : public Catch::Matchers::MatcherBase<const ROMol &> {
ROMol const *m_mol;
SubstructMatchParameters m_ps;
unsigned m_count;
public:
_IsSubstructOf(const ROMol &m, unsigned count, SubstructMatchParameters ps)
: m_mol(&m), m_ps(std::move(ps)), m_count(count) {}
bool match(const ROMol &query) const override {
return SubstructMatch(*m_mol, query, m_ps).size() == m_count;
}
std::string describe() const override {
std::ostringstream ss;
ss << "does not have expected number of matches to "
<< MolToCXSmiles(*m_mol);
return ss.str();
}
};
static _IsSubstructOf IsSubstructOf(const ROMol &m, unsigned count,
const SubstructMatchParameters &ps) {
return _IsSubstructOf(m, count, ps);
}
TEST_CASE("edge cases", "[substructure][generics]") {
SECTION("basics") {
auto query = "O=C* |$;Foo_p$|"_smarts;
REQUIRE(query);
query->getAtomWithIdx(2)->setProp(common_properties::_QueryAtomGenericLabel,
"Foo");
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 1}, {"O=CC=C", 1}, {"O=C", 0}};
SubstructMatchParameters ps;
ps.useGenericMatchers = true;
for (const auto &pr : tests) {
SmilesParserParams smilesParms;
smilesParms.removeHs = false;
std::unique_ptr<ROMol> mol{SmilesToMol(pr.first, smilesParms)};
REQUIRE(mol);
CHECK_THAT(*query, IsSubstructOf(*mol, pr.second, ps));
}
}
}
TEST_CASE("Setting generic queries", "[substructure][generics]") {
SECTION("cxsmiles") {
auto m = "CO* |$;foo_p;ARY_p$|"_smiles;
REQUIRE(m);
auto atm = m->getAtomWithIdx(2);
CHECK(atm->hasProp(common_properties::atomLabel));
GenericGroups::setGenericQueriesFromProperties(*m);
CHECK(atm->hasProp(common_properties::_QueryAtomGenericLabel));
CHECK(atm->getProp<std::string>(
common_properties::_QueryAtomGenericLabel) == "ARY");
CHECK(!atm->hasProp(common_properties::atomLabel));
// make sure we didn't remove the other atom label
CHECK(m->getAtomWithIdx(1)->hasProp(common_properties::atomLabel));
{
auto smi = MolToCXSmiles(*m, SmilesWriteParams(),
SmilesWrite::CXSmilesFields::CX_ATOM_LABELS);
CHECK(smi == "*OC |$ARY_p;foo_p;$|");
std::unique_ptr<ROMol> m2{SmilesToMol(smi)};
REQUIRE(m2);
GenericGroups::setGenericQueriesFromProperties(*m2);
CHECK(m2->getAtomWithIdx(0)->hasProp(
common_properties::_QueryAtomGenericLabel));
}
{
auto ctab = MolToV3KMolBlock(*m);
CHECK(ctab.find("ARY") != std::string::npos);
}
}
SECTION("CTAB") {
auto m = R"CTAB(
Mrv2108 11042108512D
0 0 0 0 0 999 V3000
M V30 BEGIN CTAB
M V30 COUNTS 7 7 3 0 0
M V30 BEGIN ATOM
M V30 1 C -0.0001 0.77 0 0
M V30 2 N -1.3336 0.0001 0 0
M V30 3 C -1.3336 -1.54 0 0
M V30 4 C -0.0001 -2.31 0 0
M V30 5 C 1.3336 -1.54 0 0
M V30 6 N 1.3336 0.0001 0 0
M V30 7 C -0.0001 2.31 0 0
M V30 END ATOM
M V30 BEGIN BOND
M V30 1 2 3 4
M V30 2 1 4 5
M V30 3 2 1 2
M V30 4 1 2 3
M V30 5 1 1 6
M V30 6 2 5 6
M V30 7 1 1 7
M V30 END BOND
M V30 BEGIN SGROUP
M V30 1 SUP 0 -
M V30 ATOMS=(1 7) -
M V30 LABEL="AOX"
M V30 2 DAT 0 ATOMS=(1 6) FIELDNAME=data -
M V30 FIELDDISP=" 1.3336 0.0001 DAU ALL 0 0" -
M V30 MRV_FIELDDISP=0 FIELDDATA=value
M V30 3 SUP 0 -
M V30 ATOMS=(1 5) -
M V30 LABEL="carbon"
M V30 END SGROUP
M V30 END CTAB
M END
)CTAB"_ctab;
REQUIRE(m);
auto atm = m->getAtomWithIdx(6);
CHECK(getSubstanceGroups(*m).size() == 3);
GenericGroups::setGenericQueriesFromProperties(*m);
CHECK(atm->hasProp(common_properties::_QueryAtomGenericLabel));
CHECK(atm->getProp<std::string>(
common_properties::_QueryAtomGenericLabel) == "AOX");
CHECK(getSubstanceGroups(*m).size() == 2);
{
auto smi = MolToCXSmiles(*m, SmilesWriteParams(),
SmilesWrite::CXSmilesFields::CX_ATOM_LABELS);
CHECK(smi == "Cc1ncccn1 |$AOX_p;;;;;;$|");
std::unique_ptr<ROMol> m2{SmilesToMol(smi)};
REQUIRE(m2);
GenericGroups::setGenericQueriesFromProperties(*m2);
CHECK(m2->getAtomWithIdx(0)->hasProp(
common_properties::_QueryAtomGenericLabel));
}
{
RWMol m2(*m);
GenericGroups::convertGenericQueriesToSubstanceGroups(m2);
CHECK(getSubstanceGroups(m2).size() == getSubstanceGroups(*m).size() + 1);
CHECK(!m2.getAtomWithIdx(0)->hasProp(
common_properties::_QueryAtomGenericLabel));
}
{
auto ctab = MolToV3KMolBlock(*m);
CHECK(ctab.find("AOX") != std::string::npos);
}
}
}
namespace {
bool no_match(const ROMol &mol, const std::vector<unsigned int> &ids) {
RDUNUSED_PARAM(mol);
RDUNUSED_PARAM(ids);
return false;
}
bool always_match(const ROMol &mol, const std::vector<unsigned int> &ids) {
RDUNUSED_PARAM(mol);
RDUNUSED_PARAM(ids);
return true;
}
} // namespace
TEST_CASE("generics are compatible with extraFinalChecks",
"[substructure][generics]") {
SECTION("basics") {
auto query = "O=C*"_smarts;
REQUIRE(query);
std::vector<std::string> labels = {"Heteroaryl", "HAR"};
for (auto label : labels) {
query->getAtomWithIdx(2)->setProp(
common_properties::_QueryAtomGenericLabel, label);
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1OC1", 0}, {"O=CCC1COC1", 0}, {"O=CC1CCC2C1CNC2", 0},
{"O=Cc1cccc2c1ccnc2", 1}, {"O=Cc1ccccc1", 0}, {"O=Cc1cccnc1", 1},
};
SubstructMatchParameters ps;
ps.useGenericMatchers = true;
ps.extraFinalCheck = always_match;
for (const auto &pr : tests) {
SmilesParserParams smilesParms;
smilesParms.removeHs = false;
std::unique_ptr<ROMol> mol{SmilesToMol(pr.first, smilesParms)};
REQUIRE(mol);
CHECK_THAT(*query, IsSubstructOf(*mol, pr.second, ps));
}
ps.extraFinalCheck = no_match;
for (const auto &pr : tests) {
SmilesParserParams smilesParms;
smilesParms.removeHs = false;
std::unique_ptr<ROMol> mol{SmilesToMol(pr.first, smilesParms)};
REQUIRE(mol);
CHECK_THAT(*query, IsSubstructOf(*mol, 0, ps));
}
}
}
}
std::string getCXSmilesQuery(const std::string groupToTest) {
std::ostringstream out;
out << "*C=O |$" << groupToTest << ";;$|";
return out.str();
}
std::string getMolQuery(const std::string groupToTest,
bool supGroupFlag = false) {
std::ostringstream out;
if (!supGroupFlag) {
// pad the groupToTest with spaces to make it 3 characters long
std::string groupToTestPadded = groupToTest;
while (groupToTestPadded.length() < 3) {
groupToTestPadded += " ";
}
out << R"MOLQQQ(
Ketcher 3212315322D 1 1.00000 0.00000 0
3 2 0 0 0 0 0 0 0 0999 V2000
9.2250 -1.6000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
10.0910 -2.1000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
10.9570 -1.6000 0.0000 )MOLQQQ"
<< groupToTestPadded << R"MOLQQQ( 0 0 0 0 0 0 0 0 0 0 0 0
1 2 2 0 0 0
2 3 1 0 0 0
M END
)MOLQQQ";
} else {
out << R"MOLQQQ(
Ketcher 3202311 72D 1 1.00000 0.00000 0
3 2 0 0 0 0 0 0 0 0999 V2000
6.3840 61.5000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
7.2500 61.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
8.1160 61.5000 0.0000 * 0 0 0 0 0 0 0 0 0 0 0 0
1 2 2 0 0 0
2 3 1 0 0 0
M STY 1 1 SUP
M SLB 1 1 1
M SAL 1 1 3
M SBL 1 1 2
M SMT 1 )MOLQQQ"
<< groupToTest << R"MOLQQQ(
M END
)MOLQQQ";
}
return out.str();
}
std::string getMRVQuery(const std::string groupToTest) {
std::ostringstream out;
out << R"MRVQQQ(<cml xmlns="http://www.chemaxon.com" version="ChemAxon file format v20.20.0, generated by vunknown" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com http://www.chemaxon.com/marvin/schema/mrvSchema_20_20_0.xsd">
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray>
<atom id="a1" elementType="O" x2="-1.3336693410482567" y2="0.3850084702795158" lonePair="2"/>
<atom id="a2" elementType="C" x2="0" y2="-0.3850084702795158"/>
<atom id="a3" elementType="R" x2="1.3336693410482567" y2="0.3850084702795158" sgroupRef="sg1"/>
</atomArray>
<bondArray>
<bond id="b1" atomRefs2="a1 a2" order="2"/>
<bond id="b2" atomRefs2="a2 a3" order="1"/>
</bondArray>
<molecule molID="m2" id="sg1" role="SuperatomSgroup" title=")MRVQQQ"
<< groupToTest << R"MRVQQQ(">
<atomArray>
<atom id="a4" elementType="*" x2="1.3336693410482567" y2="0.3850084702795158" sgroupAttachmentPoint="1"/>
</atomArray>
<AttachmentPointArray>
<attachmentPoint atom="a4" order="1" bond="b2"/>
</AttachmentPointArray>
</molecule>
</molecule>
</MChemicalStruct>
<MElectronContainer occupation="0 0" radical="0" id="o1">
<MElectron atomRefs="m1.a1" difLoc="0.0 0.0 0.0"/>
<MElectron atomRefs="m1.a1" difLoc="0.0 0.0 0.0"/>
</MElectronContainer>
<MElectronContainer occupation="0 0" radical="0" id="o2">
<MElectron atomRefs="m1.a1" difLoc="0.0 0.0 0.0"/>
<MElectron atomRefs="m1.a1" difLoc="0.0 0.0 0.0"/>
</MElectronContainer>
</MDocument>
</cml>
)MRVQQQ";
return out.str();
}
void runTest(RWMol *query,
std::vector<std::pair<std::string, unsigned>> &tests) {
GenericGroups::setGenericQueriesFromProperties(*query, true, true);
SubstructMatchParameters ps;
ps.useGenericMatchers = true;
ps.extraFinalCheck = always_match;
for (const auto &pr : tests) {
SmilesParserParams smilesParms;
smilesParms.removeHs = false;
std::unique_ptr<ROMol> mol{SmilesToMol(pr.first, smilesParms)};
REQUIRE(mol);
CHECK_THAT(*query, IsSubstructOf(*mol, pr.second, ps));
}
ps.extraFinalCheck = no_match;
for (const auto &pr : tests) {
SmilesParserParams smilesParms;
smilesParms.removeHs = false;
std::unique_ptr<ROMol> mol{SmilesToMol(pr.first, smilesParms)};
REQUIRE(mol);
CHECK_THAT(*query, IsSubstructOf(*mol, 0, ps));
}
}
void runCxsmilesTest(const std::string groupToTest,
std::vector<std::pair<std::string, unsigned>> &tests,
bool manualInsertOfGroupFlag = false) {
std::unique_ptr<RWMol> query;
if (!manualInsertOfGroupFlag) {
std::string queryString = getCXSmilesQuery(groupToTest);
query = std::unique_ptr<RWMol>(SmartsToMol(queryString));
} else {
query = std::unique_ptr<RWMol>(SmartsToMol("*C=O |$;;$|"));
query->getAtomWithIdx(0)->setProp(RDKit::common_properties::atomLabel,
groupToTest);
}
runTest(query.get(), tests);
}
void runMolTest(const std::string groupToTest,
std::vector<std::pair<std::string, unsigned>> &tests,
bool supGroupFlag) {
std::string queryString = getMolQuery(groupToTest, supGroupFlag);
auto query =
std::unique_ptr<RWMol>(MolBlockToMol(queryString, false, false, false));
runTest(query.get(), tests);
}
void runMRVTest(const std::string groupToTest,
std::vector<std::pair<std::string, unsigned>> &tests) {
std::string queryString = getMRVQuery(groupToTest);
auto query = std::unique_ptr<RWMol>(MrvBlockToMol(queryString, false, false));
runTest(query.get(), tests);
}
void runTest(const std::string groupToTest,
std::vector<std::pair<std::string, unsigned>> &tests) {
runCxsmilesTest(groupToTest, tests, false);
runCxsmilesTest(groupToTest, tests, true);
runMolTest(groupToTest, tests, true);
if (groupToTest.size() <= 3) {
runMolTest(groupToTest, tests, false);
}
runMolTest(groupToTest, tests, true);
runMRVTest(groupToTest, tests);
}
TEST_CASE("alkyl", "[substructure][generics]") {
SECTION("Basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 1}, {"O=CC=C", 0}, {"O=CCC=C", 0},
{"O=CCO", 0}, {"O=CC", 1}, {"O=CC[H]", 1},
{"O=C[H]", 0}, {"O=CC.CC(C=O)C", 2}, {"O=CCC1CC1", 0}};
runTest("Alkyl", tests);
runTest("ALK", tests);
}
}
TEST_CASE("alkyl or h", "[substructure][generics]") {
SECTION("Basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 1}, {"O=CC=C", 0}, {"O=CCC=C", 0},
{"O=CCO", 0}, {"O=CC", 1}, {"O=CC[H]", 1},
{"O=C[H]", 1}, {"O=CC.CC(C=O)C", 2}, {"O=CCC1CC1", 0}};
runTest("AlkylH", tests);
runTest("ALH", tests);
}
}
TEST_CASE("carboacyclic", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CC1", 0}, {"O=CCCCC1CCC1", 0},
{"O=CCCCC", 1}, {"O=CC([H])([H])([H])", 1},
{"O=CCCCO", 0}, {"O=C[H]", 0},
};
runTest("Carboacyclic", tests);
runTest("ABC", tests);
}
}
TEST_CASE("carboacyclic or h", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CC1", 0}, {"O=CCCCC1CCC1", 0},
{"O=CCCCC", 1}, {"O=CC([H])([H])([H])", 1},
{"O=CCCCO", 0}, {"O=C[H]", 1},
};
runTest("CarboacyclicH", tests);
runTest("ABH", tests);
}
}
TEST_CASE("acyclic", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CC1", 0}, {"O=CCCCC1CCC1", 0}, {"O=CCCCC", 1},
{"O=CCCCO", 1}, {"O=C[H]", 0},
};
runTest("Acyclic", tests);
runTest("ACY", tests);
}
}
TEST_CASE("acyclic or h", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CC1", 0}, {"O=CCCCC1CCC1", 0}, {"O=CCCCC", 1},
{"O=CCCCO", 1}, {"O=C[H]", 1},
};
runTest("AcyclicH", tests);
runTest("ACH", tests);
}
}
TEST_CASE("Alkenyl", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 0}, {"O=CC=C", 1}, {"O=CCC=C", 1}, {"O=CCC#C", 0},
{"O=CC=N", 0}, {"O=CC=C[H]", 1}, {"O=CCC1CC=C1", 0}, {"O=C[H]", 0}};
runTest("Alkenyl", tests);
runTest("AEL", tests);
}
}
TEST_CASE("Alkenyl or h", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 0}, {"O=CC=C", 1}, {"O=CCC=C", 1}, {"O=CCC#C", 0},
{"O=CC=N", 0}, {"O=CC=C[H]", 1}, {"O=CCC1CC=C1", 0}, {"O=C[H]", 1}};
runTest("AlkenylH", tests);
runTest("AEH", tests);
}
}
TEST_CASE("Alkynyl", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 0}, {"O=CC#C", 1}, {"O=CCC#C", 1},
{"O=CCC=C", 0}, {"O=CC#N", 0}, {"O=CC#C[H]", 1},
{"O=CCC1CC#C1", 0}, {"O=C([H])[H]", 0}};
runTest("Alkynyl", tests);
runTest("AYL", tests);
}
}
TEST_CASE("Alkynyl or h", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 0}, {"O=CC#C", 1}, {"O=CCC#C", 1},
{"O=CCC=C", 0}, {"O=CC#N", 0}, {"O=CC#C[H]", 1},
{"O=CCC1CC#C1", 0}, {"O=C([H])[H]", 2}};
runTest("AlkynylH", tests);
runTest("AYH", tests);
}
}
TEST_CASE("Heteroacyclic", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1OC1", 0}, {"O=CCCCC1CCC1", 0}, {"O=CCCCC", 0},
{"O=CCCCO", 1}, {"O=C[H]", 0},
};
runTest("Heteroacyclic", tests);
runTest("AHC", tests);
}
}
TEST_CASE("Heteroacyclic or h", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1OC1", 0}, {"O=CCCCC1CCC1", 0}, {"O=CCCCC", 0},
{"O=CCCCO", 1}, {"O=C[H]", 1},
};
runTest("HeteroacyclicH", tests);
runTest("AHH", tests);
}
}
TEST_CASE("alkoxy", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 0}, {"O=COC", 1}, {"O=COC=C", 0},
{"O=COC=C", 0}, {"O=COCO", 0}, {"O=CO", 0},
{"O=CO[H]", 0}, {"O=COC1CC1", 0}, {"O=C([H])[H]", 0}};
runTest("Alkoxy", tests);
runTest("AOX", tests);
}
}
TEST_CASE("alkoxy or H", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 0}, {"O=COC", 1}, {"O=COC=C", 0},
{"O=COC=C", 0}, {"O=COCO", 0}, {"O=CO", 0},
{"O=CO[H]", 0}, {"O=COC1CC1", 0}, {"O=C([H])[H]", 2}};
runTest("AlkoxyH", tests);
runTest("AOH", tests);
}
}
TEST_CASE("carboaryl", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CCCCC1", 0}, {"O=Cc1ccccc1", 1},
{"O=CC1=CC=CC2=C1CCCC2", 0}, {"O=Cc1cccnc1", 0},
{"O=CC1=CC=CC2=C1CCNC2", 0}, {"O=C([H])[H]", 0}};
runTest("Carboaryl", tests);
runTest("ARY", tests);
}
}
TEST_CASE("carboaryl or H", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CCCCC1", 0}, {"O=Cc1ccccc1", 1},
{"O=CC1=CC=CC2=C1CCCC2", 0}, {"O=Cc1cccnc1", 0},
{"O=CC1=CC=CC2=C1CCNC2", 0}, {"O=C([H])[H]", 2}};
runTest("CarboarylH", tests);
runTest("ARH", tests);
}
}
TEST_CASE("cycloalkyl", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 0}, {"O=CC1CC1", 1},
{"O=CC1C(O)C1", 1}, {"O=CCC1CC1", 0},
{"O=CC1C=C1", 0}, {"O=CC1OC1", 0},
{"O=CC1CC(=O)C1", 1}, {"O=CC1CC2CCC1CC2", 1},
{"O=CC1CC2CCC1NC2", 0}, {"O=CC1CCCC2CC=CCC12", 0},
{"O=C([H])[H]", 0}};
runTest("Carbocycloalkyl", tests);
runTest("CAL", tests);
}
}
TEST_CASE("cycloalkyl or H", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 0}, {"O=CC1CC1", 1},
{"O=CC1C(O)C1", 1}, {"O=CCC1CC1", 0},
{"O=CC1C=C1", 0}, {"O=CC1OC1", 0},
{"O=CC1CC(=O)C1", 1}, {"O=CC1CC2CCC1CC2", 1},
{"O=CC1CC2CCC1NC2", 0}, {"O=CC1CCCC2CC=CCC12", 0},
{"O=C([H])[H]", 2}};
runTest("CarbocycloalkylH", tests);
runTest("CAH", tests);
}
}
TEST_CASE("carbocyclic", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CCCCC1", 1}, {"O=Cc1ccccc1", 1},
{"O=Cc1ccc(O)cc1", 1}, {"O=CC1=CC=CC2=C1CCCC2", 1},
{"O=Cc1cccnc1", 0}, {"O=CC1=CC=CC2=C1CCNC2", 0},
{"O=C([H])[H]", 0},
};
runTest("Carbocyclic", tests);
runTest("CBC", tests);
}
}
TEST_CASE("carbocyclic or H", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CCCCC1", 1}, {"O=Cc1ccccc1", 1},
{"O=Cc1ccc(O)cc1", 1}, {"O=CC1=CC=CC2=C1CCCC2", 1},
{"O=Cc1cccnc1", 0}, {"O=CC1=CC=CC2=C1CCNC2", 0},
{"O=C([H])[H]", 2},
};
runTest("CarbocyclicH", tests);
runTest("CBH", tests);
}
}
TEST_CASE("cycloalkenyl", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 0},
{"O=Cc1ccccc1", 1},
{"O=CC1CC=CCC1", 1},
{"O=CC1CC2CCC1CC2", 0},
{"O=CC1CC2CCC1C=C2", 0}, // <- one of the SSSR rings doesn't match
{"O=CC1CC2C=CC1NC2", 0},
{"O=CC1CCCC2=C1CCCC2", 1},
{"O=CC1CC=CC2C1C=CC1CCC=CC21", 1},
{"O=CC1CC=CC2C1C=CC1CNC=CC21", 0},
{"O=C([H])[H]", 0},
};
runTest("Carbocycloalkenyl", tests);
runTest("CEL", tests);
}
}
TEST_CASE("cycloalkenyl or H", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCC", 0},
{"O=Cc1ccccc1", 1},
{"O=CC1CC=CCC1", 1},
{"O=CC1CC2CCC1CC2", 0},
{"O=CC1CC2CCC1C=C2", 0}, // <- one of the SSSR
// rings doesn't match
{"O=CC1CC2C=CC1NC2", 0},
{"O=CC1CCCC2=C1CCCC2", 1},
{"O=CC1CC=CC2C1C=CC1CCC=CC21", 1},
{"O=CC1CC=CC2C1C=CC1CNC=CC21", 0},
{"O=C([H])[H]", 2},
};
runTest("CarbocycloalkenylH", tests);
runTest("CEH", tests);
}
}
TEST_CASE("heterocyclic", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1OC1", 1}, {"O=CC1CC1", 0}, {"O=CCC1COC1", 0},
{"O=CC1CCC2C1CNC2", 1}, {"O=Cc1ccccc1", 0}, {"O=Cc1cccnc1", 1},
{"O=C([H])[H]", 0},
};
runTest("Heterocyclic", tests);
runTest("CHC", tests);
}
}
TEST_CASE("heterocyclic or H", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1OC1", 1}, {"O=CC1CC1", 0}, {"O=CCC1COC1", 0},
{"O=CC1CCC2C1CNC2", 1}, {"O=Cc1ccccc1", 0}, {"O=Cc1cccnc1", 1},
{"O=C([H])[H]", 2},
};
runTest("HeterocyclicH", tests);
runTest("CHH", tests);
}
}
TEST_CASE("no carbon ring", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CN1NC1", 0}, {"O=CN1NN1", 1}, {"O=CCN1NNN1", 0},
{"O=CN1NNNN2N1N2", 1}, {"O=CN1NNNN2N1C2", 0}, {"O=CNNN", 0},
{"O=C1NNN1", 0}, {"O=C([H])[H]", 0},
};
runTest("NoCarbonRing", tests);
runTest("CXX", tests);
}
}
TEST_CASE("no carbon ring or H", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CN1NC1", 0}, {"O=CN1NN1", 1}, {"O=CCN1NNN1", 0},
{"O=CN1NNNN2N1N2", 1}, {"O=CN1NNNN2N1C2", 0}, {"O=CNNN", 0},
{"O=C1NNN1", 0}, {"O=C([H])[H]", 2},
};
runTest("NoCarbonRingH", tests);
runTest("CXH", tests);
}
}
TEST_CASE("cyclic", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CCC1", 1}, {"O=C1CCCC1", 0}, {"O=CCC1CCC1", 0},
{"O=CC1CNC1", 1}, {"O=Cc1ccccc1", 1}, {"O=CC1CC2C1C2", 1},
{"O=CC1CC2CCC1CC2", 1}, {"O=C([H])[H]", 0},
};
runTest("Cyclic", tests);
runTest("CYC", tests);
}
}
TEST_CASE("cyclic or H", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CCC1", 1}, {"O=C1CCCC1", 0}, {"O=CCC1CCC1", 0},
{"O=CC1CNC1", 1}, {"O=Cc1ccccc1", 1}, {"O=CC1CC2C1C2", 1},
{"O=CC1CC2CCC1CC2", 1}, {"O=C([H])[H]", 2},
};
runTest("CyclicH", tests);
runTest("CYH", tests);
}
}
TEST_CASE("heteroaryl", "[substructure][generics]") {
SECTION("basics") {
std::string query = "*C=O |$HAH;;$|";
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1OC1", 0}, {"O=CCC1COC1", 0}, {"O=CC1CCC2C1CNC2", 0},
{"O=Cc1cccc2c1ccnc2", 1}, {"O=Cc1ccccc1", 0}, {"O=Cc1cccnc1", 1},
{"O=C([H])[H]", 0},
};
runTest("Heteroaryl", tests);
runTest("HAR", tests);
}
}
TEST_CASE("heteroaryl or H", "[substructure][generics]") {
SECTION("basics") {
std::string query = "*C=O |$HAH;;$|";
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1OC1", 0}, {"O=CCC1COC1", 0}, {"O=CC1CCC2C1CNC2", 0},
{"O=Cc1cccc2c1ccnc2", 1}, {"O=Cc1ccccc1", 0}, {"O=Cc1cccnc1", 1},
{"O=C([H])[H]", 2},
};
runTest("HeteroarylH", tests);
runTest("HAH", tests);
}
}
TEST_CASE("group", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CCC1", 1}, {"O=CCCCC", 1}, {"O=CCC1CCC1", 1},
{"O=CC1CNC1", 1}, {"O=Cc1ccccc1", 1}, {"O=CC1CC2C1C2", 1},
{"O=CC1CC2CCC1CC2", 1}, {"O=C([H])[H]", 0},
};
runTest("Group", tests);
runTest("G", tests);
}
}
TEST_CASE("group or H", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CCC1", 1}, {"O=CCCCC", 1}, {"O=CCC1CCC1", 1},
{"O=CC1CNC1", 1}, {"O=Cc1ccccc1", 1}, {"O=CC1CC2C1C2", 1},
{"O=CC1CC2CCC1CC2", 1}, {"O=C([H])[H]", 2},
};
runTest("GroupH", tests);
runTest("GH", tests);
}
}
TEST_CASE("group with ring", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CCCCC", 0}, {"O=CCC1CCC1", 1}, {"O=CC1CNC1", 1},
{"O=Cc1ccccc1", 1}, {"O=CC1CC2C1C2", 1}, {"O=CC1CC2CCC1CC2", 1},
{"O=C([H])[H]", 0},
};
runTest("Group*", tests);
runTest("G*", tests);
}
}
TEST_CASE("group with ring or H", "[substructure][generics]") {
SECTION("basics") {
std::vector<std::pair<std::string, unsigned>> tests = {
{"O=CC1CCC1", 1}, {"O=CCCCC", 0}, {"O=CCC1CCC1", 1},
{"O=CC1CNC1", 1}, {"O=Cc1ccccc1", 1}, {"O=CC1CC2C1C2", 1},
{"O=CC1CC2CCC1CC2", 1}, {"O=C([H])[H]", 2},
};
runTest("GroupH*", tests);
runTest("GH*", tests);
}
}
TEST_CASE("from mol blocks using atom labels") {
SECTION("basics") {
auto qry = R"CTAB(
Mrv2211 08032317212D
0 0 0 0 0 999 V3000
M V30 BEGIN CTAB
M V30 COUNTS 2 1 0 0 0
M V30 BEGIN ATOM
M V30 1 C -6.5833 1.9167 0 0
M V30 2 ARY -5.2497 2.6867 0 0
M V30 END ATOM
M V30 BEGIN BOND
M V30 1 1 1 2
M V30 END BOND
M V30 END CTAB
M END
)CTAB"_ctab;
REQUIRE(qry);
SubstructMatchParameters ps;
ps.useGenericMatchers = true;
auto m1 = "CC"_smiles;
REQUIRE(m1);
auto m2 = "Cc1ccccc1"_smiles;
REQUIRE(m2);
CHECK(SubstructMatch(*m1, *qry, ps).empty());
CHECK(SubstructMatch(*m2, *qry, ps).empty());
GenericGroups::setGenericQueriesFromProperties(*qry, true);
CHECK(SubstructMatch(*m1, *qry, ps).empty());
CHECK(SubstructMatch(*m2, *qry, ps).size() == 1);
}
}
void testGenericQueries() {
BOOST_LOG(rdInfoLog) << "-----------------------\n Testing generic queries: "
"Set GenericQueriesFromProperties"
<< std::endl;
auto query = R"CTAB(alkquery.mol
Generated by WebMolKit
0 0 0 0 0 999 V3000
M V30 BEGIN CTAB
M V30 COUNTS 2 1 1 0 1
M V30 BEGIN ATOM
M V30 1 O 7.4214 -9.6318 0.0000 0
M V30 2 * 8.5430 -10.2809 0.0000 0
M V30 END ATOM
M V30 BEGIN BOND
M V30 1 1 1 2
M V30 END BOND
M V30 BEGIN SGROUP
M V30 1 SUP 0 LABEL=ALK ATOMS=(1 2)
M V30 END SGROUP
M V30 END CTAB
M END)CTAB"_ctab;
TEST_ASSERT(query);
std::string target_smi{"c1c(OF)cccc1"};
std::unique_ptr<RWMol> t{SmilesToMol(target_smi)};
TEST_ASSERT(t);
MolOps::AdjustQueryParameters params;
auto m = new RWMol(*query);
TEST_ASSERT(m);
MolOps::adjustQueryProperties(*m, ¶ms);
SubstructMatchParameters params_match;
params_match.useQueryQueryMatches = true;
params_match.useGenericMatchers = true;
params_match.maxMatches = 1;
auto matchVect = SubstructMatch(*t, *m, params_match);
TEST_ASSERT(matchVect.size() == 1);
delete m;
m = new RWMol(*query);
GenericGroups::adjustQueryPropertiesWithGenericGroups(*m, ¶ms);
matchVect = SubstructMatch(*t, *m, params_match);
TEST_ASSERT(matchVect.size() == 0);
delete m;
m = new RWMol(*query);
GenericGroups::adjustQueryPropertiesWithGenericGroups(*m);
matchVect = SubstructMatch(*t, *m, params_match);
TEST_ASSERT(matchVect.size() == 0);
delete m;
}
|