Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1303 Return original format #1315

Merged
merged 11 commits into from
Oct 12, 2023
2 changes: 2 additions & 0 deletions api/c/indigo/indigo.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ CEXPORT int indigoRemove(int item);

/* Molecules, query molecules, SMARTS */

CEXPORT const char* indigoGetOriginalFormat(int item);

CEXPORT int indigoCreateMolecule(void);
CEXPORT int indigoCreateQueryMolecule(void);

Expand Down
28 changes: 28 additions & 0 deletions api/c/indigo/src/indigo_molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3784,6 +3784,34 @@ CEXPORT int indigoCountComponentBonds(int molecule, int index)
INDIGO_END(-1);
}

CEXPORT const char* indigoGetOriginalFormat(int item)
{
INDIGO_BEGIN
{
IndigoObject& obj = self.getObject(item);
if (IndigoBaseMolecule::is(obj))
{
BaseMolecule& mol = obj.getBaseMolecule();
AliaksandrDziarkach marked this conversation as resolved.
Show resolved Hide resolved
switch (mol.original_format)
{
case BaseMolecule::SMARTS:
return "chemical/x-daylight-smarts";
case BaseMolecule::SMILES:
return "chemical/x-daylight-smiles";
case BaseMolecule::MOL:
return "chemical/x-mdl-molfile";
case BaseMolecule::RXN:
return "chemical/x-mdl-rxnfile";
default:
AliaksandrDziarkach marked this conversation as resolved.
Show resolved Hide resolved
return "unknown";
}
}
else
throw IndigoError("indigoSaveJson(): expected molecule, got %s", obj.debugInfo());
}
INDIGO_END(0);
}

CEXPORT int indigoCreateMolecule()
{
INDIGO_BEGIN
Expand Down
3 changes: 3 additions & 0 deletions api/dotnet/src/IndigoLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public unsafe class IndigoLib
[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoClose(int item);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern byte* indigoGetOriginalFormat(int id);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoCreateMolecule();

Expand Down
6 changes: 6 additions & 0 deletions api/dotnet/src/IndigoObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public string cml()
return dispatcher.checkResult(IndigoLib.indigoCml(self));
}

public string getOriginalFormat()
{
dispatcher.setSessionID();
return dispatcher.checkResult(IndigoLib.indigoGetOriginalFormat(self));
}

public string json()
{
dispatcher.setSessionID();
Expand Down
2 changes: 2 additions & 0 deletions api/java/indigo/src/main/java/com/epam/indigo/IndigoLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public interface IndigoLib extends Library {

int indigoRemove(int item);

Pointer indigoGetOriginalFormat(int item);

int indigoCreateMolecule();

int indigoCreateQueryMolecule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public String molfile() {
return Indigo.checkResultString(this, lib.indigoMolfile(self));
}

public String getOriginalFormat() {
dispatcher.setSessionID();
return Indigo.checkResultString(this, lib.indigoGetOriginalFormat(self));
}

public void saveMolfile(String filename) {
dispatcher.setSessionID();
Indigo.checkResult(this, lib.indigoSaveMolfileToFile(self, filename));
Expand Down
2 changes: 2 additions & 0 deletions api/python/indigo/indigo/indigo_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ def __init__(self) -> None:
IndigoLib.lib.indigoIndex.argtypes = [c_int]
IndigoLib.lib.indigoRemove.restype = c_int
IndigoLib.lib.indigoRemove.argtypes = [c_int]
IndigoLib.lib.indigoGetOriginalFormat.restype = c_char_p
IndigoLib.lib.indigoGetOriginalFormat.argtypes = [c_int]
IndigoLib.lib.indigoSaveMolfileToFile.restype = c_int
IndigoLib.lib.indigoSaveMolfileToFile.argtypes = [c_int, c_char_p]
IndigoLib.lib.indigoMolfile.restype = c_char_p
Expand Down
11 changes: 11 additions & 0 deletions api/python/indigo/indigo/indigo_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ def remove(self):

return IndigoLib.checkResult(self._lib().indigoRemove(self.id))

def getOriginalFormat(self):
"""Molecule method return format molecule loaded from
AliaksandrDziarkach marked this conversation as resolved.
Show resolved Hide resolved

Returns:
str: original format string
"""

return IndigoLib.checkResultString(
self._lib().indigoGetOriginalFormat(self.id)
)

def saveMolfile(self, filename):
"""Molecule method saves the structure into a Molfile

Expand Down
4 changes: 4 additions & 0 deletions api/tests/integration/ref/basic/get_original_format.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
****** Test get original format: smiles ***
Molecule "N[CH](C)C(=O)O" : got "chemical/x-daylight-smiles" - OK
****** Test get original format: smarts ***
Molecule "([#6]1-[#6]-[#6]-1.[#6])" : got "chemical/x-daylight-smarts" - OK
33 changes: 33 additions & 0 deletions api/tests/integration/tests/basic/get_original_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import sys

sys.path.append(
os.path.normpath(
os.path.join(os.path.abspath(__file__), "..", "..", "..", "common")
)
)
from env_indigo import * # noqa

indigo = Indigo()


def test_mol(molecule, mol, expected):
original_format = mol.getOriginalFormat()
if original_format == expected:
print('Molecule "%s" : got "%s" - OK' % (molecule, expected))
else:
print(
'Molecule "%s" failed: expected original format "%s", got "%s"'
% (molecule, expected, original_format)
)


print("****** Test get original format: smiles ***")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test for reaction smiles and smarts

molecule = "N[CH](C)C(=O)O"
mol = indigo.loadMolecule(molecule)
test_mol(molecule, mol, "chemical/x-daylight-smiles")

print("****** Test get original format: smarts ***")
molecule = "([#6]1-[#6]-[#6]-1.[#6])"
mol = indigo.loadSmarts(molecule)
test_mol(molecule, mol, "chemical/x-daylight-smarts")
Loading
Loading