| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2011 University of Bonn. All rights reserved.
 | 
|---|
| 5 |  * Copyright (C)  2013 Frederik Heber. All rights reserved.
 | 
|---|
| 6 |  *
 | 
|---|
| 7 |  *
 | 
|---|
| 8 |  *   This file is part of MoleCuilder.
 | 
|---|
| 9 |  *
 | 
|---|
| 10 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
| 11 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
| 12 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
| 13 |  *    (at your option) any later version.
 | 
|---|
| 14 |  *
 | 
|---|
| 15 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
| 16 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 17 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 18 |  *    GNU General Public License for more details.
 | 
|---|
| 19 |  *
 | 
|---|
| 20 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
| 21 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| 22 |  */
 | 
|---|
| 23 | 
 | 
|---|
| 24 | /*
 | 
|---|
| 25 |  * ExportGraph_ToJobs.cpp
 | 
|---|
| 26 |  *
 | 
|---|
| 27 |  *  Created on: 08.03.2012
 | 
|---|
| 28 |  *      Author: heber
 | 
|---|
| 29 |  */
 | 
|---|
| 30 | 
 | 
|---|
| 31 | // include config.h
 | 
|---|
| 32 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 33 | #include <config.h>
 | 
|---|
| 34 | #endif
 | 
|---|
| 35 | 
 | 
|---|
| 36 | // boost asio required before MemDebug due to placement new
 | 
|---|
| 37 | #include <boost/asio.hpp>
 | 
|---|
| 38 | 
 | 
|---|
| 39 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 40 | 
 | 
|---|
| 41 | #include "Fragmentation/Exporters/ExportGraph_ToJobs.hpp"
 | 
|---|
| 42 | 
 | 
|---|
| 43 | #include <algorithm>
 | 
|---|
| 44 | 
 | 
|---|
| 45 | #include "Box.hpp"
 | 
|---|
| 46 | #include "Fragmentation/KeySet.hpp"
 | 
|---|
| 47 | #include "Fragmentation/Automation/FragmentJobQueue.hpp"
 | 
|---|
| 48 | #include "Fragmentation/Automation/MPQCFragmentController.hpp"
 | 
|---|
| 49 | #include "Helpers/defs.hpp"
 | 
|---|
| 50 | #include "Jobs/MPQCJob.hpp"
 | 
|---|
| 51 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
 | 
|---|
| 52 | #include "Parser/FormatParserStorage.hpp"
 | 
|---|
| 53 | #include "World.hpp"
 | 
|---|
| 54 | 
 | 
|---|
| 55 | ExportGraph_ToJobs::ExportGraph_ToJobs(
 | 
|---|
| 56 |     const Graph &_graph,
 | 
|---|
| 57 |     const enum HydrogenTreatment _treatment,
 | 
|---|
| 58 |     const enum HydrogenSaturation _saturation) :
 | 
|---|
| 59 |     ExportGraph(_graph, _treatment, _saturation),
 | 
|---|
| 60 |     level(5)
 | 
|---|
| 61 | {}
 | 
|---|
| 62 | 
 | 
|---|
| 63 | ExportGraph_ToJobs::~ExportGraph_ToJobs()
 | 
|---|
| 64 | {}
 | 
|---|
| 65 | 
 | 
|---|
| 66 | void ExportGraph_ToJobs::operator()()
 | 
