{ "cells": [ { "cell_type": "markdown", "id": "heading", "metadata": {}, "source": [ "## i-PI path integral MD with AMS\n", "\n", "This example prepares the files needed to couple [i-PI](https://ipi-code.org/) to AMS through the ASE socket interface.\n", "\n", "i-PI can be used to run, for example, path integral molecular dynamics. The example shows how to run thermostatted ring polymer molecular dynamics for a water molecule, together with the UFF force field.\n", "\n", "For more information about i-PI, refer to the i-PI documentation and examples.\n", "\n", "Note that the provided setup uses a Unix socket and therefore runs on Linux." ] }, { "cell_type": "markdown", "id": "04e4ca67-7c38-49e9-9673-fe8676a2f878", "metadata": {}, "source": [ "### Create Input File for i-PI" ] }, { "cell_type": "markdown", "id": "5a215d57-28f0-4266-9838-060cff56d314", "metadata": {}, "source": [ "First, write the input for i-PI to an xml file." ] }, { "cell_type": "code", "execution_count": 1, "id": "a6a75f30-378a-40c4-9802-69b92713ba2a", "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "Path(\"input.xml\").write_text(\n", " \"\"\"\\\n", "\n", " \n", " [ step, time{picosecond}, conserved{electronvolt}, temperature{kelvin}, pressure_cv{megapascal} ] \n", " positions{angstrom} \n", " x_centroid{angstrom} \n", " v_centroid \n", " \n", " \n", " 40 \n", " \n", " 31415 \n", " \n", "
driver-irpmd-16
\n", "
\n", " \n", " \n", " firstframe.xyz \n", " 300 \n", " [ 12.412, 12.412, 12.412 ] \n", " \n", " \n", " \n", " \n", " 0.25 \n", " \n", " 100 \n", " 0.5 \n", " \n", " \n", " \n", " \n", " 300 \n", " \n", " \n", "
\n", " \"\"\"\n", ");" ] }, { "cell_type": "markdown", "id": "b3959215-fe9e-45b6-8b7d-f1a75a664ab4", "metadata": {}, "source": [ "Create a simple xyz file with a water molecule:" ] }, { "cell_type": "code", "execution_count": 2, "id": "1b40644a-85c3-4a02-a0d4-3195579800ea", "metadata": {}, "outputs": [], "source": [ "Path(\"firstframe.xyz\").write_text(\n", " \"\"\"\\\n", "3\n", "\n", "O -0.691870 1.324715 0.212227\n", "H -1.523797 1.656370 -0.135379\n", "H -0.797941 0.389809 0.486593\n", "VEC1 12.412 0. 0.\n", "VEC2 0. 12.412 0.\n", "VEC3 0. 0. 12.412\n", "\"\"\"\n", ");" ] }, { "cell_type": "markdown", "id": "87186350-328c-4539-8f4c-89f21071b637", "metadata": {}, "source": [ "Create script to launch i-PI server (the variable `ipi_exec` can be adjusted to your installation)." ] }, { "cell_type": "code", "execution_count": 3, "id": "64b7e733-0796-4cdc-8274-1cabfe522eac", "metadata": {}, "outputs": [], "source": [ "ipi_exec = \"i-pi\"\n", "Path(\"run-server.sh\").write_text(\n", " f\"\"\"\\\n", "#!/usr/bin/env bash\n", "# Example launcher for i-PI server \n", "{ipi_exec} input.xml\n", "\"\"\"\n", ");" ] }, { "cell_type": "markdown", "id": "af35bb75-1e22-43f6-b29d-304dd571c461", "metadata": {}, "source": [ "### Launch the i-PI Server" ] }, { "cell_type": "markdown", "id": "c5dac2a1-70e6-442b-b560-42fbde579ee1", "metadata": {}, "source": [ "Now in a separate window, run `sh run-server.sh`. Once the server is up and running we can proceed with the AMS calculation. \n", "\n", "i-PI is external to AMS and must be installed separately. The provided setup uses a Unix socket and therefore runs on Linux and Mac." ] }, { "cell_type": "code", "execution_count": 4, "id": "ec6a53eb-e98e-41de-bda3-ee061dde6219", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Start i-PI server by running in a new terminal: 'sh run-server.sh'\n" ] } ], "source": [ "print(\"Start i-PI server by running in a new terminal: 'sh run-server.sh'\")" ] }, { "cell_type": "markdown", "id": "5b8b8ef2-50be-4d90-82df-918f8da997f6", "metadata": {}, "source": [ "### Run AMS Calculator" ] }, { "cell_type": "code", "execution_count": 5, "id": "e6099562-47c0-4e4d-b288-9d05d64454a9", "metadata": {}, "outputs": [], "source": [ "from ase.calculators.socketio import SocketClient\n", "from ase.io import read\n", "from scm.plams import Settings, from_smiles\n", "from scm.plams.interfaces.adfsuite.ase_calculator import AMSCalculator" ] }, { "cell_type": "code", "execution_count": 6, "id": "3a129580-fd1b-4a7f-94c3-4800d655154b", "metadata": {}, "outputs": [], "source": [ "atoms = read(\"firstframe.xyz\")\n", "\n", "sett = Settings()\n", "sett.input.ams.Task = \"SinglePoint\"\n", "sett.input.ams.Properties.Gradients = \"True\"\n", "sett.input.ams.Properties.StressTensor = \"False\"\n", "sett.input.forcefield.type = \"UFF\"\n", "sett.runscript.nproc = 1\n", "\n", "with AMSCalculator(settings=sett, amsworker=True) as calc:\n", " atoms.calc = calc\n", " client = SocketClient(unixsocket=\"driver-irpmd-16\")\n", " client.run(atoms, use_stress=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "4a4fcc93-d51b-4949-8a3b-18f1bb7cda56", "metadata": {}, "outputs": [], "source": [] } ], "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 }