<commit_before>
/**********************************************************************
  QTAIM - Extension for Quantum Theory of Atoms In Molecules Analysis

  Copyright (C) 2010 <NAME>
  This file is part of the Avogadro molecular editor project.
  For more information, see <http://avogadro.openmolecules.net/>

  Avogadro is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  Avogadro is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  02110-1301, USA.
 **********************************************************************/

#include "qtaimextension.h"

#include <avogadro/molecule.h>
#include <avogadro/atom.h>
#include <avogadro/bond.h>
#include <avogadro/painter.h>

#include <QAction>

#include <QString>
#include <QDebug>
#include <QList>
#include <QVector3D>
#include <QPair>
#include <QFileDialog>
#include <QDir>

#include <QThread>

#include "qtaimwavefunction.h"
#include "qtaimwavefunctionevaluator.h"
#include "qtaimcriticalpointlocator.h"
#include "qtaimcubature.h"

#include <QTime>

using namespace std;
using namespace Eigen;

namespace Avogadro
{

  enum QTAIMExtensionIndex {
    FirstAction = 0,
    SecondAction,
    ThirdAction
  };

  QTAIMExtension::QTAIMExtension( QObject *parent ) : Extension( parent )
  {
    // create an action for our first action
    QAction *action = new QAction( this );
    action->setText( tr("Molecular Graph" ));
    m_actions.append( action );
    action->setData( FirstAction );

    // create an action for our second action
    action = new QAction( this );
    action->setText( tr("Molecular Graph with Lone Pairs" ));
    m_actions.append( action );
    action->setData( SecondAction );

    // create an action for our third action
    action = new QAction( this );
    action->setText( tr("Atomic Charge" ));
    m_actions.append( action );
    action->setData( ThirdAction );
  }

  QTAIMExtension::~QTAIMExtension()
  {
  }

  QList<QAction *> QTAIMExtension::actions() const
  {
    return m_actions;
  }

  QString QTAIMExtension::menuPath(QAction *action) const
  {
    int i = action->data().toInt();

    switch ( i ) {
    case FirstAction:
      return tr("E&xtensions") + '>' + tr("QTAIM");
      break;
    case SecondAction:
      return tr("E&xtensions") + '>' + tr("QTAIM");
      break;
    case ThirdAction:
      return tr("E&xtensions") + '>' + tr("QTAIM");
      break;
    }
    return "";
  }

  QDockWidget * QTAIMExtension::dockWidget()
  {
    return 0;
  }

  void QTAIMExtension::setMolecule(Molecule *molecule)
  {
    m_molecule = molecule;
  }

