Skip to content

Commit

Permalink
First pass at moving from JNA to JNI inchi - some tests need adjusting.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay authored and egonw committed Dec 18, 2021
1 parent d3eb48e commit 074afb4
Show file tree
Hide file tree
Showing 10 changed files with 527 additions and 458 deletions.
21 changes: 8 additions & 13 deletions storage/inchi/pom.xml
Expand Up @@ -3,30 +3,25 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>cdk-storage</artifactId>
<groupId>org.openscience.cdk</groupId>
<version>2.7-SNAPSHOT</version>
</parent>

<artifactId>cdk-inchi</artifactId>

<name>cdk-inchi</name>
<dependencies>
<dependency>
<groupId>javax.vecmath</groupId>
<artifactId>vecmath</artifactId>
</dependency>
<dependency>
<groupId>net.sf.jni-inchi</groupId>
<artifactId>jni-inchi</artifactId>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
<groupId>io.github.dan2097</groupId>
<artifactId>jna-inchi-core</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down Expand Up @@ -95,7 +90,7 @@
<artifactId>cdk-data</artifactId>
<version>${project.parent.version}</version>
<type>test-jar</type>
<scope>test</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand All @@ -108,7 +103,7 @@
<artifactId>cdk-test</artifactId>
<version>${project.parent.version}</version>
<type>test-jar</type>
<scope>test</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand All @@ -127,7 +122,7 @@
<artifactId>cdk-testdata</artifactId>
<version>${project.parent.version}</version>
<type>test-jar</type>
<scope>test</scope>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
102 changes: 102 additions & 0 deletions storage/inchi/src/main/java/net/sf/jniinchi/INCHI_OPTION.java
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2021 John Mayfield
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package net.sf.jniinchi;

import io.github.dan2097.jnainchi.InchiFlag;

/**
* This class provides backwards compatibility of JNA-INCHI with JNI-INCHI, this enum was exposed in the CDK API.
* @author John Mayfield
*/
public enum INCHI_OPTION {
SUCF,
ChiralFlagON,
ChiralFlagOFF,
SNon,
SAbs,
SRel,
SRac,
SUU,
NEWPS,
RecMet,
FixedH,
AuxNone,
NoADP,
Compress,
DoNotAddH,
Wnumber,
OutputSDF,
WarnOnEmptyStructure,
FixSp3Bug,
FB,
SPXYZ,
SAsXYZ;

public static INCHI_OPTION wrap(InchiFlag flag) {
switch (flag) {
case SUCF: return SUCF;
case ChiralFlagON: return ChiralFlagON;
case ChiralFlagOFF: return ChiralFlagOFF;
case SNon: return SNon;
case SRel: return SRel;
case SRac: return SRac;
case SUU: return SUU;
case RecMet: return RecMet;
case FixedH: return FixedH;
case AuxNone: return AuxNone;
case DoNotAddH: return DoNotAddH;
case WarnOnEmptyStructure: return WarnOnEmptyStructure;

default: throw new IllegalArgumentException(flag + " not supported?");
}
}

public static InchiFlag wrap(INCHI_OPTION flag) {
switch (flag) {
case SUCF: return InchiFlag.SUCF;
case ChiralFlagON: return InchiFlag.ChiralFlagON;
case ChiralFlagOFF: return InchiFlag.ChiralFlagOFF;
case SNon: return InchiFlag.SNon;
case SRel: return InchiFlag.SRel;
case SRac: return InchiFlag.SRac;
case SUU: return InchiFlag.SUU;
case RecMet: return InchiFlag.RecMet;
case FixedH: return InchiFlag.FixedH;
case AuxNone: return InchiFlag.AuxNone;
case DoNotAddH: return InchiFlag.DoNotAddH;
case WarnOnEmptyStructure: return InchiFlag.WarnOnEmptyStructure;
default:
System.err.println("Unsupported flag: " + flag);
return null;
}

// case SAbs: return SAbs;
// case NEWPS: return NEWPS;
// case NoADP: return NoADP;
// case Compress: return Compress;
// case Wnumber: return Wnumber;
// case OutputSDF: return OutputSDF;
// case FixSp3Bug: return FixSp3Bug;
// case FB: return FB;
// case SPXYZ: return SPXYZ;
// case SAsXYZ: return SAsXYZ;
}
}
48 changes: 48 additions & 0 deletions storage/inchi/src/main/java/net/sf/jniinchi/INCHI_RET.java
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2021 John Mayfield
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package net.sf.jniinchi;

import io.github.dan2097.jnainchi.InchiStatus;

/**
* This class provides backwards compatibility of JNA-INCHI with JNI-INCHI, this enum was exposed in the CDK API.
* @author John Mayfield
*/
public enum INCHI_RET {
SKIP,
EOF,
OKAY,
WARNING,
ERROR,
FATAL,
UNKNOWN,
BUSY;

public static INCHI_RET wrap(InchiStatus status) {
switch (status) {
case SUCCESS: return INCHI_RET.OKAY;
case WARNING: return INCHI_RET.WARNING;
case ERROR: return INCHI_RET.ERROR;
default:
throw new IllegalArgumentException("Unexpected status!");
}
}
}

0 comments on commit 074afb4

Please sign in to comment.