{ "cells": [ { "cell_type": "markdown", "id": "5b12f0ff-6895-42b3-8988-485fb88c99ea", "metadata": {}, "source": [ "## Generating coskf files from xyz" ] }, { "cell_type": "markdown", "id": "9f0cb3e8-1f45-4db7-b4b2-d81426e47587", "metadata": {}, "source": [ "The example will first load all the molecules in the folder ``compounds_xyz`` and then optimize the gas geometry using ADF, and perform the ADF COSMO calculation for each compound. When the calculations are finished, we will find all the .coskf files in the ``test_coskfs_xyz`` directory." ] }, { "cell_type": "code", "execution_count": 1, "id": "7c0aefea-343d-4491-bf2f-a606a558a40a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "PLAMS working folder: /path/plams/examples/COSMORSCompound/plams_workdir\n" ] } ], "source": [ "from scm.plams import from_smiles, read_molecules, init, JobRunner, config\n", "from scm.plams.recipes.adfcosmorscompound import ADFCOSMORSCompoundJob\n", "import os\n", "\n", "# this line is not required in AMS2025+\n", "init();" ] }, { "cell_type": "markdown", "id": "e9de0bc4-fc84-4a36-a6cb-74efc718ce3d", "metadata": {}, "source": [ "Enable the parallel calculation through `JobRunner`. Here, we'll assign one core to each job, and we can have up to eight jobs running all at once." ] }, { "cell_type": "code", "execution_count": 2, "id": "29336cfa-282f-4d1e-a713-aa41fbea30c9", "metadata": {}, "outputs": [], "source": [ "config.default_jobrunner = JobRunner(parallel=True, maxjobs=8) # Set the default jobrunner to be parallel\n", "config.default_jobmanager.settings.hashing = None # Disable rerun prevention\n", "config.job.runscript.nproc = 1 # Number of cores for each job\n", "config.log.stdout = 1 # Suppress plams output" ] }, { "cell_type": "code", "execution_count": 3, "id": "e006c736-7706-4d9c-9675-f7d88e768d45", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[19.03|15:14:40] JOB plamsjob STARTED\n", "[19.03|15:14:40] JOB plamsjob STARTED\n", "[19.03|15:14:40] JOB plamsjob/gas STARTED\n", "[19.03|15:14:40] JOB plamsjob/solv STARTED\n", "[19.03|15:14:40] JOB plamsjob/sigma STARTED\n" ] } ], "source": [ "molecules = read_molecules(\"./compounds_xyz\")\n", "\n", "results = []\n", "for name, mol in molecules.items():\n", " job = ADFCOSMORSCompoundJob(molecule=mol, coskf_name=name, coskf_dir=\"test_coskfs_xyz\")\n", " results.append(job.run())" ] }, { "cell_type": "code", "execution_count": 4, "id": "f722c525-2ec3-4321-aa3e-eb6d5b40b78f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[19.03|15:14:40] Waiting for job plamsjob to finish\n", "[19.03|15:14:40] JOB plamsjob.002/gas STARTED\n", "[19.03|15:14:40] JOB plamsjob.002/solv STARTED\n", "[19.03|15:14:40] Waiting for job gas to finish\n", "[19.03|15:14:40] JOB plamsjob.002/sigma STARTED\n", "[19.03|15:14:40] Waiting for job solv to finish\n", "[19.03|15:14:40] Waiting for job gas to finish\n", "[19.03|15:14:40] Waiting for job solv to finish\n", "[19.03|15:14:45] JOB plamsjob.002/gas SUCCESSFUL\n", "[19.03|15:14:49] JOB plamsjob.002/solv SUCCESSFUL\n", "[19.03|15:14:49] JOB plamsjob.002/sigma SUCCESSFUL\n", "[19.03|15:14:50] JOB plamsjob.002 SUCCESSFUL\n", "[19.03|15:14:57] JOB plamsjob/gas SUCCESSFUL\n", "[19.03|15:15:10] JOB plamsjob/solv SUCCESSFUL\n", "[19.03|15:15:10] JOB plamsjob/sigma SUCCESSFUL\n", "[19.03|15:15:15] JOB plamsjob SUCCESSFUL\n" ] } ], "source": [ "for result in results:\n", " result.wait()" ] }, { "cell_type": "code", "execution_count": 5, "id": "34628536-a15f-42b7-90c7-d06a7def1776", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "coskf files generated: CO.coskf, H2O.coskf\n" ] } ], "source": [ "print(f\"coskf files generated: {', '.join([f for f in os.listdir('./test_coskfs_xyz')])}\")" ] }, { "cell_type": "markdown", "id": "3046d49e-5044-4b0c-8575-85a67ddd218b", "metadata": {}, "source": [ "## Generating .coskf files from smiles" ] }, { "cell_type": "markdown", "id": "8d057c1b-9247-4748-950b-7c808232dabf", "metadata": {}, "source": [ "Now, we will specify the smiles and name of a set of compounds and generate the initial geometry of each compound using `from_smiles` function. With the setting, `nconfs=100` and `forcefield='uff'`, we will generate 100 conformers and find the one with the lowest energy using 'uff' forcefield. When the calculations are finished, we will find all the .coskf file in the ``test_coskfs_smiles`` directory." ] }, { "cell_type": "code", "execution_count": 6, "id": "78fafd30-2344-41b8-9a8f-dc97d291e36f", "metadata": {}, "outputs": [], "source": [ "rd_smiles = [\"O\", \"CO\"]\n", "rd_names = [\"H2O\", \"CO\"]\n", "molecules = {}\n", "for name, smiles in zip(rd_names, rd_smiles):\n", " molecules[name] = from_smiles(smiles, nconfs=100, forcefield=\"uff\")[0] # lowest energy one in 100 conformers" ] }, { "cell_type": "markdown", "id": "c9be8688-e25c-4a06-98ac-a6049d8dba28", "metadata": {}, "source": [ "Lastly, we give this information to the `ADFCOSMORSCompoundJob` class, including the name of the coskf files as well as the directory in which we'll find them after the calculations complete. Using the setting, `preoptimization='GFN1-xTB'` and `singlepoint=False`, it will utilize the DFTB for a quick pre-optimization. Subsequently, it will execute a gas phase optimization using ADF, followed by the solvation calculation." ] }, { "cell_type": "code", "execution_count": 7, "id": "151850f6-f0f1-449f-9fac-9be9f3dcde81", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[19.03|15:15:16] JOB H2O STARTED\n", "[19.03|15:15:16] JOB CO STARTED\n", "[19.03|15:15:16] JOB H2O/preoptimization STARTED\n", "[19.03|15:15:16] JOB CO/preoptimization STARTED\n" ] } ], "source": [ "results = []\n", "for name, mol in molecules.items():\n", " job = ADFCOSMORSCompoundJob(\n", " molecule=mol, # The initial structure\n", " coskf_name=name, # a name to be used for coskf file\n", " coskf_dir=\"test_coskfs_smiles\", # a directory to put the .coskf files generated\n", " preoptimization=\"GFN1-xTB\", # perform preoptimize or not\n", " singlepoint=False, # run a singlepoint in gasphase and solvation calculation without geometry optimization. Cannot be combined with `preoptimization`\n", " name=name,\n", " ) # an optional name for the calculation directory\n", " results.append(job.run())" ] }, { "cell_type": "code", "execution_count": 8, "id": "f46023e5-2365-4546-b521-340c37ee412f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[19.03|15:15:16] Waiting for job H2O to finish\n", "[19.03|15:15:16] JOB CO/gas STARTED\n", "[19.03|15:15:16] JOB H2O/gas STARTED\n", "[19.03|15:15:16] JOB H2O/solv STARTED\n", "[19.03|15:15:16] JOB CO/solv STARTED\n", "[19.03|15:15:16] JOB H2O/sigma STARTED\n", "[19.03|15:15:16] JOB CO/sigma STARTED\n", "[19.03|15:15:16] Waiting for job gas to finish\n", "[19.03|15:15:16] Waiting for job preoptimization to finish\n", "[19.03|15:15:16] Waiting for job preoptimization to finish\n", "[19.03|15:15:16] Waiting for job gas to finish\n", "[19.03|15:15:16] Waiting for job solv to finish\n", "[19.03|15:15:16] Waiting for job solv to finish\n", "[19.03|15:15:16] JOB H2O/preoptimization SUCCESSFUL\n", "[19.03|15:15:16] JOB CO/preoptimization SUCCESSFUL\n", "[19.03|15:15:23] JOB H2O/gas SUCCESSFUL\n", "[19.03|15:15:27] JOB H2O/solv SUCCESSFUL\n", "[19.03|15:15:27] JOB H2O/sigma SUCCESSFUL\n", "[19.03|15:15:31] JOB H2O SUCCESSFUL\n", "[19.03|15:15:31] Waiting for job CO to finish\n", "[19.03|15:15:45] JOB CO/gas SUCCESSFUL\n", "[19.03|15:15:55] JOB CO/solv SUCCESSFUL\n", "[19.03|15:15:56] JOB CO/sigma SUCCESSFUL\n", "[19.03|15:15:56] JOB CO SUCCESSFUL\n" ] } ], "source": [ "for result in results:\n", " result.wait()" ] }, { "cell_type": "code", "execution_count": 9, "id": "250a360c-60dc-4f38-be86-6629b5811c4b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "coskf files generated: CO.coskf, H2O.coskf\n" ] } ], "source": [ "print(f\"coskf files generated: {', '.join([f for f in os.listdir('./test_coskfs_smiles')])}\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.8.16" } }, "nbformat": 4, "nbformat_minor": 5 }