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