| [de0af2] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2011 University of Bonn. All rights reserved.
 | 
|---|
| [5aaa43] | 5 |  * Copyright (C)  2013 Frederik Heber. All rights reserved.
 | 
|---|
| [de0af2] | 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 | 
 | 
|---|
| [ac9ca4] | 36 | // boost asio required before MemDebug due to placement new
 | 
|---|
 | 37 | #include <boost/asio.hpp>
 | 
|---|
 | 38 | 
 | 
|---|
| [de0af2] | 39 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
 | 40 | 
 | 
|---|
| [8652a30] | 41 | #include "Fragmentation/Exporters/ExportGraph_ToJobs.hpp"
 | 
|---|
 | 42 | 
 | 
|---|
| [ac9ca4] | 43 | #include <algorithm>
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 | #include "Box.hpp"
 | 
|---|
 | 46 | #include "Fragmentation/KeySet.hpp"
 | 
|---|
 | 47 | #include "Fragmentation/Automation/FragmentJobQueue.hpp"
 | 
|---|
 | 48 | #include "Helpers/defs.hpp"
 | 
|---|
| [1dfe00] | 49 | #ifdef HAVE_JOBMARKET
 | 
|---|
| [ac9ca4] | 50 | #include "Jobs/MPQCJob.hpp"
 | 
|---|
| [1dfe00] | 51 | #else
 | 
|---|
 | 52 | #include "Jobs/MPQCCommandJob.hpp"
 | 
|---|
 | 53 | #endif
 | 
|---|
| [ac9ca4] | 54 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
 | 
|---|
 | 55 | #include "Parser/FormatParserStorage.hpp"
 | 
|---|
| [8652a30] | 56 | #include "World.hpp"
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | ExportGraph_ToJobs::ExportGraph_ToJobs(
 | 
|---|
 | 59 |     const Graph &_graph,
 | 
|---|
 | 60 |     const enum HydrogenTreatment _treatment,
 | 
|---|
 | 61 |     const enum HydrogenSaturation _saturation) :
 | 
|---|
| [ac9ca4] | 62 |     ExportGraph(_graph, _treatment, _saturation),
 | 
|---|
 | 63 |     level(5)
 | 
|---|
| [8652a30] | 64 | {}
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | ExportGraph_ToJobs::~ExportGraph_ToJobs()
 | 
|---|
 | 67 | {}
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 | void ExportGraph_ToJobs::operator()()
 | 
|---|
 | 70 | {
 | 
|---|
| [ac9ca4] | 71 |   std::vector<FragmentJob::ptr> jobs;
 | 
|---|
 | 72 |   KeySetsContainer KeySets;
 | 
|---|
 | 73 |   KeySetsContainer FullKeySets;
 | 
|---|
 | 74 |   jobs.reserve(TotalGraph.size());
 | 
|---|
 | 75 |   LOG(1, "INFO: Creating " << TotalGraph.size() << " possible bond fragmentation jobs.");
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 |   // gather info about the domain
 | 
|---|
 | 78 |   double begin[NDIM] = { 0., 0., 0. };
 | 
|---|
 | 79 |   RealSpaceMatrix M = World::getInstance().getDomain().getM();
 | 
|---|
 | 80 |   M *= 1./AtomicLengthToAngstroem;  // scale to atomic length units
 | 
|---|
 | 81 |   const double size = M.at(0,0);
 | 
|---|
 | 82 |   double end[NDIM] = { size, size, size };
 | 
|---|
 | 83 |   const ParserTypes jobtype =
 | 
|---|
 | 84 |       FormatParserStorage::getInstance().getTypeFromName("mpqc");
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 |   // go through all fragments, output to stream and create job therefrom
 | 
|---|
 | 87 |   ExportGraph::SaturatedFragment_ptr CurrentFragment = getNextFragment();
 | 
|---|
 | 88 |   for (; (CurrentFragment != NULL) && (CurrentFragment->getKeySet() != ExportGraph::EmptySet);
 | 
|---|
 | 89 |       CurrentFragment = getNextFragment()) {
 | 
|---|
 | 90 |     const KeySet &set = CurrentFragment->getKeySet();
 | 
|---|
 | 91 |     LOG(2, "INFO: Creating bond fragment job for set " << set << ".");
 | 
|---|
 | 92 |     // store config in stream
 | 
|---|
 | 93 |     {
 | 
|---|
 | 94 |       std::stringstream output;
 | 
|---|
 | 95 |       // save to stream
 | 
|---|
 | 96 |       CurrentFragment->OutputConfig(output, jobtype);
 | 
|---|
 | 97 |       // create job and insert
 | 
|---|
| [1dfe00] | 98 |       FragmentJob::ptr testJob(
 | 
|---|
 | 99 | #ifdef HAVE_JOBMARKET
 | 
|---|
 | 100 |           new MPQCJob(JobId::IllegalJob, output.str(), begin, end, level)
 | 
|---|
 | 101 | #else
 | 
|---|
 | 102 |           new MPQCCommandJob(output.str(), JobId::IllegalJob)
 | 
|---|
 | 103 | #endif
 | 
|---|
 | 104 |       );
 | 
|---|
| [a953c4] | 105 |       testJob->setPriority(CurrentFragment->getKeySet().size());
 | 
|---|
| [ac9ca4] | 106 |       jobs.push_back(testJob);
 | 
|---|
 | 107 | 
 | 
|---|
 | 108 |       // order is the same as the number of non-hydrogen atoms
 | 
|---|
 | 109 |       const KeySet &keyset = CurrentFragment->getKeySet();
 | 
|---|
 | 110 |       const size_t order = keyset.size();
 | 
|---|
 | 111 |       const KeySet &fullmolecule = CurrentFragment->getFullMolecule();
 | 
|---|
 | 112 |       const KeySet &saturationhydrogens = CurrentFragment->getSaturationHydrogens();
 | 
|---|
 | 113 |       KeySetsContainer::IntVector indices(keyset.begin(), keyset.end());
 | 
|---|
 | 114 |       KeySetsContainer::IntVector forceindices(fullmolecule.begin(), fullmolecule.end());
 | 
|---|
 | 115 |       {
 | 
|---|
 | 116 |         // replace all saturated hydrogen indices by "-1"
 | 
|---|
 | 117 |         for (KeySetsContainer::IntVector::iterator iter = forceindices.begin();
 | 
|---|
 | 118 |             iter != forceindices.end();
 | 
|---|
 | 119 |             ++iter)
 | 
|---|
 | 120 |           if (saturationhydrogens.find(*iter) != saturationhydrogens.end())
 | 
|---|
 | 121 |             *iter = -1;
 | 
|---|
 | 122 |       }
 | 
|---|
 | 123 |       KeySets.insert(indices, order);
 | 
|---|
 | 124 |       FullKeySets.insert(forceindices, order);
 | 
|---|
 | 125 |     }
 | 
|---|
 | 126 |     // store force index reference file
 | 
|---|
 | 127 |     // explicitly release fragment
 | 
|---|
 | 128 |     CurrentFragment.reset();
 | 
|---|
 | 129 |   }
 | 
|---|
 | 130 |   if (CurrentFragment == NULL) {
 | 
|---|
 | 131 |     ELOG(1, "Some error while obtaining the next fragment occured.");
 | 
|---|
 | 132 |     return;
 | 
|---|
 | 133 |   }
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 |   // push final jobs
 | 
|---|
 | 136 |   FragmentJobQueue::getInstance().addJobs(jobs, KeySets, FullKeySets);
 | 
|---|
| [8652a30] | 137 | }
 | 
|---|