Skip to content

Commit 2758171

Browse files
#1322 Reaction cannon be saved in convert fuction (#1323)
1 parent af0c1a2 commit 2758171

File tree

11 files changed

+106
-33
lines changed

11 files changed

+106
-33
lines changed

api/c/indigo/src/indigo_misc.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,3 +1484,51 @@ CEXPORT const char* indigoJson(int item)
14841484
}
14851485
INDIGO_END(0);
14861486
}
1487+
1488+
CEXPORT const char* indigoGetOriginalFormat(int item)
1489+
{
1490+
INDIGO_BEGIN
1491+
{
1492+
IndigoObject& obj = self.getObject(item);
1493+
int original_format = BaseMolecule::UNKNOWN;
1494+
if (IndigoBaseMolecule::is(obj))
1495+
{
1496+
BaseMolecule& mol = obj.getBaseMolecule();
1497+
original_format = mol.original_format;
1498+
}
1499+
else if (IndigoBaseReaction::is(obj))
1500+
{
1501+
BaseReaction& rxn = obj.getBaseReaction();
1502+
original_format = rxn.original_format;
1503+
}
1504+
else
1505+
throw IndigoError("indigoSaveJson(): expected molecule, got %s", obj.debugInfo());
1506+
1507+
switch (original_format)
1508+
{
1509+
case BaseMolecule::CML:
1510+
return "chemical/x-cml";
1511+
case BaseMolecule::CDXML:
1512+
return "chemical/x-cdxml";
1513+
case BaseMolecule::CDX:
1514+
return "chemical/x-cdx";
1515+
case BaseMolecule::RDF:
1516+
return "chemical/x-mdl-rdfile";
1517+
case BaseMolecule::SMILES:
1518+
return "chemical/x-daylight-smiles";
1519+
case BaseMolecule::CXSMILES:
1520+
return "chemical/x-chemaxon-cxsmiles";
1521+
case BaseMolecule::SMARTS:
1522+
return "chemical/x-daylight-smarts";
1523+
case BaseMolecule::MOL:
1524+
return "chemical/x-mdl-molfile";
1525+
case BaseMolecule::RXN:
1526+
return "chemical/x-mdl-rxnfile";
1527+
case BaseMolecule::KET:
1528+
return "chemical/x-indigo-ket";
1529+
default:
1530+
return "unknown";
1531+
}
1532+
}
1533+
INDIGO_END(0);
1534+
}

api/c/indigo/src/indigo_molecule.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,34 +3784,6 @@ CEXPORT int indigoCountComponentBonds(int molecule, int index)
37843784
INDIGO_END(-1);
37853785
}
37863786

3787-
CEXPORT const char* indigoGetOriginalFormat(int item)
3788-
{
3789-
INDIGO_BEGIN
3790-
{
3791-
IndigoObject& obj = self.getObject(item);
3792-
if (IndigoBaseMolecule::is(obj))
3793-
{
3794-
BaseMolecule& mol = obj.getBaseMolecule();
3795-
switch (mol.original_format)
3796-
{
3797-
case BaseMolecule::SMARTS:
3798-
return "chemical/x-daylight-smarts";
3799-
case BaseMolecule::SMILES:
3800-
return "chemical/x-daylight-smiles";
3801-
case BaseMolecule::MOL:
3802-
return "chemical/x-mdl-molfile";
3803-
case BaseMolecule::RXN:
3804-
return "chemical/x-mdl-rxnfile";
3805-
default:
3806-
return "unknown";
3807-
}
3808-
}
3809-
else
3810-
throw IndigoError("indigoSaveJson(): expected molecule, got %s", obj.debugInfo());
3811-
}
3812-
INDIGO_END(0);
3813-
}
3814-
38153787
CEXPORT int indigoCreateMolecule()
38163788
{
38173789
INDIGO_BEGIN

api/tests/integration/ref/basic/get_original_format.py.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
Molecule "N[CH](C)C(=O)O" : got "chemical/x-daylight-smiles" - OK
33
****** Test get original format: smarts ***
44
Molecule "([#6]1-[#6]-[#6]-1.[#6])" : got "chemical/x-daylight-smarts" - OK
5+
****** Test get original format: reaction ***
6+
Molecule "N[CH](C)C(=O)O>>N[CH](C)C" : got "chemical/x-daylight-smiles" - OK
7+
****** Test get original format: reaction smarts ***
8+
Molecule "([#6]1-[#6]-[#6]-1.[#6])>>([#6]1-[#6]-[#6]-1.[#6]=O)" : got "chemical/x-daylight-smarts" - OK

api/tests/integration/tests/basic/get_original_format.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
indigo = Indigo()
1212

1313

14-
def test_mol(molecule, mol, expected):
15-
original_format = mol.getOriginalFormat()
14+
def test_mol(smarts, obj, expected):
15+
original_format = obj.getOriginalFormat()
1616
if original_format == expected:
17-
print('Molecule "%s" : got "%s" - OK' % (molecule, expected))
17+
print('Molecule "%s" : got "%s" - OK' % (smarts, expected))
1818
else:
1919
print(
2020
'Molecule "%s" failed: expected original format "%s", got "%s"'
21-
% (molecule, expected, original_format)
21+
% (smarts, expected, original_format)
2222
)
2323

2424

@@ -31,3 +31,13 @@ def test_mol(molecule, mol, expected):
3131
molecule = "([#6]1-[#6]-[#6]-1.[#6])"
3232
mol = indigo.loadSmarts(molecule)
3333
test_mol(molecule, mol, "chemical/x-daylight-smarts")
34+
35+
print("****** Test get original format: reaction ***")
36+
molecule = "N[CH](C)C(=O)O>>N[CH](C)C"
37+
mol = indigo.loadReaction(molecule)
38+
test_mol(molecule, mol, "chemical/x-daylight-smiles")
39+
40+
print("****** Test get original format: reaction smarts ***")
41+
molecule = "([#6]1-[#6]-[#6]-1.[#6])>>([#6]1-[#6]-[#6]-1.[#6]=O)"
42+
mol = indigo.loadReactionSmarts(molecule)
43+
test_mol(molecule, mol, "chemical/x-daylight-smarts")

api/wasm/indigo-ketcher/indigo-ketcher.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ namespace indigo
314314
return IndigoKetcherObject(objectId, IndigoKetcherObject::EKETMoleculeQuery);
315315
}
316316
exceptionMessages.emplace_back(indigoGetLastError());
317+
// Let's try reaction
318+
print_js("try as reaction");
319+
objectId = indigoLoadReactionSmartsFromBuffer(data.c_str(), data.size());
320+
if (objectId >= 0)
321+
{
322+
return IndigoKetcherObject(objectId, IndigoKetcherObject::EKETReaction);
323+
}
324+
exceptionMessages.emplace_back(indigoGetLastError());
317325
}
318326
else
319327
{

api/wasm/indigo-ketcher/test/test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,23 @@ M END
512512
options.delete();
513513
});
514514

