Changeset 9131f3
- Timestamp:
- Mar 30, 2010, 1:22:20 PM (15 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:
- 4415da
- Parents:
- cb2146
- Location:
- src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Makefile.am
rcb2146 r9131f3 11 11 ACTIONSHEADER = Actions/Action.hpp Actions/Process.hpp Actions/Calculation.hpp Actions/Calculation_impl.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp Actions/small_actions.hpp Actions/ManipulateAtomsProcess.hpp Actions/ActionRegistry.hpp 12 12 13 PARSERSOURCE = Parser/ChangeTracker.cpp Parser/FormatParser.cpp Parser/ XyzParser.cpp14 PARSERHEADER = Parser/ChangeTracker.hpp Parser/FormatParser.hpp Parser/ XyzParser.hpp13 PARSERSOURCE = Parser/ChangeTracker.cpp Parser/FormatParser.cpp Parser/TremoloParser.cpp Parser/XyzParser.cpp 14 PARSERHEADER = Parser/ChangeTracker.hpp Parser/FormatParser.hpp Parser/TremoloParser.hpp Parser/XyzParser.hpp 15 15 16 16 PATTERNSOURCE = Patterns/Observer.cpp -
src/Parser/FormatParser.cpp
rcb2146 r9131f3 7 7 8 8 #include "FormatParser.hpp" 9 #include <iostream> 9 10 10 11 using namespace std; … … 31 32 void FormatParser::update(Observable *publisher) { 32 33 if (!saveStream) { 33 // throw new Exception("Please invoke setOfstream() so the parser knows where to save the World's data."); 34 cerr << "Please invoke setOstream() so the parser knows where to save the World's data." << endl; 35 return; 34 36 } 35 37 -
src/Parser/TremoloParser.cpp
rcb2146 r9131f3 6 6 */ 7 7 8 void TremoloParser::load(char* fileName) { 9 MatrixContainer* data = readData(fileName, getHeaderSize('#'), 0); 10 store additional data 11 for (each line in matrix) { 12 add atom to the world 13 } 8 #include "TremoloParser.hpp" 9 #include "World.hpp" 10 #include "atom.hpp" 11 #include "element.hpp" 12 #include "periodentafel.hpp" 13 #include <map> 14 #include <vector> 15 16 using namespace std; 17 18 /** 19 * Constructor. 20 */ 21 TremoloParser::TremoloParser() { 22 knownKeys["x"] = x; 23 knownKeys["u"] = u; 24 knownKeys["F"] = F; 25 knownKeys["stress"] = stress; 26 knownKeys["Id"] = Id; 27 knownKeys["neighbors"] = neighbors; 28 knownKeys["imprData"] = imprData; 29 knownKeys["GroupMeasureTypeNo"] = GroupMeasureTypeNo; 30 knownKeys["Type"] = Type; 31 knownKeys["extType"] = extType; 32 knownKeys["name"] = name; 33 knownKeys["resName"] = resName; 34 knownKeys["chainID"] = chainID; 35 knownKeys["resSeq"] = resSeq; 36 knownKeys["occupancy"] = occupancy; 37 knownKeys["tempFactor"] = tempFactor; 38 knownKeys["segID"] = segID; 39 knownKeys["Charge"] = Charge; 40 knownKeys["charge"] = charge; 41 knownKeys["GrpTypeNo"] = GrpTypeNo; 14 42 } 15 43 16 void TremoloParser::save(char* fileName) { 44 /** 45 * Destructor. 46 */ 47 TremoloParser::~TremoloParser() { 48 } 49 50 /** 51 * Stores keys from the ATOMDATA line. 52 * 53 * \param line to parse the keys from 54 * \param with which offset the keys begin within the line 55 */ 56 void TremoloParser::parseAtomDataKeysLine(string line, int offset) { 57 string keyword; 58 stringstream lineStream; 59 60 lineStream << line.substr(offset); 61 while (lineStream.good()) { 62 lineStream >> keyword; 63 usedFields.push_back(keyword); 64 } 65 } 66 67 /** 68 * Reads one data line of a tremolo file and interprets it according to the keys 69 * obtained from the ATOMDATA line. 70 * 71 * \param line to parse as an atom 72 */ 73 void TremoloParser::readAtomDataLine(string line) { 74 vector<string>::iterator it; 75 stringstream lineStream; 76 string word; 77 78 lineStream << line; 79 for (it=usedFields.begin(); it < usedFields.end(); it++) { 80 cout << *it << " -- " << it->substr(0, it->find("=")) << " -- " << knownKeys[it->substr(0, it->find("="))] << endl; 81 switch (knownKeys[it->substr(0, it->find("="))]) { 82 case x : 83 lineStream >> word; 84 cout<< "Found an x: word: " << word << endl; 85 break; 86 default : 87 lineStream >> word; 88 cout << "Unknown key: " << *it << ", word: " << word << endl; 89 break; 90 } 91 } 92 } 93 94 95 /** 96 * Loads atoms from a tremolo-formatted file. 97 * 98 * \param tremolo file 99 */ 100 void TremoloParser::load(istream* file) { 101 string line; 102 string::size_type location; 103 104 usedFields.clear(); 105 while (file->good()) { 106 std::getline(*file, line, '\n'); 107 if (usedFields.empty()) { 108 location = line.find("ATOMDATA", 0); 109 if (location != string::npos) { 110 parseAtomDataKeysLine(line, location + 8); 111 } 112 } 113 if (line.length() > 0 && line.at(0) != '#') { 114 readAtomDataLine(line); 115 } 116 } 117 } 118 119 /* 120 #ATOMDATA <record_entry_1> ... <record_entry_n> 121 # <record_entry>: <dataname>[=<n>] 122 # <dataname> : x | u | F | stress | Id | neighbors | imprData 123 # | GroupMeasureTypeNo | Type | extType 124 # | name | resName | chainID | resSeq 125 # | occupancy | tempFactor | segID | Charge 126 # | charge 127 ATOMDATA name Id x=3 mass charge epsilon sigma eps14 sig14 name type protein protno neighbors=4 128 */ 129 130 //MatrixContainer* data = readData(fileName, getHeaderSize('#'), 0); 131 132 133 /** 134 * Saves the World's current state into as a tremolo file. 135 * 136 * \param file where to save the state 137 */ 138 void TremoloParser::save(ostream* file) { 139 /* 17 140 write header 18 141 for (each atom in world) { 19 142 write coordinates and additional data 20 143 } 144 */ 21 145 } -
src/Parser/TremoloParser.hpp
rcb2146 r9131f3 9 9 #define TREMOLOPARSER_HPP_ 10 10 11 #include <string> 11 12 #include "FormatParser.hpp" 12 #include "World.hpp"13 13 14 class TremoloParser : public FormatParser { 14 class TremoloParser:public FormatParser 15 { 15 16 public: 16 void load(char* fileName); 17 void save(char* fileName); 17 TremoloParser(); 18 ~TremoloParser(); 19 void load(std::istream* file); 20 void save(std::ostream* file); 18 21 19 22 private: 20 map<std::string, std::string> moreData; 23 void readAtomDataLine(string line); 24 void parseAtomDataKeysLine(string line, int offset); 25 26 /** 27 * Known keys for the ATOMDATA line. 28 */ 29 enum StringValue { 30 x, 31 u, 32 F, 33 stress, 34 Id, 35 neighbors, 36 imprData, 37 GroupMeasureTypeNo, 38 Type, 39 extType, 40 name, 41 resName, 42 chainID, 43 resSeq, 44 occupancy, 45 tempFactor, 46 segID, 47 Charge, 48 charge, 49 GrpTypeNo 50 }; 51 52 /** 53 * Map to associate the known keys with numbers. 54 */ 55 std::map<std::string, StringValue> knownKeys; 56 57 /** 58 * Fields used in the tremolo file. 59 */ 60 std::vector<std::string> usedFields; 61 62 /** 63 * Data which is currently not stored in atoms but was provided by the input 64 * file. 65 */ 66 std::map<std::string, std::string> moreData; 21 67 }; 22 68 -
src/unittests/Makefile.am
rcb2146 r9131f3 55 55 bondgraphunittest.cpp \ 56 56 CacheableTest.cpp \ 57 DescriptorUnittest.cpp \58 57 gslmatrixsymmetricunittest.cpp \ 59 58 gslmatrixunittest.cpp \ -
src/unittests/ParserUnitTest.cpp
rcb2146 r9131f3 13 13 14 14 #include "Parser/XyzParser.hpp" 15 #include "Parser/TremoloParser.hpp" 15 16 #include "World.hpp" 16 17 #include "element.hpp" … … 45 46 46 47 void ParserUnitTest::rewriteAnXyzTest() { 48 cout << "Testing the XYZ parser." << endl; 47 49 XyzParser* testParser = new XyzParser(); 48 50 string waterXyz = "3\nH2O: water molecule\nO\t0.000000\t0.000000\t0.000000\nH\t0.758602\t0.000000\t0.504284\nH\t0.758602\t0.000000\t-0.504284\n"; … … 61 63 } 62 64 65 void ParserUnitTest::rewriteTremoloTest() { 66 cout << "Testing the tremolo parser." << endl; 67 TremoloParser* testParser = new TremoloParser(); 68 string waterTremolo = "#\n# ATOMDATA Id name Type x=3\n\n\n"; 69 stringstream input; 70 input << waterTremolo; 71 testParser->load(&input); 72 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen 3.0 4.5 0.1\n\n"; 73 input.clear(); 74 input << waterTremolo; 75 testParser->load(&input); 76 cout << "testing the tremolo parser is done" << endl; 77 } -
src/unittests/ParserUnitTest.hpp
rcb2146 r9131f3 15 15 CPPUNIT_TEST_SUITE( ParserUnitTest ) ; 16 16 CPPUNIT_TEST ( rewriteAnXyzTest ); 17 CPPUNIT_TEST ( rewriteTremoloTest ); 17 18 CPPUNIT_TEST_SUITE_END(); 18 19 … … 22 23 23 24 void rewriteAnXyzTest(); 25 void rewriteTremoloTest(); 24 26 }; 25 27
Note:
See TracChangeset
for help on using the changeset viewer.