Skip to content

Commit

Permalink
KNIME-1496,KNIME-1478 Bugfixes in rendering (#122)
Browse files Browse the repository at this point in the history
* Added thread synchronization to avoid NullPointerException raise cond.

Fixed line endings for Linux and encoding to UTF-8.

* update rdkit to 2020.09.1

* update test zip

* remove freetype dependency from the mac binary

* Bugfix to address log4j security vulnerability - version 4.4.1 (#100)

OPSIN has addressed a security vulnerability (CVE-2021-44228) documented
in issue dan2097/opsin#174 - To package this
for the RDKit nodes we now use OPSIN 3.0 (beta) build on master commit
6aca244.
This includes then naturally also improvements between 2.5 and 3.0
(committed until Dec 11, 2021).

Bumped version to from 4.4.0 to 4.4.1.

* Fixed pom.xml version to 4.4.1 (must be in sync with plugin versions)

* NXSWE-7 JRebel, IDEA config files added to .gitignore

* KNIME-1496: Introduce normalization of scaling while rendering

* KNIME-1478: Align missing cell rendering (red ? like rest of KNIME)

* KNIME-1496: Bugfix for normalization failure when no conformers found

* KNIME-1496: Introduce preference to control normalization when rendering

Co-authored-by: greg landrum <[email protected]>
Co-authored-by: Roman Balabanov <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2022
1 parent f2cbf60 commit ace6ff6
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 31 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# JRebel plugin configuration files
rebel.xml

# JetBrains IDEA project files
.idea/
*.iws
*.ipr
*.iml

bin
/org.rdkit.knime.types/python/*.pyc
/.metadata/
Expand Down
14 changes: 0 additions & 14 deletions org.rdkit.knime.nodes/src/rebel.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ public void propertyChange(
switch (event.getProperty()) {
case RDKitDepicterPreferencePage.PREF_KEY_CONFIG_FILE:
case RDKitDepicterPreferencePage.PREF_KEY_CONFIG_JSON:
case RDKitDepicterPreferencePage.PREF_KEY_NORMALIZE_DEPICTIONS:
RDKitDepicterPreferencePage.clearConfigCacheAndResetFailure();
break;
}
}
});
RDKitDepicterPreferencePage.clearConfigCacheAndResetFailure();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ protected synchronized void setValue(final Object value) {
RDKitMolValue molCell = null;
ROMol omol = null;
boolean trySanitizing = true;

boolean bNormalize = RDKitDepicterPreferencePage.isNormalizeDepictions();

try {
// We have an old plain RDKit Mol Value
if (value instanceof RDKitMolValue) {
Expand Down Expand Up @@ -214,6 +215,11 @@ else if (value instanceof AdapterValue) {
m_strSmiles = molCell.getSmilesValue();
omol = molCell.readMoleculeValue();

// Normalize scale
if (bNormalize && omol.getNumConformers() > 0) {
omol.normalizeDepiction(-1, 0);
}

// Store the prepared molecule for drawing next
m_molecule = omol;
}
Expand Down Expand Up @@ -260,7 +266,10 @@ else if (value instanceof SmartsValue) {
omol.updatePropertyCache(false);
RDKFuncs.symmetrizeSSSR(omol);
RDKFuncs.setHybridization(omol);
tmol.delete();
if (tmol != null) {
tmol.delete();
tmol = null;
}
}
}
}
Expand Down Expand Up @@ -294,6 +303,11 @@ else if (value instanceof SmartsValue) {
RDKFuncs.prepareMolForDrawing(mol, false);
}

// Normalize scale
if (bNormalize && omol.getNumConformers() > 0) {
mol.normalizeDepiction(-1, 0);
}

// Store the prepared molecule for drawing next
m_molecule = mol;
}
Expand Down Expand Up @@ -342,8 +356,8 @@ protected void paintComponent(final Graphics g) {
// Case 1: A missing cell
if (m_bIsMissingCell || m_strError != null) {
g.setFont(MISSING_CELL_FONT);
g.setColor(Color.red);
if (m_strError != null) {
g.setColor(Color.red);
drawString(g, m_strError, 2, 12);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;

import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
Expand Down Expand Up @@ -77,12 +78,20 @@ public class RDKitDepicterPreferencePage extends FieldEditorPreferencePage imple
*/
public static final String PREF_KEY_RETRY_INTERVAL = "configLoadingRetryInterval";

/**
* The flag to enable normalization of structures before they are being depicted.
*/
public static final String PREF_KEY_NORMALIZE_DEPICTIONS = "normalizeDepictions";

/** The default filename for the depiction settings, which is referring to our internal file. */
public static final String DEFAULT_CONFIG_FILE = "[default built-in]";

/** The default retry interval (10 minutes = 60000 millis). */
public static final int DEFAULT_RETRY_INTERVAL = 60000; // 10 minutes

/** The default flag for normalizing depictions (false). */
public static final boolean DEFAULT_NORMALIZE_DEPICTIONS = false;

/** The logger instance. */
private static final NodeLogger LOGGER = NodeLogger.getLogger(RDKitDepicterPreferencePage.class);

Expand All @@ -101,6 +110,11 @@ public class RDKitDepicterPreferencePage extends FieldEditorPreferencePage imple
*/
private static String g_jsonConfig = null;

/**
* The normalize depiction flag.
*/
private static boolean g_bNormalizeDepiction = DEFAULT_NORMALIZE_DEPICTIONS;

/** The timestamp of last failure of reading the JSON config file or -1, if not set. */
private static long g_lLastFailure = -1;

Expand All @@ -116,6 +130,11 @@ public class RDKitDepicterPreferencePage extends FieldEditorPreferencePage imple
*/
private StringFieldEditor m_editorConfigJson;

/**
* The editor for setting the flag to enable normalizing depictions.
*/
private BooleanFieldEditor m_editorNormalizeDepictions;

//
// Constructor
//
Expand Down Expand Up @@ -285,6 +304,9 @@ protected void onButtonClicked() {
}
};
addField(btnClear);

m_editorNormalizeDepictions = new BooleanFieldEditor(PREF_KEY_NORMALIZE_DEPICTIONS, "Normalize depictions", getFieldEditorParent());
addField(m_editorNormalizeDepictions);
}

