| 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 "Helpers/defs.hpp" | 
|---|
| 48 | #include "Jobs/MPQCJob.hpp" | 
|---|
| 49 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
| 50 | #include "World.hpp" | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 | void FragmentJobQueue::parsejob(const std::string &filename, const unsigned int level) | 
|---|
| 54 | { | 
|---|
| 55 | std::ifstream file; | 
|---|
| 56 | file.open(filename.c_str()); | 
|---|
| 57 | ASSERT( file.good(), "parsejob() - file "+filename+" does not exist."); | 
|---|
| 58 | std::string output((std::istreambuf_iterator<char>(file)), | 
|---|
| 59 | std::istreambuf_iterator<char>()); | 
|---|
| 60 | double begin[NDIM] = { 0., 0., 0. }; | 
|---|
| 61 | RealSpaceMatrix M = World::getInstance().getDomain().getM(); | 
|---|
| 62 | M *= 1./AtomicLengthToAngstroem;  // scale to atomic length units | 
|---|
| 63 | const double size = M.at(0,0); | 
|---|
| 64 | double end[NDIM] = { size, size, size }; | 
|---|
| 65 | ASSERT( M.determinant() == size*size*size, | 
|---|
| 66 | "parsejob() - current domain matrix "+toString(M)+" is not cubic."); | 
|---|
| 67 | FragmentJob::ptr testJob( new MPQCJob(JobId::IllegalJob, output, begin, end, level) ); | 
|---|
| 68 | jobs.push_back(testJob); | 
|---|
| 69 | file.close(); | 
|---|
| 70 | LOG(1, "INFO: Added MPQCCommandJob from file "+filename+"."); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | bool FragmentJobQueue::addJobsFromFiles( | 
|---|
| 74 | const std::vector< boost::filesystem::path > &jobfiles, const unsigned int level) | 
|---|
| 75 | { | 
|---|
| 76 | for (std::vector< boost::filesystem::path >::const_iterator iter = jobfiles.begin(); | 
|---|
| 77 | iter != jobfiles .end(); ++iter) { | 
|---|
| 78 | const std::string &filename = (*iter).string(); | 
|---|
| 79 | if (boost::filesystem::exists(filename)) { | 
|---|
| 80 | LOG(1, "INFO: Creating MPQCCommandJob with filename'"+filename+"'."); | 
|---|
| 81 | parsejob(filename, level); | 
|---|
| 82 | } else { | 
|---|
| 83 | ELOG(1, "Fragment job "+filename+" does not exist."); | 
|---|
| 84 | return false; | 
|---|
| 85 | } | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | return true; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | void FragmentJobQueue::clear() | 
|---|
| 92 | { | 
|---|
| 93 | jobs.clear(); | 
|---|
| 94 | KeySets.clear(); | 
|---|
| 95 | FullKeySets.clear(); | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | CONSTRUCT_SINGLETON(FragmentJobQueue) | 
|---|
| 99 |  | 
|---|