{"action":"created","comment":{"url":"https://api.github.com/repos/mdtraj/mdtraj/pulls/comments/24952865","id":24952865,"diff_hunk":"@@ -0,0 +1,92 @@\n+##############################################################################\n+# MDTraj: A Python Library for Loading, Saving, and Manipulating\n+#         Molecular Dynamics Trajectories.\n+# Copyright 2012-2013 Stanford University and the Authors\n+#\n+# Authors: Christoph Klein\n+# Contributors:\n+#\n+# MDTraj is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU Lesser General Public License as\n+# published by the Free Software Foundation, either version 2.1\n+# of the License, or (at your option) any later version.\n+#\n+# This library is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU Lesser General Public License for more details.\n+#\n+# You should have received a copy of the GNU Lesser General Public\n+# License along with MDTraj. If not, see <http://www.gnu.org/licenses/>.\n+##############################################################################\n+\n+from __future__ import print_function, division\n+\n+import itertools\n+\n+import numpy as np\n+\n+from mdtraj.utils import ensure_type\n+from mdtraj.geometry.distance import compute_distances\n+\n+\n+__all__ = ['compute_rdf']\n+\n+\n+def compute_rdf(traj, pair_names=None, r_range=None, bin_width=0.005,\n+                periodic=True, opt=True):\n+    \"\"\"Compute radial distribution functions for pairs in every frame.\n+\n+    Parameters\n+    ----------\n+    traj : Trajectory\n+    pair_names : array-like, shape=(2), optional, default=None\n+        Pair of atomtypes to consider.\n+    r_range : array-like, shape=(2), optional, default=(0.0, 1.0)\n+        Minimum and maximum radii.\n+    bin_width : int, optional, default=0.005\n+        Width of the bins in nanometers.\n+    opt : bool, default=True\n+        Use an optimized native library to calculate the RDF.\n+\n+    Returns\n+    -------\n+    r : np.ndarray, shape=(n_bins), dtype=float\n+        Radii values corresponding to bins.\n+    g_r : np.ndarray, shape=(n_bins), dtype=float\n+        Radial distribution function values at r.\n+    \"\"\"\n+    if not r_range:\n+        r_range = np.array([0.0, 0.99])\n+    r_range = ensure_type(r_range, dtype=np.float64, ndim=1, name='r_range',\n+                          shape=(2,), warn_on_cast=False)\n+    bins = np.arange(r_range[0], r_range[1], bin_width)\n+    g_r, edges = np.histogram([0], bins=bins)\n+    g_r[0] = 0\n+\n+    if not pair_names:\n+        # all-all\n+        pairs = np.array(list(itertools.combinations(range(traj.n_atoms), 2)))\n+    else:\n+        type_a = traj.top.select(\"name =~ '{0}'\".format(pair_names[0]))\n+        type_b = traj.top.select(\"name =~ '{0}'\".format(pair_names[1]))\n+        # TODO: Probably a cleaner way to generate these pairs.\n+        prod = itertools.product(type_a, type_b)\n+        pairs = set()\n+        for a, b in prod:\n+            if a != b and (b, a) not in pairs:\n+                pairs.add((a, b))\n+        pairs = np.array(list(pairs))","path":"mdtraj/geometry/rdf.py","position":79,"original_position":79,"commit_id":"20bdc68d6047cfa9473ea846708351780614fe33","original_commit_id":"de8f87b0238a5f6ea3b98dae302c1d84001aff31","user":{"login":"mpharrigan","id":4967059,"avatar_url":"https://avatars.githubusercontent.com/u/4967059?v=3","gravatar_id":"","url":"https://api.github.com/users/mpharrigan","html_url":"https://github.com/mpharrigan","followers_url":"https://api.github.com/users/mpharrigan/followers","following_url":"https://api.github.com/users/mpharrigan/following{/other_user}","gists_url":"https://api.github.com/users/mpharrigan/gists{/gist_id}","starred_url":"https://api.github.com/users/mpharrigan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpharrigan/subscriptions","organizations_url":"https://api.github.com/users/mpharrigan/orgs","repos_url":"https://api.github.com/users/mpharrigan/repos","events_url":"https://api.github.com/users/mpharrigan/events{/privacy}","received_events_url":"https://api.github.com/users/mpharrigan/received_events","type":"User","site_admin":false},"body":"Could you refactor this into a generator\r\n```\r\ndef unique_pairs(type_a, type_b):\r\n    ...\r\n    for a, b in prod:\r\n        (logic)\r\n        yield a, b\r\n```","created_at":"2015-02-18T23:41:22Z","updated_at":"2015-02-18T23:41:22Z","html_url":"https://github.com/mdtraj/mdtraj/pull/724#discussion_r24952865","pull_request_url":"https://api.github.com/repos/mdtraj/mdtraj/pulls/724","_links":{"self":{"href":"https://api.github.com/repos/mdtraj/mdtraj/pulls/comments/24952865"},"html":{"href":"https://github.com/mdtraj/mdtraj/pull/724#discussion_r24952865"},"pull_request":{"href":"https://api.github.com/repos/mdtraj/mdtraj/pulls/724"}}},"pull_request":{"url":"https://api.github.com/repos/mdtraj/mdtraj/pulls/724","id":29573549,"html_url":"https://github.com/mdtraj/mdtraj/pull/724","diff_url":"https://github.com/mdtraj/mdtraj/pull/724.diff","patch_url":"https://github.com/mdtraj/mdtraj/pull/724.patch","issue_url":"https://api.github.com/repos/mdtraj/mdtraj/issues/724","number":724,"state":"open","locked":false,"title":"[WIP] compute RDF","user":{"login":"ctk3b","id":3527431,"avatar_url":"https://avatars.githubusercontent.com/u/3527431?v=3","gravatar_id":"","url":"https://api.github.com/users/ctk3b","html_url":"https://github.com/ctk3b","followers_url":"https://api.github.com/users/ctk3b/followers","following_url":"https://api.github.com/users/ctk3b/following{/other_user}","gists_url":"https://api.github.com/users/ctk3b/gists{/gist_id}","starred_url":"https://api.github.com/users/ctk3b/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctk3b/subscriptions","organizations_url":"https://api.github.com/users/ctk3b/orgs","repos_url":"https://api.github.com/users/ctk3b/repos","events_url":"https://api.github.com/users/ctk3b/events{/privacy}","received_events_url":"https://api.github.com/users/ctk3b/received_events","type":"User","site_admin":false},"body":"Seems to be working. The current bottleneck is in the histogramming and could probably use some C++ love. \r\n\r\nI added some reference files produced by gromacs' `g_rdf` and outlined the tests to compare but the binning is done slightly differently right now.","created_at":"2015-02-18T23:19:25Z","updated_at":"2015-02-18T23:41:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9dfe1aa9cb605d41b70cfff6abb9fd74fbd3ff00","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mdtraj/mdtraj/pulls/724/commits","review_comments_url":"https://api.github.com/repos/mdtraj/mdtraj/pulls/724/comments","review_comment_url":"https://api.github.com/repos/mdtraj/mdtraj/pulls/comments/{number}","comments_url":"https://api.github.com/repos/mdtraj/mdtraj/issues/724/comments","statuses_url":"https://api.github.com/repos/mdtraj/mdtraj/statuses/20bdc68d6047cfa9473ea846708351780614fe33","head":{"label":"ctk3b:master","ref":"master","sha":"20bdc68d6047cfa9473ea846708351780614fe33","user":{"login":"ctk3b","id":3527431,"avatar_url":"https://avatars.githubusercontent.com/u/3527431?v=3","gravatar_id":"","url":"https://api.github.com/users/ctk3b","html_url":"https://github.com/ctk3b","followers_url":"https://api.github.com/users/ctk3b/followers","following_url":"https://api.github.com/users/ctk3b/following{/other_user}","gists_url":"https://api.github.com/users/ctk3b/gists{/gist_id}","starred_url":"https://api.github.com/users/ctk3b/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctk3b/subscriptions","organizations_url":"https://api.github.com/users/ctk3b/orgs","repos_url":"https://api.github.com/users/ctk3b/repos","events_url":"https://api.github.com/users/ctk3b/events{/privacy}","received_events_url":"https://api.github.com/users/ctk3b/received_events","type":"User","site_admin":false},"repo":{"id":30364279,"name":"mdtraj","full_name":"ctk3b/mdtraj","owner":{"login":"ctk3b","id":3527431,"avatar_url":"https://avatars.githubusercontent.com/u/3527431?v=3","gravatar_id":"","url":"https://api.github.com/users/ctk3b","html_url":"https://github.com/ctk3b","followers_url":"https://api.github.com/users/ctk3b/followers","following_url":"https://api.github.com/users/ctk3b/following{/other_user}","gists_url":"https://api.github.com/users/ctk3b/gists{/gist_id}","starred_url":"https://api.github.com/users/ctk3b/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctk3b/subscriptions","organizations_url":"https://api.github.com/users/ctk3b/orgs","repos_url":"https://api.github.com/users/ctk3b/repos","events_url":"https://api.github.com/users/ctk3b/events{/privacy}","received_events_url":"https://api.github.com/users/ctk3b/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ctk3b/mdtraj","description":"A modern, open library for the analysis of molecular dynamics trajectories","fork":true,"url":"https://api.github.com/repos/ctk3b/mdtraj","forks_url":"https://api.github.com/repos/ctk3b/mdtraj/forks","keys_url":"https://api.github.com/repos/ctk3b/mdtraj/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ctk3b/mdtraj/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ctk3b/mdtraj/teams","hooks_url":"https://api.github.com/repos/ctk3b/mdtraj/hooks","issue_events_url":"https://api.github.com/repos/ctk3b/mdtraj/issues/events{/number}","events_url":"https://api.github.com/repos/ctk3b/mdtraj/events","assignees_url":"https://api.github.com/repos/ctk3b/mdtraj/assignees{/user}","branches_url":"https://api.github.com/repos/ctk3b/mdtraj/branches{/branch}","tags_url":"https://api.github.com/repos/ctk3b/mdtraj/tags","blobs_url":"https://api.github.com/repos/ctk3b/mdtraj/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ctk3b/mdtraj/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ctk3b/mdtraj/git/refs{/sha}","trees_url":"https://api.github.com/repos/ctk3b/mdtraj/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ctk3b/mdtraj/statuses/{sha}","languages_url":"https://api.github.com/repos/ctk3b/mdtraj/languages","stargazers_url":"https://api.github.com/repos/ctk3b/mdtraj/stargazers","contributors_url":"https://api.github.com/repos/ctk3b/mdtraj/contributors","subscribers_url":"https://api.github.com/repos/ctk3b/mdtraj/subscribers","subscription_url":"https://api.github.com/repos/ctk3b/mdtraj/subscription","commits_url":"https://api.github.com/repos/ctk3b/mdtraj/commits{/sha}","git_commits_url":"https://api.github.com/repos/ctk3b/mdtraj/git/commits{/sha}","comments_url":"https://api.github.com/repos/ctk3b/mdtraj/comments{/number}","issue_comment_url":"https://api.github.com/repos/ctk3b/mdtraj/issues/comments/{number}","contents_url":"https://api.github.com/repos/ctk3b/mdtraj/contents/{+path}","compare_url":"https://api.github.com/repos/ctk3b/mdtraj/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ctk3b/mdtraj/merges","archive_url":"https://api.github.com/repos/ctk3b/mdtraj/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ctk3b/mdtraj/downloads","issues_url":"https://api.github.com/repos/ctk3b/mdtraj/issues{/number}","pulls_url":"https://api.github.com/repos/ctk3b/mdtraj/pulls{/number}","milestones_url":"https://api.github.com/repos/ctk3b/mdtraj/milestones{/number}","notifications_url":"https://api.github.com/repos/ctk3b/mdtraj/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ctk3b/mdtraj/labels{/name}","releases_url":"https://api.github.com/repos/ctk3b/mdtraj/releases{/id}","created_at":"2015-02-05T16:03:11Z","updated_at":"2015-02-18T23:38:02Z","pushed_at":"2015-02-18T23:38:01Z","git_url":"git://github.com/ctk3b/mdtraj.git","ssh_url":"git@github.com:ctk3b/mdtraj.git","clone_url":"https://github.com/ctk3b/mdtraj.git","svn_url":"https://github.com/ctk3b/mdtraj","homepage":"www.mdtraj.org","size":29227,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mdtraj:master","ref":"master","sha":"7390b3d7352d64fd468bf542b93e6d0a9b469c07","user":{"login":"mdtraj","id":9259532,"avatar_url":"https://avatars.githubusercontent.com/u/9259532?v=3","gravatar_id":"","url":"https://api.github.com/users/mdtraj","html_url":"https://github.com/mdtraj","followers_url":"https://api.github.com/users/mdtraj/followers","following_url":"https://api.github.com/users/mdtraj/following{/other_user}","gists_url":"https://api.github.com/users/mdtraj/gists{/gist_id}","starred_url":"https://api.github.com/users/mdtraj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdtraj/subscriptions","organizations_url":"https://api.github.com/users/mdtraj/orgs","repos_url":"https://api.github.com/users/mdtraj/repos","events_url":"https://api.github.com/users/mdtraj/events{/privacy}","received_events_url":"https://api.github.com/users/mdtraj/received_events","type":"Organization","site_admin":false},"repo":{"id":6604361,"name":"mdtraj","full_name":"mdtraj/mdtraj","owner":{"login":"mdtraj","id":9259532,"avatar_url":"https://avatars.githubusercontent.com/u/9259532?v=3","gravatar_id":"","url":"https://api.github.com/users/mdtraj","html_url":"https://github.com/mdtraj","followers_url":"https://api.github.com/users/mdtraj/followers","following_url":"https://api.github.com/users/mdtraj/following{/other_user}","gists_url":"https://api.github.com/users/mdtraj/gists{/gist_id}","starred_url":"https://api.github.com/users/mdtraj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdtraj/subscriptions","organizations_url":"https://api.github.com/users/mdtraj/orgs","repos_url":"https://api.github.com/users/mdtraj/repos","events_url":"https://api.github.com/users/mdtraj/events{/privacy}","received_events_url":"https://api.github.com/users/mdtraj/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mdtraj/mdtraj","description":"A modern, open library for the analysis of molecular dynamics trajectories","fork":false,"url":"https://api.github.com/repos/mdtraj/mdtraj","forks_url":"https://api.github.com/repos/mdtraj/mdtraj/forks","keys_url":"https://api.github.com/repos/mdtraj/mdtraj/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mdtraj/mdtraj/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mdtraj/mdtraj/teams","hooks_url":"https://api.github.com/repos/mdtraj/mdtraj/hooks","issue_events_url":"https://api.github.com/repos/mdtraj/mdtraj/issues/events{/number}","events_url":"https://api.github.com/repos/mdtraj/mdtraj/events","assignees_url":"https://api.github.com/repos/mdtraj/mdtraj/assignees{/user}","branches_url":"https://api.github.com/repos/mdtraj/mdtraj/branches{/branch}","tags_url":"https://api.github.com/repos/mdtraj/mdtraj/tags","blobs_url":"https://api.github.com/repos/mdtraj/mdtraj/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mdtraj/mdtraj/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mdtraj/mdtraj/git/refs{/sha}","trees_url":"https://api.github.com/repos/mdtraj/mdtraj/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mdtraj/mdtraj/statuses/{sha}","languages_url":"https://api.github.com/repos/mdtraj/mdtraj/languages","stargazers_url":"https://api.github.com/repos/mdtraj/mdtraj/stargazers","contributors_url":"https://api.github.com/repos/mdtraj/mdtraj/contributors","subscribers_url":"https://api.github.com/repos/mdtraj/mdtraj/subscribers","subscription_url":"https://api.github.com/repos/mdtraj/mdtraj/subscription","commits_url":"https://api.github.com/repos/mdtraj/mdtraj/commits{/sha}","git_commits_url":"https://api.github.com/repos/mdtraj/mdtraj/git/commits{/sha}","comments_url":"https://api.github.com/repos/mdtraj/mdtraj/comments{/number}","issue_comment_url":"https://api.github.com/repos/mdtraj/mdtraj/issues/comments/{number}","contents_url":"https://api.github.com/repos/mdtraj/mdtraj/contents/{+path}","compare_url":"https://api.github.com/repos/mdtraj/mdtraj/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mdtraj/mdtraj/merges","archive_url":"https://api.github.com/repos/mdtraj/mdtraj/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mdtraj/mdtraj/downloads","issues_url":"https://api.github.com/repos/mdtraj/mdtraj/issues{/number}","pulls_url":"https://api.github.com/repos/mdtraj/mdtraj/pulls{/number}","milestones_url":"https://api.github.com/repos/mdtraj/mdtraj/milestones{/number}","notifications_url":"https://api.github.com/repos/mdtraj/mdtraj/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mdtraj/mdtraj/labels{/name}","releases_url":"https://api.github.com/repos/mdtraj/mdtraj/releases{/id}","created_at":"2012-11-08T22:01:24Z","updated_at":"2015-02-18T23:30:48Z","pushed_at":"2015-02-18T23:30:48Z","git_url":"git://github.com/mdtraj/mdtraj.git","ssh_url":"git@github.com:mdtraj/mdtraj.git","clone_url":"https://github.com/mdtraj/mdtraj.git","svn_url":"https://github.com/mdtraj/mdtraj","homepage":"www.mdtraj.org","size":34060,"stargazers_count":41,"watchers_count":41,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":36,"mirror_url":null,"open_issues_count":50,"forks":36,"open_issues":50,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mdtraj/mdtraj/pulls/724"},"html":{"href":"https://github.com/mdtraj/mdtraj/pull/724"},"issue":{"href":"https://api.github.com/repos/mdtraj/mdtraj/issues/724"},"comments":{"href":"https://api.github.com/repos/mdtraj/mdtraj/issues/724/comments"},"review_comments":{"href":"https://api.github.com/repos/mdtraj/mdtraj/pulls/724/comments"},"review_comment":{"href":"https://api.github.com/repos/mdtraj/mdtraj/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/mdtraj/mdtraj/pulls/724/commits"},"statuses":{"href":"https://api.github.com/repos/mdtraj/mdtraj/statuses/20bdc68d6047cfa9473ea846708351780614fe33"}}}}