GithubHelp home page GithubHelp logo

k-ujihara / build-rdkit Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 7.0 287 KB

RDKit .NET wrapper for Windows/Linux.

License: BSD 3-Clause "New" or "Revised" License

Batchfile 1.68% Python 76.64% C# 13.84% C 6.25% Shell 1.34% Dockerfile 0.25%
rdkit cheminformatics csharp nuget

build-rdkit's Introduction

RDKit for .NET Framework

How to Build

Build Instruction

Do the following procedure.

  • Build native binaries for Windows
  • Build native binaries for Linux
  • Build .NET wrapper
  • Build NuGet package

Build native binaries for Windows 10 (x64)

  • On Windows 10 (x64)
  • Install Visual Studio 2019 enabling C++, C# and CMAKE.
  • Install Python version greater than 3.8.
  • Install SWIG.
    • IMPORTANT: SWIG-3.0 is required. SWIG-4.0 does not work.
  • Make sure Python and SWIG are executable.
  • Clone this repository to some directory. A name of the directory including path should be short. It is highly recommended to place it under 'C:'.
  • Download the following source archives and extract them here.
  • Download binery archives of both 32-bit and 64-bit versions of Boost for Visual Studio 2019, ie, msvc-14.2.
    • https://sourceforge.net/projects/boost/files/boost-binaries/.
    • Execute EXE files to extract. Defaults to store to C:\local.
    • Copy boost_#_##_# directory here.
    • Only dll and lib, ie, the files in lib64-msvc-14.# and lib32-msvc-14.#, are used to build.
    • After above, lib64-msvc-14.# and lib32-msvc-14.# should be created under boost_#_##_# directory.
  • Customize config.txt file according to where above dependencies are installed.
  • Open Developer Command Prompt for VS 2019.
  • Execute bash build_win.bat to create native binaries in ${RDKIT_DIR}/Code/JavaWrappers/csharp_wrapper/win/.

Build native binaries for Ubuntu 18.4

  • Don't share with Windows build.
  • Ubuntu 18.4 is recommended.
  • Install python 3.8 or greater, swig 3.0, and eigen3.
  • Install dotnet-sdk-5.0 and Mono.
sudo wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \
    sudo dpkg -i packages-microsoft-prod.deb && \
    sudo rm packages-microsoft-prod.deb && \
    sudo apt-get update && \
    sudo apt-get install -y apt-transport-https && \
    sudo apt-get update && \
    sudo apt-get install -y dotnet-sdk-5.0 && \
    sudo apt-get install -y mono-mcs
  • Clone this repository.
  • Download the following source archives and extract them here.
    • RDKit to rdkit-Release_####_##_#.
  • Customize config.txt file according to where above dependencies are installed.
  • Execute bash build_linux.sh to create native binaries in ${RDKIT_DIR}/Code/JavaWrappers/csharp_wrapper/linux/.

Build .NET wrapper

  • On Windows 10 (x64)
  • Open Developer Command Prompt for VS 2019.
  • Execute python ./build_rdkit_csharp.py --build_wrapper to create assembry files named RDKit2DotNet.dll in ${RDKIT_DIR}\Code\JavaWrappers\csharp_wrapper\RDKit2DotNet\bin\Release\.

Build and create NuGet package

  • Open Developer Command Prompt for VS 2019.
  • Copy native binaries for Linux to ${RDKIT_DIR}/Code/JavaWrappers/csharp_wrapper/linux/.
  • Execute python ./build_rdkit_csharp.py --build_nuget to create NuGet package on ${RDKIT_DIR}\Code\JavaWrappers\csharp_wrapper\RDKit2DotNet\bin\Release\.

Copy created NuGet package to myApp

  • Open Developer Command Prompt for VS 2019.
  • Execute nmake -f Makefile.win copy_to_myapp.

Install SWIG-3.0.12

Because RDKit's CMakeFile.txt does not work with SWIG 4.0, we need to install SWIG-3.0.

for Windows

Download SWIG executable from https://sourceforge.net/projects/swig/files/swigwin/swigwin-3.0.12/, extract, and add the directory to PATH.

for Linux

If SWIG-3.0 package is not availabe in your system, install it from source with the following instruction.

sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
wget https://sourceforge.net/projects/swig/files/swig/swig-3.0.12/swig-3.0.12.tar.gz
tar -zxvf swig-3.0.12.tar.gz
cd swig-3.0.12
./configure
make
sudo make install
make clean

If you required to uninstall SWIG-4.0, do the following.

sudo apt-get --purge remove swig

Build Java wrapper

Do below to build and run test.

