<commit_before>#ifndef VOTCA_CTP_LOG2MPS_H
#define VOTCA_CTP_LOG2MPS_H


#include <votca/ctp/qmtool.h>
#include <votca/ctp/topology.h>
#include <votca/ctp/qmpackagefactory.h>
#include <votca/ctp/qmmachine.h>


namespace votca { namespace ctp {


class Log2Mps : public QMTool
{
public:

    Log2Mps() { };
   ~Log2Mps() { };

    string Identify() { return "log2mps"; }

    void   Initialize(Property *options);
    bool   Evaluate();



private:

    string _package;
    string _logfile;
    string _mpsfile;

};


void Log2Mps::Initialize(Property *opt) {
    
    QMPackageFactory::RegisterAll();
    
    string key = "options.log2mps";
    _package = opt->get(key+".package").as<string>();
    _logfile = opt->get(key+".logfile").as<string>();
    

    _mpsfile = (opt->exists(key+".mpsfile")) ? 
        opt->get(key+".mpsfile").as<string>() : "";
    if (_mpsfile == "") _mpsfile = _logfile.substr(0,_logfile.size()-4)+".mps";

    cout << endl << "... ... " << _logfile << " => " << _mpsfile << flush;
}


bool Log2Mps::Evaluate() {
    
    // Logger (required for QM package, so we can just as well use it)
    Logger log;
    log.setPreface(logINFO, "\n... ...");
    log.setPreface(logDEBUG, "\n... ...");
    log.setReportLevel(logDEBUG);
    log.setMultithreading(true);  
    
    // Set-up QM package
    LOG(logINFO,log) << "Using package <" << _package << ">" << flush;
    QMPackage *qmpack = QMPackages().Create(_package);    
    qmpack->doGetCharges(true);
    qmpack->setLog(&log);
    qmpack->setRunDir(".");
    qmpack->setLogFileName(_logfile);
    
    // Create orbitals, fill with life & extract QM atoms
    Orbitals orbs;
    int cdx = qmpack->ParseLogFile(&orbs);
    if (!cdx) {
        cout << "\nERROR Parsing " << _logfile << "failed. Abort." << endl;
        throw std::runtime_error("(see above, parsing error)");
    }    
    vector<QMAtom*> &qmatoms = *orbs.getAtoms();
    vector<QMAtom*>::iterator it;
    
    // Sanity checks, total charge
    double Q = 0.0;
    for (it = qmatoms.begin(); it < qmatoms.end(); ++it) {
        Q += (*it)->charge;
    }
    
    if (qmatoms.size() < 1) {
        cout << "\nERROR No charges extracted from " << _logfile 
            << ". Abort.\n" << flush;
        throw std::runtime_error("(see above, input or parsing error)");
    }
    LOG(logINFO,log) <commit_msg>some more warning found by travis<commit_after>#ifndef VOTCA_CTP_LOG2MPS_H
#define VOTCA_CTP_LOG2MPS_H


#include <votca/ctp/qmtool.h>
#include <votca/ctp/topology.h>
#include <votca/ctp/qmpackagefactory.h>
#include <votca/ctp/qmmachine.h>


namespace votca { namespace ctp {


class Log2Mps : public QMTool
{
public:

    Log2Mps() { };
   ~Log2Mps() { };

    string Identify() { return "log2mps"; }

    void   Initialize(Property *options);
    bool   Evaluate();



private:

    string _package;
    string _logfile;
    string _mpsfile;

};


void Log2Mps::Initialize(Property *opt) {
    
    QMPackageFactory::RegisterAll();
    
    string key = "options.log2mps";
    _package = opt->get(key+".package").as<string>();
    _logfile = opt->get(key+".logfile").as<string>();
    

    _mpsfile = (opt->exists(key+".mpsfile")) ? 
        opt->get(key+".mpsfile").as<string>() : "";
    if (_mpsfile == "") _mpsfile = _logfile.substr(0,_logfile.size()-4)+".mps";

    cout << endl << "... ... " << _logfile << " => " << _mpsfile << flush;
}


bool Log2Mps::Evaluate() {
    
    // Logger (required for QM package, so we can just as well use it)
    Logger log;
    log.setPreface(logINFO, "\n... ...");
    log.setPreface(logDEBUG, "\n... ...");
    log.setReportLevel(logDEBUG);
    log.setMultithreading(true);  
    
    // Set-up QM package
    LOG_SAVE(logINFO,log) << "Using package <" << _package << ">" << flush;
    QMPackage *qmpack = QMPackages().Create(_package);    
    qmpack->doGetCharges(true);
    qmpack->setLog(&log);
    qmpack->setRunDir(".");
    qmpack->setLogFileName(_logfile);
    
    // Create orbitals, fill with life & extract QM atoms
    Orbitals orbs;
    int cdx = qmpack->ParseLogFile(&orbs);
    if (!cdx) {
        cout << "\nERROR Parsing " << _logfile << "failed. Abort." << endl;
        throw std::runtime_error("(see above, parsing error)");
    }    
    vector<QMAtom*> &qmatoms = *orbs.getAtoms();
    vector<QMAtom*>::iterator it;
    
    // Sanity checks, total charge
    double Q = 0.0;
    for (it = qmatoms.begin(); it < qmatoms.end(); ++it) {
        Q += (*it)->charge;
    }
    
    if (qmatoms.size() < 1) {
        cout << "\nERROR No charges extracted from " << _logfile 
            << ". Abort.\n" << flush;
        throw std::runtime_error("(see above, input or parsing error)");
    }
    LOG_SAVE(logINFO,log) 
{'fraction_non_alphanumeric': 0.17448246725813266, 'fraction_numerical': 0.005914659907055344, 'mean_word_length': 2.769904458598726, 'pattern_counts': {'":': 0, '<': 99, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3190435', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1721, 'n_words': 339}