mychem / mychem-code

Mychem is an extension for MySQL that makes possible to use cheminformatics functions within SQL queries.
GNU General Public License v2.0
21 stars 14 forks source link

Update cmake modules to match new OpenBabel, MySQL and MariaDB versions #29

Open Pansanel opened 3 years ago

merkys commented 3 years ago

I attempted building on Ubuntu 20.04 with system-provided packages (OpenBabel 3.0.0 and MariaDB 10.3.25). I used commands

CFLAGS=-DSTANDARD cmake ..
make

First of all, I stumbled upon

Scanning dependencies of target mychem-lib
[  3%] Building C object src/CMakeFiles/mychem-lib.dir/conversion.c.o
In file included from /home/andrius/src/mychem-code/src/conversion.c:30:
/home/andrius/src/mychem-code/src/conversion.h:48:10: fatal error: m_ctype.h: No such file or directory
   48 | #include <m_ctype.h>
      |          ^~~~~~~~~~~
compilation terminated.
make[2]: *** [src/CMakeFiles/mychem-lib.dir/build.make:63: src/CMakeFiles/mychem-lib.dir/conversion.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:162: src/CMakeFiles/mychem-lib.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

I did the following change to get around it:

diff --git a/src/conversion.h b/src/conversion.h
index 453d398..6d2ebbc 100644
--- a/src/conversion.h
+++ b/src/conversion.h
@@ -45,8 +45,6 @@ typedef long long longlong;
 #include <my_sys.h>
 #endif /* STANDARD */
 #include <mysql.h>
-#include <m_ctype.h>
-#include <m_string.h>          /* To get strmov() */

After that, building failed with OpenBabel:

/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp: In member function ‘virtual bool OpenBabel::fingerprint2::GetFingerprint(OpenBabel::OBBase*, std::vector<unsigned int>&, int)’:
/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp:106:9: error: ‘OBNodeBase’ was not declared in this scope; did you mean ‘OBBase’?
  106 |  vector<OBNodeBase*>::iterator i;
      |         ^~~~~~~~~~
      |         OBBase
/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp:106:20: error: template argument 1 is invalid
  106 |  vector<OBNodeBase*>::iterator i;
      |                    ^
/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp:106:20: error: template argument 2 is invalid
/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp:106:32: error: qualified-id in declaration before ‘i’
  106 |  vector<OBNodeBase*>::iterator i;
      |                                ^
/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp:107:31: error: ‘i’ was not declared in this scope
  107 |  for (patom = pmol->BeginAtom(i);patom;patom = pmol->NextAtom(i))
      |                               ^
/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp:109:11: error: invalid use of incomplete type ‘class OpenBabel::OBAtom’
  109 |   if(patom->IsHydrogen()) continue;
      |           ^~

[skip]

In file included from /home/andrius/src/mychem-code/src/conversion_wrapper.cpp:39:
/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp: In member function ‘void OpenBabel::fingerprint2::DoReverses()’:
/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp:207:3: error: ‘reverse’ was not declared in this scope; did you mean ‘DoReverses’?
  207 |   reverse(t1.begin()+1, t1.end()); //(leave 0 at front alone)
      |   ^~~~~~~
      |   DoReverses
/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp: In member function ‘void OpenBabel::fingerprint2::DoRings()’:
/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp:235:4: error: ‘rotate’ was not declared in this scope
  235 |    rotate(t1.begin(),t1.begin()+2,t1.end());
      |    ^~~~~~
/home/andrius/src/mychem-code/src/fingerprints/finger2.cpp:247:4: error: ‘reverse’ was not declared in this scope; did you mean ‘DoReverses’?
  247 |    reverse(t2.begin()+1, t2.end());
      |    ^~~~~~~
      |    DoReverses
In file included from /home/andrius/src/mychem-code/src/conversion_wrapper.cpp:40:
/home/andrius/src/mychem-code/src/fingerprints/finger3.cpp: At global scope:
/home/andrius/src/mychem-code/src/fingerprints/finger3.cpp:38:5: error: ‘OBSmartsPattern’ does not name a type
   38 |     OBSmartsPattern obsmarts;
      |     ^~~~~~~~~~~~~~~

Maybe I am missing something?

merkys commented 3 years ago

Nevertheless, new OpenBabel and MariaDB libraries and headers are successfully found with this PR!

fredrikw commented 3 years ago

An alternative solution to the m_ctype-problem is to install libmariadbclient-dev-compat, at least that worked for me but that was before this PR.

merkys commented 3 years ago

An alternative solution to the m_ctype-problem is to install libmariadbclient-dev-compat, at least that worked for me but that was before this PR.

libmariadbclient-dev-compat has been dropped in Debian 10 and Ubuntu 20.04. It seems that MariaDB 10.1 was the last release supporting this sort of compatibility.

merkys commented 2 years ago

I confirm that 5b6f95fe859c66d9cffb9033b05c5d7bff3b8af7 fixes all my issues and I finally am able to use the functions. Thanks a lot!

Tested on Ubuntu 18.04, with system-provided OpenBabel v2.3.2 and MySQL v5.7.36. I did not need any specific CMake flags, it just went very smoothly. I had to adjust AppArmor configuration as described. I will also test it with MariaDB when I have time.

merkys commented 2 years ago

I have as well successfully built 5b6f95f on:

studur commented 1 year ago

@merkys I am trying to install the stack on a debian 10+ AWS EC2 but somehow I have some problem with the installation procedure. I always end up with a NULL value when testing the SELECT EXACTMASS(SMILES_TO_MOLECULE('c1ccccc1')); after all the installation. Could you (or anyone else) provide an updated procedure please ? Thank you

merkys commented 1 year ago

@studur I will try to reproduce, will get back to you.

merkys commented 1 year ago

@studur I have built and installed this PR on Debian 10 and ran into the same issue with all calls returning NULL. I have no idea why. What is even worse, I do not recall whether I got any non-NULL values testing on Debian 10 before.

studur commented 1 year ago

@merkys thank you for trying. I hope that this will be fixed. Have a great day

Pansanel commented 1 year ago

Hi, I will try to run it on Debian 10 (I have access to an OpenStack cloud providing such image). I will let you know ASAP. Best, Jerome

Pansanel commented 1 year ago

Can you check again? It works now on my side with debian 10 and Openbabel v2.4.1.

merkys commented 1 year ago

@Pansanel I just tried with 532eb6abfa768e62cf8a08dd73f1d9183df035f6 and got NULL for select smiles_to_molecule("c1ccccc1");. Are you using system-provided Open Babel, or have you installed it yourself?

Pansanel commented 1 year ago

I am using the system-provided Open Babel. Did you try to enable the test mode?

studur commented 1 year ago

Hi, I will try to run it on Debian 10 (I have access to an OpenStack cloud providing such image). I will let you know ASAP. Best, Jerome

Thank you for looking in to this. Could this be due to a difference between the Openstack image and the AWS Marketplace AMI Debian 10 image ? I tried with the later. image

Pansanel commented 1 year ago

Hi, there should be no difference between the images. Is your installation directory: /usr/lib/x86_64-linux-gnu/mariadb19/plugin? What gives: ldd /usr/lib/x86_64-linux-gnu/mariadb19/plugin/libmychem.so.2.0.0

studur commented 1 year ago

I will check this the next time I spin up an AWS EC2 but I noticed the plugin directory change for mariadb.

Meanwhile, I would not be surprised that I don't use the right client libs for mariadb.

Could you paste in the comments the mariadb and openbabel installations please? Specifically the section that replace the lines 81-85 in the following installation doc. https://github.com/mychem/mychem-code/commit/8ac73f6eddbb9ef8294a041a7f37c0a69ddbb9fe

Pansanel commented 1 year ago

For openbabel and mariadb, I am just using the default debian packages:

apt install openbabel libopenbabel-dev
apt install libmariadbclient-dev mariadb-server
studur commented 1 year ago

Thanks @Pansanel , it works now. I executed the following commands as a new user authenticated with ssh and member of the sudo group in Debian 10

# Install Openbabel and MariaDB

sudo apt install -y openbabel libopenbabel-dev libmariadb-dev-compat libmariadbclient-dev mariadb-server python3-mysqldb cmake g++ zip git

sudo systemctl start mariadb
sudo systemctl enable mariadb

# Configure MySQL
sudo mysql_secure_installation

mysql -u root -p 
create user 'USER'@'localhost' identified by '**********';
grant all  on *.* to 'USER'@'localhost' with grant option;
flush privileges;
exit;

# Logout MySQL and login back again
mysql -u USER -p
CREATE DATABASE mychem;
exit;

cd ~
git clone https://github.com/Pansanel/mychem-code.git
cd mychem-code
# the master branch contains the code for debian 10 / mariadb 10.3 compatibility.

mkdir build
cd build
cmake ..
make
sudo make install

# Create missing symlink
sudo mkdir -p /usr/lib/mysql/plugin/
cd /usr/lib/mysql/plugin/
sudo ln -s /usr/lib/x86_64-linux-gnu/mariadb19/plugin/libmychem.so libmychem.so

# Install Mychem extension
cd ~/mychem-code
mysql -u USER -p < src/mychemdb.sql

# Test
mysql -u USER -p
use mychem;
SELECT EXACTMASS(SMILES_TO_MOLECULE('c1ccccc1'));

Should get ...
+-------------------------------------------+
| EXACTMASS(SMILES_TO_MOLECULE('c1ccccc1')) |
+-------------------------------------------+
|                                 78.046950 |
+-------------------------------------------+

@merkys Do you want to confirm on your end ?

Pansanel commented 1 year ago

It is a good news :-) I have to find a way to have a generic build system that can work with all the most recent OpenBabel releases. In particular, the src/descriptors/* and src/fingerprints/* files are directly copied from OpenBabel source code. I will try to fix this by downloading during CMake configuration the right files.