$npx -y skills add K-Dense-AI/scientific-agent-skills --skill datamolPythonic wrapper around RDKit with simplified interface and sensible defaults. Preferred for standard drug discovery including SMILES parsing, standardization, descriptors, fingerprints, clustering, 3D conformers, parallel processing. Returns native rdkit.Chem.Mol objects. For ad
| 1 | # Datamol Cheminformatics Skill |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Datamol is a Python library that provides a lightweight, Pythonic abstraction layer over RDKit for molecular cheminformatics. Simplify complex molecular operations with sensible defaults, efficient parallelization, and modern I/O capabilities. All molecular objects are native `rdkit.Chem.Mol` instances, ensuring full compatibility with the RDKit ecosystem. |
| 6 | |
| 7 | **Version note:** Examples target **datamol 0.12.x** (PyPI stable: **0.12.5**, June 2024). Since 0.10.0, modules are lazy-loaded by default (set `DATAMOL_DISABLE_LAZY_LOADING=1` to disable). Since 0.12.2, RDKit is a direct PyPI dependency of datamol. Fingerprints use RDKit's `rdFingerprintGenerator` API (0.12.5+). |
| 8 | |
| 9 | **Key capabilities**: |
| 10 | - Molecular format conversion (SMILES, SELFIES, InChI) |
| 11 | - Structure standardization and sanitization |
| 12 | - Molecular descriptors and fingerprints |
| 13 | - 3D conformer generation and analysis |
| 14 | - Clustering and diversity selection |
| 15 | - Scaffold and fragment analysis |
| 16 | - Chemical reaction application |
| 17 | - Visualization and alignment |
| 18 | - Batch processing with parallelization |
| 19 | - Cloud storage support via fsspec |
| 20 | |
| 21 | ## Installation and Setup |
| 22 | |
| 23 | Guide users to install datamol: |
| 24 | |
| 25 | ```bash |
| 26 | uv pip install datamol |
| 27 | ``` |
| 28 | |
| 29 | RDKit is installed automatically with datamol. For remote file paths (S3, GCS, HTTP), install the matching fsspec backend: |
| 30 | |
| 31 | ```bash |
| 32 | uv pip install s3fs # AWS S3 |
| 33 | uv pip install gcsfs # Google Cloud Storage |
| 34 | ``` |
| 35 | |
| 36 | **Import convention**: |
| 37 | ```python |
| 38 | import datamol as dm |
| 39 | ``` |
| 40 | |
| 41 | ## Core Workflows |
| 42 | |
| 43 | ### 1. Basic Molecule Handling |
| 44 | |
| 45 | **Creating molecules from SMILES**: |
| 46 | ```python |
| 47 | import datamol as dm |
| 48 | |
| 49 | # Single molecule |
| 50 | mol = dm.to_mol("CCO") # Ethanol |
| 51 | |
| 52 | # From list of SMILES |
| 53 | smiles_list = ["CCO", "c1ccccc1", "CC(=O)O"] |
| 54 | mols = [dm.to_mol(smi) for smi in smiles_list] |
| 55 | |
| 56 | # Error handling |
| 57 | mol = dm.to_mol("invalid_smiles") # Returns None |
| 58 | if mol is None: |
| 59 | print("Failed to parse SMILES") |
| 60 | ``` |
| 61 | |
| 62 | **Converting molecules to SMILES**: |
| 63 | ```python |
| 64 | # Canonical SMILES |
| 65 | smiles = dm.to_smiles(mol) |
| 66 | |
| 67 | # Isomeric SMILES (includes stereochemistry) |
| 68 | smiles = dm.to_smiles(mol, isomeric=True) |
| 69 | |
| 70 | # Other formats |
| 71 | inchi = dm.to_inchi(mol) |
| 72 | inchikey = dm.to_inchikey(mol) |
| 73 | selfies = dm.to_selfies(mol) |
| 74 | ``` |
| 75 | |
| 76 | **Standardization and sanitization** (always recommend for user-provided molecules): |
| 77 | ```python |
| 78 | # Sanitize molecule |
| 79 | mol = dm.sanitize_mol(mol) |
| 80 | |
| 81 | # Full standardization (recommended for datasets) |
| 82 | mol = dm.standardize_mol( |
| 83 | mol, |
| 84 | disconnect_metals=True, |
| 85 | normalize=True, |
| 86 | reionize=True |
| 87 | ) |
| 88 | |
| 89 | # For SMILES strings directly |
| 90 | clean_smiles = dm.standardize_smiles(smiles) |
| 91 | ``` |
| 92 | |
| 93 | ### 2. Reading and Writing Molecular Files |
| 94 | |
| 95 | Refer to `references/io_module.md` for comprehensive I/O documentation. |
| 96 | |
| 97 | **Reading files**: |
| 98 | ```python |
| 99 | # SDF files (most common in chemistry) |
| 100 | df = dm.read_sdf("compounds.sdf", mol_column='mol') |
| 101 | |
| 102 | # SMILES files |
| 103 | df = dm.read_smi("molecules.smi", smiles_column='smiles', mol_column='mol') |
| 104 | |
| 105 | # CSV with SMILES column |
| 106 | df = dm.read_csv("data.csv", smiles_column="SMILES", mol_column="mol") |
| 107 | |
| 108 | # Excel files |
| 109 | df = dm.read_excel("compounds.xlsx", sheet_name=0, mol_column="mol") |
| 110 | |
| 111 | # Universal reader/writer (auto-detects format; supports compression) |
| 112 | df = dm.open_df("file.sdf") # .sdf, .csv, .xlsx, .parquet, .json, .gz, etc. |
| 113 | dm.save_df(df, "output.parquet") |
| 114 | ``` |
| 115 | |
| 116 | **Writing files**: |
| 117 | ```python |
| 118 | # Save as SDF |
| 119 | dm.to_sdf(mols, "output.sdf") |
| 120 | # Or from DataFrame |
| 121 | dm.to_sdf(df, "output.sdf", mol_column="mol") |
| 122 | |
| 123 | # Save as SMILES file |
| 124 | dm.to_smi(mols, "output.smi") |
| 125 | |
| 126 | # Excel with rendered molecule images |
| 127 | dm.to_xlsx(df, "output.xlsx", mol_columns=["mol"]) |
| 128 | ``` |
| 129 | |
| 130 | **Remote file support** (S3, GCS, HTTP via fsspec): |
| 131 | |
| 132 | Only use cloud paths when the user explicitly requests them. Confirm the destination before writing. |
| 133 | |
| 134 | ```python |
| 135 | # Read from cloud storage or HTTPS (user-provided URLs only) |
| 136 | df = dm.read_sdf("s3://bucket/compounds.sdf") |
| 137 | df = dm.read_csv("https://example.com/data.csv") |
| 138 | |
| 139 | # Write to cloud storage — confirm path with user first |
| 140 | dm.to_sdf(mols, "s3://bucket/output.sdf") |
| 141 | ``` |
| 142 | |
| 143 | Cloud backends read credentials from the standard provider environment (for example `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_DEFAULT_REGION`, or `GOOGLE_APPLICATION_CREDENTIALS`). Datamol passes these to fsspec locally; it does not collect or transmit environment variables to third-party endpoints. Scope credential access |