RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
SynthonShapeInput.h
Go to the documentation of this file.
1//
2// Copyright (C) David Cosgrove 2026.
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10// A class building on ShapeInput for Synthon shape searching.
11
12#ifndef RDKIT_SYNTHONSHAPEINPUT_H
13#define RDKIT_SYNTHONSHAPEINPUT_H
14
15#include <GraphMol/RWMol.h>
18
20#ifdef RDK_USE_BOOST_SERIALIZATION
21#include <boost/archive/text_oarchive.hpp>
22#include <boost/archive/text_iarchive.hpp>
23#include <boost/serialization/unique_ptr.hpp>
24#include <boost/serialization/utility.hpp> // for std::pair
25#include <boost/serialization/vector.hpp>
26#include <boost/serialization/split_member.hpp>
27#endif
29
30namespace RDKit {
31namespace SynthonSpaceSearch {
32
34 public:
35 SynthonShapeInput(const ROMol &mol, int confId = -1,
38 const GaussianShape::ShapeOverlayOptions &overlayOpts =
40 SynthonShapeInput(const std::string &str) {
41#ifndef RDK_USE_BOOST_SERIALIZATION
42 PRECONDITION(0, "Boost SERIALIZATION is not enabled")
43#else
44 std::stringstream ss(str);
45 boost::archive::text_iarchive ia(ss);
46 ia &*this;
47#endif
48 }
53 ~SynthonShapeInput() = default;
54
55 // Merge the other SynthonShapeInput, assuming it has the correct number
56 // of atoms etc. Empties other, unless they can't be merged in which case
57 // it returns unscathed.
58 void merge(SynthonShapeInput &&other);
59
60 std::string toString() const {
61#ifndef RDK_USE_BOOST_SERIALIZATION
62 PRECONDITION(0, "Boost SERIALIZATION is not enabled")
63#else
64 std::stringstream ss;
65 boost::archive::text_oarchive oa(ss);
66 oa &*this;
67 return ss.str();
68#endif
69 }
70
71 GaussianShape::ShapeInput &getShapes() const { return *d_shapes; }
72
73 double getDummyVolume(unsigned int shapeNum) const;
74 unsigned int getNumDummyAtoms() const;
75 unsigned int getNumDummyAtomNbors() const {
76 return d_dummyAtomsAndNbrs.size();
77 }
78 const std::vector<std::pair<unsigned int, unsigned int>> &
80 return d_dummyAtomsAndNbrs;
81 }
82
83#ifdef RDK_USE_BOOST_SERIALIZATION
84 template <class Archive>
85 void serialize(Archive &ar, const unsigned int) {
86 if (Archive::is_saving::value) {
87 std::string shape = d_shapes->toString();
88 ar & shape;
89 } else {
90 std::string shape;
91 ar & shape;
92 d_shapes.reset(new GaussianShape::ShapeInput(shape));
93 }
94 ar & d_dummyVolumes;
95 ar & d_dummyAtomsAndNbrs;
96 }
97#endif
98
99 private:
100 std::unique_ptr<GaussianShape::ShapeInput> d_shapes;
101 std::vector<double>
102 d_dummyVolumes; // The volumes of the dummy atoms in the shapes
103 // These pairs are the dummy atoms and neighbour atoms. On rare occasions
104 // a dummy may have 2 neighbours, so the first numbers in the pairs
105 // may not be unique.
106 std::vector<std::pair<unsigned int, unsigned int>> d_dummyAtomsAndNbrs;
107
108 void buildDummyAtomsAndNbrs();
109 void calculateDummyVols(const GaussianShape::ShapeOverlayOptions &opts);
110};
111
112} // namespace SynthonSpaceSearch
113} // namespace RDKit
114
115#endif // RDKIT_SYNTHONSHAPEINPUT_H
#define PRECONDITION(expr, mess)
Definition Invariant.h:108
Defines the editable molecule class RWMol.
SynthonShapeInput(const ROMol &mol, int confId=-1, const GaussianShape::ShapeInputOptions &opts=GaussianShape::ShapeInputOptions(), const GaussianShape::ShapeOverlayOptions &overlayOpts=GaussianShape::ShapeOverlayOptions())
GaussianShape::ShapeInput & getShapes() const
SynthonShapeInput & operator=(SynthonShapeInput &&)=default
const std::vector< std::pair< unsigned int, unsigned int > > & getDummyAtomsAndNbrs() const
double getDummyVolume(unsigned int shapeNum) const
SynthonShapeInput & operator=(const SynthonShapeInput &)
SynthonShapeInput(const SynthonShapeInput &)
SynthonShapeInput(SynthonShapeInput &&)=default
void merge(SynthonShapeInput &&other)
Std stuff.