{"action":"created","comment":{"url":"https://api.github.com/repos/topocm/topocm_content/pulls/comments/51643579","id":51643579,"diff_hunk":"@@ -0,0 +1,165 @@\n+import numpy as np\n+import holoviews as hv\n+from holoviews import plotting\n+from holoviews import Options, Store\n+import pfaffian as pf\n+import kwant\n+from types import SimpleNamespace\n+\n+\n+kron_prods = ['s0s0', 's0sx', 's0sy', 's0sz',\n+              'sxs0', 'sxsx', 'sxsy', 'sxsz',\n+              'sys0', 'sysx', 'sysy', 'sysz',\n+              'szs0', 'szsx', 'szsy', 'szsz']\n+\n+__all__ = ['sigma0', 'sigmax', 'sigmay', 'sigmaz', 'spectrum',\n+           'plot_bands', 'h_k', 'plot_bands', 'find_pfaffian',\n+           'kitaev_chain', 'spinful_kitaev_chain', 'nanowire_chain'] + kron_prods\n+\n+options = Store.options(backend='matplotlib')\n+options.Contours = Options('style', linewidth=2, color='k')\n+options.Contours = Options('plot', aspect='square')\n+options.HLine = Options('style', linestyle='--', color='b', linewidth=2)\n+options.VLine = Options('style', linestyle='--', color='r', linewidth=2)\n+options.Image = Options('style', cmap='gist_heat_r')\n+options.Image = Options('plot', title_format='{label}')\n+options.Path = Options('style', linewidth=1.2, color='k')\n+options.Path = Options('plot', aspect='square', title_format='{label}')\n+options.Curve = Options('style', linewidth=2, color='k')\n+options.Curve = Options('plot', aspect='square', title_format='{label}')\n+options.Overlay = Options('plot', show_legend=False, title_format='{label}')\n+\n+sigma0 = np.array([[1., 0.], [0., 1.]])\n+sigmax = np.array([[0., 1.], [1., 0.]])\n+sigmay = np.array([[0., -1j], [1j, 0.]])\n+sigmaz = np.array([[1., 0.], [0., -1.]])\n+\n+s0s0 = np.kron(sigma0, sigma0)\n+s0sx = np.kron(sigma0, sigmax)\n+s0sy = np.kron(sigma0, sigmay)\n+s0sz = np.kron(sigma0, sigmaz)\n+sxs0 = np.kron(sigmax, sigma0)\n+sxsx = np.kron(sigmax, sigmax)\n+sxsy = np.kron(sigmax, sigmay)\n+sxsz = np.kron(sigmax, sigmaz)\n+sys0 = np.kron(sigmay, sigma0)\n+sysx = np.kron(sigmay, sigmax)\n+sysy = np.kron(sigmay, sigmay)\n+sysz = np.kron(sigmay, sigmaz)\n+szs0 = np.kron(sigmaz, sigma0)\n+szsx = np.kron(sigmaz, sigmax)\n+szsy = np.kron(sigmaz, sigmay)\n+szsz = np.kron(sigmaz, sigmaz)\n+\n+\n+def spectrum(sys, xticks, yticks, xdim, ydim, xlims=None, ylims=None, **kwargs):\n+    p = SimpleNamespace(**kwargs)\n+    \n+    for key, value in kwargs.items():\n+        try:\n+            if len(value) > 0:\n+                changing_variable = key\n+                changing_values = value\n+        except:\n+            TypeError\n+    \n+    def energy(x):\n+        p.__dict__[changing_variable] = x\n+        H = sys.hamiltonian_submatrix(args=[p])\n+        return np.linalg.eigvalsh(H)\n+    \n+    spectrum = np.array([energy(x) for x in changing_values])\n+    \n+    plot = hv.Path((changing_values, spectrum), kdims=[xdim, ydim])\n+    \n+    if xlims is None:\n+        xlims = slice(xticks[0], xticks[-1])\n+    else:\n+        xlims = slice(xlims[0], xlims[1])\n+    if ylims is None:\n+        ylims = slice(yticks[0], yticks[-1], None)\n+    else:\n+        ylims = slice(ylims[0], ylims[1])\n+    \n+    return plot[xlims, ylims](plot={'xticks':xticks, 'yticks':yticks})\n+\n+def h_k(sys, p, phase_fac=1):\n+    h, t = sys.cell_hamiltonian(args=[p]), sys.inter_cell_hopping(args=[p])\n+    return h + t * phase_fac + t.T.conj() * np.conjugate(phase_fac)\n+\n+def find_pfaffian(H):\n+    return np.sign(np.real(pf.pfaffian(1j*H)))\n+\n+def plot_bands(lead, p, momenta=np.linspace(-np.pi, np.pi)):\n+    bands = kwant.physics.Bands(lead, args=[p])\n+    evs = np.array([bands(k=k) for k in momenta])\n+    return hv.Path((momenta, evs), kdims=[r'$k$', r'$E$'])\n+\n+def kitaev_chain(L=None, periodic=False):","path":"code/functions.py","position":98,"original_position":98,"commit_id":"685f6390d1428cbbc9f8d1bee1acf0b3334cdd4a","original_commit_id":"685f6390d1428cbbc9f8d1bee1acf0b3334cdd4a","user":{"login":"akhmerov","id":2069677,"avatar_url":"https://avatars.githubusercontent.com/u/2069677?v=3","gravatar_id":"","url":"https://api.github.com/users/akhmerov","html_url":"https://github.com/akhmerov","followers_url":"https://api.github.com/users/akhmerov/followers","following_url":"https://api.github.com/users/akhmerov/following{/other_user}","gists_url":"https://api.github.com/users/akhmerov/gists{/gist_id}","starred_url":"https://api.github.com/users/akhmerov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhmerov/subscriptions","organizations_url":"https://api.github.com/users/akhmerov/orgs","repos_url":"https://api.github.com/users/akhmerov/repos","events_url":"https://api.github.com/users/akhmerov/events{/privacy}","received_events_url":"https://api.github.com/users/akhmerov/received_events","type":"User","site_admin":false},"body":"Definitely doesn't belong in `functions.py`; rather inside the notebook.","created_at":"2016-02-02T22:05:05Z","updated_at":"2016-02-02T22:05:05Z","html_url":"https://github.com/topocm/topocm_content/pull/110#discussion_r51643579","pull_request_url":"https://api.github.com/repos/topocm/topocm_content/pulls/110","_links":{"self":{"href":"https://api.github.com/repos/topocm/topocm_content/pulls/comments/51643579"},"html":{"href":"https://github.com/topocm/topocm_content/pull/110#discussion_r51643579"},"pull_request":{"href":"https://api.github.com/repos/topocm/topocm_content/pulls/110"}}},"pull_request":{"url":"https://api.github.com/repos/topocm/topocm_content/pulls/110","id":58055798,"html_url":"https://github.com/topocm/topocm_content/pull/110","diff_url":"https://github.com/topocm/topocm_content/pull/110.diff","patch_url":"https://github.com/topocm/topocm_content/pull/110.patch","issue_url":"https://api.github.com/repos/topocm/topocm_content/issues/110","number":110,"state":"open","locked":false,"title":"Holoviews","user":{"login":"akhmerov","id":2069677,"avatar_url":"https://avatars.githubusercontent.com/u/2069677?v=3","gravatar_id":"","url":"https://api.github.com/users/akhmerov","html_url":"https://github.com/akhmerov","followers_url":"https://api.github.com/users/akhmerov/followers","following_url":"https://api.github.com/users/akhmerov/following{/other_user}","gists_url":"https://api.github.com/users/akhmerov/gists{/gist_id}","starred_url":"https://api.github.com/users/akhmerov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhmerov/subscriptions","organizations_url":"https://api.github.com/users/akhmerov/orgs","repos_url":"https://api.github.com/users/akhmerov/repos","events_url":"https://api.github.com/users/akhmerov/events{/privacy}","received_events_url":"https://api.github.com/users/akhmerov/received_events","type":"User","site_admin":false},"body":"The first two weeks are now converted by @basnijholt to use holoviews for plotting, and to use a `functions.py` file with useful functions being defined.","created_at":"2016-02-02T21:50:25Z","updated_at":"2016-02-02T22:05:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5189c5f7800593c369a35a3c8bbb385697db03f2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/topocm/topocm_content/pulls/110/commits","review_comments_url":"https://api.github.com/repos/topocm/topocm_content/pulls/110/comments","review_comment_url":"https://api.github.com/repos/topocm/topocm_content/pulls/comments{/number}","comments_url":"https://api.github.com/repos/topocm/topocm_content/issues/110/comments","statuses_url":"https://api.github.com/repos/topocm/topocm_content/statuses/685f6390d1428cbbc9f8d1bee1acf0b3334cdd4a","head":{"label":"topocm:holoviews","ref":"holoviews","sha":"685f6390d1428cbbc9f8d1bee1acf0b3334cdd4a","user":{"login":"topocm","id":10764039,"avatar_url":"https://avatars.githubusercontent.com/u/10764039?v=3","gravatar_id":"","url":"https://api.github.com/users/topocm","html_url":"https://github.com/topocm","followers_url":"https://api.github.com/users/topocm/followers","following_url":"https://api.github.com/users/topocm/following{/other_user}","gists_url":"https://api.github.com/users/topocm/gists{/gist_id}","starred_url":"https://api.github.com/users/topocm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/topocm/subscriptions","organizations_url":"https://api.github.com/users/topocm/orgs","repos_url":"https://api.github.com/users/topocm/repos","events_url":"https://api.github.com/users/topocm/events{/privacy}","received_events_url":"https://api.github.com/users/topocm/received_events","type":"Organization","site_admin":false},"repo":{"id":30042154,"name":"topocm_content","full_name":"topocm/topocm_content","owner":{"login":"topocm","id":10764039,"avatar_url":"https://avatars.githubusercontent.com/u/10764039?v=3","gravatar_id":"","url":"https://api.github.com/users/topocm","html_url":"https://github.com/topocm","followers_url":"https://api.github.com/users/topocm/followers","following_url":"https://api.github.com/users/topocm/following{/other_user}","gists_url":"https://api.github.com/users/topocm/gists{/gist_id}","starred_url":"https://api.github.com/users/topocm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/topocm/subscriptions","organizations_url":"https://api.github.com/users/topocm/orgs","repos_url":"https://api.github.com/users/topocm/repos","events_url":"https://api.github.com/users/topocm/events{/privacy}","received_events_url":"https://api.github.com/users/topocm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/topocm/topocm_content","description":"Course on topology in condensed matter","fork":false,"url":"https://api.github.com/repos/topocm/topocm_content","forks_url":"https://api.github.com/repos/topocm/topocm_content/forks","keys_url":"https://api.github.com/repos/topocm/topocm_content/keys{/key_id}","collaborators_url":"https://api.github.com/repos/topocm/topocm_content/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/topocm/topocm_content/teams","hooks_url":"https://api.github.com/repos/topocm/topocm_content/hooks","issue_events_url":"https://api.github.com/repos/topocm/topocm_content/issues/events{/number}","events_url":"https://api.github.com/repos/topocm/topocm_content/events","assignees_url":"https://api.github.com/repos/topocm/topocm_content/assignees{/user}","branches_url":"https://api.github.com/repos/topocm/topocm_content/branches{/branch}","tags_url":"https://api.github.com/repos/topocm/topocm_content/tags","blobs_url":"https://api.github.com/repos/topocm/topocm_content/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/topocm/topocm_content/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/topocm/topocm_content/git/refs{/sha}","trees_url":"https://api.github.com/repos/topocm/topocm_content/git/trees{/sha}","statuses_url":"https://api.github.com/repos/topocm/topocm_content/statuses/{sha}","languages_url":"https://api.github.com/repos/topocm/topocm_content/languages","stargazers_url":"https://api.github.com/repos/topocm/topocm_content/stargazers","contributors_url":"https://api.github.com/repos/topocm/topocm_content/contributors","subscribers_url":"https://api.github.com/repos/topocm/topocm_content/subscribers","subscription_url":"https://api.github.com/repos/topocm/topocm_content/subscription","commits_url":"https://api.github.com/repos/topocm/topocm_content/commits{/sha}","git_commits_url":"https://api.github.com/repos/topocm/topocm_content/git/commits{/sha}","comments_url":"https://api.github.com/repos/topocm/topocm_content/comments{/number}","issue_comment_url":"https://api.github.com/repos/topocm/topocm_content/issues/comments{/number}","contents_url":"https://api.github.com/repos/topocm/topocm_content/contents/{+path}","compare_url":"https://api.github.com/repos/topocm/topocm_content/compare/{base}...{head}","merges_url":"https://api.github.com/repos/topocm/topocm_content/merges","archive_url":"https://api.github.com/repos/topocm/topocm_content/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/topocm/topocm_content/downloads","issues_url":"https://api.github.com/repos/topocm/topocm_content/issues{/number}","pulls_url":"https://api.github.com/repos/topocm/topocm_content/pulls{/number}","milestones_url":"https://api.github.com/repos/topocm/topocm_content/milestones{/number}","notifications_url":"https://api.github.com/repos/topocm/topocm_content/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/topocm/topocm_content/labels{/name}","releases_url":"https://api.github.com/repos/topocm/topocm_content/releases{/id}","deployments_url":"https://api.github.com/repos/topocm/topocm_content/deployments","created_at":"2015-01-29T21:27:58Z","updated_at":"2016-01-13T14:04:14Z","pushed_at":"2016-02-02T21:50:26Z","git_url":"git://github.com/topocm/topocm_content.git","ssh_url":"git@github.com:topocm/topocm_content.git","clone_url":"https://github.com/topocm/topocm_content.git","svn_url":"https://github.com/topocm/topocm_content","homepage":"http://topocondmat.org","size":192003,"stargazers_count":10,"watchers_count":10,"language":"Jupyter Notebook","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":22,"forks":12,"open_issues":22,"watchers":10,"default_branch":"master"}},"base":{"label":"topocm:master","ref":"master","sha":"b26ce664c46d966207bbc4ded8ee2417acd9498f","user":{"login":"topocm","id":10764039,"avatar_url":"https://avatars.githubusercontent.com/u/10764039?v=3","gravatar_id":"","url":"https://api.github.com/users/topocm","html_url":"https://github.com/topocm","followers_url":"https://api.github.com/users/topocm/followers","following_url":"https://api.github.com/users/topocm/following{/other_user}","gists_url":"https://api.github.com/users/topocm/gists{/gist_id}","starred_url":"https://api.github.com/users/topocm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/topocm/subscriptions","organizations_url":"https://api.github.com/users/topocm/orgs","repos_url":"https://api.github.com/users/topocm/repos","events_url":"https://api.github.com/users/topocm/events{/privacy}","received_events_url":"https://api.github.com/users/topocm/received_events","type":"Organization","site_admin":false},"repo":{"id":30042154,"name":"topocm_content","full_name":"topocm/topocm_content","owner":{"login":"topocm","id":10764039,"avatar_url":"https://avatars.githubusercontent.com/u/10764039?v=3","gravatar_id":"","url":"https://api.github.com/users/topocm","html_url":"https://github.com/topocm","followers_url":"https://api.github.com/users/topocm/followers","following_url":"https://api.github.com/users/topocm/following{/other_user}","gists_url":"https://api.github.com/users/topocm/gists{/gist_id}","starred_url":"https://api.github.com/users/topocm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/topocm/subscriptions","organizations_url":"https://api.github.com/users/topocm/orgs","repos_url":"https://api.github.com/users/topocm/repos","events_url":"https://api.github.com/users/topocm/events{/privacy}","received_events_url":"https://api.github.com/users/topocm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/topocm/topocm_content","description":"Course on topology in condensed matter","fork":false,"url":"https://api.github.com/repos/topocm/topocm_content","forks_url":"https://api.github.com/repos/topocm/topocm_content/forks","keys_url":"https://api.github.com/repos/topocm/topocm_content/keys{/key_id}","collaborators_url":"https://api.github.com/repos/topocm/topocm_content/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/topocm/topocm_content/teams","hooks_url":"https://api.github.com/repos/topocm/topocm_content/hooks","issue_events_url":"https://api.github.com/repos/topocm/topocm_content/issues/events{/number}","events_url":"https://api.github.com/repos/topocm/topocm_content/events","assignees_url":"https://api.github.com/repos/topocm/topocm_content/assignees{/user}","branches_url":"https://api.github.com/repos/topocm/topocm_content/branches{/branch}","tags_url":"https://api.github.com/repos/topocm/topocm_content/tags","blobs_url":"https://api.github.com/repos/topocm/topocm_content/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/topocm/topocm_content/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/topocm/topocm_content/git/refs{/sha}","trees_url":"https://api.github.com/repos/topocm/topocm_content/git/trees{/sha}","statuses_url":"https://api.github.com/repos/topocm/topocm_content/statuses/{sha}","languages_url":"https://api.github.com/repos/topocm/topocm_content/languages","stargazers_url":"https://api.github.com/repos/topocm/topocm_content/stargazers","contributors_url":"https://api.github.com/repos/topocm/topocm_content/contributors","subscribers_url":"https://api.github.com/repos/topocm/topocm_content/subscribers","subscription_url":"https://api.github.com/repos/topocm/topocm_content/subscription","commits_url":"https://api.github.com/repos/topocm/topocm_content/commits{/sha}","git_commits_url":"https://api.github.com/repos/topocm/topocm_content/git/commits{/sha}","comments_url":"https://api.github.com/repos/topocm/topocm_content/comments{/number}","issue_comment_url":"https://api.github.com/repos/topocm/topocm_content/issues/comments{/number}","contents_url":"https://api.github.com/repos/topocm/topocm_content/contents/{+path}","compare_url":"https://api.github.com/repos/topocm/topocm_content/compare/{base}...{head}","merges_url":"https://api.github.com/repos/topocm/topocm_content/merges","archive_url":"https://api.github.com/repos/topocm/topocm_content/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/topocm/topocm_content/downloads","issues_url":"https://api.github.com/repos/topocm/topocm_content/issues{/number}","pulls_url":"https://api.github.com/repos/topocm/topocm_content/pulls{/number}","milestones_url":"https://api.github.com/repos/topocm/topocm_content/milestones{/number}","notifications_url":"https://api.github.com/repos/topocm/topocm_content/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/topocm/topocm_content/labels{/name}","releases_url":"https://api.github.com/repos/topocm/topocm_content/releases{/id}","deployments_url":"https://api.github.com/repos/topocm/topocm_content/deployments","created_at":"2015-01-29T21:27:58Z","updated_at":"2016-01-13T14:04:14Z","pushed_at":"2016-02-02T21:50:26Z","git_url":"git://github.com/topocm/topocm_content.git","ssh_url":"git@github.com:topocm/topocm_content.git","clone_url":"https://github.com/topocm/topocm_content.git","svn_url":"https://github.com/topocm/topocm_content","homepage":"http://topocondmat.org","size":192003,"stargazers_count":10,"watchers_count":10,"language":"Jupyter Notebook","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":22,"forks":12,"open_issues":22,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/topocm/topocm_content/pulls/110"},"html":{"href":"https://github.com/topocm/topocm_content/pull/110"},"issue":{"href":"https://api.github.com/repos/topocm/topocm_content/issues/110"},"comments":{"href":"https://api.github.com/repos/topocm/topocm_content/issues/110/comments"},"review_comments":{"href":"https://api.github.com/repos/topocm/topocm_content/pulls/110/comments"},"review_comment":{"href":"https://api.github.com/repos/topocm/topocm_content/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/topocm/topocm_content/pulls/110/commits"},"statuses":{"href":"https://api.github.com/repos/topocm/topocm_content/statuses/685f6390d1428cbbc9f8d1bee1acf0b3334cdd4a"}}}}