summaryrefslogtreecommitdiff
path: root/docs/posts/2020-07-01-Install-rdkit-colab.html
diff options
context:
space:
mode:
authornavanchauhan <navanchauhan@gmail.com>2022-08-07 22:54:35 -0400
committernavanchauhan <navanchauhan@gmail.com>2022-08-07 22:54:35 -0400
commitd7ec888d687725d47b8789578f0bd96876b475b4 (patch)
tree99673026f5c9199dd463748f0bc802d763c1f808 /docs/posts/2020-07-01-Install-rdkit-colab.html
parentddbe4d7126afdcd2d8bdbcc4042ec25742834600 (diff)
rebuild
Diffstat (limited to 'docs/posts/2020-07-01-Install-rdkit-colab.html')
-rw-r--r--docs/posts/2020-07-01-Install-rdkit-colab.html141
1 files changed, 74 insertions, 67 deletions
diff --git a/docs/posts/2020-07-01-Install-rdkit-colab.html b/docs/posts/2020-07-01-Install-rdkit-colab.html
index bf1da97..56e2f21 100644
--- a/docs/posts/2020-07-01-Install-rdkit-colab.html
+++ b/docs/posts/2020-07-01-Install-rdkit-colab.html
@@ -76,76 +76,83 @@
<span class="n">rdkit_version</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">add_python_path</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">force</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
- <span class="sd">&quot;&quot;&quot;install rdkit from miniconda</span>
-<span class="sd"> ```</span>
-<span class="sd"> import rdkit_installer</span>
-<span class="sd"> rdkit_installer.install()</span>
-<span class="sd"> ```</span>
-<span class="sd"> &quot;&quot;&quot;</span>
-
- <span class="n">python_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
- <span class="n">conda_path</span><span class="p">,</span>
- <span class="s2">&quot;lib&quot;</span><span class="p">,</span>
- <span class="s2">&quot;python</span><span class="si">{0}</span><span class="s2">.</span><span class="si">{1}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">*</span><span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="p">),</span>
- <span class="s2">&quot;site-packages&quot;</span><span class="p">,</span>
- <span class="p">)</span>
-
- <span class="k">if</span> <span class="n">add_python_path</span> <span class="ow">and</span> <span class="n">python_path</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="p">:</span>
- <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;add </span><span class="si">{}</span><span class="s2"> to PYTHONPATH&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">python_path</span><span class="p">))</span>
- <span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">python_path</span><span class="p">)</span>
-
- <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">python_path</span><span class="p">,</span> <span class="s2">&quot;rdkit&quot;</span><span class="p">)):</span>
- <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;rdkit is already installed&quot;</span><span class="p">)</span>
- <span class="k">if</span> <span class="ow">not</span> <span class="n">force</span><span class="p">:</span>
- <span class="k">return</span>
-
- <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;force re-install&quot;</span><span class="p">)</span>
-
- <span class="n">url</span> <span class="o">=</span> <span class="n">url_base</span> <span class="o">+</span> <span class="n">file_name</span>
- <span class="n">python_version</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{0}</span><span class="s2">.</span><span class="si">{1}</span><span class="s2">.</span><span class="si">{2}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">*</span><span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="p">)</span>
-
- <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;python version: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">python_version</span><span class="p">))</span>
-
- <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">conda_path</span><span class="p">):</span>
- <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;remove current miniconda&quot;</span><span class="p">)</span>
- <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">conda_path</span><span class="p">)</span>
- <span class="k">elif</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">conda_path</span><span class="p">):</span>
- <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;remove </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">conda_path</span><span class="p">))</span>
- <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">conda_path</span><span class="p">)</span>
-
- <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;fetching installer from </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">url</span><span class="p">))</span>
- <span class="n">res</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">stream</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
- <span class="n">res</span><span class="o">.</span><span class="n">raise_for_status</span><span class="p">()</span>
- <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">file_name</span><span class="p">,</span> <span class="s1">&#39;wb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
- <span class="k">for</span> <span class="n">chunk</span> <span class="ow">in</span> <span class="n">res</span><span class="o">.</span><span class="n">iter_content</span><span class="p">(</span><span class="n">chunk_size</span><span class="p">):</span>
- <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span>
- <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;done&#39;</span><span class="p">)</span>
-
- <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;installing miniconda to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">conda_path</span><span class="p">))</span>
- <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">([</span><span class="s2">&quot;bash&quot;</span><span class="p">,</span> <span class="n">file_name</span><span class="p">,</span> <span class="s2">&quot;-b&quot;</span><span class="p">,</span> <span class="s2">&quot;-p&quot;</span><span class="p">,</span> <span class="n">conda_path</span><span class="p">])</span>
- <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;done&#39;</span><span class="p">)</span>
-
- <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;installing rdkit&quot;</span><span class="p">)</span>
- <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">([</span>
- <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">conda_path</span><span class="p">,</span> <span class="s2">&quot;bin&quot;</span><span class="p">,</span> <span class="s2">&quot;conda&quot;</span><span class="p">),</span>
- <span class="s2">&quot;install&quot;</span><span class="p">,</span>
- <span class="s2">&quot;--yes&quot;</span><span class="p">,</span>
- <span class="s2">&quot;-c&quot;</span><span class="p">,</span> <span class="s2">&quot;rdkit&quot;</span><span class="p">,</span>
- <span class="s2">&quot;python==</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">python_version</span><span class="p">),</span>
- <span class="s2">&quot;rdkit&quot;</span> <span class="k">if</span> <span class="n">rdkit_version</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="s2">&quot;rdkit==</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">rdkit_version</span><span class="p">)])</span>
- <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;done&quot;</span><span class="p">)</span>
-
- <span class="kn">import</span> <span class="nn">rdkit</span>
- <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;rdkit-</span><span class="si">{}</span><span class="s2"> installation finished!&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">rdkit</span><span class="o">.</span><span class="n">__version__</span><span class="p">))</span>
-
-
-<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
- <span class="n">install</span><span class="p">()</span>
+ <span class="s2">&quot;&quot;&quot;install rdkit from miniconda</span>
+<span class="s2"> </span>
</code></pre></div>
- <div class="commentbox"></div>
+<pre><code>import rdkit_installer
+rdkit_installer.install()
+```
+"""
+
+python_path = os.path.join(
+ conda_path,
+ "lib",
+ "python{0}.{1}".format(*sys.version_info),
+ "site-packages",
+)
+
+if add_python_path and python_path not in sys.path:
+ logger.info("add {} to PYTHONPATH".format(python_path))
+ sys.path.append(python_path)
+
+if os.path.isdir(os.path.join(python_path, "rdkit")):
+ logger.info("rdkit is already installed")
+ if not force:
+ return
+
+ logger.info("force re-install")
+
+url = url_base + file_name
+python_version = "{0}.{1}.{2}".format(*sys.version_info)
+
+logger.info("python version: {}".format(python_version))
+
+if os.path.isdir(conda_path):
+ logger.warning("remove current miniconda")
+ shutil.rmtree(conda_path)
+elif os.path.isfile(conda_path):
+ logger.warning("remove {}".format(conda_path))
+ os.remove(conda_path)
+
+logger.info('fetching installer from {}'.format(url))
+res = requests.get(url, stream=True)
+res.raise_for_status()
+with open(file_name, 'wb') as f:
+ for chunk in res.iter_content(chunk_size):
+ f.write(chunk)
+logger.info('done')
+
+logger.info('installing miniconda to {}'.format(conda_path))
+subprocess.check_call(["bash", file_name, "-b", "-p", conda_path])
+logger.info('done')
+
+logger.info("installing rdkit")
+subprocess.check_call([
+ os.path.join(conda_path, "bin", "conda"),
+ "install",
+ "--yes",
+ "-c", "rdkit",
+ "python=={}".format(python_version),
+ "rdkit" if rdkit_version is None else "rdkit=={}".format(rdkit_version)])
+logger.info("done")
+
+import rdkit
+logger.info("rdkit-{} installation finished!".format(rdkit.__version__))
+</code></pre>
+
+<p>if <strong>name</strong> == "<strong>main</strong>":
+ install()
+```</p>
+
+ <script data-isso="//comments.navan.dev/"
+ src="//comments.navan.dev/js/embed.min.js"></script>
+ <section id="isso-thread">
+ <noscript>Javascript needs to be activated to view comments.</noscript>
+ </section>
+ <!--<div class="commentbox"></div>
<script src="https://unpkg.com/commentbox.io/dist/commentBox.min.js"></script>
- <script>commentBox('5650347917836288-proj')</script>
+ <script>commentBox('5650347917836288-proj')</script>-->
</main>