diff --git a/.gitignore b/.gitignore index 112e2c42..b5bcbcb9 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/org.rdkit.knime.nodes/src/rebel.xml b/org.rdkit.knime.nodes/src/rebel.xml deleted file mode 100644 index f9cb6422..00000000 --- a/org.rdkit.knime.nodes/src/rebel.xml +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project. - Refer to https://manuals.zeroturnaround.com/jrebel/standalone/config.html for more information. ---> -<application generated-by="eclipse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd"> - - <classpath> - <dir name="C:/DevelopmentGit/knime-rdkit/org.rdkit.knime.nodes/bin"> - </dir> - </classpath> - -</application> diff --git a/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/RDKitTypesPluginActivator.java b/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/RDKitTypesPluginActivator.java index 6ab11775..3d2c3268 100755 --- a/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/RDKitTypesPluginActivator.java +++ b/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/RDKitTypesPluginActivator.java @@ -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(); } /** diff --git a/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/types/RDKitMolValueRenderer.java b/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/types/RDKitMolValueRenderer.java index 25846c1b..e813d01b 100644 --- a/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/types/RDKitMolValueRenderer.java +++ b/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/types/RDKitMolValueRenderer.java @@ -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) { @@ -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; } @@ -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; + } } } } @@ -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; } @@ -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 { diff --git a/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/types/preferences/RDKitDepicterPreferencePage.java b/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/types/preferences/RDKitDepicterPreferencePage.java index 57ca66ee..ad330d23 100644 --- a/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/types/preferences/RDKitDepicterPreferencePage.java +++ b/org.rdkit.knime.types/rdkit-chemsrc/org/rdkit/knime/types/preferences/RDKitDepicterPreferencePage.java @@ -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; @@ -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); @@ -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; @@ -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 // @@ -285,6 +304,9 @@ protected void onButtonClicked() { } }; addField(btnClear); + + m_editorNormalizeDepictions = new BooleanFieldEditor(PREF_KEY_NORMALIZE_DEPICTIONS, "Normalize depictions", getFieldEditorParent()); + addField(m_editorNormalizeDepictions); } // @@ -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); + } } /** @@ -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. @@ -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(); } } diff --git a/org.rdkit.knime.types/rdkit-chemsrc/rebel.xml b/org.rdkit.knime.types/rdkit-chemsrc/rebel.xml deleted file mode 100644 index 54b4e2b9..00000000 --- a/org.rdkit.knime.types/rdkit-chemsrc/rebel.xml +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project. - Refer to https://manuals.zeroturnaround.com/jrebel/standalone/config.html for more information. ---> -<application generated-by="eclipse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd"> - - <classpath> - <dir name="C:/DevelopmentGit/knime-rdkit/org.rdkit.knime.types/bin"> - </dir> - </classpath> - -</application>