Adding reaction details (catalyst, base, solvents their amounts, temp etc) above and below the reaction arrow as required #7369
Unanswered
SimonMutton81
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I've been trying to write some code to add context to reactions for reports by adding e.g. catalyst, (mol%), base (mol equivs) above the reaction arrow and solvent (mls), solvent ratios, Molarity, Temp and time below the reaction arrow for a SMILES reaction, which use
reaction = AllChem.ReactionFromSmarts(reaction_smiles)
and attempt to append reaction conditions data. However, I either get this errorOr it ignores the reaction conditions and just returns the plain reaction scheme, depending on how I construct the code.
It looks as though the ChemicalReaction needs to have A [+ B] -> C [+D, E etc] with no additional contextual data. Is this correct?
I can get round this issue, but I need to convert the SMILES rxn into an image, then add Conditions_Above and Conditions_Below as text, orientate etc, save as a png and export. However, it would be better if we could have the option to make a RDKit reaction with the reaction context associated, if that context is stored in eg a pandas df. This modified reaction scheme could then used in a GUI or converted to png/svg for reporting, with all the correct formatting. Is this something that is being considered?
Happy to share the code for the workaround; I am using it in Knime Python scripting node at the moment. It's my first post, so not sure how to do all the nice formatting etc, so apologies for that! If this has already been solved, please could someone point me to where the solution could be found? Thanks
import pandas as pd
from rdkit import Chem
from rdkit.Chem import AllChem, Draw
from PIL import Image, ImageDraw, ImageFont
import io
import knime.scripting.io as knio
import base64
import os
Sample data in pandas format
'data = {
'Reaction_SMILES': ['CCO.CC(=O)C>>CCOCC(=O)C', 'CCN>>CCN'],
'Catalyst': ['PdCl2', 'PtCl2'],
'Catalyst_mol_percent': [1, 2],
'Base': ['KOH', 'NaOH'],
'Base_molar_equivalents': [2, 3],
'Solvent': ['CH3OH', 'H2O'],
'Solvent_volume_ml': [10, 20],
'Solvent_ratio': ['1:1', '2:1'],
'Molarity': [0.5, 1.0],
'Temperature_C': [25, 50],
'Time_hours': [2, 4]
}
df = pd.DataFrame(data)
Create a list to store the image data, conditions and file paths
reaction_data = []
file_paths = []
Draw the reactions with conditions, encode the image to byte array, and add to the list
for i, reaction_smiles in enumerate(df['Reaction_SMILES']):
reaction = AllChem.ReactionFromSmarts(reaction_smiles)
conditions_above = f"Catalyst: {df.at[i, 'Catalyst']} ({df.at[i, 'Catalyst_mol_percent']} mol%)\nBase: {df.at[i, 'Base']} ({df.at[i, 'Base_molar_equivalents']} equivs)"
conditions_below = f"Solvents: {df.at[i, 'Solvent']}, {df.at[i, 'Solvent_volume_ml']} ml,\n{df.at[i, 'Solvent_ratio']},\nMolarity: {df.at[i, 'Molarity']},\nTemperature: {df.at[i, 'Temperature_C']}°C,\nTime: {df.at[i, 'Time_hours']} hours"
Add the images and file paths as new columns in the dataframe
df['Reaction_Images'] = reaction_data
df['Temp_File_Location'] = file_paths
Output the dataframe as Knime table with Reaction_Images and Temp_File_Location columns as strings
knio.output_tables[0] = knio.Table.from_pandas(df)
Beta Was this translation helpful? Give feedback.
All reactions