make -f Makefile.linux rdkit_java_test USE_BOOST=TRUE
cd ${RDKIT_DIR}/Code/JavaWrappers/gmwrapper/
wget https://repo1.maven.org/maven2/junit/junit/4.13/junit-4.13.jar
mv junit-4.13.jar junit4.jar
wget https://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
mv remotecontent\?filepath=org%2Fhamcrest%2Fhamcrest-core%2F1.3%2Fhamcrest-core-1.3.jar hamcrest-core.jar
export RDBASE=${RDKIT_DIR}
LD_LIBRARY_PATH=${RDKIT_DIR}/Code/JavaWrappers/gmwrapper:$LD_LIBRARY_PATH java -cp ${RDKIT_DIR}/Code/JavaWrappers/gmwrapper/junit4.jar:${RDKIT_DIR}/Code/JavaWrappers/gmwrapper/hamcrest-core.jar:${RDKIT_DIR}/Code/JavaWrappers/gmwrapper/org.RDKit.jar:${RDKIT_DIR}/Code/JavaWrappers/gmwrapper/build-test org.junit.runner.JUnitCore org.RDKit.GraphMolTestSuite

build-rdkit's People

Contributors

k-ujihara avatar

Stargazers

Felix avatar Edwin Laboy avatar Brian Satola avatar Lukasz Dabrowski avatar SartorialOFence avatar Jared Frazier avatar hority avatar

Watchers

James Cloos avatar SartorialOFence avatar  avatar

build-rdkit's Issues

example code to calculate moleclar descriptors

Hello!
I try to calculate all molecular descriptors but seem not to find the correct examples. Would it be possible for you to provide some example code on how to calculate molecular Graph Descriptors (BalabanJ, Chi0, Kappa1,...), Descriptors (EState_VSA10,...), or Fragments(fr_Al_COO,...) using the RDKit.DotNetWrap package?

Thank you so much for your time and effort!
Looking forward for a short reply!
Jan

Unable to load DLL 'RDKFuncs' after publishing solution

Hello,

