Product |
Version |
Signals Spotfire |
All Versions |
Keywords: Python, MOL Binary conversion, SMILES, Chemical structures.
Description:
In Signals Spotfire, you may have molecular structure data stored in a binary format (MolBlock), and you want to convert this data into a more usable format like SMILES strings. This KB article demonstrates how to achieve this using Python data functions.
Solution Instructions:
1. Setup Environment:
- Ensure Spotfire is installed and configured with Python Data Functions.
- Install necessary Python packages (`pandas` and `rdkit`).
2. Create Python Data Function:
- Open TIBCO Spotfire and navigate to `Tools` > `Register Python Data Functions`.
- Create a new Python script with the following code:
python Script:
import pandas as pd
from rdkit import Chem
# Function to convert MolBlock to SMILES
def molToSmile(value):
mol = Chem.MolFromMolBlock(value)
return Chem.MolToSmiles(mol)
def convert_mol_to_smiles(data):
input_df = pd.DataFrame(data)
input_df['Smiles'] = input_df['mol'].apply(molToSmile)
output_df = input_df[['Smiles']]
return output_df
3. Save and Provide Inputs/Output Parameters to the Function:
Save the Python script and deploy it as a data function in Spotfire.
---
Please find the attached sample dashboard.
Related Articles:
Export Structures as SMILES