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
|
//
// Copyright (C) 2022 Greg Landrum and other RDKit contributors
//
// @@ 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.
//
#include "catch.hpp"
#include <GraphMol/RDKitBase.h>
#include <GraphMol/StereoGroup.h>
#include <GraphMol/Chirality.h>
#include <GraphMol/new_canon.h>
#include <GraphMol/MolOps.h>
#include <GraphMol/FileParsers/FileParsers.h>
#include <GraphMol/FileParsers/MolFileStereochem.h>
#include <GraphMol/FileParsers/MolSupplier.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/SmilesParse/SmilesWrite.h>
using namespace RDKit;
TEST_CASE("chirality and canonicalization") {
SECTION("basics") {
auto mol = "F[C@](O)(Cl)C[C@](F)(O)Cl"_smiles;
REQUIRE(mol);
bool cleanIt = true;
bool force = true;
MolOps::assignStereochemistry(*mol, cleanIt, force);
std::string cip;
CHECK(mol->getAtomWithIdx(1)->getPropIfPresent(common_properties::_CIPCode,
cip));
CHECK(cip == "S");
CHECK(mol->getAtomWithIdx(5)->getPropIfPresent(common_properties::_CIPCode,
cip));
CHECK(cip == "R");
std::vector<unsigned int> ranks;
bool breakTies = false;
Canon::rankMolAtoms(*mol, ranks, breakTies);
CHECK(ranks[1] > ranks[5]);
mol->getAtomWithIdx(1)->clearProp(common_properties::_CIPCode);
mol->getAtomWithIdx(5)->clearProp(common_properties::_CIPCode);
Canon::rankMolAtoms(*mol, ranks, breakTies);
CHECK(ranks[1] > ranks[5]);
}
SECTION("same") {
auto mol = "F[C@](O)(Cl)C[C@](O)(F)Cl"_smiles;
REQUIRE(mol);
bool cleanIt = true;
bool force = true;
MolOps::assignStereochemistry(*mol, cleanIt, force);
std::string cip;
CHECK(mol->getAtomWithIdx(1)->getPropIfPresent(common_properties::_CIPCode,
cip));
CHECK(cip == "S");
CHECK(mol->getAtomWithIdx(5)->getPropIfPresent(common_properties::_CIPCode,
cip));
CHECK(cip == "S");
std::vector<unsigned int> ranks;
bool breakTies = false;
Canon::rankMolAtoms(*mol, ranks, breakTies);
CHECK(ranks[1] == ranks[5]);
mol->getAtomWithIdx(1)->clearProp(common_properties::_CIPCode);
mol->getAtomWithIdx(5)->clearProp(common_properties::_CIPCode);
Canon::rankMolAtoms(*mol, ranks, breakTies);
CHECK(ranks[1] == ranks[5]);
}
SECTION("dependent") {
auto mol = "F[C@](O)(Cl)[C@](F)(O)[C@](F)(O)Cl"_smiles;
REQUIRE(mol);
bool cleanIt = true;
bool force = true;
MolOps::assignStereochemistry(*mol, cleanIt, force);
std::string cip;
CHECK(mol->getAtomWithIdx(1)->getPropIfPresent(common_properties::_CIPCode,
cip));
CHECK(cip == "S");
CHECK(mol->getAtomWithIdx(7)->getPropIfPresent(common_properties::_CIPCode,
cip));
CHECK(cip == "R");
CHECK(mol->getAtomWithIdx(4)->getPropIfPresent(common_properties::_CIPCode,
cip));
CHECK(cip == "R");
std::vector<unsigned int> ranks;
bool breakTies = false;
Canon::rankMolAtoms(*mol, ranks, breakTies);
CHECK(ranks[1] > ranks[7]);
mol->getAtomWithIdx(1)->clearProp(common_properties::_CIPCode);
mol->getAtomWithIdx(4)->clearProp(common_properties::_CIPCode);
mol->getAtomWithIdx(7)->clearProp(common_properties::_CIPCode);
Canon::rankMolAtoms(*mol, ranks, breakTies);
CHECK(ranks[1] > ranks[7]);
}
SECTION("dependent non-chiral") {
auto mol = "F[C@](O)(Cl)[C@](F)(O)[C@](O)(F)Cl"_smiles;
REQUIRE(mol);
bool cleanIt = false;
bool force = true;
mol->getAtomWithIdx(4)->setChiralTag(Atom::ChiralType::CHI_TETRAHEDRAL_CCW);
MolOps::assignStereochemistry(*mol, cleanIt, force);
std::string cip;
CHECK(mol->getAtomWithIdx(1)->getPropIfPresent(common_properties::_CIPCode,
cip));
CHECK(cip == "S");
CHECK(mol->getAtomWithIdx(7)->getPropIfPresent(common_properties::_CIPCode,
cip));
CHECK(cip == "S");
std::vector<unsigned int> ranks;
bool breakTies = false;
Canon::rankMolAtoms(*mol, ranks, breakTies);
CHECK(ranks[1] == ranks[7]);
mol->getAtomWithIdx(1)->clearProp(common_properties::_CIPCode);
mol->getAtomWithIdx(7)->clearProp(common_properties::_CIPCode);
Canon::rankMolAtoms(*mol, ranks, breakTies);
CHECK(ranks[1] == ranks[7]);
}
SECTION("swap parity") {
auto mol = "F[C@](O)(Cl)C[C@@](O)(Cl)F"_smiles;
REQUIRE(mol);
bool cleanIt = false;
bool force = true;
MolOps::assignStereochemistry(*mol, cleanIt, force);
std::string cip;
CHECK(mol->getAtomWithIdx(1)->getPropIfPresent(common_properties::_CIPCode,
cip));
CHECK(cip == "S");
CHECK(mol->getAtomWithIdx(5)->getPropIfPresent(common_properties::_CIPCode,
cip));
CHECK(cip == "S");
std::vector<unsigned int> ranks;
bool breakTies = false;
Canon::rankMolAtoms(*mol, ranks, breakTies);
CHECK(ranks[1] == ranks[5]);
mol->getAtomWithIdx(1)->clearProp(common_properties::_CIPCode);
mol->getAtomWithIdx(5)->clearProp(common_properties::_CIPCode);
Canon::rankMolAtoms(*mol, ranks, breakTies);
CHECK(ranks[1] == ranks[5]);
}
}
TEST_CASE("double bond stereo and canonicalization") {
SECTION("basics") {
auto mol = "CC=C(F)C(B)C(F)=CC"_smiles;
REQUIRE(mol);
mol->getBondWithIdx(1)->setStereoAtoms(0, 4);
mol->getBondWithIdx(1)->setStereo(Bond::BondStereo::STEREOTRANS);
mol->getBondWithIdx(7)->setStereoAtoms(4, 9);
mol->getBondWithIdx(7)->setStereo(Bond::BondStereo::STEREOCIS);
bool breakTies = false;
std::vector<unsigned int> ranks;
Canon::rankMolAtoms(*mol, ranks, breakTies);
std::copy(ranks.begin(), ranks.end(),
std::ostream_iterator<unsigned int>(std::cerr, " "));
std::cerr << std::endl;
mol->getBondWithIdx(1)->setStereo(Bond::BondStereo::STEREOCIS);
mol->getBondWithIdx(7)->setStereo(Bond::BondStereo::STEREOTRANS);
std::vector<unsigned int> ranks2;
Canon::rankMolAtoms(*mol, ranks2, breakTies);
std::copy(ranks2.begin(), ranks2.end(),
std::ostream_iterator<unsigned int>(std::cerr, " "));
std::cerr << std::endl;
CHECK(ranks[0] == ranks2[9]);
CHECK(ranks[1] == ranks2[8]);
CHECK(ranks[2] == ranks2[6]);
CHECK(ranks[3] == ranks2[7]);
CHECK(ranks[4] == ranks2[4]);
CHECK(ranks[5] == ranks2[5]);
// same as previous example, different controlling atoms
mol->getBondWithIdx(7)->setStereoAtoms(7, 9);
mol->getBondWithIdx(7)->setStereo(Bond::BondStereo::STEREOCIS);
std::vector<unsigned int> ranks3;
Canon::rankMolAtoms(*mol, ranks3, breakTies);
std::copy(ranks3.begin(), ranks3.end(),
std::ostream_iterator<unsigned int>(std::cerr, " "));
std::cerr << std::endl;
CHECK(ranks2 == ranks3);
}
SECTION("STEREOANY is higher priority than STEREONONE") {
auto mol = "CC=C(F)C(B)C(F)=CC"_smiles;
REQUIRE(mol);
mol->getBondWithIdx(7)->setStereoAtoms(4, 9);
mol->getBondWithIdx(7)->setStereo(Bond::BondStereo::STEREOANY);
bool breakTies = false;
std::vector<unsigned int> ranks;
Canon::rankMolAtoms(*mol, ranks, breakTies);
std::copy(ranks.begin(), ranks.end(),
std::ostream_iterator<unsigned int>(std::cerr, " "));
std::cerr << std::endl;
CHECK(ranks[0] < ranks[9]);
}
}
|