Ignore:
Timestamp:
Oct 14, 2011, 3:15:30 PM (13 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:
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)
Message:

Huge Refactoring of FormatParserStorage and all FormatParser's.

FormatParser:

FormatParserStorage:

  • We construct all lookup tables and alikes via boost preprocessor magic from a list of all available parser (enums).
  • we use the templated getParser() and addParser() functions to serve parsers to the outside. Instances are as usual created only once.

Tests:

  • tests only had to be changed because of the "renaming" of the Parsers.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/PdbParser.cpp

    r9a6b76e r765f16  
    4444using namespace std;
    4545
     46// declare specialized static variables
     47const std::string FormatParserTrait<pdb>::name = "pdb";
     48const std::string FormatParserTrait<pdb>::suffix = "pdb";
     49const ParserTypes FormatParserTrait<pdb>::type = pdb;
     50
    4651/**
    4752 * Constructor.
    4853 */
    49 PdbParser::PdbParser() {
     54FormatParser< pdb >::FormatParser() :
     55  FormatParser_common(NULL)
     56{
    5057  knownTokens["ATOM"] = PdbKey::Atom;
    5158  knownTokens["HETATM"] = PdbKey::Atom;
     
    6572 * Destructor.
    6673 */
    67 PdbParser::~PdbParser() {
     74FormatParser< pdb >::~FormatParser()
     75{
    6876  PdbAtomInfoContainer::clearknownDataKeys();
    6977  additionalAtomData.clear();
     
    7785 * @return token type
    7886 */
    79 enum PdbKey::KnownTokens PdbParser::getToken(string &line)
     87enum PdbKey::KnownTokens FormatParser< pdb >::getToken(string &line)
    8088{
    8189  // look for first space
     
    105113 * \param PDB file
    106114 */
    107 void PdbParser::load(istream* file) {
     115void FormatParser< pdb >::load(istream* file) {
    108116  string line;
    109117  size_t linecount  = 0;
     
    148156            // TODO: put a throw here
    149157            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+".");
    151159            break;
    152160        }
     
    170178 * \param atoms atoms to store
    171179 */
    172 void PdbParser::save(ostream* file, const std::vector<atom *> &AtomList)
     180void FormatParser< pdb >::save(ostream* file, const std::vector<atom *> &AtomList)
    173181{
    174182  DoLog(0) && (Log() << Verbose(0) << "Saving changes to pdb." << std::endl);
     
    240248        } else {
    241249          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?!");
    243251          MolNo = MolIdMap[mol->getId()];
    244252          atomInfo.set(PdbKey::resSeq, toString(MolIdMap[mol->getId()]));
     
    289297 * @param id of atom
    290298 */
    291 void PdbParser::AtomInserted(atomId_t id)
    292 {
    293   //LOG(3, "PdbParser::AtomInserted() - notified of atom " << id << "'s insertion.");
     299void FormatParser< pdb >::AtomInserted(atomId_t id)
     300{
     301  //LOG(3, "FormatParser< pdb >::AtomInserted() - notified of atom " << id << "'s insertion.");
    294302  ASSERT(!isPresentadditionalAtomData(id),
    295       "PdbParser::AtomInserted() - additionalAtomData already present for newly added atom "
     303      "FormatParser< pdb >::AtomInserted() - additionalAtomData already present for newly added atom "
    296304      +toString(id)+".");
    297305  // don't insert here as this is our check whether we are in the first time step
     
    304312 * @param id of atom
    305313 */
    306 void PdbParser::AtomRemoved(atomId_t id)
    307 {
    308   //LOG(3, "PdbParser::AtomRemoved() - notified of atom " << id << "'s removal.");
     314void FormatParser< pdb >::AtomRemoved(atomId_t id)
     315{
     316  //LOG(3, "FormatParser< pdb >::AtomRemoved() - notified of atom " << id << "'s removal.");
    309317  std::map<size_t, PdbAtomInfoContainer>::iterator iter = additionalAtomData.find(id);
    310318  // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence
    311319//  ASSERT(iter != additionalAtomData.end(),
    312 //      "PdbParser::AtomRemoved() - additionalAtomData is not present for atom "
     320//      "FormatParser< pdb >::AtomRemoved() - additionalAtomData is not present for atom "
    313321//      +toString(id)+" to remove.");
    314322  if (iter != additionalAtomData.end()) {
     
    325333 * @return true - entry present, false - only for atom's father or no entry
    326334 */
    327 bool PdbParser::isPresentadditionalAtomData(unsigned int _id)
     335bool FormatParser< pdb >::isPresentadditionalAtomData(unsigned int _id)
    328336{
    329337  return (additionalAtomData.find(_id) != additionalAtomData.end());
     
    336344 * @return
    337345 */
    338 PdbAtomInfoContainer& PdbParser::getadditionalAtomData(atom *_atom)
     346PdbAtomInfoContainer& FormatParser< pdb >::getadditionalAtomData(atom *_atom)
    339347{
    340348  if (additionalAtomData.find(_atom->getId()) != additionalAtomData.end()) {
     
    362370 * \param ResidueNo number of residue
    363371 */
    364 void PdbParser::saveLine(
     372void FormatParser< pdb >::saveLine(
    365373    ostream* file,
    366374    const PdbAtomInfoContainer &atomInfo)
     
    423431 * \param *currentAtom to the atom of which to take the neighbor information
    424432 */
    425 void PdbParser::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {
     433void FormatParser< pdb >::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {
    426434  int MaxNo = MaxnumberOfNeighbors;
    427435  int charsleft = 80;
     
    452460}
    453461
    454 /** Retrieves a value from PdbParser::atomIdMap.
     462/** Retrieves a value from  FormatParser< pdb >::atomIdMap.
    455463 * \param atomid key
    456464 * \return value
    457465 */
    458 size_t PdbParser::getSerial(const size_t atomid) const
    459 {
    460   ASSERT(atomIdMap.find(atomid) != atomIdMap.end(),
    461       "PdbParser::getSerial() - atomid "+toString(atomid)+" not present in Map.");
     466size_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.");
    462470  return (atomIdMap.find(atomid)->second);
    463471}
    464472
    465 /** Sets an entry in PdbParser::atomIdMap.
     473/** Sets an entry in  FormatParser< pdb >::atomIdMap.
    466474 * \param localatomid key
    467475 * \param atomid value
    468476 * \return true - key not present, false - value present
    469477 */
    470 void PdbParser::setSerial(const size_t localatomid, const size_t atomid)
     478void FormatParser< pdb >::setSerial(const size_t localatomid, const size_t atomid)
    471479{
    472480  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 ("
    474482//      << localatomid << " -> " << atomid << ")." << std::endl);
    475483  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.");
    477485}
    478486
     
    482490 * @return
    483491 */
    484 atom* PdbParser::getAtomToParse(std::string id_string) const
     492atom* FormatParser< pdb >::getAtomToParse(std::string id_string) const
    485493{
    486494  // get the local ID
     
    517525 * @param line line containing key ATOM
    518526 */
    519 void PdbParser::readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const
     527void FormatParser< pdb >::readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const
    520528{
    521529  const size_t length = line.length();
    522530  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!");
    524532  if (length >= 6) {
    525533    LOG(4,"INFO: Parsing token from "+line.substr(0,6)+".");
     
    530538    atomInfo.set(PdbKey::serial, line.substr(6,5));
    531539    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).");
    533541  }
    534542
     
    591599 * \param newmol molecule to add parsed atoms to
    592600 */
    593 void PdbParser::readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol = NULL) {
     601void FormatParser< pdb >::readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol = NULL) {
    594602  vector<string>::iterator it;
    595603
     
    598606  bool FirstTimestep = isPresentadditionalAtomData(newAtom->getId()) ? false : true;
    599607  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.");
    601609  if (FirstTimestep) {
    602610    LOG(3,"INFO: Parsing new atom.");
     
    646654      SerialSet.insert(toSize_t(atomInfo.get<std::string>(PdbKey::serial)));
    647655    ASSERT(Inserter.second,
    648         "PdbParser::readAtomDataLine() - ATOM contains entry with serial "
     656        "FormatParser< pdb >::readAtomDataLine() - ATOM contains entry with serial "
    649657        +atomInfo.get<std::string>(PdbKey::serial)+" already present!");
    650658    setSerial(toSize_t(atomInfo.get<std::string>(PdbKey::serial)), newAtom->getId());
     
    667675        ->FindElement(value);
    668676    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!");
    670678    newAtom->setType(elem);
    671679
     
    679687    // then check additional info for consistency
    680688    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 "
    682690        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    683691    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 "
    685693        +atomInfo.get<std::string>(PdbKey::serial)+":"
    686694        +atomInfo.get<std::string>(PdbKey::name)+"!="
    687695        +consistencyInfo.get<std::string>(PdbKey::name)+".");
    688696    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 "
    690698        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    691699    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 "
    693701        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    694702    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 "
    696704        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    697705    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 "
    699707        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    700708    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 "
    702710        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    703711    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 "
    705713        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    706714    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 "
    708716        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    709717    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 "
    711719        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    712720    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 "
    714722        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    715723    // and parse in trajectory
     
    734742 *
    735743 */
    736 void PdbParser::printAtomInfo(const atom * const newAtom) const
     744void FormatParser< pdb >::printAtomInfo(const atom * const newAtom) const
    737745{
    738746  const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(newAtom->getId()); // operator[] const does not exist
     
    762770 * \param line to parse as an atom
    763771 */
    764 void PdbParser::readNeighbors(const unsigned int _step, std::string &line)
     772void FormatParser< pdb >::readNeighbors(const unsigned int _step, std::string &line)
    765773{
    766774  const size_t length = line.length();
     
    772780  string output;
    773781  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) + "|";
    777785  const size_t id = toSize_t(line.substr(6,5));
    778786  for (size_t index = 11; index <= 26; index+=5) {
     
    785793        ListOfNeighbors.push_back(otherid);
    786794      else
    787         ELOG(2, "PdbParser::readNeighbors() - discarding conect entry with id 0.");
     795        ELOG(2, "FormatParser< pdb >::readNeighbors() - discarding conect entry with id 0.");
    788796    } else  {
    789797      break;
     
    813821 * \return input string with modified atom IDs
    814822 */
    815 //string PdbParser::adaptIdDependentDataString(string data) {
     823//string  FormatParser< pdb >::adaptIdDependentDataString(string data) {
    816824//  // there might be no IDs
    817825//  if (data == "-") {
     
    836844
    837845
    838 bool PdbParser::operator==(const PdbParser& b) const
     846bool FormatParser< pdb >::operator==(const FormatParser< pdb >& b) const
    839847{
    840848  bool status = true;
Note: See TracChangeset for help on using the changeset viewer.