mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
* Fixes #2647 * Updated tests * Fixes in response to review
This commit is contained in:
committed by
Greg Landrum
parent
d458e46548
commit
d55a2030cc
@@ -30,15 +30,17 @@ ROMol *pathToSubmol(const ROMol &mol, const PATH_TYPE &path, bool useQuery) {
|
||||
ROMol *pathToSubmol(const ROMol &mol, const PATH_TYPE &path, bool useQuery,
|
||||
INT_MAP_INT &atomIdxMap) {
|
||||
auto *subMol = new RWMol();
|
||||
PATH_TYPE::const_iterator pathIter;
|
||||
// path needs to be in sorted order to preserve chirality
|
||||
PATH_TYPE sorted_path(path);
|
||||
std::sort(sorted_path.begin(), sorted_path.end());
|
||||
|
||||
atomIdxMap.clear();
|
||||
|
||||
if (useQuery) {
|
||||
// have to do this in two different blocks because of issues with variable
|
||||
// scopes.
|
||||
for (pathIter = path.begin(); pathIter != path.end(); ++pathIter) {
|
||||
QueryBond *bond;
|
||||
bond = new QueryBond(*(mol.getBondWithIdx(*pathIter)));
|
||||
for(auto bondidx : sorted_path) {
|
||||
QueryBond *bond = new QueryBond(*(mol.getBondWithIdx(bondidx)));
|
||||
|
||||
int begIdx = bond->getBeginAtomIdx();
|
||||
int endIdx = bond->getEndAtomIdx();
|
||||
@@ -62,9 +64,8 @@ ROMol *pathToSubmol(const ROMol &mol, const PATH_TYPE &path, bool useQuery,
|
||||
subMol->addBond(bond, true);
|
||||
}
|
||||
} else {
|
||||
for (pathIter = path.begin(); pathIter != path.end(); ++pathIter) {
|
||||
Bond *bond;
|
||||
bond = mol.getBondWithIdx(*pathIter)->copy();
|
||||
for(auto bondidx : sorted_path) {
|
||||
Bond *bond = mol.getBondWithIdx(bondidx)->copy();
|
||||
|
||||
int begIdx = bond->getBeginAtomIdx();
|
||||
int endIdx = bond->getEndAtomIdx();
|
||||
|
||||
@@ -20,6 +20,12 @@
|
||||
using namespace std;
|
||||
using namespace RDKit;
|
||||
|
||||
std::string canon(std::string smiles) {
|
||||
unique_ptr<ROMol> m(SmilesToMol(smiles));
|
||||
const bool useStereo = true;
|
||||
return MolToSmiles(*m, useStereo);
|
||||
}
|
||||
|
||||
void test1() {
|
||||
std::cout << "-----------------------\n Test1: pathToSubmol" << std::endl;
|
||||
{
|
||||
@@ -123,7 +129,7 @@ void test2() {
|
||||
TEST_ASSERT(pth.size() == 8);
|
||||
ROMol *frag = Subgraphs::pathToSubmol(*mol, pth, false);
|
||||
smiles = MolToSmiles(*frag, true, false, 0, false);
|
||||
TEST_ASSERT(smiles == "C(C(C(O)C)C(C)C)C");
|
||||
TEST_ASSERT(canon(smiles) == canon("C(C(C(O)C)C(C)C)C"));
|
||||
delete frag;
|
||||
delete mol;
|
||||
}
|
||||
@@ -144,7 +150,7 @@ void testGithubIssue103() {
|
||||
TEST_ASSERT(pth.size() == 5);
|
||||
ROMol *frag = Subgraphs::pathToSubmol(*mol, pth, false);
|
||||
smiles = MolToSmiles(*frag, true);
|
||||
TEST_ASSERT(smiles == "C=CC(O)C=C");
|
||||
TEST_ASSERT(canon(smiles) == canon("C=CC(O)C=C"));
|
||||
delete frag;
|
||||
delete mol;
|
||||
}
|
||||
@@ -157,7 +163,7 @@ void testGithubIssue103() {
|
||||
TEST_ASSERT(pth.size() == 5);
|
||||
ROMol *frag = Subgraphs::pathToSubmol(*mol, pth, false);
|
||||
smiles = MolToSmarts(*frag);
|
||||
TEST_ASSERT(smiles == "[#6](-[#6@H](-[#8])-[#6]=[#6])=[#6]");
|
||||
TEST_ASSERT(smiles == "[#6]=[#6]-[#6@H](-[#8])-[#6]=[#6]");
|
||||
delete frag;
|
||||
delete mol;
|
||||
}
|
||||
@@ -170,7 +176,7 @@ void testGithubIssue103() {
|
||||
TEST_ASSERT(pth.size() == 5);
|
||||
ROMol *frag = Subgraphs::pathToSubmol(*mol, pth, true);
|
||||
smiles = MolToSmarts(*frag);
|
||||
TEST_ASSERT(smiles == "[#6](-[#6@](-[#8])-[#6]=[#6])=[#6]");
|
||||
TEST_ASSERT(smiles == "[#6]=[#6]-[#6@](-[#8])-[#6]=[#6]");
|
||||
delete frag;
|
||||
delete mol;
|
||||
}
|
||||
@@ -178,10 +184,24 @@ void testGithubIssue103() {
|
||||
std::cout << "Finished" << std::endl;
|
||||
}
|
||||
|
||||
void testGithubIssue2647() {
|
||||
std::cout << "-----------------------\n Testing github Issue103: "
|
||||
"more stereochemistry and pathToSubmol (path needs to be in sorted order)"
|
||||
<< std::endl;
|
||||
std::string smiles = "I[C@](F)(Br)O";
|
||||
std::unique_ptr<ROMol> mol(SmilesToMol(smiles));
|
||||
std::vector<int> path = { 0, 3, 2, 1 };
|
||||
const bool useQuery=false;
|
||||
std::unique_ptr<ROMol> mol2(Subgraphs::pathToSubmol(*mol, path, useQuery));
|
||||
TEST_ASSERT(MolToSmiles(*mol2) == MolToSmiles(*mol));
|
||||
std::cout << "Finished" << std::endl;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
int main() {
|
||||
test1();
|
||||
test2();
|
||||
testGithubIssue103();
|
||||
testGithubIssue2647();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user