Changes in / [360c8b:fa9d1d]


Ignore:
Files:
1 added
55 deleted
43 edited

Legend:

Unmodified
Added
Removed
  • configure.ac

    r360c8b rfa9d1d  
    122122BOOST_RANDOM
    123123BOOST_SMART_PTR
    124 BOOST_STRING_ALGO
    125124BOOST_TOKENIZER
    126125
  • src/Actions/MoleculeAction/FillVoidWithMoleculeAction.cpp

    r360c8b rfa9d1d  
    2828#include "Descriptors/MoleculeOrderDescriptor.hpp"
    2929#include "molecule.hpp"
    30 #include "Parser/FormatParserInterface.hpp"
    3130#include "Parser/FormatParserStorage.hpp"
    3231#include "World.hpp"
     
    6867  input.open(params.fillername.string().c_str());
    6968  ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix);
    70   FormatParserInterface &parser = FormatParserStorage::getInstance().get(type);
     69  FormatParser &parser = FormatParserStorage::getInstance().get(type);
    7170  parser.load(&input);
    7271
  • src/Actions/MoleculeAction/FillWithMoleculeAction.cpp

    r360c8b rfa9d1d  
    2828#include "Descriptors/MoleculeOrderDescriptor.hpp"
    2929#include "molecule.hpp"
    30 #include "Parser/FormatParserInterface.hpp"
    3130#include "Parser/FormatParserStorage.hpp"
    3231#include "World.hpp"
     
    6261  input.open(params.fillername.string().c_str());
    6362  ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix);
    64   FormatParserInterface &parser = FormatParserStorage::getInstance().get(type);
     63  FormatParser &parser = FormatParserStorage::getInstance().get(type);
    6564  parser.load(&input);
    6665
  • src/Actions/MoleculeAction/LoadAction.cpp

    r360c8b rfa9d1d  
    2323#include "CodePatterns/Verbose.hpp"
    2424#include "Descriptors/MoleculeIdDescriptor.hpp"
    25 #include "Parser/FormatParserInterface.hpp"
    2625#include "Parser/FormatParserStorage.hpp"
    2726#include "Parser/FormatParser_Parameters.hpp"
     
    7170    // get undo state for parser
    7271    enum ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix);
    73     ASSERT(type != ParserTypes_end,
    74         "MoleculeLoadAction::performCall() - unknown file suffix "+FilenameSuffix+".");
    7572    FormatParser_Parameters *ParserParams = FormatParserStorage::getInstance().get(type).parameters;
    7673    if (ParserParams != NULL)
  • src/Actions/ParserAction/ParseTremoloPotentialsAction.cpp

    r360c8b rfa9d1d  
    4343
    4444  boost::filesystem::ifstream test;
    45   FormatParser<tremolo> &parser = FormatParserStorage::getInstance().getParser<tremolo>();
     45  TremoloParser &tremolo = FormatParserStorage::getInstance().getTremolo();
    4646  // parsing file if present
    4747  if (!boost::filesystem::exists(params.filename)) {
    4848    DoLog(1) && (Log() << Verbose(1) << "Specified potentials file " << params.filename << " not found." << endl);
    4949    // DONT FAIL: it's just empty we re-create default id-mapping
    50     parser.createKnownTypesByIdentity();
     50    tremolo.createKnownTypesByIdentity();
    5151
    5252  } else {
     
    5555    // parse the file
    5656    test.open(params.filename);
    57     parser.parseKnownTypes(test);
     57    TremoloParser &tremolo = FormatParserStorage::getInstance().getTremolo();
     58    tremolo.parseKnownTypes(test);
    5859    test.close();
    5960  }
  • src/Actions/ParserAction/SetMpqcParametersAction.cpp

    r360c8b rfa9d1d  
    3838/** =========== define the function ====================== */
    3939Action::state_ptr ParserSetMpqcParametersAction::performCall() {
    40   MpqcParser_Parameters &parser = FormatParserStorage::getInstance().getParser<mpqc>().getParams();
     40  MpqcParser_Parameters &mpqc = FormatParserStorage::getInstance().getMpqc().getParams();
    4141
    4242  std::stringstream oldparamstream;
    43   oldparamstream << parser;
     43  oldparamstream << mpqc;
    4444  // obtain information
    4545  getParametersfromValueStorage();
    4646  std::stringstream newparamstream(params.newparams);
    47   newparamstream >> parser;
     47  newparamstream >> mpqc;
    4848
    4949  return Action::state_ptr(new ParserSetMpqcParametersState(oldparamstream.str(), params));
     
    5353  ParserSetMpqcParametersState *state = assert_cast<ParserSetMpqcParametersState*>(_state.get());
    5454
    55   MpqcParser_Parameters &parser = FormatParserStorage::getInstance().getParser<mpqc>().getParams();
     55  MpqcParser_Parameters &mpqc = FormatParserStorage::getInstance().getMpqc().getParams();
    5656  std::stringstream oldparamstream(state->oldparams);
    57   oldparamstream >> parser;
     57  oldparamstream >> mpqc;
    5858
    5959  return Action::state_ptr(_state);
     
    6363  ParserSetMpqcParametersState *state = assert_cast<ParserSetMpqcParametersState*>(_state.get());
    6464
    65   MpqcParser_Parameters &parser = FormatParserStorage::getInstance().getParser<mpqc>().getParams();
     65  MpqcParser_Parameters &mpqc = FormatParserStorage::getInstance().getMpqc().getParams();
    6666  std::stringstream newparamstream(state->params.newparams);
    67   newparamstream >> parser;
     67  newparamstream >> mpqc;
    6868
    6969  return Action::state_ptr(_state);
  • src/Actions/ParserAction/SetTremoloAtomdataAction.cpp

    r360c8b rfa9d1d  
    4242  getParametersfromValueStorage();
    4343
    44   FormatParser<tremolo> &parser = FormatParserStorage::getInstance().getParser<tremolo>();
     44  TremoloParser &tremolo = FormatParserStorage::getInstance().getTremolo();
    4545
    4646  DoLog(1) && (Log() << Verbose(1) << "Setting Tremolo's ATOMDATA to: '" << params.atomdata_string << "'" << std::endl);
    4747
    48   parser.setAtomData(params.atomdata_string);
     48  tremolo.setAtomData(params.atomdata_string);
    4949
    5050  return Action::success;
  • src/Parser/FormatParser.hpp

    r360c8b rfa9d1d  
    1414#endif
    1515
    16 #include <iosfwd>
    17 #include <string>
    18 #include <vector>
    1916
    20 #include "CodePatterns/Assert.hpp"
     17#include "CodePatterns/Observer.hpp"
     18#include "ChangeTracker.hpp"
     19#include "FormatParser_Parameters.hpp"
    2120
    22 #include "FormatParserTrait.hpp"
    23 #include "FormatParserInterface.hpp"
    24 #include "FormatParser_common.hpp"
    25 #include "ParserTypes.hpp"
     21namespace MoleCuilder {
     22  class MoleculeLoadAction;
     23}
    2624
    2725class atom;
    2826
    2927/**
    30  * @file
    31  * <H1> FormatParser Howto </H1>
    32  *
    33  * <H2> Introduction </H2>
    34  *
    35  * FormatParsers parse external streams (files) and bring their information
    36  * into the World. That is they implement load and save functions that work
    37  * on a specific vector atoms.
    38  *
    39  * <H2> Building your own Parsers </H2>
    40  *
    41  * Building Parsers is easy. All you have to do is the following:
    42  * -# add a new parser type to the file ParserTypes.def.
    43  * -# add a new template specialization of FormatParser in a new header and
    44  *    module that implement the virtual load and save functions.
    45  * -# Add the header file of your new parser to FormatParserStorage.cpp.
    46  *
    47  * <H3> Specific notes on the macros </H3>
    48  *
    49  * To clarify a bit the internals of all the different FormatParser... files, here
    50  * are some notes:
    51  * -# We make use of boost::preprocessor to generate lists from the sequence
    52  *    given in ParserTypes.def (and undefined in ParserTypes.undef). These might
    53  *    be forward declarations of even implementations. This is to assure that
    54  *    none are forgotten when a new FormatParser is added.
    55  * -# Thanks to the above construct FormatParserStorage also immediately knows
    56  *    about any new parsers and can get and add such instances.
    57  */
    58 
    59 /**
    6028 * General parser which observes the change tracker.
    6129 */
    62 template <enum ParserTypes Ptype>
    63 class FormatParser : virtual public FormatParserInterface, public FormatParser_common {
    64   FormatParser() :
    65     FormatParser_common(NULL)
    66   {
    67     ASSERT(0, "FormatParser<>::FormatParser() - unspecialized function cannot be called.");
    68   }
    69   virtual ~FormatParser()
    70   {
    71     ASSERT(0, "FormatParser<>::~FormatParser() - unspecialized function cannot be called.");
    72   }
     30class FormatParser : public Observer {
     31  friend class MoleCuilder::MoleculeLoadAction;
     32public:
     33  FormatParser();
     34  virtual ~FormatParser();
     35  virtual void save(std::ostream* file, const std::vector<atom *> &atoms)=0;
     36  virtual void load(std::istream* file)=0;
     37  void setOstream(std::ostream* file);
    7338
    74   void load(std::istream *file)
    75   {
    76     ASSERT(0, "FormatParser<>::load() - unspecialized function cannot be called.");
    77   }
    78   void save(std::ostream *file, const std::vector<atom *> &atoms)
    79   {
    80     ASSERT(0, "FormatParser<>::save() - unspecialized function cannot be called.");
    81   }
     39protected:
     40  void update(Observable *publisher);
     41  void recieveNotification(Observable *publisher, Notification_ptr notification);
     42  void subjectKilled(Observable *publisher);
     43
     44  // these functions are called when atoms are inserted or removed
     45  virtual void AtomInserted(atomId_t) {};
     46  virtual void AtomRemoved(atomId_t) {};
     47
     48  FormatParser_Parameters *parameters;
     49private:
     50
     51  std::ostream* saveStream;
    8252};
    8353
    84 #include "FormatParser_specializations_header.hpp"
    85 
    8654#endif /* FORMATPARSER_HPP_ */
  • src/Parser/FormatParserStorage.cpp

    r360c8b rfa9d1d  
    2323#include <fstream>
    2424
    25 #include <boost/preprocessor/iteration/local.hpp>
     25#include "Parser/FormatParserStorage.hpp"
     26
     27#include "CodePatterns/Log.hpp"
     28#include "CodePatterns/Verbose.hpp"
    2629
    2730#include "CodePatterns/Assert.hpp"
    28 #include "CodePatterns/Log.hpp"
    2931
    3032#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"
    4033
    4134#include "CodePatterns/Singleton_impl.hpp"
    4235
     36/** Increment operator for the enumeration ParserTypes to allow loops.
     37 * \param &type value
     38 * \return value incremented by one
     39 */
     40ParserTypes &operator++(ParserTypes &type)
     41{
     42  return type = ParserTypes(type+1);
     43}
    4344
    4445/** Constructor of class FormatParserStorage.
     
    5051  ParserPresent.resize(ParserTypes_end, false);
    5152
    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 
     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;
    11476}
    11577
     
    152114
    153115
     116/** Adds an MpqcParser to the storage.
     117 */
     118void 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 */
     132void 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 */
     145void 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 */
     158void 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 */
     171void 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
    154181ParserTypes FormatParserStorage::getTypeFromName(std::string type)
    155182{
     
    174201  if (ptype != ParserTypes_end) {
    175202    if (ParserAddFunction.find(ptype) != ParserAddFunction.end()) {
    176       LOG(0, "STATUS: Adding " << ParserNames[ptype] << " type to output.");
     203      DoLog(0) && (Log() << Verbose(0) << "Adding " << ParserNames[ptype] << " type to output." << endl);
    177204      (getInstance().*(ParserAddFunction[ptype]))(); // we still need an object to work on ...
    178205      return true;
    179206    } else {
    180       ELOG(1, "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?");
     207      DoeLog(1) && (eLog() << Verbose(1) << "No parser to add for this known type " << ParserNames[ptype] << ", not implemented?" << endl);
    181208      return false;
    182209    }
     
    188215bool FormatParserStorage::add(std::string type)
    189216{
    190   enum ParserTypes Ptype = getTypeFromName(type);
    191   return add(Ptype);
     217  return add(getTypeFromName(type));
    192218}
    193219
     
    200226bool FormatParserStorage::load(std::istream &input, std::string suffix)
    201227{
    202   enum ParserTypes type = getTypeFromSuffix(suffix);
    203   if (type != ParserTypes_end)
    204     get(type).load(&input);
    205   else
     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);
    206240    return false;
     241  }
    207242  return true;
    208243}
     
    267302bool FormatParserStorage::save(std::ostream &output, std::string suffix, const std::vector<atom *> &atoms)
    268303{
    269   enum ParserTypes type = getTypeFromSuffix(suffix);
    270   if (type != ParserTypes_end)
    271     get(type).save(&output, atoms);
    272   else
     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);
    273316    return false;
     317  }
    274318  return true;
     319}
     320
     321/** Returns reference to the output MpqcParser, adds if not present.
     322 * \return reference to the output MpqcParser
     323 */
     324MpqcParser &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 */
     334PcpParser &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 */
     344PdbParser &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 */
     354TremoloParser &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 */
     364XyzParser &FormatParserStorage::getXyz()
     365{
     366  if (!ParserPresent[xyz])
     367    addXyz();
     368  return dynamic_cast<XyzParser &>(*ParserList[xyz]);
    275369}
    276370
     
    279373 * \return reference to the output FormatParser with desired type
    280374 */
    281 FormatParserInterface &FormatParserStorage::get(ParserTypes _type)
     375FormatParser &FormatParserStorage::get(ParserTypes _type)
    282376{
    283377  if (!ParserPresent[_type]) {
  • src/Parser/FormatParserStorage.hpp

    r360c8b rfa9d1d  
    1616#include "CodePatterns/Singleton.hpp"
    1717
    18 #include <iosfwd>
     18#include <string>
    1919#include <map>
    20 #include <string>
    2120#include <vector>
    2221
    23 #include "CodePatterns/Assert.hpp"
    24 #include "CodePatterns/Log.hpp"
    25 #include "FormatParser.hpp"
    26 #include "ParserTypes.hpp"
     22#include "Parser/FormatParser.hpp"
     23#include "Parser/MpqcParser.hpp"
     24#include "Parser/PcpParser.hpp"
     25#include "Parser/PdbParser.hpp"
     26#include "Parser/TremoloParser.hpp"
     27#include "Parser/XyzParser.hpp"
    2728
    2829class atom;
    29 class FormatParserInterface;
     30
     31// enum has to be outside of class for operator++ to be possible
     32enum ParserTypes { mpqc, pcp, pdb, tremolo, xyz, ParserTypes_end, ParserTypes_begin = mpqc };
     33typedef enum ParserTypes ParserTypes;
     34
     35ParserTypes &operator++(ParserTypes &type);
    3036
    3137class FormatParserStorage : public Singleton<FormatParserStorage> {
     
    3339public:
    3440
     41  void addMpqc();
     42  void addPcp();
     43  void addPdb();
     44  void addTremolo();
     45  void addXyz();
    3546  bool add(std::string type);
    3647  bool add(ParserTypes type);
     
    4152  bool saveSelectedMolecules(std::ostream &output, std::string suffix);
    4253  bool saveWorld(std::ostream &output, std::string suffix);
    43  
    44   FormatParserInterface &get(ParserTypes _type);
     54  MpqcParser &getMpqc();
     55  PcpParser &getPcp();
     56  PdbParser &getPdb();
     57  TremoloParser &getTremolo();
     58  XyzParser &getXyz();
     59  FormatParser &get(enum ParserTypes _type);
    4560
    4661  ParserTypes getTypeFromName(std::string type);
     
    5671 
    5772  // list of allocated parsers
    58   std::vector<FormatParserInterface *> ParserList;
     73  std::vector<FormatParser *> ParserList;
    5974
    6075  // list of allocated strams
     
    7590  std::map<std::string, ParserTypes> ParserLookupNames;
    7691
     92
    7793  // prefix of the filenames to use on save
    7894  std::string prefix;
    79 
    80 public:
    81   template<ParserTypes Ptype> void addParser()
    82   {
    83     if (!ParserPresent[Ptype]) {
    84       ParserList[Ptype] = new FormatParser<Ptype>();
    85       ParserPresent[Ptype] = true;
    86     } else {
    87       ASSERT(ParserNames.find(Ptype) != ParserNames.end(),
    88           "FormatParserStorage::addParser() - ParserNames unknown for type"+toString((size_t)Ptype)+".");
    89       ASSERT(ParserSuffixes.find(Ptype) != ParserSuffixes.end(),
    90           "FormatParserStorage::addParser() - ParserSuffixes unknown for type"+toString((size_t)Ptype)+".");
    91       LOG(2, "INFO: Parser " << ParserNames[Ptype] << " is already present." << std::endl
    92           << "Note that you don't need to add '-o "
    93           << ParserSuffixes[Ptype] << "' if the input file is non-empty and of type "
    94           << ParserSuffixes[Ptype] << "." << std::endl);
    95     }
    96   }
    97 
    98   template<ParserTypes Ptype> FormatParser<Ptype> &getParser()
    99   {
    100     if(!ParserPresent[Ptype])
    101       addParser< Ptype >();
    102     return dynamic_cast<FormatParser<Ptype> &>(*ParserList[Ptype]);
    103   }
    10495};
    10596
  • src/Parser/FormatParser_Parameters.hpp

    r360c8b rfa9d1d  
    1414#endif
    1515
    16 #include <iosfwd>
    17 
    1816#include "CodePatterns/Clone.hpp"
    19 
    20 #include "Parser/Parameters/ParameterStorage.hpp"
    21 
    22 class Parameter;
    2317
    2418/** This class is an interface to the internal parameters of any FormatParser.
     
    2923class FormatParser_Parameters : public Clone<FormatParser_Parameters>
    3024{
    31   //!> allow operator access to storage for easier printing.
    32   friend std::ostream & operator << (std::ostream& ost, const FormatParser_Parameters &params);
    3325public:
    34   FormatParser_Parameters();
    35   FormatParser_Parameters(const FormatParser_Parameters &_parameters);
    36   ~FormatParser_Parameters();
     26  FormatParser_Parameters() {}
     27  ~FormatParser_Parameters() {}
    3728
    38   // cloning
    39   FormatParser_Parameters* clone() const;
    40   void makeClone(const FormatParser_Parameters &_instance);
    41 
    42   // accessing parameters in storage
    43   void appendParameter(Parameter *instance);
    44   bool haveParameter(const std::string &_name) const;
    45   Parameter *getParameter(const std::string &_name) const;
    46 
    47 protected:
    48   ParameterStorage *storage;
     29  /** Makes this instance a clone of given \a _instance.
     30   *
     31   * @param _instance instance to clone
     32   */
     33  virtual void makeClone(const FormatParser_Parameters & _instance)=0;
    4934};
    50 
    51 std::ostream & operator << (std::ostream& ost, const FormatParser_Parameters &params);
    52 
    53 std::istream & operator >> (std::istream& ist, FormatParser_Parameters &params);
    5435
    5536
  • src/Parser/Makefile.am

    r360c8b rfa9d1d  
    55PARSERSOURCE = \
    66  Parser/ChangeTracker.cpp \
    7   Parser/FormatParser_common.cpp \
    8   Parser/FormatParser_Parameters.cpp \
     7  Parser/FormatParser.cpp \
    98  Parser/FormatParserStorage.cpp \
    109  Parser/MpqcParser.cpp \
    1110  Parser/MpqcParser_Parameters.cpp \
    1211  Parser/MpqcParser_Parameters_initBasis.cpp \
    13   Parser/ParserTypes.cpp \
    1412  Parser/PcpParser.cpp \
    1513  Parser/PdbAtomInfoContainer.cpp \
    1614  Parser/PdbParser.cpp \
    17   Parser/Psi3Parser.cpp \
    18   Parser/Psi3Parser_Parameters.cpp \
    1915  Parser/TremoloParser.cpp \
    2016  Parser/TremoloAtomInfoContainer.cpp \
     
    2420  Parser/ChangeTracker.hpp \
    2521  Parser/FormatParser.hpp \
    26   Parser/FormatParser_specializations_header.hpp \
    27   Parser/FormatParser_common.hpp \
    28   Parser/FormatParserInterface.hpp \
    29   Parser/FormatParserTrait.hpp \
    30   Parser/FormatParserTrait_specializations_header.hpp \
    3122  Parser/FormatParser_Parameters.hpp \
    3223  Parser/FormatParserStorage.hpp \
    3324  Parser/MpqcParser.hpp \
    3425  Parser/MpqcParser_Parameters.hpp \
    35   Parser/ParserTypes.hpp \
    36   Parser/ParserTypes.def \
    37   Parser/ParserTypes.undef \
    3826  Parser/PcpParser.hpp \
    3927  Parser/PdbAtomInfoContainer.hpp \
    4028  Parser/PdbKey.hpp \
    4129  Parser/PdbParser.hpp \
    42   Parser/Psi3Parser.hpp \
    43   Parser/Psi3Parser_Parameters.hpp \
    4430  Parser/TremoloKey.hpp \
    4531  Parser/TremoloParser.hpp \
     
    4733  Parser/XyzParser.hpp
    4834
    49 PARSERPARAMETERSSOURCE = \
    50         Parser/Parameters/ParameterStorage.cpp \
    51         Parser/Parameters/StringParameter.cpp
    52 
    53 PARSERPARAMETERSHEADER = \
    54         Parser/Parameters/ParameterStorage.hpp \
    55         Parser/Parameters/ContinuousParameter.hpp \
    56         Parser/Parameters/ContinuousParameter_impl.hpp \
    57         Parser/Parameters/ContinuousValue.hpp \
    58         Parser/Parameters/ContinuousValue_impl.hpp \
    59         Parser/Parameters/DiscreteParameter.hpp \
    60         Parser/Parameters/DiscreteParameter_impl.hpp \
    61         Parser/Parameters/DiscreteValue.hpp \
    62         Parser/Parameters/DiscreteValue_impl.hpp \
    63         Parser/Parameters/Parameter.hpp \
    64         Parser/Parameters/StringParameter.hpp \
    65         Parser/Parameters/ValueInterface.hpp
    6635
    6736noinst_LTLIBRARIES += libMolecuilderParser.la
    6837libMolecuilderParser_la_includedir = $(includedir)/MoleCuilder/Parser/
    6938
    70 nobase_libMolecuilderParser_la_include_HEADERS = ${PARSERHEADER} ${PARSERPARAMETERSHEADER}
     39nobase_libMolecuilderParser_la_include_HEADERS = ${PARSERHEADER}
    7140
    7241## Define the source file list for the "libexample-@MOLECUILDER_API_VERSION@.la"
     
    7847## from each source file.  Note that it is not necessary to list header files
    7948## which are already listed elsewhere in a _HEADERS variable assignment.
    80 libMolecuilderParser_la_SOURCES = ${PARSERSOURCE} ${PARSERPARAMETERSSOURCE}
     49libMolecuilderParser_la_SOURCES = ${PARSERSOURCE}
    8150
    8251## Instruct libtool to include ABI version information in the generated shared
  • src/Parser/MpqcParser.cpp

    r360c8b rfa9d1d  
    3838#include "World.hpp"
    3939
    40 // declare specialized static variables
    41 const std::string FormatParserTrait<mpqc>::name = "mpqc";
    42 const std::string FormatParserTrait<mpqc>::suffix = "in";
    43 const ParserTypes FormatParserTrait<mpqc>::type = mpqc;
    44 
    45 // a converter we often need
    46 ConvertTo<bool> FormatParser<mpqc>::Converter;
    4740
    4841/** Constructor of MpqcParser.
    4942 *
    5043 */
    51 FormatParser< mpqc >::FormatParser() :
    52   FormatParser_common(new MpqcParser_Parameters())
    53 {}
     44MpqcParser::MpqcParser()
     45{
     46  parameters = new MpqcParser_Parameters();
     47}
    5448
    5549/** Destructor of MpqcParser.
    5650 *
    5751 */
    58 FormatParser< mpqc >::~FormatParser()
    59 {}
     52MpqcParser::~MpqcParser()
     53{
     54  delete parameters;
     55}
    6056
    6157/** Load an MPQC config file into the World.
    6258 * \param *file input stream
    6359 */
    64 void FormatParser< mpqc >::load(istream *file)
     60void MpqcParser::load(istream *file)
    6561{
    6662  bool MpqcSection = false;
     
    10096        tokenizer::iterator tok_iter = tokens.begin();
    10197        ASSERT(tok_iter != tokens.end(),
    102             "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");
     98            "MpqcParser::load() - missing token for MoleculeSection in line "+linestring+"!");
    10399        std::stringstream whitespacefilter(*tok_iter++);
    104100        std::string element;
    105101        whitespacefilter >> ws >> element;
    106102        ASSERT(tok_iter != tokens.end(),
    107             "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");
     103            "MpqcParser::load() - missing token for MoleculeSection in line "+linestring+"!");
    108104        std::string vector = *tok_iter;
    109105        tokenizer vectorcomponents(vector, whitesep);
     
    129125        ++tok_iter;
    130126        ASSERT(tok_iter != tokens.end(),
    131             "FormatParser< mpqc >::load() - missing token in brackets<> for mole< in line "+linestring+"!");
     127            "MpqcParser::load() - missing token in brackets<> for mole< in line "+linestring+"!");
    132128        std::string value(*tok_iter);
    133129        std::stringstream linestream("theory = "+value);
     
    138134        ++tok_iter;
    139135        ASSERT(tok_iter != tokens.end(),
    140             "FormatParser< mpqc >::load() - missing token in brackets<> for integrals< in line "+linestring+"!");
     136            "MpqcParser::load() - missing token in brackets<> for integrals< in line "+linestring+"!");
    141137        std::string value(*tok_iter);
    142138        std::stringstream linestream("integration = "+value);
     
    147143        tokenizer::iterator tok_iter = tokens.begin();
    148144        ASSERT(tok_iter != tokens.end(),
    149             "FormatParser< mpqc >::load() - missing token before '=' for MpqcSection in line "+linestring+"!");
     145            "MpqcParser::load() - missing token before '=' for MpqcSection in line "+linestring+"!");
    150146        std::stringstream whitespacefilter(*tok_iter);
    151147        std::string key;
    152148        whitespacefilter >> ws >> key;
    153         if (getParams().haveParameter(key)) {
     149        if (getParams().haveParam(key)) {
    154150          std::stringstream linestream(linestring);
    155151          linestream >> getParams();
     
    163159      tokenizer::iterator tok_iter = tokens.begin();
    164160      ASSERT(tok_iter != tokens.end(),
    165           "FormatParser< mpqc >::load() - missing token for BasisSection in line "+linestring+"!");
     161          "MpqcParser::load() - missing token for BasisSection in line "+linestring+"!");
    166162      std::string key(*tok_iter++);
    167163      ASSERT(tok_iter != tokens.end(),
    168           "FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
     164          "MpqcParser::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
    169165      std::string value(*tok_iter);
    170166      tok_iter++;
    171167      // TODO: use exception instead of ASSERT
    172168      ASSERT(tok_iter == tokens.end(),
    173           "FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+".");
     169          "MpqcParser::load() - more than (key = value) on line "+linestring+".");
    174170      if (key == "name") {
    175171        std::stringstream linestream("basis = "+value);
     
    181177      tokenizer::iterator tok_iter = tokens.begin();
    182178      ASSERT(tok_iter != tokens.end(),
    183           "FormatParser< mpqc >::load() - missing token for AuxBasisSection in line "+linestring+"!");
     179          "MpqcParser::load() - missing token for AuxBasisSection in line "+linestring+"!");
    184180      std::string key(*tok_iter++);
    185181      ASSERT(tok_iter != tokens.end(),
    186           "FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
     182          "MpqcParser::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
    187183      std::string value(*tok_iter);
    188184      tok_iter++;
    189185      // TODO: use exception instead of ASSERT
    190186      ASSERT(tok_iter == tokens.end(),
    191           "FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+".");
     187          "MpqcParser::load() - more than (key = value) on line "+linestring+".");
    192188      if (key == "name") {
    193189        std::stringstream linestream("aux_basis = "+value);
     
    220216 * \param atoms atoms to store
    221217 */
    222 void FormatParser< mpqc >::save(ostream *file, const std::vector<atom *> &atoms)
     218void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms)
    223219{
    224220  Vector center;
     
    236232    *file << "% Created by MoleCuilder" << endl;
    237233    *file << "mpqc: (" << endl;
    238     *file << "\tsavestate = " << getParams().getParameter(MpqcParser_Parameters::savestateParam) << endl;
    239     *file << "\tdo_gradient = " << getParams().getParameter(MpqcParser_Parameters::do_gradientParam) << endl;
    240     if (Converter(getParams().getParameter(MpqcParser_Parameters::hessianParam))) {
     234    *file << "\tsavestate = " << getParams().getString(MpqcParser_Parameters::savestateParam) << endl;
     235    *file << "\tdo_gradient = " << getParams().getString(MpqcParser_Parameters::do_gradientParam) << endl;
     236    if (getParams().getBool(MpqcParser_Parameters::hessianParam)) {
    241237      *file << "\tfreq<MolecularFrequencies>: (" << endl;
    242238      *file << "\t\tmolecule=$:molecule" << endl;
    243239      *file << "\t)" << endl;
    244240    }
    245     const std::string theory = getParams().getParameter(MpqcParser_Parameters::theoryParam);
    246     if (theory == getParams().getTheoryName(MpqcParser_Parameters::CLHF)) {
    247       *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    248       *file << "\t\tmolecule = $:molecule" << endl;
    249       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
    250       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam)
    251           << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
    252       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
    253           << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
    254       *file << "\t)" << endl;
    255     } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::CLKS)) {
    256       *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    257       *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
    258       *file << "\t\tmolecule = $:molecule" << endl;
    259       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
    260       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam)
    261           << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
    262       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
    263           << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
    264       *file << "\t)" << endl;
    265     } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2)) {
    266       *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    267       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
    268       *file << "\t\tmolecule = $:molecule" << endl;
    269       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
    270           << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
    271       *file << "\t\treference<CLHF>: (" << endl;
    272       *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam)
    273           << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
    274       *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
    275       *file << "\t\t\tmolecule = $:molecule" << endl;
    276       *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
    277           << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
    278       *file << "\t\t)" << endl;
    279       *file << "\t)" << endl;
    280     } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) {
    281       *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    282       *file << "\t\tmolecule = $:molecule" << endl;
    283       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
    284       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::aux_basisParam) << " = $:abasis" << endl;
    285       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::stdapproxParam)
    286           << " = \"" << getParams().getParameter(MpqcParser_Parameters::stdapproxParam) << "\"" << endl;
    287       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::nfzcParam)
    288           << " = " << getParams().getParameter(MpqcParser_Parameters::nfzcParam) << endl;
    289       *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
    290           << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
    291       *file << "\t\tintegrals<IntegralCints>:()" << endl;
    292       *file << "\t\treference<CLHF>: (" << endl;
    293       *file << "\t\t\tmolecule = $:molecule" << endl;
    294       *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
    295       *file << "\t\t\tmaxiter = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam) << endl;
    296       *file << "\t\t\tmemory = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
    297       *file << "\t\t\tintegrals<" << getParams().getParameter(MpqcParser_Parameters::integrationParam) << ">:()" << endl;
    298       *file << "\t\t)" << endl;
    299       *file << "\t)" << endl;
    300     } else {
    301       DoeLog(0) && (eLog() << Verbose(0)
    302           << "Unknown level of theory requested for MPQC output file." << std::endl);
     241    switch (getParams().getTheory()) {
     242      case MpqcParser_Parameters::CLHF:
     243        *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     244        *file << "\t\tmolecule = $:molecule" << endl;
     245        *file << "\t\tbasis = $:basis" << endl;
     246        *file << "\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl;
     247        *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
     248        *file << "\t)" << endl;
     249        break;
     250      case MpqcParser_Parameters::CLKS:
     251        *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     252        *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
     253        *file << "\t\tmolecule = $:molecule" << endl;
     254        *file << "\t\tbasis = $:basis" << endl;
     255        *file << "\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl;
     256        *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
     257        *file << "\t)" << endl;
     258        break;
     259      case MpqcParser_Parameters::MBPT2:
     260        *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     261        *file << "\t\tbasis = $:basis" << endl;
     262        *file << "\t\tmolecule = $:molecule" << endl;
     263        *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
     264        *file << "\t\treference<CLHF>: (" << endl;
     265        *file << "\t\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl;
     266        *file << "\t\t\tbasis = $:basis" << endl;
     267        *file << "\t\t\tmolecule = $:molecule" << endl;
     268        *file << "\t\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
     269        *file << "\t\t)" << endl;
     270        *file << "\t)" << endl;
     271        break;
     272      case MpqcParser_Parameters::MBPT2_R12:
     273        *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     274        *file << "\t\tmolecule = $:molecule" << endl;
     275        *file << "\t\tbasis = $:basis" << endl;
     276        *file << "\t\taux_basis = $:abasis" << endl;
     277        *file << "\t\tstdapprox = \"" << getParams().getString(MpqcParser_Parameters::stdapproxParam) << "\"" << endl;
     278        *file << "\t\tnfzc = " << toString(getParams().getInt(MpqcParser_Parameters::nfzcParam)) << endl;
     279        *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
     280        *file << "\t\tintegrals<IntegralCints>:()" << endl;
     281        *file << "\t\treference<CLHF>: (" << endl;
     282        *file << "\t\t\tmolecule = $:molecule" << endl;
     283        *file << "\t\t\tbasis = $:basis" << endl;
     284        *file << "\t\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam)) << endl;
     285        *file << "\t\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
     286        *file << "\t\t\tintegrals<" << getParams().getString(MpqcParser_Parameters::integrationParam) << ">:()" << endl;
     287        *file << "\t\t)" << endl;
     288        *file << "\t)" << endl;
     289        break;
     290      default:
     291        DoeLog(0) && (eLog() << Verbose(0)
     292            << "Unknown level of theory requested for MPQC output file." << std::endl);
     293        break;
    303294    }
    304295    *file << ")" << endl;
     
    313304    *file << ")" << endl;
    314305    *file << "basis<GaussianBasisSet>: (" << endl;
    315     *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::basisParam) << "\"" << endl;
     306    *file << "\tname = \"" << getParams().getString(MpqcParser_Parameters::basisParam) << "\"" << endl;
    316307    *file << "\tmolecule = $:molecule" << endl;
    317308    *file << ")" << endl;
    318     if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) {
     309    if (getParams().getTheory() == MpqcParser_Parameters::MBPT2_R12) {
    319310      *file << "% auxiliary basis set specification" << endl;
    320311      *file << "\tabasis<GaussianBasisSet>: (" << endl;
    321       *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
     312      *file << "\tname = \"" << getParams().getString(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
    322313      *file << "\tmolecule = $:molecule" << endl;
    323314      *file << ")" << endl;
  • src/Parser/MpqcParser.hpp

    r360c8b rfa9d1d  
    1414#endif
    1515
    16 #include "CodePatterns/toString.hpp"
    1716
    1817#include "FormatParser.hpp"
    19 #include "FormatParserTrait.hpp"
    20 #include "FormatParserInterface.hpp"
    21 #include "FormatParser_common.hpp"
    22 #include "ParserTypes.hpp"
    23 
    2418#include "MpqcParser_Parameters.hpp"
    2519
    2620#include <iosfwd>
    2721
    28 // declaration of specialized FormatParserTrait
    29 template<>
    30 struct FormatParserTrait<mpqc>
    31 {
    32   //!> Name of the parser
    33   static const std::string name;
    34   //!> suffix of the files the parser understands to read and write
    35   static const std::string suffix;
    36   //!> ParserTypes enumeration for the parser
    37   static const enum ParserTypes type;
    38 };
    39 
    4022/**
    4123 * Loads a MPQC config file into the World and saves the World as a tremolo file.
    4224 */
    43 template <>
    44 class FormatParser< mpqc >  : virtual public FormatParserInterface, public FormatParser_common
     25class MpqcParser : public FormatParser
    4526{
    4627  friend class ParserMpqcUnitTest;
    4728public:
    48   FormatParser();
    49   virtual ~FormatParser();
    5029
    51   void load(std::istream *file);
    52   void save(std::ostream *file, const std::vector<atom *> &atoms);
     30  MpqcParser();
     31  virtual ~MpqcParser();
     32  void load(std::istream* file);
     33  void save(std::ostream* file, const std::vector<atom *> &atoms);
    5334
    5435  /** Getter for parameter set.
     
    5738   */
    5839  MpqcParser_Parameters & getParams() { return *static_cast<MpqcParser_Parameters *>(parameters); }
    59 
    60 private:
    61   static ConvertTo<bool> Converter;
    6240};
    6341
  • src/Parser/MpqcParser_Parameters.cpp

    r360c8b rfa9d1d  
    1818#endif
    1919
     20#include <iostream>
     21#include <boost/tokenizer.hpp>
     22#include <string>
     23
    2024#include "CodePatterns/MemDebug.hpp"
    2125
    22 #include <string>
    23 
    2426#include "CodePatterns/Log.hpp"
     27#include "CodePatterns/Verbose.hpp"
    2528
    2629#include "MpqcParser.hpp"
     30
    2731#include "MpqcParser_Parameters.hpp"
    2832
    29 #include "Parser/Parameters/ContinuousParameter.hpp"
    30 #include "Parser/Parameters/DiscreteParameter.hpp"
    31 #include "Parser/Parameters/StringParameter.hpp"
    32 
    33 template <>
    34 const std::string ContinuousValue<bool>::get() const
    35 {
    36   ASSERT(ValueSet,
    37       "ContinuousValue<bool>::get() - requesting unset value.");
    38   if (value)
    39     return std::string("yes");
    40   else
    41     return std::string("no");
    42 }
    43 
    44 template <>
    45 void ContinuousValue<bool>::set(const std::string _value)
    46 {
    47   if (_value == std::string("yes")) {
    48     setValue(true);
    49   } else if (_value == std::string("no")) {
    50     setValue(false);
    51   } else {
    52     ASSERT(0,
    53         "void ContinuousValue<bool>::set() - value "+_value+" is neither yes or no.");
    54   }
    55 }
    56 
     33
     34using boost::any_cast;
    5735
    5836MpqcParser_Parameters::MpqcParser_Parameters()
     
    6644  initBasis();
    6745
    68   // add all parameter names
     46  // add all theory names
     47  TheoryNames[CLHF]="CLHF";
     48  TheoryNames[CLKS]="CLKS";
     49  TheoryNames[MBPT2]="MBPT2";
     50  TheoryNames[MBPT2_R12]="MBPT2_R12";
     51
    6952  {
    70     ParamNames.clear();
    71     ParamNames.resize(unknownParam);
    72     ParamNames[hessianParam] = "Hessian";
    73     ParamNames[savestateParam] = "savestate";
    74     ParamNames[do_gradientParam] = "do_gradient";
    75     ParamNames[maxiterParam] = "maxiter";
    76     ParamNames[memoryParam] = "memory";
    77     ParamNames[stdapproxParam] = "stdapprox";
    78     ParamNames[nfzcParam] = "nfzc";
    79     ParamNames[basisParam] = "basis";
    80     ParamNames[aux_basisParam] = "aux_basis";
    81     ParamNames[integrationParam] = "integration";
    82     ParamNames[theoryParam] = "theory";
    83   }
    84 
    85   // create theory parameter
     53    // TODO: throw exception instead of eLog()
     54    std::pair<TheoryLookupType::iterator, bool> inserter;
     55    for (TheoryNamesType::iterator iter = TheoryNames.begin();
     56        iter != TheoryNames.end();
     57        ++iter) {
     58      inserter = TheoryLookup.insert( make_pair(iter->second, iter->first) );
     59      if (!inserter.second)
     60        DoeLog(0) && (eLog() << Verbose(0)
     61            << "MpqcParser_Parameters::MpqcParser_Parameters() - Theory name already present: "
     62            << (inserter.first)->second << " and " << iter->first << "!"
     63            << std::endl);
     64    }
     65  }
     66
     67  // add all integration names
     68  IntegrationNames[IntegralCints] = "IntegralCints";
    8669  {
    87     ValidTheories.clear();
    88     ValidTheories.resize(unknownTheory);
    89     ValidTheories[CLHF]="CLHF";
    90     ValidTheories[CLKS]="CLKS";
    91     ValidTheories[MBPT2]="MBPT2";
    92     ValidTheories[MBPT2_R12]="MBPT2_R12";
    93     appendParameter(
    94         new DiscreteParameter<std::string>(
    95             ParamNames[theoryParam],
    96             ValidTheories,
    97             ValidTheories[MBPT2]));
    98   }
    99   //InvertMap<TheoryNamesType,TheoryLookupType>(TheoryNames,TheoryLookup);
    100 
    101   // create integration parameter
     70    // TODO: throw exception instead of eLog()
     71    std::pair<IntegrationLookupType::iterator, bool> inserter;
     72    for (IntegrationNamesType::iterator iter = IntegrationNames.begin();
     73        iter != IntegrationNames.end();
     74        ++iter) {
     75      inserter = IntegrationLookup.insert( make_pair(iter->second, iter->first) );
     76      if (!inserter.second)
     77        DoeLog(0) && (eLog() << Verbose(0)
     78            << "MpqcParser_Parameters::MpqcParser_Parameters() - Integration name already present: "
     79            << (inserter.first)->second << " and " << iter->first << "!"
     80            << std::endl);
     81    }
     82  }
     83
     84  // have names for all parmaters
     85  ParamNames[hessianParam] = "Hessian";
     86  ParamNames[savestateParam] = "savestate";
     87  ParamNames[do_gradientParam] = "do_gradient";
     88  ParamNames[maxiterParam] = "maxiter";
     89  ParamNames[memoryParam] = "memory";
     90  ParamNames[stdapproxParam] = "stdapprox";
     91  ParamNames[nfzcParam] = "nfzc";
     92  ParamNames[basisParam] = "basis";
     93  ParamNames[aux_basisParam] = "aux_basis";
     94  ParamNames[integrationParam] = "integration";
     95  ParamNames[theoryParam] = "theory";
     96
    10297  {
    103     ValidIntegrationMethods.clear();
    104     ValidIntegrationMethods.resize(unknownIntegration);
    105     ValidIntegrationMethods[IntegralCints] = "IntegralCints";
    106     appendParameter(
    107         new DiscreteParameter<std::string>(
    108             ParamNames[integrationParam],
    109             ValidIntegrationMethods,
    110             ValidIntegrationMethods[IntegralCints]));
    111   }
    112 
    113   // add all continuous parameters
    114   {
    115     appendParameter(new ContinuousParameter<bool>(ParamNames[hessianParam], false));
    116     appendParameter(new ContinuousParameter<bool>(ParamNames[savestateParam], false));
    117     appendParameter(new ContinuousParameter<bool>(ParamNames[do_gradientParam], true));
    118     appendParameter(new ContinuousParameter<int>(ParamNames[maxiterParam], 1000));
    119     appendParameter(new ContinuousParameter<int>(ParamNames[memoryParam], 16000000));
    120     appendParameter(new StringParameter(ParamNames[stdapproxParam], "A'"));
    121     appendParameter(new ContinuousParameter<int>(ParamNames[nfzcParam], 1));
    122     appendParameter(new StringParameter(ParamNames[basisParam], "3-21G"));
    123     appendParameter(new StringParameter(ParamNames[aux_basisParam], "aug-cc-pVDZ"));
    124   }
     98    // TODO: throw exception instead of eLog()
     99    std::pair<ParamLookupType::iterator, bool> inserter;
     100    for (ParamNamesType::iterator iter = ParamNames.begin();
     101        iter != ParamNames.end();
     102        ++iter) {
     103      inserter = ParamLookup.insert( make_pair(iter->second, iter->first) );
     104      if (!inserter.second)
     105        DoeLog(0) && (eLog() << Verbose(0)
     106            << "MpqcParser_Parameters::MpqcParser_Parameters() - parameter name already present: "
     107            << (inserter.first)->second << " and " << iter->first << "!"
     108            << std::endl);
     109    }
     110  }
     111
     112  initParameters();
     113}
     114
     115MpqcParser_Parameters::MpqcParser_Parameters(const MpqcParser_Parameters & state)
     116{
     117  // init
     118  Init();
     119
     120  // copy values
     121  copyParameters(state);
     122}
     123
     124void MpqcParser_Parameters::copyParameters(const MpqcParser_Parameters & state)
     125{
     126  appendParameter(hessianParam, state.getBool(hessianParam));
     127  appendParameter(savestateParam, state.getBool(savestateParam));
     128  appendParameter(do_gradientParam, state.getBool(do_gradientParam));
     129  appendParameter(maxiterParam, state.getInt(maxiterParam));
     130  appendParameter(memoryParam, state.getInt(memoryParam));
     131  appendParameter(stdapproxParam, state.getString(stdapproxParam));
     132  appendParameter(nfzcParam, state.getInt(nfzcParam));
     133  appendParameter(basisParam, state.getString(basisParam));
     134  appendParameter(aux_basisParam, state.getString(aux_basisParam));
     135  appendParameter(integrationParam, state.getIntegration());
     136  appendParameter(theoryParam, state.getTheory());
     137}
     138
     139FormatParser_Parameters* MpqcParser_Parameters::clone() const
     140{
     141  //LOG(3, "Cloning parameters.");
     142  MpqcParser_Parameters *instance = new MpqcParser_Parameters(*this);
     143  return instance;
     144}
     145
     146void MpqcParser_Parameters::makeClone(const FormatParser_Parameters & _state)
     147{
     148  //LOG(3, "Cloning parameters from other instance.");
     149  copyParameters(static_cast<const MpqcParser_Parameters &>(_state));
     150}
     151
     152void MpqcParser_Parameters::initParameters()
     153{
     154        appendParameter(hessianParam, bool(false));
     155        appendParameter(savestateParam, bool(false));
     156        appendParameter(do_gradientParam, bool(true));
     157        appendParameter(maxiterParam, int(1000));
     158        appendParameter(memoryParam, int(16000000));
     159        appendParameter(stdapproxParam, std::string("A'"));
     160        appendParameter(nfzcParam, int(1));
     161        appendParameter(basisParam, std::string("3-21G"));
     162        appendParameter(aux_basisParam, std::string("aug-cc-pVDZ"));
     163        appendParameter(integrationParam, IntegralCints);
     164        appendParameter(theoryParam, MBPT2);
    125165}
    126166
     
    128168{}
    129169
    130 /** Getter for a specific Parameter.
     170std::ostream & operator << (std::ostream& ost, MpqcParser_Parameters const &_mpqc_params)
     171{
     172  // this is ugly, but with boost::any to safeguard const-ness is plain impossible
     173  MpqcParser_Parameters &mpqc_params = const_cast<MpqcParser_Parameters &>(_mpqc_params);
     174  std::ostringstream output;
     175  output << "Hessian=" << mpqc_params.getBool(MpqcParser_Parameters::hessianParam) << ";";
     176  output << "savestate=" << mpqc_params.getBool(MpqcParser_Parameters::savestateParam) << ";";
     177  output << "do_gradient=" << mpqc_params.getBool(MpqcParser_Parameters::do_gradientParam) << ";";
     178  output << "maxiter=" << mpqc_params.getInt(MpqcParser_Parameters::maxiterParam) << ";";
     179  output << "memory=" << mpqc_params.getInt(MpqcParser_Parameters::memoryParam) << ";";
     180  output << "stdapprox=" << mpqc_params.getString(MpqcParser_Parameters::stdapproxParam) << ";";
     181  output << "nfzc=" << mpqc_params.getInt(MpqcParser_Parameters::nfzcParam) << ";";
     182  output << "basis=" << mpqc_params.getString(MpqcParser_Parameters::basisParam) << ";";
     183  output << "aux_basis=" << mpqc_params.getString(MpqcParser_Parameters::aux_basisParam) << ";";
     184  output << "integration=" << mpqc_params.getString(MpqcParser_Parameters::integrationParam) << ";";
     185  output << "theory=" << mpqc_params.getString(MpqcParser_Parameters::theoryParam) << ";";
     186  ost << output.str();
     187  return ost;
     188}
     189
     190std::istream & operator >> (std::istream& ist, MpqcParser_Parameters &params)
     191{
     192  typedef boost::tokenizer<boost::char_separator<char> >
     193      tokenizer;
     194  boost::char_separator<char> semicolonsep(";");
     195  boost::char_separator<char> equalitysep(" =");
     196  boost::char_separator<char> ticksep("\"");
     197  std::string line;
     198  std::getline( ist, line );
     199  //DoLog(0) && (Log() << Verbose(0) << "INFO: full line of parameters is '" << line << "'" << std::endl);
     200  tokenizer tokens(line, semicolonsep);
     201  ASSERT(tokens.begin() != tokens.end(),
     202      "operator<< on MpqcParser_Parameters - empty string, need at least ';' in line "+line+"!");
     203  for (tokenizer::iterator tok_iter = tokens.begin();
     204        tok_iter != tokens.end(); ++tok_iter) {
     205    tokenizer paramtokens(*tok_iter, equalitysep);
     206    if (paramtokens.begin() != paramtokens.end()) {
     207      tokenizer::iterator tok_paramiter = paramtokens.begin();
     208      tokenizer::iterator tok_valueiter = tok_paramiter;
     209      tokenizer::iterator tok_checkiter = ++tok_valueiter;
     210      ++tok_checkiter;
     211      // TODO: throw exception instead of ASSERT
     212      ASSERT(tok_paramiter != paramtokens.end(),
     213          "operator<< on MpqcParser_Parameters - missing value before ' =' in token "+*tok_iter+"!");
     214      ASSERT(tok_valueiter != paramtokens.end(),
     215          "operator<< on MpqcParser_Parameters - missing value after ' =' in token "+*tok_iter+"!");
     216      ASSERT(tok_checkiter == paramtokens.end(),
     217          "operator<< on MpqcParser_Parameters - still more tokens after ' =' in token "+*tok_iter+":"
     218          +*tok_checkiter+"!");
     219      std::stringstream keystream(*tok_paramiter);
     220      std::string key;
     221      keystream >> ws >> key;
     222      tokenizer ticklesstokens(*tok_valueiter, ticksep);
     223      ASSERT(ticklesstokens.begin() != ticklesstokens.end(),
     224          "operator<< on MpqcParser_Parameters - no tokens present after removing ticks in token "+*tok_valueiter+"!");
     225      std::stringstream valuestream(*(ticklesstokens.begin()));
     226      DoLog(2) && (Log() << Verbose(2)
     227          << "INFO: Token pair is " << key << "," << valuestream.str() << std::endl);
     228
     229      // TODO: throw exception instead of DoeLog()
     230      ASSERT(params.haveParam(key),
     231          "operator >> on MpqcParser_Parameters - unknown parameter name '"
     232          +key+"' with value "+valuestream.str()+"!");
     233      if (params.haveParam(key))
     234        params.setter(params.getParam(key), valuestream);
     235    } else {
     236      ist.setstate(std::ios::eofbit);
     237    }
     238  }
     239  return ist;
     240}
     241
     242
     243/** Sets a desired value in the params from a string.
    131244 *
    132  * @param param index among enum Parameters
    133  * @return value of the desired Parameters
     245 * This is due to strict typing of C++ very ugly and boost::any does not make
     246 * it any better because it offers to functions to use values directly from
     247 * stringstream. Probably, because value is unknown to is as well and hence
     248 * the author could not implement it beautifully, so he dropped it altogether.
     249 * Grrr ....
     250 *
     251 * @param _param param to set
     252 * @param _desired stringstream containing value as next argument
     253 * @return true - type ok, false - unknown type in params.
    134254 */
    135 const std::string MpqcParser_Parameters::getParameter(const enum Parameters param) const
    136 {
    137   return FormatParser_Parameters::getParameter(ParamNames[param])->get();
    138 }
    139 
    140 /** Setter for a specific Parameter.
    141  *
    142  * @param param index among enum Parameters
    143  * @param _value value to set desired Parameter to
    144  */
    145 void MpqcParser_Parameters::setParameter(const enum Parameters param, const std::string &_value)
    146 {
    147   const std::string &name = getParameterName(param);
    148   FormatParser_Parameters::getParameter(name)->set(_value);
    149 }
    150 
    151 /** Getter for name of a specific Parameter.
    152  *
    153  * @param param index among enum Parameters
    154  * @return name of the desired Parameter
    155  */
    156 const std::string &MpqcParser_Parameters::getParameterName(const enum Parameters param) const
    157 {
    158   return ParamNames[param];
    159 }
    160 
    161 /** Getter for name of a specific Parameter.
    162  *
    163  * @param param index among enum Theory
    164  * @return name of the desired Theory
    165  */
    166 const std::string &MpqcParser_Parameters::getTheoryName(const enum Theory theory) const
    167 {
    168   return ValidTheories[theory];
    169 }
    170 
    171 /** Getter for the name of specific of IntegrationMethod.
    172  *
    173  * @param param index among enum IntegrationMethod
    174  * @return value of the desired IntegrationMethod
    175  */
    176 const std::string &MpqcParser_Parameters::getIntegrationMethodName(const enum IntegrationMethod integration) const
    177 {
    178   return ValidIntegrationMethods[integration];
    179 }
     255bool MpqcParser_Parameters::setter(enum Parameters _param, std::stringstream& _desired) {
     256  if (_param == integrationParam) {
     257     std::string tmp;
     258    _desired >> tmp;
     259    params[_param] = IntegrationLookup[tmp];
     260  } else if(_param == theoryParam) {
     261    std::string tmp;
     262    _desired >> tmp;
     263    params[_param] = TheoryLookup[tmp];
     264  } else if (params[_param].type() == typeid(std::string)) {
     265    std::string tmp;
     266    _desired >> tmp;
     267    params[_param] = tmp;
     268  } else if (params[_param].type() ==  typeid(int)) {
     269    int tmp;
     270    _desired >> tmp;
     271    params[_param] = tmp;
     272  } else if (params[_param].type() == typeid(double)) {
     273    double tmp;
     274    _desired >> tmp;
     275    params[_param] = tmp;
     276  } else if (params[_param].type() == typeid(bool)) {
     277    std::string tmp;
     278    _desired >> tmp;
     279    if ((tmp == "yes") || (tmp == "1")) {
     280      params[_param] = bool(true);
     281    } else if ((tmp == "no") || (tmp == "0")) {
     282      params[_param] = bool(false);
     283    } else {
     284      DoeLog(0) && (eLog() << Verbose(0)
     285          << "MpqcParser_Parameters::setter() - unknown boolean key "
     286          << tmp << "!" << std::endl);
     287    }
     288  } else {
     289    DoeLog(0) && (eLog() << Verbose(0)
     290        << "MpqcParser_Parameters::setter() - unknown type!" << std::endl);
     291    return false;
     292  }
     293  return true;
     294}
     295
     296
     297void MpqcParser_Parameters::setTheory(enum Theory _theory)
     298{
     299  // TODO: throw exception instead of eLog()
     300//  try {
     301    params[theoryParam] = _theory;
     302//  } catch(const boost::bad_any_cast &) {
     303//    DoeLog(0) && (eLog() << Verbose(0)
     304//        << "MpqcParser_Parameters::setTheory() - could not set boolean!" << std::endl);
     305//  }
     306}
     307
     308void MpqcParser_Parameters::setIntegration(enum MpqcParser_Parameters::IntegrationMethod _integration){
     309  // TODO: throw exception instead of eLog()
     310//  try {
     311    params[integrationParam] = _integration;
     312//  } catch(const boost::bad_any_cast &) {
     313//    DoeLog(0) && (eLog() << Verbose(0)
     314//        << "MpqcParser_Parameters::setIntegration() - could not set boolean!" << std::endl);
     315//  }
     316}
     317
     318bool MpqcParser_Parameters::haveParam(std::string _name) const
     319{
     320  return ParamLookup.count(_name) != 0;
     321}
     322
     323enum MpqcParser_Parameters::Parameters MpqcParser_Parameters::getParam(std::string _name) const
     324{
     325  ParamLookupType::const_iterator iter = ParamLookup.find(_name);
     326  return iter->second;
     327}
     328
     329enum MpqcParser_Parameters::IntegrationMethod MpqcParser_Parameters::getIntegration() const
     330{
     331  parameterlist::const_iterator iter = params.find(integrationParam);
     332  enum IntegrationMethod value;
     333  // TODO: throw exception instead of eLog()
     334//  try {
     335    value = boost::any_cast<enum IntegrationMethod>(iter->second);
     336//  } catch(const boost::bad_any_cast &) {
     337//    DoeLog(0) && (eLog() << Verbose(0)
     338//        << "MpqcParser_Parameters::getIntegration() - could not convert "
     339//        +ParamNames[integrationParam]+" to enum IntegrationMethod!" << std::endl);
     340//  }
     341  return value;
     342}
     343
     344enum MpqcParser_Parameters::Theory MpqcParser_Parameters::getTheory() const
     345{
     346  parameterlist::const_iterator iter = params.find(theoryParam);
     347  enum Theory value;
     348  // TODO: throw exception instead of eLog()
     349//  try {
     350    value = boost::any_cast<enum Theory>(iter->second);
     351//  } catch(const boost::bad_any_cast &) {
     352//    DoeLog(0) && (eLog() << Verbose(0)
     353//        << "MpqcParser_Parameters::getTheory() - could not convert "
     354//        +ParamNames[theoryParam]+" to enum Theory!" << std::endl);
     355//  }
     356  return value;
     357}
     358
     359std::string MpqcParser_Parameters::getString(enum Parameters _param) const
     360{
     361  std::string value;
     362  enum IntegrationMethod Iindex;
     363  enum Theory Tindex;
     364  bool test;
     365  parameterlist::const_iterator iter = params.find(_param);
     366  switch (_param) {
     367    case hessianParam:
     368    case savestateParam:
     369    case do_gradientParam:
     370      test = boost::any_cast<bool>(iter->second);
     371      if (test)
     372        value = "yes";
     373      else
     374        value = "no";
     375      break;
     376    case integrationParam:
     377      // TODO: throw exception instead of eLog()
     378//      try {
     379        Iindex = boost::any_cast<enum IntegrationMethod>(iter->second);
     380//      } catch(const boost::bad_any_cast &) {
     381//        DoeLog(0) && (eLog() << Verbose(0)
     382//            << "MpqcParser_Parameters::getString() - could not convert "
     383//            +ParamNames[_param]+" to string!" << std::endl);
     384//      }
     385      {
     386        IntegrationNamesType::const_iterator Iiter = IntegrationNames.find(Iindex);
     387        value = Iiter->second;
     388      }
     389      break;
     390    case theoryParam:
     391      // TODO: throw exception instead of eLog()
     392//      try {
     393        Tindex = boost::any_cast<enum Theory>(iter->second);
     394//      } catch(const boost::bad_any_cast &) {
     395//        DoeLog(0) && (eLog() << Verbose(0)
     396//            << "MpqcParser_Parameters::getString() - could not convert "
     397//            +ParamNames[_param]+" to string!" << std::endl);
     398//      }
     399        {
     400          TheoryNamesType::const_iterator Titer = TheoryNames.find(Tindex);
     401          value = Titer->second;
     402        }
     403      break;
     404    default:
     405      // TODO: throw exception instead of eLog()
     406//      try {
     407        value = boost::any_cast<std::string>(iter->second);
     408//      } catch(const boost::bad_any_cast &) {
     409//        DoeLog(0) && (eLog() << Verbose(0)
     410//            << "MpqcParser_Parameters::getString() - could not convert "
     411//            +ParamNames[_param]+" to string!" << std::endl);
     412//      }
     413      break;
     414  }
     415
     416  return value;
     417}
     418
     419int MpqcParser_Parameters::getInt(enum Parameters _param) const
     420{
     421  int value;
     422  parameterlist::const_iterator iter = params.find(_param);
     423  switch (_param) {
     424    default:
     425      // TODO: throw exception instead of eLog()
     426//      try {
     427        value = boost::any_cast<int>(iter->second);
     428//      } catch(const boost::bad_any_cast &) {
     429//        DoeLog(0) && (eLog() << Verbose(0)
     430//            << "MpqcParser_Parameters::getInt() - could not convert "
     431//            +ParamNames[_param]+" to int!" << std::endl);
     432//      }
     433      break;
     434  }
     435  return value;
     436}
     437
     438double MpqcParser_Parameters::getDouble(enum Parameters _param) const
     439{
     440  double value;
     441  parameterlist::const_iterator iter = params.find(_param);
     442  // TODO: throw exception instead of eLog()
     443//  try {
     444    value = boost::any_cast<double>(iter->second);
     445//  } catch(const boost::bad_any_cast &) {
     446//    DoeLog(0) && (eLog() << Verbose(0)
     447//        << "MpqcParser_Parameters::getDouble() - could not convert "
     448//        +ParamNames[_param]+" to double!" << std::endl);
     449//  }
     450  return value;
     451}
     452
     453bool MpqcParser_Parameters::getBool(enum Parameters _param) const
     454{
     455  bool value;
     456  parameterlist::const_iterator iter = params.find(_param);
     457  // TODO: throw exception instead of eLog()
     458//  try {
     459    value = boost::any_cast<bool>(iter->second);
     460//  } catch(const boost::bad_any_cast &) {
     461//    DoeLog(0) && (eLog() << Verbose(0)
     462//        << "MpqcParser_Parameters::getBool() - could not convert "
     463//        +ParamNames[_param]+" to bool!" << std::endl);
     464//  }
     465  return value;
     466}
     467
    180468
    181469/** Checks whether all elements in the world also have parameters in the basis.
  • src/Parser/MpqcParser_Parameters.hpp

    r360c8b rfa9d1d  
    1414#endif
    1515
     16#include <iosfwd>
    1617#include <list>
    17 #include <map>
     18#include <typeinfo>
    1819#include <vector>
    1920
    2021#include "CodePatterns/Clone.hpp"
    2122#include "CodePatterns/Log.hpp"
     23#include "CodePatterns/Verbose.hpp"
     24
     25#include <boost/any.hpp>
    2226
    2327#include "Parser/FormatParser_Parameters.hpp"
    24 
    25 #include "Parser/Parameters/ContinuousParameter.hpp"
    26 
    27 // specialization for bool (we want "yes/no" not "1/0")
    28 template <> const std::string ContinuousValue<bool>::get() const;
    29 template <> void ContinuousValue<bool>::set(const std::string _value);
    3028
    3129class MpqcParser;
     
    4442  MpqcParser_Parameters();
    4543
     44  /** Copy Constructor of MpqcParser_Parameters.
     45   *
     46   * @param state ref to instance to copy
     47   */
     48  MpqcParser_Parameters(const MpqcParser_Parameters & state);
     49
    4650  /** Destructor of MpqcParser_Parameters.
    4751   *
    4852   */
    4953  virtual ~MpqcParser_Parameters();
     54
     55  /** Enumeration of all known theories.
     56   *
     57   */
     58  enum Theory {
     59    CLHF,       //!< Closed Shell Hartree-Fock equations
     60    CLKS,       //!< Closed Shell Kohn-Sham equations
     61    MBPT2,      //!< Moeller Plesset Perturbation Theory second order
     62    MBPT2_R12,  //!< Moeller Plesset Perturbation Theory second order with R12 integral
     63    unknownTheory //!< designates an unknown theory
     64  };
     65
     66  /** Enumeration of all known integration methods
     67   *
     68   */
     69  enum IntegrationMethod {
     70    IntegralCints,  //!< Integration method Cints in MBPT2 R12?
     71    unknownIntegration //!< designates unknown integration method
     72  };
    5073
    5174  /** Enumeration of all known Parameters to allow placing them in vectors, maps.
     
    6689    unknownParam};   //!< unknownParam, designates an unknown parameter
    6790
    68   /** Enumeration of all known theories.
    69    *
    70    */
    71   enum Theory {
    72     CLHF,       //!< Closed Shell Hartree-Fock equations
    73     CLKS,       //!< Closed Shell Kohn-Sham equations
    74     MBPT2,      //!< Moeller Plesset Perturbation Theory second order
    75     MBPT2_R12,  //!< Moeller Plesset Perturbation Theory second order with R12 integral
    76     unknownTheory //!< designates an unknown theory
    77   };
    78 
    79   /** Enumeration of all known integration methods
    80    *
    81    */
    82   enum IntegrationMethod {
    83     IntegralCints,  //!< Integration method Cints in MBPT2 R12?
    84     unknownIntegration //!< designates unknown integration method
    85   };
    86 
    87   // enum to string getters
    88   const std::string getParameter(const enum Parameters param) const;
    89   void setParameter(const enum Parameters param, const std::string &);
    90   const std::string &getParameterName(const enum Parameters param) const;
    91   const std::string &getTheoryName(const enum Theory theory) const;
    92   const std::string &getIntegrationMethodName(const enum IntegrationMethod integration) const;
     91  bool checkWorldElementsAgainstCurrentBasis() const;
     92
     93  /** Sets the desired level of solving theory to use.
     94   *
     95   * \param _theory shorthand of the theory
     96   */
     97  void setTheory(enum Theory _theory);
     98
     99  /** Sets the desired level of solving integration to use.
     100   *
     101   * \param _integration shorthand of the integration
     102   */
     103  void setIntegration(enum IntegrationMethod _integration);
     104
     105  /** Getter for integration method in params.
     106   *
     107   * @return enumeration index of IntegrationMethod.
     108   */
     109  enum IntegrationMethod getIntegration() const;
     110
     111  /** Getter for current Theory in params.
     112   *
     113   * @return enumeration index of Theory
     114   */
     115  enum Theory getTheory() const;
     116
     117  /** Getter for a parameter in params as a string.
     118   *
     119   * @param _param enumeration index of desired Parameter
     120   * @return string value
     121   */
     122  std::string getString(enum Parameters _param) const;
     123
     124  /** Getter for integer value of desired Parameter in params.
     125   *
     126   * Only if type in params matches int!
     127   *
     128   * @param _param enumeration index in Parameter
     129   * @return integer value of parameter
     130   */
     131  int getInt(enum Parameters _param) const;
     132
     133  /** Getter for double value of desired Parameter in params.
     134   *
     135   * Only if type in params matches double!
     136   *
     137   * @param _param enumeration index in Parameter
     138   * @return double value of parameter
     139   */
     140  double getDouble(enum Parameters _param) const;
     141
     142  /** Getter for bool value of desired Parameter in params.
     143   *
     144   * Only if type in params matches bool!
     145   *
     146   * @param _param enumeration index in Parameter
     147   * @return bool value of parameter
     148   */
     149  bool getBool(enum Parameters _param) const;
     150
     151  /** Setter for a desired value of its type is known.
     152   *
     153   * We check whether given type matches present type in params.
     154   *
     155   * @param _param enumeration index of Parameter
     156   * @param _desired desired value to set to
     157   * @return true - type match, value set, false - type mismatch
     158   */
     159  template <class T> bool setter(enum Parameters _param, T _desired) {
     160    if (typeid(T) == params[_param].type()) {
     161      params[_param] = _desired;
     162      return true;
     163    } else
     164      return false;
     165  }
     166
     167  /** Sets a desired value in the params from a string.
     168   *
     169   * This is due to strict typing of C++ very ugly and boost::any does not make
     170   * it any better because it offers to functions to use values directly from
     171   * stringstream. Probably, because value is unknown to is as well and hence
     172   * the author could not implement it beautifully, so he dropped it altogether.
     173   * Grrr ....
     174   *
     175   * @param _param param to set
     176   * @param _desired stringstream containing value as next argument
     177   * @return true - type ok, false - unknown type in params.
     178   */
     179  bool setter(enum Parameters _param, std::stringstream& _desired);
     180
     181  /** Grants access to ParamLookup.
     182   *
     183   *  Does not check for unknown parameter.
     184   *
     185   * @param _name name of parameter
     186   * @return enumeration index of Parameters
     187   */
     188  enum Parameters getParam(std::string _name) const;
     189
     190  /** Checker whether parameter with name is known.
     191   *
     192   * @param _name
     193   * @return true - parameter known, false - parameter unknown
     194   */
     195  bool haveParam(std::string _name) const;
     196
     197  /** Creates a clone of the class.
     198   *
     199   * @return
     200   */
     201  FormatParser_Parameters* clone() const;
     202
     203  /** Applies a before returned undo state.
     204   *
     205   * @param undo state to set
     206   */
     207  void makeClone(const FormatParser_Parameters & _state);
     208
     209  /** Set the internal parameters to the one's from the given \a state.
     210   *
     211   * @param state set of parameters
     212   */
     213  void copyParameters(const MpqcParser_Parameters & state);
    93214
    94215private:
    95 
    96 
    97   //!> vector with all available theories in same order as enum Theory.
    98   std::vector<std::string> ValidTheories;
    99 
    100   //!> vector with all available integration methods in same order as enum IntegrationMethod.
    101   std::vector<std::string> ValidIntegrationMethods;
    102 
    103   bool checkWorldElementsAgainstCurrentBasis() const;
    104 
    105216  /** Global initialization in cstor.
    106217   *
     
    113224  void initBasis();
    114225
    115   //!> vector with all parameter names in same order as enum Parameters
    116   std::vector<std::string> ParamNames;
    117 
    118   //!> typedef for the list of all available basis sets
     226  /** Initializes params.
     227   * Sets the type and the associated enumeration index.
     228   */
     229  void initParameters();
     230
     231  /** Internal function used by initParameters() to add parameters to params.
     232   *
     233   * @param _enum enumeration index to set
     234   * @param _p (default) value to set with certain type
     235   */
     236  template <class T> void appendParameter(enum Parameters _enum, T _p) {
     237    boost::any _p_value = _p;
     238    params[_enum] = _p_value;
     239  }
     240
     241  // all internal typedefs for lists below
    119242  typedef std::map<std::string, std::list<std::string> > BasisMapType;
    120 
    121   //!> list of all basis along with their present element parametrization
     243  typedef std::map<enum Theory, std::string> TheoryNamesType;
     244  typedef std::map<std::string, enum Theory> TheoryLookupType;
     245  typedef std::map<enum IntegrationMethod, std::string> IntegrationNamesType;
     246  typedef std::map<std::string, enum IntegrationMethod> IntegrationLookupType;
     247  typedef std::map<enum Parameters, std::string> ParamNamesType;
     248  typedef std::map<std::string, enum Parameters> ParamLookupType;
     249  typedef std::map<enum Parameters, boost::any> parameterlist;
     250
     251  //!> boost::any container for all the parameters
     252  parameterlist params;
     253
     254  // maps from names to enumerations
     255
     256  //!> contains basis and all elements the basis knows about
    122257  BasisMapType BasisList;
     258  //!> contains the name of a theory as string
     259  TheoryNamesType TheoryNames;
     260  //!> contains a lookup from theory name to enumeration index
     261  TheoryLookupType TheoryLookup;
     262  //!> contains the name of an integration method as string
     263  IntegrationNamesType IntegrationNames;
     264  //!> contains a lookup from integration method name to enumeration index
     265  IntegrationLookupType IntegrationLookup;
     266  //!> contains the name of a parameter
     267  ParamNamesType ParamNames;
     268  //!> contains a lookup from parameter name to enumeration index
     269  ParamLookupType ParamLookup;
    123270};
    124271
     272/** Output operator for the contents of MpqcParser_Parameters::params.
     273 *
     274 * @param ost output stream
     275 * @param params reference to MpqcParser_Parameters containing params.
     276 * @return reference to output stream for concatenation
     277 */
     278std::ostream & operator << (std::ostream& ost, const MpqcParser_Parameters &params);
     279
     280/** Input operator for a list of parameters to place into \a params.
     281 *
     282 * @param ist input stream
     283 * @param params parameters to parse into
     284 * @return input stream for concatenation
     285 */
     286std::istream & operator >> (std::istream& ist, MpqcParser_Parameters &params);
     287
    125288#endif /* MPQCPARSER_PARAMETERS_HPP_ */
  • src/Parser/PcpParser.cpp

    r360c8b rfa9d1d  
    4040
    4141
    42 // declare specialized static variables
    43 const std::string FormatParserTrait<pcp>::name = "pcp";
    44 const std::string FormatParserTrait<pcp>::suffix = "conf";
    45 const ParserTypes FormatParserTrait<pcp>::type = pcp;
    46 
    47 FormatParser< pcp >::StructParallelization::StructParallelization() :
     42PcpParser::StructParallelization::StructParallelization() :
    4843  ProcPEGamma(8),
    4944  ProcPEPsi(1)
    5045{}
    5146
    52 FormatParser< pcp >::StructParallelization::~StructParallelization()
    53 {}
    54 
    55 FormatParser< pcp >::StructPaths::StructPaths() :
     47PcpParser::StructParallelization::~StructParallelization()
     48{}
     49
     50PcpParser::StructPaths::StructPaths() :
    5651  databasepath(NULL),
    5752  configname(NULL),
     
    6156{}
    6257
    63 FormatParser< pcp >::StructPaths::~StructPaths()
    64 {}
    65 
    66 FormatParser< pcp >::StructSwitches::StructSwitches() :
     58PcpParser::StructPaths::~StructPaths()
     59{}
     60
     61PcpParser::StructSwitches::StructSwitches() :
    6762  DoConstrainedMD(0),
    6863  DoOutVis(0),
     
    7671{}
    7772
    78 FormatParser< pcp >::StructSwitches::~StructSwitches()
    79 {}
    80 
    81 FormatParser< pcp >::StructLocalizedOrbitals::StructLocalizedOrbitals() :
     73PcpParser::StructSwitches::~StructSwitches()
     74{}
     75
     76PcpParser::StructLocalizedOrbitals::StructLocalizedOrbitals() :
    8277  CommonWannier(0),
    8378  SawtoothStart(0.01),
     
    8984{}
    9085
    91 FormatParser< pcp >::StructLocalizedOrbitals::~StructLocalizedOrbitals()
    92 {}
    93 
    94 FormatParser< pcp >::StructStepCounts::StructStepCounts() :
     86PcpParser::StructLocalizedOrbitals::~StructLocalizedOrbitals()
     87{}
     88
     89PcpParser::StructStepCounts::StructStepCounts() :
    9590  MaxMinStopStep(1),
    9691  InitMaxMinStopStep(1),
     
    109104{}
    110105
    111 FormatParser< pcp >::StructStepCounts::~StructStepCounts()
    112 {}
    113 
    114 FormatParser< pcp >::StructPlaneWaveSpecifics::StructPlaneWaveSpecifics() :
     106PcpParser::StructStepCounts::~StructStepCounts()
     107{}
     108
     109PcpParser::StructPlaneWaveSpecifics::StructPlaneWaveSpecifics() :
    115110  PsiType(0),
    116111  MaxPsiDouble(0),
     
    128123{}
    129124
    130 FormatParser< pcp >::StructPlaneWaveSpecifics::~StructPlaneWaveSpecifics()
     125PcpParser::StructPlaneWaveSpecifics::~StructPlaneWaveSpecifics()
    131126{}
    132127
     
    134129 *
    135130 */
    136 FormatParser< pcp >::FormatParser() :
    137   FormatParser_common(NULL),
     131PcpParser::PcpParser() :
    138132  FastParsing(false),
    139133  Deltat(0.01),
     
    147141 *
    148142 */
    149 FormatParser< pcp >::~FormatParser()
    150 {}
    151 
    152 void FormatParser< pcp >::load(std::istream* file)
     143PcpParser::~PcpParser()
     144{}
     145
     146void PcpParser::load(std::istream* file)
    153147{
    154148  if (file->fail()) {
     
    386380 * \param atoms atoms to store
    387381 */
    388 void FormatParser< pcp >::save(std::ostream* file, const std::vector<atom *> &atoms)
     382void PcpParser::save(std::ostream* file, const std::vector<atom *> &atoms)
    389383{
    390384  DoLog(0) && (Log() << Verbose(0) << "Saving changes to pcp." << std::endl);
     
    420414    *file << "DoFullCurrent\t" << Switches.DoFullCurrent << "\t# Do full perturbation" << endl;
    421415    *file << "DoConstrainedMD\t" << Switches.DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
    422     ASSERT(Thermostats != NULL, "FormatParser< pcp >::save() - Thermostats not initialized!");
     416    ASSERT(Thermostats != NULL, "PcpParser::save() - Thermostats not initialized!");
    423417    *file << "Thermostat\t" << Thermostats->activeThermostat->name() << "\t";
    424418    *file << Thermostats->activeThermostat->writeParams();
     
    493487 * \param &allatoms all atoms to store away
    494488 */
    495 void FormatParser< pcp >::CalculateOrbitals(const std::vector<atom *> &allatoms)
     489void PcpParser::CalculateOrbitals(const std::vector<atom *> &allatoms)
    496490{
    497491  PlaneWaveSpecifics.MaxPsiDouble = PlaneWaveSpecifics.PsiMaxNoDown = PlaneWaveSpecifics.PsiMaxNoUp = PlaneWaveSpecifics.PsiType = 0;
     
    526520 * \param &ZtoIndexMap map of which atoms belong to which ion number
    527521 */
    528 void FormatParser< pcp >::OutputElements(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
     522void PcpParser::OutputElements(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
    529523{
    530524  map<int, int> PresentElements;
     
    556550 * \param &ZtoIndexMap map of which atoms belong to which ion number
    557551 */
    558 void FormatParser< pcp >::OutputAtoms(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
     552void PcpParser::OutputAtoms(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
    559553{
    560554  *file << "#Ion_TypeNr._Nr.R[0]    R[1]    R[2]    MoveType (0 MoveIon, 1 FixedIon)" << endl;
     
    604598 * \param *fb file buffer containing the config file
    605599 */
    606 void FormatParser< pcp >::ParseThermostats(class ConfigFileBuffer * const fb)
     600void PcpParser::ParseThermostats(class ConfigFileBuffer * const fb)
    607601{
    608602  char * const thermo = new char[12];
     
    621615};
    622616
    623 bool FormatParser< pcp >::operator==(const FormatParser< pcp >& b) const
     617bool PcpParser::operator==(const PcpParser& b) const
    624618{
    625619  ASSERT(Parallelization.ProcPEGamma == b.Parallelization.ProcPEGamma, "PcpParser ==: ProcPEGamma not");
  • src/Parser/PcpParser.hpp

    r360c8b rfa9d1d  
    1414#endif
    1515
     16
    1617#include <iosfwd>
    17 #include <map>
    18 #include <string>
    19 #include <vector>
    20 
    21 #include "FormatParser.hpp"
    22 #include "FormatParserTrait.hpp"
    23 #include "FormatParserInterface.hpp"
    24 #include "FormatParser_common.hpp"
    25 #include "ParserTypes.hpp"
    26 
    27 class atom;
    28 
    29 // declaration of specialized FormatParserTrait
    30 template<>
    31 struct FormatParserTrait<pcp>
    32 {
    33   //!> Name of the parser
    34   static const std::string name;
    35   //!> suffix of the files the parser understands to read and write
    36   static const std::string suffix;
    37   //!> ParserTypes enumeration for the parser
    38   static const enum ParserTypes type;
    39 };
     18#include "Parser/FormatParser.hpp"
    4019
    4120/**
    4221 * Parser for PCP config files.
    4322 */
    44 template <>
    45 class FormatParser< pcp >  : virtual public FormatParserInterface, public FormatParser_common
    46 {
     23class PcpParser : public FormatParser {
    4724public:
    48   FormatParser();
    49   virtual ~FormatParser();
     25  PcpParser();
     26  virtual ~PcpParser();
    5027  void load(std::istream* file);
    5128  void save(std::ostream* file, const std::vector<atom *> &atoms);
    5229
    53   bool operator==(const FormatParser< pcp >& b) const;
     30  bool operator==(const PcpParser& b) const;
    5431
    5532private:
    5633
    5734  void ParseThermostats(class ConfigFileBuffer * const fb);
    58   void OutputAtoms(std::ostream *file, const std::vector<atom *> &allatoms, std::map<int, int> &ZtoIndexMap);
    59   void OutputElements(std::ostream *file, const std::vector<atom *> &allatoms, std::map<int, int> &ZtoIndexMap);
     35  void OutputAtoms(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap);
     36  void OutputElements(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap);
    6037  void CalculateOrbitals(const std::vector<atom *> &allatoms);
    6138
     
    177154  int StructOpt;
    178155  int MaxTypes;
    179   std::string basis;
     156  string basis;
    180157};
    181158
  • src/Parser/PdbAtomInfoContainer.hpp

    r360c8b rfa9d1d  
    1414#endif
    1515
     16
     17#include "PdbKey.hpp"
     18
     19class PdbParser;
     20class Vector;
     21
    1622#include <string>
    1723#include <typeinfo>
    18 
    19 #include "LinearAlgebra/Vector.hpp"
    20 #include "PdbKey.hpp"
    21 
    22 #include "ParserTypes.hpp"
    23 
    24 //template <class T> class FormatParser;
    25 //template<> class FormatParser< pdb >;
    2624
    2725/**
     
    2927 */
    3028class PdbAtomInfoContainer {
    31   //!> Grant all FormatParser specializations access, otherwise we have to fully define FormatParser<pdb>
    32   template<enum ParserTypes> friend class FormatParser;
     29  friend class PdbParser;
    3330public:
    3431  PdbAtomInfoContainer();
  • src/Parser/PdbParser.cpp

    r360c8b rfa9d1d  
    4444using namespace std;
    4545
    46 // declare specialized static variables
    47 const std::string FormatParserTrait<pdb>::name = "pdb";
    48 const std::string FormatParserTrait<pdb>::suffix = "pdb";
    49 const ParserTypes FormatParserTrait<pdb>::type = pdb;
    50 
    5146/**
    5247 * Constructor.
    5348 */
    54 FormatParser< pdb >::FormatParser() :
    55   FormatParser_common(NULL)
    56 {
     49PdbParser::PdbParser() {
    5750  knownTokens["ATOM"] = PdbKey::Atom;
    5851  knownTokens["HETATM"] = PdbKey::Atom;
     
    7265 * Destructor.
    7366 */
    74 FormatParser< pdb >::~FormatParser()
    75 {
     67PdbParser::~PdbParser() {
    7668  PdbAtomInfoContainer::clearknownDataKeys();
    7769  additionalAtomData.clear();
     
    8577 * @return token type
    8678 */
    87 enum PdbKey::KnownTokens FormatParser< pdb >::getToken(string &line)
     79enum PdbKey::KnownTokens PdbParser::getToken(string &line)
    8880{
    8981  // look for first space
     
    113105 * \param PDB file
    114106 */
    115 void FormatParser< pdb >::load(istream* file) {
     107void PdbParser::load(istream* file) {
    116108  string line;
    117109  size_t linecount  = 0;
     
    156148            // TODO: put a throw here
    157149            DoeLog(2) && (eLog() << Verbose(2) << "Unknown token: '" << line << "' for time step " << step << "." << std::endl);
    158             //ASSERT(0, "FormatParser< pdb >::load() - Unknown token in line "+toString(linecount)+": "+line+".");
     150            //ASSERT(0, "PdbParser::load() - Unknown token in line "+toString(linecount)+": "+line+".");
    159151            break;
    160152        }
     
    178170 * \param atoms atoms to store
    179171 */
    180 void FormatParser< pdb >::save(ostream* file, const std::vector<atom *> &AtomList)
     172void PdbParser::save(ostream* file, const std::vector<atom *> &AtomList)
    181173{
    182174  DoLog(0) && (Log() << Verbose(0) << "Saving changes to pdb." << std::endl);
     
    248240        } else {
    249241          ASSERT(MolIdMap.find(mol->getId()) != MolIdMap.end(),
    250               "FormatParser< pdb >::save() - Mol id "+toString(mol->getId())+" not present despite we set it?!");
     242              "PdbParser::save() - Mol id "+toString(mol->getId())+" not present despite we set it?!");
    251243          MolNo = MolIdMap[mol->getId()];
    252244          atomInfo.set(PdbKey::resSeq, toString(MolIdMap[mol->getId()]));
     
    297289 * @param id of atom
    298290 */
    299 void FormatParser< pdb >::AtomInserted(atomId_t id)
    300 {
    301   //LOG(3, "FormatParser< pdb >::AtomInserted() - notified of atom " << id << "'s insertion.");
     291void PdbParser::AtomInserted(atomId_t id)
     292{
     293  //LOG(3, "PdbParser::AtomInserted() - notified of atom " << id << "'s insertion.");
    302294  ASSERT(!isPresentadditionalAtomData(id),
    303       "FormatParser< pdb >::AtomInserted() - additionalAtomData already present for newly added atom "
     295      "PdbParser::AtomInserted() - additionalAtomData already present for newly added atom "
    304296      +toString(id)+".");
    305297  // don't insert here as this is our check whether we are in the first time step
     
    312304 * @param id of atom
    313305 */
    314 void FormatParser< pdb >::AtomRemoved(atomId_t id)
    315 {
    316   //LOG(3, "FormatParser< pdb >::AtomRemoved() - notified of atom " << id << "'s removal.");
     306void PdbParser::AtomRemoved(atomId_t id)
     307{
     308  //LOG(3, "PdbParser::AtomRemoved() - notified of atom " << id << "'s removal.");
    317309  std::map<size_t, PdbAtomInfoContainer>::iterator iter = additionalAtomData.find(id);
    318310  // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence
    319311//  ASSERT(iter != additionalAtomData.end(),
    320 //      "FormatParser< pdb >::AtomRemoved() - additionalAtomData is not present for atom "
     312//      "PdbParser::AtomRemoved() - additionalAtomData is not present for atom "
    321313//      +toString(id)+" to remove.");
    322314  if (iter != additionalAtomData.end()) {
     
    333325 * @return true - entry present, false - only for atom's father or no entry
    334326 */
    335 bool FormatParser< pdb >::isPresentadditionalAtomData(unsigned int _id)
     327bool PdbParser::isPresentadditionalAtomData(unsigned int _id)
    336328{
    337329  return (additionalAtomData.find(_id) != additionalAtomData.end());
     
    344336 * @return
    345337 */
    346 PdbAtomInfoContainer& FormatParser< pdb >::getadditionalAtomData(atom *_atom)
     338PdbAtomInfoContainer& PdbParser::getadditionalAtomData(atom *_atom)
    347339{
    348340  if (additionalAtomData.find(_atom->getId()) != additionalAtomData.end()) {
     
    370362 * \param ResidueNo number of residue
    371363 */
    372 void FormatParser< pdb >::saveLine(
     364void PdbParser::saveLine(
    373365    ostream* file,
    374366    const PdbAtomInfoContainer &atomInfo)
     
    431423 * \param *currentAtom to the atom of which to take the neighbor information
    432424 */
    433 void FormatParser< pdb >::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {
     425void PdbParser::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {
    434426  int MaxNo = MaxnumberOfNeighbors;
    435427  int charsleft = 80;
     
    460452}
    461453
    462 /** Retrieves a value from  FormatParser< pdb >::atomIdMap.
     454/** Retrieves a value from PdbParser::atomIdMap.
    463455 * \param atomid key
    464456 * \return value
    465457 */
    466 size_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.");
     458size_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.");
    470462  return (atomIdMap.find(atomid)->second);
    471463}
    472464
    473 /** Sets an entry in  FormatParser< pdb >::atomIdMap.
     465/** Sets an entry in PdbParser::atomIdMap.
    474466 * \param localatomid key
    475467 * \param atomid value
    476468 * \return true - key not present, false - value present
    477469 */
    478 void FormatParser< pdb >::setSerial(const size_t localatomid, const size_t atomid)
     470void PdbParser::setSerial(const size_t localatomid, const size_t atomid)
    479471{
    480472  pair<std::map<size_t,size_t>::iterator, bool > inserter;
    481 //  DoLog(1) && (Log() << Verbose(1) << "FormatParser< pdb >::setAtomId() - Inserting ("
     473//  DoLog(1) && (Log() << Verbose(1) << "PdbParser::setAtomId() - Inserting ("
    482474//      << localatomid << " -> " << atomid << ")." << std::endl);
    483475  inserter = atomIdMap.insert( make_pair(localatomid, atomid) );
    484   ASSERT(inserter.second, "FormatParser< pdb >::setAtomId: atomId already present in Map.");
     476  ASSERT(inserter.second, "PdbParser::setAtomId: atomId already present in Map.");
    485477}
    486478
     
    490482 * @return
    491483 */
    492 atom* FormatParser< pdb >::getAtomToParse(std::string id_string) const
     484atom* PdbParser::getAtomToParse(std::string id_string) const
    493485{
    494486  // get the local ID
     
    525517 * @param line line containing key ATOM
    526518 */
    527 void FormatParser< pdb >::readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const
     519void PdbParser::readPdbAtomInfoContainer(PdbAtomInfoContainer &atomInfo, std::string &line) const
    528520{
    529521  const size_t length = line.length();
    530522  if (length < 80)
    531     ELOG(2, "FormatParser< pdb >::readPdbAtomInfoContainer() - pdb is mal-formed, containing less than 80 chars!");
     523    ELOG(2, "PdbParser::readPdbAtomInfoContainer() - pdb is mal-formed, containing less than 80 chars!");
    532524  if (length >= 6) {
    533525    LOG(4,"INFO: Parsing token from "+line.substr(0,6)+".");
     
    538530    atomInfo.set(PdbKey::serial, line.substr(6,5));
    539531    ASSERT(atomInfo.get<int>(PdbKey::serial) != 0,
    540         "FormatParser< pdb >::readPdbAtomInfoContainer() - serial 0 is invalid (filler id for conect entries).");
     532        "PdbParser::readPdbAtomInfoContainer() - serial 0 is invalid (filler id for conect entries).");
    541533  }
    542534
     
    599591 * \param newmol molecule to add parsed atoms to
    600592 */
    601 void FormatParser< pdb >::readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol = NULL) {
     593void PdbParser::readAtomDataLine(const unsigned int _step, std::string &line, molecule *newmol = NULL) {
    602594  vector<string>::iterator it;
    603595
     
    606598  bool FirstTimestep = isPresentadditionalAtomData(newAtom->getId()) ? false : true;
    607599  ASSERT((FirstTimestep && (_step == 0)) || (!FirstTimestep && (_step !=0)),
    608       "FormatParser< pdb >::readAtomDataLine() - additionalAtomData present though atom is newly parsed.");
     600      "PdbParser::readAtomDataLine() - additionalAtomData present though atom is newly parsed.");
    609601  if (FirstTimestep) {
    610602    LOG(3,"INFO: Parsing new atom.");
     
    654646      SerialSet.insert(toSize_t(atomInfo.get<std::string>(PdbKey::serial)));
    655647    ASSERT(Inserter.second,
    656         "FormatParser< pdb >::readAtomDataLine() - ATOM contains entry with serial "
     648        "PdbParser::readAtomDataLine() - ATOM contains entry with serial "
    657649        +atomInfo.get<std::string>(PdbKey::serial)+" already present!");
    658650    setSerial(toSize_t(atomInfo.get<std::string>(PdbKey::serial)), newAtom->getId());
     
    675667        ->FindElement(value);
    676668    ASSERT(elem != NULL,
    677         "FormatParser< pdb >::readAtomDataLine() - element "+atomInfo.get<std::string>(PdbKey::element)+" is unknown!");
     669        "PdbParser::readAtomDataLine() - element "+atomInfo.get<std::string>(PdbKey::element)+" is unknown!");
    678670    newAtom->setType(elem);
    679671
     
    687679    // then check additional info for consistency
    688680    ASSERT(atomInfo.get<std::string>(PdbKey::token) == consistencyInfo.get<std::string>(PdbKey::token),
    689         "FormatParser< pdb >::readAtomDataLine() - difference in token on multiple time step for atom with id "
     681        "PdbParser::readAtomDataLine() - difference in token on multiple time step for atom with id "
    690682        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    691683    ASSERT(atomInfo.get<std::string>(PdbKey::name) == consistencyInfo.get<std::string>(PdbKey::name),
    692         "FormatParser< pdb >::readAtomDataLine() - difference in name on multiple time step for atom with id "
     684        "PdbParser::readAtomDataLine() - difference in name on multiple time step for atom with id "
    693685        +atomInfo.get<std::string>(PdbKey::serial)+":"
    694686        +atomInfo.get<std::string>(PdbKey::name)+"!="
    695687        +consistencyInfo.get<std::string>(PdbKey::name)+".");
    696688    ASSERT(atomInfo.get<std::string>(PdbKey::altLoc) == consistencyInfo.get<std::string>(PdbKey::altLoc),
    697         "FormatParser< pdb >::readAtomDataLine() - difference in altLoc on multiple time step for atom with id "
     689        "PdbParser::readAtomDataLine() - difference in altLoc on multiple time step for atom with id "
    698690        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    699691    ASSERT(atomInfo.get<std::string>(PdbKey::resName) == consistencyInfo.get<std::string>(PdbKey::resName),
    700         "FormatParser< pdb >::readAtomDataLine() - difference in resName on multiple time step for atom with id "
     692        "PdbParser::readAtomDataLine() - difference in resName on multiple time step for atom with id "
    701693        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    702694    ASSERT(atomInfo.get<std::string>(PdbKey::chainID) == consistencyInfo.get<std::string>(PdbKey::chainID),
    703         "FormatParser< pdb >::readAtomDataLine() - difference in chainID on multiple time step for atom with id "
     695        "PdbParser::readAtomDataLine() - difference in chainID on multiple time step for atom with id "
    704696        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    705697    ASSERT(atomInfo.get<std::string>(PdbKey::resSeq) == consistencyInfo.get<std::string>(PdbKey::resSeq),
    706         "FormatParser< pdb >::readAtomDataLine() - difference in resSeq on multiple time step for atom with id "
     698        "PdbParser::readAtomDataLine() - difference in resSeq on multiple time step for atom with id "
    707699        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    708700    ASSERT(atomInfo.get<std::string>(PdbKey::iCode) == consistencyInfo.get<std::string>(PdbKey::iCode),
    709         "FormatParser< pdb >::readAtomDataLine() - difference in iCode on multiple time step for atom with id "
     701        "PdbParser::readAtomDataLine() - difference in iCode on multiple time step for atom with id "
    710702        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    711703    ASSERT(atomInfo.get<std::string>(PdbKey::occupancy) == consistencyInfo.get<std::string>(PdbKey::occupancy),
    712         "FormatParser< pdb >::readAtomDataLine() - difference in occupancy on multiple time step for atom with id "
     704        "PdbParser::readAtomDataLine() - difference in occupancy on multiple time step for atom with id "
    713705        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    714706    ASSERT(atomInfo.get<std::string>(PdbKey::tempFactor) == consistencyInfo.get<std::string>(PdbKey::tempFactor),
    715         "FormatParser< pdb >::readAtomDataLine() - difference in tempFactor on multiple time step for atom with id "
     707        "PdbParser::readAtomDataLine() - difference in tempFactor on multiple time step for atom with id "
    716708        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    717709    ASSERT(atomInfo.get<std::string>(PdbKey::charge) == consistencyInfo.get<std::string>(PdbKey::charge),
    718         "FormatParser< pdb >::readAtomDataLine() - difference in charge on multiple time step for atom with id "
     710        "PdbParser::readAtomDataLine() - difference in charge on multiple time step for atom with id "
    719711        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    720712    ASSERT(atomInfo.get<std::string>(PdbKey::element) == consistencyInfo.get<std::string>(PdbKey::element),
    721         "FormatParser< pdb >::readAtomDataLine() - difference in element on multiple time step for atom with id "
     713        "PdbParser::readAtomDataLine() - difference in element on multiple time step for atom with id "
    722714        +atomInfo.get<std::string>(PdbKey::serial)+"!");
    723715    // and parse in trajectory
     
    742734 *
    743735 */
    744 void FormatParser< pdb >::printAtomInfo(const atom * const newAtom) const
     736void PdbParser::printAtomInfo(const atom * const newAtom) const
    745737{
    746738  const PdbAtomInfoContainer &atomInfo = additionalAtomData.at(newAtom->getId()); // operator[] const does not exist
     
    770762 * \param line to parse as an atom
    771763 */
    772 void FormatParser< pdb >::readNeighbors(const unsigned int _step, std::string &line)
     764void PdbParser::readNeighbors(const unsigned int _step, std::string &line)
    773765{
    774766  const size_t length = line.length();
     
    780772  string output;
    781773  ASSERT(length >=16,
    782       "FormatParser< pdb >::readNeighbors() - CONECT entry has not enough entries: "+line+"!");
    783 //  output = "Split line:|";
    784 //  output += line.substr(6,5) + "|";
     774      "PdbParser::readNeighbors() - CONECT entry has not enough entries: "+line+"!");
     775  output = "Split line:|";
     776  output += line.substr(6,5) + "|";
    785777  const size_t id = toSize_t(line.substr(6,5));
    786778  for (size_t index = 11; index <= 26; index+=5) {
     
    793785        ListOfNeighbors.push_back(otherid);
    794786      else
    795         ELOG(2, "FormatParser< pdb >::readNeighbors() - discarding conect entry with id 0.");
     787        ELOG(2, "PdbParser::readNeighbors() - discarding conect entry with id 0.");
    796788    } else  {
    797789      break;
     
    821813 * \return input string with modified atom IDs
    822814 */
    823 //string  FormatParser< pdb >::adaptIdDependentDataString(string data) {
     815//string PdbParser::adaptIdDependentDataString(string data) {
    824816//  // there might be no IDs
    825817//  if (data == "-") {
     
    844836
    845837
    846 bool FormatParser< pdb >::operator==(const FormatParser< pdb >& b) const
     838bool PdbParser::operator==(const PdbParser& b) const
    847839{
    848840  bool status = true;
  • src/Parser/PdbParser.hpp

    r360c8b rfa9d1d  
    1414#endif
    1515
     16
    1617#include <string>
    17 
    1818#include "FormatParser.hpp"
    19 #include "FormatParserTrait.hpp"
    20 #include "FormatParserInterface.hpp"
    21 #include "FormatParser_common.hpp"
    22 #include "ParserTypes.hpp"
    23 
    2419#include "PdbAtomInfoContainer.hpp"
    2520#include "PdbKey.hpp"
    26 
    27 class molecule;
    28 
    29 // declaration of specialized FormatParserTrait
    30 template<>
    31 struct FormatParserTrait<pdb>
    32 {
    33   //!> Name of the parser
    34   static const std::string name;
    35   //!> suffix of the files the parser understands to read and write
    36   static const std::string suffix;
    37   //!> ParserTypes enumeration for the parser
    38   static const enum ParserTypes type;
    39 };
    4021
    4122/**
    4223 * Loads a PDB format 3.2 file into the World and saves the World as a PDB file.
    4324 */
    44 template <>
    45 class FormatParser< pdb >  : virtual public FormatParserInterface, public FormatParser_common
     25class PdbParser : public FormatParser
    4626{
    4727public:
    48   FormatParser();
    49   virtual ~FormatParser();
     28  PdbParser();
     29  virtual ~PdbParser();
    5030  void load(std::istream* file);
    5131  void save(std::ostream* file, const std::vector<atom *> &atoms);
    5232
    53   bool operator==(const FormatParser< pdb>& b) const;
     33  bool operator==(const PdbParser& b) const;
    5434  void printAtomInfo(const atom *newAtom) const;
    5535
     
    11191   */
    11292  std::set<size_t> SerialSet;
     93
    11394};
    11495
  • src/Parser/TremoloParser.cpp

    r360c8b rfa9d1d  
    4242using namespace std;
    4343
    44 // declare specialized static variables
    45 const std::string FormatParserTrait<tremolo>::name = "tremolo";
    46 const std::string FormatParserTrait<tremolo>::suffix = "data";
    47 const ParserTypes FormatParserTrait<tremolo>::type = tremolo;
    48 
    4944/**
    5045 * Constructor.
    5146 */
    52 FormatParser< tremolo >::FormatParser()  :
    53   FormatParser_common(NULL)
    54 {
     47TremoloParser::TremoloParser() {
    5548  knownKeys["x"] = TremoloKey::x;
    5649  knownKeys["u"] = TremoloKey::u;
     
    9487 * Destructor.
    9588 */
    96 FormatParser< tremolo >::~FormatParser()
    97 {
    98   std::cerr << "Clearing usedFields." << std::endl;
     89TremoloParser::~TremoloParser() {
     90        std::cerr << "Clearing usedFields." << std::endl;
    9991  usedFields.clear();
    10092  additionalAtomData.clear();
     
    108100 * \param tremolo file
    109101 */
    110 void FormatParser< tremolo >::load(istream* file) {
     102void TremoloParser::load(istream* file) {
    111103  string line;
    112104  string::size_type location;
     
    149141 * \param atoms atoms to store
    150142 */
    151 void FormatParser< tremolo >::save(ostream* file, const std::vector<atom *> &AtomList) {
     143void TremoloParser::save(ostream* file, const std::vector<atom *> &AtomList) {
    152144  DoLog(0) && (Log() << Verbose(0) << "Saving changes to tremolo." << std::endl);
    153145
     
    177169 * @param id of atom
    178170 */
    179 void FormatParser< tremolo >::AtomInserted(atomId_t id)
     171void TremoloParser::AtomInserted(atomId_t id)
    180172{
    181173  std::map<int, TremoloAtomInfoContainer>::iterator iter = additionalAtomData.find(id);
    182174  ASSERT(iter == additionalAtomData.end(),
    183       "FormatParser< tremolo >::AtomInserted() - additionalAtomData already present for newly added atom "
     175      "TremoloParser::AtomInserted() - additionalAtomData already present for newly added atom "
    184176      +toString(id)+".");
    185177  // don't add entry, as this gives a default resSeq of 0 not the molecule id
     
    191183 * @param id of atom
    192184 */
    193 void FormatParser< tremolo >::AtomRemoved(atomId_t id)
     185void TremoloParser::AtomRemoved(atomId_t id)
    194186{
    195187  std::map<int, TremoloAtomInfoContainer>::iterator iter = additionalAtomData.find(id);
    196188  // as we do not insert AtomData on AtomInserted, we cannot be assured of its presence
    197189//  ASSERT(iter != additionalAtomData.end(),
    198 //      "FormatParser< tremolo >::AtomRemoved() - additionalAtomData is not present for atom "
     190//      "TremoloParser::AtomRemoved() - additionalAtomData is not present for atom "
    199191//      +toString(id)+" to remove.");
    200192  if (iter != additionalAtomData.end())
     
    209201 *        but without the prexix "ATOMDATA"
    210202 */
    211 void FormatParser< tremolo >::setFieldsForSave(std::string atomDataLine) {
     203void TremoloParser::setFieldsForSave(std::string atomDataLine) {
    212204  parseAtomDataKeysLine(atomDataLine, 0);
    213205}
     
    220212 * \param reference to the atom of which information should be written
    221213 */
    222 void FormatParser< tremolo >::saveLine(ostream* file, atom* currentAtom) {
    223   //vector<string>::iterator it;
    224   // TODO: Is unique for FormatParser< tremolo >::usedFields still required?
    225   vector<string>::iterator it = unique(usedFields.begin(), usedFields.end()); // skips all duplicates in the vector
     214void TremoloParser::saveLine(ostream* file, atom* currentAtom) {
     215 /* vector<string>::iterator it;*/
     216        vector<string>::iterator it = unique(usedFields.begin(), usedFields.end()); // skips all duplicates in the vector
    226217
    227218  TremoloKey::atomDataKey currentField;
     
    317308 * \param reference to the atom of which to take the neighbor information
    318309 */
    319 void FormatParser< tremolo >::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) {
     310void TremoloParser::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) {
    320311  const BondList& ListOfBonds = currentAtom->getListOfBonds();
    321312  // sort bonded indices
     
    340331 * \param with which offset the keys begin within the line
    341332 */
    342 void FormatParser< tremolo >::parseAtomDataKeysLine(string line, int offset) {
     333void TremoloParser::parseAtomDataKeysLine(string line, int offset) {
    343334  string keyword;
    344335  stringstream lineStream;
     
    362353 *  \a atomdata_string.
    363354 *
    364  *  We just call \sa  FormatParser< tremolo >::parseAtomDataKeysLine() which is left
     355 *  We just call \sa TremoloParser::parseAtomDataKeysLine() which is left
    365356 *  private.,
    366357 *
    367358 * @param atomdata_string line to parse with space-separated values
    368359 */
    369 void FormatParser< tremolo >::setAtomData(const std::string &atomdata_string)
     360void TremoloParser::setAtomData(const std::string &atomdata_string)
    370361{
    371362  parseAtomDataKeysLine(atomdata_string, 0);
     
    380371 * \param *newmol molecule to add atom to
    381372 */
    382 void FormatParser< tremolo >::readAtomDataLine(string line, molecule *newmol = NULL) {
     373void TremoloParser::readAtomDataLine(string line, molecule *newmol = NULL) {
    383374  vector<string>::iterator it;
    384375  stringstream lineStream;
     
    398389  tokenizer tokens(line, whitespacesep);
    399390  ASSERT(tokens.begin() != tokens.end(),
    400       "FormatParser< tremolo >::readAtomDataLine - empty string, need at least ' '!");
     391      "TremoloParser::readAtomDataLine - empty string, need at least ' '!");
    401392  tokenizer::iterator tok_iter = tokens.begin();
    402393  // then associate each token to each file
     
    410401        // for the moment, assume there are always three dimensions
    411402        for (int i=0;i<NDIM;i++) {
    412           ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for x["+toString(i)+"]!");
     403          ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for x["+toString(i)+"]!");
    413404          DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    414405          newAtom->set(i, toDouble(*tok_iter));
     
    419410        // for the moment, assume there are always three dimensions
    420411        for (int i=0;i<NDIM;i++) {
    421           ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for u["+toString(i)+"]!");
     412          ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for u["+toString(i)+"]!");
    422413          DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    423414          tempVector[i] = toDouble(*tok_iter);
     
    428419      case TremoloKey::type :
    429420      {
    430         ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
     421        ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
    431422        DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    432423        std::string element(knownTypes[(*tok_iter)]);
     
    440431      }
    441432      case TremoloKey::Id :
    442         ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
     433        ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
    443434        DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    444435        atomIdMap[toInt(*tok_iter)] = newAtom->getId();
     
    447438      case TremoloKey::neighbors :
    448439        for (int i=0;i<atoi(it->substr(it->find("=") + 1, 1).c_str());i++) {
    449           ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
     440          ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
    450441          DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    451442          lineStream << *tok_iter << "\t";
     
    456447        break;
    457448      default :
    458         ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!");
     449        ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!");
    459450        DoLog(4) && (Log() << Verbose(4) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl);
    460451        atomInfo->set(currentField, *tok_iter);
     
    476467 * \param atomid world id of the atom the information belongs to
    477468 */
    478 void FormatParser< tremolo >::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) {
     469void TremoloParser::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) {
    479470  int neighborId = 0;
    480471  for (int i = 0; i < numberOfNeighbors; i++) {
     
    498489 * \return true if the field name is used
    499490 */
    500 bool FormatParser< tremolo >::isUsedField(string fieldName) {
     491bool TremoloParser::isUsedField(string fieldName) {
    501492  bool fieldNameExists = false;
    502493  for (vector<string>::iterator usedField = usedFields.begin(); usedField != usedFields.end(); usedField++) {
     
    514505 * Id found in the parsed file.
    515506 */
    516 void FormatParser< tremolo >::processNeighborInformation() {
     507void TremoloParser::processNeighborInformation() {
    517508  if (!isUsedField("neighbors")) {
    518509    return;
     
    547538 * \return input string with modified atom IDs
    548539 */
    549 std::string FormatParser< tremolo >::adaptIdDependentDataString(string data) {
     540string TremoloParser::adaptIdDependentDataString(string data) {
    550541  // there might be no IDs
    551542  if (data == "-") {
     
    572563 * as they might differ from the originally read IDs.
    573564 */
    574 void FormatParser< tremolo >::adaptImprData() {
     565void TremoloParser::adaptImprData() {
    575566  if (!isUsedField("imprData")) {
    576567    return;
     
    588579 * as they might differ from the originally read IDs.
    589580 */
    590 void FormatParser< tremolo >::adaptTorsion() {
     581void TremoloParser::adaptTorsion() {
    591582  if (!isUsedField("torsion")) {
    592583    return;
     
    603594 *
    604595 */
    605 void FormatParser< tremolo >::createKnownTypesByIdentity()
     596void TremoloParser::createKnownTypesByIdentity()
    606597{
    607598  // remove old mapping
     
    620611 * @param file input stream of .potentials file
    621612 */
    622 void FormatParser< tremolo >::parseKnownTypes(std::istream &file)
     613void TremoloParser::parseKnownTypes(std::istream &file)
    623614{
    624615  const periodentafel *periode = World::getInstance().getPeriode();
     
    641632      tokenizer tokens(line, tokensep);
    642633      ASSERT(tokens.begin() != tokens.end(),
    643           "FormatParser< tremolo >::parseKnownTypes() - line with 'particle:' but no particles separated by comma.");
     634          "TremoloParser::parseKnownTypes() - line with 'particle:' but no particles separated by comma.");
    644635      // look for particle_type
    645636      std::string particle_type("NULL");
     
    652643          tokenizer token((*tok_iter), equalitysep);
    653644          ASSERT(token.begin() != token.end(),
    654                     "FormatParser< tremolo >::parseKnownTypes() - could not split particle_type by equality sign");
     645                    "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign");
    655646          tokenizer::iterator particle_iter = token.begin();
    656647          particle_iter++;
     
    661652          tokenizer token((*tok_iter), equalitysep);
    662653          ASSERT(token.begin() != token.end(),
    663                     "FormatParser< tremolo >::parseKnownTypes() - could not split particle_type by equality sign");
     654                    "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign");
    664655          tokenizer::iterator element_iter = token.begin();
    665656          element_iter++;
  • src/Parser/TremoloParser.hpp

    r360c8b rfa9d1d  
    1414#endif
    1515
     16
    1617#include <string>
    17 
    18 #include "FormatParser.hpp"
    19 #include "FormatParserTrait.hpp"
    20 #include "FormatParserInterface.hpp"
    21 #include "FormatParser_common.hpp"
    22 #include "ParserTypes.hpp"
     18#include "Parser/FormatParser.hpp"
    2319
    2420#include "TremoloKey.hpp"
     
    2723class molecule;
    2824
    29 // declaration of specialized FormatParserTrait
    30 template<>
    31 struct FormatParserTrait<tremolo>
    32 {
    33   //!> Name of the parser
    34   static const std::string name;
    35   //!> suffix of the files the parser understands to read and write
    36   static const std::string suffix;
    37   //!> ParserTypes enumeration for the parser
    38   static const enum ParserTypes type;
    39 };
    40 
    4125/**
    4226 * Loads a tremolo file into the World and saves the World as a tremolo file.
    4327 */
    44 template <>
    45 class FormatParser< tremolo >  : virtual public FormatParserInterface, public FormatParser_common
     28class TremoloParser : public FormatParser
    4629{
    4730public:
    48   FormatParser();
    49   virtual ~FormatParser();
     31  TremoloParser();
     32  virtual ~TremoloParser();
    5033  void load(std::istream* file);
    5134  void save(std::ostream* file, const std::vector<atom *> &atoms);
     
    6144
    6245private:
    63   void readAtomDataLine(std::string line);
    64   void readAtomDataLine(std::string line, molecule *newmol);
    65   void parseAtomDataKeysLine(std::string line, int offset);
     46  void readAtomDataLine(string line);
     47  void readAtomDataLine(string line, molecule *newmol);
     48  void parseAtomDataKeysLine(string line, int offset);
    6649  void readNeighbors(std::stringstream* line, int numberOfNeighbors, int atomId);
    6750  void processNeighborInformation();
  • src/Parser/XyzParser.cpp

    r360c8b rfa9d1d  
    3333using namespace std;
    3434
    35 // declare specialized static variables
    36 const std::string FormatParserTrait<xyz>::name = "xyz";
    37 const std::string FormatParserTrait<xyz>::suffix = "xyz";
    38 const ParserTypes FormatParserTrait<xyz>::type = xyz;
    39 
    4035/**
    4136 * Constructor.
    4237 */
    43 FormatParser< xyz >::FormatParser() :
    44   FormatParser_common(NULL),
     38XyzParser::XyzParser() :
    4539  comment("")
    4640{}
     
    4943 * Destructor.
    5044 */
    51 FormatParser< xyz >::~FormatParser()
    52 {}
     45XyzParser::~XyzParser() {
     46}
    5347
    5448/**
     
    5751 * \param XYZ file
    5852 */
    59 void FormatParser< xyz >::load(istream* file)
     53void XyzParser::load(istream* file)
    6054{
    6155  atom* newAtom = NULL;
     
    10599        LOG(5, "INFO: Using present atom " << *newAtom << " from " << i << " th component of AddedAtoms.");
    106100        ASSERT(newAtom->getType() == World::getInstance().getPeriode()->FindElement(type),
    107             "FormatParser< xyz >::load() - atom has different type "+newAtom->getType()->getSymbol()+" than parsed now "+type+", mixed up order?");
     101            "XyzParser::load() - atom has different type "+newAtom->getType()->getSymbol()+" than parsed now "+type+", mixed up order?");
    108102      }
    109103      newAtom->setPositionAtStep(step, tempVector);
     
    135129 * \param atoms atoms to store
    136130 */
    137 void FormatParser< xyz >::save(ostream* file, const std::vector<atom *> &atoms) {
     131void XyzParser::save(ostream* file, const std::vector<atom *> &atoms) {
    138132  DoLog(0) && (Log() << Verbose(0) << "Saving changes to xyz." << std::endl);
    139133
     
    151145  }
    152146  ASSERT((min_trajectories == max_trajectories) || (min_trajectories == 1),
    153       "FormatParser< xyz >::save() - not all atoms have same number of trajectories.");
     147      "XyzParser::save() - not all atoms have same number of trajectories.");
    154148  LOG(2, "INFO: There are " << max_trajectories << " to save.");
    155149
  • src/Parser/XyzParser.hpp

    r360c8b rfa9d1d  
    1414#endif
    1515
     16
    1617#include <string>
    17 
    18 
    19 #include "FormatParser.hpp"
    20 #include "FormatParserTrait.hpp"
    21 #include "FormatParserInterface.hpp"
    22 #include "FormatParser_common.hpp"
    23 #include "ParserTypes.hpp"
    24 
    25 // declaration of specialized FormatParserTrait
    26 template<>
    27 struct FormatParserTrait<xyz>
    28 {
    29   //!> Name of the parser
    30   static const std::string name;
    31   //!> suffix of the files the parser understands to read and write
    32   static const std::string suffix;
    33   //!> ParserTypes enumeration for the parser
    34   static const enum ParserTypes type;
    35 };
     18#include "Parser/FormatParser.hpp"
    3619
    3720/**
    3821 * Parser for XYZ files.
    3922 */
    40 template <>
    41 class FormatParser< xyz >  : virtual public FormatParserInterface, public FormatParser_common
    42 {
     23class XyzParser : public FormatParser {
    4324public:
    44   FormatParser();
    45   virtual ~FormatParser();
     25  XyzParser();
     26  virtual ~XyzParser();
    4627  void load(std::istream* file);
    4728  void save(std::ostream* file, const std::vector<atom *> &atoms);
  • src/Parser/unittests/Makefile.am

    r360c8b rfa9d1d  
    22# Also indentation by a single tab
    33
    4 include ../../src/Parser/Parameters/unittests/Makefile.am
    54
    65PARSERTESTSSOURCES = \
     
    87        ../Parser/unittests/ParserPcpUnitTest.cpp \
    98        ../Parser/unittests/ParserPdbUnitTest.cpp \
    10         ../Parser/unittests/ParserPsi3UnitTest.cpp \
    119        ../Parser/unittests/ParserTremoloUnitTest.cpp \
    1210        ../Parser/unittests/ParserXyzUnitTest.cpp
     
    1614        ../Parser/unittests/ParserPcpUnitTest.hpp \
    1715        ../Parser/unittests/ParserPdbUnitTest.hpp \
    18         ../Parser/unittests/ParserPsi3UnitTest.hpp \
    1916        ../Parser/unittests/ParserTremoloUnitTest.hpp \
    2017        ../Parser/unittests/ParserXyzUnitTest.hpp
     
    2421  ParserPcpUnitTest \
    2522  ParserPdbUnitTest \
    26   ParserPsi3UnitTest \
    2723  ParserTremoloUnitTest \
    2824  ParserXyzUnitTest
     
    3733        ${CodePatterns_LIBS}
    3834#       $(BOOST_LIB)
     35
    3936
    4037
     
    5451ParserPdbUnitTest_LDADD = ${PARSERLIBS}
    5552
    56 ParserPsi3UnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
    57         ../Parser/unittests/ParserPsi3UnitTest.cpp \
    58         ../Parser/unittests/ParserPsi3UnitTest.hpp
    59 ParserPsi3UnitTest_LDADD = ${PARSERLIBS}
    60 
    6153ParserTremoloUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
    6254        ../Parser/unittests/ParserTremoloUnitTest.cpp \
  • src/Parser/unittests/ParserMpqcUnitTest.cpp

    r360c8b rfa9d1d  
    3232#include "Descriptors/AtomTypeDescriptor.hpp"
    3333#include "CodePatterns/Assert.hpp"
    34 #include "Parser/ChangeTracker.hpp"
    35 #include "Parser/MpqcParser.hpp"
    3634
    3735#ifdef HAVE_TESTRUNNER
     
    158156)\n"; // basically tested with mpqc 3.0.0-alpha (no parse errors but did not calculate due to missing code)
    159157
    160 void ParserMpqcUnitTest::setUp()
    161 {
    162   // failing asserts should be thrown
    163   ASSERT_DO(Assert::Throw);
    164 
    165   parser = new FormatParser<mpqc>();
     158void ParserMpqcUnitTest::setUp() {
     159  mpqc = new MpqcParser();
    166160
    167161  World::getInstance();
     
    174168}
    175169
    176 void ParserMpqcUnitTest::tearDown()
    177 {
    178   delete parser;
     170void ParserMpqcUnitTest::tearDown() {
     171  delete mpqc;
    179172  ChangeTracker::purgeInstance();
    180173  World::purgeInstance();
     
    183176/************************************ tests ***********************************/
    184177
     178void ParserMpqcUnitTest::ParameterTypeTest() {
     179  // check types in boost::any map
     180  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));
     181  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int));
     182  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));
     183  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));
     184  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));
     185  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int));
     186  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));
     187  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));
     188  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));
     189  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));
     190  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));
     191  CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));
     192}
     193
    185194void ParserMpqcUnitTest::ParameterDefaultTest() {
    186195  // check default values
    187   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("no"));
    188   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::savestateParam) == std::string("no"));
    189   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::do_gradientParam) == std::string("yes"));
    190   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("1000"));
    191   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::memoryParam) == std::string("16000000"));
    192   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::stdapproxParam) == std::string("A'"));
    193   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::nfzcParam) == std::string("1"));
    194   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::basisParam) == std::string("3-21G"));
    195   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::aux_basisParam) == std::string("aug-cc-pVDZ"));
    196   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::integrationParam) == std::string("IntegralCints"));
    197   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
     196  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "no");
     197  CPPUNIT_ASSERT(!mpqc->getParams().getBool(MpqcParser_Parameters::hessianParam));
     198  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::savestateParam) == "no");
     199  CPPUNIT_ASSERT(!mpqc->getParams().getBool(MpqcParser_Parameters::savestateParam));
     200  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes");
     201  CPPUNIT_ASSERT(mpqc->getParams().getBool(MpqcParser_Parameters::do_gradientParam));
     202  CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000);
     203  CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000);
     204  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'");
     205  CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1);
     206  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G");
     207  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ");
     208  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints");
     209  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     210  CPPUNIT_ASSERT(mpqc->getParams().getTheory() == MpqcParser_Parameters::MBPT2);
     211  CPPUNIT_ASSERT(mpqc->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints);
     212
     213  // check that values are not removed
     214  CPPUNIT_ASSERT(!mpqc->getParams().params[MpqcParser_Parameters::theoryParam].empty());
     215
     216  // check throw, for the moment aren't, are caught in getInt()
     217  CPPUNIT_ASSERT_THROW(mpqc->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);
     218  CPPUNIT_ASSERT_THROW(mpqc->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);
     219
    198220}
    199221
    200222void ParserMpqcUnitTest::ParameterCloneTest() {
    201   FormatParser_Parameters *clone = parser->getParams().clone();
    202   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
     223  FormatParser_Parameters *clone = mpqc->getParams().clone();
     224  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    203225  std::stringstream setvalue("theory = CLHF");
    204   setvalue >> parser->getParams();
    205   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
    206   parser->getParams().makeClone(*clone);
    207   CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
     226  setvalue >> mpqc->getParams();
     227  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
     228  mpqc->getParams().makeClone(*clone);
     229  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    208230}
    209231
     
    212234  {
    213235    std::stringstream setvalue("theory = CLHF");
    214     setvalue >> parser->getParams();
     236    setvalue >> mpqc->getParams();
    215237//    std::cout << "integration method is "
    216 //        << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
    217     CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
     238//        << mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
     239    CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
    218240  }
    219241  // test a bool
    220242  {
    221243    std::stringstream setvalue("Hessian = yes");
    222     setvalue >> parser->getParams();
     244    setvalue >> mpqc->getParams();
    223245//    std::cout << "Hessian is "
    224 //        << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
    225     CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
     246//        << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
     247    CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
    226248  }
    227249  // test int
    228250  {
    229251    std::stringstream setvalue("maxiter = 500");
    230     setvalue >> parser->getParams();
     252    setvalue >> mpqc->getParams();
    231253//    std::cout << "maxiter is "
    232 //        << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
    233     CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("500"));
     254//        << mpqc->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
     255    CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);
    234256  }
    235257  // test whether unknown key fails
     
    239261#ifndef NDEBUG
    240262    ASSERT_DO(Assert::Throw);
    241     CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
     263    CPPUNIT_ASSERT_THROW(setvalue >> mpqc->getParams(), Assert::AssertionFailure);
    242264#else
    243     setvalue >> parser->getParams();
     265    setvalue >> mpqc->getParams();
    244266#endif
    245267//    std::cout << "Hessian is still "
    246 //        << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
    247     CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
     268//        << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
     269    CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
    248270  }
    249271}
     
    251273void ParserMpqcUnitTest::readMpqcTest() {
    252274  stringstream input(waterMpqc_CLHF);
    253   parser->getParams().setParameter(
    254       MpqcParser_Parameters::theoryParam,
    255       parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
    256           );
    257   parser->load(&input);
     275  mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);
     276  mpqc->load(&input);
    258277
    259278  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
     
    282301    // compare both configs for CLHF
    283302    stringstream output;
    284     parser->getParams().setParameter(
    285         MpqcParser_Parameters::theoryParam,
    286         parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
    287             );
    288     parser->save(&output, atoms);
     303    mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);
     304    mpqc->save(&output, atoms);
    289305    stringstream input(waterMpqc_CLHF);
    290     // check for non-empty streams
    291     input.peek();
    292     output.peek();
    293     CPPUNIT_ASSERT(input.good() && output.good());
    294     // check equality of streams per line (for debugging)
    295306    for (; std::getline(input, first) && std::getline(output, second); ) {
    296307      //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
     
    301312    // compare both configs for CLKS
    302313    stringstream output;
    303     parser->getParams().setParameter(
    304         MpqcParser_Parameters::theoryParam,
    305         parser->getParams().getTheoryName(MpqcParser_Parameters::CLKS)
    306             );
    307     parser->save(&output, atoms);
     314    mpqc->getParams().setTheory(MpqcParser_Parameters::CLKS);
     315    mpqc->save(&output, atoms);
    308316    stringstream input(waterMpqc_CLKS);
    309     // check for non-empty streams
    310     input.peek();
    311     output.peek();
    312     CPPUNIT_ASSERT(input.good() && output.good());
    313     // check equality of streams per line (for debugging)
    314317    for (; std::getline(input, first) && std::getline(output, second); ) {
    315318      //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
     
    320323    // compare both configs for MBPT2
    321324    stringstream output;
    322     parser->getParams().setParameter(
    323         MpqcParser_Parameters::theoryParam,
    324         parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2)
    325             );
    326     parser->save(&output, atoms);
     325    mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2);
     326    mpqc->save(&output, atoms);
    327327    stringstream input(waterMpqc_MBPT2);
    328     // check for non-empty streams
    329     input.peek();
    330     output.peek();
    331     CPPUNIT_ASSERT(input.good() && output.good());
    332     // check equality of streams per line (for debugging)
    333328    for (; std::getline(input, first) && std::getline(output, second); ) {
    334329      //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
     
    339334    // compare both configs for MBPT2_R12
    340335    stringstream output;
    341     parser->getParams().setParameter(
    342         MpqcParser_Parameters::theoryParam,
    343         parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)
    344             );
    345     parser->save(&output, atoms);
     336    mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12);
     337    mpqc->save(&output, atoms);
    346338    stringstream input(waterMpqc_MBPT2_R12);
    347     // check for non-empty streams
    348     input.peek();
    349     output.peek();
    350     CPPUNIT_ASSERT(input.good() && output.good());
    351     // check equality of streams per line (for debugging)
    352339    for (; std::getline(input, first) && std::getline(output, second); ) {
    353340      //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
  • src/Parser/unittests/ParserMpqcUnitTest.hpp

    r360c8b rfa9d1d  
    2121{
    2222  CPPUNIT_TEST_SUITE( ParserMpqcUnitTest ) ;
     23  CPPUNIT_TEST ( ParameterTypeTest );
    2324  CPPUNIT_TEST ( ParameterDefaultTest );
    2425  CPPUNIT_TEST ( ParameterSetterTest );
     
    3233  void tearDown();
    3334
     35  void ParameterTypeTest();
    3436  void ParameterDefaultTest();
    3537  void ParameterSetterTest();
     
    3941
    4042private:
    41   FormatParser<mpqc> *parser;
     43  MpqcParser *mpqc;
    4244};
    4345
  • src/Parser/unittests/ParserPcpUnitTest.cpp

    r360c8b rfa9d1d  
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
     26#include "Parser/PcpParser.hpp"
    2627#include "World.hpp"
    2728#include "atom.hpp"
     
    3031#include "CodePatterns/Log.hpp"
    3132#include "Descriptors/AtomTypeDescriptor.hpp"
    32 #include "Parser/ChangeTracker.hpp"
    33 #include "Parser/PcpParser.hpp"
    3433
    3534#ifdef HAVE_TESTRUNNER
     
    120119  World::getInstance();
    121120
    122   parser = new FormatParser<pcp>();
    123 
    124121  setVerbosity(2);
    125122
     
    129126}
    130127
    131 void ParserPcpUnitTest::tearDown()
    132 {
    133   delete parser;
     128void ParserPcpUnitTest::tearDown() {
    134129  ChangeTracker::purgeInstance();
    135130  World::purgeInstance();
     
    140135void ParserPcpUnitTest::readwritePcpTest() {
    141136  stringstream input(waterPcp);
    142   parser->load(&input);
     137  PcpParser* testParser = new PcpParser();
     138  testParser->load(&input);
    143139  input.clear();
    144140
     
    146142
    147143  // check that equality function is ok
    148   CPPUNIT_ASSERT(*parser == *parser);
     144  CPPUNIT_ASSERT(*testParser == *testParser);
    149145
    150146  stringstream output;
    151147  std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    152   parser->save(&output, atoms);
     148  testParser->save(&output, atoms);
    153149
    154150  input << output.str();
    155   FormatParser<pcp>* parser2 = new FormatParser<pcp>();
    156   parser2->load(&input);
     151  PcpParser* testParser2 = new PcpParser();
     152  testParser2->load(&input);
    157153
    158154  CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms());
    159155
    160   CPPUNIT_ASSERT(*parser == *parser2);
    161 
    162   delete parser2;
     156  CPPUNIT_ASSERT(*testParser == *testParser2);
    163157}
  • src/Parser/unittests/ParserPcpUnitTest.hpp

    r360c8b rfa9d1d  
    1313#endif
    1414
    15 #include "Parser/PcpParser.hpp"
    1615
    1716#include <cppunit/extensions/HelperMacros.h>
     
    2928
    3029  void readwritePcpTest();
    31 
    32 private:
    33   FormatParser<pcp> *parser;
    3430};
    3531
  • src/Parser/unittests/ParserPdbUnitTest.cpp

    r360c8b rfa9d1d  
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
     26#include "Parser/PdbParser.hpp"
    2627#include "World.hpp"
    2728#include "atom.hpp"
     
    3031#include "CodePatterns/Log.hpp"
    3132#include "Descriptors/AtomTypeDescriptor.hpp"
    32 #include "Parser/ChangeTracker.hpp"
    33 #include "Parser/PdbParser.hpp"
    3433
    3534#ifdef HAVE_TESTRUNNER
     
    6463  World::getInstance();
    6564
    66   parser = new FormatParser<pdb>();
    67 
    6865  setVerbosity(2);
    6966
     
    7370}
    7471
    75 void ParserPdbUnitTest::tearDown()
    76 {
    77   delete parser;
     72void ParserPdbUnitTest::tearDown() {
    7873  ChangeTracker::purgeInstance();
    7974  World::purgeInstance();
     
    8580  stringstream input;
    8681  input << waterPdb;
    87   parser->load(&input);
     82  PdbParser* testParser = new PdbParser();
     83  testParser->load(&input);
    8884  input.clear();
    8985
     
    9288  stringstream output;
    9389  std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    94   parser->save(&output, atoms);
     90  testParser->save(&output, atoms);
    9591
    9692//  std::cout << "Save PDB is:" << std::endl;
     
    9894
    9995  input << output.str();
    100   FormatParser<pdb>* parser2 = new FormatParser<pdb>();
    101   parser2->load(&input);
     96  PdbParser* testParser2 = new PdbParser();
     97  testParser2->load(&input);
    10298
    10399  CPPUNIT_ASSERT_EQUAL(12, World::getInstance().numAtoms());
    104 
    105   delete parser2;
    106100}
  • src/Parser/unittests/ParserPdbUnitTest.hpp

    r360c8b rfa9d1d  
    1313#endif
    1414
    15 #include "Parser/PdbParser.hpp"
    1615
    1716#include <cppunit/extensions/HelperMacros.h>
     
    2928
    3029  void readwritePdbTest();
    31 
    32 private:
    33   FormatParser<pdb> *parser;
    3430};
    3531
  • src/Parser/unittests/ParserTremoloUnitTest.cpp

    r360c8b rfa9d1d  
    2727#include "Descriptors/AtomTypeDescriptor.hpp"
    2828#include "Element/element.hpp"
     29#include "Parser/MpqcParser.hpp"
     30#include "Parser/PdbParser.hpp"
     31#include "Parser/PcpParser.hpp"
     32#include "Parser/TremoloParser.hpp"
     33#include "Parser/XyzParser.hpp"
    2934#include "Element/periodentafel.hpp"
    30 #include "Parser/TremoloParser.hpp"
    31 #include "Parser/ChangeTracker.hpp"
    3235#include "World.hpp"
    3336#include "WorldTime.hpp"
     
    8285  World::getInstance();
    8386
    84   parser = new FormatParser<tremolo>();
    85 
    8687  // we need hydrogens and oxygens in the following tests
    8788  CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
     
    8990}
    9091
    91 void ParserTremoloUnitTest::tearDown()
    92 {
    93   delete parser;
     92void ParserTremoloUnitTest::tearDown() {
    9493  ChangeTracker::purgeInstance();
    9594  World::purgeInstance();
     
    10099void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
    101100  cout << "Testing the tremolo parser." << endl;
     101  TremoloParser* testParser = new TremoloParser();
    102102  stringstream input, output;
    103103
     
    105105  {
    106106    input << Tremolo_Atomdata1;
    107     parser->load(&input);
    108     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    109     parser->save(&output, atoms);
     107    testParser->load(&input);
     108    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     109    testParser->save(&output, atoms);
    110110//    std::cout << output.str() << std::endl;
    111111//    std::cout << Tremolo_Atomdata1 << std::endl;
     
    118118  {
    119119    input << Tremolo_Atomdata2;
    120     parser->load(&input);
    121     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    122     parser->save(&output, atoms);
     120    testParser->load(&input);
     121    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     122    testParser->save(&output, atoms);
    123123    std::cout << output.str() << std::endl;
    124124    CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
     
    129129  // Invalid key in Atomdata line
    130130  input << Tremolo_invalidkey;
    131   parser->load(&input);
     131  testParser->load(&input);
    132132  //TODO: prove invalidity
    133133  input.clear();
     
    135135
    136136void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
     137  TremoloParser* testParser = new TremoloParser();
    137138  stringstream input;
    138139
    139140  // One simple data line
    140141  input << Tremolo_Atomdata2;
    141   parser->load(&input);
     142  testParser->load(&input);
    142143  CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
    143144  input.clear();
     
    145146
    146147void ParserTremoloUnitTest::readTremoloVelocityTest() {
     148  TremoloParser* testParser = new TremoloParser();
    147149  stringstream input;
    148150
    149151  // One simple data line
    150152  input << Tremolo_velocity;
    151   parser->load(&input);
     153  testParser->load(&input);
    152154  CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
    153155  input.clear();
     
    155157
    156158void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
     159  TremoloParser* testParser = new TremoloParser();
    157160  stringstream input;
    158161
    159162  // Neighbor data
    160163  input << Tremolo_neighbours;
    161   parser->load(&input);
     164  testParser->load(&input);
    162165
    163166  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
     
    168171
    169172void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
     173  TremoloParser* testParser = new TremoloParser();
    170174  stringstream input, output;
    171175
     
    173177  {
    174178    input << Tremolo_improper;
    175     parser->load(&input);
    176     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    177     parser->save(&output, atoms);
     179    testParser->load(&input);
     180    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     181    testParser->save(&output, atoms);
    178182    CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
    179183    std::cout << output.str() << std::endl;
     
    185189
    186190void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
     191  TremoloParser* testParser = new TremoloParser();
    187192  stringstream input, output;
    188193
     
    190195  {
    191196    input << Tremolo_torsion;
    192     parser->load(&input);
    193     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    194     parser->save(&output, atoms);
     197    testParser->load(&input);
     198    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     199    testParser->save(&output, atoms);
    195200    CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
    196201    std::cout << output.str() << std::endl;
     
    202207
    203208void ParserTremoloUnitTest::writeTremoloTest() {
     209  TremoloParser* testParser = new TremoloParser();
    204210  stringstream output;
    205211
     
    208214    atom* newAtom = World::getInstance().createAtom();
    209215    newAtom->setType(1);
    210     parser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
    211     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    212     parser->save(&output, atoms);
     216    testParser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
     217    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     218    testParser->save(&output, atoms);
    213219    CPPUNIT_ASSERT(output.str() == Tremolo_full);
    214220  }
     
    216222  cout << "testing the tremolo parser is done" << endl;
    217223}
    218 
  • src/Parser/unittests/ParserTremoloUnitTest.hpp

    r360c8b rfa9d1d  
    1313#endif
    1414
    15 #include "Parser/TremoloParser.hpp"
    1615
    1716#include <cppunit/extensions/HelperMacros.h>
     
    4140  void readAndWriteTremoloTorsionInformationTest();
    4241  void writeTremoloTest();
    43 
    44 private:
    45   FormatParser<tremolo> *parser;
    4642};
    4743
  • src/Parser/unittests/ParserXyzUnitTest.cpp

    r360c8b rfa9d1d  
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
     26#include "Parser/XyzParser.hpp"
    2627#include "World.hpp"
    2728#include "atom.hpp"
     
    3031#include "CodePatterns/Log.hpp"
    3132#include "Descriptors/AtomTypeDescriptor.hpp"
    32 #include "Parser/ChangeTracker.hpp"
    33 #include "Parser/XyzParser.hpp"
    3433
    3534#ifdef HAVE_TESTRUNNER
     
    6362  World::getInstance();
    6463
    65   parser = new FormatParser<xyz>();
    66 
    6764  setVerbosity(2);
    6865
     
    7269}
    7370
    74 void ParserXyzUnitTest::tearDown()
    75 {
    76   delete parser;
     71void ParserXyzUnitTest::tearDown() {
    7772  ChangeTracker::purgeInstance();
    7873  World::purgeInstance();
     
    8378void ParserXyzUnitTest::rewriteAnXyzTest() {
    8479  cout << "Testing the XYZ parser." << endl;
     80  XyzParser* testParser = new XyzParser();
    8581  stringstream input;
    8682  input << waterXyz;
    87   parser->load(&input);
     83  testParser->load(&input);
    8884  input.clear();
    8985
     
    9490    stringstream output;
    9591    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    96     parser->save(&output, atoms);
     92    testParser->save(&output, atoms);
    9793    input << output.str();
    98     parser->load(&input);
     94    testParser->load(&input);
    9995  }
    10096
     
    119115void ParserXyzUnitTest::readMultiXyzTest() {
    120116  cout << "Testing the multi time step XYZ parser." << endl;
     117  XyzParser* testParser = new XyzParser();
    121118  stringstream input;
    122119  input << waterMultiXyz;
    123   parser->load(&input);
     120  testParser->load(&input);
    124121  input.clear();
    125122
     
    133130
    134131void ParserXyzUnitTest::writeMultiXyzTest() {
     132  XyzParser* testParser = new XyzParser();
    135133  stringstream input;
    136134  input << waterMultiXyz;
    137   parser->load(&input);
     135  testParser->load(&input);
    138136  input.clear();
    139137
     
    145143    stringstream output;
    146144    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    147     parser->save(&output, atoms);
     145    testParser->save(&output, atoms);
    148146    input << output.str();
    149     parser->load(&input);
     147    testParser->load(&input);
    150148  }
    151149
  • src/Parser/unittests/ParserXyzUnitTest.hpp

    r360c8b rfa9d1d  
    1313#endif
    1414
    15 #include "Parser/XyzParser.hpp"
    1615
    1716#include <cppunit/extensions/HelperMacros.h>
     
    3332  void readMultiXyzTest();
    3433  void writeMultiXyzTest();
    35 
    36 private:
    37   FormatParser<xyz> *parser;
    3834};
    3935
  • src/atom.cpp

    r360c8b rfa9d1d  
    201201};
    202202
    203 void atom::OutputPsi3Line(ostream * const out, const Vector *center) const
    204 {
    205   Vector recentered(getPosition());
    206   recentered -= *center;
    207   *out << "\t( " << getType()->getSymbol() << "\t" << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2] << " )" << endl;
    208 };
    209 
    210203bool atom::Compare(const atom &ptr) const
    211204{
  • src/atom.hpp

    r360c8b rfa9d1d  
    113113   */
    114114  void OutputMPQCLine(ostream * const out, const Vector *center) const;
    115 
    116   /** Outputs the Psi3 configuration line for this atom.
    117    * \param *out output stream
    118    * \param *center center of molecule subtracted from position
    119    * \param *AtomNo pointer to atom counter that is increased by one
    120    */
    121   void OutputPsi3Line(ostream * const out, const Vector *center) const;
    122115
    123116  /** Initialises the component number array.
  • src/moleculelist.cpp

    r360c8b rfa9d1d  
    626626//      atoms.resize((*ListRunner)->getAtomCount());
    627627//      std::copy((*ListRunner)->begin(), (*ListRunner)->end(), atoms.begin());
    628       FormatParserStorage::getInstance().get(mpqc).save(&outfile, atoms);
     628      FormatParserStorage::getInstance().getMpqc().save(&outfile, atoms);
    629629//      if ((intermediateResult = World::getInstance().getConfig()->SaveMPQC(FragmentName.c_str(), (*ListRunner))))
    630630        output << " done.";
  • src/unittests/BoxUnitTest.cpp

    r360c8b rfa9d1d  
    3939
    4040void BoxUnittest::setUp(){
    41   // failing asserts should be thrown
    4241  ASSERT_DO(Assert::Throw);
    43 
    4442  unit = new RealSpaceMatrix;
    4543  unit->setIdentity();
  • src/unittests/FormulaUnitTest.cpp

    r360c8b rfa9d1d  
    3535CPPUNIT_TEST_SUITE_REGISTRATION( FormulaUnittest );
    3636
    37 void FormulaUnittest::setUp()
    38 {
    39   // failing asserts should be thrown
    40   ASSERT_DO(Assert::Throw);
    41 }
    42 
    43 void FormulaUnittest::tearDown()
    44 {
     37void FormulaUnittest::setUp(){}
     38void FormulaUnittest::tearDown(){
    4539  World::purgeInstance();
    4640}
  • tests/regression/Makefile.am

    r360c8b rfa9d1d  
    106106        $(srcdir)/Parser/Pdb/testsuite-parser-pdb-save.at \
    107107        $(srcdir)/Parser/Pdb/testsuite-parser-pdb-with-conects.at \
    108         $(srcdir)/Parser/Psi3/testsuite-parser-psi3-empty.at \
    109         $(srcdir)/Parser/Psi3/testsuite-parser-psi3-load.at \
    110         $(srcdir)/Parser/Psi3/testsuite-parser-psi3-save.at \
    111108        $(srcdir)/Parser/Tremolo/testsuite-parser-tremolo-empty.at \
    112109        $(srcdir)/Parser/Tremolo/testsuite-parser-tremolo-load.at \
  • tests/regression/Parser/testsuite-parser.at

    r360c8b rfa9d1d  
    3030m4_include([Parser/Pdb/testsuite-parser-pdb-load-various.at])
    3131
    32 # parsing mpqc
    33 m4_include([Parser/Psi3/testsuite-parser-psi3-empty.at])
    34 m4_include([Parser/Psi3/testsuite-parser-psi3-load.at])
    35 m4_include([Parser/Psi3/testsuite-parser-psi3-save.at])
    36 
    3732# parsing tremolo
    3833m4_include([Parser/Tremolo/testsuite-parser-tremolo-empty.at])
Note: See TracChangeset for help on using the changeset viewer.