Use RDKit from NIM language #RDKit #Nim #memo

Recently I bought a book which title is ‘Nim in Action’ and started to learn NIM language. I never touched language like a nim-lang which is required compile to run the code.

I had interest about nim-lang because, many documents say NIM is speedy and efficient, and grammar seems like python. And also, rdkit binding is available! The binding is still under development but it’s good news for chemoinformatitian. Thank Axel Pahl for his great work!

Now rdkit-nim offers some chemoinformatics functions. So let’s try to use it.

At first I installed nim-lang. rdkit-nim supports nim version 1.1.1 or higher. This isn’t stable version of nim. I installed choosenim and switch the version to devel.

$ curl -sSf | sh
# Add path to bashrc
# export PATH=/home/username/.nimble/bin:$PATH
# Then switch to devel from stable version.
$ choosenim devel
$ nim -v
Nim Compiler Version 1.1.1 [Linux: amd64]
Compiled at 2020-02-05
Copyright (c) 2006-2019 by Andreas Rumpf

Next, install rdkit nim-rdkit. It is described in of original repository.

#Add rdkit path to bashrc
# export RDKIT_NIM_CONDA=/home/username/anaconda3/envs/myenv

$ git clone
$ cd rdkit_nim
$ nimble install
$ nimble test
  Executing task test in /home/username/dev/nim_dev/rdkit_nim/rdkit.nimble
    [mol.nim]             passed.
    [qed.nim]             passed.
    [sss.nim]             passed.

    All tests passed.

OK, all test is passed. ;-)

Let’s build simple example which calculate QED of given molecules.

Code is below.

import rdkit / [mol, qed]
let smiles_list = [

for smi in smiles_list:
  let m = molFromSmiles(smi)
  let a = qedDefault(m)

Current rdkit-nim supports mol, descriptors, sss and qed modules. The code above import rdkit/mol and rdkit/qed module.

Before build the code, it is required to make nim script file.


import os # `/`

  fileName = "calc_qed"
  condaPath = getEnv("RDKIT_NIM_CONDA")

task build, "Building default cpp target...":
  switch("verbosity", "0")
  # switch("hint[Conf]", "off")
  switch("hints", "off")
  switch("out", "test2/bin" / toExe(fileName))
  switch("passL", "-lstdc++")
  switch("passL", "-L" & condaPath & "/lib")
  switch("passL", "-lRDKitGraphMol")
  switch("passL", "-lRDKitDescriptors")
  switch("passL", "-lRDKitSmilesParse")
  switch("passL", "-lRDKitChemTransforms")
  switch("passL", "-lRDKitSubstructMatch")
  switch("cincludes", condaPath & "/include/rdkit")
  switch("cincludes", condaPath & "/include")
  setcommand "cpp"

Almost there, let’s compile the code.

$ nim build calc_qed.nim
Hint: used config file '/home/username/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: used config file '/home/username/.choosenim/toolchains/nim-#devel/config/config.nims' [Conf]
Hint: used config file '/home/username/dev/nim_dev/rdkit_nim/test2/calc_qed.nims' [Conf]

After that I got compiled file, test2/bin/calc_qed.

Let’s call the function.

$ ./test2/bin/calc_qed 

Works fine!

In this code, I embedded molecules as SMILES but if the code load smiles from text files, calculate target can change dynamically. It will be practical apprlcation.

I’m still new for NIM so I would like to learn NIM more and use the package to solve my chemoinformatics task!

Original repo provides many examples user can learn many things from the site. Please check it!


Published by iwatobipen

I'm medicinal chemist in mid size of pharmaceutical company. I love chemoinfo, cording, organic synthesis, my family.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: