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

cdx export #941 #1012

Merged
merged 44 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
71d0374
rgroups (#946)
even1024 Dec 22, 2022
d4f286c
CDX import: Reaction arrows disappear when opening a file https://git…
even1024 Dec 23, 2022
1885107
bond order fix
even1024 Dec 26, 2022
2350402
clang fix
even1024 Dec 26, 2022
744c3d3
test fix
even1024 Dec 26, 2022
460ebee
cdx export
even1024 Dec 28, 2022
1af734f
Merge branch 'master' into feature/941-cdx-export
even1024 Dec 28, 2022
909a42c
clang fixes
even1024 Dec 28, 2022
f11c36d
cdx python binding
even1024 Dec 28, 2022
8fd7ded
clang fixes
even1024 Dec 28, 2022
e83f9fa
api fixes
even1024 Dec 28, 2022
23e7f06
cdx export
even1024 Jan 4, 2023
9b0f63d
merged
even1024 Jan 24, 2023
082ea86
Merge branch 'master' of https://github.com/epam/Indigo into feature/…
even1024 Jan 24, 2023
ce8534e
indigo py fix
even1024 Jan 24, 2023
ecca942
cdx
even1024 Jan 25, 2023
03914a2
cdx
even1024 Jan 25, 2023
0e6ea51
cdx fixes
even1024 Jan 26, 2023
3c30a1d
cdx fixes
even1024 Jan 26, 2023
a405a5c
clang fix
even1024 Jan 26, 2023
412d377
PR comments
even1024 Jan 26, 2023
dcfaca6
clang fix
even1024 Jan 26, 2023
5d7c4cd
pr fix
even1024 Jan 26, 2023
30e4f3b
pr fix
even1024 Jan 26, 2023
8936544
b64cdx java&dotnet fix
even1024 Jan 26, 2023
5ec8b39
b64cdx java&dotnet fix
even1024 Jan 26, 2023
9e41c97
b64cdx java&dotnet fix
even1024 Jan 26, 2023
d416da5
diff fix
even1024 Jan 27, 2023
45348cb
Merge branch 'master' of https://github.com/epam/Indigo into feature/…
even1024 Jan 27, 2023
094f5d8
test fix
even1024 Jan 27, 2023
6526b7d
clang fix
even1024 Jan 27, 2023
f665783
mol_to_cdx.out deleted
even1024 Jan 27, 2023
3c8a781
clang fix
even1024 Jan 27, 2023
bf7649d
tests fix
even1024 Jan 27, 2023
33b0670
tests fix
even1024 Jan 27, 2023
d52e5c2
tests fix
even1024 Jan 27, 2023
f722542
tests fix
even1024 Jan 27, 2023
833f380
tests fix
even1024 Jan 27, 2023
1071d21
tests fix
even1024 Jan 27, 2023
e95d3dc
tests fix
even1024 Jan 27, 2023
fc714ed
tests fix
even1024 Jan 27, 2023
db4d5cb
fix dir
even1024 Jan 30, 2023
d50af9e
fix dir
even1024 Jan 30, 2023
97424c3
fix dir
even1024 Jan 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/indigo-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ jobs:
lfs: false
fetch-depth: 500
- name: Git fetch tags
run: git fetch --tags -f
run: |
git config --global --add safe.directory /__w/Indigo/Indigo
git fetch --tags -f
- name: Check
run: |
python3 -m pip install -r api/python/requirements_dev.txt
Expand Down
2 changes: 2 additions & 0 deletions api/c/indigo/indigo.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ CEXPORT int indigoSaveJson(int item, int output);
CEXPORT int indigoSaveCml(int object, int output);
CEXPORT int indigoSaveCmlToFile(int object, const char* filename);
CEXPORT const char* indigoCml(int object);
CEXPORT const char* indigoCdxBase64(int object);

// accepts molecules and reactions
CEXPORT int indigoSaveCdxml(int object, int output);
Expand Down Expand Up @@ -1021,6 +1022,7 @@ CEXPORT int indigoExpandAbbreviations(int molecule);
/* Other */

CEXPORT const char* indigoToString(int handle);
CEXPORT const char* indigoToBase64String(int handle);
CEXPORT int indigoToBuffer(int handle, char** buf, int* size);

/* Reaction products enumeration */
Expand Down
2 changes: 2 additions & 0 deletions api/c/indigo/src/indigo_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ class DLLEXPORT IndigoObject
virtual MonomersProperties& getMonomersProperties();
virtual void copyProperties(PropertiesMap&);

void toBase64String(Array<char>& str);

private:
IndigoObject(const IndigoObject&);
};
Expand Down
14 changes: 14 additions & 0 deletions api/c/indigo/src/indigo_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ CEXPORT const char* indigoToString(int handle)
INDIGO_END(0);
}

