I have gotten this to work for R now, at least for the few parts that I
have tested. I currently have it in a local git branch called
"R-script". What is the best way to make this available? Since other
script languages live in the OpenBabel code base, I'm assuming you'd
want the R stuff there as well? Does that mean the OpenBabel team will
maintain R support? I cannot commit to supporting this long or short
term myself. I am doing this to support work I am doing for my job but I
don't have extra time to support all of Open Babel in R. I will be using
stuff from the areas of format conversion, descriptors, fingerprints,
and image generation, so these areas should work now or eventually at
least. I can write unit tests for these areas as I come to them.
I copied the initial version of openbabel-R.i from
openbabel-java.i, mainly just chosen at random. It may need some
additional clean up. I also modified the CMakeLists.txt file to add a
build target for R. I also copied this block from the java target and
modified it to work. I've no real experience with CMake, so I'm sure
this will need some clean up as well. I also had to add a sed script in
to the build process to fix a bug with SWIG. It seems to miss a semi
colon after a certain function every time in the generated .cpp file.
If this is to live in the OpenBabel code base, should the build
produce a whole R package, or is it fine to just leave it as the .so
that gets produced and users can load it as needed?
I have provided a small test script below. What else would be
useful for the dev team to know or have? Thanks.
Kevin
To use the below script you need to create an R package first:
1) create directory structure: mkdir -p openbabelR/{R,src}
2) link generated .R file: cd openbabelR/R; ln -s <OB build
dir>/scripts/R/openbabelR.R
3) link gererated .cpp file: cd openbabelR/src; ln -s <OB src
dir>/scripts/R/openbabel-R.cpp
3) create the following files:
openbabelR/DESCRIPTION:
Package: openbabelR
Type: Package
Title: R interface to OpenBabel
Version: 0.99.0
Date: 2013-10-21
Author: Kevin
Maintainer: Kevin <em...@example.com>
Description: test
License: file LICENSE
Depends: R (>= 2.15.1)
openbabelR/NAMESPACE: (an empty file)
openbabelR/R/init.R:
.onLoad <- function(libname,pkgname) {
library.dynam(pkgname,package=pkgname,lib.loc=libname,local=FALSE)
}
openbabelR/src/Makevars:
PKG_CXXFLAGS += -I<OB src dir>/include/ -I/usr/include/eigen3
PKG_LIBS += -I<OB build dir>/lib -lopenbabel
4) set environment variables:
export LD_LIBRARY_PATH=<OB build dir>/lib
export BABEL_DATADIR=<OB src dir>/data
export BABEL_LIBDIR=$LD_LIBRARY_PATH
5) install the package: cd openbabelR; R CMD INSTALL .
6) create file test.R with contents:
library(openbabelR)
convertTest <- function(){
smi = "cc1cccc1c"
inStr = openbabelR:::istreamFromString(smi)
outStr = openbabelR:::ostreamToString()
conv = openbabelR:::OBConversion(inStr,outStr)
message("setting formats")
openbabelR:::OBConversion_SetInAndOutFormats(conv,"SMI","SDF")
message("converting")
openbabelR:::OBConversion_Convert(conv)
str = openbabelR:::stringFromOstream(outStr)
print(str)
}
descriptorTest <- function(){
mol = openbabelR:::OBMol()
smi = "cc1cccc1c"
inStr = openbabelR:::istreamFromString(smi)
conv = openbabelR:::OBConversion(inStr)
message("setting formats")
openbabelR:::OBConversion_SetInAndOutFormats(conv,"SMI","SDF")
message("reading mol")
openbabelR:::OBConversion_Read(conv,mol)
message("finding type")
desc = openbabelR:::OBDescriptor_FindType("logP")
message("predicting")
p= openbabelR:::OBDescriptor_Predict(desc,mol)
message("value: ",p)
strDesc = openbabelR:::OBDescriptor_FindType("cansmi")
message("found type")
cansmi = openbabelR:::stringp()
message("got pointer")
openbabelR:::OBDescriptor_GetStringValue(strDesc,mol,cansmi$cast())
message("back from getstringvalue")
#openbabelR:::OBDescriptor_GetStringValue(desc,mol,cansmi)
message("cansmi: ",cansmi$value())
}
convertTest()
descriptorTest()
7) run script with: R --vanilla --slave < test.R
On 11/05/2013 01:21 AM, Noel O'Boyle wrote:
It might be obvious, but once you get things going, it would be super
useful to create an R script which we or you could run to verify that
the bindings were working as you expect for all of the Classes of
interest.
If you have trouble getting started, email the list again and I can take a look.
By the way, openbabel-scripting is officially dead - just email the
regular or dev list in future. Also, why not email the discuss list to
announce ChemMineOB.
- Noel
On 5 November 2013 03:54, Geoffrey Hutchison<geoff.hutchi...@gmail.com> wrote:
We started with a generic file, but frankly it didn't work very well. Many
things, you'll want to customize to meet specific language needs. So it's
fairly fast to adapt, say openbabel-python.i, but not everything will apply.
I'd also look up how R bindings are compiled with SWIG so you can put in the
appropriate CMake build rules.
Hope that helps,
-Geoff
(sent to openbabel-scripting @ lists.sourceforge.net)
I am considering using SWIG to create a new language binding for the R
language (http://www.r-project.org/). I have so far just been wrapping a
few functions from openbabel that I needed in C++ code and using R's
normal interface to C/C++ (.Call). As I understand SWIG, there should be
one general "openbabel.i" file and then any language binding can be
created from that. But when I looked in the source tarball for R I found
instead a swig file for each existing language binding (ie,
openbabel-java.i, openbabel-python.i, etc. ), and no plain "openbabel.i"
file. So my first question is, is there such a file? Or else, where
should I start in creating an "openbabel-R.i" file? Also, any other
general information anyone things I should know before trying this? Thanks.
Kevin
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel
------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing
conversations that shape the rapidly evolving mobile landscape. Sign up now.
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel