- Timestamp:
- Oct 14, 2011, 3:15:30 PM (13 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- d3d6c6
- Parents:
- 9a6b76e
- git-author:
- Frederik Heber <heber@…> (09/27/11 19:04:36)
- git-committer:
- Frederik Heber <heber@…> (10/14/11 15:15:30)
- Location:
- src
- Files:
-
- 8 added
- 33 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/MoleculeAction/FillVoidWithMoleculeAction.cpp
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 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" -
src/Actions/ParserAction/ParseTremoloPotentialsAction.cpp
r9a6b76e r765f16 43 43 44 44 boost::filesystem::ifstream test; 45 TremoloParser &tremolo = FormatParserStorage::getInstance().getParser<TremoloParser>();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().getParser<TremoloParser>(); 58 tremolo.parseKnownTypes(test); 57 parser.parseKnownTypes(test); 59 58 test.close(); 60 59 } -
src/Actions/ParserAction/SetMpqcParametersAction.cpp
r9a6b76e r765f16 38 38 /** =========== define the function ====================== */ 39 39 Action::state_ptr ParserSetMpqcParametersAction::performCall() { 40 MpqcParser_Parameters & mpqc = FormatParserStorage::getInstance().getParser<MpqcParser>().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().getParser<MpqcParser>().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().getParser<MpqcParser>().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
r9a6b76e r765f16 42 42 getParametersfromValueStorage(); 43 43 44 TremoloParser &tremolo = FormatParserStorage::getInstance().getParser<TremoloParser>();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
r9a6b76e r765f16 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 "parser.hpp" 20 #include "CodePatterns/Assert.hpp" 21 21 22 namespace MoleCuilder { 23 class MoleculeLoadAction; 24 } 22 #include "FormatParserTrait.hpp" 23 #include "FormatParserInterface.hpp" 24 #include "FormatParser_common.hpp" 25 #include "ParserTypes.hpp" 25 26 26 27 class atom; 27 28 28 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 /** 29 60 * General parser which observes the change tracker. 30 61 */ 31 class FormatParser : public Observer { 32 friend class MoleCuilder::MoleculeLoadAction; 33 public: 34 FormatParser(); 35 virtual ~FormatParser(); 36 virtual void save(std::ostream* file, const std::vector<atom *> &atoms)=0; 37 virtual void load(std::istream* file)=0; 38 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 } 39 73 40 protected: 41 void update(Observable *publisher); 42 void recieveNotification(Observable *publisher, Notification_ptr notification); 43 void subjectKilled(Observable *publisher); 44 45 // these functions are called when atoms are inserted or removed 46 virtual void AtomInserted(atomId_t) {}; 47 virtual void AtomRemoved(atomId_t) {}; 48 49 FormatParser_Parameters *parameters; 50 private: 51 52 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 } 53 82 }; 54 83 84 #include "FormatParser_specializations_header.hpp" 85 55 86 #endif /* FORMATPARSER_HPP_ */ -
src/Parser/FormatParserStorage.cpp
r9a6b76e r765f16 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 "TremoloParser.hpp" 38 #include "XyzParser.hpp" 33 39 34 40 #include "CodePatterns/Singleton_impl.hpp" 35 41 36 template <> enum ParserTypes getPType<MpqcParser>() { return (enum ParserTypes)mpqc; }37 template <> enum ParserTypes getPType<PcpParser>() { return (enum ParserTypes)pcp; }38 template <> enum ParserTypes getPType<PdbParser>() { return (enum ParserTypes)pdb; }39 template <> enum ParserTypes getPType<TremoloParser>() { return (enum ParserTypes)tremolo; }40 template <> enum ParserTypes getPType<XyzParser>() { return (enum ParserTypes)xyz; }41 42 /** Increment operator for the enumeration ParserTypes to allow loops.43 * \param &type value44 * \return value incremented by one45 */46 ParserTypes &operator++(ParserTypes &type)47 {48 return type = ParserTypes(type+1);49 }50 42 51 43 /** Constructor of class FormatParserStorage. … … 57 49 ParserPresent.resize(ParserTypes_end, false); 58 50 59 ParserNames[mpqc] = "mpqc"; 60 ParserNames[pcp] = "pcp"; 61 ParserNames[pdb] = "pdb"; 62 ParserNames[tremolo] = "tremolo"; 63 ParserNames[xyz] = "xyz"; 51 #include "ParserTypes.def" 52 53 #define insert_print(z,n,seq,map, before, after) \ 54 map .insert( std::make_pair( \ 55 BOOST_PP_SEQ_ELEM(n, seq) \ 56 , before < \ 57 BOOST_PP_SEQ_ELEM(n, seq) \ 58 > after \ 59 ) ); 64 60 65 for (std::map<ParserTypes, std::string>::const_iterator it = ParserNames.begin(); it != ParserNames.end(); ++it) 66 ParserLookupNames.insert(pair<std::string, ParserTypes>(it->second,it->first) ); 67 68 ParserSuffixes[mpqc] = "in"; 69 ParserSuffixes[pcp] = "conf"; 70 ParserSuffixes[pdb] = "pdb"; 71 ParserSuffixes[tremolo] = "data"; 72 ParserSuffixes[xyz] = "xyz"; 73 74 for (std::map<ParserTypes, std::string>::const_iterator it = ParserSuffixes.begin(); it != ParserSuffixes.end(); ++it) 75 ParserLookupSuffixes.insert(pair<std::string, ParserTypes>(it->second,it->first) ); 76 77 ParserAddFunction[mpqc] = &FormatParserStorage::addParser<MpqcParser>; 78 ParserAddFunction[pcp] = &FormatParserStorage::addParser<PcpParser>; 79 ParserAddFunction[pdb] = &FormatParserStorage::addParser<PdbParser>; 80 ParserAddFunction[tremolo] = &FormatParserStorage::addParser<TremoloParser>; 81 ParserAddFunction[xyz] = &FormatParserStorage::addParser<XyzParser>; 61 #define insert_invert_print(z,n,seq,map, before, after) \ 62 map .insert( std::make_pair( before < \ 63 BOOST_PP_SEQ_ELEM(n, seq) \ 64 > after, \ 65 BOOST_PP_SEQ_ELEM(n, seq) \ 66 ) ); 67 68 // fill ParserNames 69 #if defined ParserTypes_END // do we have parameters at all? 70 #define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserNames, FormatParserTrait, ::name) 71 #define BOOST_PP_LOCAL_LIMITS (0, ParserTypes_END-1) 72 #include BOOST_PP_LOCAL_ITERATE() 73 #endif 74 75 // fill ParserLookupNames 76 #if defined ParserTypes_END // do we have parameters at all? 77 #define BOOST_PP_LOCAL_MACRO(n) insert_invert_print(~, n, PARSERSEQUENCE, ParserLookupNames, FormatParserTrait, ::name) 78 #define BOOST_PP_LOCAL_LIMITS (0, ParserTypes_END-1) 79 #include BOOST_PP_LOCAL_ITERATE() 80 #endif 81 82 // fill ParserSuffixes 83 #if defined ParserTypes_END // do we have parameters at all? 84 #define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserSuffixes, FormatParserTrait, ::suffix) 85 #define BOOST_PP_LOCAL_LIMITS (0, ParserTypes_END-1) 86 #include BOOST_PP_LOCAL_ITERATE() 87 #endif 88 89 // fill ParserLookupSuffixes 90 #if defined ParserTypes_END // do we have parameters at all? 91 #define BOOST_PP_LOCAL_MACRO(n) insert_invert_print(~, n, PARSERSEQUENCE, ParserLookupSuffixes, FormatParserTrait, ::suffix) 92 #define BOOST_PP_LOCAL_LIMITS (0, ParserTypes_END-1) 93 #include BOOST_PP_LOCAL_ITERATE() 94 #endif 95 96 // fill ParserAddFunction 97 #if defined ParserTypes_END // do we have parameters at all? 98 #define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserAddFunction, &FormatParserStorage::addParser, ) 99 #define BOOST_PP_LOCAL_LIMITS (0, ParserTypes_END-1) 100 #include BOOST_PP_LOCAL_ITERATE() 101 #endif 102 103 #undef insert_print 104 #undef insert_invert_print 105 #include "ParserTypes.undef" 106 107 //std::cout << "ParserNames:" << std::endl << ParserNames << std::endl; 108 //std::cout << "ParserSuffixes:" << std::endl << ParserSuffixes << std::endl; 109 //std::cout << "ParserLookupNames:" << std::endl << ParserLookupNames << std::endl; 110 //std::cout << "ParserLookupSuffixes:" << std::endl << ParserLookupSuffixes << std::endl; 111 //std::cout << "ParserAddFunction:" << std::endl << ParserAddFunction << std::endl; 112 82 113 } 83 114 … … 142 173 if (ptype != ParserTypes_end) { 143 174 if (ParserAddFunction.find(ptype) != ParserAddFunction.end()) { 144 DoLog(0) && (Log() << Verbose(0) << "Adding " << ParserNames[ptype] << " type to output." << endl);175 LOG(0, "STATUS: Adding " << ParserNames[ptype] << " type to output."); 145 176 (getInstance().*(ParserAddFunction[ptype]))(); // we still need an object to work on ... 146 177 return true; 147 178 } else { 148 DoeLog(1) && (eLog() << Verbose(1) << "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?" << endl);179 ELOG(1, "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?"); 149 180 return false; 150 181 } … … 156 187 bool FormatParserStorage::add(std::string type) 157 188 { 158 return add(getTypeFromName(type)); 189 enum ParserTypes Ptype = getTypeFromName(type); 190 return add(Ptype); 159 191 } 160 192 … … 246 278 * \return reference to the output FormatParser with desired type 247 279 */ 248 FormatParser &FormatParserStorage::get(ParserTypes _type)280 FormatParserInterface &FormatParserStorage::get(ParserTypes _type) 249 281 { 250 282 if (!ParserPresent[_type]) { -
src/Parser/FormatParserStorage.hpp
r9a6b76e r765f16 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/ParserTypes.hpp" 23 #include "Parser/FormatParser.hpp" 24 #include "Parser/MpqcParser.hpp" 25 #include "Parser/PcpParser.hpp" 26 #include "Parser/PdbParser.hpp" 27 #include "Parser/TremoloParser.hpp" 28 #include "Parser/XyzParser.hpp" 23 #include "CodePatterns/Assert.hpp" 24 #include "CodePatterns/Log.hpp" 25 #include "FormatParser.hpp" 26 #include "ParserTypes.hpp" 29 27 30 28 class atom; 31 32 template <class T> enum ParserTypes getPType(); 33 template <> enum ParserTypes getPType<MpqcParser>(); 34 template <> enum ParserTypes getPType<PcpParser>(); 35 template <> enum ParserTypes getPType<PdbParser>(); 36 template <> enum ParserTypes getPType<TremoloParser>(); 37 template <> enum ParserTypes getPType<XyzParser>(); 38 29 class FormatParserInterface; 39 30 40 31 class FormatParserStorage : public Singleton<FormatParserStorage> { … … 51 42 bool saveWorld(std::ostream &output, std::string suffix); 52 43 53 FormatParser &get(enumParserTypes _type);44 FormatParserInterface &get(ParserTypes _type); 54 45 55 46 ParserTypes getTypeFromName(std::string type); … … 65 56 66 57 // list of allocated parsers 67 std::vector<FormatParser *> ParserList;58 std::vector<FormatParserInterface *> ParserList; 68 59 69 60 // list of allocated strams … … 84 75 std::map<std::string, ParserTypes> ParserLookupNames; 85 76 86 87 77 // prefix of the filenames to use on save 88 78 std::string prefix; 89 79 90 80 public: 91 92 template<class ParserT> void addParser() 81 template<ParserTypes Ptype> void addParser() 93 82 { 94 enum ParserTypes Ptype = getPType<ParserT>();95 83 if (!ParserPresent[Ptype]) { 96 ParserList[Ptype] = new ParserT();84 ParserList[Ptype] = new FormatParser<Ptype>(); 97 85 ParserPresent[Ptype] = true; 98 86 } else { … … 108 96 } 109 97 110 template< class ParserT> ParserT&getParser()98 template<ParserTypes Ptype> FormatParser<Ptype> &getParser() 111 99 { 112 enum ParserTypes Ptype = getPType<ParserT>();113 100 if(!ParserPresent[Ptype]) 114 addParser< ParserT>();115 return dynamic_cast< ParserT&>(*ParserList[Ptype]);101 addParser< Ptype >(); 102 return dynamic_cast<FormatParser<Ptype> &>(*ParserList[Ptype]); 116 103 } 117 118 104 }; 119 105 -
src/Parser/FormatParser_common.cpp
r9a6b76e r765f16 7 7 8 8 /* 9 * FormatParser .cpp9 * FormatParser_common_common.cpp 10 10 * 11 11 * Created on: Mar 1, 2010 … … 20 20 #include "CodePatterns/MemDebug.hpp" 21 21 22 #include "FormatParser.hpp"23 22 #include <iostream> 23 24 #include "CodePatterns/Observer.hpp" 25 #include "World.hpp" 26 #include "ChangeTracker.hpp" 27 #include "FormatParser_common.hpp" 24 28 25 29 using namespace std; … … 28 32 * Constructor. 29 33 */ 30 FormatParser::FormatParser() : 31 Observer("FormatParser"), 32 parameters(NULL), 33 saveStream(NULL) 34 FormatParser_common::FormatParser_common(FormatParser_Parameters *_parameters) : 35 Observer("FormatParser_common") 34 36 { 37 parameters = _parameters; 35 38 ChangeTracker::getInstance().signOn(this); 36 39 World::getInstance().signOn(this, World::getInstance().getChannel(World::AtomInserted)); … … 41 44 * Destructor. 42 45 */ 43 FormatParser::~FormatParser() { 46 FormatParser_common::~FormatParser_common() 47 { 44 48 ChangeTracker::getInstance().signOff(this); 45 49 World::getInstance().signOff(this, World::getInstance().getChannel(World::AtomInserted)); 46 50 World::getInstance().signOff(this, World::getInstance().getChannel(World::AtomRemoved)); 51 if (parameters != NULL) 52 delete parameters; 47 53 } 48 54 … … 51 57 * change tracker here). 52 58 */ 53 void FormatParser ::update(Observable *publisher) {59 void FormatParser_common::update(Observable *publisher) { 54 60 if (!saveStream) { 55 61 cerr << "Please invoke setOstream() so the parser knows where to save the World's data." << endl; … … 64 70 * With this, each format parser is informed about specific changes in the World. 65 71 */ 66 void FormatParser ::recieveNotification(Observable *publisher, Notification_ptr notification) {72 void FormatParser_common::recieveNotification(Observable *publisher, Notification_ptr notification) { 67 73 switch (notification->getChannelNo()) { 68 74 case World::AtomInserted: … … 74 80 default: 75 81 ASSERT(0, 76 "FormatParser ::recieveNotification() - unknown notification "82 "FormatParser_common::recieveNotification() - unknown notification " 77 83 +toString(notification->getChannelNo())+" received."); 78 84 break; … … 83 89 * The observable can tell when it dies. 84 90 */ 85 void FormatParser::subjectKilled(Observable *publisher) {} 86 91 void FormatParser_common::subjectKilled(Observable *publisher) {} 87 92 88 93 /** … … 92 97 * \param ostream where to save the World's state 93 98 */ 94 void FormatParser ::setOstream(ostream* output) {99 void FormatParser_common::setOstream(ostream* output) { 95 100 saveStream = output; 96 101 } -
src/Parser/Makefile.am
r9a6b76e r765f16 5 5 PARSERSOURCE = \ 6 6 Parser/ChangeTracker.cpp \ 7 Parser/FormatParser .cpp \7 Parser/FormatParser_common.cpp \ 8 8 Parser/FormatParserStorage.cpp \ 9 9 Parser/MpqcParser.cpp \ 10 10 Parser/MpqcParser_Parameters.cpp \ 11 11 Parser/MpqcParser_Parameters_initBasis.cpp \ 12 Parser/ParserTypes.cpp \ 12 13 Parser/PcpParser.cpp \ 13 14 Parser/PdbAtomInfoContainer.cpp \ … … 20 21 Parser/ChangeTracker.hpp \ 21 22 Parser/FormatParser.hpp \ 23 Parser/FormatParser_specializations_header.hpp \ 24 Parser/FormatParser_common.hpp \ 25 Parser/FormatParserInterface.hpp \ 26 Parser/FormatParserTrait.hpp \ 27 Parser/FormatParserTrait_specializations_header.hpp \ 22 28 Parser/FormatParser_Parameters.hpp \ 23 29 Parser/FormatParserStorage.hpp \ 24 30 Parser/MpqcParser.hpp \ 25 31 Parser/MpqcParser_Parameters.hpp \ 32 Parser/ParserTypes.hpp \ 33 Parser/ParserTypes.def \ 34 Parser/ParserTypes.undef \ 26 35 Parser/PcpParser.hpp \ 27 36 Parser/PdbAtomInfoContainer.hpp \ -
src/Parser/MpqcParser.cpp
r9a6b76e r765f16 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; 40 44 41 45 /** Constructor of MpqcParser. 42 46 * 43 47 */ 44 MpqcParser::MpqcParser() 45 { 46 parameters = new MpqcParser_Parameters(); 47 } 48 FormatParser< mpqc >::FormatParser() : 49 FormatParser_common(new MpqcParser_Parameters()) 50 {} 48 51 49 52 /** Destructor of MpqcParser. 50 53 * 51 54 */ 52 MpqcParser::~MpqcParser() 53 { 54 delete parameters; 55 } 55 FormatParser< mpqc >::~FormatParser() 56 {} 56 57 57 58 /** Load an MPQC config file into the World. 58 59 * \param *file input stream 59 60 */ 60 void MpqcParser::load(istream *file)61 void FormatParser< mpqc >::load(istream *file) 61 62 { 62 63 bool MpqcSection = false; … … 96 97 tokenizer::iterator tok_iter = tokens.begin(); 97 98 ASSERT(tok_iter != tokens.end(), 98 " MpqcParser::load() - missing token for MoleculeSection in line "+linestring+"!");99 "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!"); 99 100 std::stringstream whitespacefilter(*tok_iter++); 100 101 std::string element; 101 102 whitespacefilter >> ws >> element; 102 103 ASSERT(tok_iter != tokens.end(), 103 " MpqcParser::load() - missing token for MoleculeSection in line "+linestring+"!");104 "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!"); 104 105 std::string vector = *tok_iter; 105 106 tokenizer vectorcomponents(vector, whitesep); … … 125 126 ++tok_iter; 126 127 ASSERT(tok_iter != tokens.end(), 127 " MpqcParser::load() - missing token in brackets<> for mole< in line "+linestring+"!");128 "FormatParser< mpqc >::load() - missing token in brackets<> for mole< in line "+linestring+"!"); 128 129 std::string value(*tok_iter); 129 130 std::stringstream linestream("theory = "+value); … … 134 135 ++tok_iter; 135 136 ASSERT(tok_iter != tokens.end(), 136 " MpqcParser::load() - missing token in brackets<> for integrals< in line "+linestring+"!");137 "FormatParser< mpqc >::load() - missing token in brackets<> for integrals< in line "+linestring+"!"); 137 138 std::string value(*tok_iter); 138 139 std::stringstream linestream("integration = "+value); … … 143 144 tokenizer::iterator tok_iter = tokens.begin(); 144 145 ASSERT(tok_iter != tokens.end(), 145 " MpqcParser::load() - missing token before '=' for MpqcSection in line "+linestring+"!");146 "FormatParser< mpqc >::load() - missing token before '=' for MpqcSection in line "+linestring+"!"); 146 147 std::stringstream whitespacefilter(*tok_iter); 147 148 std::string key; … … 159 160 tokenizer::iterator tok_iter = tokens.begin(); 160 161 ASSERT(tok_iter != tokens.end(), 161 " MpqcParser::load() - missing token for BasisSection in line "+linestring+"!");162 "FormatParser< mpqc >::load() - missing token for BasisSection in line "+linestring+"!"); 162 163 std::string key(*tok_iter++); 163 164 ASSERT(tok_iter != tokens.end(), 164 " MpqcParser::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");165 "FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!"); 165 166 std::string value(*tok_iter); 166 167 tok_iter++; 167 168 // TODO: use exception instead of ASSERT 168 169 ASSERT(tok_iter == tokens.end(), 169 " MpqcParser::load() - more than (key = value) on line "+linestring+".");170 "FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+"."); 170 171 if (key == "name") { 171 172 std::stringstream linestream("basis = "+value); … … 177 178 tokenizer::iterator tok_iter = tokens.begin(); 178 179 ASSERT(tok_iter != tokens.end(), 179 " MpqcParser::load() - missing token for AuxBasisSection in line "+linestring+"!");180 "FormatParser< mpqc >::load() - missing token for AuxBasisSection in line "+linestring+"!"); 180 181 std::string key(*tok_iter++); 181 182 ASSERT(tok_iter != tokens.end(), 182 " MpqcParser::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");183 "FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!"); 183 184 std::string value(*tok_iter); 184 185 tok_iter++; 185 186 // TODO: use exception instead of ASSERT 186 187 ASSERT(tok_iter == tokens.end(), 187 " MpqcParser::load() - more than (key = value) on line "+linestring+".");188 "FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+"."); 188 189 if (key == "name") { 189 190 std::stringstream linestream("aux_basis = "+value); … … 216 217 * \param atoms atoms to store 217 218 */ 218 void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms)219 void FormatParser< mpqc >::save(ostream *file, const std::vector<atom *> &atoms) 219 220 { 220 221 Vector center; -
src/Parser/MpqcParser.hpp
r9a6b76e r765f16 16 16 17 17 #include "FormatParser.hpp" 18 #include "FormatParserTrait.hpp" 19 #include "FormatParserInterface.hpp" 20 #include "FormatParser_common.hpp" 21 #include "ParserTypes.hpp" 22 18 23 #include "MpqcParser_Parameters.hpp" 19 24 20 25 #include <iosfwd> 21 26 27 // declaration of specialized FormatParserTrait 28 template<> 29 struct FormatParserTrait<mpqc> 30 { 31 //!> Name of the parser 32 static const std::string name; 33 //!> suffix of the files the parser understands to read and write 34 static const std::string suffix; 35 //!> ParserTypes enumeration for the parser 36 static const enum ParserTypes type; 37 }; 38 22 39 /** 23 40 * Loads a MPQC config file into the World and saves the World as a tremolo file. 24 41 */ 25 class MpqcParser : public FormatParser 42 template <> 43 class FormatParser< mpqc > : virtual public FormatParserInterface, public FormatParser_common 26 44 { 27 45 friend class ParserMpqcUnitTest; 28 46 public: 47 FormatParser(); 48 virtual ~FormatParser(); 29 49 30 MpqcParser(); 31 virtual ~MpqcParser(); 32 void load(std::istream* file); 33 void save(std::ostream* file, const std::vector<atom *> &atoms); 50 void load(std::istream *file); 51 void save(std::ostream *file, const std::vector<atom *> &atoms); 34 52 35 53 /** Getter for parameter set. -
src/Parser/ParserTypes.hpp
r9a6b76e r765f16 14 14 #endif 15 15 16 // enum has to be outside of class for operator++ to be possible 17 enum ParserTypes { mpqc, pcp, pdb, tremolo, xyz, ParserTypes_end, ParserTypes_begin = mpqc }; 16 #include <boost/preprocessor/seq/elem.hpp> 17 #include <boost/preprocessor/seq/seq.hpp> 18 #include <boost/preprocessor/seq/size.hpp> 19 #include <boost/preprocessor/iteration/local.hpp> 20 21 22 #include "ParserTypes.def" 23 24 //!> function to print each member of the sequence in the enumeration 25 #define sequence_print(z,n,seq) \ 26 BOOST_PP_SEQ_ELEM(n, seq) , 27 28 //!> Enumeration of all known parsers 29 enum ParserTypes { 30 // some proprocessor magic to generate the body from the above sequence 31 #if defined ParserTypes_END // do we have parameters at all? 32 #define BOOST_PP_LOCAL_MACRO(n) sequence_print(~, n, PARSERSEQUENCE) 33 #define BOOST_PP_LOCAL_LIMITS (0, ParserTypes_END-1) 34 #include BOOST_PP_LOCAL_ITERATE() 35 #undef BOOST_PP_LOCAL_MACRO 36 #undef BOOST_PP_LOCAL_LIMITS 37 #endif 38 ParserTypes_end = ParserTypes_END, 39 ParserTypes_begin = BOOST_PP_SEQ_HEAD(PARSERSEQUENCE) 40 }; 41 42 #undef sequence_print 43 44 //!> Number of known ParserTypes 45 const size_t ParserTypesMax = ParserTypes_END; 46 47 #include "ParserTypes.undef" 48 49 //!> Typedef for enumeration to ease its use 18 50 typedef enum ParserTypes ParserTypes; 51 52 /** Increment operator for the enumeration ParserTypes to allow loops. 53 * \param &type value 54 * \return value incremented by one 55 */ 56 ParserTypes &operator++(ParserTypes &type); 19 57 20 58 #endif /* PARSERTYPES_HPP_ */ -
src/Parser/PcpParser.cpp
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 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/ParserMpqcUnitTest.cpp
r9a6b76e r765f16 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 … … 157 159 158 160 void ParserMpqcUnitTest::setUp() { 159 mpqc = new MpqcParser();161 parser = new FormatParser<mpqc>(); 160 162 161 163 World::getInstance(); … … 169 171 170 172 void ParserMpqcUnitTest::tearDown() { 171 delete mpqc;173 delete parser; 172 174 ChangeTracker::purgeInstance(); 173 175 World::purgeInstance(); … … 178 180 void ParserMpqcUnitTest::ParameterTypeTest() { 179 181 // check types in boost::any map 180 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));181 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int));182 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));183 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));184 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));185 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int));186 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));187 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));188 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));189 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));190 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));191 CPPUNIT_ASSERT( mpqc->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));182 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool)); 183 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int)); 184 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool)); 185 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool)); 186 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int)); 187 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int)); 188 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string)); 189 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int)); 190 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string)); 191 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string)); 192 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints)); 193 CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2)); 192 194 } 193 195 194 196 void ParserMpqcUnitTest::ParameterDefaultTest() { 195 197 // 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);198 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "no"); 199 CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::hessianParam)); 200 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::savestateParam) == "no"); 201 CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::savestateParam)); 202 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes"); 203 CPPUNIT_ASSERT(parser->getParams().getBool(MpqcParser_Parameters::do_gradientParam)); 204 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000); 205 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000); 206 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'"); 207 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1); 208 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G"); 209 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ"); 210 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints"); 211 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2"); 212 CPPUNIT_ASSERT(parser->getParams().getTheory() == MpqcParser_Parameters::MBPT2); 213 CPPUNIT_ASSERT(parser->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints); 212 214 213 215 // check that values are not removed 214 CPPUNIT_ASSERT(! mpqc->getParams().params[MpqcParser_Parameters::theoryParam].empty());216 CPPUNIT_ASSERT(!parser->getParams().params[MpqcParser_Parameters::theoryParam].empty()); 215 217 216 218 // 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 CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast); 220 CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast); 219 221 220 222 } 221 223 222 224 void ParserMpqcUnitTest::ParameterCloneTest() { 223 FormatParser_Parameters *clone = mpqc->getParams().clone();224 CPPUNIT_ASSERT( mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");225 FormatParser_Parameters *clone = parser->getParams().clone(); 226 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2"); 225 227 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");228 setvalue >> parser->getParams(); 229 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF"); 230 parser->getParams().makeClone(*clone); 231 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2"); 230 232 } 231 233 … … 234 236 { 235 237 std::stringstream setvalue("theory = CLHF"); 236 setvalue >> mpqc->getParams();238 setvalue >> parser->getParams(); 237 239 // std::cout << "integration method is " 238 // << mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;239 CPPUNIT_ASSERT( mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");240 // << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl; 241 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF"); 240 242 } 241 243 // test a bool 242 244 { 243 245 std::stringstream setvalue("Hessian = yes"); 244 setvalue >> mpqc->getParams();246 setvalue >> parser->getParams(); 245 247 // std::cout << "Hessian is " 246 // << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;247 CPPUNIT_ASSERT( mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");248 // << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl; 249 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes"); 248 250 } 249 251 // test int 250 252 { 251 253 std::stringstream setvalue("maxiter = 500"); 252 setvalue >> mpqc->getParams();254 setvalue >> parser->getParams(); 253 255 // std::cout << "maxiter is " 254 // << mpqc->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;255 CPPUNIT_ASSERT( mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);256 // << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl; 257 CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500); 256 258 } 257 259 // test whether unknown key fails … … 261 263 #ifndef NDEBUG 262 264 ASSERT_DO(Assert::Throw); 263 CPPUNIT_ASSERT_THROW(setvalue >> mpqc->getParams(), Assert::AssertionFailure);265 CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure); 264 266 #else 265 setvalue >> mpqc->getParams();267 setvalue >> parser->getParams(); 266 268 #endif 267 269 // std::cout << "Hessian is still " 268 // << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;269 CPPUNIT_ASSERT( mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");270 // << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl; 271 CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes"); 270 272 } 271 273 } … … 273 275 void ParserMpqcUnitTest::readMpqcTest() { 274 276 stringstream input(waterMpqc_CLHF); 275 mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);276 mpqc->load(&input);277 parser->getParams().setTheory(MpqcParser_Parameters::CLHF); 278 parser->load(&input); 277 279 278 280 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); … … 301 303 // compare both configs for CLHF 302 304 stringstream output; 303 mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);304 mpqc->save(&output, atoms);305 parser->getParams().setTheory(MpqcParser_Parameters::CLHF); 306 parser->save(&output, atoms); 305 307 stringstream input(waterMpqc_CLHF); 306 308 for (; std::getline(input, first) && std::getline(output, second); ) { … … 312 314 // compare both configs for CLKS 313 315 stringstream output; 314 mpqc->getParams().setTheory(MpqcParser_Parameters::CLKS);315 mpqc->save(&output, atoms);316 parser->getParams().setTheory(MpqcParser_Parameters::CLKS); 317 parser->save(&output, atoms); 316 318 stringstream input(waterMpqc_CLKS); 317 319 for (; std::getline(input, first) && std::getline(output, second); ) { … … 323 325 // compare both configs for MBPT2 324 326 stringstream output; 325 mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2);326 mpqc->save(&output, atoms);327 parser->getParams().setTheory(MpqcParser_Parameters::MBPT2); 328 parser->save(&output, atoms); 327 329 stringstream input(waterMpqc_MBPT2); 328 330 for (; std::getline(input, first) && std::getline(output, second); ) { … … 334 336 // compare both configs for MBPT2_R12 335 337 stringstream output; 336 mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12);337 mpqc->save(&output, atoms);338 parser->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12); 339 parser->save(&output, atoms); 338 340 stringstream input(waterMpqc_MBPT2_R12); 339 341 for (; std::getline(input, first) && std::getline(output, second); ) { -
src/Parser/unittests/ParserMpqcUnitTest.hpp
r9a6b76e r765f16 41 41 42 42 private: 43 MpqcParser *mpqc;43 FormatParser<mpqc> *parser; 44 44 }; 45 45 -
src/Parser/unittests/ParserPcpUnitTest.cpp
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 27 27 #include "Descriptors/AtomTypeDescriptor.hpp" 28 28 #include "element.hpp" 29 #include "Parser/MpqcParser.hpp"30 #include "Parser/PdbParser.hpp"31 #include "Parser/PcpParser.hpp"32 29 #include "Parser/TremoloParser.hpp" 33 #include "Parser/ XyzParser.hpp"30 #include "Parser/ChangeTracker.hpp" 34 31 #include "periodentafel.hpp" 35 32 #include "World.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
r9a6b76e r765f16 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
r9a6b76e r765f16 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
r9a6b76e r765f16 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/moleculelist.cpp
r9a6b76e r765f16 626 626 // atoms.resize((*ListRunner)->getAtomCount()); 627 627 // std::copy((*ListRunner)->begin(), (*ListRunner)->end(), atoms.begin()); 628 FormatParserStorage::getInstance().get Parser<MpqcParser>().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.";
Note:
See TracChangeset
for help on using the changeset viewer.