1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2013 University of Bonn. 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 | * FragmentJobQueue.cpp
|
---|
25 | *
|
---|
26 | * Created on: Mar 4, 2013
|
---|
27 | * Author: heber
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include "CodePatterns/MemDebug.hpp"
|
---|
36 |
|
---|
37 | #include "Fragmentation/Automation/FragmentJobQueue.hpp"
|
---|
38 |
|
---|
39 | #include <boost/filesystem.hpp>
|
---|
40 | #include <fstream>
|
---|
41 |
|
---|
42 | #include "CodePatterns/Assert.hpp"
|
---|
43 | #include "CodePatterns/Log.hpp"
|
---|
44 | #include "CodePatterns/Singleton_impl.hpp"
|
---|
45 |
|
---|
46 | #include "Box.hpp"
|
---|
47 | #include "Fragmentation/Automation/parseKeySetFile.hpp"
|
---|
48 | #include "Helpers/defs.hpp"
|
---|
49 | #include "Jobs/MPQCJob.hpp"
|
---|
50 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
|
---|
51 | #include "World.hpp"
|
---|
52 |
|
---|
53 |
|
---|
54 | void FragmentJobQueue::parsejob(const std::string &filename, const unsigned int level)
|
---|
55 | {
|
---|
56 | std::ifstream file;
|
---|
57 | file.open(filename.c_str());
|
---|
58 | ASSERT( file.good(), "parsejob() - file "+filename+" does not exist.");
|
---|
59 | std::string output((std::istreambuf_iterator<char>(file)),
|
---|
60 | std::istreambuf_iterator<char>());
|
---|
61 | double begin[NDIM] = { 0., 0., 0. };
|
---|
62 | RealSpaceMatrix M = World::getInstance().getDomain().getM();
|
---|
63 | M *= 1./AtomicLengthToAngstroem; // scale to atomic length units
|
---|
64 | const double size = M.at(0,0);
|
---|
65 | double end[NDIM] = { size, size, size };
|
---|
66 | ASSERT( M.determinant() == size*size*size,
|
---|
67 | "parsejob() - current domain matrix "+toString(M)+" is not cubic.");
|
---|
68 | FragmentJob::ptr testJob( new MPQCJob(JobId::IllegalJob, output, begin, end, level) );
|
---|
69 | jobs.push_back(testJob);
|
---|
70 | file.close();
|
---|
71 | LOG(1, "INFO: Added MPQCCommandJob from file "+filename+".");
|
---|
72 | }
|
---|
73 |
|
---|
74 | bool FragmentJobQueue::addJobsFromFiles(
|
---|
75 | const std::vector< boost::filesystem::path > &jobfiles, const unsigned int level)
|
---|
76 | {
|
---|
77 | for (std::vector< boost::filesystem::path >::const_iterator iter = jobfiles.begin();
|
---|
78 | iter != jobfiles .end(); ++iter) {
|
---|
79 | const std::string &filename = (*iter).string();
|
---|
80 | if (boost::filesystem::exists(filename)) {
|
---|
81 | LOG(1, "INFO: Creating MPQCCommandJob with filename'"+filename+"'.");
|
---|
82 | parsejob(filename, level);
|
---|
83 | } else {
|
---|
84 | ELOG(1, "Fragment job "+filename+" does not exist.");
|
---|
85 | return false;
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | return true;
|
---|
90 | }
|
---|
91 |
|
---|
92 | bool FragmentJobQueue::addKeySetsFromFiles(
|
---|
93 | const boost::filesystem::path &path,
|
---|
94 | const size_t FragmentCounter,
|
---|
95 | const enum KeySetFileType keysettype
|
---|
96 | )
|
---|
97 | {
|
---|
98 | const size_t NoJobs = KeySets.KeySets.size();
|
---|
99 | parseKeySetFile(KeySets, path.string(), FragmentCounter, NonHydrogenKeySets);
|
---|
100 | ASSERT( (KeySets.KeySets.size()-NoJobs) == FragmentCounter,
|
---|
101 | "FragmentJobQueue::addKeySetsFromFiles() - mismatching number of new fragments "
|
---|
102 | +toString(KeySets.KeySets.size()-NoJobs)+" and number of Keyset "
|
---|
103 | +toString(FragmentCounter)+".");
|
---|
104 | return (KeySets.KeySets.size() > NoJobs);
|
---|
105 | }
|
---|
106 |
|
---|
107 | bool FragmentJobQueue::addFullKeySetsFromFiles(
|
---|
108 | const boost::filesystem::path &path,
|
---|
109 | const size_t FragmentCounter,
|
---|
110 | const enum KeySetFileType keysettype
|
---|
111 | )
|
---|
112 | {
|
---|
113 | const size_t NoJobs = FullKeySets.KeySets.size();
|
---|
114 | parseKeySetFile(FullKeySets, path.string(), FragmentCounter, NonHydrogenKeySets);
|
---|
115 | ASSERT( (FullKeySets.KeySets.size()-NoJobs) == FragmentCounter,
|
---|
116 | "FragmentJobQueue::addKeySetsFromFiles() - mismatching number of fragments "
|
---|
117 | +toString(FullKeySets.KeySets.size()-NoJobs)+" and number of FullKeyset "
|
---|
118 | +toString(FragmentCounter)+".");
|
---|
119 | return (FullKeySets.KeySets.size() > NoJobs);
|
---|
120 | }
|
---|
121 |
|
---|
122 | void FragmentJobQueue::clear()
|
---|
123 | {
|
---|
124 | jobs.clear();
|
---|
125 | KeySets.clear();
|
---|
126 | FullKeySets.clear();
|
---|
127 | }
|
---|
128 |
|
---|
129 | CONSTRUCT_SINGLETON(FragmentJobQueue)
|
---|
130 |
|
---|