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

Port IQmol to OpenBabel 3 #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 5 additions & 9 deletions src/Configurator/IsotopesConfigurator.C
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "IsotopesConfigurator.h"
#include "IsotopesLayer.h"
#include "openbabel/data.h"
#include "openbabel/elements.h"
#include "AtomLayer.h"
#include <QComboBox>
#include <QSpinBox>
Expand Down Expand Up @@ -75,14 +76,13 @@ void Isotopes::loadTable(QList<Layer::Atom*> const& atoms)
QTableWidgetItem* index;
QComboBox* combo;

OpenBabel::OBElementTable pt;
unsigned n(atomicNumbers.size());
table->setRowCount(n);

for (unsigned i = 0; i < n; ++i) {
unsigned Z(atomicNumbers[i]);
combo = new QComboBox(table);
name = new QTableWidgetItem(QString::fromStdString(pt.GetName(Z)));
name = new QTableWidgetItem(QString::fromStdString(OpenBabel::OBElements::GetName(Z)));
index = new QTableWidgetItem(indices[Z]);
table->setItem( i, 0, name);
table->setCellWidget(i, 1, combo);
Expand All @@ -94,12 +94,8 @@ void Isotopes::loadTable(QList<Layer::Atom*> const& atoms)

void Isotopes::loadMasses(unsigned Z, QComboBox* combo)
{
OpenBabel::OBElementTable pt;
OpenBabel::OBIsotopeTable it;


QList<unsigned> isotopes;
QString symbol(pt.GetSymbol(Z));
QString symbol(OpenBabel::OBElements::GetSymbol(Z));

// The isotopes are ordered by abundance
switch(Z) {
Expand Down Expand Up @@ -150,12 +146,12 @@ void Isotopes::loadMasses(unsigned Z, QComboBox* combo)
}

combo->clear();
double m(pt.GetMass(Z));
double m(OpenBabel::OBElements::GetMass(Z));
combo->addItem(symbol + "(std)", m);

for (int i = 0; i < isotopes.size(); ++i) {
QString label(symbol + "(" + QString::number(isotopes[i]) + ")");
double m(it.GetExactMass(Z,isotopes[i]));
double m(OpenBabel::OBElements::GetExactMass(Z,isotopes[i]));
combo->addItem(label, m);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Configurator/SurfaceConfigurator.C
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include "SurfaceConfigurator.h"
#include "SurfaceLayer.h"
#include "MoleculeLayer.h"
#include <openbabel/mol.h> // for etab
#include <openbabel/mol.h>
#include <openbabel/elements.h>
#include <QColorDialog>


Expand Down Expand Up @@ -228,7 +229,8 @@ ColorGradient::ColorList Surface::atomColorGradient(unsigned const maxAtomicNumb
ColorGradient::ColorList atomColors;
QColor color;
for (unsigned int Z = 1; Z <= maxAtomicNumber; ++Z) {
std::vector<double> rgb(OpenBabel::etab.GetRGB(Z));
std::vector<double> rgb(3);
OpenBabel::OBElements::GetRGB(Z,&rgb[0],&rgb[1],&rgb[2]);
color.setRgbF(rgb[0],rgb[1],rgb[2],1.0);
atomColors.append(color);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Data/Atom.C
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Atom.h"
#include "AtomicProperty.h"
#include <openbabel/mol.h>
#include <openbabel/elements.h>
#include <QDebug>


Expand All @@ -34,7 +35,7 @@ template<> const Type::ID AtomList::TypeID = Type::AtomList;

unsigned Atom::atomicNumber(QString const& symbol)
{
unsigned z(OpenBabel::etab.GetAtomicNum(symbol.toLatin1().data()));
unsigned z(OpenBabel::OBElements::GetAtomicNum(symbol.toLatin1().data()));
return z;
}

Expand Down
12 changes: 5 additions & 7 deletions src/Data/AtomicProperty.C
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "AtomicProperty.h"
#include <openbabel/mol.h>
#include <openbabel/elements.h>
#include <vector>
#include <QDebug>

Expand All @@ -32,7 +33,7 @@ namespace Data {
// ---------- AtomicSymbol ----------
void AtomicSymbol::setDefault(int const Z)
{
if (Z > 0) m_symbol = QString(OpenBabel::etab.GetSymbol(Z));
if (Z > 0) m_symbol = QString(OpenBabel::OBElements::GetSymbol(Z));
}


Expand All @@ -54,15 +55,15 @@ void ScalarProperty::dump() const
// ---------- Mass ----------
void Mass::setDefault(int const Z)
{
if (Z > 0) m_value = OpenBabel::etab.GetMass(Z);
if (Z > 0) m_value = OpenBabel::OBElements::GetMass(Z);
}



// ---------- VdwRadius ----------
void VdwRadius::setDefault(int const Z)
{
if (Z > 0) m_value = OpenBabel::etab.GetVdwRad(Z);
if (Z > 0) m_value = OpenBabel::OBElements::GetVdwRad(Z);
}


Expand All @@ -71,10 +72,7 @@ void VdwRadius::setDefault(int const Z)
void AtomColor::setDefault(int const Z)
{
if (Z > 0) {
std::vector<double> rgb(OpenBabel::etab.GetRGB(Z));
m_color[0] = rgb[0];
m_color[1] = rgb[1];
m_color[2] = rgb[2];
OpenBabel::OBElements::GetRGB(Z, &m_color[0], &m_color[1], &m_color[2]);
m_color[3] = 1.0;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Data/EfpFragment.C
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "EulerAngles.h"
#include "Align.h"
#include "openbabel/mol.h"
#include "openbabel/elements.h"
#include <QDebug>


Expand Down Expand Up @@ -58,7 +59,7 @@ bool EfpFragment::align(QList<Vec> const& coordinates)

QList<double> weights;
for (unsigned i = 0; i < geometry.nAtoms(); ++i) {
weights.append(OpenBabel::etab.GetMass(geometry.atomicNumber(i)));
weights.append(OpenBabel::OBElements::GetMass(geometry.atomicNumber(i)));
}

Util::Align align(geometry.coordinates(), coordinates, weights);
Expand Down
4 changes: 3 additions & 1 deletion src/Data/Geometry.C
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "QsLog.h"
#include <QDebug>
#include "openbabel/mol.h"
#include "openbabel/atom.h"
#include "openbabel/obiter.h"


namespace IQmol {
Expand Down Expand Up @@ -258,7 +260,7 @@ return;
OpenBabel::OBMol obMol;

obMol.BeginModify();
obMol.UnsetPartialChargesPerceived();
obMol.SetPartialChargesPerceived(false);
for (int i = 0; i < m_atoms.size(); ++i) {
obAtom = obMol.NewAtom();
obAtom->SetAtomicNum(m_atoms[i]->atomicNumber());
Expand Down
14 changes: 8 additions & 6 deletions src/Layer/AtomLayer.C
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "GLShape.h"
#include <openbabel/mol.h>
#include <openbabel/data.h>
#include <openbabel/elements.h>
#include <QColor>
#include <QMenu>
#include <vector>
Expand Down Expand Up @@ -147,20 +148,21 @@ void Atom::updateHybridization()

void Atom::resetMass()
{
m_mass = OpenBabel::etab.GetMass(m_atomicNumber);
m_mass = OpenBabel::OBElements::GetMass(m_atomicNumber);
}


void Atom::setAtomicNumber(unsigned int const Z)
{
m_atomicNumber = Z;
m_vdwRadius = OpenBabel::etab.GetVdwRad(Z);
m_mass = OpenBabel::etab.GetMass(Z);
m_symbol = QString(OpenBabel::etab.GetSymbol(Z));
m_valency = OpenBabel::etab.GetMaxBonds(Z);
m_vdwRadius = OpenBabel::OBElements::GetVdwRad(Z);
m_mass = OpenBabel::OBElements::GetMass(Z);
m_symbol = QString(OpenBabel::OBElements::GetSymbol(Z));
m_valency = OpenBabel::OBElements::GetMaxBonds(Z);
setText(m_symbol);

std::vector<double> rgb(OpenBabel::etab.GetRGB(Z));
std::vector<double> rgb(3);
OpenBabel::OBElements::GetRGB(Z,&rgb[0],&rgb[1],&rgb[2]);
m_color[0] = rgb[0];
m_color[1] = rgb[1];
m_color[2] = rgb[2];
Expand Down
3 changes: 3 additions & 0 deletions src/Layer/LayerFactory.C
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
#include "RemLayer.h"
#include "QsLog.h"
#include "openbabel/mol.h"
#include "openbabel/atom.h"
#include "openbabel/bond.h"
#include "openbabel/obiter.h"

#include <typeinfo> // for std::bad_cast

Expand Down
10 changes: 7 additions & 3 deletions src/Layer/MoleculeLayer.C
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@
#include "IQmolParser.h"

#include "openbabel/mol.h"
#include "openbabel/atom.h"
#include "openbabel/bond.h"
#include "openbabel/typer.h"
#include "openbabel/format.h"
#include "openbabel/obconversion.h"
#include "openbabel/generic.h"
#include "openbabel/forcefield.h"
#include "openbabel/plugin.h"
#include "openbabel/obiter.h"

#include <QFileDialog>
#include <QDropEvent>
Expand Down Expand Up @@ -516,7 +520,7 @@ OBMol* Molecule::toOBMol(AtomMap* atomMap, BondMap* bondMap, GroupMap* groupMap)
AtomList::iterator atomIter;

obMol->BeginModify();
obMol->SetImplicitValencePerceived();
//obMol->SetImplicitValencePerceived(); // FIXME: this function doesn't appear to exist in OpenBabel3?
obMol->SetHybridizationPerceived();

for (atomIter = atoms.begin(); atomIter != atoms.end(); ++atomIter) {
Expand Down Expand Up @@ -1803,14 +1807,14 @@ void Molecule::addHydrogens()
// We now type the atoms and overwrite the valency/hybridization info
// if it has been changed by the user.
OBAtomTyper atomTyper;
atomTyper.AssignImplicitValence(*obMol);
// atomTyper.AssignImplicitValence(*obMol); // FIXME: this function doesn't appear to exist in OpenBabel3?
atomTyper.AssignHyb(*obMol);

AtomMap::iterator iter;
for (iter = atomMap.begin(); iter != atomMap.end(); ++iter) {
int hybrid(iter.value()->getHybridization());
if (hybrid > 0) {
iter.key()->SetImplicitValence(iter.value()->getValency());
// iter.key()->SetImplicitValence(iter.value()->getValency()); // FIXME: this function doesn't appear to exist in OpenBabel3?
iter.key()->SetHyb(hybrid);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Layer/PrimitiveLayer.C
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "Geometry.h"
#include "openbabel/obiter.h"
#include "openbabel/mol.h"
#include "openbabel/atom.h"
#include "openbabel/bond.h"

#define _USE_MATH_DEFINES
#include <cmath>
Expand Down
4 changes: 2 additions & 2 deletions src/Main/PeriodicTable.C
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void PeriodicTable::connectSignals() {
name.remove(QRegExp("element_"));
atomicNumber = name.toUInt(&ok);
if (ok) {
name = QString(OpenBabel::etab.GetName(atomicNumber).c_str());
name = QString(OpenBabel::OBElements::GetName(atomicNumber));
(*iter)->setToolTip(QString::number(atomicNumber) + " " + name);
}
}
Expand All @@ -75,7 +75,7 @@ void PeriodicTable::buttonPushed() {
int atomicNumber = name.toUInt(&ok);
if (ok) {
elementSelected(atomicNumber);
elementSelected(QString(OpenBabel::etab.GetSymbol(atomicNumber)));
elementSelected(QString(OpenBabel::OBElements::GetSymbol(atomicNumber)));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Old/AtomicDensity.C
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "Constants.h"
#include "AtomicDensity.h"
#include "AtomicDensityData.h"
#include <openbabel/mol.h> // for OpenBabel::etab
#include <openbabel/elements.h>
#include <cmath>


Expand Down Expand Up @@ -168,7 +168,7 @@ unsigned VanDerWaals::s_indices[20][3] = {
VanDerWaals::VanDerWaals(unsigned atomicNumber, Vec const& center, double const scale,
double const solventRadius) : Base(atomicNumber), m_center(center)
{
m_radius = scale*OpenBabel::etab.GetVdwRad(atomicNumber)+solventRadius;
m_radius = scale*OpenBabel::OBElements::GetVdwRad(atomicNumber)+solventRadius;
}


Expand Down
2 changes: 1 addition & 1 deletion src/Parser/OpenBabelParser.C
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "openbabel/forcefield.h"
#include "openbabel/griddata.h"
#include "openbabel/math/vector3.h"

#include "openbabel/obiter.h"


namespace IQmol {
Expand Down
2 changes: 2 additions & 0 deletions src/Parser/ZMatrixCoordinatesParser.C
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "openbabel/obconversion.h"
#include "openbabel/format.h"
#include "openbabel/mol.h"
#include "openbabel/obiter.h"
#include "openbabel/atom.h"

#include <QDebug>

Expand Down
Loading