#1. Import modules pip install rdkit pip install molvs import pandas as pd import numpy as np import rdkit import molvs from rdkit import Chem standardizer = molvs.Standardizer() fragment_remover = molvs.fragment.FragmentRemover() # 2. Convert the SDF file from the original paper into data frame # Before running the code, please download SDF files from the original paper # https://pubs.acs.org/doi/10.1021/acs.jmedchem.3c00482 from rdkit.Chem import PandasTools sdfFile = 'Redox_training_set_curated.sdf' dataframe = PandasTools.LoadSDF(sdfFile) dataframe.to_csv('redox.csv', index=False) df = pd.read_csv('redox.csv') # 3. Resolve SMILES parse error # Some of the 'Raw_SMILES' rows contain TWO SMILES separated by ';'' and, they cause SMILES parse error (which means they cannot be read) # So we separated the SMILES and renamed the columns df.rename(columns = {'PUBCHEM_EXT_DATASOURCE_REGID': 'REGID_1'}, inplace = True) df.rename(columns = {'Other REGIDs': 'REGID_2'}, inplace = True) df.insert(3, 'SMILES_2', np.NaN) df['SMILES_2'] = df['Raw_SMILES'].str.split(';').str[1] df['Raw_SMILES'] = df['Raw_SMILES'].str.split(';').str[0] df.rename(columns= {'Raw_SMILES' : 'SMILES_1'}, inplace = True) df.insert(10, 'AC50_uM_2', np.NaN) df['AC50_uM_2'] = df['AC50_uM'].str.split(';').str[1] df['AC50_uM'] = df['AC50_uM'].str.split(';').str[0] df.rename(columns = {'AC50_uM': 'AC50_uM_1'}, inplace = True) # 4. Sanitize with MolVS and print problems df['X_1'] = [ \ rdkit.Chem.MolToSmiles( fragment_remover.remove( standardizer.standardize( rdkit.Chem.MolFromSmiles( smiles)))) for smiles in df['SMILES_1']] def process_smiles(smiles): if pd.isna(smiles): return None try: return rdkit.Chem.MolToSmiles( fragment_remover.remove( standardizer.standardize( rdkit.Chem.MolFromSmiles(smiles)))) except Exception as e: print(f"Error processing SMILES {smiles}: {e}") return None df['X_2'] = df['SMILES_2'].apply(process_smiles) # 5. Rename the columns df.rename(columns={'X_1' : 'newSMILES_1', 'X_2' : 'newSMILES_2'}, inplace = True) # 6. Create a file with sanitized SMILES df[['REGID_1', 'REGID_2', 'newSMILES_1', 'newSMILES_2', 'log_AC50_M', 'Efficacy', 'CC-v2', 'Outcome', 'InChIKey', 'AC50_uM_1', 'AC50_uM_2', 'ID', 'ROMol']].to_csv('redox_sanitized.csv', index = False)