## Script to sanitize and split AggregatorAdvisor dataset # 1. Load modules pip install rdkit pip install molvs import pandas as pd import numpy as np import urllib.request import tqdm import rdkit from rdkit import Chem import molvs standardizer = molvs.Standardizer() fragment_remover = molvs.fragment.FragmentRemover() #3. Resolve SMILES parse error # Smiles is 'None', found the compound on ChemSpider # Smiles displayed 'Explicit valence for atom # 2 O, 3, is greater than permitted' # https://www.chemspider.com/Chemical-Structure.17588253.html?rid=026abd00-5d7b-4c7a-b279-3ba43ab46203 AA.loc[AA['smiles'] == '[O-][N+](=[O-])C1=CC=CC(=C1)C2=NC(CO2)C3=CC=CC=C3' , 'smiles'] = 'c1ccc(cc1)C2COC(=N2)c3cccc(c3)[N+](=O)[O-]' # Smiles is 'None', found the compound on ChemSpider # Smiles displayed 'Explicit valence for atom # 2 O, 3, is greater than permitted' # https://www.chemspider.com/Chemical-Structure.17588254.html?rid=0f94ced5-dee6-4274-b0c5-796500b40be7 AA.loc[AA['smiles'] == '[O-][N+](=[O-])C1=CC=CC(=C1)C2=NCCC(O2)C3=CC=CC=C3', 'smiles'] = 'c1ccc(cc1)C2CCN=C(O2)c3cccc(c3)[N+](=O)[O-]' #4. Sanitize with MolVS and print problems AA['X'] = [ \ rdkit.Chem.MolToSmiles( fragment_remover.remove( standardizer.standardize( rdkit.Chem.MolFromSmiles( smiles)))) for smiles in AA['smiles']] problems = [] for index, row in tqdm.tqdm(AA.iterrows()): result = molvs.validate_smiles(row['X']) if len(result) == 0: continue problems.append( (row['substance_id'], result) ) # most are because it includes the salt form and/or it is not neutralized for substance_id, alert in problems: print(f"substance_id: {substance_id}, problem: {alert[0]}") #5. Select columns and rename the dataset AA.rename(columns={'X': 'new SMILES'}, inplace=True) AA[['new SMILES', 'substance_id', 'aggref_index', 'logP']].to_csv('AggregatorAdvisor.csv', index=False)