bryanherger / xdrawchem

XDrawChem is a two-dimensional molecule drawing program.
37 stars 11 forks source link

Support Open Babel 3 #16

Closed merkys closed 3 years ago

merkys commented 4 years ago

Open Babel 3 has been released recently. It would be great if xdrawchem could support it. For now trying to build it with Open Babel 3 results in the following:

xdrawchem/ioiface.cpp: In member function ‘void
IOIface::convertToChemData()’:
xdrawchem/ioiface.cpp:122:21: error: invalid use of incomplete type
‘class OpenBabel::OBBond’
  122 |         atom1 = bond->GetBeginAtom();
      |                     ^~

...

xdrawchem/ioiface.cpp: In member function ‘bool IOIface::convertToOBMol()’:
xdrawchem/ioiface.cpp:275:13: error: aggregate ‘OpenBabel::vector3 v’
has incomplete type and cannot be defined
  275 |     vector3 v;
      |             ^
xdrawchem/ioiface.cpp:276:12: error: aggregate ‘OpenBabel::OBAtom atom’
has incomplete type and cannot be defined
  276 |     OBAtom atom;
      |            ^~~~
Krzmbrzl commented 4 years ago

I have the feeling that this project has been abandoned a few years ago, so I don't think it's likely to see this happening...

merkys commented 4 years ago

Indeed, last commit was done two years ago.

baoilleach commented 4 years ago

Looking at the error messages above, the fixes are:

#include <openbabel/bond.h>
#include <openbabel/math/vector3.h>
#include <openbabel/atom.h>
merkys commented 4 years ago

Thanks @baoilleach, this worked! However, I ran into the following:

xdrawchem/ioiface.cpp: In member function ‘void IOIface::convertToChemData()’:
xdrawchem/ioiface.cpp:196:22: error: ‘class OpenBabel::OBAtom’ has no member named ‘IsCarbon’
  196 |         if ( !atom1->IsCarbon() ) {
      |                      ^~~~~~~~

IsCarbon() seems to be gone in OB3. Is there a way to get around this?

baoilleach commented 4 years ago

That's one of the examples I wrote up at https://open-babel.readthedocs.io/en/latest/UseTheLibrary/migration.html#handling-of-elements-and-related-information. Instead of IsCarbon() use GetAtomicNum() == 6.

merkys commented 4 years ago

Thanks @baoilleach for the superb link, GetAtomicNum() == 6 does the trick. Will soon open a PR.