mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-04 21:54:27 +08:00
* add a couple test files * backup * first pass at some theory documentatin * it's a draft * Update enhanced stereochemistry documentation Adds initial target use case and caveats about the tentative nature of the current implementation. * Support read/write of molfile enhanced stereochemistry This includes reading and writing of enhanced stereochemistry from v3000 molfiles (sdf). Enhanced stereochemistry encodes the relative configuration of stereocenters, allowing representation of racemic mixtures and compounds with unknown absolute stereochemistry. It does not include: * Python wrapping * invalidation of the enhanced stereochemistry * use of enhanced stereochemistry in search * depiction of enhanced stereochemistry. * Update to reflect changes from #1971 * change names of enum elements to allow compilation in VS2017 I think it's also clearer to do things this way * Addressed most review comments. * Run missed test "testEnhancedStereoChemistry" * In tests, added size checks to group equality checks * Updated copyright statements * Deleted mol created for a test * Use perfect forwarding in RWMol::setStereoGroups() * use references for stereo groups that are checked in write and pickle * Updated stereogroup.h in hopes of fixing compilation on Windows. * clang-format * try allowing a switch to boost regex and requiring it for g++-4.8 * do a better job of that * typo * Code review comments. Updated Copyright notice. * When an atom is deleted, delete stereo groups containing it. Also updates StereoGroup toUse accessors instead of constant member attributes. This allows move of StereoGroups. * RDKit style guide * Add header required on Windows. * get the SWIG wrappers to build
108 lines
3.3 KiB
C++
108 lines
3.3 KiB
C++
//
|
|
// Copyright (C) 2018 T5 Informatics GmbH
|
|
// @@ 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 <RDGeneral/RDLog.h>
|
|
#include <GraphMol/RDKitBase.h>
|
|
#include <GraphMol/StereoGroup.h>
|
|
#include "FileParsers.h"
|
|
#include "MolFileStereochem.h"
|
|
#include <RDGeneral/FileParseException.h>
|
|
#include <RDGeneral/BadFileException.h>
|
|
#include <clocale>
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
|
#include <fstream>
|
|
#include <memory>
|
|
|
|
using namespace RDKit;
|
|
|
|
std::unique_ptr<RWMol> readTestFile(const std::string &baseName) {
|
|
std::string rdbase = getenv("RDBASE");
|
|
std::string fName =
|
|
rdbase + "/Code/GraphMol/FileParsers/test_data/" + baseName;
|
|
auto m = MolFileToMol(fName);
|
|
return std::unique_ptr<RWMol>(m);
|
|
}
|
|
|
|
void testOr() {
|
|
BOOST_LOG(rdInfoLog) << "testing extended stereo parsing with an OR block"
|
|
<< std::endl;
|
|
|
|
auto m = readTestFile("two_centers_or.mol");
|
|
TEST_ASSERT(m.get());
|
|
TEST_ASSERT(m->getNumAtoms() == 8);
|
|
|
|
auto stereo_groups = m->getStereoGroups();
|
|
TEST_ASSERT(stereo_groups.size() == 2);
|
|
TEST_ASSERT(stereo_groups[0].getGroupType() ==
|
|
RDKit::StereoGroupType::STEREO_ABSOLUTE);
|
|
TEST_ASSERT(stereo_groups[0].getAtoms().size() == 1u);
|
|
TEST_ASSERT(stereo_groups[1].getGroupType() == RDKit::StereoGroupType::STEREO_OR);
|
|
TEST_ASSERT(stereo_groups[1].getAtoms().size() == 2u);
|
|
|
|
BOOST_LOG(rdInfoLog) << "done" << std::endl;
|
|
}
|
|
|
|
void testAnd() {
|
|
BOOST_LOG(rdInfoLog) << "testing extended stereo parsing with an AND block"
|
|
<< std::endl;
|
|
|
|
auto m = readTestFile("two_centers_and.mol");
|
|
TEST_ASSERT(m.get());
|
|
TEST_ASSERT(m->getNumAtoms() == 8);
|
|
|
|
auto stereo_groups = m->getStereoGroups();
|
|
TEST_ASSERT(stereo_groups.size() == 2);
|
|
TEST_ASSERT(stereo_groups[0].getGroupType() ==
|
|
RDKit::StereoGroupType::STEREO_ABSOLUTE);
|
|
TEST_ASSERT(stereo_groups[1].getGroupType() == RDKit::StereoGroupType::STEREO_AND);
|
|
|
|
BOOST_LOG(rdInfoLog) << "done" << std::endl;
|
|
}
|
|
|
|
void testWrite() {
|
|
BOOST_LOG(rdInfoLog) << "testing extended stereo file writing" << std::endl;
|
|
|
|
auto m0 = readTestFile("two_centers_and.mol");
|
|
TEST_ASSERT(m0.get());
|
|
std::string block = RDKit::MolToMolBlock(*m0);
|
|
auto m1 = RDKit::MolBlockToMol(block);
|
|
|
|
// Check that the extended stereo information has the same extended stereo
|
|
// types and same atoms marked for extended stereo.
|
|
auto stereo_groups0 = m0->getStereoGroups();
|
|
auto stereo_groups1 = m1->getStereoGroups();
|
|
TEST_ASSERT(stereo_groups0.size() == stereo_groups1.size());
|
|
|
|
for (unsigned i = 0u; i < 2; ++i) {
|
|
TEST_ASSERT(stereo_groups0[i].getGroupType() == stereo_groups1[i].getGroupType());
|
|
TEST_ASSERT(stereo_groups0[i].getAtoms().size() ==
|
|
stereo_groups1[i].getAtoms().size());
|
|
for (auto &&atom0 = stereo_groups0[i].getAtoms().begin(),
|
|
atom1 = stereo_groups1[i].getAtoms().begin();
|
|
atom0 != stereo_groups0[i].getAtoms().end(); ++atom0, ++atom1) {
|
|
TEST_ASSERT((*atom0)->getIdx() == (*atom1)->getIdx());
|
|
}
|
|
}
|
|
delete (m1);
|
|
|
|
BOOST_LOG(rdInfoLog) << "done" << std::endl;
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
(void)argc;
|
|
(void)argv;
|
|
|
|
testOr();
|
|
testAnd();
|
|
testWrite();
|
|
|
|
return 0;
|
|
}
|