| [d9dbef] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2016 Frederik Heber. All rights reserved. | 
|---|
|  | 5 | * | 
|---|
|  | 6 | * | 
|---|
|  | 7 | *   This file is part of MoleCuilder. | 
|---|
|  | 8 | * | 
|---|
|  | 9 | *    MoleCuilder is free software: you can redistribute it and/or modify | 
|---|
|  | 10 | *    it under the terms of the GNU General Public License as published by | 
|---|
|  | 11 | *    the Free Software Foundation, either version 2 of the License, or | 
|---|
|  | 12 | *    (at your option) any later version. | 
|---|
|  | 13 | * | 
|---|
|  | 14 | *    MoleCuilder is distributed in the hope that it will be useful, | 
|---|
|  | 15 | *    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 16 | *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 17 | *    GNU General Public License for more details. | 
|---|
|  | 18 | * | 
|---|
|  | 19 | *    You should have received a copy of the GNU General Public License | 
|---|
|  | 20 | *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
|  | 21 | */ | 
|---|
|  | 22 |  | 
|---|
|  | 23 | /* | 
|---|
|  | 24 | * ExportGraph_ToAtomFragments.cpp | 
|---|
|  | 25 | * | 
|---|
|  | 26 | *  Created on: Mar 07, 2016 | 
|---|
|  | 27 | *      Author: heber | 
|---|
|  | 28 | */ | 
|---|
|  | 29 |  | 
|---|
|  | 30 | // include config.h | 
|---|
|  | 31 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 32 | #include <config.h> | 
|---|
|  | 33 | #endif | 
|---|
|  | 34 |  | 
|---|
|  | 35 | // boost asio required before MemDebug due to placement new | 
|---|
|  | 36 | #include <boost/asio.hpp> | 
|---|
|  | 37 |  | 
|---|
|  | 38 | #include "CodePatterns/MemDebug.hpp" | 
|---|
|  | 39 |  | 
|---|
|  | 40 | #include "Fragmentation/Exporters/ExportGraph_ToAtomFragments.hpp" | 
|---|
|  | 41 |  | 
|---|
|  | 42 | #include <algorithm> | 
|---|
|  | 43 |  | 
|---|
|  | 44 | #include "Fragmentation/Homology/AtomFragmentsMap.hpp" | 
|---|
|  | 45 | #include "Fragmentation/KeySet.hpp" | 
|---|
|  | 46 | #include "World.hpp" | 
|---|
|  | 47 |  | 
|---|
|  | 48 | ExportGraph_ToAtomFragments::ExportGraph_ToAtomFragments( | 
|---|
|  | 49 | const Graph &_graph, | 
|---|
|  | 50 | const enum HydrogenTreatment _treatment, | 
|---|
|  | 51 | const enum HydrogenSaturation _saturation, | 
|---|
|  | 52 | const SaturatedFragment::GlobalSaturationPositions_t &_globalsaturationpositions) : | 
|---|
|  | 53 | ExportGraph(_graph, _treatment, _saturation,_globalsaturationpositions) | 
|---|
|  | 54 | {} | 
|---|
|  | 55 |  | 
|---|
|  | 56 | ExportGraph_ToAtomFragments::~ExportGraph_ToAtomFragments() | 
|---|
|  | 57 | {} | 
|---|
|  | 58 |  | 
|---|
|  | 59 | void ExportGraph_ToAtomFragments::operator()() | 
|---|
|  | 60 | { | 
|---|
|  | 61 | AtomFragmentsMap &atomfragments = AtomFragmentsMap::getInstance(); | 
|---|
|  | 62 | LOG(1, "INFO: Creating " << TotalGraph.size() << " possible fragments."); | 
|---|
|  | 63 |  | 
|---|
|  | 64 | // go through all fragments, output to stream and create job therefrom | 
|---|
|  | 65 | ExportGraph::SaturatedFragment_ptr CurrentFragment = getNextFragment(); | 
|---|
|  | 66 | for (; (CurrentFragment != NULL) && (CurrentFragment->getKeySet() != ExportGraph::EmptySet); | 
|---|
|  | 67 | CurrentFragment = getNextFragment()) { | 
|---|
|  | 68 | const KeySet &set = CurrentFragment->getKeySet(); | 
|---|
|  | 69 | LOG(3, "DEBUG: Creating fragment keysets for set " << set << "."); | 
|---|
|  | 70 | { | 
|---|
|  | 71 | // order is the same as the number of non-hydrogen atoms | 
|---|
|  | 72 | const KeySet &keyset = CurrentFragment->getKeySet(); | 
|---|
|  | 73 | const KeySet &fullmolecule = CurrentFragment->getFullMolecule(); | 
|---|
|  | 74 | const KeySet &saturationhydrogens = CurrentFragment->getSaturationHydrogens(); | 
|---|
|  | 75 | AtomFragmentsMap::indices_t forceindices(fullmolecule.begin(), fullmolecule.end()); | 
|---|
|  | 76 | { | 
|---|
|  | 77 | // replace all saturated hydrogen indices by "-1" | 
|---|
|  | 78 | for (AtomFragmentsMap::indices_t::iterator iter = forceindices.begin(); | 
|---|
|  | 79 | iter != forceindices.end(); | 
|---|
|  | 80 | ++iter) | 
|---|
|  | 81 | if (saturationhydrogens.find(*iter) != saturationhydrogens.end()) | 
|---|
|  | 82 | *iter = -1; | 
|---|
|  | 83 | } | 
|---|
|  | 84 | const bool status = atomfragments.addFullKeyset(keyset, forceindices); | 
|---|
|  | 85 | if (!status) | 
|---|
|  | 86 | ELOG(1, "Something went wrong with insertion for keyset " << keyset); | 
|---|
|  | 87 | } | 
|---|
|  | 88 | // store force index reference file | 
|---|
|  | 89 | // explicitly release fragment | 
|---|
|  | 90 | CurrentFragment.reset(); | 
|---|
|  | 91 | } | 
|---|
|  | 92 | if (CurrentFragment == NULL) { | 
|---|
|  | 93 | ELOG(1, "Some error while obtaining the next fragment occured."); | 
|---|
|  | 94 | return; | 
|---|
|  | 95 | } | 
|---|
|  | 96 | } | 
|---|