Skip to content

Commit 3afe684

Browse files
Two enhancements to existing nodes (#81)
* Fixes #64 * add support to the molecule substruct filter too * update substruct counter * update tests * finish updating tests * Support additional options in Adjust Query Properties node * Bugfixes, documentation and test updates Added cleanup for RDKit objects to free memory. Added backward-compatibility for new parameters with call of registerSettings(xxx, true) to avoid ugly error when loading workflows with older node versions. Completed JavaDocs for new functionality and fixed some old one. Minor performance improvements. Cleanup some formatting. Simplified some test workflows, saved them with KNIME 4.2.3. Corrected TestFlowConfiguration nodes with old configurations. Co-authored-by: Manuel Schwarze <manuel.schwarze@novartis.com>
1 parent 7794be3 commit 3afe684

19 files changed

+373
-22
lines changed

org.rdkit.knime.nodes/src/org/rdkit/knime/nodes/adjustqueryproperties/RDKitAdjustQueryPropertiesNodeDialog.java

Lines changed: 203 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,65 @@ protected void setEnabledComponents(boolean enabled) {
204204
filterPanelRingCountOption.getComponentPanel().setPreferredSize(new Dimension(550, 135));
205205

206206
super.addDialogComponent(new DialogComponentSeparator());
207+
208+
SettingsModelBoolean makeAtomsGenericModel = createMakeAtomsGenericOptionModel();
209+
super.addDialogComponent(new DialogComponentBoolean(
210+
makeAtomsGenericModel, "Make atoms generic"));
211+
DialogComponentEnumFilterPanel<AdjustQueryWhichFlags> filterPanelAtomsGenericOption =
212+
new DialogComponentEnumFilterPanel(
213+
createMakeAtomsGenericFlagsOptionModel(makeAtomsGenericModel),
214+
"Use the following flags to make atoms generic:",
215+
generateReducedFlagList(), true) {
216+
protected void setEnabledComponents(boolean enabled) {
217+
super.setEnabledComponents(enabled);
218+
setListCellRenderer(enabled ? TOOLTIP_LIST_RENDERER : new DefaultListCellRenderer());
219+
}
220+
};
221+
super.addDialogComponent(filterPanelAtomsGenericOption);
222+
filterPanelAtomsGenericOption.setSearchVisible(false);
223+
filterPanelAtomsGenericOption.setExcludeTitle(" Do not use ");
224+
filterPanelAtomsGenericOption.setIncludeTitle(" Use ");
225+
filterPanelAtomsGenericOption.setListCellRenderer(TOOLTIP_LIST_RENDERER);
226+
filterPanelAtomsGenericOption.getComponentPanel().setPreferredSize(new Dimension(550, 135));
227+
super.addDialogComponent(new DialogComponentSeparator());
228+
229+
SettingsModelBoolean makeBondsGenericModel = createMakeBondsGenericOptionModel();
230+
super.addDialogComponent(new DialogComponentBoolean(
231+
makeBondsGenericModel, "Make bonds generic"));
232+
DialogComponentEnumFilterPanel<AdjustQueryWhichFlags> filterPanelBondsGenericOption =
233+
new DialogComponentEnumFilterPanel(
234+
createMakeBondsGenericFlagsOptionModel(makeBondsGenericModel),
235+
"Use the following flags to make bonds generic:",
236+
generateReducedFlagList(), true) {
237+
protected void setEnabledComponents(boolean enabled) {
238+
super.setEnabledComponents(enabled);
239+
setListCellRenderer(enabled ? TOOLTIP_LIST_RENDERER : new DefaultListCellRenderer());
240+
}
241+
};
242+
super.addDialogComponent(filterPanelBondsGenericOption);
243+
filterPanelAtomsGenericOption.setSearchVisible(false);
244+
filterPanelAtomsGenericOption.setExcludeTitle(" Do not use ");
245+
filterPanelAtomsGenericOption.setIncludeTitle(" Use ");
246+
filterPanelAtomsGenericOption.setListCellRenderer(TOOLTIP_LIST_RENDERER);
247+
filterPanelAtomsGenericOption.getComponentPanel().setPreferredSize(new Dimension(550, 135));
248+
super.addDialogComponent(new DialogComponentSeparator());
207249

208250
super.addDialogComponent(new DialogComponentBoolean(
209251
createMakeDummiesQueriesOptionModel(), "Make dummies queries"));
210-
}
252+
super.addDialogComponent(new DialogComponentBoolean(
253+
createAromatizeOptionModel(), "Aromatize if possible"));
254+
super.addDialogComponent(new DialogComponentBoolean(
255+
createAdjustConjugated5RingsOptionModel(), "Adjust conjugated 5 rings"));
256+
super.addDialogComponent(new DialogComponentBoolean(
257+
createSetMDL5RingAromaticityOptionModel(), "Set MDL 5 ring aromaticity"));
258+
super.addDialogComponent(new DialogComponentBoolean(
259+
createAdjustSingleBondsToDegree1NeighborsOptionModel(), "Adjust single bonds to degree 1 neighbors"));
260+
super.addDialogComponent(new DialogComponentBoolean(
261+
createAdjustSingleBondsBetweenAromaticAtomsOptionModel(), "Adjust single bonds between aromatic atoms"));
262+
super.addDialogComponent(new DialogComponentBoolean(
263+
createUseStereoCareForBondsOptionModel(), "Use stereo care for bonds"));
264+
265+
}
211266

