diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2021-05-26 23:59:17 +0530 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2021-05-26 23:59:17 +0530 |
commit | dfc509b95ff03d0c9027ee74d31d7b171f867bf1 (patch) | |
tree | 4a7bfc10cc0e8c1cf41a0d50d9ec30d5f97d95e5 /docs/posts/2020-07-01-Install-rdkit-colab.html | |
parent | d8b9e9c58b1ee676b4eaf605d94b38325775d12c (diff) |
generated website
Diffstat (limited to 'docs/posts/2020-07-01-Install-rdkit-colab.html')
-rw-r--r-- | docs/posts/2020-07-01-Install-rdkit-colab.html | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/docs/posts/2020-07-01-Install-rdkit-colab.html b/docs/posts/2020-07-01-Install-rdkit-colab.html new file mode 100644 index 0000000..b60d405 --- /dev/null +++ b/docs/posts/2020-07-01-Install-rdkit-colab.html @@ -0,0 +1,124 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + + <link rel="stylesheet" href="/assets/main.css" /> + <link rel="stylesheet" href="/assets/sakura.css" /> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Hey - Post</title> + +</head> +<body> + <nav style="display: block;"> +| +<a href="/">home</a> | +<a href="/about/">about/links</a> | +<a href="/posts/">posts</a> | +<a href="/publications/">publications</a> | +<a href="/repo/">iOS repo</a> | +<a href="/feed.rss">RSS Feed</a> | +</nav> + +<main> + <h1>Installing RDKit on Google Colab</h1> + +<p>RDKit is one of the most integral part of any Cheminfomatic specialist's toolkit but it is notoriously difficult to install unless you already have <code>conda</code> installed. I originally found this in a GitHub Gist but I have not been able to find that gist again :/ </p> + +<p>Just copy and paste this in a Colab cell and it will install it 👍</p> + +<div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="nn">sys</span> +<span class="kn">import</span> <span class="nn">os</span> +<span class="kn">import</span> <span class="nn">requests</span> +<span class="kn">import</span> <span class="nn">subprocess</span> +<span class="kn">import</span> <span class="nn">shutil</span> +<span class="kn">from</span> <span class="nn">logging</span> <span class="kn">import</span> <span class="n">getLogger</span><span class="p">,</span> <span class="n">StreamHandler</span><span class="p">,</span> <span class="n">INFO</span> + + +<span class="n">logger</span> <span class="o">=</span> <span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span> +<span class="n">logger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">StreamHandler</span><span class="p">())</span> +<span class="n">logger</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span> + + +<span class="k">def</span> <span class="nf">install</span><span class="p">(</span> + <span class="n">chunk_size</span><span class="o">=</span><span class="mi">4096</span><span class="p">,</span> + <span class="n">file_name</span><span class="o">=</span><span class="s2">"Miniconda3-latest-Linux-x86_64.sh"</span><span class="p">,</span> + <span class="n">url_base</span><span class="o">=</span><span class="s2">"https://repo.continuum.io/miniconda/"</span><span class="p">,</span> + <span class="n">conda_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">expanduser</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="s2">"~"</span><span class="p">,</span> <span class="s2">"miniconda"</span><span class="p">)),</span> + <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">"""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"> """</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">"lib"</span><span class="p">,</span> + <span class="s2">"python</span><span class="si">{0}</span><span class="s2">.</span><span class="si">{1}</span><span class="s2">"</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">"site-packages"</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">"add </span><span class="si">{}</span><span class="s2"> to PYTHONPATH"</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">"rdkit"</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">"rdkit is already installed"</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">"force re-install"</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">"</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">"</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">"python version: </span><span class="si">{}</span><span class="s2">"</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">"remove current miniconda"</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">"remove </span><span class="si">{}</span><span class="s2">"</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">'fetching installer from </span><span class="si">{}</span><span class="s1">'</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">'wb'</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">'done'</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">'installing miniconda to </span><span class="si">{}</span><span class="s1">'</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">"bash"</span><span class="p">,</span> <span class="n">file_name</span><span class="p">,</span> <span class="s2">"-b"</span><span class="p">,</span> <span class="s2">"-p"</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">'done'</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">"installing rdkit"</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">"bin"</span><span class="p">,</span> <span class="s2">"conda"</span><span class="p">),</span> + <span class="s2">"install"</span><span class="p">,</span> + <span class="s2">"--yes"</span><span class="p">,</span> + <span class="s2">"-c"</span><span class="p">,</span> <span class="s2">"rdkit"</span><span class="p">,</span> + <span class="s2">"python==</span><span class="si">{}</span><span class="s2">"</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">"rdkit"</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">"rdkit==</span><span class="si">{}</span><span class="s2">"</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">"done"</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">"rdkit-</span><span class="si">{}</span><span class="s2"> installation finished!"</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">"__main__"</span><span class="p">:</span> + <span class="n">install</span><span class="p">()</span> +</code></pre></div> + +</main> + + +<script src="assets/manup.min.js"></script> +<script src="/pwabuilder-sw-register.js"></script> +</body> +</html>
\ No newline at end of file |