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

Use the new --noh flag in Open Babel 3.0.1 and later #471

Merged
merged 4 commits into from
May 8, 2020
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
5 changes: 3 additions & 2 deletions avogadro/qtplugins/openbabel/obprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,10 @@ bool OBProcess::optimizeGeometry(const QByteArray& mol,
}

QStringList realOptions;
realOptions << "-imol"
<< "-omol"
realOptions << "-icml"
<< "-ocml"
<< "--minimize"
<< "--noh" // new in OB 3.0.1
<< "--log" << options;

// We'll need to read the log (printed to stderr) to update progress
Expand Down
74 changes: 37 additions & 37 deletions avogadro/qtplugins/openbabel/openbabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,38 @@ OpenBabel::OpenBabel(QObject* p)
{
QAction* action = new QAction(this);
action->setEnabled(true);
action->setText(tr("Optimize geometry"));
action->setText(tr("Optimize Geometry"));
action->setShortcut(QKeySequence("Ctrl+Alt+O"));
connect(action, SIGNAL(triggered()), SLOT(onOptimizeGeometry()));
m_actions.push_back(action);

action = new QAction(this);
action->setEnabled(true);
action->setText(tr("Configure geometry optimization..."));
action->setText(tr("Configure Force Field..."));
connect(action, SIGNAL(triggered()), SLOT(onConfigureGeometryOptimization()));
m_actions.push_back(action);

action = new QAction(this);
action->setEnabled(true);
action->setText(tr("Perceive bonds"));
action->setText(tr("Perceive Bonds"));
connect(action, SIGNAL(triggered()), SLOT(onPerceiveBonds()));
m_actions.push_back(action);

action = new QAction(this);
action->setEnabled(true);
action->setText(tr("Add hydrogens"));
action->setText(tr("Add Hydrogens"));
connect(action, SIGNAL(triggered()), SLOT(onAddHydrogens()));
m_actions.push_back(action);

action = new QAction(this);
action->setEnabled(true);
action->setText(tr("Add hydrogens for pH..."));
action->setText(tr("Add Hydrogens for pH..."));
connect(action, SIGNAL(triggered()), SLOT(onAddHydrogensPh()));
m_actions.push_back(action);

action = new QAction(this);
action->setEnabled(true);
action->setText(tr("Remove hydrogens"));
action->setText(tr("Remove Hydrogens"));
connect(action, SIGNAL(triggered()), SLOT(onRemoveHydrogens()));
m_actions.push_back(action);

Expand All @@ -99,9 +99,7 @@ OpenBabel::OpenBabel(QObject* p)
}
}

OpenBabel::~OpenBabel()
{
}
OpenBabel::~OpenBabel() {}

