[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,
|
---|
[98a293b] | 61 | const enum HydrogenSaturation _saturation,
|
---|
| 62 | const SaturatedFragment::GlobalSaturationPositions_t &_globalsaturationpositions) :
|
---|
| 63 | ExportGraph(_graph, _treatment, _saturation,_globalsaturationpositions),
|
---|
[ac9ca4] | 64 | level(5)
|
---|
[8652a30] | 65 | {}
|
---|
| 66 |
|
---|
| 67 | ExportGraph_ToJobs::~ExportGraph_ToJobs()
|
---|
| 68 | {}
|
---|
| 69 |
|
---|
| 70 | void ExportGraph_ToJobs::operator()()
|
---|
| 71 | {
|
---|
[ac9ca4] | 72 | std::vector<FragmentJob::ptr> jobs;
|
---|
| 73 | KeySetsContainer KeySets;
|
---|
| 74 | KeySetsContainer FullKeySets;
|
---|
| 75 | jobs.reserve(TotalGraph.size());
|
---|
| 76 | LOG(1, "INFO: Creating " << TotalGraph.size() << " possible bond fragmentation jobs.");
|
---|
| 77 |
|
---|
| 78 | // gather info about the domain
|
---|
| 79 | double begin[NDIM] = { 0., 0., 0. };
|
---|
| 80 | RealSpaceMatrix M = World::getInstance().getDomain().getM();
|
---|
| 81 | M *= 1./AtomicLengthToAngstroem; // scale to atomic length units
|
---|
| 82 | const double size = M.at(0,0);
|
---|
| 83 | double end[NDIM] = { size, size, size };
|
---|
| 84 | const ParserTypes jobtype =
|
---|
| 85 | FormatParserStorage::getInstance().getTypeFromName("mpqc");
|
---|
| 86 |
|
---|
| 87 | // go through all fragments, output to stream and create job therefrom
|
---|
| 88 | ExportGraph::SaturatedFragment_ptr CurrentFragment = getNextFragment();
|
---|
| 89 | for (; (CurrentFragment != NULL) && (CurrentFragment->getKeySet() != ExportGraph::EmptySet);
|
---|
| 90 | CurrentFragment = getNextFragment()) {
|
---|
| 91 | const KeySet &set = CurrentFragment->getKeySet();
|
---|
| 92 | LOG(2, "INFO: Creating bond fragment job for set " << set << ".");
|
---|
| 93 | // store config in stream
|
---|
| 94 | {
|
---|
| 95 | std::stringstream output;
|
---|
| 96 | // save to stream
|
---|
| 97 | CurrentFragment->OutputConfig(output, jobtype);
|
---|
| 98 | // create job and insert
|
---|
[1dfe00] | 99 | FragmentJob::ptr testJob(
|
---|
| 100 | #ifdef HAVE_JOBMARKET
|
---|
| 101 | new MPQCJob(JobId::IllegalJob, output.str(), begin, end, level)
|
---|
| 102 | #else
|
---|
| 103 | new MPQCCommandJob(output.str(), JobId::IllegalJob)
|
---|
| 104 | #endif
|
---|
| 105 | );
|
---|
[a953c4] | 106 | testJob->setPriority(CurrentFragment->getKeySet().size());
|
---|
[ac9ca4] | 107 | jobs.push_back(testJob);
|
---|
| 108 |
|
---|
| 109 | // order is the same as the number of non-hydrogen atoms
|
---|
| 110 | const KeySet &keyset = CurrentFragment->getKeySet();
|
---|
| 111 | const size_t order = keyset.size();
|
---|
| 112 | const KeySet &fullmolecule = CurrentFragment->getFullMolecule();
|
---|
| 113 | const KeySet &saturationhydrogens = CurrentFragment->getSaturationHydrogens();
|
---|
| 114 | KeySetsContainer::IntVector indices(keyset.begin(), keyset.end());
|
---|
| 115 | KeySetsContainer::IntVector forceindices(fullmolecule.begin(), fullmolecule.end());
|
---|
| 116 | {
|
---|
| 117 | // replace all saturated hydrogen indices by "-1"
|
---|
| 118 | for (KeySetsContainer::IntVector::iterator iter = forceindices.begin();
|
---|
| 119 | iter != forceindices.end();
|
---|
| 120 | ++iter)
|
---|
| 121 | if (saturationhydrogens.find(*iter) != saturationhydrogens.end())
|
---|
| 122 | *iter = -1;
|
---|
| 123 | }
|
---|
| 124 | KeySets.insert(indices, order);
|
---|
| 125 | FullKeySets.insert(forceindices, order);
|
---|
| 126 | }
|
---|
| 127 | // store force index reference file
|
---|
| 128 | // explicitly release fragment
|
---|
| 129 | CurrentFragment.reset();
|
---|
| 130 | }
|
---|
| 131 | if (CurrentFragment == NULL) {
|
---|
| 132 | ELOG(1, "Some error while obtaining the next fragment occured.");
|
---|
| 133 | return;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | // push final jobs
|
---|
| 137 | FragmentJobQueue::getInstance().addJobs(jobs, KeySets, FullKeySets);
|
---|
[8652a30] | 138 | }
|
---|