Changeset fd4905 for src/Parser


Ignore:
Timestamp:
Aug 28, 2010, 1:45:13 AM (15 years ago)
Author:
Frederik Heber <heber@…>
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.
Message:

Merge branch 'stable' into StructureRefactoring

Location:
src/Parser
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/FormatParserStorage.cpp

    r8fd934 rfd4905  
    2828#include "Parser/MpqcParser.hpp"
    2929#include "Parser/PcpParser.hpp"
     30#include "Parser/PdbParser.hpp"
    3031#include "Parser/TremoloParser.hpp"
    3132#include "Parser/XyzParser.hpp"
     
    5657  ParserSuffix.resize(ParserTypes_end, "");
    5758
     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
    5868  ParserSuffix[mpqc] = "in";
    5969  ParserSuffix[pcp] = "conf";
     70  ParserSuffix[pdb] = "pdb";
    6071  ParserSuffix[tremolo] = "data";
    6172  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;
    6279}
    6380
     
    112129}
    113130
     131
    114132/** Adds an PcpParser to the storage.
    115133 */
     
    124142
    125143
     144/** Adds an PdbParser to the storage.
     145 */
     146void 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
    126156/** Adds an TremoloParser to the storage.
    127157 */
     
    146176    DoeLog(1) && (eLog() << Verbose(1) << "Parser xyz is already present." << endl);
    147177}
     178
     179ParserTypes 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
     188bool 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
     204bool FormatParserStorage::add(std::string type)
     205{
     206  return add(getType(type));
     207}
     208
    148209
    149210/** Parses an istream depending on its suffix
     
    158219  } else if (suffix == ParserSuffix[pcp]) {
    159220    getPcp().load(&input);
     221  } else if (suffix == ParserSuffix[pdb]) {
     222    getPdb().load(&input);
    160223  } else if (suffix == ParserSuffix[tremolo]) {
    161224    getTremolo().load(&input);
     
    163226    getXyz().load(&input);
    164227  } 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);
    166229    return false;
    167230  }
     
    189252}
    190253
     254/** Returns reference to the output PdbParser, adds if not present.
     255 * \return reference to the output PdbParser
     256 */
     257PdbParser &FormatParserStorage::getPdb()
     258{
     259  if (!ParserPresent[pdb])
     260    addPdb();
     261  return dynamic_cast<PdbParser &>(*ParserList[pdb]);
     262}
     263
    191264/** Returns reference to the output TremoloParser, adds if not present.
    192265 * \return reference to the output TremoloParser
  • src/Parser/FormatParserStorage.hpp

    r8fd934 rfd4905  
    1717
    1818#include <string>
     19#include <map>
    1920#include <vector>
    2021
    2122class FormatParser;
    2223class MpqcParser;
     24class PdbParser;
    2325class PcpParser;
    2426class TremoloParser;
     
    2628
    2729// enum has to be outside of class for operator++ to be possible
    28 enum ParserTypes { mpqc, pcp, tremolo, xyz, ParserTypes_end, ParserTypes_begin = mpqc };
     30enum ParserTypes { mpqc, pcp, pdb, tremolo, xyz, ParserTypes_end, ParserTypes_begin = mpqc };
    2931typedef enum ParserTypes ParserTypes;
    3032
     
    3537public:
    3638
    37 
    3839  void addMpqc();
    3940  void addPcp();
     41  void addPdb();
    4042  void addTremolo();
    4143  void addXyz();
     44  bool add(std::string type);
     45  bool add(ParserTypes type);
    4246
    4347  bool get(std::istream &input, std::string suffix);
    4448  MpqcParser &getMpqc();
    4549  PcpParser &getPcp();
     50  PdbParser &getPdb();
    4651  TremoloParser &getTremolo();
    4752  XyzParser &getXyz();
     53
     54  ParserTypes getType(std::string type);
    4855
    4956  void SetOutputPrefixForAll(std::string &_prefix);
     
    6774  std::vector<std::string> ParserSuffix;
    6875
     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
    6984  // prefix of the filenames to use on save
    7085  std::string prefix;
  • src/Parser/Makefile.am

    r8fd934 rfd4905  
    1313  MpqcParser.cpp \
    1414  PcpParser.cpp \
     15  PdbParser.cpp \
    1516  TremoloParser.cpp \
    1617  XyzParser.cpp
     
    2223  MpqcParser.hpp \
    2324  PcpParser.hpp \
     25  PdbParser.hpp \
    2426  TremoloParser.hpp \
    2527  XyzParser.hpp
  • src/Parser/TremoloParser.cpp

    r8fd934 rfd4905  
    2626#include "World.hpp"
    2727#include "atom.hpp"
     28#include "bond.hpp"
    2829#include "element.hpp"
    29 #include "bond.hpp"
     30#include "molecule.hpp"
    3031#include "periodentafel.hpp"
    3132#include "Descriptors/AtomIdDescriptor.hpp"
     
    3334#include <vector>
    3435
     36#include <iostream>
     37#include <iomanip>
    3538
    3639using namespace std;
     
    8891
    8992  usedFields.clear();
     93  molecule *newmol = World::getInstance().createMolecule();
    9094  while (file->good()) {
    9195    std::getline(*file, line, '\n');
     
    97101    }
    98102    if (line.length() > 0 && line.at(0) != '#') {
    99       readAtomDataLine(line);
     103      readAtomDataLine(line, newmol);
    100104    }
    101105  }
     
    169173        break;
    170174      case TremoloKey::Id :
    171         *file << currentAtom->getId() << "\t";
     175        *file << currentAtom->getId()+1 << "\t";
    172176        break;
    173177      case TremoloKey::neighbors :
    174178        writeNeighbors(file, atoi(it->substr(it->find("=") + 1, 1).c_str()), currentAtom);
    175179        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;
    176190      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        }
    180198        *file << "\t";
    181199        break;
     
    197215  for (int i = 0; i < numberOfNeighbors; i++) {
    198216    *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++;
    200220  }
    201221}
     
    229249 *
    230250 * \param line to parse as an atom
    231  */
    232 void TremoloParser::readAtomDataLine(string line) {
     251 * \param *newmol molecule to add atom to
     252 */
     253void TremoloParser::readAtomDataLine(string line, molecule *newmol = NULL) {
    233254  vector<string>::iterator it;
    234255  stringstream lineStream;
     
    279300    }
    280301  }
     302  if (newmol != NULL)
     303    newmol->AddAtom(newAtom);
    281304}
    282305
  • src/Parser/TremoloParser.hpp

    r8fd934 rfd4905  
    1111#include <string>
    1212#include "Parser/FormatParser.hpp"
     13
     14class molecule;
    1315
    1416/**
     
    8587private:
    8688  void readAtomDataLine(string line);
     89  void readAtomDataLine(string line, molecule *newmol);
    8790  void parseAtomDataKeysLine(string line, int offset);
    8891  void readNeighbors(std::stringstream* line, int numberOfNeighbors, int atomId);
Note: See TracChangeset for help on using the changeset viewer.