//
Expand All @@ -300,6 +322,14 @@ public static synchronized void clearConfigCacheAndResetFailure() {
g_jsonConfig = null;
g_lLastFailure = -1;
getJsonConfig();

// Read current normalize depictions flag
final RDKitTypesPluginActivator plugin = RDKitTypesPluginActivator.getDefault();

if (plugin != null) {
final IPreferenceStore prefStore = plugin.getPreferenceStore();
g_bNormalizeDepiction = prefStore.getBoolean(PREF_KEY_NORMALIZE_DEPICTIONS);
}
}

/**
Expand Down Expand Up @@ -381,6 +411,15 @@ else if (PreferenceUtils.isSet(strConfigJsonData)) {

return strJsonConfig;
}

/**
* Returns the current setting for normalizing depictions.
*
* @return Normalize depictions flag.
*/
public static boolean isNormalizeDepictions() {
return g_bNormalizeDepiction;
}

/**
* Gets the appropriate preference store and initializes its default values.
Expand All @@ -405,12 +444,15 @@ public static synchronized void initializeDefaultPreferences() {
prefStore.setDefault(PREF_KEY_CONFIG_FILE, DEFAULT_CONFIG_FILE);
prefStore.setDefault(PREF_KEY_CONFIG_JSON, "");
prefStore.setDefault(PREF_KEY_RETRY_INTERVAL, DEFAULT_RETRY_INTERVAL);
prefStore.setDefault(PREF_KEY_NORMALIZE_DEPICTIONS, DEFAULT_NORMALIZE_DEPICTIONS);
}
}
catch (final Exception exc) {
LOGGER.error(
"Default values could not be set for the RDKit 2D Depiction preferences. Plug-In or Preference Store not found.", exc);
}

RDKitDepicterPreferencePage.clearConfigCacheAndResetFailure();
}
}

Expand Down
14 changes: 0 additions & 14 deletions org.rdkit.knime.types/rdkit-chemsrc/rebel.xml

This file was deleted.

0 comments on commit ace6ff6

Please sign in to comment.