Skip to content

Commit

Permalink
Backmerge: #2713 - Support for the star atom (*) (#2766)
Browse files Browse the repository at this point in the history
  • Loading branch information
AliaksandrDziarkach authored Feb 13, 2025
1 parent b9b9386 commit 4909444
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 96 deletions.
2 changes: 1 addition & 1 deletion api/c/indigo/src/indigo_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ int indigoIterateMatches(int target_matcher, int query)
{
IndigoMoleculeSubstructureMatcher& matcher = IndigoMoleculeSubstructureMatcher::cast(obj);

if (matcher.tau_params.method != BASIC && matcher.mode == IndigoMoleculeSubstructureMatcher::TAUTOMER)
if (matcher.mode == IndigoMoleculeSubstructureMatcher::TAUTOMER && matcher.tau_params.method != BASIC)
{
std::unique_ptr<IndigoTautomerSubstructureMatchIter> match_iter(
matcher.getTautomerMatchIterator(self, query, true, self.max_embeddings, matcher.tau_params.method));
Expand Down
3 changes: 3 additions & 0 deletions api/tests/integration/ref/formats/2713-star-atom.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*** 2713 star atom support ***
star_atom ket : SUCCEED
star_atom scxmiles : SUCCEED
50 changes: 50 additions & 0 deletions api/tests/integration/tests/formats/2713-star-atom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 Indigo, joinPathPy # noqa

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

print("*** 2713 star atom support ***")

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

filename = "star_atom"
expected_smiles = "*C.*N.*O |$;;AH_p;;star_e;$|"

mol = indigo.loadQueryMolecule(expected_smiles)

# with open(os.path.join(ref_path, filename) + ".ket", "w") as file:
# file.write(mol.json())
with open(os.path.join(ref_path, filename) + ".ket", "r") as file:
ket_ref = file.read()
ket = mol.json()
diff = find_diff(ket_ref, ket)
if not diff:
print(filename + " ket : SUCCEED")
else:
print(filename + " ket : FAILED")
print(diff)
indigo.setOption("smiles-saving-format", "chemaxon")
smiles3 = mol.smiles()
diff = find_diff(smiles3, smiles3)
if not diff:
print(filename + " scxmiles : SUCCEED")
else:
print(filename + " scxmiles : FAILED")
print(diff)
4 changes: 2 additions & 2 deletions api/tests/integration/tests/formats/ket_cdxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def find_diff(a, b):
print(getIndigoExceptionText(e))
raise SystemExit
cdxml_text = ket.cdxml()
with open(os.path.join(ref_path, filename) + ".cdxml", "w") as file:
file.write(cdxml_text)
# with open(os.path.join(ref_path, filename) + ".cdxml", "w") as file:
# file.write(cdxml_text)

indigo.loadMolecule(
cdxml_text
Expand Down
168 changes: 84 additions & 84 deletions api/tests/integration/tests/formats/ref/macro/sa-mono.cdxml
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE CDXML SYSTEM "http://www.cambridgesoft.com/xml/cdxml.dtd">
<CDXML BondLength="30.000000" LabelFont="3" CaptionFont="4">
<fonttable id="1">
<font id="2" charset="utf-8" name="Arial"/>
<font id="3" charset="utf-8" name="Times New Roman"/>
</fonttable>
<colortable>
<color r="1" g="1" b="1"/>
<color r="0" g="0" b="0"/>
<color r="1" g="0" b="0"/>
<color r="1" g="1" b="0"/>
<color r="0" g="1" b="0"/>
<color r="0" g="1" b="1"/>
<color r="0" g="0" b="1"/>
<color r="1" g="0" b="1"/>
<color r="0.5" g="0.5" b="0.5"/>
</colortable>
<page HeightPages="1" WidthPages="1" BoundingBox="439.795471 354.751007 503.250000 232.500000">
<fragment id="4">
<n id="29" NodeType="Fragment">
<fragment id="31">
<n id="16" Element="8" NumHydrogens="1" p="111.163788 -6.171985">
<t p="111.163788 -6.171985" LabelJustification="Left">
<s font="3" size="10" face="96">OH</s>
</t>
</n>
<n id="32" NodeType="ExternalConnectionPoint"/>
<b id="34" B="32" E="16"/>
</fragment>
<t LabelJustification="Left" LabelAlignment="Above">
<s>OH</s>
</t>
</n>
<n id="30" NodeType="Fragment" BondOrdering="37 33">
<fragment id="35" ConnectionOrder="36 38">
<n id="11" Element="7" NumHydrogens="1" p="34.038506 9.188833">
<t p="34.038506 9.188833" LabelJustification="Left">
<s font="3" size="10" face="96">NH</s>
</t>
</n>
<n id="36" NodeType="ExternalConnectionPoint"/>
<n id="12" p="57.078609 -6.171985" Geometry="Tetrahedral" BondOrdering="11 13 14 5" EnhancedStereoType="Absolute"/>
<n id="13" p="56.180820 -40.770763"/>
<n id="14" p="88.121399 9.188833"/>
<n id="38" NodeType="ExternalConnectionPoint"/>
<n id="15" Element="8" NumHydrogens="0" p="88.838654 36.853783">
<t p="88.838654 36.853783" LabelJustification="Left">
<s font="3" size="10" face="96">O</s>
</t>
</n>
<b id="23" B="12" E="11"/>
<b id="24" B="12" E="13" Display="WedgeBegin"/>
<b id="25" B="12" E="14"/>
<b id="26" B="14" E="15" Order="2"/>
<b id="39" B="36" E="11"/>
<b id="40" B="38" E="14"/>
</fragment>
<t LabelJustification="Left" LabelAlignment="Above">
<s>A</s>
</t>
</n>
<n id="5" p="0.000000 77.252228"/>
<n id="6" p="51.909027 77.237663"/>
<n id="7" p="26.003637 62.248993"/>
<n id="8" p="51.909027 107.265961"/>
<n id="9" p="0.000000 107.400597"/>
<n id="10" p="26.069155 122.250992"/>
<b id="17" B="7" E="5" Order="2"/>
<b id="18" B="5" E="9"/>
<b id="19" B="9" E="10" Order="2"/>
<b id="20" B="10" E="8"/>
<b id="21" B="8" E="6" Order="2"/>
<b id="22" B="6" E="7"/>
<b id="33" B="30" E="29"/>
<b id="37" B="7" E="30"/>
<graphic BoundingBox="51.909027 62.248993 51.909027 62.248993" GraphicType="Symbol" SymbolType="Absolute" FrameType="None">
<t p="51.909027 62.248993" Justification="Center" InterpretChemically="no">
<s font="3" size="10" face="96">Chiral</s>
</t>
</graphic>
</fragment>
</page>
</CDXML>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE CDXML SYSTEM "http://www.cambridgesoft.com/xml/cdxml.dtd">
<CDXML BondLength="30.000000" LabelFont="3" CaptionFont="4">
<fonttable id="1">
<font id="2" charset="utf-8" name="Arial"/>
<font id="3" charset="utf-8" name="Times New Roman"/>
</fonttable>
<colortable>
<color r="1" g="1" b="1"/>
<color r="0" g="0" b="0"/>
<color r="1" g="0" b="0"/>
<color r="1" g="1" b="0"/>
<color r="0" g="1" b="0"/>
<color r="0" g="1" b="1"/>
<color r="0" g="0" b="1"/>
<color r="1" g="0" b="1"/>
<color r="0.5" g="0.5" b="0.5"/>
</colortable>
<page HeightPages="1" WidthPages="1" BoundingBox="439.795471 354.751007 503.250000 232.500000">
<fragment id="4">
<n id="29" NodeType="Fragment">
<fragment id="31">
<n id="16" Element="8" NumHydrogens="1" p="111.163788 -6.171985">
<t p="111.163788 -6.171985" LabelJustification="Left">
<s font="3" size="10" face="96">OH</s>
</t>
</n>
<n id="32" NodeType="ExternalConnectionPoint"/>
<b id="34" B="32" E="16"/>
</fragment>
<t LabelJustification="Left" LabelAlignment="Above">
<s>OH</s>
</t>
</n>
<n id="30" NodeType="Fragment" BondOrdering="37 33">
<fragment id="35" ConnectionOrder="36 38">
<n id="11" Element="7" NumHydrogens="1" p="34.038506 9.188833">
<t p="34.038506 9.188833" LabelJustification="Left">
<s font="3" size="10" face="96">NH</s>
</t>
</n>
<n id="36" NodeType="ExternalConnectionPoint"/>
<n id="12" p="57.078609 -6.171985" Geometry="Tetrahedral" BondOrdering="11 13 14 5" EnhancedStereoType="Absolute"/>
<n id="13" p="56.180820 -40.770763"/>
<n id="14" p="88.121399 9.188833"/>
<n id="38" NodeType="ExternalConnectionPoint"/>
<n id="15" Element="8" NumHydrogens="0" p="88.838654 36.853783">
<t p="88.838654 36.853783" LabelJustification="Left">
<s font="3" size="10" face="96">O</s>
</t>
</n>
<b id="23" B="12" E="11"/>
<b id="24" B="12" E="13" Display="WedgeBegin"/>
<b id="25" B="12" E="14"/>
<b id="26" B="14" E="15" Order="2"/>
<b id="39" B="36" E="11"/>
<b id="40" B="38" E="14"/>
</fragment>
<t LabelJustification="Left" LabelAlignment="Above">
<s>A</s>
</t>
</n>
<n id="5" p="0.000000 77.252228"/>
<n id="6" p="51.909027 77.237663"/>
<n id="7" p="26.003637 62.248993"/>
<n id="8" p="51.909027 107.265961"/>
<n id="9" p="0.000000 107.400597"/>
<n id="10" p="26.069155 122.250992"/>
<b id="17" B="7" E="5" Order="2"/>
<b id="18" B="5" E="9"/>
<b id="19" B="9" E="10" Order="2"/>
<b id="20" B="10" E="8"/>
<b id="21" B="8" E="6" Order="2"/>
<b id="22" B="6" E="7"/>
<b id="33" B="30" E="29"/>
<b id="37" B="7" E="30"/>
<graphic BoundingBox="51.909027 62.248993 51.909027 62.248993" GraphicType="Symbol" SymbolType="Absolute" FrameType="None">
<t p="51.909027 62.248993" Justification="Center" InterpretChemically="no">
<s font="3" size="10" face="96">Chiral</s>
</t>
</graphic>
</fragment>
</page>
</CDXML>
106 changes: 106 additions & 0 deletions api/tests/integration/tests/formats/ref/star_atom.ket
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"root": {
"nodes": [
{
"$ref": "mol0"
},
{
"$ref": "mol1"
},
{
"$ref": "mol2"
}
]
},
"mol0": {
"type": "molecule",
"atoms": [
{
"label": "A",
"location": [
0.0,
0.0,
0.0
]
},
{
"label": "C",
"location": [
1.0,
0.0,
0.0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
}
]
},
"mol1": {
"type": "molecule",
"atoms": [
{
"label": "AH",
"location": [
3.0,
0.0,
0.0
]
},
{
"label": "N",
"location": [
4.0,
0.0,
0.0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
}
]
},
"mol2": {
"type": "molecule",
"atoms": [
{
"label": "*",
"alias": "*",
"location": [
0.0,
2.0,
0.0
]
},
{
"label": "O",
"location": [
1.0,
2.0,
0.0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
}
]
}
}
8 changes: 6 additions & 2 deletions core/indigo-core/molecule/src/molecule_json_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ int MoleculeJsonLoader::addBondToMoleculeQuery(int beg, int end, int order, int
int MoleculeJsonLoader::addAtomToMoleculeQuery(const char* label, int element, int charge, int valence, int radical, int isotope)
{
std::unique_ptr<QueryMolecule::Atom> atom = std::make_unique<QueryMolecule::Atom>();
int atom_type = QueryMolecule::QUERY_ATOM_UNKNOWN;
if (element != -1 && element < ELEM_MAX)
atom = std::make_unique<QueryMolecule::Atom>(QueryMolecule::ATOM_NUMBER, element);
else if (element == ELEM_ATOMLIST)
Expand All @@ -154,7 +155,7 @@ int MoleculeJsonLoader::addAtomToMoleculeQuery(const char* label, int element, i
}
else
{
int atom_type = QueryMolecule::getAtomType(label);
atom_type = QueryMolecule::getAtomType(label);
switch (atom_type)
{
case _ATOM_PSEUDO:
Expand Down Expand Up @@ -242,7 +243,10 @@ int MoleculeJsonLoader::addAtomToMoleculeQuery(const char* label, int element, i
if (radical != 0)
atom.reset(QueryMolecule::Atom::und(atom.release(), new QueryMolecule::Atom(QueryMolecule::ATOM_RADICAL, radical)));

return _pqmol->addAtom(atom.release());
auto atom_idx = _pqmol->addAtom(atom.release());
if (label != nullptr && label[0] == '*' && label[1] == 0)
_pqmol->setAlias(atom_idx, label);
return atom_idx;
}

void MoleculeJsonLoader::validateMoleculeBond(int order)
Expand Down
Loading

0 comments on commit 4909444

Please sign in to comment.