Class JniInchiWrapper
- java.lang.Object
-
- net.sf.jniinchi.JniInchiWrapper
-
public class JniInchiWrapper extends java.lang.Object
JNI Wrapper for International Chemical Identifier (InChI) C++ library.
This class is not intended to be used directly, but should be accessed through subclasses that read data formats and load them into the InChI data structures.
Subclasses should load data through the addAtom, addBond and addParity methods. Once the molecule is fully loaded then the generateInchi method should be called. Ideally this should all take place within the subclass's constructor. The public get methods will all return null until this has happened.
See inchi_api.h.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
flagChar
Switch character for passing options.private static java.lang.String
ID
private static JniInchiWrapper
inchiWrapper
private static boolean
IS_WINDOWS
Flag indicating windows or linux.private static boolean
libraryLoaded
Records whether native library has been loaded by system.private static java.util.concurrent.locks.Lock
lock
private static int
MAX_LOCK_TIMEOUT
Maximum time to wait for a lock (in seconds).private static java.lang.String
VERSION
-
Constructor Summary
Constructors Modifier Constructor Description private
JniInchiWrapper()
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static INCHI_STATUS
checkInchi(java.lang.String inchi, boolean strict)
Checks if the string represents valid InChI/standard InChI.private int
CheckINCHI(java.lang.String inchi, boolean strict)
static INCHI_KEY_STATUS
checkInchiKey(java.lang.String key)
Checks whether a string represents valid InChIKey.private int
CheckINCHIKey(java.lang.String key)
private static void
checkNativeCodeVersion()
Checks the expected native code version has been loaded.protected static java.lang.String
checkOptions(java.lang.String ops)
Checks and canonicalises options.protected static java.lang.String
checkOptions(java.util.List<INCHI_OPTION> ops)
Checks and canonicalises options.static JniInchiOutput
getInchi(JniInchiInput input)
Generates the InChI for a chemical structure.private JniInchiOutput
GetINCHI(JniInchiInput input)
static JniInchiOutput
getInchiFromInchi(JniInchiInputInchi input)
Converts an InChI into an InChI for validation purposes (the same as the -InChI2InChI option).private JniInchiOutput
GetINCHIfromINCHI(java.lang.String inchi, java.lang.String options)
private JniInchiInputData
GetINCHIInputFromAuxInfo(java.lang.String auxInfo, boolean bDoNotAddH, boolean bDiffUnkUndfStereo)
static JniInchiOutputKey
getInchiKey(java.lang.String inchi)
Calculates the InChIKey for an InChI string.private JniInchiOutputKey
GetINCHIKeyFromINCHI(java.lang.String inchi)
static JniInchiInputData
getInputFromAuxInfo(java.lang.String auxInfo)
private static void
getLock()
static JniInchiOutput
getStdInchi(JniInchiInput input)
Calculates the Standard InChI string for a chemical structure.private JniInchiOutput
GetStdINCHI(JniInchiInput input)
private JniInchiOutputKey
GetStdINCHIKeyFromStdINCHI(java.lang.String inchi)
private JniInchiOutputStructure
GetStructFromINCHI(java.lang.String inchi, java.lang.String options)
static JniInchiOutputStructure
getStructureFromInchi(JniInchiInputInchi input)
Generated 0D structure from an InChI string.private static JniInchiWrapper
getWrapper()
private static void
init()
protected static java.lang.String
LibInchiGetVersion()
static void
loadLibrary()
Loads native library.
-
-
-
Field Detail
-
ID
private static final java.lang.String ID
- See Also:
- Constant Field Values
-
VERSION
private static final java.lang.String VERSION
- See Also:
- Constant Field Values
-
MAX_LOCK_TIMEOUT
private static final int MAX_LOCK_TIMEOUT
Maximum time to wait for a lock (in seconds).- See Also:
- Constant Field Values
-
IS_WINDOWS
private static final boolean IS_WINDOWS
Flag indicating windows or linux.
-
flagChar
static final java.lang.String flagChar
Switch character for passing options. / in windows, - on other systems.
-
libraryLoaded
private static boolean libraryLoaded
Records whether native library has been loaded by system.
-
inchiWrapper
private static JniInchiWrapper inchiWrapper
-
lock
private static final java.util.concurrent.locks.Lock lock
-
-
Constructor Detail
-
JniInchiWrapper
private JniInchiWrapper() throws LoadNativeLibraryException
Constructor- Throws:
LoadNativeLibraryException
-
-
Method Detail
-
loadLibrary
public static void loadLibrary() throws LoadNativeLibraryException
Loads native library.- Throws:
JniInchiException
- Library failed to loadLoadNativeLibraryException
-
checkNativeCodeVersion
private static void checkNativeCodeVersion()
Checks the expected native code version has been loaded.- Throws:
java.lang.UnsatisfiedLinkError
-
getWrapper
private static JniInchiWrapper getWrapper() throws LoadNativeLibraryException
- Throws:
LoadNativeLibraryException
-
checkOptions
protected static java.lang.String checkOptions(java.util.List<INCHI_OPTION> ops) throws JniInchiException
Checks and canonicalises options.- Parameters:
ops
- List of INCHI_OPTION- Throws:
JniInchiException
-
checkOptions
protected static java.lang.String checkOptions(java.lang.String ops) throws JniInchiException
Checks and canonicalises options.- Parameters:
ops
- Space delimited string of options to pass to InChI library. Each option may optionally be preceded by a command line switch (/ or -).- Throws:
JniInchiException
-
getInchi
public static JniInchiOutput getInchi(JniInchiInput input) throws JniInchiException
Generates the InChI for a chemical structure.
If no InChI creation/stereo modification options are specified then a standard InChI is produced, otherwise the generated InChI will be a non-standard one.
Valid options:
Structure perception (compatible with stdInChI): /NEWPSOFF /DoNotAddH /SNon Stereo interpretation (lead to generation of non-standard InChI) /SRel /SRac /SUCF /ChiralFlagON /ChiralFlagOFF InChI creation options (lead to generation of non-standard InChI) /SUU /SLUUD /FixedH /RecMet /KET /15T
Other options:
/AuxNone Omit auxiliary information (default: Include) /Wnumber Set time-out per structure in seconds; W0 means unlimited In InChI library the default value is unlimited /OutputSDF Output SDfile instead of InChI /WarnOnEmptyStructure Warn and produce empty InChI for empty structure /SaveOpt Save custom InChI creation options (non-standard InChI)
- Parameters:
input
-- Returns:
- Throws:
JniInchiException
-
getStdInchi
public static JniInchiOutput getStdInchi(JniInchiInput input) throws JniInchiException
Calculates the Standard InChI string for a chemical structure.
The only valid structure perception options are NEWPSOFF/DoNotAddH/SNon. In any other structural perception options are specified then the calculation will fail.
- Parameters:
input
-- Returns:
- Throws:
JniInchiException
-
getInchiFromInchi
public static JniInchiOutput getInchiFromInchi(JniInchiInputInchi input) throws JniInchiException
Converts an InChI into an InChI for validation purposes (the same as the -InChI2InChI option).
This method may also be used to filter out specific layers. For instance, /Snon would remove the stereochemical layer; Omitting /FixedH and/or /RecMet would remove Fixed-H or Reconnected layers. In order to keep all InChI layers use options string "/FixedH /RecMet"; option /InChI2InChI is not needed.
- Parameters:
input
-- Returns:
- Throws:
JniInchiException
-
getStructureFromInchi
public static JniInchiOutputStructure getStructureFromInchi(JniInchiInputInchi input) throws JniInchiException
Generated 0D structure from an InChI string.- Parameters:
input
-- Returns:
- Throws:
JniInchiException
-
getInchiKey
public static JniInchiOutputKey getInchiKey(java.lang.String inchi) throws JniInchiException
Calculates the InChIKey for an InChI string.- Parameters:
inchi
- source InChI string- Returns:
- InChIKey output
- Throws:
JniInchiException
-
checkInchiKey
public static INCHI_KEY_STATUS checkInchiKey(java.lang.String key) throws JniInchiException
Checks whether a string represents valid InChIKey.- Parameters:
key
-- Returns:
- Throws:
JniInchiException
-
checkInchi
public static INCHI_STATUS checkInchi(java.lang.String inchi, boolean strict) throws JniInchiException
Checks if the string represents valid InChI/standard InChI.
- Parameters:
inchi
- source InChIstrict
- iffalse
, just briefly check for proper layout (prefix, version, etc.) The result may not be strict. Iftrue
, try to perform InChI2InChI conversion and returns success if a resulting InChI string exactly match source. The result may be 'false alarm' due to imperfectness of- Throws:
JniInchiException
-
getInputFromAuxInfo
public static JniInchiInputData getInputFromAuxInfo(java.lang.String auxInfo) throws JniInchiException
- Throws:
JniInchiException
-
getLock
private static void getLock() throws JniInchiException
- Throws:
JniInchiException
-
LibInchiGetVersion
protected static java.lang.String LibInchiGetVersion()
-
init
private static void init()
-
GetINCHI
private JniInchiOutput GetINCHI(JniInchiInput input)
-
GetStdINCHI
private JniInchiOutput GetStdINCHI(JniInchiInput input)
-
GetINCHIfromINCHI
private JniInchiOutput GetINCHIfromINCHI(java.lang.String inchi, java.lang.String options)
-
GetStructFromINCHI
private JniInchiOutputStructure GetStructFromINCHI(java.lang.String inchi, java.lang.String options)
-
GetINCHIKeyFromINCHI
private JniInchiOutputKey GetINCHIKeyFromINCHI(java.lang.String inchi)
-
GetStdINCHIKeyFromStdINCHI
private JniInchiOutputKey GetStdINCHIKeyFromStdINCHI(java.lang.String inchi)
-
CheckINCHIKey
private int CheckINCHIKey(java.lang.String key)
-
CheckINCHI
private int CheckINCHI(java.lang.String inchi, boolean strict)
-
GetINCHIInputFromAuxInfo
private JniInchiInputData GetINCHIInputFromAuxInfo(java.lang.String auxInfo, boolean bDoNotAddH, boolean bDiffUnkUndfStereo)
-
-