Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Update the Open Babel API in Avogadro #886

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
11 changes: 7 additions & 4 deletions avogadro/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include <avogadro/color.h>

#include <openbabel/obconversion.h>
#include <openbabel/elements.h>
#include <openbabel/mol.h>
#include <openbabel/builder.h>
#include <openbabel/forcefield.h>
Expand Down Expand Up @@ -1999,7 +2000,7 @@ class XMLEventSource : public pqEventSource

int GetAtomicNum(string name, int &iso)
{
int n = OpenBabel::etab.GetAtomicNum(name.c_str(), iso);
int n = OpenBabel::OBElements::GetAtomicNum(name.c_str());
if (iso != 0)
return 0; // "D" ot "T"
if (n != 0)
Expand All @@ -2012,8 +2013,10 @@ class XMLEventSource : public pqEventSource
if (name == (*i)->GetSymbol())
return((*i)->GetAtomicNum());*/

for (unsigned int i=0; i<etab.GetNumberOfElements(); i++)
if (!QString::compare(name.c_str(), etab.GetName(i).c_str(), Qt::CaseInsensitive))
// 118 elements right now in Open Babel. We can change in the future if
// needed
for (unsigned int i=0; i < 118; i++)
if (!QString::compare(name.c_str(), OBElements::GetName(i), Qt::CaseInsensitive))
return i;

if (!QString::compare(name.c_str(), "Deuterium", Qt::CaseInsensitive))
Expand Down Expand Up @@ -2271,7 +2274,7 @@ class XMLEventSource : public pqEventSource
QStringList ids;
for (QList<Atom*>::const_iterator it = atoms.constBegin(),
it_end = atoms.constEnd(); it != it_end; ++it) {
ids << OpenBabel::etab.GetSymbol((*it)->atomicNumber());
ids << OpenBabel::OBElements::GetSymbol((*it)->atomicNumber());
}

// Fractional coordinates
Expand Down
3 changes: 2 additions & 1 deletion avogadro/src/primitiveitemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <avogadro/molecule.h>
#include <avogadro/engine.h>

#include <openbabel/elements.h>
#include <openbabel/mol.h>

namespace Avogadro {
Expand Down Expand Up @@ -263,7 +264,7 @@ namespace Avogadro {
}
else if(type == Primitive::AtomType) {
Atom *atom = static_cast<Atom*>(primitive);
str = QString(OpenBabel::etab.GetSymbol(atom->atomicNumber())) + ' '
str = QString(OpenBabel::OBElements::GetSymbol(atom->atomicNumber())) + ' '
+ QString::number(atom->index()+1);
}
else if(type == Primitive::BondType){
Expand Down
39 changes: 20 additions & 19 deletions avogadro/src/projectdelegates/atomdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <avogadro/molecule.h>
#include <avogadro/atom.h>

#include <openbabel/elements.h>
#include <openbabel/mol.h>

#include <QDebug>
Expand All @@ -39,11 +40,11 @@ namespace Avogadro
AtomDelegate::AtomDelegate(ProjectTreeModel *model) : ProjectTreeModelDelegate(model), m_label(0), m_widget(0)
{
}

AtomDelegate::~AtomDelegate()
{
}

void AtomDelegate::initStructure(GLWidget *widget, ProjectTreeItem *parent)
{
// save the widget
Expand All @@ -58,7 +59,7 @@ namespace Avogadro
{
// the user has expanded our label, we now initialize the bond items
// and keep track of the using the signals...

Molecule *molecule = m_widget->molecule();
disconnect(molecule, 0, this, 0);
// connect some signals to keep track of changes
Expand All @@ -77,11 +78,11 @@ namespace Avogadro
if (m_label->childCount())
model()->removeRows(m_label, 0, m_label->childCount());

// add the atoms...
// add the atoms...
model()->insertRows(m_label, 0, molecule->numAtoms());
for (int i = 0; i < m_label->childCount(); ++i) {
ProjectTreeItem *item = m_label->child(i);
item->setData(0, QString(OpenBabel::etab.GetSymbol(molecule->atom(i)->atomicNumber())));
item->setData(0, QString(OpenBabel::OBElements::GetSymbol(molecule->atom(i)->atomicNumber())));
item->setData(1, QString("%1").arg(i));
// set the primitive
PrimitiveList primitives;
Expand All @@ -90,45 +91,45 @@ namespace Avogadro
}

}

void AtomDelegate::primitiveAdded(Primitive *primitive)
{
if (primitive->type() != Primitive::AtomType)
return;

Atom *atom = static_cast<Atom*>(primitive);

// add the new primitive to the end
model()->insertRows(m_label, m_label->childCount(), 1);
ProjectTreeItem *item = m_label->child(m_label->childCount() - 1);
item->setData(0, QString(OpenBabel::etab.GetSymbol(atom->atomicNumber())));
item->setData(1, QString("%1").arg(primitive->index()));
item->setData(0, QString(OpenBabel::OBElements::GetSymbol(atom->atomicNumber())));
item->setData(1, QString("%1").arg(primitive->index()));
// set the primitive
PrimitiveList primitives;
primitives.append(primitive);
item->setPrimitives(primitives);
}

void AtomDelegate::primitiveUpdated(Primitive *primitive)
{
if (primitive->type() == Primitive::MoleculeType) {
initialize();
return;
}

if (primitive->type() != Primitive::AtomType)
if (primitive->type() != Primitive::AtomType)
return;

Atom *atom = static_cast<Atom*>(primitive);

ProjectTreeItem *item = m_label->child(primitive->index());
item->setData(0, QString(OpenBabel::etab.GetSymbol(atom->atomicNumber())));
item->setData(1, QString("%1").arg(primitive->index()));
item->setData(0, QString(OpenBabel::OBElements::GetSymbol(atom->atomicNumber())));
item->setData(1, QString("%1").arg(primitive->index()));


model()->emitDataChanged(m_label, primitive->index());
}

void AtomDelegate::primitiveRemoved(Primitive *primitive)
{
if (primitive->type() != Primitive::AtomType)
Expand All @@ -145,12 +146,12 @@ namespace Avogadro
}
}
}

void AtomDelegate::writeSettings(QSettings &settings) const
{
ProjectTreeModelDelegate::writeSettings(settings);
}

void AtomDelegate::readSettings(QSettings &settings)
{
ProjectTreeModelDelegate::readSettings(settings);
Expand Down
10 changes: 6 additions & 4 deletions libavogadro/src/colors/elementcolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <avogadro/atom.h>
#include <QtPlugin>

#include <openbabel/elements.h>
#include <openbabel/mol.h>

namespace Avogadro {
Expand All @@ -48,10 +49,11 @@ namespace Avogadro {
const Atom *atom = static_cast<const Atom*>(p);

if (atom->atomicNumber()) {
std::vector<double> rgb = OpenBabel::etab.GetRGB(atom->atomicNumber());
m_channels[0] = rgb[0];
m_channels[1] = rgb[1];
m_channels[2] = rgb[2];
double r, g, b;
OpenBabel::OBElements::GetRGB(atom->atomicNumber(), &r, &g, &b);
m_channels[0] = r;
m_channels[1] = g;
m_channels[2] = b;
} else {
m_channels[0] = 0.2;
m_channels[1] = 0.2;
Expand Down
16 changes: 9 additions & 7 deletions libavogadro/src/colors/residuecolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <avogadro/residue.h>
#include <avogadro/atom.h>

#include <openbabel/elements.h>
#include <openbabel/mol.h>
#include <openbabel/atom.h>
#include <openbabel/residue.h>
Expand Down Expand Up @@ -169,20 +170,21 @@ namespace Avogadro {
residue = atom->residue();

// default is to color by element if no residue is specified
std::vector<double> rgb = OpenBabel::etab.GetRGB( atom->atomicNumber() );
double r, g, b;
OpenBabel::OBElements::GetRGB(atom->atomicNumber(), &r, &g, &b);

if (!residue) {
m_channels[0] = rgb[0];
m_channels[1] = rgb[1];
m_channels[2] = rgb[2];
m_channels[0] = r;
m_channels[1] = g;
m_channels[2] = b;
m_channels[3] = 1.0;
return;
}
residueName = residue->name();
if (residueName.compare("UNK", Qt::CaseInsensitive) == 0) {
m_channels[0] = rgb[0];
m_channels[1] = rgb[1];
m_channels[2] = rgb[2];
m_channels[0] = r;
m_channels[1] = g;
m_channels[2] = b;
m_channels[3] = 1.0;
return;
}
Expand Down
12 changes: 7 additions & 5 deletions libavogadro/src/colors/smartscolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <avogadro/atom.h>
#include <avogadro/colorbutton.h>

#include <openbabel/elements.h>
#include <openbabel/mol.h>
#include <openbabel/atom.h>
#include <openbabel/parsmart.h>
Expand All @@ -45,14 +46,14 @@ namespace Avogadro {

/// Constructor
SmartsColor::SmartsColor() : _highlightColor(255, 0, 128), _settingsWidget(NULL)
{
{
_pattern = new OBSmartsPattern;
_smartsString.clear();
}

/// Destructor
SmartsColor::~SmartsColor()
{
{
if (_pattern) {
delete _pattern;
_pattern = NULL;
Expand Down Expand Up @@ -132,8 +133,9 @@ namespace Avogadro {
// Start with the default "element color"
QColor newcolor;
if (atom->atomicNumber()) {
std::vector<double> rgb = OpenBabel::etab.GetRGB(atom->atomicNumber());
newcolor.setRgbF(rgb[0], rgb[1], rgb[2]);
double r, g, b;
OpenBabel::OBElements::GetRGB(atom->atomicNumber(), &r, &g, &b);
newcolor.setRgbF(r, g, b);
} else {
newcolor.setRgbF(0.2f, 0.2f, 0.2f);
}
Expand All @@ -160,7 +162,7 @@ namespace Avogadro {
if (matched)
break; // no need to check other matches
} // matches

} // matched molecule
} // finite, valid SMARTS

Expand Down
10 changes: 6 additions & 4 deletions libavogadro/src/elementdetail_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "elementdetail_p.h"
#include "elementtranslator.h"

#include <openbabel/elements.h>
#include <openbabel/mol.h>

#include <QGraphicsSceneMouseEvent>
Expand Down Expand Up @@ -65,13 +66,14 @@ namespace Avogadro{
QFontMetrics fm(font);
int pixelHeight = fm.height();

QString symbol = OpenBabel::etab.GetSymbol(m_element);
QString symbol = OpenBabel::OBElements::GetSymbol(m_element);
QString name(ElementTranslator::name(m_element));
QString mass = QString("%L1").arg(OpenBabel::etab.GetMass(m_element), 0, 'f', 3);
QString mass = QString("%L1").arg(OpenBabel::OBElements::GetMass(m_element), 0, 'f', 3);

std::vector<double> color = OpenBabel::etab.GetRGB(m_element);
double r, g, b;
OpenBabel::OBElements::GetRGB(m_element, &r, &g, &b);
QColor m_color;
m_color.setRgbF(color[0], color[1], color[2]);
m_color.setRgbF(r, g, b);

// Draw the element detail border and fill with the element colour
painter->setBrush(m_color);
Expand Down
8 changes: 5 additions & 3 deletions libavogadro/src/elementitem_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "elementitem_p.h"
#include "elementtranslator.h"

#include <openbabel/elements.h>
#include <openbabel/mol.h>

#include <QGraphicsSceneMouseEvent>
Expand All @@ -45,12 +46,13 @@ namespace Avogadro{
// Want these items to be selectable
setFlags(QGraphicsItem::ItemIsSelectable);

m_symbol = OpenBabel::etab.GetSymbol(m_element);
m_symbol = OpenBabel::OBElements::GetSymbol(m_element);
if(!m_symbol.isEmpty())
m_valid = true;
std::vector<double> color = OpenBabel::etab.GetRGB(m_element);
double r, g, b;
OpenBabel::OBElements::GetRGB(m_element, &r, &g, &b);
m_color = new QColor();
m_color->setRgbF(color[0], color[1], color[2]);
m_color->setRgbF(r, g, b);
// Set some custom data to make it easy to figure out which element we are
setData(0, m_element);
}
Expand Down
5 changes: 3 additions & 2 deletions libavogadro/src/engines/bsdyengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <QGLWidget> // for OpenGL bits
#include <QDebug>

#include <openbabel/elements.h>
#include <openbabel/mol.h>

using namespace std;
Expand Down Expand Up @@ -91,12 +92,12 @@ namespace Avogadro
{
double radiusCovalent(const Atom *atom)
{
return OpenBabel::etab.GetCovalentRad(atom->atomicNumber());
return OpenBabel::OBElements::GetCovalentRad(atom->atomicNumber());
}

double radiusVdW(const Atom *atom)
{
return OpenBabel::etab.GetVdwRad(atom->atomicNumber());
return OpenBabel::OBElements::GetVdwRad(atom->atomicNumber());
}
} // End of anonymous namespace

Expand Down
11 changes: 6 additions & 5 deletions libavogadro/src/engines/labelengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <QtGui/QFontDialog>
//#include <QtGui/QPainter>

#include <openbabel/elements.h>
#include <openbabel/mol.h>

using namespace std;
Expand Down Expand Up @@ -134,19 +135,19 @@ namespace Avogadro {
str = QString("%L1").arg(a->index() + 1);
break;
case 2: // Element Symbol
str = QString(OpenBabel::etab.GetSymbol(a->atomicNumber()));
str = QString(OpenBabel::OBElements::GetSymbol(a->atomicNumber()));
break;
case 3: // Symbol & Number in Group
gi = a->groupIndex();
if (gi != 0) {
str = QString(OpenBabel::etab.GetSymbol(a->atomicNumber())) + QString("%L1").arg(gi);
str = QString(OpenBabel::OBElements::GetSymbol(a->atomicNumber())) + QString("%L1").arg(gi);
}
else {
str = QString(OpenBabel::etab.GetSymbol(a->atomicNumber()));
str = QString(OpenBabel::OBElements::GetSymbol(a->atomicNumber()));
}
break;
case 4: // Symbol & Atom Number
str = QString(OpenBabel::etab.GetSymbol(a->atomicNumber())) + QString("%L1").arg(a->index() + 1);
str = QString(OpenBabel::OBElements::GetSymbol(a->atomicNumber())) + QString("%L1").arg(a->index() + 1);
break;
case 5: // Formal charge
if (a->formalCharge())
Expand Down Expand Up @@ -174,7 +175,7 @@ namespace Avogadro {
QList<QByteArray> propertyNames = a->dynamicPropertyNames();
// If this is a strange offset, use the element symbol
if ( customIndex < 0 || customIndex >= propertyNames.size())
str = QString(OpenBabel::etab.GetSymbol(a->atomicNumber()));
str = QString(OpenBabel::OBElements::GetSymbol(a->atomicNumber()));
else
str = a->property(propertyNames[customIndex].data()).toString();
}
Expand Down
Loading