515+
test("convert", "rsmiles-app-json", () => {
516+
let options = new indigo.MapStringString();
517+
options.set("output-content-type", "application/json");
518+
const rsmiles = indigo.convert(rxn_smiles, "smiles", options);
519+
assert.equal(rsmiles, '{"struct":"C1C=CC=CC=1.N>>C1N=CC=CC=1.[CH3-]","format":"smiles","original_format":"chemical/x-daylight-smiles"}');
520+
options.delete();
521+
});
522+
523+
test("convert", "rsmiles-input-format-smarts", () => {
524+
let options = new indigo.MapStringString();
525+
options.set("output-content-type", "application/json");
526+
options.set("input-format", "chemical/x-daylight-smarts");
527+
const rsmiles = indigo.convert(rxn_smiles, "smiles", options);
528+
assert.equal(rsmiles, '{"struct":"C1C=CC=CC=1.N>>C1N=CC=CC=1.[CH3-]","format":"smiles","original_format":"chemical/x-daylight-smarts"}');
529+
options.delete();
530+
});
531+
515532
}
516533

517534

core/indigo-core/molecule/src/molecule_json_loader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ void MoleculeJsonLoader::loadMolecule(BaseMolecule& mol, bool load_arrows)
10611061
{
10621062
_pmol = &pmol->asMolecule();
10631063
}
1064+
mol.original_format = BaseMolecule::KET;
10641065

10651066
auto& mol_node = _mol_nodes[node_idx];
10661067
if (mol_node.HasMember("atoms"))

core/indigo-core/reaction/base_reaction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ namespace indigo
321321

322322
Array<char> name;
323323

324+
int original_format;
325+
324326
DECL_ERROR;
325327

326328
protected:

core/indigo-core/reaction/src/base_reaction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ SideIter SideAuto::end()
9191
}
9292

9393
BaseReaction::BaseReaction()
94-
: reactants(*this, REACTANT), catalysts(*this, CATALYST), products(*this, PRODUCT), intermediates(*this, INTERMEDIATE), undefined(*this, UNDEFINED)
94+
: reactants(*this, REACTANT), catalysts(*this, CATALYST), products(*this, PRODUCT), intermediates(*this, INTERMEDIATE), undefined(*this, UNDEFINED),
95+
original_format(BaseMolecule::UNKNOWN)
9596
{
9697
clear();
9798
}

core/indigo-core/reaction/src/reaction_json_loader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ void ReactionJsonLoader::loadReaction(BaseReaction& rxn)
6868
else
6969
throw Error("unknown reaction type: %s", typeid(rxn).name());
7070

71+
rxn.original_format = BaseMolecule::KET;
72+
7173
rxn.meta().clone(_pmol->meta());
7274
_pmol->meta().resetMetaData();
7375

0 commit comments

Comments
 (0)