{ "cells": [ { "cell_type": "markdown", "id": "a8990bb1", "metadata": {}, "source": [ "# `molli map` script\n", "\n", "Used to apply a function defined in a generic python file to all items in the library with multiprocessing parallelization.\n", "This is a newer approach of embarassingly parallel loop running that requires way less code and results in workflows that are way more legible\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "a24031ec", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "usage: molli combine [-h] -t [-n 1] [-b 1] [-o ]\n", " [--overwrite]\n", " script\n", "\n", "Read a molli library and perform some basic inspections\n", "\n", "positional arguments:\n", " script This is a python file that defines a molli_main\n", " function\n", "\n", "options:\n", " -h, --help show this help message and exit\n", " -t , --target \n", " Target library that the function is going to be\n", " applied to\n", " -n 1, --nprocs 1 Number of processes to be used in parallel\n", " -b 1, --batchsize 1 Number of molecules to be processed at a time on a\n", " single core\n", " -o , --output \n", " Output library\n", " --overwrite Overwrite the target files if they exist (default is\n", " false)\n" ] } ], "source": [ "!molli map --help" ] }, { "cell_type": "markdown", "id": "883a60b8", "metadata": {}, "source": [ "The main file to provide here is in `script` (positional argument). This file can be stored anywhere on the file system and does not need to be in the molli script folder, which improves its usability.\n", "\n", "An example of this file would be the following script designed for conformer generation using `RDKit`:\n", "\n", "File: `../examples-scripts/004_rdkit_confs.py`\n", "\n", "```python\n", "import molli as ml\n", "from molli.external.openbabel import obabel_optimize\n", "from rdkit import Chem\n", "from rdkit.Chem import rdDepictor, rdDistGeom\n", "from rdkit import RDLogger\n", "\n", "IN_CTYPE = ml.MoleculeLibrary\n", "OUT_CTYPE = ml.ConformerLibrary\n", "\n", "N_CONFS = 20\n", "\n", "def main(mol: ml.Molecule) -> ml.ConformerEnsemble:\n", "\n", " rdmol = Chem.MolFromMol2Block(\n", " ml.dumps(mol, \"mol2\"),\n", " removeHs=False,\n", " )\n", "\n", " if rdmol is None:\n", " return RuntimeError(f\"Cannot create an rdkit mol from {mol}\")\n", "\n", " rdDistGeom.EmbedMolecule(rdmol)\n", " rdDistGeom.EmbedMultipleConfs(rdmol, N_CONFS, pruneRmsThresh=0.3)\n", "\n", " ens = ml.ConformerEnsemble(mol, n_conformers=rdmol.GetNumConformers())\n", "\n", " for i, conf in enumerate(rdmol.GetConformers()):\n", " ens.coords[i] = conf.GetPositions()\n", "\n", " return ens\n", "\n", "```" ] }, { "cell_type": "markdown", "id": "41b9fa9d", "metadata": {}, "source": [ "A few parts of this script are important:\n", "\n", "1. `IN_CTYPE` and `OUT_CTYPE` are intended to indicate which type of library is appropriate to use with the input and output files, respectfully.\n", "2. `main` function should take one argument corresponding to the type compatible with `IN_CTYPE` and return one object compatible with `OUT_TYPE`\n", "3. The rest of the dependencies need to exist in the same pip/conda environment as the current molli version" ] }, { "cell_type": "code", "execution_count": 5, "id": "5bb679d9", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", " 0%| | 0/88 [00:00\n

3Dmol.js failed to load for some reason. Please check your browser console for error messages.

\n \n", "text/html": [ "
\n", "

3Dmol.js failed to load for some reason. Please check your browser console for error messages.

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/3dmoljs_load.v0": "", "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/3dmoljs_load.v0": "", "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%clib_view ../misc/output.clib 3_13_c_cf0" ] } ], "metadata": { "kernelspec": { "display_name": "molli", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.11" } }, "nbformat": 4, "nbformat_minor": 5 }