Skip to content

Commit d25887e

Browse files
authored
Add RDKit2SVG node (#99)
* initial pass at new RDKit2SVG node * version bump * a bunch of new options updated tests * rearrange and document * updates in response to review
1 parent 3f47148 commit d25887e

File tree

19 files changed

+900
-19
lines changed

19 files changed

+900
-19
lines changed

org.rdkit.knime.bin.linux.x86_64/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: RDKit binaries for 64bit Linux
44
Bundle-SymbolicName: org.rdkit.knime.bin.linux.x86_64;singleton:=true
5-
Bundle-Version: 4.3.1.qualifier
6-
Fragment-Host: org.rdkit.knime.types;bundle-version="4.3.1"
5+
Bundle-Version: 4.4.0.qualifier
6+
Fragment-Host: org.rdkit.knime.types;bundle-version="4.4.0"
77
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
88
Eclipse-PlatformFilter: (&(osgi.os=linux)(osgi.arch=x86_64))
99
Bundle-Vendor: NIBR

org.rdkit.knime.bin.macosx.x86_64/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: RDKit binaries for 64bit MacOSX
44
Bundle-SymbolicName: org.rdkit.knime.bin.macosx.x86_64;singleton:=true
5-
Bundle-Version: 4.3.1.qualifier
6-
Fragment-Host: org.rdkit.knime.types;bundle-version="4.3.1"
5+
Bundle-Version: 4.4.0.qualifier
6+
Fragment-Host: org.rdkit.knime.types;bundle-version="4.4.0"
77
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
88
Eclipse-PlatformFilter: (&(osgi.os=macosx)(osgi.arch=x86_64))
99
Bundle-Vendor: NIBR

org.rdkit.knime.bin.win32.x86_64/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: RDKit binaries for 64bit Windows
44
Bundle-SymbolicName: org.rdkit.knime.bin.win32.x86_64;singleton:=true
5-
Bundle-Version: 4.3.1.qualifier
6-
Fragment-Host: org.rdkit.knime.types;bundle-version="4.3.1"
5+
Bundle-Version: 4.4.0.qualifier
6+
Fragment-Host: org.rdkit.knime.types;bundle-version="4.4.0"
77
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
88
Eclipse-PlatformFilter: (&(osgi.os=win32)(osgi.arch=x86_64))
99
Bundle-Vendor: NIBR

org.rdkit.knime.binaries.feature/feature.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<feature
33
id="org.rdkit.knime.binaries.feature"
44
label="RDKit Binaries and Chemistry Type Definitions Feature"
5-
version="4.3.1.qualifier"
5+
version="4.4.0.qualifier"
66
provider-name="NIBR">
77

88
<description>

org.rdkit.knime.feature/feature.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<feature
33
id="org.rdkit.knime.feature"
44
label="RDKit Nodes Feature"
5-
version="4.3.1.qualifier"
5+
version="4.4.0.qualifier"
66
provider-name="NIBR"
77
plugin="org.rdkit.knime.nodes">
88

org.rdkit.knime.nodes/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ Bundle-ManifestVersion: 2
33
Bundle-Name: RDKit Nodes
44
Bundle-SymbolicName: org.rdkit.knime.nodes;singleton:=true
55
Automatic-Module-Name: org.rdkit.knime.nodes
6-
Bundle-Version: 4.3.1.qualifier
6+
Bundle-Version: 4.4.0.qualifier
77
Bundle-Vendor: NIBR
88
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
99
Require-Bundle: org.eclipse.ui;bundle-version="[3.109.0,4.0.0)",
1010
org.knime.base;bundle-version="[4.2.0,5.0.0)",
1111
org.knime.chem.types;bundle-version="[4.2.0,5.0.0)",
1212
org.knime.workbench.repository;bundle-version="[4.2.0,5.0.0)",
13-
org.rdkit.knime.types;bundle-version="[4.3.1,5.0.0)",
13+
org.rdkit.knime.types;bundle-version="[4.4.0,5.0.0)",
1414
org.knime.ext.svg;bundle-version="[4.2.0,5.0.0)"
1515
Export-Package: org.rdkit.knime.nodes,
1616
org.rdkit.knime.nodes.addconformers,

org.rdkit.knime.nodes/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<node category-path="/community/rdkit/viewing" factory-class="org.rdkit.knime.nodes.interactivetable.RDKitInteractiveTableNodeFactory"/>
5454
<node after="org.rdkit.knime.nodes.interactivetable.RDKitInteractiveTableNodeFactory" category-path="/community/rdkit/viewing" factory-class="org.rdkit.knime.nodes.smilesheaders.RDKitSmilesHeadersNodeFactory"/>
5555
<node after="org.rdkit.knime.nodes.smilesheaders.RDKitSmilesHeadersNodeFactory" category-path="/community/rdkit/viewing" factory-class="org.rdkit.knime.nodes.highlighting.RDKitHighlightingNodeFactory"/>
56+
<node after="org.rdkit.knime.nodes.highlighting.RDKitHighlightingNodeFactory" category-path="/community/rdkit/viewing" factory-class="org.rdkit.knime.nodes.rdkit2svg.RDKit2SVGNodeFactory"/>
5657
<node deprecated="true" category-path="/community/rdkit/viewing" factory-class="org.rdkit.knime.nodes.highlightingatoms.RDKitHighlightingAtomsNodeFactory"/>
5758

5859
<node category-path="/community/rdkit/testing" factory-class="org.rdkit.knime.nodes.sdfdifferencechecker.RDKitSDFDifferenceCheckerNodeFactory"/>
Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
/*
2+
* ------------------------------------------------------------------
3+
* This source code, its documentation and all appendant files
4+
* are protected by copyright law. All rights reserved.
5+
*
6+
* Copyright (C) 2021
7+
* Novartis Institutes for BioMedical Research
8+
*
9+
*
10+
* This program is free software; you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License, Version 3, as
12+
* published by the Free Software Foundation.
13+
*
14+
* This program is distributed in the hope that it will be useful, but
15+
* WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program; if not, see <http://www.gnu.org/licenses>.
21+
*
22+
* Additional permission under GNU GPL version 3 section 7:
23+
*
24+
* KNIME interoperates with ECLIPSE solely via ECLIPSE's plug-in APIs.
25+
* Hence, KNIME and ECLIPSE are both independent programs and are not
26+
* derived from each other. Should, however, the interpretation of the
27+
* GNU GPL Version 3 ("License") under any applicable laws result in
28+
* KNIME and ECLIPSE being a combined program, KNIME GMBH herewith grants
29+
* you the additional permission to use and propagate KNIME together with
30+
* ECLIPSE with only the license terms in place for ECLIPSE applying to
31+
* ECLIPSE and the GNU GPL Version 3 applying for KNIME, provided the
32+
* license terms of ECLIPSE themselves allow for the respective use and
33+
* propagation of ECLIPSE together with KNIME.
34+
*
35+
* Additional permission relating to nodes for KNIME that extend the Node
36+
* Extension (and in particular that are based on subclasses of NodeModel,
37+
* NodeDialog, and NodeView) and that only interoperate with KNIME through
38+
* standard APIs ("Nodes"):
39+
* Nodes are deemed to be separate and independent programs and to not be
40+
* covered works. Notwithstanding anything to the contrary in the
41+
* License, the License does not apply to Nodes, you are not required to
42+
* license Nodes under the License, and you are granted a license to
43+
* prepare and propagate Nodes, in each case even if such Nodes are
44+
* propagated with or for interoperation with KNIME. The owner of a Node
45+
* may freely choose the license terms applicable to such Node, including
46+
* when such Node is propagated with or for interoperation with KNIME.
47+
* ---------------------------------------------------------------------
48+
*/
49+
package org.rdkit.knime.nodes.rdkit2svg;
50+
51+
import java.awt.Color;
52+
import java.awt.Component;
53+
import java.awt.Dimension;
54+
import java.awt.event.ActionEvent;
55+
import java.awt.event.ActionListener;
56+
57+
import javax.swing.BorderFactory;
58+
import javax.swing.DefaultCellEditor;
59+
import javax.swing.DefaultListCellRenderer;
60+
import javax.swing.JComboBox;
61+
import javax.swing.JLabel;
62+
import javax.swing.JMenuItem;
63+
import javax.swing.JPopupMenu;
64+
import javax.swing.JTable;
65+
import javax.swing.SwingConstants;
66+
import javax.swing.table.DefaultTableCellRenderer;
67+
import javax.swing.table.TableCellEditor;
68+
import javax.swing.table.TableCellRenderer;
69+
70+
import org.RDKit.EmbedParameters;
71+
import org.RDKit.MolDrawOptions;
72+
import org.RDKit.RDKFuncs;
73+
import org.knime.base.data.aggregation.dialogutil.DataColumnSpecTableCellRenderer;
74+
import org.knime.core.data.DataColumnSpec;
75+
import org.knime.core.data.DataTableSpec;
76+
import org.knime.core.data.IntValue;
77+
import org.knime.core.data.LongValue;
78+
import org.knime.core.node.NodeSettingsRO;
79+
import org.knime.core.node.NotConfigurableException;
80+
import org.knime.core.node.defaultnodesettings.DefaultNodeSettingsPane;
81+
import org.knime.core.node.defaultnodesettings.DialogComponentBoolean;
82+
import org.knime.core.node.defaultnodesettings.DialogComponentButton;
83+
import org.knime.core.node.defaultnodesettings.DialogComponentDoubleRange;
84+
import org.knime.core.node.defaultnodesettings.DialogComponentLabel;
85+
import org.knime.core.node.defaultnodesettings.DialogComponentNumber;
86+
import org.knime.core.node.defaultnodesettings.DialogComponentString;
87+
import org.knime.core.node.defaultnodesettings.SettingsModelBoolean;
88+
import org.knime.core.node.defaultnodesettings.SettingsModelDouble;
89+
import org.knime.core.node.defaultnodesettings.SettingsModelDoubleBounded;
90+
import org.knime.core.node.defaultnodesettings.SettingsModelInteger;
91+
import org.knime.core.node.defaultnodesettings.SettingsModelIntegerBounded;
92+
import org.knime.core.node.defaultnodesettings.SettingsModelString;
93+
import org.knime.core.node.util.ColumnFilter;
94+
import org.knime.core.node.util.ColumnSelectionPanel;
95+
import org.rdkit.knime.nodes.highlighting.HighlightingDefinition.Type;
96+
import org.rdkit.knime.types.RDKitMolValue;
97+
import org.rdkit.knime.util.DialogComponentColumnNameSelection;
98+
import org.rdkit.knime.util.DialogComponentSeparator;
99+
import org.rdkit.knime.util.DialogComponentTable;
100+
import org.rdkit.knime.util.LayoutUtils;
101+
import org.rdkit.knime.util.TableCellAction;
102+
import org.rdkit.knime.util.TableColorCellEditor;
103+
104+
/**
105+
* <code>NodeDialog</code> for the "RDKit2SVG" Node. Creates a SVG column
106+
* showing a molecule.
107+
*
108+
* This node dialog derives from {@link DefaultNodeSettingsPane} which allows
109+
* creation of a simple dialog with standard components. If you need a more
110+
* complex dialog please derive directly from
111+
* {@link org.knime.core.node.NodeDialogPane}.
112+
*
113+
* @author Greg Landrum
114+
*/
115+
public class RDKit2SVGNodeDialog extends DefaultNodeSettingsPane {
116+
117+
//
118+
// Constants
119+
//
120+
121+
/** Default values, directly taken from RDKit binaries. */
122+
public static final MolDrawOptions RDKIT_DEFAULT_PARAMETERS = new MolDrawOptions();
123+
124+
//
125+
// Constructor
126+
//
127+
128+
/**
129+
* Create a new dialog pane with default components to configure an input
130+
* column, the name of a new column, which will contain the calculation results,
131+
* an option to tell, if the source column shall be removed from the result
132+
* table.
133+
*/
134+
RDKit2SVGNodeDialog() {
135+
super.addDialogComponent(new DialogComponentColumnNameSelection(createInputColumnNameModel(),
136+
"RDKit Mol column: ", 0, RDKitMolValue.class));
137+
super.addDialogComponent(new DialogComponentString(createNewColumnNameModel(), "New column name: "));
138+
super.addDialogComponent(
139+
new DialogComponentBoolean(createRemoveSourceColumnsOptionModel(), "Remove source column"));
140+
141+
super.createNewTab("Drawing Options");
142+
super.addDialogComponent(
143+
new DialogComponentBoolean(createPrepareBeforeDrawingOptionModel(), "Prepare before drawing"));
144+
super.addDialogComponent(
145+
new DialogComponentBoolean(createCenterBeforeDrawingOptionModel(), "Center before drawing"));
146+
super.addDialogComponent(new DialogComponentBoolean(createClearBackgroundOptionModel(), "Clear background"));
147+
super.addDialogComponent(new DialogComponentBoolean(createAddAtomIndicesOptionModel(), "Add atom indices"));
148+
super.addDialogComponent(new DialogComponentBoolean(createAddBondIndicesOptionModel(), "Add bond indices"));
149+
super.addDialogComponent(
150+
new DialogComponentBoolean(createAddStereoAnnotationOptionModel(), "Add stereo annotations"));
151+
super.addDialogComponent(
152+
new DialogComponentBoolean(createIncludeChiralFlagOptionModel(), "Include chiral flag"));
153+
super.addDialogComponent(
154+
new DialogComponentBoolean(createSimplifiedStereoGroupsOptionModel(), "Use simplified stereo groups"));
155+
super.addDialogComponent(
156+
new DialogComponentBoolean(createSingleColorWedgeBondsOptionModel(), "Single color wedge bonds"));
157+
super.addDialogComponent(
158+
new DialogComponentBoolean(createExplicitMethylOptionModel(), "Draw explicit methyl groups"));
159+
super.addDialogComponent(
160+
new DialogComponentBoolean(createDummiesAreAttachmentsOptionModel(), "Dummies are attachment points"));
161+
super.addDialogComponent(new DialogComponentBoolean(createIncludeRadicalsOptionModel(), "Draw radicals"));
162+
super.addDialogComponent(new DialogComponentBoolean(createNoAtomLabelsOptionModel(), "No atom labels"));
163+
super.addDialogComponent(
164+
new DialogComponentBoolean(createIsotopeLabelsOptionModel(), "Include isotope labels"));
165+
super.addDialogComponent(
166+
new DialogComponentBoolean(createDummyIsotopeLabelsOptionModel(), "Include isotope labels on dummies"));
167+
super.addDialogComponent(new DialogComponentBoolean(createComicModeOptionModel(), "Comic mode"));
168+
super.addDialogComponent(new DialogComponentBoolean(createBWModeOptionModel(), "Black&White mode"));
169+
170+
super.addDialogComponent(
171+
new DialogComponentNumber(createBondLineWidthOptionModel(), "Line width for bonds", 1));
172+
173+
super.addDialogComponent(new DialogComponentNumber(createMinFontSizeOptionModel(), "Min font size", 1));
174+
super.addDialogComponent(new DialogComponentNumber(createMaxFontSizeOptionModel(), "Max font size", 1));
175+
super.addDialogComponent(
176+
new DialogComponentNumber(createAnnotationFontScaleOptionModel(), "Annotation font scale", 0.05));
177+
178+
}
179+
180+
//
181+
// Static Methods
182+
//
183+
184+
/**
185+
* Creates the settings model to be used for the input column.
186+
*
187+
* @return Settings model for input column selection.
188+
*/
189+
static final SettingsModelString createInputColumnNameModel() {
190+
return new SettingsModelString("input_column", null);
191+
}
192+
193+
/**
194+
* Creates the settings model to be used to specify the new column name.
195+
*
196+
* @return Settings model for result column name.
197+
*/
198+
static final SettingsModelString createNewColumnNameModel() {
199+
return new SettingsModelString("new_column_name", null);
200+
}
201+
202+
/**
203+
* Creates the settings model for the boolean flag to determine if the source
204+
* column shall be removed from the result table. The default is false.
205+
*
206+
* @return Settings model for check box whether to remove source columns.
207+
*/
208+
static final SettingsModelBoolean createRemoveSourceColumnsOptionModel() {
209+
return new SettingsModelBoolean("remove_source_columns", false);
210+
}
211+
212+
static final SettingsModelBoolean createClearBackgroundOptionModel() {
213+
return new SettingsModelBoolean("clear_background", RDKIT_DEFAULT_PARAMETERS.getClearBackground());
214+
}
215+
216+
static final SettingsModelBoolean createDummiesAreAttachmentsOptionModel() {
217+
return new SettingsModelBoolean("dummies_are_attachments",
218+
RDKIT_DEFAULT_PARAMETERS.getDummiesAreAttachments());
219+
}
220+
221+
static final SettingsModelBoolean createAddAtomIndicesOptionModel() {
222+
return new SettingsModelBoolean("add_atom_indices",
223+
RDKIT_DEFAULT_PARAMETERS.getAddAtomIndices());
224+
}
225+
226+
static final SettingsModelBoolean createAddBondIndicesOptionModel() {
227+
return new SettingsModelBoolean("add_bond_indices",
228+
RDKIT_DEFAULT_PARAMETERS.getAddBondIndices());
229+
}
230+
231+
static final SettingsModelBoolean createIsotopeLabelsOptionModel() {
232+
return new SettingsModelBoolean("isotope_labels",
233+
RDKIT_DEFAULT_PARAMETERS.getIsotopeLabels());
234+
}
235+
236+
static final SettingsModelBoolean createDummyIsotopeLabelsOptionModel() {
237+
return new SettingsModelBoolean("dummy_isotope_labels",
238+
RDKIT_DEFAULT_PARAMETERS.getDummyIsotopeLabels());
239+
}
240+
241+
static final SettingsModelBoolean createAddStereoAnnotationOptionModel() {
242+
return new SettingsModelBoolean("add_stereo_annotation",
243+
true); // here the RDKit default is a bad one
244+
}
245+
246+
static final SettingsModelBoolean createCenterBeforeDrawingOptionModel() {
247+
return new SettingsModelBoolean("center_before_drawing",
248+
RDKIT_DEFAULT_PARAMETERS.getCentreMoleculesBeforeDrawing());
249+
}
250+
251+
static final SettingsModelBoolean createPrepareBeforeDrawingOptionModel() {
252+
return new SettingsModelBoolean("prepare_before_drawing",
253+
RDKIT_DEFAULT_PARAMETERS.getPrepareMolsBeforeDrawing());
254+
}
255+
256+
static final SettingsModelBoolean createExplicitMethylOptionModel() {
257+
return new SettingsModelBoolean("explicit_methyl",
258+
RDKIT_DEFAULT_PARAMETERS.getExplicitMethyl());
259+
}
260+
261+
static final SettingsModelBoolean createIncludeRadicalsOptionModel() {
262+
return new SettingsModelBoolean("include_radicals",
263+
RDKIT_DEFAULT_PARAMETERS.getIncludeRadicals());
264+
}
265+
266+
static final SettingsModelBoolean createComicModeOptionModel() {
267+
return new SettingsModelBoolean("comic_mode",
268+
RDKIT_DEFAULT_PARAMETERS.getComicMode());
269+
}
270+
271+
static final SettingsModelBoolean createBWModeOptionModel() {
272+
return new SettingsModelBoolean("bw_mode",false); // not actually an option in the RDKit API
273+
}
274+
275+
static final SettingsModelBoolean createNoAtomLabelsOptionModel() {
276+
return new SettingsModelBoolean("no_atom_labels",
277+
RDKIT_DEFAULT_PARAMETERS.getNoAtomLabels());
278+
}
279+
280+
static final SettingsModelBoolean createIncludeChiralFlagOptionModel() {
281+
return new SettingsModelBoolean("include_chiral_flag",
282+
RDKIT_DEFAULT_PARAMETERS.getIncludeChiralFlagLabel());
283+
}
284+
285+
static final SettingsModelBoolean createSimplifiedStereoGroupsOptionModel() {
286+
return new SettingsModelBoolean("simplified_stereo_groups",
287+
RDKIT_DEFAULT_PARAMETERS.getSimplifiedStereoGroupLabel());
288+
}
289+
290+
static final SettingsModelBoolean createSingleColorWedgeBondsOptionModel() {
291+
return new SettingsModelBoolean("single_color_wedge_bonds",
292+
RDKIT_DEFAULT_PARAMETERS.getSingleColourWedgeBonds());
293+
}
294+
295+
static final SettingsModelIntegerBounded createBondLineWidthOptionModel() {
296+
return new SettingsModelIntegerBounded("bond_line_width",
297+
RDKIT_DEFAULT_PARAMETERS.getBondLineWidth(), 0, 100);
298+
}
299+
300+
static final SettingsModelIntegerBounded createMinFontSizeOptionModel() {
301+
return new SettingsModelIntegerBounded("min_font_size",
302+
RDKIT_DEFAULT_PARAMETERS.getMinFontSize(), 0, 100);
303+
}
304+
305+
static final SettingsModelIntegerBounded createMaxFontSizeOptionModel() {
306+
return new SettingsModelIntegerBounded("max_font_size",
307+
RDKIT_DEFAULT_PARAMETERS.getMaxFontSize(), 0, 100);
308+
}
309+
310+
static final SettingsModelDoubleBounded createAnnotationFontScaleOptionModel() {
311+
return new SettingsModelDoubleBounded("annotation_font_scale",
312+
RDKIT_DEFAULT_PARAMETERS.getAnnotationFontScale(), 0, 2);
313+
}
314+
315+
}

0 commit comments

Comments
 (0)