### Setup Datamol Development Environment Source: https://github.com/datamol-io/datamol/blob/main/docs/contribute.md Instructions to set up the Datamol development environment using mamba and pip. This creates a dedicated environment based on 'env.yml' and installs the project in editable mode for development. ```bash mamba env create -n datamol -f env.yml mamba activate datamol pip install -e . ``` -------------------------------- ### Datamol Quick API Tour: Molecular Processing Examples Source: https://github.com/datamol-io/datamol/blob/main/README.md Demonstrates common molecular processing tasks using the `datamol` Python library. Includes examples for converting molecules to different formats (SMILES, InChI, SELFIES), standardizing and sanitizing molecules, manipulating molecular dataframes, 2D and 3D visualization, conformer generation, and I/O operations with remote paths. ```python import datamol as dm # Common functions mol = dm.to_mol("O=C(C)Oc1ccccc1C(=O)O", sanitize=True) fp = dm.to_fp(mol) selfies = dm.to_selfies(mol) inchi = dm.to_inchi(mol) # Standardize and sanitize mol = dm.to_mol("O=C(C)Oc1ccccc1C(=O)O") mol = dm.fix_mol(mol) mol = dm.sanitize_mol(mol) mol = dm.standardize_mol(mol) # Dataframe manipulation df = dm.data.freesolv() mols = dm.from_df(df) # 2D viz legends = [dm.to_smiles(mol) for mol in mols[:10]] dm.viz.to_image(mols[:10], legends=legends) # Generate conformers smiles = "O=C(C)Oc1ccccc1C(=O)O" mol = dm.to_mol(smiles) mol_with_conformers = dm.conformers.generate(mol) # 3D viz (using nglview) dm.viz.conformers(mol, n_confs=10) # Compute SASA from conformers sasa = dm.conformers.sasa(mol_with_conformers) # Easy IO mols = dm.read_sdf("s3://my-awesome-data-lake/smiles.sdf", as_df=False) dm.to_sdf(mols, "gs://data-bucket/smiles.sdf") ``` -------------------------------- ### Install Datamol using Conda/Mamba Source: https://github.com/datamol-io/datamol/blob/main/README.md Instructions for installing the Datamol library using the Conda package manager, specifically with mamba for faster installation. ```bash mamba install -c conda-forge datamol ``` -------------------------------- ### Install Datamol Python Library via Conda/Mamba Source: https://github.com/datamol-io/datamol/blob/main/docs/index.md This snippet provides the command to install the Datamol library using `mamba` or `conda` from the `conda-forge` channel. It's the recommended installation method to ensure all dependencies are correctly managed for the Python library. ```bash mamba install -c conda-forge datamol ``` -------------------------------- ### Join Remote Paths with datamol.fs.join Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This example illustrates how `dm.fs.join` can concatenate path components, including remote bucket paths, to form a complete and valid path string. ```python data_dir = "gs://awesome-data-bucket/data_dir" filename = "molecules.sdf" dm.fs.join(data_dir, filename) ``` -------------------------------- ### Define Molecules for Fragment Replacement (Python) Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Reactions.ipynb This snippet defines a scaffold and two fragment molecules using `dm.to_mol` for subsequent fragment replacement examples. It also visualizes these molecules using `dm.to_image` to illustrate the starting materials for the reactions. ```python scaffold = dm.to_mol("O=C(NCc1ccnc([2*])c1)[1*]") frag1 = dm.to_mol("[1*]OC1CCC1") frag2 = dm.to_mol("[2*]N1CCCC1") dm.to_image([scaffold, frag1, frag2]) ``` -------------------------------- ### Copy Remote File to Local Destination with datamol.fs.copy_file Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This example shows how to copy a file from a remote URL to a local destination using `dm.fs.copy_file`. It includes options for displaying progress and forcing overwrite if the destination exists. ```python destination_path = dm.fs.join(subdir_path, "cdk2.sdf") dm.fs.copy_file( source="https://raw.githubusercontent.com/rdkit/rdkit/master/Docs/Book/data/cdk2.sdf", destination=destination_path, progress=True, force=True, ) ``` -------------------------------- ### Retrieve Remote Paths Matching Pattern with datamol.fs.glob Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This example demonstrates using `dm.fs.glob` to find paths matching a specified pattern on a remote FTP server. The `[:5]` slices the result to show only the first five matches. ```python dm.fs.glob("https://ftp.ncbi.nlm.nih.gov/pubchem/Compound/Daily/**")[:5] ``` -------------------------------- ### API Reference for datamol.fragment._assemble Source: https://github.com/datamol-io/datamol/blob/main/docs/api/datamol.fragment.md This entry refers to the auto-generated API documentation for the `_assemble` object (function or class) within the `datamol.fragment` module. It typically includes details on its purpose, parameters, return values, and usage examples related to assembling molecular fragments. ```APIDOC datamol.fragment._assemble ``` -------------------------------- ### Get MD5 Checksum of Remote File with datamol.fs.md5 Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This example demonstrates how to compute the MD5 checksum of a remote file using `dm.fs.md5`, providing a way to verify file integrity after transfer. ```python dm.fs.md5("https://ftp.ncbi.nlm.nih.gov/pubchem/Compound/CURRENT-Full/README-Compound") ``` -------------------------------- ### Assemble New Molecules from Fragments using Datamol BRICS Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Fragment.ipynb This example illustrates how to assemble new molecules from a list of fragments generated by the BRICS algorithm. It emphasizes the computational cost of assembly and demonstrates limiting the number of fragments and assembled molecules using `max_n_mols` for efficiency. The process involves generating fragments from a SMILES string, selecting a subset, and then assembling them into new molecules for visualization. ```python # Assembling new molecules based on a list of fragments # Get the fragment set of a molecule smiles = "CCCOCc1cc(c2ncccc2)ccc1" mol = dm.to_mol(smiles) with dm.without_rdkit_log(): frags = dm.fragment.brics(mol) # Limit the number of fragments to work with because assembling is computationally intensive. frags = frags[:3] # Assemble 8 molecules from the list of fragments with dm.without_rdkit_log(): mols = list(dm.fragment.assemble_fragment_order(frags, max_n_mols=8)) dm.to_image(mols, mol_size=(250, 150)) ``` -------------------------------- ### Get Basename of a Remote Directory Path Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This example further illustrates `dm.fs.get_basename` by extracting the last component of a remote directory path, which is the directory's name itself. ```python dm.fs.get_basename("https://ftp.ncbi.nlm.nih.gov/pubchem/Compound/Daily/2021-12-03") ``` -------------------------------- ### Align Molecules by Clustering Common Scaffolds in Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Aligning.ipynb This example demonstrates a more advanced automatic alignment where molecules are first partitioned into clusters based on shared scaffolds using `partition_method="cluster"` with `dm.align.auto_align_many`. This is useful for larger datasets where molecules might share multiple distinct cores. The aligned molecules are then visualized with a custom image size. ```python data = dm.data.cdk2()[0:24] smiles = data["smiles"].iloc[:].tolist() mols = [dm.to_mol(s) for s in smiles] aligned_list = dm.align.auto_align_many(mols, partition_method="cluster") dm.to_image(aligned_list, mol_size=(200, 150)) ``` -------------------------------- ### Generate a single 3D conformer using ETKDG Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Conformers.ipynb Generates an initial 3D conformer for the molecule using the default ETKDG (Experimental-Torsion Distance Geometry) algorithm. This provides a starting 3D structure before generating multiple conformers. ```Python AllChem.EmbedMolecule(m2) ``` -------------------------------- ### Get Size of Remote File with datamol.fs.get_size Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This snippet uses `dm.fs.get_size` to retrieve the size in bytes of a specified remote file, which is useful for managing data transfers or storage. ```python dm.fs.get_size( "https://ftp.ncbi.nlm.nih.gov/pubchem/Compound/CURRENT-Full/SDF/Compound_000000001_000500000.sdf.gz" ) ``` -------------------------------- ### API Reference for datamol.fragment._fragment Source: https://github.com/datamol-io/datamol/blob/main/docs/api/datamol.fragment.md This entry refers to the auto-generated API documentation for the `_fragment` object (function or class) within the `datamol.fragment` module. It typically includes details on its purpose, parameters, return values, and usage examples related to molecular fragmentation. ```APIDOC datamol.fragment._fragment ``` -------------------------------- ### Get Number of Generated Conformers Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Conformers.ipynb Returns the total count of conformers present in the list obtained from the molecule object. Useful for verifying the number of conformers generated. ```python len(conformers) ``` -------------------------------- ### Check Existence of Remote GCS Path Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb Similar to the previous example, this snippet uses `dm.fs.exists` to check the existence of a path on a Google Cloud Storage (GCS) bucket, highlighting multi-cloud support. ```python dm.fs.exists("gs://a-gcs-bucket-random/subdir1/subdir2/hello.txt") ``` -------------------------------- ### Get Shape of RMSD Matrix Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Conformers.ipynb Returns the dimensions of the computed RMSD matrix. For N conformers, the shape will be (N, N), indicating the pairwise RMSD values. ```python rmsd.shape ``` -------------------------------- ### Get File Extension from Remote Path Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This snippet demonstrates `dm.fs.get_extension` to retrieve the file extension from a given remote S3 path, useful for file type identification. ```python dm.fs.get_extension("s3://an-s3-bucket-random/subdir1/subdir2/hello.txt") ``` -------------------------------- ### Get Basename of a Remote File Path Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This snippet uses `dm.fs.get_basename` to extract the file name (basename) from a full remote URL path, demonstrating its utility for path manipulation. ```python dm.fs.get_basename( "https://ftp.ncbi.nlm.nih.gov/pubchem/Compound/Daily/2021-12-03/SDF/Compound_013500001_014000000.sdf.gz" ) ``` -------------------------------- ### Check if Remote Path is a Directory with datamol.fs.is_dir Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This example uses `dm.fs.is_dir` to verify if a specified Google Cloud Storage path refers to an existing directory, useful for distinguishing between file and directory paths. ```python dm.fs.is_dir("gs://a-gcs-bucket-random/subdir1/subdir2/") ``` -------------------------------- ### Build and Serve Datamol Documentation Locally Source: https://github.com/datamol-io/datamol/blob/main/docs/contribute.md Command to build and serve the Datamol documentation locally using the 'mike' tool. This allows developers to preview documentation changes before deployment. ```bash mike serve ``` -------------------------------- ### Create and Verify Temporary Directory Existence Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This code creates a temporary directory using `tempfile.mkdtemp()` and then verifies its existence using `dm.fs.exists()`, demonstrating a basic filesystem check. ```python temp_dir = tempfile.mkdtemp() dm.fs.exists(temp_dir) ``` -------------------------------- ### Import Datamol and tempfile Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This snippet imports the necessary `tempfile` module for creating temporary directories and the `datamol` library, aliased as `dm`, to access its filesystem utilities. ```python import tempfile import datamol as dm ``` -------------------------------- ### Initialize Datamol and Import Libraries Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Preprocessing.ipynb Imports necessary libraries like pandas and datamol, and disables RDKit logging for cleaner output, preparing the environment for molecular data processing. ```python import pandas as pd import datamol as dm dm.disable_rdkit_log() ``` -------------------------------- ### Load and Sample Datamol Freesolv Dataset Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Preprocessing.ipynb This snippet demonstrates how to load the 'freesolv' dataset using `dm.data.freesolv()` from the datamol library and then sample the first 100 rows using pandas `iloc` for quicker processing or testing. ```python data = dm.data.freesolv() data = data.iloc[:100] data ``` -------------------------------- ### Create Nested Directory with datamol.fs.mkdir Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This snippet demonstrates how to create a nested directory structure using `dm.fs.join` for path construction and `dm.fs.mkdir` to create the directory, ensuring it exists with `exist_ok=True`. It then verifies the creation with `dm.fs.exists`. ```python subdir_path = dm.fs.join(temp_dir, "subdir1", "subsubdir293") dm.fs.mkdir(subdir_path, exist_ok=True) dm.fs.exists(subdir_path) ``` -------------------------------- ### Load and Prepare Molecular Data with Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Fuzzy_Scaffolds.ipynb This snippet demonstrates how to load a sample dataset (cdk2) using `dm.data.cdk2()`, convert SMILES strings to RDKit molecule objects using `dm.to_mol()`, and then visualize a subset of these molecules as an image. This is a common first step before performing molecular operations. ```python import datamol as dm # Get some mols data = dm.data.cdk2() data["mol"] = data["smiles"].apply(dm.to_mol) dm.to_image(data["mol"].iloc[:12].tolist(), mol_size=(200, 150)) ``` -------------------------------- ### Copy Remote Directory Tree with datamol.fs.copy_dir Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This snippet illustrates copying an entire directory tree from a remote source to a local destination using `dm.fs.copy_dir`. The `progress=True` argument enables progress reporting during the transfer. ```python subdir2_path = dm.fs.join(temp_dir, "subdir2") dm.fs.copy_dir( source="https://ftp.ncbi.nlm.nih.gov/pubchem/specifications/", destination=subdir2_path, progress=True, ) ``` -------------------------------- ### Import necessary RDKit and utility libraries Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Conformers.ipynb This snippet imports all the required modules from RDKit for molecular manipulation, conformer generation, and alignment, along with standard Python libraries like `copy` and `numpy`. ```Python from rdkit import Chem from rdkit.Chem import AllChem from rdkit.Chem import rdDistGeom from rdkit.Chem import rdMolAlign from rdkit.Chem import rdMolDescriptors from rdkit.Chem import rdMolTransforms from rdkit.Chem import rdForceFieldHelpers from rdkit.Chem import PyMol import copy import numpy as np ``` -------------------------------- ### Picking Diverse Molecules with Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Clustering.ipynb Demonstrates how to select a diverse set of molecules from a collection using Datamol's `dm.pick_diverse` function, specifying the number of picks, and then visualizes the selected molecules. ```python indices, picks = dm.pick_diverse(mols, npick=10) dm.to_image(picks, mol_size=(150, 100)) ``` -------------------------------- ### Apply Reaction with SMARTS for Multiple Attachments (Python) Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Reactions.ipynb This snippet demonstrates defining a complex reaction using SMARTS to connect multiple molecules at several specified attachment points simultaneously. It then applies this reaction using `datamol.reactions.apply_reaction` to combine a scaffold and two fragments, showcasing advanced multi-component reactions. ```python rxn2 = dm.reactions.rxn_from_smarts("[1*][*:1].[2*][*:4].([1*][*:2].[2*][*:3])>>([*:1][*:2].[*:3][*:4])") res2 = dm.reactions.apply_reaction(rxn2, (frag1, frag2, scaffold), product_index=0) dm.to_image(res2) ``` -------------------------------- ### Molecular Clustering and Diversity Picking with RDKit and Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Clustering.ipynb Demonstrates how to perform Butina clustering and MaxMinPicker diversity selection on molecular data using RDKit, with data loading facilitated by Datamol. It involves calculating fingerprints, defining a Tanimoto similarity-based distance function, and applying the picking algorithm. ```python # now cluster the data cluster_indices = Butina.ClusterData(dists, n_mols, cutoff, isDistData=True) cluster_mols = [operator.itemgetter(*cluster)(mols) for cluster in cluster_indices] # Make single mol cluster a list cluster_mols = [[c] if isinstance(c, Chem.rdchem.Mol) else c for c in cluster_mols] ### Pick diverse compounds # Get some mols data = dm.data.freesolv() smiles = data["smiles"].iloc[:].tolist() mols = [Chem.MolFromSmiles(s) for s in smiles] # Calculate fingerprints fps = [Chem.RDKFingerprint(x) for x in mols] def distij(i, j, features=fps): return 1.0 - DataStructs.cDataStructs.TanimotoSimilarity(fps[i], fps[j]) npick = 10 seed = 0 picker = MaxMinPicker() initial_picks = [] picked_inds = picker.LazyPick(distij, len(mols), npick, firstPicks=initial_picks, seed=seed) picked_inds = np.array(picked_inds) picked_mols = [mols[x] for x in picked_inds] picked_inds, picked_mols ``` -------------------------------- ### Run Datamol Tests Source: https://github.com/datamol-io/datamol/blob/main/docs/contribute.md Command to execute the test suite for the Datamol project. This runs all defined tests to ensure code functionality and stability. ```bash pytest ``` -------------------------------- ### Datamol Quick API Tour: Molecular Manipulation and I/O in Python Source: https://github.com/datamol-io/datamol/blob/main/docs/index.md This Python code demonstrates a wide range of Datamol's capabilities, including converting molecular representations (SMILES, InChI, SELFIES), standardizing and sanitizing molecules, integrating with Pandas DataFrames, performing 2D and 3D visualizations, generating molecular conformers, and handling I/O operations for various molecular file formats. ```python import datamol as dm # Common functions mol = dm.to_mol("O=C(C)Oc1ccccc1C(=O)O", sanitize=True) fp = dm.to_fp(mol) selfies = dm.to_selfies(mol) inchi = dm.to_inchi(mol) # Standardize and sanitize mol = dm.to_mol("O=C(C)Oc1ccccc1C(=O)O") mol = dm.fix_mol(mol) mol = dm.sanitize_mol(mol) mol = dm.standardize_mol(mol) # Dataframe manipulation df = dm.data.freesolv() mols = dm.from_df(df) # 2D viz legends = [dm.to_smiles(mol) for mol in mols[:10]] dm.viz.to_image(mols[:10], legends=legends) # Generate conformers smiles = "O=C(C)Oc1ccccc1C(=O)O" mol = dm.to_mol(smiles) mol_with_conformers = dm.conformers.generate(mol) # 3D viz (using nglview) dm.viz.conformers(mol, n_confs=10) # Compute SASA from conformers sasa = dm.conformers.sasa(mol_with_conformers) # Easy IO mols = dm.read_sdf("s3://my-awesome-data-lake/smiles.sdf", as_df=False) dm.to_sdf(mols, "gs://data-bucket/smiles.sdf") ``` -------------------------------- ### List Files in Directory Using datamol.fs.glob Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This code uses `dm.fs.glob` with a wildcard pattern to list all files and directories within the recently copied `subdir2_path`, verifying the success of the directory copy operation. ```python dm.fs.glob(dm.fs.join(subdir2_path, "**")) ``` -------------------------------- ### Load and Visualize Molecules with Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Aligning.ipynb This snippet demonstrates how to load a subset of molecules from the `cdk2` dataset using `datamol` and convert them into molecular objects. The initial, unaligned molecules are then displayed as an image. ```python import datamol as dm data = dm.data.cdk2()[13:15] smiles = data["smiles"].iloc[:].tolist() mols = [dm.to_mol(s) for s in smiles] dm.to_image(mols) ``` -------------------------------- ### Molecular Clustering with Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Clustering.ipynb Illustrates simplified molecular clustering using Datamol's `dm.cluster_mols` function. It loads a dataset, converts SMILES to molecules, applies the clustering algorithm with a specified cutoff, and visualizes the first cluster. ```python import datamol as dm # Load example dataset data = dm.data.freesolv() smiles = data["smiles"].iloc[:].tolist() mols = [dm.to_mol(s) for s in smiles] # Cluster the mols clusters, mol_clusters = dm.cluster_mols(mols, cutoff=0.7) # Cluster #1 dm.to_image(mol_clusters[0], mol_size=(150, 100), n_cols=6, max_mols=18) ``` -------------------------------- ### Define Chemical Reaction from Block File (Python) Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Reactions.ipynb This snippet demonstrates how to load a chemical reaction definition from a Reaction Block (.rxn) file using `datamol.reactions.rxn_from_block_file`. The `sanitize` parameter ensures the reaction is chemically valid. ```python rxn = dm.reactions.rxn_from_block_file("data/ReactionBlock.rxn", sanitize=True) rxn ``` -------------------------------- ### Importing the datamol library Source: https://github.com/datamol-io/datamol/blob/main/docs/usage.md Datamol is designed for single-import usage, making all its functions available under the 'dm' alias. This snippet demonstrates the standard and recommended way to import the library for general use. ```python import datamol as dm ``` -------------------------------- ### Picking Centroids from Molecular Data with Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Clustering.ipynb Shows how to identify and visualize centroids from a set of molecules using Datamol's `dm.pick_centroids` function. It allows specifying the number of centroids, a threshold, the picking method, and parallel processing. ```python indices, centroids = dm.pick_centroids(mols, npick=18, threshold=0.7, method="sphere", n_jobs=-1) dm.to_image(centroids, mol_size=(150, 100), n_cols=6) ``` -------------------------------- ### Apply Reaction and Retain Open Attachment Points (Python) Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Reactions.ipynb This snippet demonstrates applying a reaction where open attachment points are explicitly retained in the product. It uses `datamol.reactions.apply_reaction` with `rm_attach=False` and `single_product_group=True` to return a single product molecule, useful for multi-step synthesis or building blocks. ```python prod_smi_att = dm.reactions.apply_reaction( rxn=rxn, reactants=(dm.to_mol("[2*]CC(=O)O"), dm.to_mol("NC[1*]")), as_smiles=False, sanitize=True, single_product_group=True, rm_attach=False, product_index=0 ) prod_smi_att ``` -------------------------------- ### API Reference: datamol.viz.conformers Source: https://github.com/datamol-io/datamol/blob/main/docs/api/datamol.viz.md Provides functionalities related to the visualization of molecular conformers. This can include rendering multiple conformers or specific conformer properties. ```APIDOC datamol.viz.conformers ``` -------------------------------- ### Apply Reaction with SMARTS for Single Attachment (Python) Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Reactions.ipynb This snippet defines a reaction using SMARTS for connecting two molecules at a single attachment point. It then applies this reaction using `datamol.reactions.apply_reaction` to connect a fragment to a scaffold, demonstrating a common fragment coupling strategy. ```python rxn1 = dm.reactions.rxn_from_smarts("[1*][*:1].[1*][*:2]>>[*:1][*:2]") res1 = dm.reactions.apply_reaction(rxn1, (dm.to_mol(frag1), dm.to_mol(scaffold)), rm_attach=True, product_index=0) dm.to_image(res1) ``` -------------------------------- ### Initialize Molecule for RDKit Fragmentation Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Fragment.ipynb Imports necessary RDKit modules and converts a SMILES string into an RDKit molecule object, preparing it for various fragmentation algorithms. ```python from rdkit import Chem from rdkit.Chem.Draw import IPythonConsole, MolsToGridImage from rdkit.Chem import BRICS from rdkit.Chem import Recap from rdkit.Chem.Fraggle import FraggleSim smiles = "CCCOCc1cc(c2ncccc2)ccc1" mol = Chem.MolFromSmiles(smiles) mol ``` -------------------------------- ### Datamol Conformer Generation Parameters Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Conformers.ipynb Key parameters for `dm.conformers.generate` function, controlling the conformer generation process. ```APIDOC dm.conformers.generate parameters: n_confs: int Description: Number of conformers to generate. Default is 200 for >8 rotatable bonds, 50 for <8. add_hs: bool Description: Whether to add hydrogen atoms before embedding. Default is True. minimize_energy: bool Description: Whether to minimize the energy of generated conformers. Default is True. method: string Description: Conformer generation method (e.g., ETKDG versions). energy_iterations: int Description: Number of iterations for energy minimization. rms_cutoff: float Description: Maximum RMSD value for two conformers to be considered the same. ``` -------------------------------- ### Display Picked Molecules using Datamol's to_image Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Clustering.ipynb Shows how to visualize the molecules selected by the RDKit MaxMinPicker using the `dm.to_image` utility function from Datamol, specifying image dimensions. ```python dm.to_image(picked_mols, mol_size=(150, 100)) ``` -------------------------------- ### Perform FraggleSim Fragmentation using Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Fragment.ipynb Illustrates the application of the FraggleSim algorithm using Datamol's `dm.fragment.frag` function. The code suppresses RDKit logs and then visualizes the fragmented molecules. ```python # FraggleSims with dm.without_rdkit_log(): frags = dm.fragment.frag(mol) dm.to_image(frags, mol_size=(250, 150)) ``` -------------------------------- ### Import Datamol Library Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Conformers.ipynb Imports the Datamol library, commonly aliased as `dm`, to access its functionalities for cheminformatics tasks. ```python import datamol as dm ``` -------------------------------- ### Initialize Molecule for Datamol Fragmentation Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Fragment.ipynb Imports the `datamol` library and converts a SMILES string into a Datamol molecule object, setting it up for fragmentation operations within the Datamol framework. ```python import datamol as dm smiles = "CCCOCc1cc(c2ncccc2)ccc1" mol = dm.to_mol(smiles) mol ``` -------------------------------- ### Load Molecules and Display with RDKit Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Scaffolds.ipynb This Python snippet demonstrates how to load a list of SMILES strings into RDKit molecule objects. It then uses `MolsToGridImage` from `rdkit.Chem.Draw` to visualize these molecules in a grid format, providing a clear overview of the input compounds. ```python from rdkit import Chem from rdkit.Chem.Draw import MolsToGridImage # Load a list of molecules smiles_list = [ "CCOC1=CC=CC=C1C(=O)OCC(=O)NC1=CC=CC=C1", "NC(=O)C1=C(NC(=O)COC2=CC=CC=C2C(F)(F)F)SC=C1", "CC(C)NC(=O)CSCC1=CC=CC=C1Br", "CC1=CC=C(C(=O)NC(C)C)C=C1NC(=O)C1=CC=CO1", "O=C(CN1CCCCCC1=O)NCC1=CC=C(N2C=CN=C2)C(F)=C1" ] mol_list = [Chem.MolFromSmiles(smi) for smi in smiles_list] MolsToGridImage(mol_list) ``` -------------------------------- ### Generate and Display Murcko Scaffolds with RDKit Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Scaffolds.ipynb This Python code illustrates how to extract Murcko scaffolds from a list of RDKit molecule objects. It utilizes `MurckoScaffold.GetScaffoldForMol` to derive the core structures, and then visualizes these scaffolds using `MolsToGridImage`, allowing for easy inspection of the generated frameworks. ```python from rdkit import Chem from rdkit.Chem.Scaffolds import MurckoScaffold from rdkit.Chem.Draw import MolsToGridImage # Assuming 'mol_list' is already defined from previous steps # mol_list = [Chem.MolFromSmiles(smi) for smi in smiles_list] scaffolds = [MurckoScaffold.GetScaffoldForMol(mol) for mol in mol_list] MolsToGridImage(scaffolds) ``` -------------------------------- ### Configure conformer embedding parameters Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Conformers.ipynb Sets up parameters for the conformer generation process, including the algorithm (ETDG), a random seed for reproducibility, chirality enforcement, and the number of threads to use. These parameters allow fine-grained control over the quality and diversity of generated conformers. ```Python params = getattr(rdDistGeom, "ETDG")() params.randomSeed = 0 params.enforceChirality = True params.useRandomCoords = True params.numThreads = 1 ``` -------------------------------- ### Prepare Molecules and Fingerprints for Clustering using RDKit Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Clustering.ipynb This Python code snippet demonstrates the initial steps for molecular clustering using RDKit. It loads SMILES data from a datamol dataset, converts them into RDKit molecule objects, generates RDKit fingerprints for each molecule, and then calculates a Tanimoto distance matrix. This distance matrix is a prerequisite for subsequent clustering algorithms like Butina, which will group molecules based on their structural similarity. ```python import operator import datamol as dm import numpy as np from rdkit import Chem from rdkit.Chem import DataStructs from rdkit.ML.Cluster import Butina from rdkit.SimDivFilters.rdSimDivPickers import MaxMinPicker ### Clustering compounds # Get some mols data = dm.data.freesolv() smiles = data["smiles"].iloc[:].tolist() mols = [Chem.MolFromSmiles(s) for s in smiles] # Create fingerprints fps = [Chem.RDKFingerprint(x) for x in mols] # Calculate distance matrix dists = [] n_mols = len(mols) for i in range(1, n_mols): dist = DataStructs.cDataStructs.BulkTanimotoSimilarity(fps[i], fps[:i], returnDistance=True) dists.extend([x for x in dist]) cutoff = 0.2 ``` -------------------------------- ### Perform BRICS Fragmentation using Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Fragment.ipynb Demonstrates how to use Datamol's `dm.fragment.brics` function to perform BRICS fragmentation. It includes a context manager to suppress RDKit logs and visualizes the resulting fragments. ```python # BRICS with dm.without_rdkit_log(): frags = dm.fragment.brics(mol) dm.to_image(frags, mol_size=(250, 150)) ``` -------------------------------- ### Load and Visualize Molecular Data with Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Descriptors.ipynb This Python snippet uses `datamol` to load molecular data from an SDF file into a pandas DataFrame. It converts SMILES strings to `mol` objects and visualizes the first 12 molecules, serving as the initial step for processing a virtual screening library. ```python import datamol as dm # Part 1: Obtain a list of molecules and visualize # Load sdf downloaded from Enamine with the flag as_df set to True # This will automatically create a 'smiles' column from the sdf file data = dm.read_sdf("./data/Enamine_DNA_Libary_5530cmpds_20200831_SMALL.sdf", as_df=True) data["mol"] = data["smiles"].apply(dm.to_mol) mols = data["mol"].tolist() dm.to_image(mols[:12], mol_size=(200, 150)) ``` -------------------------------- ### Retrieve Application Cache Directory Path with datamol.fs.get_cache_dir Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Filesystem.ipynb This snippet shows how to obtain the platform-specific official cache directory path using `dm.fs.get_cache_dir`. It allows specifying an application name and a suffix, and can optionally prevent directory creation. ```python dm.fs.get_cache_dir(app_name="datamol-demo", suffix="subdir1", create=False) ``` -------------------------------- ### Import datamol Library (Python) Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Reactions.ipynb This snippet imports the `datamol` library, aliasing it as `dm`, which is necessary to use its functionalities for chemical reactions and molecule manipulation. ```python import datamol as dm ``` -------------------------------- ### Apply Reaction and Remove Open Attachment Points (Python) Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Reactions.ipynb This snippet shows how to apply a reaction and remove any open attachment points from the product. It uses `datamol.reactions.apply_reaction` with `rm_attach=True` and `single_product_group=True` to return a single, complete product molecule, suitable for final products. ```python prod_mol = dm.reactions.apply_reaction( rxn=rxn, reactants=(dm.to_mol("[2*]CC(=O)O"), dm.to_mol("NC[1*]")), as_smiles=False, sanitize=True, single_product_group=True, rm_attach=True, product_index=0 ) prod_mol ``` -------------------------------- ### Display a Source Molecule for Template Alignment Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Aligning.ipynb This snippet displays the first molecule (`mols[0]`) from the loaded list. This molecule will serve as the 'source' molecule that will be aligned to a specified template. ```python mols[0] ``` -------------------------------- ### Perform RECAP Fragmentation with Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Fragment.ipynb This snippet demonstrates how to apply the RECAP fragmentation algorithm to a molecule using `dm.fragment.recap`. It also shows how to visualize the resulting fragments. The `dm.without_rdkit_log()` context manager is used to suppress RDKit logging during the fragmentation process. ```python with dm.without_rdkit_log(): frags = dm.fragment.recap(mol) dm.to_image(frags, mol_size=(250, 150)) ``` -------------------------------- ### Apply Chemical Reaction to Reactants (Python) Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Reactions.ipynb This snippet applies a defined chemical reaction to a set of reactants (SMILES converted to Mol objects) using `datamol.reactions.apply_reaction`. It returns multiple product molecules, sanitizes them, and allows specifying the product group and index for more control over the output. ```python prod_mols = dm.reactions.apply_reaction( rxn=rxn, reactants=(dm.to_mol("CC(=O)O"), dm.to_mol("NC")), as_smiles=False, sanitize=True, single_product_group=False, product_index=0 ) dm.to_image(prod_mols) ``` -------------------------------- ### Perform BRICS Fragmentation using RDKit Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Fragment.ipynb Applies the BRICS algorithm via RDKit's `BRICSDecompose` function to fragment a molecule. The code then converts the resulting fragments into a list and visualizes them using `MolsToGridImage`. ```python # Decompose compounds based on BRICS algorithm. # Calling dm.fragment.brics runs this algorithm, as well as fixes/sanitizes fragments in one line of code. brics_frags = BRICS.BRICSDecompose(mol, returnMols=True, singlePass=True) brics_frags = list(brics_frags) MolsToGridImage(brics_frags) # Recap, FraggleSim and rdMMPA can be run in a similar manner as the BRICS algorithm above. ``` -------------------------------- ### Display Second Molecular Cluster from Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Clustering.ipynb Visualizes the molecules belonging to the second cluster generated by Datamol's `dm.cluster_mols` function, arranging them in a grid. ```python # Cluster #2 dm.to_image(mol_clusters[1], mol_size=(150, 100), n_cols=6, max_mols=18) ``` -------------------------------- ### Placeholder for Ro5 Compliance Statistics Analysis Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Descriptors.ipynb This Python snippet serves as a placeholder for the final part of the tutorial, which involves revealing statistics on how many compounds fulfill versus violate Lipinski's Rule of Five. The actual implementation for this analysis is not provided. ```python # Part 4: Reveal the statistics for the dataset of compounds using Ro5 as a filter. How many fulfill vs. violate Ro5? ``` -------------------------------- ### Access Properties of a Datamol Conformer Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Conformers.ipynb Demonstrates how to access properties associated with a specific conformer, such as computed energy, if minimization was enabled during generation. Properties are returned as a dictionary. ```python conf = mol.GetConformer(0) props = conf.GetPropsAsDict() print(props) ``` -------------------------------- ### Import Libraries for ChEMBL Data Retrieval Source: https://github.com/datamol-io/datamol/blob/main/notebooks/Get_ChEMBL_Approved_Drugs.ipynb Imports necessary Python libraries: pandas for data manipulation, datamol for efficient parallel processing, and chembl_webresource_client for interacting with the ChEMBL API. ```python import pandas as pd import datamol as dm from chembl_webresource_client.new_client import new_client as client ``` -------------------------------- ### Display a Template Molecule for Alignment Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Aligning.ipynb This snippet displays the eighth molecule (`mols[7]`) from the loaded list. This molecule will serve as the 'template' to which another molecule will be aligned. ```python mols[7] ``` -------------------------------- ### Create RDKit molecule from SMILES string Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Conformers.ipynb Initializes an RDKit molecule object from a given SMILES string representing Aspirin. This is the first step to load a molecule for further processing and 3D structure generation. ```Python m = Chem.MolFromSmiles("O=C(C)Oc1ccccc1C(=O)O") ``` -------------------------------- ### Datamol Clustering API Reference Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Clustering.ipynb Reference to the detailed API documentation for Datamol's molecular clustering functions, including methods, arguments, and return types. The full definition is available externally on GitHub. ```APIDOC External API documentation for `datamol.cluster` module: https://github.com/datamol-io/datamol/blob/main/datamol/cluster.py#L173 ``` -------------------------------- ### Retrieve All Conformers as a List Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Conformers.ipynb Retrieves all generated conformers from a Datamol molecule object as a list of RDKit conformer objects. This allows for individual access and manipulation of each conformer. ```python conformers = mol.GetConformers() ``` -------------------------------- ### Generate multiple 3D conformers Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Conformers.ipynb Generates 50 3D conformers for the molecule using the previously configured parameters. This function performs the core conformational search, producing a set of diverse 3D structures that can then be analyzed or optimized. ```Python confs = rdDistGeom.EmbedMultipleConfs(m2, numConfs=50, params=params) ``` -------------------------------- ### Validate Chemical Reaction (Python) Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Reactions.ipynb This snippet shows how to validate a loaded chemical reaction using `datamol.reactions.is_reaction_ok`. The `enable_logs` parameter provides detailed output during validation, helping to identify any issues with the reaction definition. ```python dm.reactions.is_reaction_ok(rxn, enable_logs=True) ``` -------------------------------- ### Preprocess Molecular Data Sequentially with Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Preprocessing.ipynb This Python function `_preprocess` takes a row of data, converts a SMILES string to a molecular object, fixes, sanitizes, and standardizes it using `datamol` functions. It then generates standardized SMILES, SELFIES, InChI, and InChIKey, adding them as new columns to the row. The snippet applies this function row-wise to a DataFrame using `df.apply()`. ```python smiles_column = "smiles" def _preprocess(row): mol = dm.to_mol(row[smiles_column], ordered=True) mol = dm.fix_mol(mol) mol = dm.sanitize_mol(mol, sanifix=True, charge_neutral=False) mol = dm.standardize_mol( mol, disconnect_metals=False, normalize=True, reionize=True, uncharge=False, stereo=True, ) row["standard_smiles"] = dm.standardize_smiles(dm.to_smiles(mol)) row["selfies"] = dm.to_selfies(mol) row["inchi"] = dm.to_inchi(mol) row["inchikey"] = dm.to_inchikey(mol) return row data_clean = data.apply(_preprocess, axis=1) data_clean ``` -------------------------------- ### Perform Fuzzy Scaffolding with Datamol Source: https://github.com/datamol-io/datamol/blob/main/docs/tutorials/Fuzzy_Scaffolds.ipynb This code block applies the fuzzy scaffolding algorithm from Datamol to a list of molecule objects. It uses `dm.scaffold.fuzzy_scaffolding()` to generate scaffolds, and then converts the resulting scaffold SMILES strings back into molecule objects for visualization. The `dm.without_rdkit_log()` context manager is used to suppress RDKit logging during the process. ```python with dm.without_rdkit_log(): scaffolds, scf2infos, scf2groups = dm.scaffold.fuzzy_scaffolding(data["mol"].tolist()) sfs = [dm.to_mol(s) for s in list(scaffolds)] dm.to_image(sfs, mol_size=(200, 150), max_mols=12) ```