RDKit: MolBundle.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

MolBundle.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Greg Landrum
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 /*! \file MolBundle.h
11
12 \brief Defines a class for managing bundles of molecules
13
14 */
15
16 #ifndef RD_MOLBUNDLE_AUG2017
17 #define RD_MOLBUNDLE_AUG2017
18
19 /// Std stuff
20 #include <vector>
21
22 // boost stuff
23 #include <RDGeneral/BoostStartInclude.h>
24 #include <boost/smart_ptr.hpp>
25 #include <RDGeneral/BoostEndInclude.h>
26
27 // our stuff
28 #include <RDGeneral/Exceptions.h>
29
30 namespace RDKit {
31 class ROMol;
32
33 //! MolBundle contains (conceptually) a collection of ROMols with the same
34 //! topology
35 /*!
36 This is designed to allow handling things like enhanced stereochemistry,
37 but can no doubt be (ab)used in other ways.
38 */
39 class MolBundle : public RDProps {
40 public:
41 MolBundle() : RDProps(){};
42
43 //! copy constructor
44 MolBundle(const MolBundle &other) : RDProps(other) { d_mols = other.d_mols; };
45 // FIX: need serialization/deserialization
46
47 virtual ~MolBundle(){};
48
49 //! returns our molecules
50 virtual const std::vector<boost::shared_ptr<ROMol> > &getMols() const {
51 return d_mols;
52 };
53
54 //! adds a new molecule and returns the total number of molecules
55 //! enforces that the new molecule has the same number of atoms and bonds
56 //! as the molecules that are already there.
57 virtual size_t addMol(boost::shared_ptr<ROMol> nmol) {
58 PRECONDITION(nmol.get(), "bad mol pointer");
59 if (d_mols.size()) {
60 if (nmol->getNumAtoms() != d_mols[0]->getNumAtoms())
61 throw ValueErrorException(
62 "all molecules in a bundle must have the same number of atoms");
63 // REVIEW: should we allow different numbers of bonds?
64 if (nmol->getNumBonds() != d_mols[0]->getNumBonds())
65 throw ValueErrorException(
66 "all molecules in a bundle must have the same number of bonds");
67 }
68 d_mols.push_back(nmol);
69 return (d_mols.size());
70 }
71 //! returns the number of molecules from the bundle
72 virtual size_t size() const { return d_mols.size(); };
73 //! returns a particular molecule in the bundle
74 virtual const boost::shared_ptr<ROMol> getMol(size_t idx) const {
75 if (idx >= d_mols.size()) throw IndexErrorException(idx);
76 return d_mols[idx];
77 };
78 //! returns a particular molecule from the bundle
79 virtual const boost::shared_ptr<ROMol> operator[](size_t idx) const {
80 return getMol(idx);
81 };
82
83 private:
84 std::vector<boost::shared_ptr<ROMol> > d_mols;
85 };
86
87 }; // end of RDKit namespace
88 #endif
RDKit::MolBundle::addMol
virtual size_t addMol(boost::shared_ptr< ROMol > nmol)
Definition: MolBundle.h:57
RDKit::MolBundle::~MolBundle
virtual ~MolBundle()
Definition: MolBundle.h:47
BoostStartInclude.h
RDKit::MolBundle::MolBundle
MolBundle()
Definition: MolBundle.h:41
RDKit::MolBundle::getMols
virtual const std::vector< boost::shared_ptr< ROMol > > & getMols() const
returns our molecules
Definition: MolBundle.h:50
RDKit::MolBundle::size
virtual size_t size() const
returns the number of molecules from the bundle
Definition: MolBundle.h:72
RDKit::RDProps
Definition: RDProps.h:9
Exceptions.h
RDKit::MolBundle::getMol
virtual const boost::shared_ptr< ROMol > getMol(size_t idx) const
returns a particular molecule in the bundle
Definition: MolBundle.h:74
BoostEndInclude.h
RDKit
Std stuff.
Definition: Atom.h:29
IndexErrorException
Class to allow us to throw an IndexError from C++ and have it make it back to Python.
Definition: Exceptions.h:18
PRECONDITION
#define PRECONDITION(expr, mess)
Definition: Invariant.h:107
RDKit::MolBundle::operator[]
virtual const boost::shared_ptr< ROMol > operator[](size_t idx) const
returns a particular molecule from the bundle
Definition: MolBundle.h:79
RDKit::MolBundle
Definition: MolBundle.h:39
ValueErrorException
Class to allow us to throw a ValueError from C++ and have it make it back to Python.
Definition: Exceptions.h:32
RDKit::MolBundle::MolBundle
MolBundle(const MolBundle &other)
copy constructor
Definition: MolBundle.h:44