CEXPORT const char* indigoToBase64String(int handle)
{
INDIGO_BEGIN
{
IndigoObject& obj = self.getObject(handle);

auto& tmp = self.getThreadTmpData();
obj.toBase64String(tmp.string);
tmp.string.push(0);
return tmp.string.ptr();
}
INDIGO_END(0);
}

CEXPORT int indigoToBuffer(int handle, char** buf, int* size)
{
INDIGO_BEGIN
Expand Down
16 changes: 16 additions & 0 deletions api/c/indigo/src/indigo_macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ CEXPORT const char* indigoMolfile(int molecule)
return res;
}

CEXPORT const char* indigoCdxBase64(int object)
{
int b = indigoWriteBuffer();
const char* res;

if (b == -1)
return 0;

if (indigoSaveCdx(object, b) == -1)
return 0;

res = indigoToBase64String(b);
indigoFree(b);
return res;
}

CEXPORT const char* indigoCml(int molecule)
{
int b = indigoWriteBuffer();
Expand Down
16 changes: 12 additions & 4 deletions api/c/indigo/src/indigo_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
* limitations under the License.
***************************************************************************/

#include "indigo_internal.h"

#include <map>

#include "base_cpp/output.h"
#include "base_cpp/properties_map.h"
#include "indigo_internal.h"
#include "reaction/reaction.h"

#include <../cppcodec/cppcodec/base64_default_rfc4648.hpp>
#include <map>

using IndigoObjectTypesMap = std::map<int, const char* const>;
class IndigoObjectTypes : public IndigoObjectTypesMap, public NonCopyable
{
Expand Down Expand Up @@ -161,6 +161,14 @@ const char* IndigoObject::debugInfo() const
return getTypeName();
}

void IndigoObject::toBase64String(Array<char>& str)
{
Array<char> temp;
toString(temp);
auto encoded = base64::encode(temp.ptr(), temp.size());
str.copy(encoded.c_str(), encoded.size());
}

void IndigoObject::toString(Array<char>& str)
{
throw IndigoError("can not convert %s to string", debugInfo());
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 @@ -164,6 +164,9 @@ public unsafe class IndigoLib
[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern byte* indigoCdxml(int molecule);

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

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoSaveMDLCT(int item, int output);

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 @@ -112,6 +112,12 @@ public string cdxml()
return dispatcher.checkResult(IndigoLib.indigoCdxml(self));
}

public string b64cdx()
{
dispatcher.setSessionID();
return dispatcher.checkResult(IndigoLib.indigoCdxBase64(self));
}

public void saveCdxml(string filename)
{
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 @@ -140,6 +140,8 @@ public interface IndigoLib extends Library {

Pointer indigoCdxml(int object);

Pointer indigoCdxBase64(int object);

int indigoSaveMDLCT(int item, int output);

int indigoLoadReaction(int source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public String cdxml() {
return Indigo.checkResultString(this, lib.indigoCdxml(self));
}

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

public void saveCdxml(String filename) {
dispatcher.setSessionID();
Indigo.checkResult(this, lib.indigoSaveCdxmlToFile(self, filename));
Expand Down
4 changes: 4 additions & 0 deletions api/python/indigo/indigo/indigo_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,12 @@ def __init__(self) -> None:
IndigoLib.lib.indigoCml.argtypes = [c_int]
IndigoLib.lib.indigoSaveCdxmlToFile.restype = c_int
IndigoLib.lib.indigoSaveCdxmlToFile.argtypes = [c_int, c_char_p]
IndigoLib.lib.indigoSaveCdxToFile.restype = c_int
IndigoLib.lib.indigoSaveCdxToFile.argtypes = [c_int, c_char_p]
IndigoLib.lib.indigoCdxml.restype = c_char_p
IndigoLib.lib.indigoCdxml.argtypes = [c_int]
IndigoLib.lib.indigoCdxBase64.restype = c_char_p
IndigoLib.lib.indigoCdxBase64.argtypes = [c_int]
IndigoLib.lib.indigoJson.restype = c_char_p
IndigoLib.lib.indigoJson.argtypes = [c_int]
IndigoLib.lib.indigoSaveMDLCT.restype = c_int
Expand Down
25 changes: 25 additions & 0 deletions api/python/indigo/indigo/indigo_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,20 @@ def saveCdxml(self, filename):
self._lib().indigoSaveCdxmlToFile(self.id, filename.encode())
)

def saveCdx(self, filename):
"""Molecule method saves the structure into a CDX file

Args:
filename (str): full path to the output file

Returns:
int: 1 if the file is saved successfully
"""

return IndigoLib.checkResult(
self._lib().indigoSaveCdxToFile(self.id, filename.encode())
)

def cdxml(self):
"""Molecule method returns the structure as a string in CDXML format

Expand All @@ -305,6 +319,17 @@ def cdxml(self):

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

def b64cdx(self):
"""Molecule method returns the structure as a string in CDX base64 encoded format

Returns:
str: base64 encoded CDX string
"""

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

def json(self):
"""Structure method returns the structure as a string in KET format

Expand Down
5 changes: 5 additions & 0 deletions api/tests/integration/ref/formats/cdx_export.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*** Mol to CDX ***
enhanced_stereo1:success
enhanced_stereo2:success
enhanced_stereo3:success
stereo_either-0020:success
54 changes: 54 additions & 0 deletions api/tests/integration/tests/formats/cdx_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import difflib
import os
import sys


def find_diff(a, b):
return "\n".join(difflib.unified_diff(a.splitlines(), b.splitlines()))


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

indigo = Indigo()

print("*** Mol to CDX ***")

root = joinPathPy("molecules/", __file__)
files = [
"stereo_either-0020",
"enhanced_stereo1",
"enhanced_stereo2",
"enhanced_stereo3",
]

ref_path = joinPathPy("ref/", __file__)
files.sort()

for filename in files:
try:
mol = indigo.loadMoleculeFromFile(
os.path.join(root, filename + ".mol")
)
resb64 = mol.b64cdx()
# with open(os.path.join(ref_path, filename + ".cdxml"), 'w') as file:
# data = file.write(mol.cdxml())
with open(os.path.join(ref_path, filename + ".b64cdx"), "r") as file:
refb64 = file.read()
print(filename + (":success" if refb64 == resb64 else ":failed"))
except IndigoException as e:
print(getIndigoExceptionText(e))
print("*** Try as Query ***")
mol = indigo.loadQueryMoleculeFromFile(
os.path.join(root, filename + ".mol")
)
resb64 = mol.b64cdx()
# with open(os.path.join(ref_path, filename + ".cdxml"), 'w') as file:
# data = file.write(mol.cdxml())
with open(os.path.join(ref_path, filename + ".b64cdx"), "r") as file:
refb64 = file.read()
print(filename + (":success" if refb64 == resb64 else ":failed"))
Loading