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