QList<QAction*> OpenBabel::actions() const
{
Expand All @@ -117,7 +115,7 @@ QList<Io::FileFormat*> OpenBabel::fileFormats() const
{
// Return empty list if not ready yet, and print a warning.
if (m_readFormatsPending || m_writeFormatsPending) {
qWarning() << tr("The obabel file formats are not ready to be added.");
qWarning() << tr("The Open Babel file formats are not ready to be added.");
return QList<Io::FileFormat*>();
}

Expand Down Expand Up @@ -208,7 +206,7 @@ bool OpenBabel::readMolecule(QtGui::Molecule& mol)
// Empty output means openbabel crashed, etc.
if (output.isEmpty()) {
QMessageBox::critical(qobject_cast<QWidget*>(parent()), tr("Error"),
tr("An error occurred while running OpenBabel "
tr("An error occurred while running Open Babel "
"(%1).")
.arg(m_process->obabelExecutable()),
QMessageBox::Ok);
Expand Down Expand Up @@ -355,7 +353,7 @@ void OpenBabel::onOptimizeGeometry()

// Fail here if the process is already in use
if (m_process->inUse()) {
showProcessInUseError(tr("Cannot optimize geometry with OpenBabel."));
showProcessInUseError(tr("Cannot optimize geometry with Open Babel."));
return;
}

Expand All @@ -380,7 +378,7 @@ void OpenBabel::onOptimizeGeometry()
}

// Setup progress dialog
initializeProgressDialog(tr("Optimizing Geometry (OpenBabel)"),
initializeProgressDialog(tr("Optimizing Geometry (Open Babel)"),
tr("Generating MDL..."), 0, 0, 0);

// Connect process
Expand All @@ -395,11 +393,11 @@ void OpenBabel::onOptimizeGeometry()

// Generate CML
std::string mol;
if (!Io::FileFormatManager::instance().writeString(*m_molecule, mol, "mol")) {
if (!Io::FileFormatManager::instance().writeString(*m_molecule, mol, "cml")) {
m_progress->reset();
QMessageBox::critical(qobject_cast<QWidget*>(parent()), tr("Error"),
tr("An internal error occurred while generating an "
"MDL representation of the current molecule."),
"CML representation of the current molecule."),
QMessageBox::Ok);
return;
}
Expand Down Expand Up @@ -444,10 +442,10 @@ void OpenBabel::onOptimizeGeometryFinished(const QByteArray& output)
// CML --> molecule
Core::Molecule mol;
if (!Io::FileFormatManager::instance().readString(mol, output.constData(),
"mol")) {
"cml")) {
m_progress->reset();
QMessageBox::critical(qobject_cast<QWidget*>(parent()), tr("Error"),
tr("Error interpreting obabel MDL output."),
tr("Error interpreting Open Babel output."),
QMessageBox::Ok);
qDebug() << "MDL:" << output;
return;
Expand Down Expand Up @@ -479,7 +477,7 @@ void OpenBabel::onPerceiveBonds()
{
// Fail here if the process is already in use
if (m_process->inUse()) {
showProcessInUseError(tr("Cannot open file with OpenBabel."));
showProcessInUseError(tr("Cannot open file with Open Babel."));
return;
}

Expand All @@ -491,7 +489,7 @@ void OpenBabel::onPerceiveBonds()
}

// Setup progress dialog
initializeProgressDialog(tr("Perceiving Bonds (OpenBabel)"),
initializeProgressDialog(tr("Perceiving Bonds (Open Babel)"),
tr("Generating XYZ representation..."), 0, 0, 0);

// Generate XYZ
Expand Down Expand Up @@ -576,15 +574,16 @@ void OpenBabel::onAddHydrogens()
}

// Setup progress dialog
initializeProgressDialog(tr("Adding Hydrogens (OpenBabel)"),
tr("Generating obabel input..."), 0, 0, 0);
initializeProgressDialog(tr("Adding Hydrogens (Open Babel)"),
tr("Generating Open Babel input..."), 0, 0, 0);

// Generate MDL
std::string mol;
if (!Io::FileFormatManager::instance().writeString(*m_molecule, mol, "mol")) {
if (!Io::FileFormatManager::instance().writeString(*m_molecule, mol, "cml")) {
m_progress->reset();
QMessageBox::critical(qobject_cast<QWidget*>(parent()), tr("Error"),
tr("Error generating MDL string."), QMessageBox::Ok);
tr("Error generating Open Babel input."),
QMessageBox::Ok);
return;
}

Expand All @@ -599,7 +598,7 @@ void OpenBabel::onAddHydrogens()
tr("Running %1...").arg(m_process->obabelExecutable()));

// Run process
m_process->convert(QByteArray(mol.c_str(), mol.size()), "mol", "mol",
m_process->convert(QByteArray(mol.c_str(), mol.size()), "cml", "cml",
QStringList() << "-h");
}

Expand All @@ -623,15 +622,16 @@ void OpenBabel::onAddHydrogensPh()
return;

// Setup progress dialog
initializeProgressDialog(tr("Adding Hydrogens (OpenBabel)"),
initializeProgressDialog(tr("Adding Hydrogens (Open Babel)"),
tr("Generating obabel input..."), 0, 0, 0);

// Generate MDL
std::string mol;
if (!Io::FileFormatManager::instance().writeString(*m_molecule, mol, "mol")) {
if (!Io::FileFormatManager::instance().writeString(*m_molecule, mol, "cml")) {
m_progress->reset();
QMessageBox::critical(qobject_cast<QWidget*>(parent()), tr("Error"),
tr("Error generating MDL string."), QMessageBox::Ok);
tr("Error generating Open Babel input."),
QMessageBox::Ok);
return;
}

Expand All @@ -646,7 +646,7 @@ void OpenBabel::onAddHydrogensPh()
tr("Running %1...").arg(m_process->obabelExecutable()));

// Run process
m_process->convert(QByteArray(mol.c_str(), mol.size()), "mol", "mol",
m_process->convert(QByteArray(mol.c_str(), mol.size()), "cml", "cml",
QStringList() << "-p" << QString::number(pH));
}

Expand All @@ -662,15 +662,15 @@ void OpenBabel::onRemoveHydrogens()
}

// Setup progress dialog
initializeProgressDialog(tr("Removing Hydrogens (OpenBabel)"),
initializeProgressDialog(tr("Removing Hydrogens (Open Babel)"),
tr("Generating obabel input..."), 0, 0, 0);

// Generate MDL
std::string mol;
if (!Io::FileFormatManager::instance().writeString(*m_molecule, mol, "mol")) {
if (!Io::FileFormatManager::instance().writeString(*m_molecule, mol, "cml")) {
m_progress->reset();
QMessageBox::critical(qobject_cast<QWidget*>(parent()), tr("Error"),
tr("Error generating MDL string."), QMessageBox::Ok);
tr("Error generating CML data."), QMessageBox::Ok);
return;
}

Expand All @@ -685,7 +685,7 @@ void OpenBabel::onRemoveHydrogens()
tr("Running %1...").arg(m_process->obabelExecutable()));

// Run process
m_process->convert(QByteArray(mol.c_str(), mol.size()), "mol", "mol",
m_process->convert(QByteArray(mol.c_str(), mol.size()), "cml", "cml",
QStringList() << "-d");
}

Expand All @@ -696,11 +696,11 @@ void OpenBabel::onHydrogenOperationFinished(const QByteArray& mdl)
// MDL --> molecule
Core::Molecule mol;
if (!Io::FileFormatManager::instance().readString(mol, mdl.constData(),
"mol")) {
"cml")) {
m_progress->reset();
qWarning() << "Bad MDL: " << mdl;
QMessageBox::critical(qobject_cast<QWidget*>(parent()), tr("Error"),
tr("Error interpreting obabel MDL output."),
tr("Error interpreting Open Babel output."),
QMessageBox::Ok);
qDebug() << "MDL:" << mdl;
return;
Expand Down Expand Up @@ -754,7 +754,7 @@ void OpenBabel::initializeProgressDialog(const QString& title,
void OpenBabel::showProcessInUseError(const QString& title) const
{
QMessageBox::critical(qobject_cast<QWidget*>(parent()), title,
tr("Already running OpenBabel. Wait for the other "
tr("Already running Open Babel. Wait for the other "
"operation to complete and try again."),
QMessageBox::Ok);
}
Expand Down Expand Up @@ -803,5 +803,5 @@ QString OpenBabel::autoDetectForceField() const

return result;
}
}
}
} // namespace QtPlugins
} // namespace Avogadro