Ignore:
Timestamp:
Oct 20, 2011, 10:42:16 PM (14 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, Candidate_v1.7.0, 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:
f94953
Parents:
fa9d1d (diff), 752bb4 (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.
git-author:
Frederik Heber <heber@…> (10/20/11 22:40:59)
git-committer:
Frederik Heber <heber@…> (10/20/11 22:42:16)
Message:

Merge branch 'Adding_Psi3Parser' into stable

Conflicts:

src/Parser/FormatParser.hpp
src/Parser/unittests/ParserTremoloUnitTest.cpp

Issues:

  • Element and periodentafel have been moved to folder src/Element.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/FormatParserStorage.cpp

    rfa9d1d r360c8b  
    2323#include <fstream>
    2424
    25 #include "Parser/FormatParserStorage.hpp"
    26 
     25#include <boost/preprocessor/iteration/local.hpp>
     26
     27#include "CodePatterns/Assert.hpp"
    2728#include "CodePatterns/Log.hpp"
    28 #include "CodePatterns/Verbose.hpp"
    29 
    30 #include "CodePatterns/Assert.hpp"
    3129
    3230#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 "Psi3Parser.hpp"
     38#include "TremoloParser.hpp"
     39#include "XyzParser.hpp"
    3340
    3441#include "CodePatterns/Singleton_impl.hpp"
    3542
    36 /** Increment operator for the enumeration ParserTypes to allow loops.
    37  * \param &type value
    38  * \return value incremented by one
    39  */
    40 ParserTypes &operator++(ParserTypes &type)
    41 {
    42   return type = ParserTypes(type+1);
    43 }
    4443
    4544/** Constructor of class FormatParserStorage.
     
    5150  ParserPresent.resize(ParserTypes_end, false);
    5251
    53   ParserNames[mpqc] = "mpqc";
    54   ParserNames[pcp] = "pcp";
    55   ParserNames[pdb] = "pdb";
    56   ParserNames[tremolo] = "tremolo";
    57   ParserNames[xyz] = "xyz";
    58 
    59   for (std::map<ParserTypes, std::string>::const_iterator it = ParserNames.begin(); it != ParserNames.end(); ++it)
    60     ParserLookupNames.insert(pair<std::string, ParserTypes>(it->second,it->first) );
    61 
    62   ParserSuffixes[mpqc] = "in";
    63   ParserSuffixes[pcp] = "conf";
    64   ParserSuffixes[pdb] = "pdb";
    65   ParserSuffixes[tremolo] = "data";
    66   ParserSuffixes[xyz] = "xyz";
    67 
    68   for (std::map<ParserTypes, std::string>::const_iterator it = ParserSuffixes.begin(); it != ParserSuffixes.end(); ++it)
    69     ParserLookupSuffixes.insert(pair<std::string, ParserTypes>(it->second,it->first) );
    70 
    71   ParserAddFunction[mpqc] = &FormatParserStorage::addMpqc;
    72   ParserAddFunction[pcp] = &FormatParserStorage::addPcp;
    73   ParserAddFunction[pdb] = &FormatParserStorage::addPdb;
    74   ParserAddFunction[tremolo] = &FormatParserStorage::addTremolo;
    75   ParserAddFunction[xyz] = &FormatParserStorage::addXyz;
     52#include "ParserTypes.def"
     53
     54#define insert_print(z,n,seq,map, before, after) \
     55   map .insert( std::make_pair(  \
     56     BOOST_PP_SEQ_ELEM(n, seq) \
     57     , before < \
     58       BOOST_PP_SEQ_ELEM(n, seq) \
     59       > after \
     60     ) );
     61 
     62#define insert_invert_print(z,n,seq,map, before, after) \
     63   map .insert( std::make_pair( before < \
     64   BOOST_PP_SEQ_ELEM(n, seq) \
     65   > after, \
     66   BOOST_PP_SEQ_ELEM(n, seq) \
     67  ) );
     68
     69  // fill ParserNames
     70#if defined ParserTypes_END // do we have parameters at all?
     71#define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserNames, FormatParserTrait, ::name)
     72#define BOOST_PP_LOCAL_LIMITS  (0, ParserTypes_END-1)
     73#include BOOST_PP_LOCAL_ITERATE()
     74#endif
     75
     76  // fill ParserLookupNames
     77#if defined ParserTypes_END // do we have parameters at all?
     78#define BOOST_PP_LOCAL_MACRO(n) insert_invert_print(~, n, PARSERSEQUENCE, ParserLookupNames, FormatParserTrait, ::name)
     79#define BOOST_PP_LOCAL_LIMITS  (0, ParserTypes_END-1)
     80#include BOOST_PP_LOCAL_ITERATE()
     81#endif
     82
     83  // fill ParserSuffixes
     84#if defined ParserTypes_END // do we have parameters at all?
     85#define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserSuffixes, FormatParserTrait, ::suffix)
     86#define BOOST_PP_LOCAL_LIMITS  (0, ParserTypes_END-1)
     87#include BOOST_PP_LOCAL_ITERATE()
     88#endif
     89
     90  // fill ParserLookupSuffixes
     91#if defined ParserTypes_END // do we have parameters at all?
     92#define BOOST_PP_LOCAL_MACRO(n) insert_invert_print(~, n, PARSERSEQUENCE, ParserLookupSuffixes, FormatParserTrait, ::suffix)
     93#define BOOST_PP_LOCAL_LIMITS  (0, ParserTypes_END-1)
     94#include BOOST_PP_LOCAL_ITERATE()
     95#endif
     96
     97  // fill ParserAddFunction
     98#if defined ParserTypes_END // do we have parameters at all?
     99#define BOOST_PP_LOCAL_MACRO(n) insert_print(~, n, PARSERSEQUENCE, ParserAddFunction, &FormatParserStorage::addParser, )
     100#define BOOST_PP_LOCAL_LIMITS  (0, ParserTypes_END-1)
     101#include BOOST_PP_LOCAL_ITERATE()
     102#endif
     103
     104#undef insert_print
     105#undef insert_invert_print
     106#include "ParserTypes.undef"
     107
     108  //std::cout << "ParserNames:" << std::endl << ParserNames << std::endl;
     109  //std::cout << "ParserSuffixes:" << std::endl << ParserSuffixes << std::endl;
     110  //std::cout << "ParserLookupNames:" << std::endl << ParserLookupNames << std::endl;
     111  //std::cout << "ParserLookupSuffixes:" << std::endl << ParserLookupSuffixes << std::endl;
     112  //std::cout << "ParserAddFunction:" << std::endl << ParserAddFunction << std::endl;
     113
    76114}
    77115
     
    114152
    115153
    116 /** Adds an MpqcParser to the storage.
    117  */
    118 void FormatParserStorage::addMpqc()
    119 {
    120   if (!ParserPresent[mpqc]) {
    121     ParserList[mpqc] = dynamic_cast<FormatParser *>(new MpqcParser);
    122     ParserPresent[mpqc] = true;
    123   }
    124   else
    125     DoeLog(2) && (eLog() << Verbose(2) << "Parser mpqc is already present." << endl
    126         << "Note that you don't need to add '-o mpqc' if the input file is of type mpqc." << endl);
    127 }
    128 
    129 
    130 /** Adds an PcpParser to the storage.
    131  */
    132 void FormatParserStorage::addPcp()
    133 {
    134   if (!ParserPresent[pcp]) {
    135     ParserList[pcp] = new PcpParser();
    136     ParserPresent[pcp] = true;
    137   } else
    138     DoeLog(2) && (eLog() << Verbose(2) << "Parser pcp is already present." << endl
    139         << "Note that you don't need to add '-o pcp' if the input file is of type pcp." << endl);
    140 }
    141 
    142 
    143 /** Adds an PdbParser to the storage.
    144  */
    145 void FormatParserStorage::addPdb()
    146 {
    147   if (!ParserPresent[pdb]) {
    148     ParserList[pdb] = new PdbParser();
    149     ParserPresent[pdb] = true;
    150   } else
    151     DoeLog(2) && (eLog() << Verbose(2) << "Parser pdb is already present." << endl
    152         << "Note that you don't need to add '-o pdb' if the input file is of type pdb." << endl);
    153 }
    154 
    155 
    156 /** Adds an TremoloParser to the storage.
    157  */
    158 void FormatParserStorage::addTremolo()
    159 {
    160   if (!ParserPresent[tremolo]) {
    161     ParserList[tremolo] = new TremoloParser();
    162     ParserPresent[tremolo] = true;
    163   } else
    164     DoeLog(2) && (eLog() << Verbose(2) << "Parser tremolo is already present." << endl
    165         << "Note that you don't need to add '-o tremolo' if the input file is of type tremolo." << endl);
    166 }
    167 
    168 
    169 /** Adds an XyzParser to the storage.
    170  */
    171 void FormatParserStorage::addXyz()
    172 {
    173   if (!ParserPresent[xyz]) {
    174     ParserList[xyz] = new XyzParser();
    175     ParserPresent[xyz] = true;
    176   } else
    177     DoeLog(2) && (eLog() << Verbose(2) << "Parser xyz is already present." << endl
    178         << "Note that you don't need to add '-o xyz' if the input file is of type xyz." << endl);
    179 }
    180 
    181154ParserTypes FormatParserStorage::getTypeFromName(std::string type)
    182155{
     
    201174  if (ptype != ParserTypes_end) {
    202175    if (ParserAddFunction.find(ptype) != ParserAddFunction.end()) {
    203       DoLog(0) && (Log() << Verbose(0) << "Adding " << ParserNames[ptype] << " type to output." << endl);
     176      LOG(0, "STATUS: Adding " << ParserNames[ptype] << " type to output.");
    204177      (getInstance().*(ParserAddFunction[ptype]))(); // we still need an object to work on ...
    205178      return true;
    206179    } else {
    207       DoeLog(1) && (eLog() << Verbose(1) << "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?" << endl);
     180      ELOG(1, "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?");
    208181      return false;
    209182    }
     
    215188bool FormatParserStorage::add(std::string type)
    216189{
    217   return add(getTypeFromName(type));
     190  enum ParserTypes Ptype = getTypeFromName(type);
     191  return add(Ptype);
    218192}
    219193
     
    226200bool FormatParserStorage::load(std::istream &input, std::string suffix)
    227201{
    228   if (suffix == ParserSuffixes[mpqc]) {
    229     getMpqc().load(&input);
    230   } else if (suffix == ParserSuffixes[pcp]) {
    231     getPcp().load(&input);
    232   } else if (suffix == ParserSuffixes[pdb]) {
    233     getPdb().load(&input);
    234   } else if (suffix == ParserSuffixes[tremolo]) {
    235     getTremolo().load(&input);
    236   } else if (suffix == ParserSuffixes[xyz]) {
    237     getXyz().load(&input);
    238   } else {
    239     DoeLog(1) && (eLog() << Verbose(1) << "Unknown suffix " << suffix << " to for FormatParserStorage::get()." << endl);
     202  enum ParserTypes type = getTypeFromSuffix(suffix);
     203  if (type != ParserTypes_end)
     204    get(type).load(&input);
     205  else
    240206    return false;
    241   }
    242207  return true;
    243208}
     
    302267bool FormatParserStorage::save(std::ostream &output, std::string suffix, const std::vector<atom *> &atoms)
    303268{
    304   if (suffix == ParserSuffixes[mpqc]) {
    305     getMpqc().save(&output, atoms);
    306   } else if (suffix == ParserSuffixes[pcp]) {
    307     getPcp().save(&output, atoms);
    308   } else if (suffix == ParserSuffixes[pdb]) {
    309     getPdb().save(&output, atoms);
    310   } else if (suffix == ParserSuffixes[tremolo]) {
    311     getTremolo().save(&output, atoms);
    312   } else if (suffix == ParserSuffixes[xyz]) {
    313     getXyz().save(&output, atoms);
    314   } else {
    315     DoeLog(1) && (eLog() << Verbose(1) << "Unknown suffix " << suffix << " to for FormatParserStorage::put()." << endl);
     269  enum ParserTypes type = getTypeFromSuffix(suffix);
     270  if (type != ParserTypes_end)
     271    get(type).save(&output, atoms);
     272  else
    316273    return false;
    317   }
    318274  return true;
    319 }
    320 
    321 /** Returns reference to the output MpqcParser, adds if not present.
    322  * \return reference to the output MpqcParser
    323  */
    324 MpqcParser &FormatParserStorage::getMpqc()
    325 {
    326   if (!ParserPresent[mpqc])
    327     addMpqc();
    328   return dynamic_cast<MpqcParser &>(*ParserList[mpqc]);
    329 }
    330 
    331 /** Returns reference to the output PcpParser, adds if not present.
    332  * \return reference to the output PcpParser
    333  */
    334 PcpParser &FormatParserStorage::getPcp()
    335 {
    336   if (!ParserPresent[pcp])
    337     addPcp();
    338   return dynamic_cast<PcpParser &>(*ParserList[pcp]);
    339 }
    340 
    341 /** Returns reference to the output PdbParser, adds if not present.
    342  * \return reference to the output PdbParser
    343  */
    344 PdbParser &FormatParserStorage::getPdb()
    345 {
    346   if (!ParserPresent[pdb])
    347     addPdb();
    348   return dynamic_cast<PdbParser &>(*ParserList[pdb]);
    349 }
    350 
    351 /** Returns reference to the output TremoloParser, adds if not present.
    352  * \return reference to the output TremoloParser
    353  */
    354 TremoloParser &FormatParserStorage::getTremolo()
    355 {
    356   if (!ParserPresent[tremolo])
    357     addTremolo();
    358   return dynamic_cast<TremoloParser &>(*ParserList[tremolo]);
    359 }
    360 
    361 /** Returns reference to the output XyzParser, adds if not present.
    362  * \return reference to the output XyzParser
    363  */
    364 XyzParser &FormatParserStorage::getXyz()
    365 {
    366   if (!ParserPresent[xyz])
    367     addXyz();
    368   return dynamic_cast<XyzParser &>(*ParserList[xyz]);
    369275}
    370276
     
    373279 * \return reference to the output FormatParser with desired type
    374280 */
    375 FormatParser &FormatParserStorage::get(ParserTypes _type)
     281FormatParserInterface &FormatParserStorage::get(ParserTypes _type)
    376282{
    377283  if (!ParserPresent[_type]) {
Note: See TracChangeset for help on using the changeset viewer.