212267
//
213268
// Static Methods
@@ -272,6 +327,72 @@ static final SettingsModelBoolean createMakeDummiesQueriesOptionModel() {
272327
DEFAULT_ADJUST_QUERY_PARAMETERS.getMakeDummiesQueries());
273328
}
274329

330+
/**
331+
* Creates the settings model to be used to specify, if molecule should be aromatized.
332+
* Added in November 2020.
333+
*
334+
* @return Settings model for aromatize option.
335+
*/
336+
static final SettingsModelBoolean createAromatizeOptionModel() {
337+
return new SettingsModelBoolean("aromatize_if_possible",
338+
DEFAULT_ADJUST_QUERY_PARAMETERS.getAromatizeIfPossible());
339+
}
340+
341+
/**
342+
* Creates the settings model to be used to specify, if conjugated 5-rings shall be adjusted.
343+
* Added in November 2020.
344+
*
345+
* @return Settings model for adjusting conjugated 5-rings.
346+
*/
347+
static final SettingsModelBoolean createAdjustConjugated5RingsOptionModel() {
348+
return new SettingsModelBoolean("adjust_conjugated_five_rings",
349+
DEFAULT_ADJUST_QUERY_PARAMETERS.getAdjustConjugatedFiveRings());
350+
}
351+
352+
/**
353+
* Creates the settings model to be used to specify, if single bonds shall be adjusted to degree 1 neighbors.
354+
* Added in November 2020.
355+
*
356+
* @return Settings model for adjusting single bonds to degree 1 neighbors option.
357+
*/
358+
static final SettingsModelBoolean createAdjustSingleBondsToDegree1NeighborsOptionModel() {
359+
return new SettingsModelBoolean("adjust_single_bonds_to_degree_1_neighbors",
360+
DEFAULT_ADJUST_QUERY_PARAMETERS.getAdjustSingleBondsToDegreeOneNeighbors());
361+
}
362+
363+
/**
364+
* Creates the settings model to be used to specify, if single bonds between aromatic atoms shall be adjusted.
365+
* Added in November 2020.
366+
*
367+
* @return Settings model for adjusting single bonds between aromatic atoms.
368+
*/
369+
static final SettingsModelBoolean createAdjustSingleBondsBetweenAromaticAtomsOptionModel() {
370+
return new SettingsModelBoolean("adjust_single_bonds_between_aromatic_atoms",
371+
DEFAULT_ADJUST_QUERY_PARAMETERS.getAdjustSingleBondsBetweenAromaticAtoms());
372+
}
373+
374+
/**
375+
* Creates the settings model to be used to specify, if MDL 5-ring aromaticity shall be set.
376+
* Added in November 2020.
377+
*
378+
* @return Settings model for setting MDL 5-ring aromaticity.
379+
*/
380+
static final SettingsModelBoolean createSetMDL5RingAromaticityOptionModel() {
381+
return new SettingsModelBoolean("set_mdl_five_ring_aromaticity",
382+
DEFAULT_ADJUST_QUERY_PARAMETERS.getSetMDLFiveRingAromaticity());
383+
}
384+
385+
/**
386+
* Creates the settings model to be used to specify, if stereo care for bonds shall be used.
387+
* Added in November 2020.
388+
*
389+
* @return Settings model for using stereo care for bonds.
390+
*/
391+
static final SettingsModelBoolean createUseStereoCareForBondsOptionModel() {
392+
return new SettingsModelBoolean("use_stereo_care_for_bonds",
393+
DEFAULT_ADJUST_QUERY_PARAMETERS.getUseStereoCareForBonds());
394+
}
395+
275396
/**
276397
* Removes elements from the {@link AdjustQueryWhichFlags} enumeration, which
277398
* are not meaningful in the UI.
@@ -338,7 +459,88 @@ public void stateChanged(final ChangeEvent e) {
338459

339460
return model;
340461
}
462+
463+
/**
464+
* Creates the settings model to be used to specify, if atoms shall be made generic.
465+
* Added in November 2020.
466+
*
467+
* @return Settings model for making atoms generic.
468+
*/
469+
static final SettingsModelBoolean createMakeAtomsGenericOptionModel() {
470+
return new SettingsModelBoolean("make_atoms_generic",
471+
DEFAULT_ADJUST_QUERY_PARAMETERS.getMakeAtomsGeneric());
472+
}
473+
474+
/**
475+
* Creates the settings model to be used to specify, how atoms shall be made generic,
476+
* which has only an effect, if the making atoms generic option is enabled.
477+
* Added in November 2020.
478+
*
479+
* @param makeAtomsGenericModel Model that the model to be created depends on.
480+
* Based on the state of the passed in model we will enable or disable the
481+
* AdjustQueryWhichFlags model.
482+
*
483+
* @return Settings model for defining the flags how to make atoms generic.
484+
*/
485+
static final SettingsModelEnumerationArray<AdjustQueryWhichFlags> createMakeAtomsGenericFlagsOptionModel(
486+
final SettingsModelBoolean makeAtomsGenericModel) {
487+
SettingsModelEnumerationArray<AdjustQueryWhichFlags> model =
488+
new SettingsModelEnumerationArray<>(AdjustQueryWhichFlags.class, "make_atoms_generic_flags",
489+
getFlags(DEFAULT_ADJUST_QUERY_PARAMETERS.getMakeAtomsGenericFlags()));
341490

491+
makeAtomsGenericModel.addChangeListener(new ChangeListener() {
492+
@Override
493+
public void stateChanged(final ChangeEvent e) {
494+
model.setEnabled(makeAtomsGenericModel.getBooleanValue());
495+
}
496+
});
497+
498+
model.setEnabled(makeAtomsGenericModel.getBooleanValue());
499+
500+
return model;
501+
}
502+
503+
/**
504+
* Creates the settings model to be used to specify, if bonds shall be made generic.
505+
* Added in November 2020.
506+
*
507+
* @return Settings model for making bonds generic.
508+
*/
509+
static final SettingsModelBoolean createMakeBondsGenericOptionModel() {
510+
return new SettingsModelBoolean("make_bonds_generic",
511+
DEFAULT_ADJUST_QUERY_PARAMETERS.getMakeBondsGeneric());
512+
}
513+
514+
515+
/**
516+
* Creates the settings model to be used to specify, how bonds shall be made
517+
* generic, which has only an effect, if the making atoms generic option is enabled.
518+
* Added in November 2020.
519+
*
520+
* @param makeBondsGenericModel Model that the model to be created depends on.
521+
* Based on the state of the passed in model we will enable or disable the
522+
* AdjustQueryWhichFlags model.
523+
*
524+
* @return Settings model for defining the flags how to make bonds generic.
525+
*/
526+
static final SettingsModelEnumerationArray<AdjustQueryWhichFlags> createMakeBondsGenericFlagsOptionModel(
527+
final SettingsModelBoolean makeBondsGenericModel) {
528+
SettingsModelEnumerationArray<AdjustQueryWhichFlags> model =
529+
new SettingsModelEnumerationArray<>(AdjustQueryWhichFlags.class, "make_bonds_generic_flags",
530+
getFlags(DEFAULT_ADJUST_QUERY_PARAMETERS.getMakeBondsGenericFlags()));
531+
532+
makeBondsGenericModel.addChangeListener(new ChangeListener() {
533+
@Override
534+
public void stateChanged(final ChangeEvent e) {
535+
model.setEnabled(makeBondsGenericModel.getBooleanValue());
536+
}
537+
});
538+
539+
model.setEnabled(makeBondsGenericModel.getBooleanValue());
540+
541+
return model;
542+
}
543+
342544
/**
343545
* Converts the passed in array of flags into a long value.
344546
*

org.rdkit.knime.nodes/src/org/rdkit/knime/nodes/adjustqueryproperties/RDKitAdjustQueryPropertiesNodeFactory.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,23 @@
2525
<option name="Adjust ring count">Enable so that modified atoms have a ring-count query added
2626
based on their ring count in the query.</option>
2727
<option name="Adjust ring count flag">Control which atoms have a ring-count query added.</option>
28+
<option name="Make atoms generic">Convert atoms to any-atom queries.</option>
29+
<option name="Make atoms generic flag">Control which atoms are converted to any-atom queries.</option>
30+
<option name="Make bonds generic">Convert bonds to any-bond queries.</option>
31+
<option name="Make bonds generic flag">Control which bonds are converted to any-bond queries.</option>
2832
<option name="Make dummies queries">Enable so that dummy atoms that do not have a specified isotope
2933
are converted to any-atom queries.</option>
34+
<option name="Aromatize if possible">Perceive and set aromaticity.</option>
35+
<option name="Adjust conjugated 5 rings">Sets bond queries in conjugated five-rings to
36+
SINGLE|DOUBLE|AROMATIC.</option>
37+
<option name="Set MDL 5 ring aromaticity">Uses the 5-ring aromaticity behavior of the (former) MDL
38+
software as documented in the Chemical Representation Guide.</option>
39+
<option name="Adjust single bonds to degree 1 neighbors">Sets single bonds between aromatic atoms and degree one
40+
neighbors to SINGLE|AROMATIC.</option>
41+
<option name="Adjust single bonds between aromatic atoms">Sets non-ring single bonds between two aromatic atoms to
42+
SINGLE|AROMATIC.</option>
43+
<option name="Use stereo care for bonds">Remove stereochemistry info from double bonds that do not have
44+
the stereoCare property set.</option>
3045
</tab>
3146
</fullDescription>
3247

org.rdkit.knime.nodes/src/org/rdkit/knime/nodes/adjustqueryproperties/RDKitAdjustQueryPropertiesNodeModel.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,30 @@ public class RDKitAdjustQueryPropertiesNodeModel extends AbstractRDKitCalculator
123123
private final SettingsModelBoolean m_modelMakeDummiesQueriesOption =
124124
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createMakeDummiesQueriesOptionModel());
125125

126+
/** Settings model for aromatize option. Added in November 2020. */
127+
private final SettingsModelBoolean m_modelAromatizeOption =
128+
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createAromatizeOptionModel(), true);
129+
130+
/** Settings model for adjust conjugated 5-rings option. Added in November 2020. */
131+
private final SettingsModelBoolean m_modelAdjustConjugated5Rings =
132+
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createAdjustConjugated5RingsOptionModel(), true);
133+
134+
/** Settings model for adjust single bonds to degree 1 neighbors option. Added in November 2020. */
135+
private final SettingsModelBoolean m_modelAdjustSingleBondsToDegree1Neighbors =
136+
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createAdjustSingleBondsToDegree1NeighborsOptionModel(), true);
137+
138+
/** Settings model for adjust single bonds between aromatic atoms option. Added in November 2020. */
139+
private final SettingsModelBoolean m_modelAdjustSingleBondsBetweenAromaticAtoms =
140+
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createAdjustSingleBondsBetweenAromaticAtomsOptionModel(), true);
141+
142+
/** Settings model for set MDL 5-ring aromaticity option. Added in November 2020. */
143+
private final SettingsModelBoolean m_modelSetMDL5RingAromaticity =
144+
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createSetMDL5RingAromaticityOptionModel(), true);
145+
146+
/** Settings model for use stereo care for bonds option. Added in November 2020. */
147+
private final SettingsModelBoolean m_modelUseStereoCareForBonds =
148+
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createUseStereoCareForBondsOptionModel(), true);
149+
126150
/** Settings model for the adjust degree flags. */
127151
private final SettingsModelEnumerationArray<AdjustQueryWhichFlags> m_modelAdjustDegreeFlags =
128152
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createAdjustDegreeFlagsOptionModel(
@@ -133,6 +157,25 @@ public class RDKitAdjustQueryPropertiesNodeModel extends AbstractRDKitCalculator
133157
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createAdjustRingCountFlagsOptionModel(
134158
m_modelAdjustRingCountOption));
135159

