Skip to content

Commit

Permalink
Backmerge: #2458 The reaction with catalysts is displayed incorrect w…
Browse files Browse the repository at this point in the history
…ith ACS style setting and after layout (#2561)
  • Loading branch information
AliaksandrDziarkach authored Oct 17, 2024
1 parent 7d03fb4 commit 73d9e08
Show file tree
Hide file tree
Showing 16 changed files with 1,501 additions and 187 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/indigo-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ jobs:
name: indigo-python
path: dist/
- name: Install Pillow
run: python -m pip install Pillow --break-system-packages
run: python3 -m pip install Pillow
- name: Install wrappers Linux
if: ${{ startsWith(matrix.os, 'ubuntu') }}
run: python3 -m pip install dist/*manylinux1_x86_64*.whl --break-system-packages
run: python3 -m pip install dist/*manylinux1_x86_64*.whl
- name: Install wrappers Windows
if: ${{ startsWith(matrix.os, 'windows') }}
run: Get-ChildItem dist -Filter *win_amd64*.whl -Recurse | % { python3 -m pip install $_.FullName }
Expand Down
58 changes: 5 additions & 53 deletions api/c/indigo-renderer/src/indigo_render2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,54 +186,6 @@ void indigoRenderGetStereoStyle(Array<char>& value)
}
}

void indigoRenderSetLabelMode(const char* mode)
{
std::string mode_string(mode);
LABEL_MODE result;
if (mode_string == "none")
{
result = LABEL_MODE_NONE;
}
else if (mode_string == "hetero")
{
result = LABEL_MODE_HETERO;
}
else if (mode_string == "terminal-hetero")
{
result = LABEL_MODE_TERMINAL_HETERO;
}
else if (mode_string == "all")
{
result = LABEL_MODE_ALL;
}
else
{
throw IndigoError("Invalid label mode, should be 'none', 'hetero', 'terminal-hetero' or 'all'");
}
RenderParams& rp = indigoRendererGetInstance().renderParams;
rp.rOpt.labelMode = result;
}

void indigoRenderGetLabelMode(Array<char>& value)
{
RenderParams& rp = indigoRendererGetInstance().renderParams;
switch (rp.rOpt.labelMode)
{
case LABEL_MODE_NONE:
value.readString("none", true);
break;
case LABEL_MODE_HETERO:
value.readString("hetero", true);
break;
case LABEL_MODE_TERMINAL_HETERO:
value.readString("terminal-hetero", true);
break;
case LABEL_MODE_ALL:
value.readString("all", true);
break;
}
}

void indigoRenderSetCatalystsPlacement(const char* mode)
{
int result;
Expand Down Expand Up @@ -454,6 +406,11 @@ static void setParams(RenderParams& rp, LayoutOptions& layout_options)
rp.cnvOpt.bondLength = layout_options.bondLength;
rp.cnvOpt.bondLengthUnit = layout_options.bondLengthUnit;
rp.rOpt.ppi = layout_options.ppi;
rp.rOpt.fontSize = layout_options.fontSize;
rp.rOpt.fontSizeUnit = layout_options.fontSizeUnit;
rp.rOpt.fontSizeSub = layout_options.fontSizeSub;
rp.rOpt.fontSizeSubUnit = layout_options.fontSizeSubUnit;
rp.rOpt.labelMode = layout_options.labelMode;
rp.rOpt.bond_length_px = layout_options.bondLength > EPSILON ? layout_options.getBondLengthPx() : LayoutOptions::DEFAULT_BOND_LENGTH_PX;
if (rp.cnvOpt.outputSheetWidth > 0)
{
Expand Down Expand Up @@ -732,7 +689,6 @@ void IndigoRenderer::setOptionsHandlers()

mgr->setOptionHandlerString("render-output-format", indigoRenderSetOutputFormat, indigoRenderGetOutputFormat);

mgr->setOptionHandlerString("render-label-mode", indigoRenderSetLabelMode, indigoRenderGetLabelMode);
mgr->setOptionHandlerString("render-comment", SETTER_GETTER_STR_OPTION(rp.cnvOpt.comment));
mgr->setOptionHandlerString("render-comment-position", indigoRenderSetCommentPosition, indigoRenderGetCommentPosition);
mgr->setOptionHandlerString("render-stereo-style", indigoRenderSetStereoStyle, indigoRenderGetStereoStyle);
Expand Down Expand Up @@ -790,10 +746,6 @@ void IndigoRenderer::setOptionsHandlers()
mgr->setOptionHandlerVoid("reset-render-options", indigoRenderResetOptions);

// ACS style options
mgr->setOptionHandlerFloat("render-font-size", SETTER_GETTER_FLOAT_OPTION(rp.rOpt.fontSize));
mgr->setOptionHandlerString("render-font-size-unit", SETTER_GETTER_UNIT_OPTION(rp.rOpt.fontSizeUnit));
mgr->setOptionHandlerFloat("render-font-size-sub", SETTER_GETTER_FLOAT_OPTION(rp.rOpt.fontSizeSub));
mgr->setOptionHandlerString("render-font-size-sub-unit", SETTER_GETTER_UNIT_OPTION(rp.rOpt.fontSizeSubUnit));
mgr->setOptionHandlerFloat("render-bond-thickness", SETTER_GETTER_FLOAT_OPTION(rp.rOpt.bondThickness));
mgr->setOptionHandlerString("render-bond-thickness-unit", SETTER_GETTER_UNIT_OPTION(rp.rOpt.bondThicknessUnit));
mgr->setOptionHandlerFloat("render-bond-spacing", SETTER_GETTER_FLOAT_OPTION(rp.rOpt.bondSpacing));
Expand Down
53 changes: 53 additions & 0 deletions api/c/indigo/src/indigo_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,54 @@ void indigoProductEnumeratorGetOneTubeMode(Array<char>& value)
value.readString("grid", true);
}

void indigoRenderSetLabelMode(const char* mode)
{
std::string mode_string(mode);
LABEL_MODE result;
if (mode_string == "none")
{
result = LABEL_MODE_NONE;
}
else if (mode_string == "hetero")
{
result = LABEL_MODE_HETERO;
}
else if (mode_string == "terminal-hetero")
{
result = LABEL_MODE_TERMINAL_HETERO;
}
else if (mode_string == "all")
{
result = LABEL_MODE_ALL;
}
else
{
throw IndigoError("Invalid label mode, should be 'none', 'hetero', 'terminal-hetero' or 'all'");
}
LayoutOptions& layout_options = indigoGetInstance().layout_options;
layout_options.labelMode = result;
}

void indigoRenderGetLabelMode(Array<char>& value)
{
LayoutOptions& layout_options = indigoGetInstance().layout_options;
switch (layout_options.labelMode)
{
case LABEL_MODE_NONE:
value.readString("none", true);
break;
case LABEL_MODE_HETERO:
value.readString("hetero", true);
break;
case LABEL_MODE_TERMINAL_HETERO:
value.readString("terminal-hetero", true);
break;
case LABEL_MODE_ALL:
value.readString("all", true);
break;
}
}

void IndigoOptionHandlerSetter::setBasicOptionHandlers(const qword id)
{
auto mgr = sf::xlock_safe_ptr(indigoGetOptionManager(id));
Expand Down Expand Up @@ -391,4 +439,9 @@ void IndigoOptionHandlerSetter::setBasicOptionHandlers(const qword id)
mgr->setOptionHandlerFloat("reaction-component-margin-size", SETTER_GETTER_FLOAT_OPTION(indigo.layout_options.reactionComponentMarginSize));
mgr->setOptionHandlerString("reaction-component-margin-size-unit", SETTER_GETTER_UNIT_OPTION(indigo.layout_options.reactionComponentMarginSizeUnit));
mgr->setOptionHandlerInt("image-resolution", SET_POSITIVE_INT_OPTION(indigo.layout_options.ppi, "image resolution ppi must be positive"));
mgr->setOptionHandlerFloat("render-font-size", SETTER_GETTER_FLOAT_OPTION(indigo.layout_options.fontSize));
mgr->setOptionHandlerString("render-font-size-unit", SETTER_GETTER_UNIT_OPTION(indigo.layout_options.fontSizeUnit));
mgr->setOptionHandlerFloat("render-font-size-sub", SETTER_GETTER_FLOAT_OPTION(indigo.layout_options.fontSizeSub));
mgr->setOptionHandlerString("render-font-size-sub-unit", SETTER_GETTER_UNIT_OPTION(indigo.layout_options.fontSizeSubUnit));
mgr->setOptionHandlerString("render-label-mode", indigoRenderSetLabelMode, indigoRenderGetLabelMode);
}
2 changes: 1 addition & 1 deletion api/tests/integration/ref/basic/options.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bool
True
true
***** Float *****
0.800
0.500
float
21.333
21.333
11 changes: 11 additions & 0 deletions api/tests/integration/ref/layout/acs_style_reaction.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@

*** 2389 wrong margin ***
acs_issue_2389.ket:SUCCEED

*** 2458 catalist margins margin ***
Result: Molecule #0: Success
Molecule #1: Success
Molecule #2: Success
Molecule #3: Success
Molecule #4: Success
Molecule #5: Success
Molecule #6: Success
Molecule #7: Success
Molecule #8: Success
28 changes: 28 additions & 0 deletions api/tests/integration/tests/layout/acs_style_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,31 @@ def find_diff(a, b):
else:
print(filename + ":FAILED")
print(diff)


print("\n*** 2458 catalist margins margin ***")
filename = "acs_issue_2458.ket"
rxn = indigo.loadReactionFromFile(os.path.join(root, filename))
indigo.resetOptions()
indigo.setOption("molfile-saving-skip-date", "1")
indigo.setOption("json-saving-pretty", "1")
indigo.setOption("json-use-native-precision", "1")
indigo.setOption("smart-layout", "true")
indigo.setOption("dearomatize-on-load", "false")
indigo.setOption("render-font-size", "10")
indigo.setOption("render-font-size-unit", "pt")
indigo.setOption("image-resolution", "600")
indigo.setOption("bond-length-unit", "pt")
indigo.setOption("bond-length", "14.4")
indigo.setOption("render-label-mode", "terminal-hetero")
rxn.layout()
# with open(os.path.join(ref, filename), "w") as file:
# file.write(rxn.json())
res = reactionLayoutDiff(
indigo,
rxn,
filename,
update=upd,
update_format="ket",
)
print(" Result: {}".format(res))
Loading

0 comments on commit 73d9e08

Please sign in to comment.