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