| 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 |  | 
|---|
| 17 | #include "CodePatterns/Singleton.hpp" | 
|---|
| 18 |  | 
|---|
| 19 | #include <list> | 
|---|
| 20 | #include <map> | 
|---|
| 21 | #include <vector> | 
|---|
| 22 |  | 
|---|
| 23 | // bug in boost/serialization 1.58. set.hpp needs serialization.hpp included before | 
|---|
| 24 | #include <boost/serialization/serialization.hpp> | 
|---|
| 25 |  | 
|---|
| 26 | #include <boost/serialization/export.hpp> | 
|---|
| 27 | #include <boost/serialization/list.hpp> | 
|---|
| 28 | #include <boost/serialization/map.hpp> | 
|---|
| 29 | #include <boost/serialization/set.hpp> | 
|---|
| 30 | #include <boost/serialization/vector.hpp> | 
|---|
| 31 | #include <boost/serialization/version.hpp> | 
|---|
| 32 |  | 
|---|
| 33 | #include "types.hpp" | 
|---|
| 34 |  | 
|---|
| 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 | * | 
|---|
| 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 | * | 
|---|
| 45 | */ | 
|---|
| 46 | class AtomFragmentsMap : public Singleton<AtomFragmentsMap> | 
|---|
| 47 | { | 
|---|
| 48 | public: | 
|---|
| 49 | //** Function to insert new fragments into storage container. | 
|---|
| 50 | void insert( | 
|---|
| 51 | const Graph &_graph); | 
|---|
| 52 |  | 
|---|
| 53 | /** Function to clear the container. | 
|---|
| 54 | * | 
|---|
| 55 | */ | 
|---|
| 56 | void clear(); | 
|---|
| 57 |  | 
|---|
| 58 | typedef std::vector<atomId_t> indices_t; | 
|---|
| 59 | typedef std::list<KeySet> keysets_t; | 
|---|
| 60 | //!> typedef for the internal map | 
|---|
| 61 | typedef std::map<atomId_t, keysets_t> AtomFragmentsMap_t; | 
|---|
| 62 | typedef std::map<KeySet, indices_t > FragmentFullKeysetMap_t; | 
|---|
| 63 |  | 
|---|
| 64 | /** Getter for full stored map. | 
|---|
| 65 | * | 
|---|
| 66 | * \return const ref to internal map | 
|---|
| 67 | */ | 
|---|
| 68 | const AtomFragmentsMap_t& getMap() const | 
|---|
| 69 | { return atommap; } | 
|---|
| 70 |  | 
|---|
| 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 |  | 
|---|
| 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; | 
|---|
| 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 |  | 
|---|
| 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 |  | 
|---|
| 119 | private: | 
|---|
| 120 | //!> internal map associating atoms and fragments | 
|---|
| 121 | AtomFragmentsMap_t atommap; | 
|---|
| 122 |  | 
|---|
| 123 | //!> internal map to get from keyset (without hydrogens) to full keyset, i.e. forcekeyset | 
|---|
| 124 | FragmentFullKeysetMap_t fullkeysets; | 
|---|
| 125 |  | 
|---|
| 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; | 
|---|
| 133 | ar & fullkeysets; | 
|---|
| 134 | } | 
|---|
| 135 | }; | 
|---|
| 136 |  | 
|---|
| 137 |  | 
|---|
| 138 | #endif /* ATOMFRAGMENTSMAP_HPP_ */ | 
|---|