Monday, November 10, 2008

The Chemistry Development Kit and IronPython

The Scientific C# blog looks at using another "mature open source cheminformatics api" from C# and IronPython: The java Chemistry Development Kit.
As it is a Java library, using it from .NET is a novel idea... The blog entry shows you how to compile the library for .NET using IKVM, an implementation of Java for .NET.

The command line magic to compile CDK for .NET is:

ikvmc -assembly:cdk_dotnet -target:library yourcdkjar.jar

This produces a .NET assembly. An example of using the library from IronPython:

import clr


from org.openscience.cdk import Molecule
from org.openscience.cdk.smiles import SmilesParser
#import the whole package for brevity
from org.openscience.cdk.qsar.descriptors.molecular import *
from org.openscience.cdk.qsar.result import DoubleResult

tpsa = TPSADescriptor()
logP = XLogPDescriptor()

smiles = SmilesParser()
mol = smiles.parseSmiles("N=CCC=O")
dr = tpsa.calculate(mol).getValue()
tpsaVal = dr.doubleValue()
dr = logP.calculate(mol).getValue()
logPVal = dr.doubleValue()
print logPVal,tpsaVal

the output is:
3.181 40.92

No comments:

Post a Comment

Note: only a member of this blog may post a comment.