I am using Visual Studio 2019 for VSTO Office add-in with .NET framework 4.7.2 (windows 10 and Office 365 64-bit. I installed the Nuget package fine, and the solution compiles and runs fine in debug mode. However after publishing the solution, I get unable to load DLL 'RDKFuncs' at runtime. I have checked the References in Visual Studio and it's howing Copy Local as true. I am not sure what I am missing.

Can't not run simple Test on linux (WSL, ubuntu) on net6.0

Here is a simple test code which runs fine on net6.0 in windows.

static void Main(string[] args)
 { 
        var rwMol = RWMol.MolFromSmiles("C(Cl)(=O)CCC(=O)Cl");
        Console.WriteLine(RDKFuncs.calcAMW(rwMol));
}

However, when I publish it and run under WSL, I got this error:

Unhandled exception. System.TypeInitializationException: The type initializer for 'GraphMolWrap.RDKFuncsPINVOKE' threw an exception.
---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception.
---> System.DllNotFoundException: Unable to load shared library 'RDKFuncs' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libRDKFuncs: cannot open shared object file: No such file or directory
at GraphMolWrap.RDKFuncsPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_RDKFuncs(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
at GraphMolWrap.RDKFuncsPINVOKE.SWIGExceptionHelper..cctor()
--- End of inner exception stack trace ---
at GraphMolWrap.RDKFuncsPINVOKE.SWIGExceptionHelper..ctor()
at GraphMolWrap.RDKFuncsPINVOKE..cctor()
--- End of inner exception stack trace ---
at GraphMolWrap.RDKFuncsPINVOKE.RWMol_MolFromSmiles__SWIG_3(String jarg1)
at GraphMolWrap.RWMol.MolFromSmiles(String smi)
at Test.Program.Main(String[] args) in D:\Project\Test\Test\Program.cs:line 45

It looks like WSL missed some deps. I have found RDKFuncs.so in the runtimes/linux-x64/native folder, so it may be one of it deps missing.

Could you please look into this issue? @kazuyaujihara

Your help will be greatly appreciated!

Accessing Values in SparseIntVectu32

First of all, thanks so much for packaging this all up! I was able to create fingerprints and compare them for similarity, but I am having lots of issues saving them in a format that I can rapidly access later on. IOW, I want to serialize and deserialize them as binary objects or as a compact text representation. But nothing seems to work. Is this a problem with the wrappers?

using var mol = RWMol.MolFromSmiles("O=Cc1ccc(O)c(OC)c1 COc1cc(C=O)ccc1O");

//this returns a valid FP that can be used for sim comparisons
SparseIntVectu32 fp = RDKFuncs.MorganFingerprintMol(mol, 2);

var a = fp.getLength(); //2^32-1
var b = fp.toString(); // "\u0001"
var aa = fp.size(); //2^32-1

//I have not yet dug into this:
SWIGTYPE_p_std__mapT_unsigned_int_int_std__lessT_unsigned_int_t_t t = fp.getNonzeroElements();

//checking for set FP positions never finds a 1
for (uint i = 0; i < 100_000; i++)
{
    var k = fp.getVal(i);
    
    if (k > 0)
    {
        //never occurs
    }
}

var asString = fp.toString();

//error
fp.fromString(asString);

Generate high resolution molecular image in Black & White format

Hi,
I am currently using MolDraw2DCairo to create a /png molecular image. I am facing 2 issues which I have mentioned below. Please let me know how to fix these.

  1. The image generated is of a very low resolution, and because of this it is blurr when i print it to pdf.
  2. I am unable to generate the image in Black & White format. On Google it suggests to use 'useBWColourPalette' but this option is not available under MolDraw2DCairo.DrawOptions().

Please let me know how to fix these issues. I have pasted the code snippet below. Thank you.

var view = new MolDraw2DCairo(width, height);
view.drawMolecule(mol);
view.finishDrawing();
view.writeDrawingText(imageName);

PINVOKE error on linux

Hi,

This is a great package as I was looking forward to have a way to use rdkit from f#!

I did run tests on windows and everything worked as expected but I didn't manage to get anything working on linux.
I tried Arch linux and Redhat 8.3.1 but with my first attempt to use MolFromSmiles I already get

System.TypeInitializationException: The type initializer for 'GraphMolWrap.RDKFuncsPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'RDKFuncs' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libRDKFuncs: cannot open shared object file: No such file or directory at GraphMolWrap.RDKFuncsPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_RDKFuncs(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate) at GraphMolWrap.RDKFuncsPINVOKE.SWIGExceptionHelper..cctor() --- End of inner exception stack trace --- at GraphMolWrap.RDKFuncsPINVOKE.SWIGExceptionHelper..ctor() at GraphMolWrap.RDKFuncsPINVOKE..cctor() --- End of inner exception stack trace --- at GraphMolWrap.RDKFuncsPINVOKE.RWMol_MolFromSmiles__SWIG_3(String jarg1) at GraphMolWrap.RWMol.MolFromSmiles(String smi) at <StartupCode$FSI_0005>.$FSI_0005.main@()

The code to reproduce is
`
#r "nuget: RDKit.DotNetWrap, 0.2020094.1"

open GraphMolWrap

let mol = RWMol.MolFromSmiles "CS(=O)(=O)NC1C([NH3+])C1O"
`

The environment is a dotnet interactive notebook in VSCode running dotnet sdk 5.0.103.
I am new to this programming environment so please let me know if you need further information.
The error is the same with Arch linux and Redhat 8.3.1.

GraphMolWrap.RDKFuncsPINVOKE Exception

when i use this package in my asp.net websit ,the RWMol Class Init throw a error message "GraphMolWrap.RDKFuncsPINVOKE”的类型初始值设定项引发异常" ;but is use this package in Console
project thats all ok

Update ?

Is there any chance, the nuget package will be updated to current (2024) RDkit version ? We must some detect-bond futures not present in the 2021 release ...

Add macOS native libs

Hi,
would it be possible for you to add the option to build macOS native RDKFuncs?

Visual Studio 2022 shows all the rdkit dll's in solution explorer

Hi,

Thanks for this library! There is an annoying issue that popped up in VS 2022. It shows all the boost and RDKit dll's.

image

It looks like this issue:

dotnet/project-system#4069

I think all that it needs is to add the <Visible>False</Visible> tag when RDKit.DotNetWrap.targets is built in build_rdkit_csharp.py.

Normally I would submit a PR, but the build process is pretty involved. I can still do this - but this seems like a pretty small change.

关于docker容器里面无法初始化

您好,在docker运行时,报错,如下“The type initializer for 'GraphMolWrap.RDKFuncsPINVOKE' threw an exception.”,请问这需要配置其他的操作嘛

Is Visual Studio 2019 workable for this build?

Hello, I use VS 2019 instead of VS 2017 to build the whole project, all the other libraries are configured as suggested.

It throws error

Command 'MSBuild RDKit.sln /p:Configuration=Release,Platform=x64 /maxcpucount' returned non-zero exit status 1.

when executing python build-rdkit-csharp.py

I cannot find more detailed hint about this error. Is it due to the version of visual studio?

Error while trying to run SDMolSupplier

Hi,

I am trying to use SDMolSupplier to read molecules from .SDF file, but this is just throwing a generic 'Error' message. Can you let me know what I am doing wrong?
I am getting the error in the line which is Bold.

Sample code:
var molSupplier = new SDMolSupplier("SDF_path");
while(!molSupplier.atEnd())
{
var mol = molSupplier.next();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.