160+
/** Settings model for option to make atoms generic. Added in November 2020. */
161+
private final SettingsModelBoolean m_modelMakeAtomsGenericOption =
162+
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createMakeAtomsGenericOptionModel(), true);
163+
164+
/** Settings model for flags to make atoms generic. Added in November 2020. */
165+
private final SettingsModelEnumerationArray<AdjustQueryWhichFlags> m_modelMakeAtomsGenericFlags =
166+
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createMakeAtomsGenericFlagsOptionModel(
167+
m_modelMakeAtomsGenericOption), true);
168+
169+
/** Settings model for option to make bonds generic. Added in November 2020. */
170+
private final SettingsModelBoolean m_modelMakeBondsGenericOption =
171+
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createMakeBondsGenericOptionModel(), true);
172+
173+
/** Settings model for flags to make bonds generic. Added in November 2020. */
174+
private final SettingsModelEnumerationArray<AdjustQueryWhichFlags> m_modelMakeBondsGenericFlags =
175+
registerSettings(RDKitAdjustQueryPropertiesNodeDialog.createMakeBondsGenericFlagsOptionModel(
176+
m_modelMakeBondsGenericOption), true);
177+
178+
136179
//
137180
// Constructor
138181
//
@@ -237,7 +280,17 @@ protected AbstractRDKitCellFactory[] createOutputFactories(int outPort, DataTabl
237280
adjustParams.setAdjustDegreeFlags(RDKitAdjustQueryPropertiesNodeDialog.getFlags(m_modelAdjustDegreeFlags.getValues()));
238281
adjustParams.setAdjustRingCount(m_modelAdjustRingCountOption.getBooleanValue());
239282
adjustParams.setAdjustRingCountFlags(RDKitAdjustQueryPropertiesNodeDialog.getFlags(m_modelAdjustRingCountFlags.getValues()));
283+
adjustParams.setMakeAtomsGeneric(m_modelMakeAtomsGenericOption.getBooleanValue());
284+
adjustParams.setMakeAtomsGenericFlags(RDKitAdjustQueryPropertiesNodeDialog.getFlags(m_modelMakeAtomsGenericFlags.getValues()));
285+
adjustParams.setMakeBondsGeneric(m_modelMakeBondsGenericOption.getBooleanValue());
286+
adjustParams.setMakeBondsGenericFlags(RDKitAdjustQueryPropertiesNodeDialog.getFlags(m_modelMakeBondsGenericFlags.getValues()));
240287
adjustParams.setMakeDummiesQueries(m_modelMakeDummiesQueriesOption.getBooleanValue());
288+
adjustParams.setAromatizeIfPossible(m_modelAromatizeOption.getBooleanValue());
289+
adjustParams.setAdjustConjugatedFiveRings(m_modelAdjustConjugated5Rings.getBooleanValue());
290+
adjustParams.setAdjustSingleBondsBetweenAromaticAtoms(m_modelAdjustSingleBondsBetweenAromaticAtoms.getBooleanValue());
291+
adjustParams.setAdjustSingleBondsToDegreeOneNeighbors(m_modelAdjustSingleBondsToDegree1Neighbors.getBooleanValue());
292+
adjustParams.setUseStereoCareForBonds(m_modelUseStereoCareForBonds.getBooleanValue());
293+
adjustParams.setSetMDLFiveRingAromaticity(m_modelSetMDL5RingAromaticity.getBooleanValue());
241294

242295
// Generate factory
243296
arrOutputFactories[0] = new AbstractRDKitCellFactory(this, AbstractRDKitCellFactory.RowFailurePolicy.DeliverEmptyValues,

org.rdkit.knime.nodes/src/org/rdkit/knime/nodes/moleculesubstructfilter/RDKitMoleculeSubstructFilterNodeDialog.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ protected RDKitMoleculeSubstructFilterNodeDialog() {
102102
final DialogComponent compQueryColumn = add(new DialogComponentColumnNameSelection(
103103
createQueryColumnNameModel(), "Query Mol column: ", 1,
104104
arrClassesQueryType));
105+
final DialogComponent compUseChirality = add(new DialogComponentBoolean(createUseChiralityModel(),
106+
"Use stereochemistry"));
105107
final SettingsModelEnumeration<MatchingCriteria> modelMatchingCriteria =
106108
createMatchingCriteriaModel();
107109
final DialogComponent compMatchingCriteria = add(new DialogComponentEnumButtonGroup<MatchingCriteria>(
@@ -130,6 +132,10 @@ protected RDKitMoleculeSubstructFilterNodeDialog() {
130132
0, iRow++, LayoutUtils.REMAINDER, 1,
131133
LayoutUtils.NONE, LayoutUtils.CENTER, 0.0d, 0.0d,
132134
0, 10, 0, 10);
135+
LayoutUtils.constrain(panel, compUseChirality.getComponentPanel(),
136+
0, iRow++, LayoutUtils.REMAINDER, 1,
137+
LayoutUtils.NONE, LayoutUtils.CENTER, 0.0d, 0.0d,
138+
0, 10, 0, 10);
133139
LayoutUtils.constrain(panel, new JLabel("Match:", SwingConstants.RIGHT),
134140
0, iRow, 1, 1,
135141
LayoutUtils.HORIZONTAL, LayoutUtils.NORTHEAST, 1.0d, 0.0d,
@@ -255,6 +261,15 @@ static final SettingsModelString createNewColumnNameModel() {
255261
return new SettingsModelString("new_column_name", null);
256262
}
257263

264+
/**
265+
* Creates the settings model to specify the use chirality option.
266+
*
267+
* @return settings model for the use chirality toggle.
268+
*/
269+
static final SettingsModelBoolean createUseChiralityModel() {
270+
return new SettingsModelBoolean("use_chirality", false);
271+
}
272+
258273
/**
259274
* Creates the settings model to be used to specify the option
260275
* to switch on the fingerprint screening feature. Used only internally.

0 commit comments

Comments
 (0)