Skip to content

Commit

Permalink
#2422 - Indigo functions doesn't work prorerly: Aromatize, Dearomati…
Browse files Browse the repository at this point in the history
…ze, Layout, Clean Up, Hydrogens, Auto-Mapping Tool

Cherry-pick fix into release 1.25
  • Loading branch information
AliaksandrDziarkach committed Oct 14, 2024
1 parent 3965eb7 commit 687417b
Show file tree
Hide file tree
Showing 37 changed files with 384 additions and 202 deletions.
10 changes: 8 additions & 2 deletions api/c/indigo/src/indigo_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ CEXPORT int indigoLayout(int object)
if (rxn.isPathwayReaction())
{
PathwayLayout pl(static_cast<PathwayReaction&>(rxn), self.layout_options);
pl.setPreserveMoleculeLayout(false);
pl.make();
}
else
Expand Down Expand Up @@ -184,10 +185,15 @@ CEXPORT int indigoClean2d(int object)
if (IndigoBaseReaction::is(obj))
{
BaseReaction& rxn = obj.getBaseReaction();
for (int i = rxn.begin(); i < rxn.end(); i = rxn.next(i))
if (rxn.isPathwayReaction())
{
MoleculeCleaner2d::clean(rxn.getBaseMolecule(i));
auto& pwr = rxn.asPathwayReaction();
for (int i = 0; i < pwr.getMoleculeCount(); i++)
MoleculeCleaner2d::clean(pwr.getMolecule(i));
}
else
for (int i = rxn.begin(); i < rxn.end(); i = rxn.next(i))
MoleculeCleaner2d::clean(rxn.getBaseMolecule(i));
}
else
throw IndigoError("Clean2d can be executed only for molecules but %s was provided", obj.debugInfo());
Expand Down
122 changes: 94 additions & 28 deletions api/c/indigo/src/indigo_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,24 +507,53 @@ CEXPORT int indigoUnfoldHydrogens(int item)
{
BaseReaction& rxn = obj.getBaseReaction();
bool has_coords = false;
bool only_selected = false;
for (int i = rxn.begin(); i != rxn.end(); i = rxn.next(i))
if (MoleculeHasCoords(rxn.getBaseMolecule(i)))
bool selected_only = false;
if (rxn.isPathwayReaction())
{
auto& pwr = rxn.asPathwayReaction();
for (int i = 0; i < pwr.getMoleculeCount(); ++i)
{
has_coords = true;
break;
if (MoleculeHasCoords(pwr.getMolecule(i)))
{
has_coords = true;
break;
}
}

for (int i = rxn.begin(); i != rxn.end(); i = rxn.next(i))
if (rxn.getBaseMolecule(i).countSelectedAtoms() > 0)
for (int i = 0; i < pwr.getMoleculeCount(); ++i)
{
only_selected = true;
break;
if (pwr.getMolecule(i).countSelectedAtoms() > 0)
{
selected_only = true;
break;
}
}

for (int i = rxn.begin(); i != rxn.end(); i = rxn.next(i))
for (int i = 0; i < pwr.getMoleculeCount(); ++i)
{
UnfoldAndLayoutHydrogens(pwr.getMolecule(i), selected_only, has_coords);
}
}
else
{
UnfoldAndLayoutHydrogens(rxn.getBaseMolecule(i), only_selected, has_coords);
for (int i = rxn.begin(); i != rxn.end(); i = rxn.next(i))
if (MoleculeHasCoords(rxn.getBaseMolecule(i)))
{
has_coords = true;
break;
}

for (int i = rxn.begin(); i != rxn.end(); i = rxn.next(i))
if (rxn.getBaseMolecule(i).countSelectedAtoms() > 0)
{
selected_only = true;
break;
}

for (int i = rxn.begin(); i != rxn.end(); i = rxn.next(i))
{
UnfoldAndLayoutHydrogens(rxn.getBaseMolecule(i), selected_only, has_coords);
}
}
}
else
Expand Down Expand Up @@ -566,18 +595,39 @@ CEXPORT int indigoFoldUnfoldHydrogens(int item)
else if (IndigoBaseReaction::is(obj))
{
BaseReaction& brxn = obj.getBaseReaction();
for (int i = brxn.begin(); i != brxn.end(); i = brxn.next(i))
if (brxn.getBaseMolecule(i).countSelectedAtoms() > 0)
{
selected_only = true;
break;
}
for (int i = brxn.begin(); i != brxn.end(); i = brxn.next(i))
if (hasConvertableToImplicitHydrogen(brxn.getBaseMolecule(i), selected_only))
if (brxn.isPathwayReaction())
{
auto& pwr = brxn.asPathwayReaction();
for (int i = 0; i < pwr.getMoleculeCount(); ++i)
{
fold = true;
break;
if (pwr.getMolecule(i).countSelectedAtoms() > 0)
{
selected_only = true;
break;
}
}
for (int i = 0; i < pwr.getMoleculeCount(); ++i)
if (hasConvertableToImplicitHydrogen(pwr.getMolecule(i), selected_only))
{
fold = true;
break;
}
}
else
{
for (int i = brxn.begin(); i != brxn.end(); i = brxn.next(i))
if (brxn.getBaseMolecule(i).countSelectedAtoms() > 0)
{
selected_only = true;
break;
}
for (int i = brxn.begin(); i != brxn.end(); i = brxn.next(i))
if (hasConvertableToImplicitHydrogen(brxn.getBaseMolecule(i), selected_only))
{
fold = true;
break;
}
}
}
else
{
Expand Down Expand Up @@ -634,18 +684,34 @@ CEXPORT int indigoFoldHydrogens(int item)
}
else if (IndigoBaseReaction::is(obj))
{
int i;
BaseReaction& rxn = obj.getBaseReaction();
bool selected_only = false;
for (i = rxn.begin(); i != rxn.end(); i = rxn.next(i))
if (rxn.getBaseMolecule(i).countSelectedAtoms() > 0)
if (rxn.isPathwayReaction())
{
auto& pwr = rxn.asPathwayReaction();
for (int i = 0; i < pwr.getMoleculeCount(); ++i)
{
selected_only = true;
break;
if (pwr.getMolecule(i).countSelectedAtoms() > 0)
{
selected_only = true;
break;
}
}
for (int i = 0; i < pwr.getMoleculeCount(); ++i)
_removeHydrogens(pwr.getMolecule(i), selected_only);
}
else
{
for (int i = rxn.begin(); i != rxn.end(); i = rxn.next(i))
if (rxn.getBaseMolecule(i).countSelectedAtoms() > 0)
{
selected_only = true;
break;
}

for (i = rxn.begin(); i != rxn.end(); i = rxn.next(i))
_removeHydrogens(rxn.getBaseMolecule(i), selected_only);
for (int i = rxn.begin(); i != rxn.end(); i = rxn.next(i))
_removeHydrogens(rxn.getBaseMolecule(i), selected_only);
}
}
else
throw IndigoError("indigoFoldHydrogens(): %s given", obj.debugInfo());
Expand Down
5 changes: 2 additions & 3 deletions api/c/indigo/src/indigo_savers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,9 @@ CEXPORT int indigoSaveCdx(int item, int output)
if (IndigoBaseReaction::is(obj))
{
ReactionCdxmlSaver saver(out, true);
if (obj.type == IndigoObject::REACTION)
if (obj.type == IndigoObject::REACTION || obj.type == IndigoObject::PATHWAY_REACTION)
{
Reaction& rxn = obj.getReaction();
saver.saveReaction(rxn);
saver.saveReaction(obj.getBaseReaction());
}
else if (obj.type == IndigoObject::QUERY_REACTION)
{
Expand Down
11 changes: 11 additions & 0 deletions api/tests/integration/ref/reaction/pathway_ops.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*** PATHWAY AROMATIZE/DEAROMATIZE ***
pathway1.rdf:SUCCEED
pathway2.rdf:SUCCEED
pathway3.rdf:SUCCEED
pathway4.rdf:SUCCEED
pathway5.rdf:SUCCEED
pathway6.rdf:SUCCEED
pathway7.rdf:SUCCEED
pathway8.rdf:SUCCEED
pathway9.rdf:SUCCEED
pathway10.rdf:SUCCEED
87 changes: 42 additions & 45 deletions api/tests/integration/tests/formats/ref/pathway1.cdxml
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@
<n id="8" p="98.053192 -172.899597"/>
<n id="9" p="15.000010 -172.683609"/>
<n id="10" p="56.711403 -148.923965"/>
<b id="59" B="7" E="5" Order="2"/>
<b id="60" B="5" E="9"/>
<b id="61" B="9" E="10" Order="2"/>
<b id="62" B="10" E="8"/>
<b id="63" B="8" E="6" Order="2"/>
<b id="64" B="6" E="7"/>
<b id="58" B="7" E="5" Order="2"/>
<b id="59" B="5" E="9"/>
<b id="60" B="9" E="10" Order="2"/>
<b id="61" B="10" E="8"/>
<b id="62" B="8" E="6" Order="2"/>
<b id="63" B="6" E="7"/>
</fragment>
<fragment id="11">
<n id="12" p="56.526604 -73.923943"/>
<n id="13" p="80.545532 -0.000000"/>
<n id="14" p="95.391754 -45.421871"/>
<n id="15" p="32.512493 -0.000000"/>
<n id="16" p="17.661453 -45.421871"/>
<b id="65" B="12" E="16"/>
<b id="66" B="16" E="15" Order="2"/>
<b id="67" B="15" E="13"/>
<b id="68" B="13" E="14" Order="2"/>
<b id="69" B="14" E="12"/>
<b id="64" B="12" E="16"/>
<b id="65" B="16" E="15" Order="2"/>
<b id="66" B="15" E="13"/>
<b id="67" B="13" E="14" Order="2"/>
<b id="68" B="14" E="12"/>
</fragment>
<fragment id="17">
<n id="18" p="495.132690 -140.943573"/>
Expand All @@ -51,13 +51,13 @@
<n id="22" p="578.272705 -140.943573"/>
<n id="23" p="536.700317 -164.943359"/>
<n id="24" p="619.840393 -164.943359"/>
<b id="70" B="23" E="18"/>
<b id="71" B="18" E="19"/>
<b id="72" B="19" E="20"/>
<b id="73" B="20" E="21"/>
<b id="74" B="21" E="22"/>
<b id="75" B="22" E="23"/>
<b id="76" B="22" E="24"/>
<b id="69" B="23" E="18"/>
<b id="70" B="18" E="19"/>
<b id="71" B="19" E="20"/>
<b id="72" B="20" E="21"/>
<b id="73" B="21" E="22"/>
<b id="74" B="22" E="23"/>
<b id="75" B="22" E="24"/>
</fragment>
<fragment id="25">
<n id="26" p="552.919373 -496.768616"/>
Expand All @@ -67,13 +67,13 @@
<n id="30" p="514.053833 -468.266327"/>
<n id="31" p="552.919373 -544.768555"/>
<n id="32" p="600.919250 -544.768555"/>
<b id="77" B="26" E="30"/>
<b id="78" B="30" E="29" Order="2"/>
<b id="79" B="29" E="27"/>
<b id="80" B="27" E="28" Order="2"/>
<b id="81" B="28" E="26"/>
<b id="82" B="26" E="31" Order="2"/>
<b id="83" B="31" E="32"/>
<b id="76" B="26" E="30"/>
<b id="77" B="30" E="29" Order="2"/>
<b id="78" B="29" E="27"/>
<b id="79" B="27" E="28" Order="2"/>
<b id="80" B="28" E="26"/>
<b id="81" B="26" E="31" Order="2"/>
<b id="82" B="31" E="32"/>
</fragment>
<fragment id="33">
<n id="34" p="528.083740 -318.203552"/>
Expand All @@ -84,14 +84,14 @@
<n id="39" p="612.449646 -250.623489"/>
<n id="40" p="565.711426 -239.943359"/>
<n id="41" p="481.719940 -330.626129"/>
<b id="84" B="35" E="34"/>
<b id="85" B="34" E="38"/>
<b id="86" B="38" E="40"/>
<b id="87" B="40" E="39"/>
<b id="88" B="39" E="37"/>
<b id="89" B="37" E="36"/>
<b id="90" B="36" E="35"/>
<b id="91" B="34" E="41"/>
<b id="83" B="35" E="34"/>
<b id="84" B="34" E="38"/>
<b id="85" B="38" E="40"/>
<b id="86" B="40" E="39"/>
<b id="87" B="39" E="37"/>
<b id="88" B="37" E="36"/>
<b id="89" B="36" E="35"/>
<b id="90" B="34" E="41"/>
</fragment>
<fragment id="42">
<n id="43" p="1058.488403 -341.341309"/>
Expand All @@ -103,18 +103,15 @@
<n id="49" p="1016.919678 -269.104889"/>
<n id="50" p="1066.259766 -235.403503"/>
<n id="51" p="1175.485596 -259.379883"/>
<b id="92" B="45" E="43" Order="2"/>
<b id="93" B="43" E="47"/>
<b id="94" B="47" E="48" Order="2"/>
<b id="95" B="48" E="46"/>
<b id="96" B="46" E="44" Order="2"/>
<b id="97" B="44" E="45"/>
<b id="98" B="47" E="49"/>
<b id="99" B="48" E="50" Order="2"/>
<b id="100" B="46" E="51"/>
<b id="91" B="45" E="43" Order="2"/>
<b id="92" B="43" E="47"/>
<b id="93" B="47" E="48" Order="2"/>
<b id="94" B="48" E="46"/>
<b id="95" B="46" E="44" Order="2"/>
<b id="96" B="44" E="45"/>
<b id="97" B="47" E="49"/>
<b id="98" B="48" E="50" Order="2"/>
<b id="99" B="46" E="51"/>
</fragment>
<scheme>
<step ReactionStepReactants="4 11 17" ReactionStepProducts="25" ReactionStepArrows="58"/>
</scheme>
</page>
</CDXML>
Loading

0 comments on commit 687417b

Please sign in to comment.