| [d45ed9] | 1 | /* | 
|---|
|  | 2 | * AtomFragmentsMap.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Mar 7, 2016 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 |  | 
|---|
|  | 9 | #ifndef ATOMFRAGMENTSMAP_HPP_ | 
|---|
|  | 10 | #define ATOMFRAGMENTSMAP_HPP_ | 
|---|
|  | 11 |  | 
|---|
|  | 12 | // include config.h | 
|---|
|  | 13 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 14 | #include <config.h> | 
|---|
|  | 15 | #endif | 
|---|
|  | 16 |  | 
|---|
| [d713ce] | 17 | #include "CodePatterns/Singleton.hpp" | 
|---|
|  | 18 |  | 
|---|
| [d45ed9] | 19 | #include <list> | 
|---|
|  | 20 | #include <map> | 
|---|
| [70aeed] | 21 | #include <vector> | 
|---|
| [d45ed9] | 22 |  | 
|---|
| [16d67a] | 23 | #include <boost/serialization/export.hpp> | 
|---|
| [78202b] | 24 | #include <boost/serialization/list.hpp> | 
|---|
| [16d67a] | 25 | #include <boost/serialization/map.hpp> | 
|---|
| [70aeed] | 26 | #include <boost/serialization/set.hpp> | 
|---|
|  | 27 | #include <boost/serialization/vector.hpp> | 
|---|
| [16d67a] | 28 | #include <boost/serialization/version.hpp> | 
|---|
|  | 29 |  | 
|---|
| [bd6e5c] | 30 | #include "types.hpp" | 
|---|
|  | 31 |  | 
|---|
| [d45ed9] | 32 | class KeySet; | 
|---|
|  | 33 | class Graph; | 
|---|
|  | 34 |  | 
|---|
|  | 35 | /** This class creates in instantiation a map connecting each atom with | 
|---|
|  | 36 | * the (known) fragments it takes part in. | 
|---|
|  | 37 | * | 
|---|
| [d713ce] | 38 | * In the HomologyGraph and its -Container we do not have this information | 
|---|
|  | 39 | * any longer. However, we need this in order to make statements about atomic | 
|---|
|  | 40 | * properties from calculated fragment properties. | 
|---|
|  | 41 | * | 
|---|
| [d45ed9] | 42 | */ | 
|---|
| [d713ce] | 43 | class AtomFragmentsMap : public Singleton<AtomFragmentsMap> | 
|---|
| [d45ed9] | 44 | { | 
|---|
|  | 45 | public: | 
|---|
| [d713ce] | 46 | //** Function to insert new fragments into storage container. | 
|---|
|  | 47 | void insert( | 
|---|
| [2fd88d1] | 48 | const Graph &_graph); | 
|---|
| [d45ed9] | 49 |  | 
|---|
| [d713ce] | 50 | /** Function to clear the container. | 
|---|
|  | 51 | * | 
|---|
|  | 52 | */ | 
|---|
| [4fa333] | 53 | void clear(); | 
|---|
| [d713ce] | 54 |  | 
|---|
| [70aeed] | 55 | typedef std::vector<atomId_t> indices_t; | 
|---|
| [bd6e5c] | 56 | typedef std::list<KeySet> keysets_t; | 
|---|
| [d45ed9] | 57 | //!> typedef for the internal map | 
|---|
| [bd6e5c] | 58 | typedef std::map<atomId_t, keysets_t> AtomFragmentsMap_t; | 
|---|
| [70aeed] | 59 | typedef std::map<KeySet, indices_t > FragmentFullKeysetMap_t; | 
|---|
| [d45ed9] | 60 |  | 
|---|
| [2fd88d1] | 61 | /** Getter for full stored map. | 
|---|
|  | 62 | * | 
|---|
|  | 63 | * \return const ref to internal map | 
|---|
|  | 64 | */ | 
|---|
| [d45ed9] | 65 | const AtomFragmentsMap_t& getMap() const | 
|---|
|  | 66 | { return atommap; } | 
|---|
|  | 67 |  | 
|---|
| [70aeed] | 68 | /** Allows to add the full keyset, with excluded hydrogens, to add | 
|---|
|  | 69 | * to a given \a _keyset | 
|---|
|  | 70 | * | 
|---|
|  | 71 | * \param _keyset keyset to a fragment without hydrogens | 
|---|
|  | 72 | * \param _fullkeyset full keyset with excluded hydrogens to associate with \a _keyset | 
|---|
|  | 73 | * \return true - insertion ok, else - index set already present | 
|---|
|  | 74 | */ | 
|---|
|  | 75 | bool addFullKeyset(const KeySet &_keyset, const indices_t &_fullkeyset); | 
|---|
|  | 76 |  | 
|---|
|  | 77 | /** Getter for the full key set, i.e. including excluded hydrogens, for a | 
|---|
|  | 78 | * given \a _keyset without them. | 
|---|
|  | 79 | * | 
|---|
|  | 80 | * \param _keyset keyset to a fragment without hydrogens | 
|---|
|  | 81 | * \return full index set containing all keys from \a _keyset and all excluded | 
|---|
|  | 82 | *         hydrogens | 
|---|
|  | 83 | */ | 
|---|
|  | 84 | const indices_t &getFullKeyset(const KeySet &_keyset) const; | 
|---|
|  | 85 |  | 
|---|
| [2fd88d1] | 86 | /** Getter to map cut down to given selection of atoms. | 
|---|
|  | 87 | * | 
|---|
|  | 88 | * \param _candidates subset of atoms | 
|---|
|  | 89 | * \param _MaxOrder constrain returned fragment list to contain at most this size | 
|---|
|  | 90 | * \return map with fragments for each of the candidates | 
|---|
|  | 91 | */ | 
|---|
|  | 92 | AtomFragmentsMap_t getMap( | 
|---|
|  | 93 | const std::vector<atomId_t> &_candidates, | 
|---|
|  | 94 | size_t _MaxOrder) const; | 
|---|
| [70aeed] | 95 |  | 
|---|
|  | 96 | /** Checks whether we have a full keyset for every keyset contained. | 
|---|
|  | 97 | * | 
|---|
|  | 98 | * \return true - is complete, false - else | 
|---|
|  | 99 | */ | 
|---|
|  | 100 | bool checkCompleteness() const; | 
|---|
|  | 101 |  | 
|---|
| [d713ce] | 102 | private: | 
|---|
|  | 103 | //!> grant singleton pattern access to private cstor/dstor | 
|---|
|  | 104 | friend class Singleton<AtomFragmentsMap>; | 
|---|
|  | 105 |  | 
|---|
|  | 106 | /** Private default cstor. | 
|---|
|  | 107 | * | 
|---|
|  | 108 | */ | 
|---|
|  | 109 | AtomFragmentsMap() {} | 
|---|
|  | 110 |  | 
|---|
|  | 111 | /** Private default dstor. | 
|---|
|  | 112 | * | 
|---|
|  | 113 | */ | 
|---|
|  | 114 | ~AtomFragmentsMap() {} | 
|---|
|  | 115 |  | 
|---|
| [d45ed9] | 116 | private: | 
|---|
| [70aeed] | 117 | //!> internal map associating atoms and fragments | 
|---|
| [d45ed9] | 118 | AtomFragmentsMap_t atommap; | 
|---|
| [16d67a] | 119 |  | 
|---|
| [70aeed] | 120 | //!> internal map to get from keyset (without hydrogens) to full keyset, i.e. forcekeyset | 
|---|
|  | 121 | FragmentFullKeysetMap_t fullkeysets; | 
|---|
|  | 122 |  | 
|---|
| [16d67a] | 123 | private: | 
|---|
|  | 124 | friend class boost::serialization::access; | 
|---|
|  | 125 | // serialization | 
|---|
|  | 126 | template <typename Archive> | 
|---|
|  | 127 | void serialize(Archive& ar, const unsigned int version) | 
|---|
|  | 128 | { | 
|---|
|  | 129 | ar & atommap; | 
|---|
| [70aeed] | 130 | ar & fullkeysets; | 
|---|
| [16d67a] | 131 | } | 
|---|
| [d45ed9] | 132 | }; | 
|---|
|  | 133 |  | 
|---|
|  | 134 |  | 
|---|
|  | 135 | #endif /* ATOMFRAGMENTSMAP_HPP_ */ | 
|---|