Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conformer search box #1507

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions avogadro/qtplugins/openbabel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ if(QT_VERSION EQUAL 6)
endif()

set(openbabel_srcs
conformersearchdialog.cpp
obcharges.cpp
obfileformat.cpp
obforcefielddialog.cpp
Expand All @@ -11,6 +12,7 @@ set(openbabel_srcs
)

set(openbabel_uis
conformersearchdialog.ui
obforcefielddialog.ui
)

Expand Down
172 changes: 172 additions & 0 deletions avogadro/qtplugins/openbabel/conformersearchdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/******************************************************************************
This source file is part of the Avogadro project.
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

#include "conformersearchdialog.h"

#include <QButtonGroup>
#include <QDebug>
#include <QPushButton>

namespace Avogadro {

ConformerSearchDialog::ConformerSearchDialog(QWidget* parent, Qt::WindowFlags f)
: QDialog(parent, f)
{
ui.setupUi(this);

connect(ui.systematicRadio, SIGNAL(toggled(bool)), this,
SLOT(systematicToggled(bool)));
connect(ui.randomRadio, SIGNAL(toggled(bool)), this,
SLOT(randomToggled(bool)));
connect(ui.weightedRadio, SIGNAL(toggled(bool)), this,
SLOT(weightedToggled(bool)));
connect(ui.geneticRadio, SIGNAL(toggled(bool)), this,
SLOT(geneticToggled(bool)));

connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this,
SLOT(buttonClicked(QAbstractButton*)));

m_method = 1; // systematic
m_numConformers = 100;

ui.numSpin->setValue(0);
ui.systematicRadio->setChecked(true);
ui.randomRadio->setChecked(false);
ui.weightedRadio->setChecked(false);
ui.geneticRadio->setChecked(false);
ui.childrenSpinBox->setEnabled(false);
ui.mutabilitySpinBox->setEnabled(false);
ui.convergenceSpinBox->setEnabled(false);
ui.scoringComboBox->setEnabled(false);
}

ConformerSearchDialog::~ConformerSearchDialog() {}

void ConformerSearchDialog::buttonClicked(QAbstractButton* button)
{
if (button == ui.buttonBox->button(QDialogButtonBox::Ok)) {
emit accepted();
}
close();
}

QStringList ConformerSearchDialog::options() const
{
QStringList options;

// in OB v3.2
options << "--steps" << QString::number(ui.optimizationStepsSpinBox->value());

if (ui.systematicRadio->isChecked())
options << "--systematic";
else if (ui.randomRadio->isChecked()) {
options << "--random";
options << "--nconf" << QString::number(ui.numSpin->value());
} else if (ui.weightedRadio->isChecked()) {
options << "--weighted";
options << "--nconf" << QString::number(ui.numSpin->value());
} else if (ui.geneticRadio->isChecked()) {
// genetic is the default, no need to specify
options << "--nconf" << QString::number(ui.numSpin->value());
options << "--children" << QString::number(ui.childrenSpinBox->value());
options << "--mutability" << QString::number(ui.mutabilitySpinBox->value());
options << "--convergence"
<< QString::number(ui.convergenceSpinBox->value());
options << "--scoring" << ui.scoringComboBox->currentText();
}

return options;
}

void ConformerSearchDialog::systematicToggled(bool checked)
{
if (checked) {
m_method = 1;
ui.systematicRadio->setChecked(true);
ui.randomRadio->setChecked(false);
ui.weightedRadio->setChecked(false);
ui.geneticRadio->setChecked(false);
ui.childrenSpinBox->setEnabled(false);
ui.mutabilitySpinBox->setEnabled(false);
ui.convergenceSpinBox->setEnabled(false);
ui.scoringComboBox->setEnabled(false);

ui.numSpin->setEnabled(false);
ui.numSpin->setValue(0);
}
}

void ConformerSearchDialog::randomToggled(bool checked)
{
if (checked) {
m_method = 2;
ui.systematicRadio->setChecked(false);
ui.randomRadio->setChecked(true);
ui.weightedRadio->setChecked(false);
ui.geneticRadio->setChecked(false);
ui.childrenSpinBox->setEnabled(false);
ui.mutabilitySpinBox->setEnabled(false);
ui.convergenceSpinBox->setEnabled(false);
ui.scoringComboBox->setEnabled(false);
ui.numSpin->setEnabled(true);
ui.numSpin->setValue(100);
}
}

void ConformerSearchDialog::weightedToggled(bool checked)
{
if (checked) {
m_method = 3;
ui.systematicRadio->setChecked(false);
ui.randomRadio->setChecked(false);
ui.weightedRadio->setChecked(true);
ui.geneticRadio->setChecked(false);
ui.childrenSpinBox->setEnabled(false);
ui.mutabilitySpinBox->setEnabled(false);
ui.convergenceSpinBox->setEnabled(false);
ui.scoringComboBox->setEnabled(false);
ui.numSpin->setEnabled(true);
ui.numSpin->setValue(100);
}
}

void ConformerSearchDialog::geneticToggled(bool checked)
{
if (checked) {
m_method = 4;
ui.systematicRadio->setChecked(false);
ui.randomRadio->setChecked(false);
ui.weightedRadio->setChecked(false);
ui.geneticRadio->setChecked(true);
ui.childrenSpinBox->setEnabled(true);
ui.mutabilitySpinBox->setEnabled(true);
ui.convergenceSpinBox->setEnabled(true);
ui.scoringComboBox->setEnabled(true);
ui.numSpin->setEnabled(true);
ui.numSpin->setValue(100);
}
}

void ConformerSearchDialog::accept()
{
m_numConformers = ui.numSpin->value();
hide();
}

void ConformerSearchDialog::reject()
{
hide();
}

int ConformerSearchDialog::numConformers()
{
return m_numConformers;
}

int ConformerSearchDialog::method()
{
return m_method;
}
} // namespace Avogadro
50 changes: 50 additions & 0 deletions avogadro/qtplugins/openbabel/conformersearchdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/******************************************************************************
This source file is part of the Avogadro project.
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

#ifndef CONFORMERSEARCHDIALOG_H
#define CONFORMERSEARCHDIALOG_H

#include <QDialog>

#include "ui_conformersearchdialog.h"

namespace Avogadro {
class ConformerSearchDialog : public QDialog
{
Q_OBJECT

public:
//! Constructor
explicit ConformerSearchDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
//! Desconstructor
~ConformerSearchDialog();

int method();
int numConformers();

QStringList options() const;

public slots:
void accept();
void reject();
void systematicToggled(bool checked);
void randomToggled(bool checked);
void weightedToggled(bool checked);
void geneticToggled(bool checked);

void buttonClicked(QAbstractButton* button);

signals:
void accepted();

private:
Ui::ConformerSearchDialog ui;

int m_method;
int m_numConformers;
};
} // namespace Avogadro

#endif
Loading
Loading