{"action":"created","comment":{"url":"https://api.github.com/repos/biocad/bcd_mcts/pulls/comments/206155632","pull_request_review_id":141553274,"id":206155632,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwNjE1NTYzMg==","diff_hunk":"@@ -0,0 +1,110 @@\n+import pandas as pd\n+import keras\n+from rdkit import Chem\n+from rdkit.Chem import AllChem\n+import numpy as np\n+from mcts.MCTS import *\n+\n+\n+class RetroNode(TreeNode):\n+    def __init__(self, parent_edge, **kwargs):\n+        super().__init__(parent_edge)\n+        self.children = []\n+        self.model = kwargs[\"model\"]                \n+        self.mols = kwargs[\"mols\"]\n+        # self.mols = [kwargs[\"mols\"]]\n+        self.home_mols = kwargs[\"home_mols\"]\n+        self.available_substanse = kwargs[\"available_substance\"]\n+        self.re_types = kwargs[\"re_types\"]\n+        self.depth = kwargs[\"depth\"]\n+#         self.home_mols = self.home_mols + list(set([m for m in self.mols if m in self.available_substanse]))\n+        self.home_mols = self.home_mols + [m for m in self.mols if m in self.available_substanse]\n+        self.mols = list(set(self.mols) - set(self.home_mols))\n+\n+    def is_finish(self):\n+        return self.get_reward() != 0 or len(self.get_available_child_nodes()) == 0\n+\n+\n+    def _get_fp(self):\n+        mols_fp = []\n+        FP_SIZE = 128\n+        for mol in self.mols:\n+            m = Chem.MolFromSmiles(mol)\n+            AllChem.AddHs(m)\n+            Chem.SanitizeMol(m)\n+            cur_fp_ = AllChem.GetMorganFingerprintAsBitVect(m, 2, nBits=FP_SIZE)\n+            cur_fp = cur_fp_.ToBitString()\n+            mols_fp.append(cur_fp)\n+        return mols_fp\n+\n+    def get_available_child_nodes(self):\n+        if self.get_reward() != 0:\n+            return []\n+\n+        results = []\n+        data_for_modeling = self._get_fp()\n+        list_of_fp = []\n+        for elem in data_for_modeling:\n+            count = -1\n+            m_dict = dict()\n+            for smth in elem:\n+                count += 1\n+                m_dict[count] = smth\n+            list_of_fp.append(m_dict)\n+        df_list_of_fp = pd.DataFrame(list_of_fp).astype(np.int8)\n+        smth_pred = self.model.predict(df_list_of_fp.values)\n+        all_predictions = []\n+        for IDX in range(len(smth_pred)):\n+            non_zero_pred = np.where(smth_pred[IDX, :] > 0.01)[0]\n+            sorted_non_zero_idx = non_zero_pred[np.argsort(smth_pred[IDX, non_zero_pred])][-5:]\n+            sorted_probas = smth_pred[IDX, sorted_non_zero_idx][-5:]\n+            all_predictions.append(list(zip(sorted_non_zero_idx, sorted_probas)))\n+\n+        all_new = []\n+        for i in range(len(all_predictions)):\n+            list_of_smiles = [ll for ii, ll in enumerate(self.mols) if ii != i]\n+            s = list(zip(all_predictions[i], [list_of_smiles] * len(all_predictions[i])))\n+            all_new.append(s)\n+\n+        for i in range(len(all_new)):\n+            cur_mol = Chem.MolFromSmiles(self.mols[i])\n+            for j, (pred, old_mols) in enumerate(all_new[i]):\n+                r_type = pred[0]\n+                # cur_smirks = smi_type_df.loc[r_type].mapped_SMILES\n+                cur_smirks = self.re_types.loc[r_type].mapped_SMILES\n+\n+                pred_rea = AllChem.ReactionFromSmarts(\">>\")\n+                pred_rea.AddReactantTemplate(Chem.MolFromSmarts(cur_smirks.split(\">>\")[1]))\n+                pred_rea.AddProductTemplate(Chem.MolFromSmarts(cur_smirks.split(\">>\")[0]))\n+                pred_rea.Initialize()\n+\n+                pred_rcts_mol = None\n+                for d in pred_rea.RunReactants([AllChem.AddHs(cur_mol)]):\n+                    try:\n+                        pred_rcts_mol = d[0]\n+                        Chem.SanitizeMol(d[0], Chem.SanitizeFlags.SANITIZE_ADJUSTHS)\n+                    except ValueError:\n+                        continue\n+\n+                if pred_rcts_mol is None:\n+                    continue\n+\n+                Chem.SanitizeMol(pred_rcts_mol, sanitizeOps=Chem.SanitizeFlags.SANITIZE_ADJUSTHS)\n+                mol_children = Chem.MolToSmiles(AllChem.RemoveHs(pred_rcts_mol))\n+                everything_for_children = old_mols + mol_children.split(\".\")\n+                new_node = RetroNode(None, home_mols=self.home_mols, depth=self.depth + 1, model=self.model,\n+                                     mols=everything_for_children, available_substance=self.available_substanse, re_types=self.re_types)\n+                results.append((new_node, 1))\n+        return results\n+\n+    def get_reward(self):\n+        if self.depth == 5:","path":"retrosynthetic_tree.py","position":101,"original_position":101,"commit_id":"f6465f0f7a005997d51afb2c8e88207f3bb5591e","original_commit_id":"f6465f0f7a005997d51afb2c8e88207f3bb5591e","user":{"login":"artemkondyukov","id":12516136,"node_id":"MDQ6VXNlcjEyNTE2MTM2","avatar_url":"https://avatars0.githubusercontent.com/u/12516136?v=4","gravatar_id":"","url":"https://api.github.com/users/artemkondyukov","html_url":"https://github.com/artemkondyukov","followers_url":"https://api.github.com/users/artemkondyukov/followers","following_url":"https://api.github.com/users/artemkondyukov/following{/other_user}","gists_url":"https://api.github.com/users/artemkondyukov/gists{/gist_id}","starred_url":"https://api.github.com/users/artemkondyukov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artemkondyukov/subscriptions","organizations_url":"https://api.github.com/users/artemkondyukov/orgs","repos_url":"https://api.github.com/users/artemkondyukov/repos","events_url":"https://api.github.com/users/artemkondyukov/events{/privacy}","received_events_url":"https://api.github.com/users/artemkondyukov/received_events","type":"User","site_admin":false},"body":"5 — магическое число, нужно сделать свойством класса","created_at":"2018-07-30T14:32:24Z","updated_at":"2018-07-30T14:38:23Z","html_url":"https://github.com/biocad/bcd_mcts/pull/2#discussion_r206155632","pull_request_url":"https://api.github.com/repos/biocad/bcd_mcts/pulls/2","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/biocad/bcd_mcts/pulls/comments/206155632"},"html":{"href":"https://github.com/biocad/bcd_mcts/pull/2#discussion_r206155632"},"pull_request":{"href":"https://api.github.com/repos/biocad/bcd_mcts/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/biocad/bcd_mcts/pulls/2","id":204818808,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA0ODE4ODA4","html_url":"https://github.com/biocad/bcd_mcts/pull/2","diff_url":"https://github.com/biocad/bcd_mcts/pull/2.diff","patch_url":"https://github.com/biocad/bcd_mcts/pull/2.patch","issue_url":"https://api.github.com/repos/biocad/bcd_mcts/issues/2","number":2,"state":"open","locked":false,"title":"Building a retrosynthesis tree using the MCTS algorith","user":{"login":"aigulkhkmv","id":40434269,"node_id":"MDQ6VXNlcjQwNDM0MjY5","avatar_url":"https://avatars3.githubusercontent.com/u/40434269?v=4","gravatar_id":"","url":"https://api.github.com/users/aigulkhkmv","html_url":"https://github.com/aigulkhkmv","followers_url":"https://api.github.com/users/aigulkhkmv/followers","following_url":"https://api.github.com/users/aigulkhkmv/following{/other_user}","gists_url":"https://api.github.com/users/aigulkhkmv/gists{/gist_id}","starred_url":"https://api.github.com/users/aigulkhkmv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aigulkhkmv/subscriptions","organizations_url":"https://api.github.com/users/aigulkhkmv/orgs","repos_url":"https://api.github.com/users/aigulkhkmv/repos","events_url":"https://api.github.com/users/aigulkhkmv/events{/privacy}","received_events_url":"https://api.github.com/users/aigulkhkmv/received_events","type":"User","site_admin":false},"body":"Building a retrosynthesis tree using the MCTS algorith. The file main_retrosynthesis.py for prediction of resynthesizes molecule, output - pdf file. ","created_at":"2018-07-30T14:15:32Z","updated_at":"2018-07-30T14:38:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a3b6c0acf3cc337c0e12f8261dbec98b6ec3a185","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/biocad/bcd_mcts/pulls/2/commits","review_comments_url":"https://api.github.com/repos/biocad/bcd_mcts/pulls/2/comments","review_comment_url":"https://api.github.com/repos/biocad/bcd_mcts/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biocad/bcd_mcts/issues/2/comments","statuses_url":"https://api.github.com/repos/biocad/bcd_mcts/statuses/f6465f0f7a005997d51afb2c8e88207f3bb5591e","head":{"label":"biocad:MCTS_for_retrosynthesis","ref":"MCTS_for_retrosynthesis","sha":"f6465f0f7a005997d51afb2c8e88207f3bb5591e","user":{"login":"biocad","id":4646719,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2NDY3MTk=","avatar_url":"https://avatars3.githubusercontent.com/u/4646719?v=4","gravatar_id":"","url":"https://api.github.com/users/biocad","html_url":"https://github.com/biocad","followers_url":"https://api.github.com/users/biocad/followers","following_url":"https://api.github.com/users/biocad/following{/other_user}","gists_url":"https://api.github.com/users/biocad/gists{/gist_id}","starred_url":"https://api.github.com/users/biocad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocad/subscriptions","organizations_url":"https://api.github.com/users/biocad/orgs","repos_url":"https://api.github.com/users/biocad/repos","events_url":"https://api.github.com/users/biocad/events{/privacy}","received_events_url":"https://api.github.com/users/biocad/received_events","type":"Organization","site_admin":false},"repo":{"id":138162576,"node_id":"MDEwOlJlcG9zaXRvcnkxMzgxNjI1NzY=","name":"bcd_mcts","full_name":"biocad/bcd_mcts","owner":{"login":"biocad","id":4646719,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2NDY3MTk=","avatar_url":"https://avatars3.githubusercontent.com/u/4646719?v=4","gravatar_id":"","url":"https://api.github.com/users/biocad","html_url":"https://github.com/biocad","followers_url":"https://api.github.com/users/biocad/followers","following_url":"https://api.github.com/users/biocad/following{/other_user}","gists_url":"https://api.github.com/users/biocad/gists{/gist_id}","starred_url":"https://api.github.com/users/biocad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocad/subscriptions","organizations_url":"https://api.github.com/users/biocad/orgs","repos_url":"https://api.github.com/users/biocad/repos","events_url":"https://api.github.com/users/biocad/events{/privacy}","received_events_url":"https://api.github.com/users/biocad/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/biocad/bcd_mcts","description":"A set of tools related to Monte-Carlo Tree Search.","fork":false,"url":"https://api.github.com/repos/biocad/bcd_mcts","forks_url":"https://api.github.com/repos/biocad/bcd_mcts/forks","keys_url":"https://api.github.com/repos/biocad/bcd_mcts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/biocad/bcd_mcts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/biocad/bcd_mcts/teams","hooks_url":"https://api.github.com/repos/biocad/bcd_mcts/hooks","issue_events_url":"https://api.github.com/repos/biocad/bcd_mcts/issues/events{/number}","events_url":"https://api.github.com/repos/biocad/bcd_mcts/events","assignees_url":"https://api.github.com/repos/biocad/bcd_mcts/assignees{/user}","branches_url":"https://api.github.com/repos/biocad/bcd_mcts/branches{/branch}","tags_url":"https://api.github.com/repos/biocad/bcd_mcts/tags","blobs_url":"https://api.github.com/repos/biocad/bcd_mcts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/biocad/bcd_mcts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/biocad/bcd_mcts/git/refs{/sha}","trees_url":"https://api.github.com/repos/biocad/bcd_mcts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/biocad/bcd_mcts/statuses/{sha}","languages_url":"https://api.github.com/repos/biocad/bcd_mcts/languages","stargazers_url":"https://api.github.com/repos/biocad/bcd_mcts/stargazers","contributors_url":"https://api.github.com/repos/biocad/bcd_mcts/contributors","subscribers_url":"https://api.github.com/repos/biocad/bcd_mcts/subscribers","subscription_url":"https://api.github.com/repos/biocad/bcd_mcts/subscription","commits_url":"https://api.github.com/repos/biocad/bcd_mcts/commits{/sha}","git_commits_url":"https://api.github.com/repos/biocad/bcd_mcts/git/commits{/sha}","comments_url":"https://api.github.com/repos/biocad/bcd_mcts/comments{/number}","issue_comment_url":"https://api.github.com/repos/biocad/bcd_mcts/issues/comments{/number}","contents_url":"https://api.github.com/repos/biocad/bcd_mcts/contents/{+path}","compare_url":"https://api.github.com/repos/biocad/bcd_mcts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/biocad/bcd_mcts/merges","archive_url":"https://api.github.com/repos/biocad/bcd_mcts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/biocad/bcd_mcts/downloads","issues_url":"https://api.github.com/repos/biocad/bcd_mcts/issues{/number}","pulls_url":"https://api.github.com/repos/biocad/bcd_mcts/pulls{/number}","milestones_url":"https://api.github.com/repos/biocad/bcd_mcts/milestones{/number}","notifications_url":"https://api.github.com/repos/biocad/bcd_mcts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/biocad/bcd_mcts/labels{/name}","releases_url":"https://api.github.com/repos/biocad/bcd_mcts/releases{/id}","deployments_url":"https://api.github.com/repos/biocad/bcd_mcts/deployments","created_at":"2018-06-21T11:39:53Z","updated_at":"2018-06-25T15:02:46Z","pushed_at":"2018-07-30T14:15:33Z","git_url":"git://github.com/biocad/bcd_mcts.git","ssh_url":"git@github.com:biocad/bcd_mcts.git","clone_url":"https://github.com/biocad/bcd_mcts.git","svn_url":"https://github.com/biocad/bcd_mcts","homepage":null,"size":7521,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"biocad:master","ref":"master","sha":"15aeaf52868f0b98c156efb608c4bec4e9b64db7","user":{"login":"biocad","id":4646719,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2NDY3MTk=","avatar_url":"https://avatars3.githubusercontent.com/u/4646719?v=4","gravatar_id":"","url":"https://api.github.com/users/biocad","html_url":"https://github.com/biocad","followers_url":"https://api.github.com/users/biocad/followers","following_url":"https://api.github.com/users/biocad/following{/other_user}","gists_url":"https://api.github.com/users/biocad/gists{/gist_id}","starred_url":"https://api.github.com/users/biocad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocad/subscriptions","organizations_url":"https://api.github.com/users/biocad/orgs","repos_url":"https://api.github.com/users/biocad/repos","events_url":"https://api.github.com/users/biocad/events{/privacy}","received_events_url":"https://api.github.com/users/biocad/received_events","type":"Organization","site_admin":false},"repo":{"id":138162576,"node_id":"MDEwOlJlcG9zaXRvcnkxMzgxNjI1NzY=","name":"bcd_mcts","full_name":"biocad/bcd_mcts","owner":{"login":"biocad","id":4646719,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2NDY3MTk=","avatar_url":"https://avatars3.githubusercontent.com/u/4646719?v=4","gravatar_id":"","url":"https://api.github.com/users/biocad","html_url":"https://github.com/biocad","followers_url":"https://api.github.com/users/biocad/followers","following_url":"https://api.github.com/users/biocad/following{/other_user}","gists_url":"https://api.github.com/users/biocad/gists{/gist_id}","starred_url":"https://api.github.com/users/biocad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocad/subscriptions","organizations_url":"https://api.github.com/users/biocad/orgs","repos_url":"https://api.github.com/users/biocad/repos","events_url":"https://api.github.com/users/biocad/events{/privacy}","received_events_url":"https://api.github.com/users/biocad/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/biocad/bcd_mcts","description":"A set of tools related to Monte-Carlo Tree Search.","fork":false,"url":"https://api.github.com/repos/biocad/bcd_mcts","forks_url":"https://api.github.com/repos/biocad/bcd_mcts/forks","keys_url":"https://api.github.com/repos/biocad/bcd_mcts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/biocad/bcd_mcts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/biocad/bcd_mcts/teams","hooks_url":"https://api.github.com/repos/biocad/bcd_mcts/hooks","issue_events_url":"https://api.github.com/repos/biocad/bcd_mcts/issues/events{/number}","events_url":"https://api.github.com/repos/biocad/bcd_mcts/events","assignees_url":"https://api.github.com/repos/biocad/bcd_mcts/assignees{/user}","branches_url":"https://api.github.com/repos/biocad/bcd_mcts/branches{/branch}","tags_url":"https://api.github.com/repos/biocad/bcd_mcts/tags","blobs_url":"https://api.github.com/repos/biocad/bcd_mcts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/biocad/bcd_mcts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/biocad/bcd_mcts/git/refs{/sha}","trees_url":"https://api.github.com/repos/biocad/bcd_mcts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/biocad/bcd_mcts/statuses/{sha}","languages_url":"https://api.github.com/repos/biocad/bcd_mcts/languages","stargazers_url":"https://api.github.com/repos/biocad/bcd_mcts/stargazers","contributors_url":"https://api.github.com/repos/biocad/bcd_mcts/contributors","subscribers_url":"https://api.github.com/repos/biocad/bcd_mcts/subscribers","subscription_url":"https://api.github.com/repos/biocad/bcd_mcts/subscription","commits_url":"https://api.github.com/repos/biocad/bcd_mcts/commits{/sha}","git_commits_url":"https://api.github.com/repos/biocad/bcd_mcts/git/commits{/sha}","comments_url":"https://api.github.com/repos/biocad/bcd_mcts/comments{/number}","issue_comment_url":"https://api.github.com/repos/biocad/bcd_mcts/issues/comments{/number}","contents_url":"https://api.github.com/repos/biocad/bcd_mcts/contents/{+path}","compare_url":"https://api.github.com/repos/biocad/bcd_mcts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/biocad/bcd_mcts/merges","archive_url":"https://api.github.com/repos/biocad/bcd_mcts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/biocad/bcd_mcts/downloads","issues_url":"https://api.github.com/repos/biocad/bcd_mcts/issues{/number}","pulls_url":"https://api.github.com/repos/biocad/bcd_mcts/pulls{/number}","milestones_url":"https://api.github.com/repos/biocad/bcd_mcts/milestones{/number}","notifications_url":"https://api.github.com/repos/biocad/bcd_mcts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/biocad/bcd_mcts/labels{/name}","releases_url":"https://api.github.com/repos/biocad/bcd_mcts/releases{/id}","deployments_url":"https://api.github.com/repos/biocad/bcd_mcts/deployments","created_at":"2018-06-21T11:39:53Z","updated_at":"2018-06-25T15:02:46Z","pushed_at":"2018-07-30T14:15:33Z","git_url":"git://github.com/biocad/bcd_mcts.git","ssh_url":"git@github.com:biocad/bcd_mcts.git","clone_url":"https://github.com/biocad/bcd_mcts.git","svn_url":"https://github.com/biocad/bcd_mcts","homepage":null,"size":7521,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biocad/bcd_mcts/pulls/2"},"html":{"href":"https://github.com/biocad/bcd_mcts/pull/2"},"issue":{"href":"https://api.github.com/repos/biocad/bcd_mcts/issues/2"},"comments":{"href":"https://api.github.com/repos/biocad/bcd_mcts/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/biocad/bcd_mcts/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/biocad/bcd_mcts/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biocad/bcd_mcts/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/biocad/bcd_mcts/statuses/f6465f0f7a005997d51afb2c8e88207f3bb5591e"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"artemkondyukov"}}