Changeset fd4905 for src/Parser
- Timestamp:
- Aug 28, 2010, 1:45:13 AM (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:
- 6c438f
- Parents:
- 8fd934 (diff), 653542 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/Parser
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/FormatParserStorage.cpp
r8fd934 rfd4905 28 28 #include "Parser/MpqcParser.hpp" 29 29 #include "Parser/PcpParser.hpp" 30 #include "Parser/PdbParser.hpp" 30 31 #include "Parser/TremoloParser.hpp" 31 32 #include "Parser/XyzParser.hpp" … … 56 57 ParserSuffix.resize(ParserTypes_end, ""); 57 58 59 ParserNames[mpqc] = "mpqc"; 60 ParserNames[pcp] = "pcp"; 61 ParserNames[pdb] = "pdb"; 62 ParserNames[tremolo] = "tremolo"; 63 ParserNames[xyz] = "xyz"; 64 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 58 68 ParserSuffix[mpqc] = "in"; 59 69 ParserSuffix[pcp] = "conf"; 70 ParserSuffix[pdb] = "pdb"; 60 71 ParserSuffix[tremolo] = "data"; 61 72 ParserSuffix[xyz] = "xyz"; 73 74 ParserAddFunction[mpqc] = &FormatParserStorage::addMpqc; 75 ParserAddFunction[pcp] = &FormatParserStorage::addPcp; 76 ParserAddFunction[pdb] = &FormatParserStorage::addPdb; 77 ParserAddFunction[tremolo] = &FormatParserStorage::addTremolo; 78 ParserAddFunction[xyz] = &FormatParserStorage::addXyz; 62 79 } 63 80 … … 112 129 } 113 130 131 114 132 /** Adds an PcpParser to the storage. 115 133 */ … … 124 142 125 143 144 /** Adds an PdbParser to the storage. 145 */ 146 void FormatParserStorage::addPdb() 147 { 148 if (!ParserPresent[pdb]) { 149 ParserList[pdb] = new PdbParser(); 150 ParserPresent[pdb] = true; 151 } else 152 DoeLog(1) && (eLog() << Verbose(1) << "Parser pdb is already present." << endl); 153 } 154 155 126 156 /** Adds an TremoloParser to the storage. 127 157 */ … … 146 176 DoeLog(1) && (eLog() << Verbose(1) << "Parser xyz is already present." << endl); 147 177 } 178 179 ParserTypes FormatParserStorage::getType(std::string type) 180 { 181 if (ParserLookupNames.find(type) == ParserLookupNames.end()) { 182 DoeLog(1) && (eLog() << Verbose(1) << "Unknown type " << type << "." << endl); 183 return ParserTypes_end; 184 } else 185 return ParserLookupNames[type]; 186 } 187 188 bool FormatParserStorage::add(ParserTypes ptype) 189 { 190 if (ptype != ParserTypes_end) { 191 if (ParserAddFunction.find(ptype) != ParserAddFunction.end()) { 192 DoLog(0) && (Log() << Verbose(0) << "Adding " << ParserNames[ptype] << " type to output." << endl); 193 (getInstance().*(ParserAddFunction[ptype]))(); // we still need an object to work on ... 194 return true; 195 } else { 196 DoeLog(1) && (eLog() << Verbose(1) << "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?" << endl); 197 return false; 198 } 199 } else { 200 return false; 201 } 202 } 203 204 bool FormatParserStorage::add(std::string type) 205 { 206 return add(getType(type)); 207 } 208 148 209 149 210 /** Parses an istream depending on its suffix … … 158 219 } else if (suffix == ParserSuffix[pcp]) { 159 220 getPcp().load(&input); 221 } else if (suffix == ParserSuffix[pdb]) { 222 getPdb().load(&input); 160 223 } else if (suffix == ParserSuffix[tremolo]) { 161 224 getTremolo().load(&input); … … 163 226 getXyz().load(&input); 164 227 } else { 165 DoeLog(1) && (eLog() << Verbose(1) << "Unknown suffix to for FormatParserStorage::get()." << endl);228 DoeLog(1) && (eLog() << Verbose(1) << "Unknown suffix " << suffix << " to for FormatParserStorage::get()." << endl); 166 229 return false; 167 230 } … … 189 252 } 190 253 254 /** Returns reference to the output PdbParser, adds if not present. 255 * \return reference to the output PdbParser 256 */ 257 PdbParser &FormatParserStorage::getPdb() 258 { 259 if (!ParserPresent[pdb]) 260 addPdb(); 261 return dynamic_cast<PdbParser &>(*ParserList[pdb]); 262 } 263 191 264 /** Returns reference to the output TremoloParser, adds if not present. 192 265 * \return reference to the output TremoloParser -
src/Parser/FormatParserStorage.hpp
r8fd934 rfd4905 17 17 18 18 #include <string> 19 #include <map> 19 20 #include <vector> 20 21 21 22 class FormatParser; 22 23 class MpqcParser; 24 class PdbParser; 23 25 class PcpParser; 24 26 class TremoloParser; … … 26 28 27 29 // enum has to be outside of class for operator++ to be possible 28 enum ParserTypes { mpqc, pcp, tremolo, xyz, ParserTypes_end, ParserTypes_begin = mpqc };30 enum ParserTypes { mpqc, pcp, pdb, tremolo, xyz, ParserTypes_end, ParserTypes_begin = mpqc }; 29 31 typedef enum ParserTypes ParserTypes; 30 32 … … 35 37 public: 36 38 37 38 39 void addMpqc(); 39 40 void addPcp(); 41 void addPdb(); 40 42 void addTremolo(); 41 43 void addXyz(); 44 bool add(std::string type); 45 bool add(ParserTypes type); 42 46 43 47 bool get(std::istream &input, std::string suffix); 44 48 MpqcParser &getMpqc(); 45 49 PcpParser &getPcp(); 50 PdbParser &getPdb(); 46 51 TremoloParser &getTremolo(); 47 52 XyzParser &getXyz(); 53 54 ParserTypes getType(std::string type); 48 55 49 56 void SetOutputPrefixForAll(std::string &_prefix); … … 67 74 std::vector<std::string> ParserSuffix; 68 75 76 // function pointers to each add...() 77 std::map< ParserTypes, void (FormatParserStorage::*)() > ParserAddFunction; 78 79 // type name of each parser type and reverse lookup 80 std::map<ParserTypes, std::string> ParserNames; 81 std::map<std::string, ParserTypes> ParserLookupNames; 82 83 69 84 // prefix of the filenames to use on save 70 85 std::string prefix; -
src/Parser/Makefile.am
r8fd934 rfd4905 13 13 MpqcParser.cpp \ 14 14 PcpParser.cpp \ 15 PdbParser.cpp \ 15 16 TremoloParser.cpp \ 16 17 XyzParser.cpp … … 22 23 MpqcParser.hpp \ 23 24 PcpParser.hpp \ 25 PdbParser.hpp \ 24 26 TremoloParser.hpp \ 25 27 XyzParser.hpp -
src/Parser/TremoloParser.cpp
r8fd934 rfd4905 26 26 #include "World.hpp" 27 27 #include "atom.hpp" 28 #include "bond.hpp" 28 29 #include "element.hpp" 29 #include " bond.hpp"30 #include "molecule.hpp" 30 31 #include "periodentafel.hpp" 31 32 #include "Descriptors/AtomIdDescriptor.hpp" … … 33 34 #include <vector> 34 35 36 #include <iostream> 37 #include <iomanip> 35 38 36 39 using namespace std; … … 88 91 89 92 usedFields.clear(); 93 molecule *newmol = World::getInstance().createMolecule(); 90 94 while (file->good()) { 91 95 std::getline(*file, line, '\n'); … … 97 101 } 98 102 if (line.length() > 0 && line.at(0) != '#') { 99 readAtomDataLine(line );103 readAtomDataLine(line, newmol); 100 104 } 101 105 } … … 169 173 break; 170 174 case TremoloKey::Id : 171 *file << currentAtom->getId() << "\t";175 *file << currentAtom->getId()+1 << "\t"; 172 176 break; 173 177 case TremoloKey::neighbors : 174 178 writeNeighbors(file, atoi(it->substr(it->find("=") + 1, 1).c_str()), currentAtom); 175 179 break; 180 case TremoloKey::resSeq : 181 if (additionalAtomData.find(currentAtom->getId()) != additionalAtomData.end()) { 182 *file << additionalAtomData[currentAtom->getId()].get(currentField); 183 } else if (currentAtom->getMolecule() != NULL) { 184 *file << setw(4) << currentAtom->getMolecule()->getId()+1; 185 } else { 186 *file << defaultAdditionalData.get(currentField); 187 } 188 *file << "\t"; 189 break; 176 190 default : 177 *file << (additionalAtomData.find(currentAtom->getId()) != additionalAtomData.end() 178 ? additionalAtomData[currentAtom->getId()].get(currentField) 179 : defaultAdditionalData.get(currentField)); 191 if (additionalAtomData.find(currentAtom->getId()) != additionalAtomData.end()) { 192 *file << additionalAtomData[currentAtom->getId()].get(currentField); 193 } else if (additionalAtomData.find(currentAtom->GetTrueFather()->getId()) != additionalAtomData.end()) { 194 *file << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField); 195 } else { 196 *file << defaultAdditionalData.get(currentField); 197 } 180 198 *file << "\t"; 181 199 break; … … 197 215 for (int i = 0; i < numberOfNeighbors; i++) { 198 216 *file << (currentBond != currentAtom->ListOfBonds.end() 199 ? (*currentBond)->GetOtherAtom(currentAtom)->getId() : 0) << "\t"; 217 ? (*currentBond)->GetOtherAtom(currentAtom)->getId()+1 : 0) << "\t"; 218 if (currentBond != currentAtom->ListOfBonds.end()) 219 currentBond++; 200 220 } 201 221 } … … 229 249 * 230 250 * \param line to parse as an atom 231 */ 232 void TremoloParser::readAtomDataLine(string line) { 251 * \param *newmol molecule to add atom to 252 */ 253 void TremoloParser::readAtomDataLine(string line, molecule *newmol = NULL) { 233 254 vector<string>::iterator it; 234 255 stringstream lineStream; … … 279 300 } 280 301 } 302 if (newmol != NULL) 303 newmol->AddAtom(newAtom); 281 304 } 282 305 -
src/Parser/TremoloParser.hpp
r8fd934 rfd4905 11 11 #include <string> 12 12 #include "Parser/FormatParser.hpp" 13 14 class molecule; 13 15 14 16 /** … … 85 87 private: 86 88 void readAtomDataLine(string line); 89 void readAtomDataLine(string line, molecule *newmol); 87 90 void parseAtomDataKeysLine(string line, int offset); 88 91 void readNeighbors(std::stringstream* line, int numberOfNeighbors, int atomId);
Note:
See TracChangeset
for help on using the changeset viewer.