<jupyter_start><jupyter_text>Chapter 2 : Rdkit<jupyter_code>from rdkit import Chem
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Loading Molecules from SMILES Representations:<jupyter_code>SMILES = "[Br-].[Br-].CCCCCCCCCCC[N+]1=CC=C(CCCC2=CC=[N+](CCCCCCCCCCC)C=C2)C=C1"
molecule = Chem.MolFromSmiles(SMILES)
molecule
print(molecule)<jupyter_output><rdkit.Chem.rdchem.Mol object at 0x00000217075DEF40><jupyter_text>Searching for Substructures:<jupyter_code>tail_pattern = Chem.MolFromSmarts('CCCCCCCCCCC')
tail_pattern
molecule.HasSubstructMatch(tail_pattern)
phenol_pattern = Chem.MolFromSmarts('OC1=CC=CC=C1 ')
phenol_pattern
molecule.HasSubstructMatch(phenol_pattern)<jupyter_output><empty_output><jupyter_text>Similarity Calculations<jupyter_code>from rdkit import DataStructs
from rdkit.Chem import Draw
mol_sim = [Chem.MolFromSmiles('[Br-].[Br-].CCCCCC[N+]1=CC=C(CCCC2=CC=[N+](CCCCCC)C=C2)C=C1'), Chem.MolFromSmiles('[Br-].[Br-].CCCCCCCCCCC[N+]1=CC=C(CCCC2=CC=[N+](CCCCCCCCCCC)C=C2)C=C1')]
mol_sim
fps = [Chem.RDKFingerprint(x) for x in mol_sim]
fps
DataStructs.FingerprintSimilarity(fps[0],fps[1], metric=DataStructs.DiceSimilarity)
DataStructs.FingerprintSimilarity(fps[0],fps[1], metric=DataStructs.CosineSimilarity)
DataStructs.FingerprintSimilarity(fps[0],fps[1], metric=DataStructs.SokalSimilarity)
mol1=Chem.MolFromSmiles('[Br-].[Br-].CCCCCCCCCCC[N+]1=CC=C(CCCC2=CC=[N+](CCCCCCCCCCC)C=C2)C=C1')
mol2=Chem.MolFromSmiles('[Br-].[Br-].C\C=C\CC\C=C\CCCC[N+]1=CC=C(CCCC2=CC=[N+](CCCC\C=C\CC\C=C\C)C=C2)C=C1')
mol1
mol2
fig, maxweight = SimilarityMaps.GetSimilarityMapForFingerprint(mol1, mol2, SimilarityMaps.GetMorganFingerprint)<jupyter_output><empty_output><jupyter_text>Chemical Transformations<jupyter_code>molecule = Chem.MolFromSmiles('[Br-].[Br-].CCCCCCCCCCC[N+]1=CC=C(CCCC2=CC=[N+](CCCCCCCCCCC)C=C2)C=C1')
molecule
pattern = Chem.MolFromSmarts('CCCCCCCCCCC')
pattern
modified_molecule = AllChem.DeleteSubstructs(molecule, pattern)
modified_molecule<jupyter_output><empty_output><jupyter_text>Feature Generation<jupyter_code>from rdkit.Chem import Descriptors
mol1=Chem.MolFromSmiles('[Br-].[Br-].CCCCCCCCCCC[N+]1=CC=C(CCCC2=CC=[N+](CCCCCCCCCCC)C=C2)C=C1')
Descriptors.ExactMolWt(mol1)
Descriptors.MolLogP(mol1)
Descriptors.HeavyAtomCount(mol1)
Descriptors.NumRotatableBonds(mol1)
Descriptors.RingCountmol1m)
Chem.Fragments.fr_Ar_N(mol1, countUnique=True)
Chem.rdmolops.GetFormalCharge(mol1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15780933062880326, 'fraction_numerical': 0.02636916835699797, 'mean_word_length': 13.254335260115607, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 12, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '575518', 'license': 'MIT', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1060, 'n_words': 88, 'path': 'chapters/chapter2/ch2_rdkit.ipynb', 'repo_name': 'arifmudi/Machine-Learning-in-Biotechnology-using-Python', 'size': '2465'}