|---|
| 67 | {
 | 
|---|
| 68 |   std::vector<FragmentJob::ptr> jobs;
 | 
|---|
| 69 |   KeySetsContainer KeySets;
 | 
|---|
| 70 |   KeySetsContainer FullKeySets;
 | 
|---|
| 71 |   jobs.reserve(TotalGraph.size());
 | 
|---|
| 72 |   LOG(1, "INFO: Creating " << TotalGraph.size() << " possible bond fragmentation jobs.");
 | 
|---|
| 73 | 
 | 
|---|
| 74 |   // gather info about the domain
 | 
|---|
| 75 |   double begin[NDIM] = { 0., 0., 0. };
 | 
|---|
| 76 |   RealSpaceMatrix M = World::getInstance().getDomain().getM();
 | 
|---|
| 77 |   M *= 1./AtomicLengthToAngstroem;  // scale to atomic length units
 | 
|---|
| 78 |   const double size = M.at(0,0);
 | 
|---|
| 79 |   double end[NDIM] = { size, size, size };
 | 
|---|
| 80 |   const ParserTypes jobtype =
 | 
|---|
| 81 |       FormatParserStorage::getInstance().getTypeFromName("mpqc");
 | 
|---|
| 82 | 
 | 
|---|
| 83 |   // go through all fragments, output to stream and create job therefrom
 | 
|---|
| 84 |   ExportGraph::SaturatedFragment_ptr CurrentFragment = getNextFragment();
 | 
|---|
| 85 |   for (; (CurrentFragment != NULL) && (CurrentFragment->getKeySet() != ExportGraph::EmptySet);
 | 
|---|
| 86 |       CurrentFragment = getNextFragment()) {
 | 
|---|
| 87 |     const KeySet &set = CurrentFragment->getKeySet();
 | 
|---|
| 88 |     LOG(2, "INFO: Creating bond fragment job for set " << set << ".");
 | 
|---|
| 89 |     // store config in stream
 | 
|---|
| 90 |     {
 | 
|---|
| 91 |       std::stringstream output;
 | 
|---|
| 92 |       // save to stream
 | 
|---|
| 93 |       CurrentFragment->OutputConfig(output, jobtype);
 | 
|---|
| 94 |       // create job and insert
 | 
|---|
| 95 |       FragmentJob::ptr testJob( new MPQCJob(JobId::IllegalJob, output.str(), begin, end, level) );
 | 
|---|
| 96 |       testJob->setPriority(CurrentFragment->getKeySet().size());
 | 
|---|
| 97 |       jobs.push_back(testJob);
 | 
|---|
| 98 | 
 | 
|---|
| 99 |       // order is the same as the number of non-hydrogen atoms
 | 
|---|
| 100 |       const KeySet &keyset = CurrentFragment->getKeySet();
 | 
|---|
| 101 |       const size_t order = keyset.size();
 | 
|---|
| 102 |       const KeySet &fullmolecule = CurrentFragment->getFullMolecule();
 | 
|---|
| 103 |       const KeySet &saturationhydrogens = CurrentFragment->getSaturationHydrogens();
 | 
|---|
| 104 |       KeySetsContainer::IntVector indices(keyset.begin(), keyset.end());
 | 
|---|
| 105 |       KeySetsContainer::IntVector forceindices(fullmolecule.begin(), fullmolecule.end());
 | 
|---|
| 106 |       {
 | 
|---|
| 107 |         // replace all saturated hydrogen indices by "-1"
 | 
|---|
| 108 |         for (KeySetsContainer::IntVector::iterator iter = forceindices.begin();
 | 
|---|
| 109 |             iter != forceindices.end();
 | 
|---|
| 110 |             ++iter)
 | 
|---|
| 111 |           if (saturationhydrogens.find(*iter) != saturationhydrogens.end())
 | 
|---|
| 112 |             *iter = -1;
 | 
|---|
| 113 |       }
 | 
|---|
| 114 |       KeySets.insert(indices, order);
 | 
|---|
| 115 |       FullKeySets.insert(forceindices, order);
 | 
|---|
| 116 |     }
 | 
|---|
| 117 |     // store force index reference file
 | 
|---|
| 118 |     // explicitly release fragment
 | 
|---|
| 119 |     CurrentFragment.reset();
 | 
|---|
| 120 |   }
 | 
|---|
| 121 |   if (CurrentFragment == NULL) {
 | 
|---|
| 122 |     ELOG(1, "Some error while obtaining the next fragment occured.");
 | 
|---|
| 123 |     return;
 | 
|---|
| 124 |   }
 | 
|---|
| 125 | 
 | 
|---|
| 126 |   // push final jobs
 | 
|---|
| 127 |   FragmentJobQueue::getInstance().addJobs(jobs, KeySets, FullKeySets);
 | 
|---|
| 128 | }
 | 
|---|