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 "Helpers/defs.hpp"
|
---|
49 | #ifdef HAVE_JOBMARKET
|
---|
50 | #include "Jobs/MPQCJob.hpp"
|
---|
51 | #else
|
---|
52 | #include "Jobs/MPQCCommandJob.hpp"
|
---|
53 | #endif
|
---|
54 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
|
---|
55 | #include "Parser/FormatParserStorage.hpp"
|
---|
56 | #include "World.hpp"
|
---|
57 |
|
---|
58 | ExportGraph_ToJobs::ExportGraph_ToJobs(
|
---|
59 | const Graph &_graph,
|
---|
60 | const enum HydrogenTreatment _treatment,
|
---|
61 | const enum HydrogenSaturation _saturation,
|
---|
62 | const SaturatedFragment::GlobalSaturationPositions_t &_globalsaturationpositions) :
|
---|
63 | ExportGraph(_graph, _treatment, _saturation,_globalsaturationpositions),
|
---|
64 | level(5)
|
---|
65 | {}
|
---|
66 |
|
---|
67 | ExportGraph_ToJobs::~ExportGraph_ToJobs()
|
---|
68 | {}
|
---|
69 |
|
---|
70 | void ExportGraph_ToJobs::operator()()
|
---|
71 | {
|
---|
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 = std::max( std::max(M.at(0,0), M.at(1,1)), M.at(2,2));
|
---|
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
|
---|
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 | );
|
---|
106 | testJob->setPriority(CurrentFragment->getKeySet().size());
|
---|
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);
|
---|
138 | }
|
---|