Changes in / [360c8b:fa9d1d]
- Files:
-
- 1 added
- 55 deleted
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
configure.ac
r360c8b rfa9d1d 122 122 BOOST_RANDOM 123 123 BOOST_SMART_PTR 124 BOOST_STRING_ALGO125 124 BOOST_TOKENIZER 126 125 -
src/Actions/MoleculeAction/FillVoidWithMoleculeAction.cpp
r360c8b rfa9d1d 28 28 #include "Descriptors/MoleculeOrderDescriptor.hpp" 29 29 #include "molecule.hpp" 30 #include "Parser/FormatParserInterface.hpp"31 30 #include "Parser/FormatParserStorage.hpp" 32 31 #include "World.hpp" … … 68 67 input.open(params.fillername.string().c_str()); 69 68 ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix); 70 FormatParser Interface&parser = FormatParserStorage::getInstance().get(type);69 FormatParser &parser = FormatParserStorage::getInstance().get(type); 71 70 parser.load(&input); 72 71 -
src/Actions/MoleculeAction/FillWithMoleculeAction.cpp
r360c8b rfa9d1d 28 28 #include "Descriptors/MoleculeOrderDescriptor.hpp" 29 29 #include "molecule.hpp" 30 #include "Parser/FormatParserInterface.hpp"31 30 #include "Parser/FormatParserStorage.hpp" 32 31 #include "World.hpp" … … 62 61 input.open(params.fillername.string().c_str()); 63 62 ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix); 64 FormatParser Interface&parser = FormatParserStorage::getInstance().get(type);63 FormatParser &parser = FormatParserStorage::getInstance().get(type); 65 64 parser.load(&input); 66 65 -
src/Actions/MoleculeAction/LoadAction.cpp
r360c8b rfa9d1d 23 23 #include "CodePatterns/Verbose.hpp" 24 24 #include "Descriptors/MoleculeIdDescriptor.hpp" 25 #include "Parser/FormatParserInterface.hpp"26 25 #include "Parser/FormatParserStorage.hpp" 27 26 #include "Parser/FormatParser_Parameters.hpp" … … 71 70 // get undo state for parser 72 71 enum ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix); 73 ASSERT(type != ParserTypes_end,74 "MoleculeLoadAction::performCall() - unknown file suffix "+FilenameSuffix+".");75 72 FormatParser_Parameters *ParserParams = FormatParserStorage::getInstance().get(type).parameters; 76 73 if (ParserParams != NULL) -
src/Actions/ParserAction/ParseTremoloPotentialsAction.cpp
r360c8b rfa9d1d 43 43 44 44 boost::filesystem::ifstream test; 45 FormatParser<tremolo> &parser = FormatParserStorage::getInstance().getParser<tremolo>();45 TremoloParser &tremolo = FormatParserStorage::getInstance().getTremolo(); 46 46 // parsing file if present 47 47 if (!boost::filesystem::exists(params.filename)) { 48 48 DoLog(1) && (Log() << Verbose(1) << "Specified potentials file " << params.filename << " not found." << endl); 49 49 // DONT FAIL: it's just empty we re-create default id-mapping 50 parser.createKnownTypesByIdentity();50 tremolo.createKnownTypesByIdentity(); 51 51 52 52 } else { … … 55 55 // parse the file 56 56 test.open(params.filename); 57 parser.parseKnownTypes(test); 57 TremoloParser &tremolo = FormatParserStorage::getInstance().getTremolo(); 58 tremolo.parseKnownTypes(test); 58 59 test.close(); 59 60 } -
src/Actions/ParserAction/SetMpqcParametersAction.cpp
r360c8b rfa9d1d 38 38 /** =========== define the function ====================== */ 39 39 Action::state_ptr ParserSetMpqcParametersAction::performCall() { 40 MpqcParser_Parameters & parser = FormatParserStorage::getInstance().getParser<mpqc>().getParams();40 MpqcParser_Parameters &mpqc = FormatParserStorage::getInstance().getMpqc().getParams(); 41 41 42 42 std::stringstream oldparamstream; 43 oldparamstream << parser;43 oldparamstream << mpqc; 44 44 // obtain information 45 45 getParametersfromValueStorage(); 46 46 std::stringstream newparamstream(params.newparams); 47 newparamstream >> parser;47 newparamstream >> mpqc; 48 48 49 49 return Action::state_ptr(new ParserSetMpqcParametersState(oldparamstream.str(), params)); … … 53 53 ParserSetMpqcParametersState *state = assert_cast<ParserSetMpqcParametersState*>(_state.get()); 54 54 55 MpqcParser_Parameters & parser = FormatParserStorage::getInstance().getParser<mpqc>().getParams();55 MpqcParser_Parameters &mpqc = FormatParserStorage::getInstance().getMpqc().getParams(); 56 56 std::stringstream oldparamstream(state->oldparams); 57 oldparamstream >> parser;57 oldparamstream >> mpqc; 58 58 59 59 return Action::state_ptr(_state); … … 63 63 ParserSetMpqcParametersState *state = assert_cast<ParserSetMpqcParametersState*>(_state.get()); 64 64 65 MpqcParser_Parameters & parser = FormatParserStorage::getInstance().getParser<mpqc>().getParams();65 MpqcParser_Parameters &mpqc = FormatParserStorage::getInstance().getMpqc().getParams(); 66 66 std::stringstream newparamstream(state->params.newparams); 67 newparamstream >> parser;67 newparamstream >> mpqc; 68 68 69 69 return Action::state_ptr(_state); -
src/Actions/ParserAction/SetTremoloAtomdataAction.cpp
r360c8b rfa9d1d 42 42 getParametersfromValueStorage(); 43 43 44 FormatParser<tremolo> &parser = FormatParserStorage::getInstance().getParser<tremolo>();44 TremoloParser &tremolo = FormatParserStorage::getInstance().getTremolo(); 45 45 46 46 DoLog(1) && (Log() << Verbose(1) << "Setting Tremolo's ATOMDATA to: '" << params.atomdata_string << "'" << std::endl); 47 47 48 parser.setAtomData(params.atomdata_string);48 tremolo.setAtomData(params.atomdata_string); 49 49 50 50 return Action::success; -
src/Parser/FormatParser.hpp
r360c8b rfa9d1d 14 14 #endif 15 15 16 #include <iosfwd>17 #include <string>18 #include <vector>19 16 20 #include "CodePatterns/Assert.hpp" 17 #include "CodePatterns/Observer.hpp" 18 #include "ChangeTracker.hpp" 19 #include "FormatParser_Parameters.hpp" 21 20 22 #include "FormatParserTrait.hpp" 23 #include "FormatParserInterface.hpp" 24 #include "FormatParser_common.hpp" 25 #include "ParserTypes.hpp" 21 namespace MoleCuilder { 22 class MoleculeLoadAction; 23 } 26 24 27 25 class atom; 28 26 29 27 /** 30 * @file31 * <H1> FormatParser Howto </H1>32 *33 * <H2> Introduction </H2>34 *35 * FormatParsers parse external streams (files) and bring their information36 * into the World. That is they implement load and save functions that work37 * on a specific vector atoms.38 *39 * <H2> Building your own Parsers </H2>40 *41 * Building Parsers is easy. All you have to do is the following:42 * -# add a new parser type to the file ParserTypes.def.43 * -# add a new template specialization of FormatParser in a new header and44 * module that implement the virtual load and save functions.45 * -# Add the header file of your new parser to FormatParserStorage.cpp.46 *47 * <H3> Specific notes on the macros </H3>48 *49 * To clarify a bit the internals of all the different FormatParser... files, here50 * are some notes:51 * -# We make use of boost::preprocessor to generate lists from the sequence52 * given in ParserTypes.def (and undefined in ParserTypes.undef). These might53 * be forward declarations of even implementations. This is to assure that54 * none are forgotten when a new FormatParser is added.55 * -# Thanks to the above construct FormatParserStorage also immediately knows56 * about any new parsers and can get and add such instances.57 */58 59 /**60 28 * General parser which observes the change tracker. 61 29 */ 62 template <enum ParserTypes Ptype> 63 class FormatParser : virtual public FormatParserInterface, public FormatParser_common { 64 FormatParser() : 65 FormatParser_common(NULL) 66 { 67 ASSERT(0, "FormatParser<>::FormatParser() - unspecialized function cannot be called."); 68 } 69 virtual ~FormatParser() 70 { 71 ASSERT(0, "FormatParser<>::~FormatParser() - unspecialized function cannot be called."); 72 } 30 class FormatParser : public Observer { 31 friend class MoleCuilder::MoleculeLoadAction; 32 public: 33 FormatParser(); 34 virtual ~FormatParser(); 35 virtual void save(std::ostream* file, const std::vector<atom *> &atoms)=0; 36 virtual void load(std::istream* file)=0; 37 void setOstream(std::ostream* file); 73 38 74 void load(std::istream *file) 75 { 76 ASSERT(0, "FormatParser<>::load() - unspecialized function cannot be called."); 77 } 78 void save(std::ostream *file, const std::vector<atom *> &atoms) 79 { 80 ASSERT(0, "FormatParser<>::save() - unspecialized function cannot be called."); 81 } 39 protected: 40 void update(Observable *publisher); 41 void recieveNotification(Observable *publisher, Notification_ptr notification); 42 void subjectKilled(Observable *publisher); 43 44 // these functions are called when atoms are inserted or removed 45 virtual void AtomInserted(atomId_t) {}; 46 virtual void AtomRemoved(atomId_t) {}; 47 48 FormatParser_Parameters *parameters; 49 private: 50 51 std::ostream* saveStream; 82 52 }; 83 53 84 #include "FormatParser_specializations_header.hpp"85 86 54 #endif /* FORMATPARSER_HPP_ */ -
src/Parser/FormatParserStorage.cpp
r360c8b rfa9d1d 23 23 #include <fstream> 24 24 25 #include <boost/preprocessor/iteration/local.hpp> 25 #include "Parser/FormatParserStorage.hpp" 26 27 #include "CodePatterns/Log.hpp" 28 #include "CodePatterns/Verbose.hpp" 26 29 27 30 #include "CodePatterns/Assert.hpp" 28 #include "CodePatterns/Log.hpp"29 31 30 32 #include "molecule.hpp" 31 #include "FormatParserStorage.hpp"32 #include "ParserTypes.hpp"33 34 #include "MpqcParser.hpp"35 #include "PcpParser.hpp"36 #include "PdbParser.hpp"37 #include "Psi3Parser.hpp"38 #include "TremoloParser.hpp"39 #include "XyzParser.hpp"40 33 41 34 #include "CodePatterns/Singleton_impl.hpp" 42 35 36 /** Increment operator for the enumeration ParserTypes to allow loops. 37 * \param &type value 38 * \return value incremented by one 39 */ 40 ParserTypes &operator++(ParserTypes &type) 41 { 42 return type = ParserTypes(type+1); 43 } 43 44 44 45 /** Constructor of class FormatParserStorage. … … 50 51 ParserPresent.resize(ParserTypes_end, false); 51 52 52 #include "ParserTypes.def" 53 54 #define insert_print(z,n,seq,map, before, after) \ 55 map .insert( std::make_pair( \ 56 BOOST_PP_SEQ_ELEM(n, seq) \ 57 , before < \ 58 BOOST_PP_SEQ_ELEM(n, seq) \ 59 > after \ 60 ) ); 61 62 #define insert_invert_print(z,n,seq,map, before, after) \ 63 map .insert( std::make_pair( before < \ 64 BOOST_PP_SEQ_ELEM(n, seq) \ 65 > after, \ 66 BOOST_PP_SEQ_ELEM(n, seq) \ 67 ) ); 68 69 // fill ParserNames 70 #if defined ParserTypes_END // do we have parameters at all? 71 #define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserNames, FormatParserTrait, ::name) 72 #define BOOST_PP_LOCAL_LIMITS (0, ParserTypes_END-1) 73 #include BOOST_PP_LOCAL_ITERATE() 74 #endif 75 76 // fill ParserLookupNames 77 #if defined ParserTypes_END // do we have parameters at all? 78 #define BOOST_PP_LOCAL_MACRO(n) insert_invert_print(~, n, PARSERSEQUENCE, ParserLookupNames, FormatParserTrait, ::name) 79 #define BOOST_PP_LOCAL_LIMITS (0, ParserTypes_END-1) 80 #include BOOST_PP_LOCAL_ITERATE() 81 #endif 82 83 // fill ParserSuffixes 84 #if defined ParserTypes_END // do we have parameters at all? 85 #define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserSuffixes, FormatParserTrait, ::suffix) 86 #define BOOST_PP_LOCAL_LIMITS (0, ParserTypes_END-1) 87 #include BOOST_PP_LOCAL_ITERATE() 88 #endif 89 90 // fill ParserLookupSuffixes 91 #if defined ParserTypes_END // do we have parameters at all? 92 #define BOOST_PP_LOCAL_MACRO(n) insert_invert_print(~, n, PARSERSEQUENCE, ParserLookupSuffixes, FormatParserTrait, ::suffix) 93 #define BOOST_PP_LOCAL_LIMITS (0, ParserTypes_END-1) 94 #include BOOST_PP_LOCAL_ITERATE() 95 #endif 96 97 // fill ParserAddFunction 98 #if defined ParserTypes_END // do we have parameters at all? 99 #define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserAddFunction, &FormatParserStorage::addParser, ) 100 #define BOOST_PP_LOCAL_LIMITS (0, ParserTypes_END-1) 101 #include BOOST_PP_LOCAL_ITERATE() 102 #endif 103 104 #undef insert_print 105 #undef insert_invert_print 106 #include "ParserTypes.undef" 107 108 //std::cout << "ParserNames:" << std::endl << ParserNames << std::endl; 109 //std::cout << "ParserSuffixes:" << std::endl << ParserSuffixes << std::endl; 110 //std::cout << "ParserLookupNames:" << std::endl << ParserLookupNames << std::endl; 111 //std::cout << "ParserLookupSuffixes:" << std::endl << ParserLookupSuffixes << std::endl; 112 //std::cout << "ParserAddFunction:" << std::endl << ParserAddFunction << std::endl; 113 53 ParserNames[mpqc] = "mpqc"; 54 ParserNames[pcp] = "pcp"; 55 ParserNames[pdb] = "pdb"; 56 ParserNames[tremolo] = "tremolo"; 57 ParserNames[xyz] = "xyz"; 58 59 for (std::map<ParserTypes, std::string>::const_iterator it = ParserNames.begin(); it != ParserNames.end(); ++it) 60 ParserLookupNames.insert(pair<std::string, ParserTypes>(it->second,it->first) ); 61 62 ParserSuffixes[mpqc] = "in"; 63 ParserSuffixes[pcp] = "conf"; 64 ParserSuffixes[pdb] = "pdb"; 65 ParserSuffixes[tremolo] = "data"; 66 ParserSuffixes[xyz] = "xyz"; 67 68 for (std::map<ParserTypes, std::string>::const_iterator it = ParserSuffixes.begin(); it != ParserSuffixes.end(); ++it) 69 ParserLookupSuffixes.insert(pair<std::string, ParserTypes>(it->second,it->first) ); 70 71 ParserAddFunction[mpqc] = &FormatParserStorage::addMpqc; 72 ParserAddFunction[pcp] = &FormatParserStorage::addPcp; 73 ParserAddFunction[pdb] = &FormatParserStorage::addPdb; 74 ParserAddFunction[tremolo] = &FormatParserStorage::addTremolo; 75 ParserAddFunction[xyz] = &FormatParserStorage::addXyz; 114 76 } 115 77 … … 152 114 153 115 116 /** Adds an MpqcParser to the storage. 117 */ 118 void FormatParserStorage::addMpqc() 119 { 120 if (!ParserPresent[mpqc]) { 121 ParserList[mpqc] = dynamic_cast<FormatParser *>(new MpqcParser); 122 ParserPresent[mpqc] = true; 123 } 124 else 125 DoeLog(2) && (eLog() << Verbose(2) << "Parser mpqc is already present." << endl 126 << "Note that you don't need to add '-o mpqc' if the input file is of type mpqc." << endl); 127 } 128 129 130 /** Adds an PcpParser to the storage. 131 */ 132 void FormatParserStorage::addPcp() 133 { 134 if (!ParserPresent[pcp]) { 135 ParserList[pcp] = new PcpParser(); 136 ParserPresent[pcp] = true; 137 } else 138 DoeLog(2) && (eLog() << Verbose(2) << "Parser pcp is already present." << endl 139 << "Note that you don't need to add '-o pcp' if the input file is of type pcp." << endl); 140 } 141 142 143 /** Adds an PdbParser to the storage. 144 */ 145 void FormatParserStorage::addPdb() 146 { 147 if (!ParserPresent[pdb]) { 148 ParserList[pdb] = new PdbParser(); 149 ParserPresent[pdb] = true; 150 } else 151 DoeLog(2) && (eLog() << Verbose(2) << "Parser pdb is already present." << endl 152 << "Note that you don't need to add '-o pdb' if the input file is of type pdb." << endl); 153 } 154 155 156 /** Adds an TremoloParser to the storage. 157 */ 158 void FormatParserStorage::addTremolo() 159 { 160 if (!ParserPresent[tremolo]) { 161 ParserList[tremolo] = new TremoloParser(); 162 ParserPresent[tremolo] = true; 163 } else 164 DoeLog(2) && (eLog() << Verbose(2) << "Parser tremolo is already present." << endl 165 << "Note that you don't need to add '-o tremolo' if the input file is of type tremolo." << endl); 166 } 167 168 169 /** Adds an XyzParser to the storage. 170 */ 171 void FormatParserStorage::addXyz() 172 { 173 if (!ParserPresent[xyz]) { 174 ParserList[xyz] = new XyzParser(); 175 ParserPresent[xyz] = true; 176 } else 177 DoeLog(2) && (eLog() << Verbose(2) << "Parser xyz is already present." << endl 178 << "Note that you don't need to add '-o xyz' if the input file is of type xyz." << endl); 179 } 180 154 181 ParserTypes FormatParserStorage::getTypeFromName(std::string type) 155 182 { … … 174 201 if (ptype != ParserTypes_end) { 175 202 if (ParserAddFunction.find(ptype) != ParserAddFunction.end()) { 176 LOG(0, "STATUS: Adding " << ParserNames[ptype] << " type to output.");203 DoLog(0) && (Log() << Verbose(0) << "Adding " << ParserNames[ptype] << " type to output." << endl); 177 204 (getInstance().*(ParserAddFunction[ptype]))(); // we still need an object to work on ... 178 205 return true; 179 206 } else { 180 ELOG(1, "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?");207 DoeLog(1) && (eLog() << Verbose(1) << "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?" << endl); 181 208 return false; 182 209 } … … 188 215 bool FormatParserStorage::add(std::string type) 189 216 { 190 enum ParserTypes Ptype = getTypeFromName(type); 191 return add(Ptype); 217 return add(getTypeFromName(type)); 192 218 } 193 219 … … 200 226 bool FormatParserStorage::load(std::istream &input, std::string suffix) 201 227 { 202 enum ParserTypes type = getTypeFromSuffix(suffix); 203 if (type != ParserTypes_end) 204 get(type).load(&input); 205 else 228 if (suffix == ParserSuffixes[mpqc]) { 229 getMpqc().load(&input); 230 } else if (suffix == ParserSuffixes[pcp]) { 231 getPcp().load(&input); 232 } else if (suffix == ParserSuffixes[pdb]) { 233 getPdb().load(&input); 234 } else if (suffix == ParserSuffixes[tremolo]) { 235 getTremolo().load(&input); 236 } else if (suffix == ParserSuffixes[xyz]) { 237 getXyz().load(&input); 238 } else { 239 DoeLog(1) && (eLog() << Verbose(1) << "Unknown suffix " << suffix << " to for FormatParserStorage::get()." << endl); 206 240 return false; 241 } 207 242 return true; 208 243 } … … 267 302 bool FormatParserStorage::save(std::ostream &output, std::string suffix, const std::vector<atom *> &atoms) 268 303 { 269 enum ParserTypes type = getTypeFromSuffix(suffix); 270 if (type != ParserTypes_end) 271 get(type).save(&output, atoms); 272 else 304 if (suffix == ParserSuffixes[mpqc]) { 305 getMpqc().save(&output, atoms); 306 } else if (suffix == ParserSuffixes[pcp]) { 307 getPcp().save(&output, atoms); 308 } else if (suffix == ParserSuffixes[pdb]) { 309 getPdb().save(&output, atoms); 310 } else if (suffix == ParserSuffixes[tremolo]) { 311 getTremolo().save(&output, atoms); 312 } else if (suffix == ParserSuffixes[xyz]) { 313 getXyz().save(&output, atoms); 314 } else { 315 DoeLog(1) && (eLog() << Verbose(1) << "Unknown suffix " << suffix << " to for FormatParserStorage::put()." << endl); 273 316 return false; 317 } 274 318 return true; 319 } 320 321 /** Returns reference to the output MpqcParser, adds if not present. 322 * \return reference to the output MpqcParser 323 */ 324 MpqcParser &FormatParserStorage::getMpqc() 325 { 326 if (!ParserPresent[mpqc]) 327 addMpqc(); 328 return dynamic_cast<MpqcParser &>(*ParserList[mpqc]); 329 } 330 331 /** Returns reference to the output PcpParser, adds if not present. 332 * \return reference to the output PcpParser 333 */ 334 PcpParser &FormatParserStorage::getPcp() 335 { 336 if (!ParserPresent[pcp]) 337 addPcp(); 338 return dynamic_cast<PcpParser &>(*ParserList[pcp]); 339 } 340 341 /** Returns reference to the output PdbParser, adds if not present. 342 * \return reference to the output PdbParser 343 */ 344 PdbParser &FormatParserStorage::getPdb() 345 { 346 if (!ParserPresent[pdb]) 347 addPdb(); 348 return dynamic_cast<PdbParser &>(*ParserList[pdb]); 349 } 350 351 /** Returns reference to the output TremoloParser, adds if not present. 352 * \return reference to the output TremoloParser 353 */ 354 TremoloParser &FormatParserStorage::getTremolo() 355 { 356 if (!ParserPresent[tremolo]) 357 addTremolo(); 358 return dynamic_cast<TremoloParser &>(*ParserList[tremolo]); 359 } 360 361 /** Returns reference to the output XyzParser, adds if not present. 362 * \return reference to the output XyzParser 363 */ 364 XyzParser &FormatParserStorage::getXyz() 365 { 366 if (!ParserPresent[xyz]) 367 addXyz(); 368 return dynamic_cast<XyzParser &>(*ParserList[xyz]); 275 369 } 276 370 … … 279 373 * \return reference to the output FormatParser with desired type 280 374 */ 281 FormatParser Interface&FormatParserStorage::get(ParserTypes _type)375 FormatParser &FormatParserStorage::get(ParserTypes _type) 282 376 { 283 377 if (!ParserPresent[_type]) { -
src/Parser/FormatParserStorage.hpp
r360c8b rfa9d1d 16 16 #include "CodePatterns/Singleton.hpp" 17 17 18 #include < iosfwd>18 #include <string> 19 19 #include <map> 20 #include <string>21 20 #include <vector> 22 21 23 #include "CodePatterns/Assert.hpp" 24 #include "CodePatterns/Log.hpp" 25 #include "FormatParser.hpp" 26 #include "ParserTypes.hpp" 22 #include "Parser/FormatParser.hpp" 23 #include "Parser/MpqcParser.hpp" 24 #include "Parser/PcpParser.hpp" 25 #include "Parser/PdbParser.hpp" 26 #include "Parser/TremoloParser.hpp" 27 #include "Parser/XyzParser.hpp" 27 28 28 29 class atom; 29 class FormatParserInterface; 30 31 // enum has to be outside of class for operator++ to be possible 32 enum ParserTypes { mpqc, pcp, pdb, tremolo, xyz, ParserTypes_end, ParserTypes_begin = mpqc }; 33 typedef enum ParserTypes ParserTypes; 34 35 ParserTypes &operator++(ParserTypes &type); 30 36 31 37 class FormatParserStorage : public Singleton<FormatParserStorage> { … … 33 39 public: 34 40 41 void addMpqc(); 42 void addPcp(); 43 void addPdb(); 44 void addTremolo(); 45 void addXyz(); 35 46 bool add(std::string type); 36 47 bool add(ParserTypes type); … … 41 52 bool saveSelectedMolecules(std::ostream &output, std::string suffix); 42 53 bool saveWorld(std::ostream &output, std::string suffix); 43 44 FormatParserInterface &get(ParserTypes _type); 54 MpqcParser &getMpqc(); 55 PcpParser &getPcp(); 56 PdbParser &getPdb(); 57 TremoloParser &getTremolo(); 58 XyzParser &getXyz(); 59 FormatParser &get(enum ParserTypes _type); 45 60 46 61 ParserTypes getTypeFromName(std::string type); … … 56 71 57 72 // list of allocated parsers 58 std::vector<FormatParser Interface*> ParserList;73 std::vector<FormatParser *> ParserList; 59 74 60 75 // list of allocated strams … … 75 90 std::map<std::string, ParserTypes> ParserLookupNames; 76 91 92 77 93 // prefix of the filenames to use on save 78 94 std::string prefix; 79 80 public:81 template<ParserTypes Ptype> void addParser()82 {83 if (!ParserPresent[Ptype]) {84 ParserList[Ptype] = new FormatParser<Ptype>();85 ParserPresent[Ptype] = true;86 } else {87 ASSERT(ParserNames.find(Ptype) != ParserNames.end(),88 "FormatParserStorage::addParser() - ParserNames unknown for type"+toString((size_t)Ptype)+".");89 ASSERT(ParserSuffixes.find(Ptype) != ParserSuffixes.end(),90 "FormatParserStorage::addParser() - ParserSuffixes unknown for type"+toString((size_t)Ptype)+".");91 LOG(2, "INFO: Parser " << ParserNames[Ptype] << " is already present." << std::endl92 << "Note that you don't need to add '-o "93 << ParserSuffixes[Ptype] << "' if the input file is non-empty and of type "94 << ParserSuffixes[Ptype] << "." << std::endl);95 }96 }97 98 template<ParserTypes Ptype> FormatParser<Ptype> &getParser()99 {100 if(!ParserPresent[Ptype])101 addParser< Ptype >();102 return dynamic_cast<FormatParser<Ptype> &>(*ParserList[Ptype]);103 }104 95 }; 105 96 -
src/Parser/FormatParser_Parameters.hpp
r360c8b rfa9d1d 14 14 #endif 15 15 16 #include <iosfwd>17 18 16 #include "CodePatterns/Clone.hpp" 19 20 #include "Parser/Parameters/ParameterStorage.hpp"21 22 class Parameter;23 17 24 18 /** This class is an interface to the internal parameters of any FormatParser. … … 29 23 class FormatParser_Parameters : public Clone<FormatParser_Parameters> 30 24 { 31 //!> allow operator access to storage for easier printing.32 friend std::ostream & operator << (std::ostream& ost, const FormatParser_Parameters ¶ms);33 25 public: 34 FormatParser_Parameters(); 35 FormatParser_Parameters(const FormatParser_Parameters &_parameters); 36 ~FormatParser_Parameters(); 26 FormatParser_Parameters() {} 27 ~FormatParser_Parameters() {} 37 28 38 // cloning 39 FormatParser_Parameters* clone() const; 40 void makeClone(const FormatParser_Parameters &_instance); 41 42 // accessing parameters in storage 43 void appendParameter(Parameter *instance); 44 bool haveParameter(const std::string &_name) const; 45 Parameter *getParameter(const std::string &_name) const; 46 47 protected: 48 ParameterStorage *storage; 29 /** Makes this instance a clone of given \a _instance. 30 * 31 * @param _instance instance to clone 32 */ 33 virtual void makeClone(const FormatParser_Parameters & _instance)=0; 49 34 }; 50 51 std::ostream & operator << (std::ostream& ost, const FormatParser_Parameters ¶ms);52 53 std::istream & operator >> (std::istream& ist, FormatParser_Parameters ¶ms);54 35 55 36 -
src/Parser/Makefile.am
r360c8b rfa9d1d 5 5 PARSERSOURCE = \ 6 6 Parser/ChangeTracker.cpp \ 7 Parser/FormatParser_common.cpp \ 8 Parser/FormatParser_Parameters.cpp \ 7 Parser/FormatParser.cpp \ 9 8 Parser/FormatParserStorage.cpp \ 10 9 Parser/MpqcParser.cpp \ 11 10 Parser/MpqcParser_Parameters.cpp \ 12 11 Parser/MpqcParser_Parameters_initBasis.cpp \ 13 Parser/ParserTypes.cpp \14 12 Parser/PcpParser.cpp \ 15 13 Parser/PdbAtomInfoContainer.cpp \ 16 14 Parser/PdbParser.cpp \ 17 Parser/Psi3Parser.cpp \18 Parser/Psi3Parser_Parameters.cpp \19 15 Parser/TremoloParser.cpp \ 20 16 Parser/TremoloAtomInfoContainer.cpp \ … … 24 20 Parser/ChangeTracker.hpp \ 25 21 Parser/FormatParser.hpp \ 26 Parser/FormatParser_specializations_header.hpp \27 Parser/FormatParser_common.hpp \28 Parser/FormatParserInterface.hpp \29 Parser/FormatParserTrait.hpp \30 Parser/FormatParserTrait_specializations_header.hpp \31 22 Parser/FormatParser_Parameters.hpp \ 32 23 Parser/FormatParserStorage.hpp \ 33 24 Parser/MpqcParser.hpp \ 34 25 Parser/MpqcParser_Parameters.hpp \ 35 Parser/ParserTypes.hpp \36 Parser/ParserTypes.def \37 Parser/ParserTypes.undef \38 26 Parser/PcpParser.hpp \ 39 27 Parser/PdbAtomInfoContainer.hpp \ 40 28 Parser/PdbKey.hpp \ 41 29 Parser/PdbParser.hpp \ 42 Parser/Psi3Parser.hpp \43 Parser/Psi3Parser_Parameters.hpp \44 30 Parser/TremoloKey.hpp \ 45 31 Parser/TremoloParser.hpp \ … … 47 33 Parser/XyzParser.hpp 48 34 49 PARSERPARAMETERSSOURCE = \50 Parser/Parameters/ParameterStorage.cpp \51 Parser/Parameters/StringParameter.cpp52 53 PARSERPARAMETERSHEADER = \54 Parser/Parameters/ParameterStorage.hpp \55 Parser/Parameters/ContinuousParameter.hpp \56 Parser/Parameters/ContinuousParameter_impl.hpp \57 Parser/Parameters/ContinuousValue.hpp \58 Parser/Parameters/ContinuousValue_impl.hpp \59 Parser/Parameters/DiscreteParameter.hpp \60 Parser/Parameters/DiscreteParameter_impl.hpp \61 Parser/Parameters/DiscreteValue.hpp \62 Parser/Parameters/DiscreteValue_impl.hpp \63 Parser/Parameters/Parameter.hpp \64 Parser/Parameters/StringParameter.hpp \65 Parser/Parameters/ValueInterface.hpp66 35 67 36 noinst_LTLIBRARIES += libMolecuilderParser.la 68 37 libMolecuilderParser_la_includedir = $(includedir)/MoleCuilder/Parser/ 69 38 70 nobase_libMolecuilderParser_la_include_HEADERS = ${PARSERHEADER} ${PARSERPARAMETERSHEADER}39 nobase_libMolecuilderParser_la_include_HEADERS = ${PARSERHEADER} 71 40 72 41 ## Define the source file list for the "libexample-@MOLECUILDER_API_VERSION@.la" … … 78 47 ## from each source file. Note that it is not necessary to list header files 79 48 ## which are already listed elsewhere in a _HEADERS variable assignment. 80 libMolecuilderParser_la_SOURCES = ${PARSERSOURCE} ${PARSERPARAMETERSSOURCE}49 libMolecuilderParser_la_SOURCES = ${PARSERSOURCE} 81 50 82 51 ## Instruct libtool to include ABI version information in the generated shared -
src/Parser/MpqcParser.cpp
r360c8b rfa9d1d 38 38 #include "World.hpp" 39 39 40 // declare specialized static variables41 const std::string FormatParserTrait<mpqc>::name = "mpqc";42 const std::string FormatParserTrait<mpqc>::suffix = "in";43 const ParserTypes FormatParserTrait<mpqc>::type = mpqc;44 45 // a converter we often need46 ConvertTo<bool> FormatParser<mpqc>::Converter;47 40 48 41 /** Constructor of MpqcParser. 49 42 * 50 43 */ 51 FormatParser< mpqc >::FormatParser() : 52 FormatParser_common(new MpqcParser_Parameters()) 53 {} 44 MpqcParser::MpqcParser() 45 { 46 parameters = new MpqcParser_Parameters(); 47 } 54 48 55 49 /** Destructor of MpqcParser. 56 50 * 57 51 */ 58 FormatParser< mpqc >::~FormatParser() 59 {} 52 MpqcParser::~MpqcParser() 53 { 54 delete parameters; 55 } 60 56 61 57 /** Load an MPQC config file into the World. 62 58 * \param *file input stream 63 59 */ 64 void FormatParser< mpqc >::load(istream *file)60 void MpqcParser::load(istream *file) 65 61 { 66 62 bool MpqcSection = false; … … 100 96 tokenizer::iterator tok_iter = tokens.begin(); 101 97 ASSERT(tok_iter != tokens.end(), 102 " FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");98 "MpqcParser::load() - missing token for MoleculeSection in line "+linestring+"!"); 103 99 std::stringstream whitespacefilter(*tok_iter++); 104 100 std::string element; 105 101 whitespacefilter >> ws >> element; 106 102 ASSERT(tok_iter != tokens.end(), 107 " FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");103 "MpqcParser::load() - missing token for MoleculeSection in line "+linestring+"!"); 108 104 std::string vector = *tok_iter; 109 105 tokenizer vectorcomponents(vector, whitesep); … … 129 125 ++tok_iter; 130 126 ASSERT(tok_iter != tokens.end(), 131 " FormatParser< mpqc >::load() - missing token in brackets<> for mole< in line "+linestring+"!");127 "MpqcParser::load() - missing token in brackets<> for mole< in line "+linestring+"!"); 132 128 std::string value(*tok_iter); 133 129 std::stringstream linestream("theory = "+value); … … 138 134 ++tok_iter; 139 135 ASSERT(tok_iter != tokens.end(), 140 " FormatParser< mpqc >::load() - missing token in brackets<> for integrals< in line "+linestring+"!");136 "MpqcParser::load() - missing token in brackets<> for integrals< in line "+linestring+"!"); 141 137 std::string value(*tok_iter); 142 138 std::stringstream linestream("integration = "+value); … … 147 143 tokenizer::iterator tok_iter = tokens.begin(); 148 144 ASSERT(tok_iter != tokens.end(), 149 " FormatParser< mpqc >::load() - missing token before '=' for MpqcSection in line "+linestring+"!");145 "MpqcParser::load() - missing token before '=' for MpqcSection in line "+linestring+"!"); 150 146 std::stringstream whitespacefilter(*tok_iter); 151 147 std::string key; 152 148 whitespacefilter >> ws >> key; 153 if (getParams().haveParam eter(key)) {149 if (getParams().haveParam(key)) { 154 150 std::stringstream linestream(linestring); 155 151 linestream >> getParams(); … … 163 159 tokenizer::iterator tok_iter = tokens.begin(); 164 160 ASSERT(tok_iter != tokens.end(), 165 " FormatParser< mpqc >::load() - missing token for BasisSection in line "+linestring+"!");161 "MpqcParser::load() - missing token for BasisSection in line "+linestring+"!"); 166 162 std::string key(*tok_iter++); 167 163 ASSERT(tok_iter != tokens.end(), 168 " FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");164 "MpqcParser::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!"); 169 165 std::string value(*tok_iter); 170 166 tok_iter++; 171 167 // TODO: use exception instead of ASSERT 172 168 ASSERT(tok_iter == tokens.end(), 173 " FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+".");169 "MpqcParser::load() - more than (key = value) on line "+linestring+"."); 174 170 if (key == "name") { 175 171 std::stringstream linestream("basis = "+value); … … 181 177 tokenizer::iterator tok_iter = tokens.begin(); 182 178 ASSERT(tok_iter != tokens.end(), 183 " FormatParser< mpqc >::load() - missing token for AuxBasisSection in line "+linestring+"!");179 "MpqcParser::load() - missing token for AuxBasisSection in line "+linestring+"!"); 184 180 std::string key(*tok_iter++); 185 181 ASSERT(tok_iter != tokens.end(), 186 " FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");182 "MpqcParser::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!"); 187 183 std::string value(*tok_iter); 188 184 tok_iter++; 189 185 // TODO: use exception instead of ASSERT 190 186 ASSERT(tok_iter == tokens.end(), 191 " FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+".");187 "MpqcParser::load() - more than (key = value) on line "+linestring+"."); 192 188 if (key == "name") { 193 189 std::stringstream linestream("aux_basis = "+value); … … 220 216 * \param atoms atoms to store 221 217 */ 222 void FormatParser< mpqc >::save(ostream *file, const std::vector<atom *> &atoms)218 void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms) 223 219 { 224 220 Vector center; … … 236 232 *file << "% Created by MoleCuilder" << endl; 237 233 *file << "mpqc: (" << endl; 238 *file << "\tsavestate = " << getParams().get Parameter(MpqcParser_Parameters::savestateParam) << endl;239 *file << "\tdo_gradient = " << getParams().get Parameter(MpqcParser_Parameters::do_gradientParam) << endl;240 if ( Converter(getParams().getParameter(MpqcParser_Parameters::hessianParam))) {234 *file << "\tsavestate = " << getParams().getString(MpqcParser_Parameters::savestateParam) << endl; 235 *file << "\tdo_gradient = " << getParams().getString(MpqcParser_Parameters::do_gradientParam) << endl; 236 if (getParams().getBool(MpqcParser_Parameters::hessianParam)) { 241 237 *file << "\tfreq<MolecularFrequencies>: (" << endl; 242 238 *file << "\t\tmolecule=$:molecule" << endl; 243 239 *file << "\t)" << endl; 244 240 } 245 const std::string theory = getParams().getParameter(MpqcParser_Parameters::theoryParam); 246 if (theory == getParams().getTheoryName(MpqcParser_Parameters::CLHF)) { 247 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 248 *file << "\t\tmolecule = $:molecule" << endl; 249 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl; 250 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam) 251 << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl; 252 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam) 253 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl; 254 *file << "\t)" << endl; 255 } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::CLKS)) { 256 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 257 *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl; 258 *file << "\t\tmolecule = $:molecule" << endl; 259 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl; 260 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam) 261 << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl; 262 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam) 263 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl; 264 *file << "\t)" << endl; 265 } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2)) { 266 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 267 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl; 268 *file << "\t\tmolecule = $:molecule" << endl; 269 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam) 270 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl; 271 *file << "\t\treference<CLHF>: (" << endl; 272 *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam) 273 << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl; 274 *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl; 275 *file << "\t\t\tmolecule = $:molecule" << endl; 276 *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam) 277 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl; 278 *file << "\t\t)" << endl; 279 *file << "\t)" << endl; 280 } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) { 281 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 282 *file << "\t\tmolecule = $:molecule" << endl; 283 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl; 284 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::aux_basisParam) << " = $:abasis" << endl; 285 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::stdapproxParam) 286 << " = \"" << getParams().getParameter(MpqcParser_Parameters::stdapproxParam) << "\"" << endl; 287 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::nfzcParam) 288 << " = " << getParams().getParameter(MpqcParser_Parameters::nfzcParam) << endl; 289 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam) 290 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl; 291 *file << "\t\tintegrals<IntegralCints>:()" << endl; 292 *file << "\t\treference<CLHF>: (" << endl; 293 *file << "\t\t\tmolecule = $:molecule" << endl; 294 *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl; 295 *file << "\t\t\tmaxiter = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam) << endl; 296 *file << "\t\t\tmemory = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl; 297 *file << "\t\t\tintegrals<" << getParams().getParameter(MpqcParser_Parameters::integrationParam) << ">:()" << endl; 298 *file << "\t\t)" << endl; 299 *file << "\t)" << endl; 300 } else { 301 DoeLog(0) && (eLog() << Verbose(0) 302 << "Unknown level of theory requested for MPQC output file." << std::endl); 241 switch (getParams().getTheory()) { 242 case MpqcParser_Parameters::CLHF: 243 *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 244 *file << "\t\tmolecule = $:molecule" << endl; 245 *file << "\t\tbasis = $:basis" << endl; 246 *file << "\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl; 247 *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl; 248 *file << "\t)" << endl; 249 break; 250 case MpqcParser_Parameters::CLKS: 251 *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 252 *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl; 253 *file << "\t\tmolecule = $:molecule" << endl; 254 *file << "\t\tbasis = $:basis" << endl; 255 *file << "\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl; 256 *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl; 257 *file << "\t)" << endl; 258 break; 259 case MpqcParser_Parameters::MBPT2: 260 *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 261 *file << "\t\tbasis = $:basis" << endl; 262 *file << "\t\tmolecule = $:molecule" << endl; 263 *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl; 264 *file << "\t\treference<CLHF>: (" << endl; 265 *file << "\t\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl; 266 *file << "\t\t\tbasis = $:basis" << endl; 267 *file << "\t\t\tmolecule = $:molecule" << endl; 268 *file << "\t\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl; 269 *file << "\t\t)" << endl; 270 *file << "\t)" << endl; 271 break; 272 case MpqcParser_Parameters::MBPT2_R12: 273 *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 274 *file << "\t\tmolecule = $:molecule" << endl; 275 *file << "\t\tbasis = $:basis" << endl; 276 *file << "\t\taux_basis = $:abasis" << endl; 277 *file << "\t\tstdapprox = \"" << getParams().getString(MpqcParser_Parameters::stdapproxParam) << "\"" << endl; 278 *file << "\t\tnfzc = " << toString(getParams().getInt(MpqcParser_Parameters::nfzcParam)) << endl; 279 *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl; 280 *file << "\t\tintegrals<IntegralCints>:()" << endl; 281 *file << "\t\treference<CLHF>: (" << endl; 282 *file << "\t\t\tmolecule = $:molecule" << endl; 283 *file << "\t\t\tbasis = $:basis" << endl; 284 *file << "\t\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam)) << endl; 285 *file << "\t\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl; 286 *file << "\t\t\tintegrals<" << getParams().getString(MpqcParser_Parameters::integrationParam) << ">:()" << endl; 287 *file << "\t\t)" << endl; 288 *file << "\t)" << endl; 289 break; 290 default: 291 DoeLog(0) && (eLog() << Verbose(0) 292 << "Unknown level of theory requested for MPQC output file." << std::endl); 293 break; 303 294 } 304 295 *file << ")" << endl; … … 313 304 *file << ")" << endl; 314 305 *file << "basis<GaussianBasisSet>: (" << endl; 315 *file << "\tname = \"" << getParams().get Parameter(MpqcParser_Parameters::basisParam) << "\"" << endl;306 *file << "\tname = \"" << getParams().getString(MpqcParser_Parameters::basisParam) << "\"" << endl; 316 307 *file << "\tmolecule = $:molecule" << endl; 317 308 *file << ")" << endl; 318 if ( theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) {309 if (getParams().getTheory() == MpqcParser_Parameters::MBPT2_R12) { 319 310 *file << "% auxiliary basis set specification" << endl; 320 311 *file << "\tabasis<GaussianBasisSet>: (" << endl; 321 *file << "\tname = \"" << getParams().get Parameter(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;312 *file << "\tname = \"" << getParams().getString(MpqcParser_Parameters::aux_basisParam) << "\"" << endl; 322 313 *file << "\tmolecule = $:molecule" << endl; 323 314 *file << ")" << endl; -
src/Parser/MpqcParser.hpp
r360c8b rfa9d1d 14 14 #endif 15 15 16 #include "CodePatterns/toString.hpp"17 16 18 17 #include "FormatParser.hpp" 19 #include "FormatParserTrait.hpp"20 #include "FormatParserInterface.hpp"21 #include "FormatParser_common.hpp"22 #include "ParserTypes.hpp"23 24 18 #include "MpqcParser_Parameters.hpp" 25 19 26 20 #include <iosfwd> 27 21 28 // declaration of specialized FormatParserTrait29 template<>30 struct FormatParserTrait<mpqc>31 {32 //!> Name of the parser33 static const std::string name;34 //!> suffix of the files the parser understands to read and write35 static const std::string suffix;36 //!> ParserTypes enumeration for the parser37 static const enum ParserTypes type;38 };39 40 22 /** 41 23 * Loads a MPQC config file into the World and saves the World as a tremolo file. 42 24 */ 43 template <> 44 class FormatParser< mpqc > : virtual public FormatParserInterface, public FormatParser_common 25 class MpqcParser : public FormatParser 45 26 { 46 27 friend class ParserMpqcUnitTest; 47 28 public: 48 FormatParser();49 virtual ~FormatParser();50 29 51 void load(std::istream *file); 52 void save(std::ostream *file, const std::vector<atom *> &atoms); 30 MpqcParser(); 31 virtual ~MpqcParser(); 32 void load(std::istream* file); 33 void save(std::ostream* file, const std::vector<atom *> &atoms); 53 34 54 35 /** Getter for parameter set. … … 57 38 */ 58 39 MpqcParser_Parameters & getParams() { return *static_cast<MpqcParser_Parameters *>(parameters); } 59 60 private:61 static ConvertTo<bool> Converter;62 40 }; 63 41 -
src/Parser/MpqcParser_Parameters.cpp
r360c8b rfa9d1d 18 18 #endif 19 19 20 #include <iostream> 21 #include <boost/tokenizer.hpp> 22 #include <string> 23 20 24 #include "CodePatterns/MemDebug.hpp" 21 25 22 #include <string>23 24 26 #include "CodePatterns/Log.hpp" 27 #include "CodePatterns/Verbose.hpp" 25 28 26 29 #include "MpqcParser.hpp" 30 27 31 #include "MpqcParser_Parameters.hpp" 28 32 29 #include "Parser/Parameters/ContinuousParameter.hpp" 30 #include "Parser/Parameters/DiscreteParameter.hpp" 31 #include "Parser/Parameters/StringParameter.hpp" 32 33 template <> 34 const std::string ContinuousValue<bool>::get() const 35 { 36 ASSERT(ValueSet, 37 "ContinuousValue<bool>::get() - requesting unset value."); 38 if (value) 39 return std::string("yes"); 40 else 41 return std::string("no"); 42 } 43 44 template <> 45 void ContinuousValue<bool>::set(const std::string _value) 46 { 47 if (_value == std::string("yes")) { 48 setValue(true); 49 } else if (_value == std::string("no")) { 50 setValue(false); 51 } else { 52 ASSERT(0, 53 "void ContinuousValue<bool>::set() - value "+_value+" is neither yes or no."); 54 } 55 } 56 33 34 using boost::any_cast; 57 35 58 36 MpqcParser_Parameters::MpqcParser_Parameters() … … 66 44 initBasis(); 67 45 68 // add all parameter names 46 // add all theory names 47 TheoryNames[CLHF]="CLHF"; 48 TheoryNames[CLKS]="CLKS"; 49 TheoryNames[MBPT2]="MBPT2"; 50 TheoryNames[MBPT2_R12]="MBPT2_R12"; 51 69 52 { 70 ParamNames.clear();71 ParamNames.resize(unknownParam);72 ParamNames[hessianParam] = "Hessian";73 ParamNames[savestateParam] = "savestate";74 ParamNames[do_gradientParam] = "do_gradient";75 ParamNames[maxiterParam] = "maxiter";76 ParamNames[memoryParam] = "memory";77 ParamNames[stdapproxParam] = "stdapprox";78 ParamNames[nfzcParam] = "nfzc";79 ParamNames[basisParam] = "basis";80 ParamNames[aux_basisParam] = "aux_basis";81 ParamNames[integrationParam] = "integration";82 ParamNames[theoryParam] = "theory";83 } 84 85 // create theory parameter53 // TODO: throw exception instead of eLog() 54 std::pair<TheoryLookupType::iterator, bool> inserter; 55 for (TheoryNamesType::iterator iter = TheoryNames.begin(); 56 iter != TheoryNames.end(); 57 ++iter) { 58 inserter = TheoryLookup.insert( make_pair(iter->second, iter->first) ); 59 if (!inserter.second) 60 DoeLog(0) && (eLog() << Verbose(0) 61 << "MpqcParser_Parameters::MpqcParser_Parameters() - Theory name already present: " 62 << (inserter.first)->second << " and " << iter->first << "!" 63 << std::endl); 64 } 65 } 66 67 // add all integration names 68 IntegrationNames[IntegralCints] = "IntegralCints"; 86 69 { 87 ValidTheories.clear(); 88 ValidTheories.resize(unknownTheory); 89 ValidTheories[CLHF]="CLHF"; 90 ValidTheories[CLKS]="CLKS"; 91 ValidTheories[MBPT2]="MBPT2"; 92 ValidTheories[MBPT2_R12]="MBPT2_R12"; 93 appendParameter( 94 new DiscreteParameter<std::string>( 95 ParamNames[theoryParam], 96 ValidTheories, 97 ValidTheories[MBPT2])); 98 } 99 //InvertMap<TheoryNamesType,TheoryLookupType>(TheoryNames,TheoryLookup); 100 101 // create integration parameter 70 // TODO: throw exception instead of eLog() 71 std::pair<IntegrationLookupType::iterator, bool> inserter; 72 for (IntegrationNamesType::iterator iter = IntegrationNames.begin(); 73 iter != IntegrationNames.end(); 74 ++iter) { 75 inserter = IntegrationLookup.insert( make_pair(iter->second, iter->first) ); 76 if (!inserter.second) 77 DoeLog(0) && (eLog() << Verbose(0) 78 << "MpqcParser_Parameters::MpqcParser_Parameters() - Integration name already present: " 79 << (inserter.first)->second << " and " << iter->first << "!" 80 << std::endl); 81 } 82 } 83 84 // have names for all parmaters 85 ParamNames[hessianParam] = "Hessian"; 86 ParamNames[savestateParam] = "savestate"; 87 ParamNames[do_gradientParam] = "do_gradient"; 88 ParamNames[maxiterParam] = "maxiter"; 89 ParamNames[memoryParam] = "memory"; 90 ParamNames[stdapproxParam] = "stdapprox"; 91 ParamNames[nfzcParam] = "nfzc"; 92 ParamNames[basisParam] = "basis"; 93 ParamNames[aux_basisParam] = "aux_basis"; 94 ParamNames[integrationParam] = "integration"; 95 ParamNames[theoryParam] = "theory"; 96 102 97 { 103 ValidIntegrationMethods.clear(); 104 ValidIntegrationMethods.resize(unknownIntegration); 105 ValidIntegrationMethods[IntegralCints] = "IntegralCints"; 106 appendParameter( 107 new DiscreteParameter<std::string>( 108 ParamNames[integrationParam], 109 ValidIntegrationMethods, 110 ValidIntegrationMethods[IntegralCints])); 111 } 112 113 // add all continuous parameters 114 { 115 appendParameter(new ContinuousParameter<bool>(ParamNames[hessianParam], false)); 116 appendParameter(new ContinuousParameter<bool>(ParamNames[savestateParam], false)); 117 appendParameter(new ContinuousParameter<bool>(ParamNames[do_gradientParam], true)); 118 appendParameter(new ContinuousParameter<int>(ParamNames[maxiterParam], 1000)); 119 appendParameter(new ContinuousParameter<int>(ParamNames[memoryParam], 16000000)); 120 appendParameter(new StringParameter(ParamNames[stdapproxParam], "A'")); 121 appendParameter(new ContinuousParameter<int>(ParamNames[nfzcParam], 1)); 122 appendParameter(new StringParameter(ParamNames[basisParam], "3-21G")); 123 appendParameter(new StringParameter(ParamNames[aux_basisParam], "aug-cc-pVDZ")); 124 } 98 // TODO: throw exception instead of eLog() 99 std::pair<ParamLookupType::iterator, bool> inserter; 100 for (ParamNamesType::iterator iter = ParamNames.begin(); 101 iter != ParamNames.end(); 102 ++iter) { 103 inserter = ParamLookup.insert( make_pair(iter->second, iter->first) ); 104 if (!inserter.second) 105 DoeLog(0) && (eLog() << Verbose(0) 106 << "MpqcParser_Parameters::MpqcParser_Parameters() - parameter name already present: " 107 << (inserter.first)->second << " and " << iter->first << "!" 108 << std::endl); 109 } 110 } 111 112 initParameters(); 113 } 114 115 MpqcParser_Parameters::MpqcParser_Parameters(const MpqcParser_Parameters & state) 116 { 117 // init 118 Init(); 119 120 // copy values 121 copyParameters(state); 122 } 123 124 void MpqcParser_Parameters::copyParameters(const MpqcParser_Parameters & state) 125 { 126 appendParameter(hessianParam, state.getBool(hessianParam)); 127 appendParameter(savestateParam, state.getBool(savestateParam)); 128 appendParameter(do_gradientParam, state.getBool(do_gradientParam)); 129 appendParameter(maxiterParam, state.getInt(maxiterParam)); 130 appendParameter(memoryParam, state.getInt(memoryParam)); 131 appendParameter(stdapproxParam, state.getString(stdapproxParam)); 132 appendParameter(nfzcParam, state.getInt(nfzcParam)); 133 appendParameter(basisParam, state.getString(basisParam)); 134 appendParameter(aux_basisParam, state.getString(aux_basisParam)); 135 appendParameter(integrationParam, state.getIntegration()); 136 appendParameter(theoryParam, state.getTheory()); 137 } 138 139 FormatParser_Parameters* MpqcParser_Parameters::clone() const 140 { 141 //LOG(3, "Cloning parameters."); 142 MpqcParser_Parameters *instance = new MpqcParser_Parameters(*this); 143 return instance; 144 } 145 146 void MpqcParser_Parameters::makeClone(const FormatParser_Parameters & _state) 147 { 148 //LOG(3, "Cloning parameters from other instance."); 149 copyParameters(static_cast<const MpqcParser_Parameters &>(_state)); 150 } 151 152 void MpqcParser_Parameters::initParameters() 153 { 154 appendParameter(hessianParam, bool(false)); 155 appendParameter(savestateParam, bool(false)); 156 appendParameter(do_gradientParam, bool(true)); 157 appendParameter(maxiterParam, int(1000)); 158 appendParameter(memoryParam, int(16000000)); 159 appendParameter(stdapproxParam, std::string("A'")); 160 appendParameter(nfzcParam, int(1)); 161 appendParameter(basisParam, std::string("3-21G")); 162 appendParameter(aux_basisParam, std::string("aug-cc-pVDZ")); 163 appendParameter(integrationParam, IntegralCints); 164 appendParameter(theoryParam, MBPT2); 125 165 } 126 166 … … 128 168 {} 129 169 130 /** Getter for a specific Parameter. 170 std::ostream & operator << (std::ostream& ost, MpqcParser_Parameters const &_mpqc_params) 171 { 172 // this is ugly, but with boost::any to safeguard const-ness is plain impossible 173 MpqcParser_Parameters &mpqc_params = const_cast<MpqcParser_Parameters &>(_mpqc_params); 174 std::ostringstream output; 175 output << "Hessian=" << mpqc_params.getBool(MpqcParser_Parameters::hessianParam) << ";"; 176 output << "savestate=" << mpqc_params.getBool(MpqcParser_Parameters::savestateParam) << ";"; 177 output << "do_gradient=" << mpqc_params.getBool(MpqcParser_Parameters::do_gradientParam) << ";"; 178 output << "maxiter=" << mpqc_params.getInt(MpqcParser_Parameters::maxiterParam) << ";"; 179 output << "memory=" << mpqc_params.getInt(MpqcParser_Parameters::memoryParam) << ";"; 180 output << "stdapprox=" << mpqc_params.getString(MpqcParser_Parameters::stdapproxParam) << ";"; 181 output << "nfzc=" << mpqc_params.getInt(MpqcParser_Parameters::nfzcParam) << ";"; 182 output << "basis=" << mpqc_params.getString(MpqcParser_Parameters::basisParam) << ";"; 183 output << "aux_basis=" << mpqc_params.getString(MpqcParser_Parameters::aux_basisParam) << ";"; 184 output << "integration=" << mpqc_params.getString(MpqcParser_Parameters::integrationParam) << ";"; 185 output << "theory=" << mpqc_params.getString(MpqcParser_Parameters::theoryParam) << ";"; 186 ost << output.str(); 187 return ost; 188 } 189 190 std::istream & operator >> (std::istream& ist, MpqcParser_Parameters ¶ms) 191 { 192 typedef boost::tokenizer<boost::char_separator<char> > 193 tokenizer; 194 boost::char_separator<char> semicolonsep(";"); 195 boost::char_separator<char> equalitysep(" ="); 196 boost::char_separator<char> ticksep("\""); 197 std::string line; 198 std::getline( ist, line ); 199 //DoLog(0) && (Log() << Verbose(0) << "INFO: full line of parameters is '" << line << "'" << std::endl); 200 tokenizer tokens(line, semicolonsep); 201 ASSERT(tokens.begin() != tokens.end(), 202 "operator<< on MpqcParser_Parameters - empty string, need at least ';' in line "+line+"!"); 203 for (tokenizer::iterator tok_iter = tokens.begin(); 204 tok_iter != tokens.end(); ++tok_iter) { 205 tokenizer paramtokens(*tok_iter, equalitysep); 206 if (paramtokens.begin() != paramtokens.end()) { 207 tokenizer::iterator tok_paramiter = paramtokens.begin(); 208 tokenizer::iterator tok_valueiter = tok_paramiter; 209 tokenizer::iterator tok_checkiter = ++tok_valueiter; 210 ++tok_checkiter; 211 // TODO: throw exception instead of ASSERT 212 ASSERT(tok_paramiter != paramtokens.end(), 213 "operator<< on MpqcParser_Parameters - missing value before ' =' in token "+*tok_iter+"!"); 214 ASSERT(tok_valueiter != paramtokens.end(), 215 "operator<< on MpqcParser_Parameters - missing value after ' =' in token "+*tok_iter+"!"); 216 ASSERT(tok_checkiter == paramtokens.end(), 217 "operator<< on MpqcParser_Parameters - still more tokens after ' =' in token "+*tok_iter+":" 218 +*tok_checkiter+"!"); 219 std::stringstream keystream(*tok_paramiter); 220 std::string key; 221 keystream >> ws >> key; 222 tokenizer ticklesstokens(*tok_valueiter, ticksep); 223 ASSERT(ticklesstokens.begin() != ticklesstokens.end(), 224 "operator<< on MpqcParser_Parameters - no tokens present after removing ticks in token "+*tok_valueiter+"!"); 225 std::stringstream valuestream(*(ticklesstokens.begin())); 226 DoLog(2) && (Log() << Verbose(2) 227 << "INFO: Token pair is " << key << "," << valuestream.str() << std::endl); 228 229 // TODO: throw exception instead of DoeLog() 230 ASSERT(params.haveParam(key), 231 "operator >> on MpqcParser_Parameters - unknown parameter name '" 232 +key+"' with value "+valuestream.str()+"!"); 233 if (params.haveParam(key)) 234 params.setter(params.getParam(key), valuestream); 235 } else { 236 ist.setstate(std::ios::eofbit); 237 } 238 } 239 return ist; 240 } 241 242 243 /** Sets a desired value in the params from a string. 131 244 * 132 * @param param index among enum Parameters 133 * @return value of the desired Parameters 245 * This is due to strict typing of C++ very ugly and boost::any does not make 246 * it any better because it offers to functions to use values directly from 247 * stringstream. Probably, because value is unknown to is as well and hence 248 * the author could not implement it beautifully, so he dropped it altogether. 249 * Grrr .... 250 * 251 * @param _param param to set 252 * @param _desired stringstream containing value as next argument 253 * @return true - type ok, false - unknown type in params. 134 254 */ 135 const std::string MpqcParser_Parameters::getParameter(const enum Parameters param) const 136 { 137 return FormatParser_Parameters::getParameter(ParamNames[param])->get(); 138 } 139 140 /** Setter for a specific Parameter. 141 * 142 * @param param index among enum Parameters 143 * @param _value value to set desired Parameter to 144 */ 145 void MpqcParser_Parameters::setParameter(const enum Parameters param, const std::string &_value) 146 { 147 const std::string &name = getParameterName(param); 148 FormatParser_Parameters::getParameter(name)->set(_value); 149 } 150 151 /** Getter for name of a specific Parameter. 152 * 153 * @param param index among enum Parameters 154 * @return name of the desired Parameter 155 */ 156 const std::string &MpqcParser_Parameters::getParameterName(const enum Parameters param) const 157 { 158 return ParamNames[param]; 159 } 160 161 /** Getter for name of a specific Parameter. 162 * 163 * @param param index among enum Theory 164 * @return name of the desired Theory 165 */ 166 const std::string &MpqcParser_Parameters::getTheoryName(const enum Theory theory) const 167 { 168 return ValidTheories[theory]; 169 } 170 171 /** Getter for the name of specific of IntegrationMethod. 172 * 173 * @param param index among enum IntegrationMethod 174 * @return value of the desired IntegrationMethod 175 */ 176 const std::string &MpqcParser_Parameters::getIntegrationMethodName(const enum IntegrationMethod integration) const 177 { 178 return ValidIntegrationMethods[integration]; 179 } 255 bool MpqcParser_Parameters::setter(enum Parameters _param, std::stringstream& _desired) { 256 if (_param == integrationParam) { 257 std::string tmp; 258 _desired >> tmp; 259 params[_param] = IntegrationLookup[tmp]; 260 } else if(_param == theoryParam) { 261 std::string tmp; 262 _desired >> tmp; 263 params[_param] = TheoryLookup[tmp]; 264 } else if (params[_param].type() == typeid(std::string)) { 265 std::string tmp; 266 _desired >> tmp; 267 params[_param] = tmp; 268 } else if (params[_param].type() == typeid(int)) { 269 int tmp; 270 _desired >> tmp; 271 params[_param] = tmp; 272 } else if (params[_param].type() == typeid(double)) { 273 double tmp; 274 _desired >> tmp; 275 params[_param] = tmp; 276 } else if (params[_param].type() == typeid(bool)) { 277 std::string tmp; 278 _desired >> tmp; 279 if ((tmp == "yes") || (tmp == "1")) { 280 params[_param] = bool(true); 281 } else if ((tmp == "no") || (tmp == "0")) { 282 params[_param] = bool(false); 283 } else { 284 DoeLog(0) && (eLog() << Verbose(0) 285 << "MpqcParser_Parameters::setter() - unknown boolean key " 286 << tmp << "!" << std::endl); 287 } 288 } else { 289 DoeLog(0) && (eLog() << Verbose(0) 290 << "MpqcParser_Parameters::setter() - unknown type!" << std::endl); 291 return false; 292 } 293 return true; 294 } 295 296 297 void MpqcParser_Parameters::setTheory(enum Theory _theory) 298 { 299 // TODO: throw exception instead of eLog() 300 // try { 301 params[theoryParam] = _theory; 302 // } catch(const boost::bad_any_cast &) { 303 // DoeLog(0) && (eLog() << Verbose(0) 304 // << "MpqcParser_Parameters::setTheory() - could not set boolean!" << std::endl); 305 // } 306 } 307 308 void MpqcParser_Parameters::setIntegration(enum MpqcParser_Parameters::IntegrationMethod _integration){ 309 // TODO: throw exception instead of eLog() 310 // try { 311 params[integrationParam] = _integration; 312 // } catch(const boost::bad_any_cast &) { 313 // DoeLog(0) && (eLog() << Verbose(0) 314 // << "MpqcParser_Parameters::setIntegration() - could not set boolean!" << std::endl); 315 // } 316 } 317 318 bool MpqcParser_Parameters::haveParam(std::string _name) const 319 { 320 return ParamLookup.count(_name) != 0; 321 } 322 323 enum MpqcParser_Parameters::Parameters MpqcParser_Parameters::getParam(std::string _name) const 324 { 325 ParamLookupType::const_iterator iter = ParamLookup.find(_name); 326 return iter->second; 327 } 328 329 enum MpqcParser_Parameters::IntegrationMethod MpqcParser_Parameters::getIntegration() const 330 { 331 parameterlist::const_iterator iter = params.find(integrationParam); 332 enum IntegrationMethod value; 333 // TODO: throw exception instead of eLog() 334 // try { 335 value = boost::any_cast<enum IntegrationMethod>(iter->second); 336 // } catch(const boost::bad_any_cast &) { 337 // DoeLog(0) && (eLog() << Verbose(0) 338 // << "MpqcParser_Parameters::getIntegration() - could not convert " 339 // +ParamNames[integrationParam]+" to enum IntegrationMethod!" << std::endl); 340 // } 341 return value; 342 } 343 344 enum MpqcParser_Parameters::Theory MpqcParser_Parameters::getTheory() const 345 { 346 parameterlist::const_iterator iter = params.find(theoryParam); 347 enum Theory value; 348 // TODO: throw exception instead of eLog() 349 // try { 350 value = boost::any_cast<enum Theory>(iter->second); 351 // } catch(const boost::bad_any_cast &) { 352 // DoeLog(0) && (eLog() << Verbose(0) 353 // << "MpqcParser_Parameters::getTheory() - could not convert " 354 // +ParamNames[theoryParam]+" to enum Theory!" << std::endl); 355 // } 356 return value; 357 } 358 359 std::string MpqcParser_Parameters::getString(enum Parameters _param) const 360 { 361 std::string value; 362 enum IntegrationMethod Iindex; 363 enum Theory Tindex; 364 bool test; 365 parameterlist::const_iterator iter = params.find(_param); 366 switch (_param) { 367 case hessianParam: 368 case savestateParam: 369 case do_gradientParam: 370 test = boost::any_cast<bool>(iter->second); 371 if (test) 372 value = "yes"; 373 else 374 value = "no"; 375 break; 376 case integrationParam: 377 // TODO: throw exception instead of eLog() 378 // try { 379 Iindex = boost::any_cast<enum IntegrationMethod>(iter->second); 380 // } catch(const boost::bad_any_cast &) { 381 // DoeLog(0) && (eLog() << Verbose(0) 382 // << "MpqcParser_Parameters::getString() - could not convert " 383 // +ParamNames[_param]+" to string!" << std::endl); 384 // } 385 { 386 IntegrationNamesType::const_iterator Iiter = IntegrationNames.find(Iindex); 387 value = Iiter->second; 388 } 389 break; 390 case theoryParam: 391 // TODO: throw exception instead of eLog() 392 // try { 393 Tindex = boost::any_cast<enum Theory>(iter->second); 394 // } catch(const boost::bad_any_cast &) { 395 // DoeLog(0) && (eLog() << Verbose(0) 396 // << "MpqcParser_Parameters::getString() - could not convert " 397 // +ParamNames[_param]+" to string!" << std::endl); 398 // } 399 { 400 TheoryNamesType::const_iterator Titer = TheoryNames.find(Tindex); 401 value = Titer->second; 402 } 403 break; 404 default: 405 // TODO: throw exception instead of eLog() 406 // try { 407 value = boost::any_cast<std::string>(iter->second); 408 // } catch(const boost::bad_any_cast &) { 409 // DoeLog(0) && (eLog() << Verbose(0) 410 // << "MpqcParser_Parameters::getString() - could not convert " 411 // +ParamNames[_param]+" to string!" << std::endl); 412 // } 413 break; 414 } 415 416 return value; 417 } 418 419 int MpqcParser_Parameters::getInt(enum Parameters _param) const 420 { 421 int value; 422 parameterlist::const_iterator iter = params.find(_param); 423 switch (_param) { 424 default: 425 // TODO: throw exception instead of eLog() 426 // try { 427 value = boost::any_cast<int>(iter->second); 428 // } catch(const boost::bad_any_cast &) { 429 // DoeLog(0) && (eLog() << Verbose(0) 430 // << "MpqcParser_Parameters::getInt() - could not convert " 431 // +ParamNames[_param]+" to int!" << std::endl); 432 // } 433 break; 434 } 435 return value; 436 } 437 438 double MpqcParser_Parameters::getDouble(enum Parameters _param) const 439 { 440 double value; 441 parameterlist::const_iterator iter = params.find(_param); 442 // TODO: throw exception instead of eLog() 443 // try { 444 value = boost::any_cast<double>(iter->second); 445 // } catch(const boost::bad_any_cast &) { 446 // DoeLog(0) && (eLog() << Verbose(0) 447 // << "MpqcParser_Parameters::getDouble() - could not convert " 448 // +ParamNames[_param]+" to double!" << std::endl); 449 // } 450 return value; 451 } 452 453 bool MpqcParser_Parameters::getBool(enum Parameters _param) const 454 { 455 bool value; 456 parameterlist::const_iterator iter = params.find(_param); 457 // TODO: throw exception instead of eLog() 458 // try { 459 value = boost::any_cast<bool>(iter->second); 460 // } catch(const boost::bad_any_cast &) { 461 // DoeLog(0) && (eLog() << Verbose(0) 462 // << "MpqcParser_Parameters::getBool() - could not convert " 463 // +ParamNames[_param]+" to bool!" << std::endl); 464 // } 465 return value; 466 } 467 180 468 181 469 /** Checks whether all elements in the world also have parameters in the basis. -
src/Parser/MpqcParser_Parameters.hpp
r360c8b rfa9d1d 14 14 #endif 15 15 16 #include <iosfwd> 16 17 #include <list> 17 #include < map>18 #include <typeinfo> 18 19 #include <vector> 19 20 20 21 #include "CodePatterns/Clone.hpp" 21 22 #include "CodePatterns/Log.hpp" 23 #include "CodePatterns/Verbose.hpp" 24 25 #include <boost/any.hpp> 22 26 23 27 #include "Parser/FormatParser_Parameters.hpp" 24 25 #include "Parser/Parameters/ContinuousParameter.hpp"26 27 // specialization for bool (we want "yes/no" not "1/0")28 template <> const std::string ContinuousValue<bool>::get() const;29 template <> void ContinuousValue<bool>::set(const std::string _value);30 28 31 29 class MpqcParser; … … 44 42 MpqcParser_Parameters(); 45 43 44 /** Copy Constructor of MpqcParser_Parameters. 45 * 46 * @param state ref to instance to copy 47 */ 48 MpqcParser_Parameters(const MpqcParser_Parameters & state); 49 46 50 /** Destructor of MpqcParser_Parameters. 47 51 * 48 52 */ 49 53 virtual ~MpqcParser_Parameters(); 54 55 /** Enumeration of all known theories. 56 * 57 */ 58 enum Theory { 59 CLHF, //!< Closed Shell Hartree-Fock equations 60 CLKS, //!< Closed Shell Kohn-Sham equations 61 MBPT2, //!< Moeller Plesset Perturbation Theory second order 62 MBPT2_R12, //!< Moeller Plesset Perturbation Theory second order with R12 integral 63 unknownTheory //!< designates an unknown theory 64 }; 65 66 /** Enumeration of all known integration methods 67 * 68 */ 69 enum IntegrationMethod { 70 IntegralCints, //!< Integration method Cints in MBPT2 R12? 71 unknownIntegration //!< designates unknown integration method 72 }; 50 73 51 74 /** Enumeration of all known Parameters to allow placing them in vectors, maps. … … 66 89 unknownParam}; //!< unknownParam, designates an unknown parameter 67 90 68 /** Enumeration of all known theories. 69 * 70 */ 71 enum Theory { 72 CLHF, //!< Closed Shell Hartree-Fock equations 73 CLKS, //!< Closed Shell Kohn-Sham equations 74 MBPT2, //!< Moeller Plesset Perturbation Theory second order 75 MBPT2_R12, //!< Moeller Plesset Perturbation Theory second order with R12 integral 76 unknownTheory //!< designates an unknown theory 77 }; 78 79 /** Enumeration of all known integration methods 80 * 81 */ 82 enum IntegrationMethod { 83 IntegralCints, //!< Integration method Cints in MBPT2 R12? 84 unknownIntegration //!< designates unknown integration method 85 }; 86 87 // enum to string getters 88 const std::string getParameter(const enum Parameters param) const; 89 void setParameter(const enum Parameters param, const std::string &); 90 const std::string &getParameterName(const enum Parameters param) const; 91 const std::string &getTheoryName(const enum Theory theory) const; 92 const std::string &getIntegrationMethodName(const enum IntegrationMethod integration) const; 91 bool checkWorldElementsAgainstCurrentBasis() const; 92 93 /** Sets the desired level of solving theory to use. 94 * 95 * \param _theory shorthand of the theory 96 */ 97 void setTheory(enum Theory _theory); 98 99 /** Sets the desired level of solving integration to use. 100 * 101 * \param _integration shorthand of the integration 102 */ 103 void setIntegration(enum IntegrationMethod _integration); 104 105 /** Getter for integration method in params. 106 * 107 * @return enumeration index of IntegrationMethod. 108 */ 109 enum IntegrationMethod getIntegration() const; 110 111 /** Getter for current Theory in params. 112 * 113 * @return enumeration index of Theory 114 */ 115 enum Theory getTheory() const; 116 117 /** Getter for a parameter in params as a string. 118 * 119 * @param _param enumeration index of desired Parameter 120 * @return string value 121 */ 122 std::string getString(enum Parameters _param) const; 123 124 /** Getter for integer value of desired Parameter in params. 125 * 126 * Only if type in params matches int! 127 * 128 * @param _param enumeration index in Parameter 129 * @return integer value of parameter 130 */ 131 int getInt(enum Parameters _param) const; 132 133 /** Getter for double value of desired Parameter in params. 134 * 135 * Only if type in params matches double! 136 * 137 * @param _param enumeration index in Parameter 138 * @return double value of parameter 139 */ 140 double getDouble(enum Parameters _param) const; 141 142 /** Getter for bool value of desired Parameter in params. 143 * 144 * Only if type in params matches bool! 145 * 146 * @param _param enumeration index in Parameter 147 * @return bool value of parameter 148 */ 149 bool getBool(enum Parameters _param) const; 150 151 /** Setter for a desired value of its type is known. 152 * 153 * We check whether given type matches present type in params. 154 * 155 * @param _param enumeration index of Parameter 156 * @param _desired desired value to set to 157 * @return true - type match, value set, false - type mismatch 158 */ 159 template <class T> bool setter(enum Parameters _param, T _desired) { 160 if (typeid(T) == params[_param].type()) { 161 params[_param] = _desired; 162 return true; 163 } else 164 return false; 165 } 166 167 /** Sets a desired value in the params from a string. 168 * 169 * This is due to strict typing of C++ very ugly and boost::any does not make 170 * it any better because it offers to functions to use values directly from 171 * stringstream. Probably, because value is unknown to is as well and hence 172 * the author could not implement it beautifully, so he dropped it altogether. 173 * Grrr .... 174 * 175 * @param _param param to set 176 * @param _desired stringstream containing value as next argument 177 * @return true - type ok, false - unknown type in params. 178 */ 179 bool setter(enum Parameters _param, std::stringstream& _desired); 180 181 /** Grants access to ParamLookup. 182 * 183 * Does not check for unknown parameter. 184 * 185 * @param _name name of parameter 186 * @return enumeration index of Parameters 187 */ 188 enum Parameters getParam(std::string _name) const; 189 190 /** Checker whether parameter with name is known. 191 * 192 * @param _name 193 * @return true - parameter known, false - parameter unknown 194 */ 195 bool haveParam(std::string _name) const; 196 197 /** Creates a clone of the class. 198 * 199 * @return 200 */ 201 FormatParser_Parameters* clone() const; 202 203 /** Applies a before returned undo state. 204 * 205 * @param undo state to set 206 */ 207 void makeClone(const FormatParser_Parameters & _state); 208 209 /** Set the internal parameters to the one's from the given \a state. 210 * 211 * @param state set of parameters 212 */ 213 void copyParameters(const MpqcParser_Parameters & state); 93 214 94 215 private: 95 96 97 //!> vector with all available theories in same order as enum Theory.98 std::vector<std::string> ValidTheories;99 100 //!> vector with all available integration methods in same order as enum IntegrationMethod.101 std::vector<std::string> ValidIntegrationMethods;102 103 bool checkWorldElementsAgainstCurrentBasis() const;104 105 216 /** Global initialization in cstor. 106 217 * … … 113 224 void initBasis(); 114 225 115 //!> vector with all parameter names in same order as enum Parameters 116 std::vector<std::string> ParamNames; 117 118 //!> typedef for the list of all available basis sets 226 /** Initializes params. 227 * Sets the type and the associated enumeration index. 228 */ 229 void initParameters(); 230 231 /** Internal function used by initParameters() to add parameters to params. 232 * 233 * @param _enum enumeration index to set 234 * @param _p (default) value to set with certain type 235 */ 236 template <class T> void appendParameter(enum Parameters _enum, T _p) { 237 boost::any _p_value = _p; 238 params[_enum] = _p_value; 239 } 240 241 // all internal typedefs for lists below 119 242 typedef std::map<std::string, std::list<std::string> > BasisMapType; 120 121 //!> list of all basis along with their present element parametrization 243 typedef std::map<enum Theory, std::string> TheoryNamesType; 244 typedef std::map<std::string, enum Theory> TheoryLookupType; 245 typedef std::map<enum IntegrationMethod, std::string> IntegrationNamesType; 246 typedef std::map<std::string, enum IntegrationMethod> IntegrationLookupType; 247 typedef std::map<enum Parameters, std::string> ParamNamesType; 248 typedef std::map<std::string, enum Parameters> ParamLookupType; 249 typedef std::map<enum Parameters, boost::any> parameterlist; 250 251 //!> boost::any container for all the parameters 252 parameterlist params; 253 254 // maps from names to enumerations 255 256 //!> contains basis and all elements the basis knows about 122 257 BasisMapType BasisList; 258 //!> contains the name of a theory as string 259 TheoryNamesType TheoryNames; 260 //!> contains a lookup from theory name to enumeration index 261 TheoryLookupType TheoryLookup; 262 //!> contains the name of an integration method as string 263 IntegrationNamesType IntegrationNames; 264 //!> contains a lookup from integration method name to enumeration index 265 IntegrationLookupType IntegrationLookup; 266 //!> contains the name of a parameter 267 ParamNamesType ParamNames; 268 //!> contains a lookup from parameter name to enumeration index 269 ParamLookupType ParamLookup; 123 270 }; 124 271 272 /** Output operator for the contents of MpqcParser_Parameters::params. 273 * 274 * @param ost output stream 275 * @param params reference to MpqcParser_Parameters containing params. 276 * @return reference to output stream for concatenation 277 */ 278 std::ostream & operator << (std::ostream& ost, const MpqcParser_Parameters ¶ms); 279 280 /** Input operator for a list of parameters to place into \a params. 281 * 282 * @param ist input stream 283 * @param params parameters to parse into 284 * @return input stream for concatenation 285 */ 286 std::istream & operator >> (std::istream& ist, MpqcParser_Parameters ¶ms); 287 125 288 #endif /* MPQCPARSER_PARAMETERS_HPP_ */ -
src/Parser/PcpParser.cpp
r360c8b rfa9d1d 40 40 41 41 42 // declare specialized static variables 43 const std::string FormatParserTrait<pcp>::name = "pcp"; 44 const std::string FormatParserTrait<pcp>::suffix = "conf"; 45 const ParserTypes FormatParserTrait<pcp>::type = pcp; 46 47 FormatParser< pcp >::StructParallelization::StructParallelization() : 42 PcpParser::StructParallelization::StructParallelization() : 48 43 ProcPEGamma(8), 49 44 ProcPEPsi(1) 50 45 {} 51 46 52 FormatParser< pcp >::StructParallelization::~StructParallelization()53 {} 54 55 FormatParser< pcp >::StructPaths::StructPaths() :47 PcpParser::StructParallelization::~StructParallelization() 48 {} 49 50 PcpParser::StructPaths::StructPaths() : 56 51 databasepath(NULL), 57 52 configname(NULL), … … 61 56 {} 62 57 63 FormatParser< pcp >::StructPaths::~StructPaths()64 {} 65 66 FormatParser< pcp >::StructSwitches::StructSwitches() :58 PcpParser::StructPaths::~StructPaths() 59 {} 60 61 PcpParser::StructSwitches::StructSwitches() : 67 62 DoConstrainedMD(0), 68 63 DoOutVis(0), … … 76 71 {} 77 72 78 FormatParser< pcp >::StructSwitches::~StructSwitches()79 {} 80 81 FormatParser< pcp >::StructLocalizedOrbitals::StructLocalizedOrbitals() :73 PcpParser::StructSwitches::~StructSwitches() 74 {} 75 76 PcpParser::StructLocalizedOrbitals::StructLocalizedOrbitals() : 82 77 CommonWannier(0), 83 78 SawtoothStart(0.01), … … 89 84 {} 90 85 91 FormatParser< pcp >::StructLocalizedOrbitals::~StructLocalizedOrbitals()92 {} 93 94 FormatParser< pcp >::StructStepCounts::StructStepCounts() :86 PcpParser::StructLocalizedOrbitals::~StructLocalizedOrbitals() 87 {} 88 89 PcpParser::StructStepCounts::StructStepCounts() : 95 90 MaxMinStopStep(1), 96 91 InitMaxMinStopStep(1), … … 109 104 {} 110 105 111 FormatParser< pcp >::StructStepCounts::~StructStepCounts()112 {} 113 114 FormatParser< pcp >::StructPlaneWaveSpecifics::StructPlaneWaveSpecifics() :106 PcpParser::StructStepCounts::~StructStepCounts() 107 {} 108 109 PcpParser::StructPlaneWaveSpecifics::StructPlaneWaveSpecifics() : 115 110 PsiType(0), 116 111 MaxPsiDouble(0), … … 128 123 {} 129 124 130 FormatParser< pcp >::StructPlaneWaveSpecifics::~StructPlaneWaveSpecifics()125 PcpParser::StructPlaneWaveSpecifics::~StructPlaneWaveSpecifics() 131 126 {} 132 127 … … 134 129 * 135 130 */ 136 FormatParser< pcp >::FormatParser() : 137 FormatParser_common(NULL), 131 PcpParser::PcpParser() : 138 132 FastParsing(false), 139 133 Deltat(0.01), … … 147 141 * 148 142 */ 149 FormatParser< pcp >::~FormatParser()150 {} 151 152 void FormatParser< pcp >::load(std::istream* file)143 PcpParser::~PcpParser() 144 {} 145 146 void PcpParser::load(std::istream* file) 153 147 { 154 148 if (file->fail()) { … … 386 380 * \param atoms atoms to store 387 381 */ 388 void FormatParser< pcp >::save(std::ostream* file, const std::vector<atom *> &atoms)382 void PcpParser::save(std::ostream* file, const std::vector<atom *> &atoms) 389 383 { 390 384 DoLog(0) && (Log() << Verbose(0) << "Saving changes to pcp." << std::endl); … … 420 414 *file << "DoFullCurrent\t" << Switches.DoFullCurrent << "\t# Do full perturbation" << endl; 421 415 *file << "DoConstrainedMD\t" << Switches.DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl; 422 ASSERT(Thermostats != NULL, " FormatParser< pcp >::save() - Thermostats not initialized!");416 ASSERT(Thermostats != NULL, "PcpParser::save() - Thermostats not initialized!"); 423 417 *file << "Thermostat\t" << Thermostats->activeThermostat->name() << "\t"; 424 418 *file << Thermostats->activeThermostat->writeParams(); … … 493 487 * \param &allatoms all atoms to store away 494 488 */ 495 void FormatParser< pcp >::CalculateOrbitals(const std::vector<atom *> &allatoms)489 void PcpParser::CalculateOrbitals(const std::vector<atom *> &allatoms) 496 490 { 497 491 PlaneWaveSpecifics.MaxPsiDouble = PlaneWaveSpecifics.PsiMaxNoDown = PlaneWaveSpecifics.PsiMaxNoUp = PlaneWaveSpecifics.PsiType = 0; … … 526 520 * \param &ZtoIndexMap map of which atoms belong to which ion number 527 521 */ 528 void FormatParser< pcp >::OutputElements(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)522 void PcpParser::OutputElements(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap) 529 523 { 530 524 map<int, int> PresentElements; … … 556 550 * \param &ZtoIndexMap map of which atoms belong to which ion number 557 551 */ 558 void FormatParser< pcp >::OutputAtoms(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)552 void PcpParser::OutputAtoms(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap) 559 553 { 560 554 *file << "#Ion_TypeNr._Nr.R[0] R[1] R[2] MoveType (0 MoveIon, 1 FixedIon)" << endl; … … 604 598 * \param *fb file buffer containing the config file 605 599 */ 606 void FormatParser< pcp >::ParseThermostats(class ConfigFileBuffer * const fb)600 void PcpParser::ParseThermostats(class ConfigFileBuffer * const fb) 607 601 { 608 602 char * const thermo = new char[12]; … … 621 615 }; 622 616 623 bool FormatParser< pcp >::operator==(const FormatParser< pcp >& b) const617 bool PcpParser::operator==(const PcpParser& b) const 624 618 { 625 619 ASSERT(Parallelization.ProcPEGamma == b.Parallelization.ProcPEGamma, "PcpParser ==: ProcPEGamma not"); -
src/Parser/PcpParser.hpp
r360c8b rfa9d1d 14 14 #endif 15 15 16 16 17 #include <iosfwd> 17 #include <map> 18 #include <string> 19 #include <vector> 20 21 #include "FormatParser.hpp" 22 #include "FormatParserTrait.hpp" 23 #include "FormatParserInterface.hpp" 24 #include "FormatParser_common.hpp" 25 #include "ParserTypes.hpp" 26 27 class atom; 28 29 // declaration of specialized FormatParserTrait 30 template<> 31 struct FormatParserTrait<pcp> 32 { 33 //!> Name of the parser 34 static const std::string name; 35 //!> suffix of the files the parser understands to read and write 36 static const std::string suffix; 37 //!> ParserTypes enumeration for the parser 38 static const enum ParserTypes type; 39 }; 18 #include "Parser/FormatParser.hpp" 40 19 41 20 /** 42 21 * Parser for PCP config files. 43 22 */ 44 template <> 45 class FormatParser< pcp > : virtual public FormatParserInterface, public FormatParser_common 46 { 23 class PcpParser : public FormatParser { 47 24 public: 48 FormatParser();49 virtual ~ FormatParser();25 PcpParser(); 26 virtual ~PcpParser(); 50 27 void load(std::istream* file); 51 28 void save(std::ostream* file, const std::vector<atom *> &atoms); 52 29 53 bool operator==(const FormatParser< pcp >& b) const;30 bool operator==(const PcpParser& b) const; 54 31 55 32 private: 56 33 57 34 void ParseThermostats(class ConfigFileBuffer * const fb); 58 void OutputAtoms( std::ostream *file, const std::vector<atom *> &allatoms, std::map<int, int> &ZtoIndexMap);59 void OutputElements( std::ostream *file, const std::vector<atom *> &allatoms, std::map<int, int> &ZtoIndexMap);35 void OutputAtoms(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap); 36 void OutputElements(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap); 60 37 void CalculateOrbitals(const std::vector<atom *> &allatoms); 61 38 … … 177 154 int StructOpt; 178 155 int MaxTypes; 179 st d::string basis;156 string basis; 180 157 }; 181 158 -
src/Parser/PdbAtomInfoContainer.hpp
r360c8b rfa9d1d 14 14 #endif 15 15 16 17 #include "PdbKey.hpp" 18 19 class PdbParser; 20 class Vector; 21 16 22 #include <string> 17 23 #include <typeinfo> 18 19 #include "LinearAlgebra/Vector.hpp"20 #include "PdbKey.hpp"21 22 #include "ParserTypes.hpp"23 24 //template <class T> class FormatParser;25 //template<> class FormatParser< pdb >;26 24 27 25 /** … … 29 27 */ 30 28 class PdbAtomInfoContainer { 31 //!> Grant all FormatParser specializations access, otherwise we have to fully define FormatParser<pdb> 32 template<enum ParserTypes> friend class FormatParser; 29 friend class PdbParser; 33 30 public: 34 31 PdbAtomInfoContainer(); -
src/Parser/PdbParser.cpp
r360c8b rfa9d1d 44 44 using namespace std; 45 45 46 // declare specialized static variables47 const std::string FormatParserTrait<pdb>::name = "pdb";48 const std::string FormatParserTrait<pdb>::suffix = "pdb";49 const ParserTypes FormatParserTrait<pdb>::type = pdb;50 51 46 /** 52 47 * Constructor. 53 48 */ 54 FormatParser< pdb >::FormatParser() : 55 FormatParser_common(NULL) 56 { 49 PdbParser::PdbParser() { 57 50 knownTokens["ATOM"] = PdbKey::Atom; 58 51 knownTokens["HETATM"] = PdbKey::Atom; … … 72 65 * Destructor. 73 66 */ 74 FormatParser< pdb >::~FormatParser() 75 { 67 PdbParser::~PdbParser() { 76 68 PdbAtomInfoContainer::clearknownDataKeys(); 77 69 additionalAtomData.clear(); … … 85 77 * @return token type 86 78 */ 87 enum PdbKey::KnownTokens FormatParser< pdb >::getToken(string &line)79 enum PdbKey::KnownTokens PdbParser::getToken(string &line) 88 80 { 89 81 // look for first space … … 113 105 * \param PDB file 114 106 */ 115 void FormatParser< pdb >::load(istream* file) {107 void PdbParser::load(istream* file) { 116 108 string line; 117 109 size_t linecount = 0; … … 156 148 // TODO: put a throw here 157 149 DoeLog(2) && (eLog() << Verbose(2) << "Unknown token: '" << line << "' for time step " << step << "." << std::endl); 158 //ASSERT(0, " FormatParser< pdb >::load() - Unknown token in line "+toString(linecount)+": "+line+".");150 //ASSERT(0, "PdbParser::load() - Unknown token in line "+toString(linecount)+": "+line+"."); 159 151 break; 160 152 } … … 178 170 * \param atoms atoms to store 179 171 */ 180 void FormatParser< pdb >::save(ostream* file, const std::vector<atom *> &AtomList)172 void PdbParser::save(ostream* file, const std::vector<atom *> &AtomList) 181 173 { 182 174 DoLog(0) && (Log() << Verbose(0) << "Saving changes to pdb." << std::endl); … … 248 240 } else { 249 241 ASSERT(MolIdMap.find(mol->getId()) != MolIdMap.end(), 250 " FormatParser< pdb >::save() - Mol id "+toString(mol->getId())+" not present despite we set it?!");242 "PdbParser::save() - Mol id "+toString(mol->getId())+" not present despite we set it?!"); 251 243 MolNo = MolIdMap[mol->getId()]; 252 244 atomInfo.set(PdbKey::resSeq, toString(MolIdMap[mol->getId()])); … … 297 289 * @param id of atom 298 290 */ 299 void FormatParser< pdb >::AtomInserted(atomId_t id)300 { 301 //LOG(3, " FormatParser< pdb >::AtomInserted() - notified of atom " << id << "'s insertion.");291 void PdbParser::AtomInserted(atomId_t id) 292 { 293 //LOG(3, "PdbParser::AtomInserted() - notified of atom " << id << "'s insertion."); 302 294 ASSERT(!isPresentadditionalAtomData(id), 303 " FormatParser< pdb >::AtomInserted() - additionalAtomData already present for newly added atom "295 "PdbParser::AtomInserted() - additionalAtomData already present for newly added atom " 304 296 +toString(id)+"."); 305 297 // don't insert here as this is our check whether we are in the first time step … … 312 304 * @param id of atom 313 305 */ 314 void FormatParser< pdb >::AtomRemoved(atomId_t id)315 { 316 //LOG(3, " FormatParser< pdb >::AtomRemoved() - notified of atom " << id << "'s removal.");306 void PdbParser::AtomRemoved(atomId_t id) 307 { 308 //LOG(3, "PdbParser::AtomRemoved() - notified of atom " << id << "'s removal."); 317 309 std::map<size_t, PdbAtomInfoContainer>::iterator iter = additionalAtomData.find(id); 318 310 // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence 319 311 // ASSERT(iter != additionalAtomData.end(), 320 // " FormatParser< pdb >::AtomRemoved() - additionalAtomData is not present for atom "312 // "PdbParser::AtomRemoved() - additionalAtomData is not present for atom " 321 313 // +toString(id)+" to remove."); 322 314 if (iter != additionalAtomData.end()) { … … 333 325 * @return true - entry present, false - only for atom's father or no entry 334 326 */ 335 bool FormatParser< pdb >::isPresentadditionalAtomData(unsigned int _id)327 bool PdbParser::isPresentadditionalAtomData(unsigned int _id) 336 328 { 337 329 return (additionalAtomData.find(_id) != additionalAtomData.end()); … … 344 336 * @return 345 337 */ 346 PdbAtomInfoContainer& FormatParser< pdb >::getadditionalAtomData(atom *_atom)338 PdbAtomInfoContainer& PdbParser::getadditionalAtomData(atom *_atom) 347 339 { 348 340 if (additionalAtomData.find(_atom->getId()) != additionalAtomData.end()) { … … 370 362 * \param ResidueNo number of residue 371 363 */ 372 void FormatParser< pdb >::saveLine(364 void PdbParser::saveLine( 373 365 ostream* file, 374 366 const PdbAtomInfoContainer &atomInfo) … … 431 423 * \param *currentAtom to the atom of which to take the neighbor information 432 424 */ 433 void FormatParser< pdb >::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {425 void PdbParser::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) { 434 426 int MaxNo = MaxnumberOfNeighbors; 435 427 int charsleft = 80; … … 460 452 } 461 453 462 /** Retrieves a value from FormatParser< pdb >::atomIdMap.454 /** Retrieves a value from PdbParser::atomIdMap. 463 455 * \param atomid key 464 456 * \return value 465 457 */ 466 size_t FormatParser< pdb >::getSerial(const size_t atomid) const467 { 468 ASSERT(atomIdMap.find(atomid) != atomIdMap.end(), 469 " FormatParser< pdb >::getAtomId:atomid "+toString(atomid)+" not present in Map.");458 size_t PdbParser::getSerial(const size_t atomid) const 459 { 460 ASSERT(atomIdMap.find(atomid) != atomIdMap.end(), 461 "PdbParser::getSerial() - atomid "+toString(atomid)+" not present in Map."); 470 462 return (atomIdMap.find(atomid)->second); 471 463 } 472 464 473 /** Sets an entry in FormatParser< pdb >::atomIdMap.465 /** Sets an entry in PdbParser::atomIdMap. 474 466 * \param localatomid key 475 467 * \param atomid value 476 468 * \return true - key not present, false - value present 477 469 */ 478 void FormatParser< pdb >::setSerial(const size_t localatomid, const size_t atomid)470 void PdbParser::setSerial(const size_t localatomid, const size_t atomid) 479 471 { 480 472 pair<std::map<size_t,size_t>::iterator, bool > inserter; 481 // DoLog(1) && (Log() << Verbose(1) << " FormatParser< pdb >::setAtomId() - Inserting ("473 // DoLog(1) && (Log() << Verbose(1) << "PdbParser::setAtomId() - Inserting (" 482 474 // << localatomid << " -> " << atomid << ")." << std::endl); 483 475 inserter = atomIdMap.insert( make_pair(localatomid, atomid) ); 484 ASSERT(inserter.second, " FormatParser< pdb >::setAtomId: atomId already present in Map.");476 ASSERT(inserter.second, "PdbParser::setAtomId: atomId already present in Map."); 485 477 } 486 478 … … 490 482 * @return 491 483 */ 492 atom* FormatParser< pdb >::getAtomToParse(std::string id_string) const484 atom* PdbParser::getAtomToParse(std::string id_string) const 493 485 { 494 486 // get the local ID … … 525 517 * @param line line containing key ATOM 526 518 */ 527 void FormatParser< pdb >::readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const519 void PdbParser::readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const 528 520 { 529 521 const size_t length = line.length(); 530 522 if (length < 80) 531 ELOG(2, " FormatParser< pdb >::readPdbAtomInfoContainer() - pdb is mal-formed, containing less than 80 chars!");523 ELOG(2, "PdbParser::readPdbAtomInfoContainer() - pdb is mal-formed, containing less than 80 chars!"); 532 524 if (length >= 6) { 533 525 LOG(4,"INFO: Parsing token from "+line.substr(0,6)+"."); … … 538 530 atomInfo.set(PdbKey::serial, line.substr(6,5)); 539 531 ASSERT(atomInfo.get<int>(PdbKey::serial) != 0, 540 " FormatParser< pdb >::readPdbAtomInfoContainer() - serial 0 is invalid (filler id for conect entries).");532 "PdbParser::readPdbAtomInfoContainer() - serial 0 is invalid (filler id for conect entries)."); 541 533 } 542 534 … … 599 591 * \param newmol molecule to add parsed atoms to 600 592 */ 601 void FormatParser< pdb >::readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol = NULL) {593 void PdbParser::readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol = NULL) { 602 594 vector<string>::iterator it; 603 595 … … 606 598 bool FirstTimestep = isPresentadditionalAtomData(newAtom->getId()) ? false : true; 607 599 ASSERT((FirstTimestep && (_step == 0)) || (!FirstTimestep && (_step !=0)), 608 " FormatParser< pdb >::readAtomDataLine() - additionalAtomData present though atom is newly parsed.");600 "PdbParser::readAtomDataLine() - additionalAtomData present though atom is newly parsed."); 609 601 if (FirstTimestep) { 610 602 LOG(3,"INFO: Parsing new atom."); … … 654 646 SerialSet.insert(toSize_t(atomInfo.get<std::string>(PdbKey::serial))); 655 647 ASSERT(Inserter.second, 656 " FormatParser< pdb >::readAtomDataLine() - ATOM contains entry with serial "648 "PdbParser::readAtomDataLine() - ATOM contains entry with serial " 657 649 +atomInfo.get<std::string>(PdbKey::serial)+" already present!"); 658 650 setSerial(toSize_t(atomInfo.get<std::string>(PdbKey::serial)), newAtom->getId()); … … 675 667 ->FindElement(value); 676 668 ASSERT(elem != NULL, 677 " FormatParser< pdb >::readAtomDataLine() - element "+atomInfo.get<std::string>(PdbKey::element)+" is unknown!");669 "PdbParser::readAtomDataLine() - element "+atomInfo.get<std::string>(PdbKey::element)+" is unknown!"); 678 670 newAtom->setType(elem); 679 671 … … 687 679 // then check additional info for consistency 688 680 ASSERT(atomInfo.get<std::string>(PdbKey::token) == consistencyInfo.get<std::string>(PdbKey::token), 689 " FormatParser< pdb >::readAtomDataLine() - difference in token on multiple time step for atom with id "681 "PdbParser::readAtomDataLine() - difference in token on multiple time step for atom with id " 690 682 +atomInfo.get<std::string>(PdbKey::serial)+"!"); 691 683 ASSERT(atomInfo.get<std::string>(PdbKey::name) == consistencyInfo.get<std::string>(PdbKey::name), 692 " FormatParser< pdb >::readAtomDataLine() - difference in name on multiple time step for atom with id "684 "PdbParser::readAtomDataLine() - difference in name on multiple time step for atom with id " 693 685 +atomInfo.get<std::string>(PdbKey::serial)+":" 694 686 +atomInfo.get<std::string>(PdbKey::name)+"!=" 695 687 +consistencyInfo.get<std::string>(PdbKey::name)+"."); 696 688 ASSERT(atomInfo.get<std::string>(PdbKey::altLoc) == consistencyInfo.get<std::string>(PdbKey::altLoc), 697 " FormatParser< pdb >::readAtomDataLine() - difference in altLoc on multiple time step for atom with id "689 "PdbParser::readAtomDataLine() - difference in altLoc on multiple time step for atom with id " 698 690 +atomInfo.get<std::string>(PdbKey::serial)+"!"); 699 691 ASSERT(atomInfo.get<std::string>(PdbKey::resName) == consistencyInfo.get<std::string>(PdbKey::resName), 700 " FormatParser< pdb >::readAtomDataLine() - difference in resName on multiple time step for atom with id "692 "PdbParser::readAtomDataLine() - difference in resName on multiple time step for atom with id " 701 693 +atomInfo.get<std::string>(PdbKey::serial)+"!"); 702 694 ASSERT(atomInfo.get<std::string>(PdbKey::chainID) == consistencyInfo.get<std::string>(PdbKey::chainID), 703 " FormatParser< pdb >::readAtomDataLine() - difference in chainID on multiple time step for atom with id "695 "PdbParser::readAtomDataLine() - difference in chainID on multiple time step for atom with id " 704 696 +atomInfo.get<std::string>(PdbKey::serial)+"!"); 705 697 ASSERT(atomInfo.get<std::string>(PdbKey::resSeq) == consistencyInfo.get<std::string>(PdbKey::resSeq), 706 " FormatParser< pdb >::readAtomDataLine() - difference in resSeq on multiple time step for atom with id "698 "PdbParser::readAtomDataLine() - difference in resSeq on multiple time step for atom with id " 707 699 +atomInfo.get<std::string>(PdbKey::serial)+"!"); 708 700 ASSERT(atomInfo.get<std::string>(PdbKey::iCode) == consistencyInfo.get<std::string>(PdbKey::iCode), 709 " FormatParser< pdb >::readAtomDataLine() - difference in iCode on multiple time step for atom with id "701 "PdbParser::readAtomDataLine() - difference in iCode on multiple time step for atom with id " 710 702 +atomInfo.get<std::string>(PdbKey::serial)+"!"); 711 703 ASSERT(atomInfo.get<std::string>(PdbKey::occupancy) == consistencyInfo.get<std::string>(PdbKey::occupancy), 712 " FormatParser< pdb >::readAtomDataLine() - difference in occupancy on multiple time step for atom with id "704 "PdbParser::readAtomDataLine() - difference in occupancy on multiple time step for atom with id " 713 705 +atomInfo.get<std::string>(PdbKey::serial)+"!"); 714 706 ASSERT(atomInfo.get<std::string>(PdbKey::tempFactor) == consistencyInfo.get<std::string>(PdbKey::tempFactor), 715 " FormatParser< pdb >::readAtomDataLine() - difference in tempFactor on multiple time step for atom with id "707 "PdbParser::readAtomDataLine() - difference in tempFactor on multiple time step for atom with id " 716 708 +atomInfo.get<std::string>(PdbKey::serial)+"!"); 717 709 ASSERT(atomInfo.get<std::string>(PdbKey::charge) == consistencyInfo.get<std::string>(PdbKey::charge), 718 " FormatParser< pdb >::readAtomDataLine() - difference in charge on multiple time step for atom with id "710 "PdbParser::readAtomDataLine() - difference in charge on multiple time step for atom with id " 719 711 +atomInfo.get<std::string>(PdbKey::serial)+"!"); 720 712 ASSERT(atomInfo.get<std::string>(PdbKey::element) == consistencyInfo.get<std::string>(PdbKey::element), 721 " FormatParser< pdb >::readAtomDataLine() - difference in element on multiple time step for atom with id "713 "PdbParser::readAtomDataLine() - difference in element on multiple time step for atom with id " 722 714 +atomInfo.get<std::string>(PdbKey::serial)+"!"); 723 715 // and parse in trajectory … … 742 734 * 743 735 */ 744 void FormatParser< pdb >::printAtomInfo(const atom * const newAtom) const736 void PdbParser::printAtomInfo(const atom * const newAtom) const 745 737 { 746 738 const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(newAtom->getId()); // operator[] const does not exist … … 770 762 * \param line to parse as an atom 771 763 */ 772 void FormatParser< pdb >::readNeighbors(const unsigned int _step, std::string &line)764 void PdbParser::readNeighbors(const unsigned int _step, std::string &line) 773 765 { 774 766 const size_t length = line.length(); … … 780 772 string output; 781 773 ASSERT(length >=16, 782 " FormatParser< pdb >::readNeighbors() - CONECT entry has not enough entries: "+line+"!");783 //output = "Split line:|";784 //output += line.substr(6,5) + "|";774 "PdbParser::readNeighbors() - CONECT entry has not enough entries: "+line+"!"); 775 output = "Split line:|"; 776 output += line.substr(6,5) + "|"; 785 777 const size_t id = toSize_t(line.substr(6,5)); 786 778 for (size_t index = 11; index <= 26; index+=5) { … … 793 785 ListOfNeighbors.push_back(otherid); 794 786 else 795 ELOG(2, " FormatParser< pdb >::readNeighbors() - discarding conect entry with id 0.");787 ELOG(2, "PdbParser::readNeighbors() - discarding conect entry with id 0."); 796 788 } else { 797 789 break; … … 821 813 * \return input string with modified atom IDs 822 814 */ 823 //string FormatParser< pdb >::adaptIdDependentDataString(string data) {815 //string PdbParser::adaptIdDependentDataString(string data) { 824 816 // // there might be no IDs 825 817 // if (data == "-") { … … 844 836 845 837 846 bool FormatParser< pdb >::operator==(const FormatParser< pdb >& b) const838 bool PdbParser::operator==(const PdbParser& b) const 847 839 { 848 840 bool status = true; -
src/Parser/PdbParser.hpp
r360c8b rfa9d1d 14 14 #endif 15 15 16 16 17 #include <string> 17 18 18 #include "FormatParser.hpp" 19 #include "FormatParserTrait.hpp"20 #include "FormatParserInterface.hpp"21 #include "FormatParser_common.hpp"22 #include "ParserTypes.hpp"23 24 19 #include "PdbAtomInfoContainer.hpp" 25 20 #include "PdbKey.hpp" 26 27 class molecule;28 29 // declaration of specialized FormatParserTrait30 template<>31 struct FormatParserTrait<pdb>32 {33 //!> Name of the parser34 static const std::string name;35 //!> suffix of the files the parser understands to read and write36 static const std::string suffix;37 //!> ParserTypes enumeration for the parser38 static const enum ParserTypes type;39 };40 21 41 22 /** 42 23 * Loads a PDB format 3.2 file into the World and saves the World as a PDB file. 43 24 */ 44 template <> 45 class FormatParser< pdb > : virtual public FormatParserInterface, public FormatParser_common 25 class PdbParser : public FormatParser 46 26 { 47 27 public: 48 FormatParser();49 virtual ~ FormatParser();28 PdbParser(); 29 virtual ~PdbParser(); 50 30 void load(std::istream* file); 51 31 void save(std::ostream* file, const std::vector<atom *> &atoms); 52 32 53 bool operator==(const FormatParser< pdb>& b) const;33 bool operator==(const PdbParser& b) const; 54 34 void printAtomInfo(const atom *newAtom) const; 55 35 … … 111 91 */ 112 92 std::set<size_t> SerialSet; 93 113 94 }; 114 95 -
src/Parser/TremoloParser.cpp
r360c8b rfa9d1d 42 42 using namespace std; 43 43 44 // declare specialized static variables45 const std::string FormatParserTrait<tremolo>::name = "tremolo";46 const std::string FormatParserTrait<tremolo>::suffix = "data";47 const ParserTypes FormatParserTrait<tremolo>::type = tremolo;48 49 44 /** 50 45 * Constructor. 51 46 */ 52 FormatParser< tremolo >::FormatParser() : 53 FormatParser_common(NULL) 54 { 47 TremoloParser::TremoloParser() { 55 48 knownKeys["x"] = TremoloKey::x; 56 49 knownKeys["u"] = TremoloKey::u; … … 94 87 * Destructor. 95 88 */ 96 FormatParser< tremolo >::~FormatParser() 97 { 98 std::cerr << "Clearing usedFields." << std::endl; 89 TremoloParser::~TremoloParser() { 90 std::cerr << "Clearing usedFields." << std::endl; 99 91 usedFields.clear(); 100 92 additionalAtomData.clear(); … … 108 100 * \param tremolo file 109 101 */ 110 void FormatParser< tremolo >::load(istream* file) {102 void TremoloParser::load(istream* file) { 111 103 string line; 112 104 string::size_type location; … … 149 141 * \param atoms atoms to store 150 142 */ 151 void FormatParser< tremolo >::save(ostream* file, const std::vector<atom *> &AtomList) {143 void TremoloParser::save(ostream* file, const std::vector<atom *> &AtomList) { 152 144 DoLog(0) && (Log() << Verbose(0) << "Saving changes to tremolo." << std::endl); 153 145 … … 177 169 * @param id of atom 178 170 */ 179 void FormatParser< tremolo >::AtomInserted(atomId_t id)171 void TremoloParser::AtomInserted(atomId_t id) 180 172 { 181 173 std::map<int, TremoloAtomInfoContainer>::iterator iter = additionalAtomData.find(id); 182 174 ASSERT(iter == additionalAtomData.end(), 183 " FormatParser< tremolo >::AtomInserted() - additionalAtomData already present for newly added atom "175 "TremoloParser::AtomInserted() - additionalAtomData already present for newly added atom " 184 176 +toString(id)+"."); 185 177 // don't add entry, as this gives a default resSeq of 0 not the molecule id … … 191 183 * @param id of atom 192 184 */ 193 void FormatParser< tremolo >::AtomRemoved(atomId_t id)185 void TremoloParser::AtomRemoved(atomId_t id) 194 186 { 195 187 std::map<int, TremoloAtomInfoContainer>::iterator iter = additionalAtomData.find(id); 196 188 // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence 197 189 // ASSERT(iter != additionalAtomData.end(), 198 // " FormatParser< tremolo >::AtomRemoved() - additionalAtomData is not present for atom "190 // "TremoloParser::AtomRemoved() - additionalAtomData is not present for atom " 199 191 // +toString(id)+" to remove."); 200 192 if (iter != additionalAtomData.end()) … … 209 201 * but without the prexix "ATOMDATA" 210 202 */ 211 void FormatParser< tremolo >::setFieldsForSave(std::string atomDataLine) {203 void TremoloParser::setFieldsForSave(std::string atomDataLine) { 212 204 parseAtomDataKeysLine(atomDataLine, 0); 213 205 } … … 220 212 * \param reference to the atom of which information should be written 221 213 */ 222 void FormatParser< tremolo >::saveLine(ostream* file, atom* currentAtom) { 223 //vector<string>::iterator it; 224 // TODO: Is unique for FormatParser< tremolo >::usedFields still required? 225 vector<string>::iterator it = unique(usedFields.begin(), usedFields.end()); // skips all duplicates in the vector 214 void TremoloParser::saveLine(ostream* file, atom* currentAtom) { 215 /* vector<string>::iterator it;*/ 216 vector<string>::iterator it = unique(usedFields.begin(), usedFields.end()); // skips all duplicates in the vector 226 217 227 218 TremoloKey::atomDataKey currentField; … … 317 308 * \param reference to the atom of which to take the neighbor information 318 309 */ 319 void FormatParser< tremolo >::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) {310 void TremoloParser::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) { 320 311 const BondList& ListOfBonds = currentAtom->getListOfBonds(); 321 312 // sort bonded indices … … 340 331 * \param with which offset the keys begin within the line 341 332 */ 342 void FormatParser< tremolo >::parseAtomDataKeysLine(string line, int offset) {333 void TremoloParser::parseAtomDataKeysLine(string line, int offset) { 343 334 string keyword; 344 335 stringstream lineStream; … … 362 353 * \a atomdata_string. 363 354 * 364 * We just call \sa FormatParser< tremolo >::parseAtomDataKeysLine() which is left355 * We just call \sa TremoloParser::parseAtomDataKeysLine() which is left 365 356 * private., 366 357 * 367 358 * @param atomdata_string line to parse with space-separated values 368 359 */ 369 void FormatParser< tremolo >::setAtomData(const std::string &atomdata_string)360 void TremoloParser::setAtomData(const std::string &atomdata_string) 370 361 { 371 362 parseAtomDataKeysLine(atomdata_string, 0); … … 380 371 * \param *newmol molecule to add atom to 381 372 */ 382 void FormatParser< tremolo >::readAtomDataLine(string line, molecule *newmol = NULL) {373 void TremoloParser::readAtomDataLine(string line, molecule *newmol = NULL) { 383 374 vector<string>::iterator it; 384 375 stringstream lineStream; … … 398 389 tokenizer tokens(line, whitespacesep); 399 390 ASSERT(tokens.begin() != tokens.end(), 400 " FormatParser< tremolo >::readAtomDataLine - empty string, need at least ' '!");391 "TremoloParser::readAtomDataLine - empty string, need at least ' '!"); 401 392 tokenizer::iterator tok_iter = tokens.begin(); 402 393 // then associate each token to each file … … 410 401 // for the moment, assume there are always three dimensions 411 402 for (int i=0;i<NDIM;i++) { 412 ASSERT(tok_iter != tokens.end(), " FormatParser< tremolo >::readAtomDataLine() - no value for x["+toString(i)+"]!");403 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for x["+toString(i)+"]!"); 413 404 DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl); 414 405 newAtom->set(i, toDouble(*tok_iter)); … … 419 410 // for the moment, assume there are always three dimensions 420 411 for (int i=0;i<NDIM;i++) { 421 ASSERT(tok_iter != tokens.end(), " FormatParser< tremolo >::readAtomDataLine() - no value for u["+toString(i)+"]!");412 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for u["+toString(i)+"]!"); 422 413 DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl); 423 414 tempVector[i] = toDouble(*tok_iter); … … 428 419 case TremoloKey::type : 429 420 { 430 ASSERT(tok_iter != tokens.end(), " FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");421 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!"); 431 422 DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl); 432 423 std::string element(knownTypes[(*tok_iter)]); … … 440 431 } 441 432 case TremoloKey::Id : 442 ASSERT(tok_iter != tokens.end(), " FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");433 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!"); 443 434 DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl); 444 435 atomIdMap[toInt(*tok_iter)] = newAtom->getId(); … … 447 438 case TremoloKey::neighbors : 448 439 for (int i=0;i<atoi(it->substr(it->find("=") + 1, 1).c_str());i++) { 449 ASSERT(tok_iter != tokens.end(), " FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");440 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!"); 450 441 DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl); 451 442 lineStream << *tok_iter << "\t"; … … 456 447 break; 457 448 default : 458 ASSERT(tok_iter != tokens.end(), " FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");449 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!"); 459 450 DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl); 460 451 atomInfo->set(currentField, *tok_iter); … … 476 467 * \param atomid world id of the atom the information belongs to 477 468 */ 478 void FormatParser< tremolo >::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) {469 void TremoloParser::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) { 479 470 int neighborId = 0; 480 471 for (int i = 0; i < numberOfNeighbors; i++) { … … 498 489 * \return true if the field name is used 499 490 */ 500 bool FormatParser< tremolo >::isUsedField(string fieldName) {491 bool TremoloParser::isUsedField(string fieldName) { 501 492 bool fieldNameExists = false; 502 493 for (vector<string>::iterator usedField = usedFields.begin(); usedField != usedFields.end(); usedField++) { … … 514 505 * Id found in the parsed file. 515 506 */ 516 void FormatParser< tremolo >::processNeighborInformation() {507 void TremoloParser::processNeighborInformation() { 517 508 if (!isUsedField("neighbors")) { 518 509 return; … … 547 538 * \return input string with modified atom IDs 548 539 */ 549 st d::string FormatParser< tremolo >::adaptIdDependentDataString(string data) {540 string TremoloParser::adaptIdDependentDataString(string data) { 550 541 // there might be no IDs 551 542 if (data == "-") { … … 572 563 * as they might differ from the originally read IDs. 573 564 */ 574 void FormatParser< tremolo >::adaptImprData() {565 void TremoloParser::adaptImprData() { 575 566 if (!isUsedField("imprData")) { 576 567 return; … … 588 579 * as they might differ from the originally read IDs. 589 580 */ 590 void FormatParser< tremolo >::adaptTorsion() {581 void TremoloParser::adaptTorsion() { 591 582 if (!isUsedField("torsion")) { 592 583 return; … … 603 594 * 604 595 */ 605 void FormatParser< tremolo >::createKnownTypesByIdentity()596 void TremoloParser::createKnownTypesByIdentity() 606 597 { 607 598 // remove old mapping … … 620 611 * @param file input stream of .potentials file 621 612 */ 622 void FormatParser< tremolo >::parseKnownTypes(std::istream &file)613 void TremoloParser::parseKnownTypes(std::istream &file) 623 614 { 624 615 const periodentafel *periode = World::getInstance().getPeriode(); … … 641 632 tokenizer tokens(line, tokensep); 642 633 ASSERT(tokens.begin() != tokens.end(), 643 " FormatParser< tremolo >::parseKnownTypes() - line with 'particle:' but no particles separated by comma.");634 "TremoloParser::parseKnownTypes() - line with 'particle:' but no particles separated by comma."); 644 635 // look for particle_type 645 636 std::string particle_type("NULL"); … … 652 643 tokenizer token((*tok_iter), equalitysep); 653 644 ASSERT(token.begin() != token.end(), 654 " FormatParser< tremolo >::parseKnownTypes() - could not split particle_type by equality sign");645 "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign"); 655 646 tokenizer::iterator particle_iter = token.begin(); 656 647 particle_iter++; … … 661 652 tokenizer token((*tok_iter), equalitysep); 662 653 ASSERT(token.begin() != token.end(), 663 " FormatParser< tremolo >::parseKnownTypes() - could not split particle_type by equality sign");654 "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign"); 664 655 tokenizer::iterator element_iter = token.begin(); 665 656 element_iter++; -
src/Parser/TremoloParser.hpp
r360c8b rfa9d1d 14 14 #endif 15 15 16 16 17 #include <string> 17 18 #include "FormatParser.hpp" 19 #include "FormatParserTrait.hpp" 20 #include "FormatParserInterface.hpp" 21 #include "FormatParser_common.hpp" 22 #include "ParserTypes.hpp" 18 #include "Parser/FormatParser.hpp" 23 19 24 20 #include "TremoloKey.hpp" … … 27 23 class molecule; 28 24 29 // declaration of specialized FormatParserTrait30 template<>31 struct FormatParserTrait<tremolo>32 {33 //!> Name of the parser34 static const std::string name;35 //!> suffix of the files the parser understands to read and write36 static const std::string suffix;37 //!> ParserTypes enumeration for the parser38 static const enum ParserTypes type;39 };40 41 25 /** 42 26 * Loads a tremolo file into the World and saves the World as a tremolo file. 43 27 */ 44 template <> 45 class FormatParser< tremolo > : virtual public FormatParserInterface, public FormatParser_common 28 class TremoloParser : public FormatParser 46 29 { 47 30 public: 48 FormatParser();49 virtual ~ FormatParser();31 TremoloParser(); 32 virtual ~TremoloParser(); 50 33 void load(std::istream* file); 51 34 void save(std::ostream* file, const std::vector<atom *> &atoms); … … 61 44 62 45 private: 63 void readAtomDataLine(st d::string line);64 void readAtomDataLine(st d::string line, molecule *newmol);65 void parseAtomDataKeysLine(st d::string line, int offset);46 void readAtomDataLine(string line); 47 void readAtomDataLine(string line, molecule *newmol); 48 void parseAtomDataKeysLine(string line, int offset); 66 49 void readNeighbors(std::stringstream* line, int numberOfNeighbors, int atomId); 67 50 void processNeighborInformation(); -
src/Parser/XyzParser.cpp
r360c8b rfa9d1d 33 33 using namespace std; 34 34 35 // declare specialized static variables36 const std::string FormatParserTrait<xyz>::name = "xyz";37 const std::string FormatParserTrait<xyz>::suffix = "xyz";38 const ParserTypes FormatParserTrait<xyz>::type = xyz;39 40 35 /** 41 36 * Constructor. 42 37 */ 43 FormatParser< xyz >::FormatParser() : 44 FormatParser_common(NULL), 38 XyzParser::XyzParser() : 45 39 comment("") 46 40 {} … … 49 43 * Destructor. 50 44 */ 51 FormatParser< xyz >::~FormatParser() 52 {}45 XyzParser::~XyzParser() { 46 } 53 47 54 48 /** … … 57 51 * \param XYZ file 58 52 */ 59 void FormatParser< xyz >::load(istream* file)53 void XyzParser::load(istream* file) 60 54 { 61 55 atom* newAtom = NULL; … … 105 99 LOG(5, "INFO: Using present atom " << *newAtom << " from " << i << " th component of AddedAtoms."); 106 100 ASSERT(newAtom->getType() == World::getInstance().getPeriode()->FindElement(type), 107 " FormatParser< xyz >::load() - atom has different type "+newAtom->getType()->getSymbol()+" than parsed now "+type+", mixed up order?");101 "XyzParser::load() - atom has different type "+newAtom->getType()->getSymbol()+" than parsed now "+type+", mixed up order?"); 108 102 } 109 103 newAtom->setPositionAtStep(step, tempVector); … … 135 129 * \param atoms atoms to store 136 130 */ 137 void FormatParser< xyz >::save(ostream* file, const std::vector<atom *> &atoms) {131 void XyzParser::save(ostream* file, const std::vector<atom *> &atoms) { 138 132 DoLog(0) && (Log() << Verbose(0) << "Saving changes to xyz." << std::endl); 139 133 … … 151 145 } 152 146 ASSERT((min_trajectories == max_trajectories) || (min_trajectories == 1), 153 " FormatParser< xyz >::save() - not all atoms have same number of trajectories.");147 "XyzParser::save() - not all atoms have same number of trajectories."); 154 148 LOG(2, "INFO: There are " << max_trajectories << " to save."); 155 149 -
src/Parser/XyzParser.hpp
r360c8b rfa9d1d 14 14 #endif 15 15 16 16 17 #include <string> 17 18 19 #include "FormatParser.hpp" 20 #include "FormatParserTrait.hpp" 21 #include "FormatParserInterface.hpp" 22 #include "FormatParser_common.hpp" 23 #include "ParserTypes.hpp" 24 25 // declaration of specialized FormatParserTrait 26 template<> 27 struct FormatParserTrait<xyz> 28 { 29 //!> Name of the parser 30 static const std::string name; 31 //!> suffix of the files the parser understands to read and write 32 static const std::string suffix; 33 //!> ParserTypes enumeration for the parser 34 static const enum ParserTypes type; 35 }; 18 #include "Parser/FormatParser.hpp" 36 19 37 20 /** 38 21 * Parser for XYZ files. 39 22 */ 40 template <> 41 class FormatParser< xyz > : virtual public FormatParserInterface, public FormatParser_common 42 { 23 class XyzParser : public FormatParser { 43 24 public: 44 FormatParser();45 virtual ~ FormatParser();25 XyzParser(); 26 virtual ~XyzParser(); 46 27 void load(std::istream* file); 47 28 void save(std::ostream* file, const std::vector<atom *> &atoms); -
src/Parser/unittests/Makefile.am
r360c8b rfa9d1d 2 2 # Also indentation by a single tab 3 3 4 include ../../src/Parser/Parameters/unittests/Makefile.am5 4 6 5 PARSERTESTSSOURCES = \ … … 8 7 ../Parser/unittests/ParserPcpUnitTest.cpp \ 9 8 ../Parser/unittests/ParserPdbUnitTest.cpp \ 10 ../Parser/unittests/ParserPsi3UnitTest.cpp \11 9 ../Parser/unittests/ParserTremoloUnitTest.cpp \ 12 10 ../Parser/unittests/ParserXyzUnitTest.cpp … … 16 14 ../Parser/unittests/ParserPcpUnitTest.hpp \ 17 15 ../Parser/unittests/ParserPdbUnitTest.hpp \ 18 ../Parser/unittests/ParserPsi3UnitTest.hpp \19 16 ../Parser/unittests/ParserTremoloUnitTest.hpp \ 20 17 ../Parser/unittests/ParserXyzUnitTest.hpp … … 24 21 ParserPcpUnitTest \ 25 22 ParserPdbUnitTest \ 26 ParserPsi3UnitTest \27 23 ParserTremoloUnitTest \ 28 24 ParserXyzUnitTest … … 37 33 ${CodePatterns_LIBS} 38 34 # $(BOOST_LIB) 35 39 36 40 37 … … 54 51 ParserPdbUnitTest_LDADD = ${PARSERLIBS} 55 52 56 ParserPsi3UnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \57 ../Parser/unittests/ParserPsi3UnitTest.cpp \58 ../Parser/unittests/ParserPsi3UnitTest.hpp59 ParserPsi3UnitTest_LDADD = ${PARSERLIBS}60 61 53 ParserTremoloUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \ 62 54 ../Parser/unittests/ParserTremoloUnitTest.cpp \ -
src/Parser/unittests/ParserMpqcUnitTest.cpp
r360c8b rfa9d1d 32 32 #include "Descriptors/AtomTypeDescriptor.hpp" 33 33 #include "CodePatterns/Assert.hpp" 34 #include "Parser/ChangeTracker.hpp"35 #include "Parser/MpqcParser.hpp"36 34 37 35 #ifdef HAVE_TESTRUNNER … … 158 156 )\n"; // basically tested with mpqc 3.0.0-alpha (no parse errors but did not calculate due to missing code) 159 157 160 void ParserMpqcUnitTest::setUp() 161 { 162 // failing asserts should be thrown 163 ASSERT_DO(Assert::Throw); 164 165 parser = new FormatParser<mpqc>(); 158 void ParserMpqcUnitTest::setUp() { 159 mpqc = new MpqcParser(); 166 160 167 161 World::getInstance(); … … 174 168 } 175 169 176 void ParserMpqcUnitTest::tearDown() 177 { 178 delete parser; 170 void ParserMpqcUnitTest::tearDown() { 171 delete mpqc; 179 172 ChangeTracker::purgeInstance(); 180 173 World::purgeInstance(); … … 183 176 /************************************ tests ***********************************/ 184 177 178 void ParserMpqcUnitTest::ParameterTypeTest() { 179 // check types in boost::any map 180 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool)); 181 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int)); 182 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool)); 183 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool)); 184 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int)); 185 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int)); 186 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string)); 187 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int)); 188 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string)); 189 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string)); 190 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints)); 191 CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2)); 192 } 193 185 194 void ParserMpqcUnitTest::ParameterDefaultTest() { 186 195 // check default values 187 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("no")); 188 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::savestateParam) == std::string("no")); 189 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::do_gradientParam) == std::string("yes")); 190 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("1000")); 191 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::memoryParam) == std::string("16000000")); 192 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::stdapproxParam) == std::string("A'")); 193 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::nfzcParam) == std::string("1")); 194 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::basisParam) == std::string("3-21G")); 195 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::aux_basisParam) == std::string("aug-cc-pVDZ")); 196 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::integrationParam) == std::string("IntegralCints")); 197 CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2")); 196 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "no"); 197 CPPUNIT_ASSERT(!mpqc->getParams().getBool(MpqcParser_Parameters::hessianParam)); 198 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::savestateParam) == "no"); 199 CPPUNIT_ASSERT(!mpqc->getParams().getBool(MpqcParser_Parameters::savestateParam)); 200 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes"); 201 CPPUNIT_ASSERT(mpqc->getParams().getBool(MpqcParser_Parameters::do_gradientParam)); 202 CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000); 203 CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000); 204 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'"); 205 CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1); 206 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G"); 207 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ"); 208 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints"); 209 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2"); 210 CPPUNIT_ASSERT(mpqc->getParams().getTheory() == MpqcParser_Parameters::MBPT2); 211 CPPUNIT_ASSERT(mpqc->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints); 212 213 // check that values are not removed 214 CPPUNIT_ASSERT(!mpqc->getParams().params[MpqcParser_Parameters::theoryParam].empty()); 215 216 // check throw, for the moment aren't, are caught in getInt() 217 CPPUNIT_ASSERT_THROW(mpqc->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast); 218 CPPUNIT_ASSERT_THROW(mpqc->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast); 219 198 220 } 199 221 200 222 void ParserMpqcUnitTest::ParameterCloneTest() { 201 FormatParser_Parameters *clone = parser->getParams().clone();202 CPPUNIT_ASSERT( parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));223 FormatParser_Parameters *clone = mpqc->getParams().clone(); 224 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2"); 203 225 std::stringstream setvalue("theory = CLHF"); 204 setvalue >> parser->getParams();205 CPPUNIT_ASSERT( parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));206 parser->getParams().makeClone(*clone);207 CPPUNIT_ASSERT( parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));226 setvalue >> mpqc->getParams(); 227 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF"); 228 mpqc->getParams().makeClone(*clone); 229 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2"); 208 230 } 209 231 … … 212 234 { 213 235 std::stringstream setvalue("theory = CLHF"); 214 setvalue >> parser->getParams();236 setvalue >> mpqc->getParams(); 215 237 // std::cout << "integration method is " 216 // << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;217 CPPUNIT_ASSERT( parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));238 // << mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl; 239 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF"); 218 240 } 219 241 // test a bool 220 242 { 221 243 std::stringstream setvalue("Hessian = yes"); 222 setvalue >> parser->getParams();244 setvalue >> mpqc->getParams(); 223 245 // std::cout << "Hessian is " 224 // << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;225 CPPUNIT_ASSERT( parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));246 // << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl; 247 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes"); 226 248 } 227 249 // test int 228 250 { 229 251 std::stringstream setvalue("maxiter = 500"); 230 setvalue >> parser->getParams();252 setvalue >> mpqc->getParams(); 231 253 // std::cout << "maxiter is " 232 // << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;233 CPPUNIT_ASSERT( parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("500"));254 // << mpqc->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl; 255 CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500); 234 256 } 235 257 // test whether unknown key fails … … 239 261 #ifndef NDEBUG 240 262 ASSERT_DO(Assert::Throw); 241 CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);263 CPPUNIT_ASSERT_THROW(setvalue >> mpqc->getParams(), Assert::AssertionFailure); 242 264 #else 243 setvalue >> parser->getParams();265 setvalue >> mpqc->getParams(); 244 266 #endif 245 267 // std::cout << "Hessian is still " 246 // << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;247 CPPUNIT_ASSERT( parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));268 // << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl; 269 CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes"); 248 270 } 249 271 } … … 251 273 void ParserMpqcUnitTest::readMpqcTest() { 252 274 stringstream input(waterMpqc_CLHF); 253 parser->getParams().setParameter( 254 MpqcParser_Parameters::theoryParam, 255 parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF) 256 ); 257 parser->load(&input); 275 mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF); 276 mpqc->load(&input); 258 277 259 278 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); … … 282 301 // compare both configs for CLHF 283 302 stringstream output; 284 parser->getParams().setParameter( 285 MpqcParser_Parameters::theoryParam, 286 parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF) 287 ); 288 parser->save(&output, atoms); 303 mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF); 304 mpqc->save(&output, atoms); 289 305 stringstream input(waterMpqc_CLHF); 290 // check for non-empty streams291 input.peek();292 output.peek();293 CPPUNIT_ASSERT(input.good() && output.good());294 // check equality of streams per line (for debugging)295 306 for (; std::getline(input, first) && std::getline(output, second); ) { 296 307 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl; … … 301 312 // compare both configs for CLKS 302 313 stringstream output; 303 parser->getParams().setParameter( 304 MpqcParser_Parameters::theoryParam, 305 parser->getParams().getTheoryName(MpqcParser_Parameters::CLKS) 306 ); 307 parser->save(&output, atoms); 314 mpqc->getParams().setTheory(MpqcParser_Parameters::CLKS); 315 mpqc->save(&output, atoms); 308 316 stringstream input(waterMpqc_CLKS); 309 // check for non-empty streams310 input.peek();311 output.peek();312 CPPUNIT_ASSERT(input.good() && output.good());313 // check equality of streams per line (for debugging)314 317 for (; std::getline(input, first) && std::getline(output, second); ) { 315 318 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl; … … 320 323 // compare both configs for MBPT2 321 324 stringstream output; 322 parser->getParams().setParameter( 323 MpqcParser_Parameters::theoryParam, 324 parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2) 325 ); 326 parser->save(&output, atoms); 325 mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2); 326 mpqc->save(&output, atoms); 327 327 stringstream input(waterMpqc_MBPT2); 328 // check for non-empty streams329 input.peek();330 output.peek();331 CPPUNIT_ASSERT(input.good() && output.good());332 // check equality of streams per line (for debugging)333 328 for (; std::getline(input, first) && std::getline(output, second); ) { 334 329 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl; … … 339 334 // compare both configs for MBPT2_R12 340 335 stringstream output; 341 parser->getParams().setParameter( 342 MpqcParser_Parameters::theoryParam, 343 parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12) 344 ); 345 parser->save(&output, atoms); 336 mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12); 337 mpqc->save(&output, atoms); 346 338 stringstream input(waterMpqc_MBPT2_R12); 347 // check for non-empty streams348 input.peek();349 output.peek();350 CPPUNIT_ASSERT(input.good() && output.good());351 // check equality of streams per line (for debugging)352 339 for (; std::getline(input, first) && std::getline(output, second); ) { 353 340 //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl; -
src/Parser/unittests/ParserMpqcUnitTest.hpp
r360c8b rfa9d1d 21 21 { 22 22 CPPUNIT_TEST_SUITE( ParserMpqcUnitTest ) ; 23 CPPUNIT_TEST ( ParameterTypeTest ); 23 24 CPPUNIT_TEST ( ParameterDefaultTest ); 24 25 CPPUNIT_TEST ( ParameterSetterTest ); … … 32 33 void tearDown(); 33 34 35 void ParameterTypeTest(); 34 36 void ParameterDefaultTest(); 35 37 void ParameterSetterTest(); … … 39 41 40 42 private: 41 FormatParser<mpqc> *parser;43 MpqcParser *mpqc; 42 44 }; 43 45 -
src/Parser/unittests/ParserPcpUnitTest.cpp
r360c8b rfa9d1d 24 24 #include <cppunit/ui/text/TestRunner.h> 25 25 26 #include "Parser/PcpParser.hpp" 26 27 #include "World.hpp" 27 28 #include "atom.hpp" … … 30 31 #include "CodePatterns/Log.hpp" 31 32 #include "Descriptors/AtomTypeDescriptor.hpp" 32 #include "Parser/ChangeTracker.hpp"33 #include "Parser/PcpParser.hpp"34 33 35 34 #ifdef HAVE_TESTRUNNER … … 120 119 World::getInstance(); 121 120 122 parser = new FormatParser<pcp>();123 124 121 setVerbosity(2); 125 122 … … 129 126 } 130 127 131 void ParserPcpUnitTest::tearDown() 132 { 133 delete parser; 128 void ParserPcpUnitTest::tearDown() { 134 129 ChangeTracker::purgeInstance(); 135 130 World::purgeInstance(); … … 140 135 void ParserPcpUnitTest::readwritePcpTest() { 141 136 stringstream input(waterPcp); 142 parser->load(&input); 137 PcpParser* testParser = new PcpParser(); 138 testParser->load(&input); 143 139 input.clear(); 144 140 … … 146 142 147 143 // check that equality function is ok 148 CPPUNIT_ASSERT(* parser == *parser);144 CPPUNIT_ASSERT(*testParser == *testParser); 149 145 150 146 stringstream output; 151 147 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 152 parser->save(&output, atoms);148 testParser->save(&output, atoms); 153 149 154 150 input << output.str(); 155 FormatParser<pcp>* parser2 = new FormatParser<pcp>();156 parser2->load(&input);151 PcpParser* testParser2 = new PcpParser(); 152 testParser2->load(&input); 157 153 158 154 CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms()); 159 155 160 CPPUNIT_ASSERT(*parser == *parser2); 161 162 delete parser2; 156 CPPUNIT_ASSERT(*testParser == *testParser2); 163 157 } -
src/Parser/unittests/ParserPcpUnitTest.hpp
r360c8b rfa9d1d 13 13 #endif 14 14 15 #include "Parser/PcpParser.hpp"16 15 17 16 #include <cppunit/extensions/HelperMacros.h> … … 29 28 30 29 void readwritePcpTest(); 31 32 private:33 FormatParser<pcp> *parser;34 30 }; 35 31 -
src/Parser/unittests/ParserPdbUnitTest.cpp
r360c8b rfa9d1d 24 24 #include <cppunit/ui/text/TestRunner.h> 25 25 26 #include "Parser/PdbParser.hpp" 26 27 #include "World.hpp" 27 28 #include "atom.hpp" … … 30 31 #include "CodePatterns/Log.hpp" 31 32 #include "Descriptors/AtomTypeDescriptor.hpp" 32 #include "Parser/ChangeTracker.hpp"33 #include "Parser/PdbParser.hpp"34 33 35 34 #ifdef HAVE_TESTRUNNER … … 64 63 World::getInstance(); 65 64 66 parser = new FormatParser<pdb>();67 68 65 setVerbosity(2); 69 66 … … 73 70 } 74 71 75 void ParserPdbUnitTest::tearDown() 76 { 77 delete parser; 72 void ParserPdbUnitTest::tearDown() { 78 73 ChangeTracker::purgeInstance(); 79 74 World::purgeInstance(); … … 85 80 stringstream input; 86 81 input << waterPdb; 87 parser->load(&input); 82 PdbParser* testParser = new PdbParser(); 83 testParser->load(&input); 88 84 input.clear(); 89 85 … … 92 88 stringstream output; 93 89 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 94 parser->save(&output, atoms);90 testParser->save(&output, atoms); 95 91 96 92 // std::cout << "Save PDB is:" << std::endl; … … 98 94 99 95 input << output.str(); 100 FormatParser<pdb>* parser2 = new FormatParser<pdb>();101 parser2->load(&input);96 PdbParser* testParser2 = new PdbParser(); 97 testParser2->load(&input); 102 98 103 99 CPPUNIT_ASSERT_EQUAL(12, World::getInstance().numAtoms()); 104 105 delete parser2;106 100 } -
src/Parser/unittests/ParserPdbUnitTest.hpp
r360c8b rfa9d1d 13 13 #endif 14 14 15 #include "Parser/PdbParser.hpp"16 15 17 16 #include <cppunit/extensions/HelperMacros.h> … … 29 28 30 29 void readwritePdbTest(); 31 32 private:33 FormatParser<pdb> *parser;34 30 }; 35 31 -
src/Parser/unittests/ParserTremoloUnitTest.cpp
r360c8b rfa9d1d 27 27 #include "Descriptors/AtomTypeDescriptor.hpp" 28 28 #include "Element/element.hpp" 29 #include "Parser/MpqcParser.hpp" 30 #include "Parser/PdbParser.hpp" 31 #include "Parser/PcpParser.hpp" 32 #include "Parser/TremoloParser.hpp" 33 #include "Parser/XyzParser.hpp" 29 34 #include "Element/periodentafel.hpp" 30 #include "Parser/TremoloParser.hpp"31 #include "Parser/ChangeTracker.hpp"32 35 #include "World.hpp" 33 36 #include "WorldTime.hpp" … … 82 85 World::getInstance(); 83 86 84 parser = new FormatParser<tremolo>();85 86 87 // we need hydrogens and oxygens in the following tests 87 88 CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL); … … 89 90 } 90 91 91 void ParserTremoloUnitTest::tearDown() 92 { 93 delete parser; 92 void ParserTremoloUnitTest::tearDown() { 94 93 ChangeTracker::purgeInstance(); 95 94 World::purgeInstance(); … … 100 99 void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() { 101 100 cout << "Testing the tremolo parser." << endl; 101 TremoloParser* testParser = new TremoloParser(); 102 102 stringstream input, output; 103 103 … … 105 105 { 106 106 input << Tremolo_Atomdata1; 107 parser->load(&input);108 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 109 parser->save(&output, atoms);107 testParser->load(&input); 108 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 109 testParser->save(&output, atoms); 110 110 // std::cout << output.str() << std::endl; 111 111 // std::cout << Tremolo_Atomdata1 << std::endl; … … 118 118 { 119 119 input << Tremolo_Atomdata2; 120 parser->load(&input);121 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 122 parser->save(&output, atoms);120 testParser->load(&input); 121 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 122 testParser->save(&output, atoms); 123 123 std::cout << output.str() << std::endl; 124 124 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos); … … 129 129 // Invalid key in Atomdata line 130 130 input << Tremolo_invalidkey; 131 parser->load(&input);131 testParser->load(&input); 132 132 //TODO: prove invalidity 133 133 input.clear(); … … 135 135 136 136 void ParserTremoloUnitTest::readTremoloCoordinatesTest() { 137 TremoloParser* testParser = new TremoloParser(); 137 138 stringstream input; 138 139 139 140 // One simple data line 140 141 input << Tremolo_Atomdata2; 141 parser->load(&input);142 testParser->load(&input); 142 143 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0); 143 144 input.clear(); … … 145 146 146 147 void ParserTremoloUnitTest::readTremoloVelocityTest() { 148 TremoloParser* testParser = new TremoloParser(); 147 149 stringstream input; 148 150 149 151 // One simple data line 150 152 input << Tremolo_velocity; 151 parser->load(&input);153 testParser->load(&input); 152 154 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0); 153 155 input.clear(); … … 155 157 156 158 void ParserTremoloUnitTest::readTremoloNeighborInformationTest() { 159 TremoloParser* testParser = new TremoloParser(); 157 160 stringstream input; 158 161 159 162 // Neighbor data 160 163 input << Tremolo_neighbours; 161 parser->load(&input);164 testParser->load(&input); 162 165 163 166 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); … … 168 171 169 172 void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() { 173 TremoloParser* testParser = new TremoloParser(); 170 174 stringstream input, output; 171 175 … … 173 177 { 174 178 input << Tremolo_improper; 175 parser->load(&input);176 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 177 parser->save(&output, atoms);179 testParser->load(&input); 180 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 181 testParser->save(&output, atoms); 178 182 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 179 183 std::cout << output.str() << std::endl; … … 185 189 186 190 void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() { 191 TremoloParser* testParser = new TremoloParser(); 187 192 stringstream input, output; 188 193 … … 190 195 { 191 196 input << Tremolo_torsion; 192 parser->load(&input);193 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 194 parser->save(&output, atoms);197 testParser->load(&input); 198 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 199 testParser->save(&output, atoms); 195 200 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 196 201 std::cout << output.str() << std::endl; … … 202 207 203 208 void ParserTremoloUnitTest::writeTremoloTest() { 209 TremoloParser* testParser = new TremoloParser(); 204 210 stringstream output; 205 211 … … 208 214 atom* newAtom = World::getInstance().createAtom(); 209 215 newAtom->setType(1); 210 parser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");211 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 212 parser->save(&output, atoms);216 testParser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion"); 217 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 218 testParser->save(&output, atoms); 213 219 CPPUNIT_ASSERT(output.str() == Tremolo_full); 214 220 } … … 216 222 cout << "testing the tremolo parser is done" << endl; 217 223 } 218 -
src/Parser/unittests/ParserTremoloUnitTest.hpp
r360c8b rfa9d1d 13 13 #endif 14 14 15 #include "Parser/TremoloParser.hpp"16 15 17 16 #include <cppunit/extensions/HelperMacros.h> … … 41 40 void readAndWriteTremoloTorsionInformationTest(); 42 41 void writeTremoloTest(); 43 44 private:45 FormatParser<tremolo> *parser;46 42 }; 47 43 -
src/Parser/unittests/ParserXyzUnitTest.cpp
r360c8b rfa9d1d 24 24 #include <cppunit/ui/text/TestRunner.h> 25 25 26 #include "Parser/XyzParser.hpp" 26 27 #include "World.hpp" 27 28 #include "atom.hpp" … … 30 31 #include "CodePatterns/Log.hpp" 31 32 #include "Descriptors/AtomTypeDescriptor.hpp" 32 #include "Parser/ChangeTracker.hpp"33 #include "Parser/XyzParser.hpp"34 33 35 34 #ifdef HAVE_TESTRUNNER … … 63 62 World::getInstance(); 64 63 65 parser = new FormatParser<xyz>();66 67 64 setVerbosity(2); 68 65 … … 72 69 } 73 70 74 void ParserXyzUnitTest::tearDown() 75 { 76 delete parser; 71 void ParserXyzUnitTest::tearDown() { 77 72 ChangeTracker::purgeInstance(); 78 73 World::purgeInstance(); … … 83 78 void ParserXyzUnitTest::rewriteAnXyzTest() { 84 79 cout << "Testing the XYZ parser." << endl; 80 XyzParser* testParser = new XyzParser(); 85 81 stringstream input; 86 82 input << waterXyz; 87 parser->load(&input);83 testParser->load(&input); 88 84 input.clear(); 89 85 … … 94 90 stringstream output; 95 91 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 96 parser->save(&output, atoms);92 testParser->save(&output, atoms); 97 93 input << output.str(); 98 parser->load(&input);94 testParser->load(&input); 99 95 } 100 96 … … 119 115 void ParserXyzUnitTest::readMultiXyzTest() { 120 116 cout << "Testing the multi time step XYZ parser." << endl; 117 XyzParser* testParser = new XyzParser(); 121 118 stringstream input; 122 119 input << waterMultiXyz; 123 parser->load(&input);120 testParser->load(&input); 124 121 input.clear(); 125 122 … … 133 130 134 131 void ParserXyzUnitTest::writeMultiXyzTest() { 132 XyzParser* testParser = new XyzParser(); 135 133 stringstream input; 136 134 input << waterMultiXyz; 137 parser->load(&input);135 testParser->load(&input); 138 136 input.clear(); 139 137 … … 145 143 stringstream output; 146 144 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 147 parser->save(&output, atoms);145 testParser->save(&output, atoms); 148 146 input << output.str(); 149 parser->load(&input);147 testParser->load(&input); 150 148 } 151 149 -
src/Parser/unittests/ParserXyzUnitTest.hpp
r360c8b rfa9d1d 13 13 #endif 14 14 15 #include "Parser/XyzParser.hpp"16 15 17 16 #include <cppunit/extensions/HelperMacros.h> … … 33 32 void readMultiXyzTest(); 34 33 void writeMultiXyzTest(); 35 36 private:37 FormatParser<xyz> *parser;38 34 }; 39 35 -
src/atom.cpp
r360c8b rfa9d1d 201 201 }; 202 202 203 void atom::OutputPsi3Line(ostream * const out, const Vector *center) const204 {205 Vector recentered(getPosition());206 recentered -= *center;207 *out << "\t( " << getType()->getSymbol() << "\t" << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2] << " )" << endl;208 };209 210 203 bool atom::Compare(const atom &ptr) const 211 204 { -
src/atom.hpp
r360c8b rfa9d1d 113 113 */ 114 114 void OutputMPQCLine(ostream * const out, const Vector *center) const; 115 116 /** Outputs the Psi3 configuration line for this atom.117 * \param *out output stream118 * \param *center center of molecule subtracted from position119 * \param *AtomNo pointer to atom counter that is increased by one120 */121 void OutputPsi3Line(ostream * const out, const Vector *center) const;122 115 123 116 /** Initialises the component number array. -
src/moleculelist.cpp
r360c8b rfa9d1d 626 626 // atoms.resize((*ListRunner)->getAtomCount()); 627 627 // std::copy((*ListRunner)->begin(), (*ListRunner)->end(), atoms.begin()); 628 FormatParserStorage::getInstance().get (mpqc).save(&outfile, atoms);628 FormatParserStorage::getInstance().getMpqc().save(&outfile, atoms); 629 629 // if ((intermediateResult = World::getInstance().getConfig()->SaveMPQC(FragmentName.c_str(), (*ListRunner)))) 630 630 output << " done."; -
src/unittests/BoxUnitTest.cpp
r360c8b rfa9d1d 39 39 40 40 void BoxUnittest::setUp(){ 41 // failing asserts should be thrown42 41 ASSERT_DO(Assert::Throw); 43 44 42 unit = new RealSpaceMatrix; 45 43 unit->setIdentity(); -
src/unittests/FormulaUnitTest.cpp
r360c8b rfa9d1d 35 35 CPPUNIT_TEST_SUITE_REGISTRATION( FormulaUnittest ); 36 36 37 void FormulaUnittest::setUp() 38 { 39 // failing asserts should be thrown 40 ASSERT_DO(Assert::Throw); 41 } 42 43 void FormulaUnittest::tearDown() 44 { 37 void FormulaUnittest::setUp(){} 38 void FormulaUnittest::tearDown(){ 45 39 World::purgeInstance(); 46 40 } -
tests/regression/Makefile.am
r360c8b rfa9d1d 106 106 $(srcdir)/Parser/Pdb/testsuite-parser-pdb-save.at \ 107 107 $(srcdir)/Parser/Pdb/testsuite-parser-pdb-with-conects.at \ 108 $(srcdir)/Parser/Psi3/testsuite-parser-psi3-empty.at \109 $(srcdir)/Parser/Psi3/testsuite-parser-psi3-load.at \110 $(srcdir)/Parser/Psi3/testsuite-parser-psi3-save.at \111 108 $(srcdir)/Parser/Tremolo/testsuite-parser-tremolo-empty.at \ 112 109 $(srcdir)/Parser/Tremolo/testsuite-parser-tremolo-load.at \ -
tests/regression/Parser/testsuite-parser.at
r360c8b rfa9d1d 30 30 m4_include([Parser/Pdb/testsuite-parser-pdb-load-various.at]) 31 31 32 # parsing mpqc33 m4_include([Parser/Psi3/testsuite-parser-psi3-empty.at])34 m4_include([Parser/Psi3/testsuite-parser-psi3-load.at])35 m4_include([Parser/Psi3/testsuite-parser-psi3-save.at])36 37 32 # parsing tremolo 38 33 m4_include([Parser/Tremolo/testsuite-parser-tremolo-empty.at])
Note:
See TracChangeset
for help on using the changeset viewer.