  QUndoCommand* QTAIMExtension::performAction(QAction *action, GLWidget *)
  {

    bool wavefunctionAlreadyLoaded;

    if( m_molecule->property("QTAIMComment").isValid() )
    {
      wavefunctionAlreadyLoaded=true;
    }
    else
    {
      wavefunctionAlreadyLoaded=false;
    }

    int i = action->data().toInt();

    QTime timer;
    timer.start();

    QString fileName;
    if( wavefunctionAlreadyLoaded )
    {
      // do nothing
    }
    else
    {
       fileName = QFileDialog::getOpenFileName(
          new QWidget,
          tr("Open WFN File"),
          QDir::homePath(),
          tr("WFN files (*.wfn);;All files (*.*)") );

      if(fileName.isNull())
      {
        qDebug() << "No such file.";
        return 0;
      }
    }

    // Instantiate a Wavefunction
    bool success;
    QTAIMWavefunction wfn;
    if( wavefunctionAlreadyLoaded )
    {
      success=wfn.initializeWithMoleculeProperties(m_molecule);
    }
    else
    {
      success=wfn.initializeWithWFNFile(fileName);
    }

    if(!success)
    {
      if( wavefunctionAlreadyLoaded )
      {
        qDebug() << "Error initializing wavefunction.";
      }
      else
      {
        qDebug() << "Error reading WFN file.";
      }
        return 0;
    }

    m_molecule->clear();

    // Instantiate an Evaluator
    QTAIMWavefunctionEvaluator eval(wfn);

    switch ( i ) {
    case FirstAction: // Molecular Graph
      {
        // Instantiate a Critical Point Locator
        QTAIMCriticalPointLocator cpl(wfn);

        // Locate the Nuclear Critical Points
        cpl.locateNuclearCriticalPoints();

        // QLists of results
        QList<qint64>    nucChargeList=wfn.nuclearChargesList();
        QList<QVector3D> ncpList=cpl.nuclearCriticalPoints();

        QVariantList xNCPsVariantList;
        QVariantList yNCPsVariantList;
        QVariantList zNCPsVariantList;
        QVariantList nuclearChargesVariantList;

        const qreal convertBohrToAngstrom=0.529177249;

        // Nuclear Critical Points
        for( qint64 n=0 ; n < ncpList.length() ; ++n )
        {
          QVector3D thisNuclearCriticalPoint=ncpList.at(n);

          qreal x=thisNuclearCriticalPoint.x() * convertBohrToAngstrom;
          qreal y=thisNuclearCriticalPoint.y() * convertBohrToAngstrom;<commit_msg>When loading QTAIM files, switch to the navigate tool.<commit_after>
/**********************************************************************
  QTAIM - Extension for Quantum Theory of Atoms In Molecules Analysis

  Copyright (C) 2010 <NAME>
  This file is part of the Avogadro molecular editor project.
  For more information, see <http://avogadro.openmolecules.net/>

  Avogadro is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  Avogadro is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  02110-1301, USA.
 **********************************************************************/

#include "qtaimextension.h"

#include <avogadro/molecule.h>
#include <avogadro/atom.h>
#include <avogadro/bond.h>
#include <avogadro/painter.h>
#include <avogadro/toolgroup.h>

#include <QAction>

#include <QString>
#include <QDebug>
#include <QList>
#include <QVector3D>
#include <QPair>
#include <QFileDialog>
#include <QDir>

#include <QThread>

#include "qtaimwavefunction.h"
#include "qtaimwavefunctionevaluator.h"
#include "qtaimcriticalpointlocator.h"
#include "qtaimcubature.h"

#include <QTime>

using namespace std;
using namespace Eigen;

namespace Avogadro
{

  enum QTAIMExtensionIndex {
    FirstAction = 0,
    SecondAction,
    ThirdAction
  };

  QTAIMExtension::QTAIMExtension( QObject *parent ) : Extension( parent )
  {
    // create an action for our first action
    QAction *action = new QAction( this );
    action->setText( tr("Molecular Graph..." ));
    m_actions.append( action );
    action->setData( FirstAction );

    // create an action for our second action
    action = new QAction( this );
    action->setText( tr("Molecular Graph with Lone Pairs..." ));
    m_actions.append( action );
    action->setData( SecondAction );

    // create an action for our third action
    action = new QAction( this );
    action->setText( tr("Atomic Charge..." ));
    m_actions.append( action );
    action->setData( ThirdAction );
  }

  QTAIMExtension::~QTAIMExtension()
  {
  }

  QList<QAction *> QTAIMExtension::actions() const
  {
    return m_actions;
  }

  QString QTAIMExtension::menuPath(QAction *action) const
  {
    int i = action->data().toInt();

    switch ( i ) {
    case FirstAction:
      return tr("E&xtensions") + '>' + tr("QTAIM");
      break;
    case SecondAction:
      return tr("E&xtensions") + '>' + tr("QTAIM");
      break;
    case ThirdAction:
      return tr("E&xtensions") + '>' + tr("QTAIM");
      break;
    }
    return "";
  }

  QDockWidget * QTAIMExtension::dockWidget()
  {
    return 0;
  }

  void QTAIMExtension::setMolecule(Molecule *molecule)
  {
    m_molecule = molecule;
  }

  QUndoCommand* QTAIMExtension::performAction(QAction *action, GLWidget *widget)
  {

    bool wavefunctionAlreadyLoaded;

    if( m_molecule->property("QTAIMComment").isValid() )
    {
      wavefunctionAlreadyLoaded=true;
    }
    else
    {
      wavefunctionAlreadyLoaded=false;
    }

    int i = action->data().toInt();

    QTime timer;
    timer.start();

    QString fileName;
    if( wavefunctionAlreadyLoaded )
    {
      // do nothing
    }
    else
    {
       fileName = QFileDialog::getOpenFileName(
          new QWidget,
          tr("Open WFN File"),
          QDir::homePath(),
          tr("WFN files (*.wfn);;All files (*.*)") );

      if(fileName.isNull())
      {
        qDebug() << "No such file.";
        return 0;
      }
    }

    // Instantiate a Wavefunction
    bool success;
    QTAIMWavefunction wfn;
    if( wavefunctionAlreadyLoaded )
    {
      success=wfn.initializeWithMoleculeProperties(m_molecule);
    }
    else
    {
      success=wfn.initializeWithWFNFile(fileName);
    }

    if(!success)
    {
      if( wavefunctionAlreadyLoaded )
      {
        qDebug() << "Error initializing wavefunction.";
      }
      else
      {
        qDebug() << "Error reading WFN file.";
      }
        return 0;
    }

    m_molecule->clear();
    widget->toolGroup()->setActiveTool("Navigate");


    // Instantiate an Evaluator
    QTAIMWavefunctionEvaluator eval(wfn);

    switch ( i ) {
    case FirstAction: // Molecular Graph
      {
        // Instantiate a Critical Point Locator
        QTAIMCriticalPointLocator cpl(wfn);

        // Locate the Nuclear Critical Points
        cpl.locateNuclearCriticalPoints();

        // QLists of results
        QList<qint64>    nucChargeList=wfn.nuclearChargesList();
        QList<QVector3D> ncpList=cpl.nuclearCriticalPoints();

        QVariantList xNCPsVariantList;
        QVariantList yNCPsVariantList;
        QVariantList zNCPsVariantList;
        QVariantList nuclearChargesVariantList;

        const qreal convertBohrToAngstrom=0.529177249;

        // Nuclear Critical Points
        for( qint64 n=0 ; n < ncpList.length() ; ++n )
        {
          QVector3D thisNuclearCriticalPoint=ncpList.at(n);

          qreal x=thisNuclearCriticalPoint.x() * convertBohrToAngstrom;
          qreal y=thisNuclearCriticalPoint.y() * convertBohrToAngstrom;
{'fraction_non_alphanumeric': 0.12725276735888758, 'fraction_numerical': 0.006952703320830665, 'mean_word_length': 2.9883254286756658, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 70, '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': '722313', 'n_tokens_mistral': 3579, 'n_tokens_neox': 3310, 'n_words': 869}