From 2fb8dea9d1ace5b1fc1ddcf0f7034cf119763b53 Mon Sep 17 00:00:00 2001 From: Andrius Merkys Date: Wed, 8 Jan 2020 11:47:58 +0200 Subject: [PATCH] Migrating xdrawchem to Open Babel 3. --- xdrawchem-qt5/xdrawchem.pro | 4 ++-- xdrawchem-qt5/xdrawchem/ioiface.cpp | 8 ++++---- xdrawchem-qt5/xdrawchem/ioiface.h | 3 +++ xdrawchem-qt5/xdrawchem/molecule.h | 4 ++++ xdrawchem-qt5/xdrawchem/molecule_obmol.cpp | 10 +++++----- xdrawchem-qt5/xdrawchem/molecule_smiles.cpp | 8 +++----- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/xdrawchem-qt5/xdrawchem.pro b/xdrawchem-qt5/xdrawchem.pro index e8e1886..2b4e2a2 100644 --- a/xdrawchem-qt5/xdrawchem.pro +++ b/xdrawchem-qt5/xdrawchem.pro @@ -2,8 +2,8 @@ TEMPLATE = app TARGET = xdrawchem # edit to match your OB install -exists(/usr/include/openbabel-2.0/openbabel/mol.h) { -INCLUDEPATH += /usr/include/openbabel-2.0 +exists(/usr/include/openbabel3/openbabel/mol.h) { +INCLUDEPATH += /usr/include/openbabel3 LIBS += -lopenbabel } exists(/usr/local/include/openbabel-2.0/openbabel/mol.h) { diff --git a/xdrawchem-qt5/xdrawchem/ioiface.cpp b/xdrawchem-qt5/xdrawchem/ioiface.cpp index acba119..5123970 100644 --- a/xdrawchem-qt5/xdrawchem/ioiface.cpp +++ b/xdrawchem-qt5/xdrawchem/ioiface.cpp @@ -193,7 +193,7 @@ void IOIface::convertToChemData() int bondorder = bond->GetBondOrder(); //set elements - if ( !atom1->IsCarbon() ) { + if ( atom1->GetAtomicNum() != 6 ) { QString str( "" ); str += IOIface::symbol[atom1->GetAtomicNum() - 1]; str += ""; @@ -201,7 +201,7 @@ void IOIface::convertToChemData() } - if ( !atom2->IsCarbon() ) { + if ( atom2->GetAtomicNum() != 6 ) { QString str( "" ); str += IOIface::symbol[atom2->GetAtomicNum() - 1]; @@ -216,7 +216,7 @@ void IOIface::convertToChemData() //label atoms if not Carbon - if ( !atom1->IsCarbon() ) { + if ( atom1->GetAtomicNum() != 6 ) { text = new Text( chemdata->getRender2D() ); QString str = IOIface::symbol[atom1->GetAtomicNum() - 1]; @@ -229,7 +229,7 @@ void IOIface::convertToChemData() //qDebug() << "ioiface(1) text:" << str; } - if ( !atom2->IsCarbon() ) { + if ( atom2->GetAtomicNum() != 6 ) { text = new Text( chemdata->getRender2D() ); QString str = IOIface::symbol[atom2->GetAtomicNum() - 1]; diff --git a/xdrawchem-qt5/xdrawchem/ioiface.h b/xdrawchem-qt5/xdrawchem/ioiface.h index 9db30f8..dd671da 100644 --- a/xdrawchem-qt5/xdrawchem/ioiface.h +++ b/xdrawchem-qt5/xdrawchem/ioiface.h @@ -20,6 +20,9 @@ #include "chemdata.h" +#include +#include +#include #include using namespace OpenBabel; diff --git a/xdrawchem-qt5/xdrawchem/molecule.h b/xdrawchem-qt5/xdrawchem/molecule.h index f11cb73..cf57096 100644 --- a/xdrawchem-qt5/xdrawchem/molecule.h +++ b/xdrawchem-qt5/xdrawchem/molecule.h @@ -3,6 +3,10 @@ #ifndef MOLECULE_H #define MOLECULE_H +#include +#include +#include +#include #include #include diff --git a/xdrawchem-qt5/xdrawchem/molecule_obmol.cpp b/xdrawchem-qt5/xdrawchem/molecule_obmol.cpp index b48d860..50dd949 100644 --- a/xdrawchem-qt5/xdrawchem/molecule_obmol.cpp +++ b/xdrawchem-qt5/xdrawchem/molecule_obmol.cpp @@ -58,7 +58,7 @@ bool Molecule::convertFromOBMol( OBMol * obmol ) Point point; Text *text; - std::vector < OBEdgeBase * >::iterator bonditr; + std::vector < OBBond * >::iterator bonditr; std::map < Point, DPoint *, pt_cmp > points; std::map < Point, DPoint *, pt_cmp >::iterator itr; @@ -133,7 +133,7 @@ bool Molecule::convertFromOBMol( OBMol * obmol ) int bondorder = bond->GetBondOrder(); //set elements - if ( !atom1->IsCarbon() ) { + if ( atom1->GetAtomicNum() != 6 ) { QString str( "" ); str += symbol[atom1->GetAtomicNum() - 1]; @@ -142,7 +142,7 @@ bool Molecule::convertFromOBMol( OBMol * obmol ) } - if ( !atom2->IsCarbon() ) { + if ( atom2->GetAtomicNum() != 6 ) { QString str( "" ); str += symbol[atom2->GetAtomicNum() - 1]; @@ -155,7 +155,7 @@ bool Molecule::convertFromOBMol( OBMol * obmol ) //label atoms if not Carbon - if ( !atom1->IsCarbon() ) { + if ( atom1->GetAtomicNum() != 6 ) { text = new Text( r ); QString str = symbol[atom1->GetAtomicNum() - 1]; @@ -167,7 +167,7 @@ bool Molecule::convertFromOBMol( OBMol * obmol ) addText( text ); } - if ( !atom2->IsCarbon() ) { + if ( atom2->GetAtomicNum() != 6 ) { text = new Text( r ); QString str = symbol[atom2->GetAtomicNum() - 1]; diff --git a/xdrawchem-qt5/xdrawchem/molecule_smiles.cpp b/xdrawchem-qt5/xdrawchem/molecule_smiles.cpp index 5d7c8b3..4bf9fbb 100644 --- a/xdrawchem-qt5/xdrawchem/molecule_smiles.cpp +++ b/xdrawchem-qt5/xdrawchem/molecule_smiles.cpp @@ -254,8 +254,6 @@ void Molecule::FromSMILES( QString sm ) DPoint *thisDPoint; - OpenBabel::OBElementTable etable; - std::vector < OpenBabel::OBNodeBase * >::iterator ait; std::map < OpenBabel::OBAtom *, DPoint * >hashit; @@ -265,9 +263,9 @@ void Molecule::FromSMILES( QString sm ) qInfo() << "Adding OBAtom: " << i++ << " of element#: " << thisAtom->GetAtomicNum() << " type: " << - etable.GetSymbol(thisAtom->GetAtomicNum()) ; + OBElements::GetSymbol(thisAtom->GetAtomicNum()) ; thisDPoint = new DPoint; - tmp_element = etable.GetSymbol( thisAtom->GetAtomicNum() ); + tmp_element = OBElements::GetSymbol( thisAtom->GetAtomicNum() ); tmp_element_mask = tmp_element; tmp_element_mask.fill( ' ' ); // fix the mask characters @@ -292,7 +290,7 @@ void Molecule::FromSMILES( QString sm ) OpenBabel::OBBond * thisBond; - std::vector < OpenBabel::OBEdgeBase * >::iterator bit; + std::vector < OpenBabel::OBBond * >::iterator bit; for ( thisBond = myMol.BeginBond( bit ); thisBond; thisBond = myMol.NextBond( bit ) ) { addBond( hashit[thisBond->GetBeginAtom()], hashit[thisBond->GetEndAtom()], 1, thisBond->GetBondOrder(), QColor( 0, 0, 0 ), true ); }