source: src/Jobs/MPQCCommandJob.cpp@ d93d2c

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since d93d2c was 20bb3b, checked in by Frederik Heber <heber@…>, 9 years ago

MPQCData now also uses FragmentForces (instead of typedef forcevector).

  • required small changes to MPQCCommandJob due to changed typedef.
  • we need to maintain the old code which used vector of forces. Therefore, the serialization version of MPQCData is increased and a simple conversion routine added.
  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 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 * MPQCCommandJob.cpp
25 *
26 * Created on: Feb 05, 2012
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 headers that implement a archive in simple text format
38// otherwise BOOST_CLASS_EXPORT_IMPLEMENT has no effect
39#include <boost/archive/text_oarchive.hpp>
40#include <boost/archive/text_iarchive.hpp>
41
42#include "MPQCCommandJob.hpp"
43
44#include <boost/algorithm/string.hpp>
45#include <boost/lexical_cast.hpp>
46#include <boost/tokenizer.hpp>
47#include <sstream>
48
49#include "CodePatterns/Assert.hpp"
50#include "CodePatterns/Log.hpp"
51
52#include "LinearAlgebra/defs.hpp"
53
54#include "Fragmentation/Summation/SetValues/FragmentForces.hpp"
55
56const std::string MPQCCommandJob::keyword_hartreefock_energy("total scf energy");
57const std::string MPQCCommandJob::keyword_moellerplesset_energy("MP2 energy [au]:");
58const std::string MPQCCommandJob::keyword_hartreefock_forces("Total Gradient");
59const std::string MPQCCommandJob::keyword_moellerplesset_forces("Total MP2 gradient [au]:");
60
61/** Default constructor for class MPQCCommandJob.
62 *
63 */
64MPQCCommandJob::MPQCCommandJob()
65{}
66
67/** Constructor for class MPQCCommandJob.
68 *
69 * @param _inputfile string of inputfile contents
70 * @param _JobId id of this job
71 * @param command mpqc command, "mpqc" as default
72 */
73MPQCCommandJob::MPQCCommandJob(
74 const std::string &_inputfile,
75 const JobId_t _JobId,
76 const std::string &command) :
77 SystemCommandJob(command, _inputfile, _JobId)
78{}
79
80/** Destructor for class MPQCCommandJob.
81 *
82 */
83MPQCCommandJob::~MPQCCommandJob()
84{}
85
86/** Extracts energy and forces from the output of the command.
87 *
88 * @param resultstring output of the command to parse
89 * @return FragmentResult with energy and forces
90 */
91FragmentResult::ptr MPQCCommandJob::extractResult(const std::string &resultstring)
92{
93 std::stringstream returnstream;
94 // tokenizers
95 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
96 boost::char_separator<char> keyvalue_separator("=:");
97 boost::char_separator<char> whitespace(" \t");
98
99 // split into lines
100 std::vector<std::string> lines;
101 boost::split(lines, resultstring, boost::is_any_of("\n"));
102
103 // go through each line
104 bool gradient_section = false;
105 for (std::vector<std::string>::const_iterator iter = lines.begin();
106 iter != lines.end();++iter) {
107 LOG(3, "DEBUG: Current line is '" << *iter << "'.");
108 if (gradient_section) {
109 tokenizer tokens(*iter, whitespace);
110 if (*iter != std::string("")) {
111 tokenizer::iterator tok_iter = tokens.begin();
112 tok_iter++;
113 tok_iter++;
114 FragmentForces::force_t forcevector(NDIM);
115 try { // first col is index, second is element
116 for (size_t index = 0;index < NDIM; ++index)
117 forcevector[index] = boost::lexical_cast<double>(*(tok_iter++));
118 LOG(2, "INFO: Recognized force vector in '"+*iter+"'.");
119 data.forces.push_back( forcevector );
120 } catch(boost::bad_lexical_cast){
121 LOG(2, "INFO: Did not recognize a force vector, hence ending section at '"+*iter+"'.");
122 gradient_section = false;
123 }
124 } else {
125 LOG(2, "INFO: Recognized gradient section end in '"+*iter+"'.");
126 gradient_section = false;
127 }
128 }
129 // extract energy ("total scf energy") ...
130 if (((*iter).find(keyword_hartreefock_energy) != std::string::npos)
131 || ((*iter).find(keyword_moellerplesset_energy) != std::string::npos))
132 {
133 LOG(2, "INFO: Recognized energy in '"+*iter+"'.");
134 tokenizer tokens(*iter, keyvalue_separator);
135 tokenizer::iterator tok_iter = tokens.begin();
136 tok_iter++;
137 std::stringstream energystring(*tok_iter);
138 energystring >> data.energies.total;
139 }
140 // ... and forces ("Total Gradient") from resultstring
141 if (((*iter).find(keyword_hartreefock_forces) != std::string::npos)
142 || ((*iter).find(keyword_moellerplesset_forces) != std::string::npos))
143 {
144 LOG(2, "INFO: Recognized gradient section init in '"+*iter+"'.");
145 gradient_section=true;
146 data.forces.clear();
147 }
148 }
149
150 // place into returnstream
151 {
152 const MPQCData archivedata(data);
153 boost::archive::text_oarchive oa(returnstream);
154 oa << archivedata;
155 }
156
157 FragmentResult::ptr s( new FragmentResult(getId(), returnstream.str()) );
158 return s;
159}
160
161bool MPQCCommandJob::operator==(const MPQCCommandJob &other) const
162{
163 if (data != other.data) {
164 LOG(2, "INFO: data's of both MPQCCommandJob don't match.");
165 return false;
166 }
167 return (static_cast<const SystemCommandJob &>(*this)
168 == static_cast<const SystemCommandJob &>(other));
169}
170
171
172// we need to explicitly instantiate the serialization functions as
173// its is only serialized through its base class FragmentJob
174BOOST_CLASS_EXPORT_IMPLEMENT(MPQCCommandJob)
Note: See TracBrowser for help on using the repository browser.