mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-05 22:04:27 +08:00
* MolDraw2D refactoring - rename setupMoleculeDraw->initMoleculeDraw - track whether or not initDrawing() has been called - centralize calls to initDrawing() and clearDrawing() into initMoleculeDraw() - update svg hashes in tests * update some expected test results * support changing font scale and default scale add reaction test * does not work... this is hard * all tests pass * do something about legends * docs * more tests * more docs * cleanup * going around in circles... hopefully converging * cleanup * Single bond skeleton works. * Simple bond drawing seems to be working. * Initial addition of atom symbols. * Stash of not-quite-working atom symbols prior to major surgery. * Atom symbols seem to be working. Major surgery not required, just inverted Y coords at the outset. * Add classes to atom labels. * Renamed AtomLabel AtomSymbol. * Add highlights. * Fix bug from PR4839. * Molecule note. * Added atom notes. * Added bond notes. * Extract radicals. * Annotation via new DrawAnnotation class. * Add brackets. * Add linknodes. * Add close contacts. * Add attachment points. Fix wavy lines. * Draw molecules in grid. * Tidy. * Fix radicals when font has hit maxFontSize. Make getDrawCoords work. * Draw primitives take atom or draw coords. * Fix legends. * More fixing for tests. DrawMol::setScale now takes font scale as well. * tidy debug writes * Variable fraction of panel for legend. * Better legend positioning. * Fix sub- and super-script spacing. Added spaces to Freetype strings. * Basic reaction drawing. * Reaction highlighting. * Minor tweak to reacctions. * Tweaked reaction DrawMol widths. * Fix atomTags. * Fix catch tests except contours. * Contouring working in catch_tests.cpp. * Fix catch tests. * AtomSymbol and DrawAnnotation into MolDraw2D_detail. * DrawMol and DrawShape into MolDraw2D_detail. * DrawText inot MolDraw2D_detail. * Machete out. * DrawText goes private. * Move some stuff about, such as StringRect to its own header. * Python wrapper compiles (but crashes when Draw imported). * More tidying. Python DrawArrow failing. * Linux changes. * Fixed error in DrawShapeArrow spotted by valgrind. Fixed some warnings from gcc. * Maybe fixed DrawArrow. * Added basic argparse interface. * Added newlines. * Changes in response to review. Non-const args in move constructors and operator=. Added missing classes to MolDraw2D_detail. Deleted move operator= where it had been forgotten. Fixed copyright dates. * Deleted all default c'tors in derived classes. * Changes in response to review: Wedge widths now a proportion of mean bond length in draw coords.. Add padding below legend when positioning it. * Fix tests. * Fix the private/protected mess of the new classes. * Moved doesLineIntersect etc. * Reinstate original alignString for non-FT drawings. * More faffing about with reaction layouts. * Fix font sizes in testGitHub3391. * Fix atom notes fitting inside fat wedges. * Fix molecule annotation font size. * More fixes of rectangle/triangle collision detection. * Test for highlight linewidth multiplier. * Use push_back not emplace_back. * Attempt at better Freetype char spacing. * Option to turn off TEST_ASSERT. Currently off. * Fixed embarrassing maths to do with wedge fatness. * More tidying post-review. * Document highlight_linewidth_multipliers. * Expose baseFontSize to Python. * Changes in response to review. * Allow DrawMolecules molecules to be drawn to different scales. * Fix bond sneaking between C:8 in, for example, reactions. * Fix bad re-factoring. * Fix globbing. * Changes in response to review. * Add invariant check. * Add draw option to fix font size. * suggested changes * Update catch test results. * Fix expected freetype results. * Fix non-freetype drawers. * Fin non-freetype test results. * get the Qt drawer working too * Fix disappearing reaction highlights. * Changes as result of review. * Fixed non-FreeType hash codes for reaction SVGs. Extra comment in catch_tests. * reactant highlighting was clearning properties * Fix for failing contour python test. * fix a non-freetype problem * swig wrappers working * Bump timeouts in test. Co-authored-by: greg landrum <greg.landrum@gmail.com> Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
238 lines
9.3 KiB
C++
238 lines
9.3 KiB
C++
//
|
|
// Copyright (C) 2019 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.
|
|
//
|
|
|
|
#include "RDGeneral/test.h"
|
|
#include "catch.hpp"
|
|
|
|
#include <GraphMol/RDKitBase.h>
|
|
#include <GraphMol/FileParsers/FileParsers.h>
|
|
#include <GraphMol/FileParsers/FileParserUtils.h>
|
|
#include <GraphMol/FileParsers/MolSupplier.h>
|
|
#include <GraphMol/SmilesParse/SmilesParse.h>
|
|
|
|
using namespace RDKit;
|
|
|
|
TEST_CASE("Property list conversion", "[atom_list_properties]") {
|
|
SECTION("basics: iprops") {
|
|
auto m = "COC"_smiles;
|
|
REQUIRE(m);
|
|
m->setProp("atom.iprop.foo1", "1 6 9");
|
|
m->setProp("atom.iprop.foo2", "3 n/a 9");
|
|
m->setProp("atom.iprop.foo3", "[?] 5 1 ?");
|
|
m->setProp("atom.iprop.foo4", "[foo] 3 foo 9");
|
|
FileParserUtils::applyMolListPropsToAtoms<std::int64_t>(*m, "atom.iprop.");
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(1)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo2"));
|
|
CHECK(!m->getAtomWithIdx(1)->hasProp("foo2"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo2"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo3"));
|
|
CHECK(m->getAtomWithIdx(1)->hasProp("foo3"));
|
|
CHECK(!m->getAtomWithIdx(2)->hasProp("foo3"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo4"));
|
|
CHECK(!m->getAtomWithIdx(1)->hasProp("foo4"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo4"));
|
|
CHECK(m->getAtomWithIdx(1)->getProp<std::int64_t>("foo1") == 6);
|
|
CHECK(m->getAtomWithIdx(2)->getProp<std::int64_t>("foo2") == 9);
|
|
CHECK(m->getAtomWithIdx(1)->getProp<std::int64_t>("foo3") == 1);
|
|
}
|
|
SECTION("basics: dprops") {
|
|
auto m = "COC"_smiles;
|
|
REQUIRE(m);
|
|
m->setProp("atom.dprop.foo1", "1 6 9");
|
|
m->setProp("atom.dprop.foo2", "3 n/a 9");
|
|
m->setProp("atom.dprop.foo3", "[?] 5 1 ?");
|
|
FileParserUtils::applyMolListPropsToAtoms<double>(*m, "atom.dprop.");
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(1)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo2"));
|
|
CHECK(!m->getAtomWithIdx(1)->hasProp("foo2"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo2"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo3"));
|
|
CHECK(m->getAtomWithIdx(1)->hasProp("foo3"));
|
|
CHECK(!m->getAtomWithIdx(2)->hasProp("foo3"));
|
|
CHECK(m->getAtomWithIdx(1)->getProp<double>("foo1") == 6);
|
|
CHECK(m->getAtomWithIdx(2)->getProp<double>("foo2") == 9);
|
|
CHECK(m->getAtomWithIdx(1)->getProp<double>("foo3") == 1);
|
|
}
|
|
SECTION("basics: props") {
|
|
auto m = "COC"_smiles;
|
|
REQUIRE(m);
|
|
m->setProp("atom.prop.foo1", "1 6 9");
|
|
m->setProp("atom.prop.foo2", "3 n/a 9");
|
|
m->setProp("atom.prop.foo3", "[?] 5 1 ?");
|
|
FileParserUtils::applyMolListPropsToAtoms<std::string>(*m, "atom.prop.");
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(1)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo2"));
|
|
CHECK(!m->getAtomWithIdx(1)->hasProp("foo2"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo2"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo3"));
|
|
CHECK(m->getAtomWithIdx(1)->hasProp("foo3"));
|
|
CHECK(!m->getAtomWithIdx(2)->hasProp("foo3"));
|
|
CHECK(m->getAtomWithIdx(1)->getProp<std::string>("foo1") == "6");
|
|
CHECK(m->getAtomWithIdx(2)->getProp<std::string>("foo2") == "9");
|
|
CHECK(m->getAtomWithIdx(1)->getProp<std::string>("foo3") == "1");
|
|
}
|
|
SECTION("basics: bprops") {
|
|
auto m = "COC"_smiles;
|
|
REQUIRE(m);
|
|
m->setProp("atom.bprop.foo1", "1 0 0");
|
|
m->setProp("atom.bprop.foo2", "0 n/a 1");
|
|
m->setProp("atom.bprop.foo3", "[?] 0 1 ?");
|
|
FileParserUtils::applyMolListPropsToAtoms<bool>(*m, "atom.bprop.");
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(1)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo2"));
|
|
CHECK(!m->getAtomWithIdx(1)->hasProp("foo2"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo2"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo3"));
|
|
CHECK(m->getAtomWithIdx(1)->hasProp("foo3"));
|
|
CHECK(!m->getAtomWithIdx(2)->hasProp("foo3"));
|
|
CHECK(m->getAtomWithIdx(1)->getProp<bool>("foo1") == false);
|
|
CHECK(m->getAtomWithIdx(2)->getProp<bool>("foo2") == true);
|
|
CHECK(m->getAtomWithIdx(1)->getProp<bool>("foo3") == true);
|
|
}
|
|
}
|
|
TEST_CASE("processMolPropertyLists", "[atom_list_properties]") {
|
|
SECTION("basics") {
|
|
auto m = "COC"_smiles;
|
|
REQUIRE(m);
|
|
m->setProp("atom.iprop.foo1", "1 6 9");
|
|
m->setProp("atom.dprop.foo2", "3 n/a 9");
|
|
m->setProp("atom.prop.foo3", "[?] 5 1 ?");
|
|
m->setProp("atom.bprop.foo4", "1 0 0");
|
|
FileParserUtils::processMolPropertyLists(*m);
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(1)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo1"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo2"));
|
|
CHECK(!m->getAtomWithIdx(1)->hasProp("foo2"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo2"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo3"));
|
|
CHECK(m->getAtomWithIdx(1)->hasProp("foo3"));
|
|
CHECK(!m->getAtomWithIdx(2)->hasProp("foo3"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("foo4"));
|
|
CHECK(m->getAtomWithIdx(1)->hasProp("foo4"));
|
|
CHECK(m->getAtomWithIdx(2)->hasProp("foo4"));
|
|
CHECK(m->getAtomWithIdx(1)->getProp<std::int64_t>("foo1") == 6);
|
|
CHECK(m->getAtomWithIdx(2)->getProp<double>("foo2") == 9);
|
|
CHECK(m->getAtomWithIdx(1)->getProp<std::string>("foo3") == "1");
|
|
CHECK(m->getAtomWithIdx(1)->getProp<bool>("foo4") == false);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("basic SDF handling", "[SDF][atom_list_properties]") {
|
|
std::string sdf = R"SDF(
|
|
RDKit 2D
|
|
|
|
3 3 0 0 0 0 0 0 0 0999 V2000
|
|
0.8660 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
|
-0.4330 0.7500 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
|
|
-0.4330 -0.7500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
|
1 2 1 0
|
|
2 3 1 0
|
|
3 1 1 0
|
|
M END
|
|
> <atom.dprop.PartialCharge> (1)
|
|
0.008 -0.314 0.008
|
|
|
|
> <atom.iprop.NumHeavyNeighbors> (1)
|
|
2 2 2
|
|
|
|
> <atom.prop.AtomLabel> (1)
|
|
C1 N2 C3
|
|
|
|
> <atom.bprop.IsCarbon> (1)
|
|
1 0 1
|
|
|
|
> <atom.prop.PartiallyMissing> (1)
|
|
one n/a three
|
|
|
|
> <atom.iprop.PartiallyMissingInt> (1)
|
|
[?] 2 2 ?
|
|
|
|
$$$$
|
|
)SDF";
|
|
SECTION("no processing") {
|
|
RDKit::SDMolSupplier suppl;
|
|
suppl.setData(sdf);
|
|
suppl.setProcessPropertyLists(false);
|
|
std::unique_ptr<RDKit::ROMol> m(suppl[0]);
|
|
REQUIRE(m);
|
|
CHECK(m->hasProp("atom.prop.AtomLabel"));
|
|
CHECK(!m->getAtomWithIdx(0)->hasProp("AtomLabel"));
|
|
}
|
|
SECTION("with processing") {
|
|
RDKit::SDMolSupplier suppl;
|
|
suppl.setData(sdf);
|
|
std::unique_ptr<RDKit::ROMol> m(suppl[0]);
|
|
REQUIRE(m);
|
|
CHECK(m->hasProp("atom.prop.AtomLabel"));
|
|
CHECK(m->getAtomWithIdx(0)->hasProp("AtomLabel"));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("createAtomPropertyLists", "[atom_list_properties]") {
|
|
SECTION("basics") {
|
|
auto m = "COC"_smiles;
|
|
REQUIRE(m);
|
|
m->getAtomWithIdx(0)->setProp<std::int64_t>("foo1", 1);
|
|
m->getAtomWithIdx(2)->setProp<std::int64_t>("foo1", 9);
|
|
FileParserUtils::createAtomIntPropertyList(*m, "foo1");
|
|
REQUIRE(m->hasProp("atom.iprop.foo1"));
|
|
CHECK(m->getProp<std::string>("atom.iprop.foo1") == "1 n/a 9");
|
|
|
|
m->getAtomWithIdx(0)->setProp<double>("foo2", 1);
|
|
m->getAtomWithIdx(1)->setProp<double>("foo2", 4);
|
|
m->getAtomWithIdx(2)->setProp<double>("foo2", 9);
|
|
FileParserUtils::createAtomDoublePropertyList(*m, "foo2");
|
|
REQUIRE(m->hasProp("atom.dprop.foo2"));
|
|
CHECK(m->getProp<std::string>("atom.dprop.foo2") == "1 4 9");
|
|
|
|
m->getAtomWithIdx(0)->setProp<std::string>("foo3", "1");
|
|
m->getAtomWithIdx(1)->setProp<std::string>("foo3", "4");
|
|
FileParserUtils::createAtomStringPropertyList(*m, "foo3", "?");
|
|
REQUIRE(m->hasProp("atom.prop.foo3"));
|
|
CHECK(m->getProp<std::string>("atom.prop.foo3") == "[?] 1 4 ?");
|
|
|
|
m->getAtomWithIdx(0)->setProp<bool>("foo4", 1);
|
|
m->getAtomWithIdx(1)->setProp<bool>("foo4", 0);
|
|
m->getAtomWithIdx(2)->setProp<bool>("foo4", 0);
|
|
FileParserUtils::createAtomBoolPropertyList(*m, "foo4");
|
|
REQUIRE(m->hasProp("atom.bprop.foo4"));
|
|
CHECK(m->getProp<std::string>("atom.bprop.foo4") == "1 0 0");
|
|
}
|
|
SECTION("long lines") {
|
|
auto m = "COC"_smiles;
|
|
REQUIRE(m);
|
|
m->getAtomWithIdx(0)->setProp<std::string>("foo1", std::string(80, 'a'));
|
|
m->getAtomWithIdx(1)->setProp<std::string>("foo1", std::string(80, 'b'));
|
|
m->getAtomWithIdx(2)->setProp<std::string>("foo1", std::string(80, 'c'));
|
|
FileParserUtils::createAtomStringPropertyList(*m, "foo1");
|
|
REQUIRE(m->hasProp("atom.prop.foo1"));
|
|
std::string ps = m->getProp<std::string>("atom.prop.foo1");
|
|
CHECK(ps.length() > 240);
|
|
CHECK(ps.find("\n") != std::string::npos);
|
|
for (auto &atom : m->atoms()) {
|
|
atom->clearProp("foo1");
|
|
}
|
|
FileParserUtils::applyMolListPropsToAtoms<std::string>(*m, "atom.prop.");
|
|
CHECK(m->getAtomWithIdx(0)->getProp<std::string>("foo1") ==
|
|
std::string(80, 'a'));
|
|
CHECK(m->getAtomWithIdx(1)->getProp<std::string>("foo1") ==
|
|
std::string(80, 'b'));
|
|
CHECK(m->getAtomWithIdx(2)->getProp<std::string>("foo1") ==
|
|
std::string(80, 'c'));
|
|
}
|
|
} |