{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Make your own custom two body model\n",
    "\n",
    "In this example, a user can follow the instructions in /feasst/plugin/example/include/model_example.h to make their own custom model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "import subprocess\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Write a two site xyz file for testing the energy with a cubic box length of 8, one particle on the origin and the second particle a distance of 1.125 away from the origin along the z-axis."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('example_two.xyz', 'w') as myfile: myfile.write(\"\"\"2\n",
    "-1 8 8 8\n",
    "0 0 0 0\n",
    "0 0 0 1.125\n",
    "\"\"\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare to run a feasst simulation with the given parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def run_fst(params):\n",
    "    with open(\"launch1.txt\", \"w\") as myfile: myfile.write(\"\"\"\n",
    "MonteCarlo\n",
    "Configuration particle_type=jagla:/feasst/plugin/example/particle/jagla.txt xyz_file=example_two.xyz\n",
    "Potential Model=ModelExample num_discretized_steps={num_discretized_steps}\n",
    "ThermoParams beta=1\n",
    "Metropolis\n",
    "Log output_file=log.csv max_precision=true clear_file=true\n",
    "Run num_trials=1\n",
    "\"\"\".format(**params))\n",
    "    syscode = subprocess.call(\"feasst < launch1.txt\", shell=True, executable='/bin/bash')\n",
    "    if syscode > 0: sys.exit(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Run the test and check the energy."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Usage: feasst < file.txt\n",
      "# For more information, use the command \"feasst-menu\"\n",
      "# Exit with ctrl-c\n",
      "FEASST version 0.25.19\n",
      "MonteCarlo\n",
      "Configuration particle_type=jagla:/feasst/plugin/example/particle/jagla.txt xyz_file=example_two.xyz\n",
      "Potential Model=ModelExample num_discretized_steps=0\n",
      "ThermoParams beta=1\n",
      "Metropolis\n",
      "Log clear_file=true max_precision=true output_file=log.csv\n",
      "Run num_trials=1\n",
      "#Warn 0 [:802] No Trials to attempt.\n"
     ]
    }
   ],
   "source": [
    "run_fst({\"num_discretized_steps\": \"0\"})\n",
    "df = pd.read_csv('log.csv')\n",
    "assert 2 == df['num_particles_jagla'][0]\n",
    "assert 0.5 == df['energy'][0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Did this tutorial work as expected? Did you find any inconsistencies or have any comments? Please [contact](../../../CONTACT.rst) us. Any feedback is appreciated!"
   ]
  }
 ],
 "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.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
