Hi Everyone,
I had a need to neutralize a list of molecules. I came across this post:
I wanted to get something similar working in KNIME 4.7 so I played around and came up with this. It will work on a column name “smiles”. I hope this is useful to others. Of note, I am a python and RDKit beginner so this may not be the best way.
Here is the code if you just want to paste it into a node yourself
import knime.scripting.io as knio
from rdkit import Chem
from rdkit.Chem import MolStandardize
from rdkit.Chem.MolStandardize import rdMolStandardize
import knime.types.chemistry as ktchem
import rdkit.Chem
import pandas as pd
df = knio.input_tables[0].to_pandas()
# Convert SMILES to RDKit molecules, assuming there is a "Smiles" column
mols = [rdkit.Chem.MolFromSmiles(s) for s in df["smiles"]]
df["RDKit Molecules"] = mols
# Convert molecule to it's neutral state
mols = [rdMolStandardize.ChargeParent(m, skipStandardize=True) for m in df["RDKit Molecules"]]
df["Uncharged"] = mols
# Also output the uncharged smiles
df["smiles_uncharged"] = [ktchem.SmilesValue(rdkit.Chem.MolToSmiles(m)) for m in mols]
knio.output_tables[0] = knio.Table.from_pandas(df)
RDKit_neutralize_4.7.knwf (11.5 KB)