{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from itertools import chain\n", "import numpy as np\n", "import math\n", "from scipy import sparse\n", "from scipy.sparse.linalg import eigsh\n", "\n", "#sample potential\n", "def V_gauss(dr_sqr):\n", " return -4*math.exp(-dr_sqr/4)\n", "\n", "n=3 # no of particles\n", "L=14\n", "N=6 # no of lattice points\n", "mu=1/2 # reduced mass\n", "\n", "DOF=(n-1)*3 # degrees of freedom after excluding CM\n", "\n", "s=np.arange(N**DOF) # matrix index\n", "\n", "# k index for each particle and each dimension\n", "k=np.empty((n-1,3),dtype=np.dtype)\n", "for dof in range(DOF):\n", " k[dof//3,dof%3]=(s%N**(DOF-dof))//N**(DOF-1-dof)-N//2\n", "\n", "x=k*(L/N) # x coordinate from k index\n", "\n", "# adding up all non-local interactions\n", "V_local=np.zeros(N**DOF)\n", "\n", "# 2-body interactions\n", "V2=np.vectorize(V_gauss)\n", "dxs=chain((x[i,:] for i in range(n-1)), (x[i,:]-x[j,:] for (i,j) in np.ndindex((n-1,n-1)) if i