| 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 | #include <boost/serialization/export.hpp> | 
|---|
| 24 | #include <boost/serialization/list.hpp> | 
|---|
| 25 | #include <boost/serialization/map.hpp> | 
|---|
| 26 | #include <boost/serialization/set.hpp> | 
|---|
| 27 | #include <boost/serialization/vector.hpp> | 
|---|
| 28 | #include <boost/serialization/version.hpp> | 
|---|
| 29 |  | 
|---|
| 30 | #include "types.hpp" | 
|---|
| 31 |  | 
|---|
| 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 | * | 
|---|
| 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 | * | 
|---|
| 42 | */ | 
|---|
| 43 | class AtomFragmentsMap : public Singleton<AtomFragmentsMap> | 
|---|
| 44 | { | 
|---|
| 45 | public: | 
|---|
| 46 | //** Function to insert new fragments into storage container. | 
|---|
| 47 | void insert( | 
|---|
| 48 | const Graph &_graph); | 
|---|
| 49 |  | 
|---|
| 50 | /** Function to clear the container. | 
|---|
| 51 | * | 
|---|
| 52 | */ | 
|---|
| 53 | void clear(); | 
|---|
| 54 |  | 
|---|
| 55 | typedef std::vector<atomId_t> indices_t; | 
|---|
| 56 | typedef std::list<KeySet> keysets_t; | 
|---|
| 57 | //!> typedef for the internal map | 
|---|
| 58 | typedef std::map<atomId_t, keysets_t> AtomFragmentsMap_t; | 
|---|
| 59 | typedef std::map<KeySet, indices_t > FragmentFullKeysetMap_t; | 
|---|
| 60 |  | 
|---|
| 61 | /** Getter for full stored map. | 
|---|
| 62 | * | 
|---|
| 63 | * \return const ref to internal map | 
|---|
| 64 | */ | 
|---|
| 65 | const AtomFragmentsMap_t& getMap() const | 
|---|
| 66 | { return atommap; } | 
|---|
| 67 |  | 
|---|
| 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 |  | 
|---|
| 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; | 
|---|
| 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 |  | 
|---|
| 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 |  | 
|---|
| 116 | private: | 
|---|
| 117 | //!> internal map associating atoms and fragments | 
|---|
| 118 | AtomFragmentsMap_t atommap; | 
|---|
| 119 |  | 
|---|
| 120 | //!> internal map to get from keyset (without hydrogens) to full keyset, i.e. forcekeyset | 
|---|
| 121 | FragmentFullKeysetMap_t fullkeysets; | 
|---|
| 122 |  | 
|---|
| 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; | 
|---|
| 130 | ar & fullkeysets; | 
|---|
| 131 | } | 
|---|
| 132 | }; | 
|---|
| 133 |  | 
|---|
| 134 |  | 
|---|
| 135 | #endif /* ATOMFRAGMENTSMAP_HPP_ */ | 
|---|