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

#2552 - "Calculate Properties" for macromolecules #2743

Merged
merged 8 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions api/c/indigo/indigo.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ CEXPORT int indigoCountHydrogens(int item, int* hydro);
// Applicable to non-query molecules and atoms.
CEXPORT int indigoCountImplicitHydrogens(int item);

// Calculate macromolecule properties. Return Json string with properties.
CEXPORT const char* indigoMacroProperties(int object);

// On success, returns always the same pointer to a 3-element array;
// you should not free() it, but rather memcpy() it if you want to keep it.
CEXPORT float* indigoXYZ(int atom);
Expand Down
20 changes: 20 additions & 0 deletions api/c/indigo/src/indigo_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,26 @@ CEXPORT const char* indigoJson(int item)
INDIGO_END(0);
}

CEXPORT const char* indigoMacroProperties(int object)
{
INDIGO_BEGIN
{
auto& tmp = self.getThreadTmpData();
ArrayOutput out(tmp.string);

IndigoObject& obj = self.getObject(object);

if (IndigoBaseMolecule::is(obj) || IndigoBaseReaction::is(obj) || IndigoKetDocument::is(obj))
{
auto& doc = obj.getKetDocument();
doc.CalculateMacroProps(out, self.json_saving_pretty);
}
out.writeChar(0);
return tmp.string.ptr();
}
INDIGO_END(0);
}

CEXPORT const char* indigoGetOriginalFormat(int item)
{
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* indigoMacroProperties(int id);

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

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

public string macroProperties()
{
dispatcher.setSessionID();
return dispatcher.checkResult(IndigoLib.indigoMacroProperties(self));
}

public string getOriginalFormat()
{
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 indigoMacroProperties(int item);

Pointer indigoGetOriginalFormat(int item);

int indigoCreateMolecule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public String helm(IndigoObject library) {
return Indigo.checkResultString(this, lib.indigoHelm(self, library.self));
}

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

public String getOriginalFormat() {
dispatcher.setSessionID();
return Indigo.checkResultString(this, lib.indigoGetOriginalFormat(self));
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 @@ -286,6 +286,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.indigoMacroProperties.restype = c_char_p
IndigoLib.lib.indigoMacroProperties.argtypes = [c_int]
IndigoLib.lib.indigoGetOriginalFormat.restype = c_char_p
IndigoLib.lib.indigoGetOriginalFormat.argtypes = [c_int]
IndigoLib.lib.indigoSaveMolfileToFile.restype = c_int
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 macroProperties(self):
"""Method return macro-molecules properties

Returns:
str: json with properties
"""

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

def getOriginalFormat(self):
"""Molecule method return format molecule loaded from

Expand Down
4 changes: 4 additions & 0 deletions api/tests/integration/ref/formats/macromol_props.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*** HELM to KET ***
props_double_dna.json: SUCCEED
props_peptides.json: SUCCEED
props_peptides_micro.json: SUCCEED
56 changes: 56 additions & 0 deletions api/tests/integration/tests/formats/macromol_props.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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,
IndigoException,
getIndigoExceptionText,
joinPathPy,
)

indigo = Indigo()
indigo.setOption("json-saving-pretty", True)
indigo.setOption("ignore-stereochemistry-errors", True)

print("*** HELM to KET ***")

root = joinPathPy("molecules/", __file__)
ref = joinPathPy("ref/", __file__)

macro_data = [
"props_double_dna",
"props_peptides",
"props_peptides_micro",
]

lib = indigo.loadMonomerLibraryFromFile(
os.path.join(ref, "monomer_library.ket")
)

for filename in sorted(macro_data):
mol = indigo.loadKetDocumentFromFile(os.path.join(root, filename + ".ket"))
try:
props = mol.macroProperties()
except IndigoException as e:
print("Test '%s' filed: %", (filename, getIndigoExceptionText(e)))
# with open(os.path.join(ref, filename) + ".json", "w") as file:
# file.write(props)
with open(os.path.join(ref, filename) + ".json", "r") as file:
props_ref = file.read()
diff = find_diff(props_ref, props)
if not diff:
print(filename + ".json: SUCCEED")
else:
print(filename + ".json: FAILED")
print(diff)
Loading
Loading