summaryrefslogtreecommitdiff
path: root/docs/posts/2020-07-01-Install-rdkit-colab.html
blob: 4ab823d36036139625d6e46d6b16d3c1a467144a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="en">
<head>
    
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">

    <title>Installing RDKit on Google Colab</title>

    <!--
    <link rel="stylesheet" href="https://unpkg.com/latex.css/style.min.css" /> 
    -->

    <link rel="stylesheet" href="/assets/c-hyde.css" />

    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">

    <link rel="stylesheet" href="/assets/main.css" />
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="og:site_name" content="Navan Chauhan" />
    <link rel="canonical" href="https://web.navan.dev/posts/2020-07-01-Install-rdkit-colab.html" />
    <meta name="twitter:url" content="https://web.navan.dev/posts/2020-07-01-Install-rdkit-colab.html" />
    <meta name="og:url" content="https://web.navan.dev/posts/2020-07-01-Install-rdkit-colab.html" />
    <meta name="twitter:title" content="Installing RDKit on Google Colab" />
    <meta name="og:title" content="Installing RDKit on Google Colab" />
    <meta name="description" content="Install RDKit on Google Colab with one code snippet." />
    <meta name="twitter:description" content="Install RDKit on Google Colab with one code snippet." />
    <meta name="og:description" content="Install RDKit on Google Colab with one code snippet." />
    <meta name="twitter:card" content="summary_large_image" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="shortcut icon" href="/images/favicon.png" type="image/png" />
    <link rel="alternate" href="/feed.rss" type="application/rss+xml" title="Subscribe to Navan Chauhan" />
    <meta name="twitter:image" content="https://web.navan.dev/images/opengraph/posts/2020-07-01-Install-rdkit-colab.png" />
    <meta name="og:image" content="https://web.navan.dev/images/opengraph/posts/2020-07-01-Install-rdkit-colab.png" />
    <meta name="google-site-verification" content="LVeSZxz-QskhbEjHxOi7-BM5dDxTg53x2TwrjFxfL0k" />
    <script data-goatcounter="https://navanchauhan.goatcounter.com/count"
        async src="//gc.zgo.at/count.js"></script>
    <script defer data-domain="web.navan.dev" src="https://plausible.io/js/plausible.js"></script>
    <link rel="manifest" href="/manifest.json" />
    
</head>
<body class="theme-base-0d">
    <div class="sidebar">
    <div class="container sidebar-sticky">
        <div class="sidebar-about">
            <h1><a href="/">Navan</a></h1>
            <p class="lead" id="random-lead">Alea iacta est.</p>
        </div>

        <ul class="sidebar-nav">
            <li><a class="sidebar-nav-item" href="/about/">about/links</a></li>
            <li><a class="sidebar-nav-item" href="/posts/">posts</a></li>
            <li><a class="sidebar-nav-item" href="/3D-Designs/">3D designs</a></li>
            <li><a class="sidebar-nav-item" href="/feed.rss">RSS Feed</a></li>
            <li><a class="sidebar-nav-item" href="/colophon/">colophon</a></li>
        </ul>
        <div class="copyright"><p>&copy; 2019-2024. Navan Chauhan <br> <a href="/feed.rss">RSS</a></p></div>
    </div>
</div>

<script>
let phrases = [
    "Something Funny", "Veni, vidi, vici", "Alea iacta est", "In vino veritas", "Acta, non verba", "Castigat ridendo mores",
    "Cui bono?", "Memento vivere", "अहम् ब्रह्मास्मि", "अनुगच्छतु प्रवाहं", "चरन्मार्गान्विजानाति", "coq de cheval", "我愛啤酒"
    ];

let new_phrase = phrases[Math.floor(Math.random()*phrases.length)];

let lead = document.getElementById("random-lead");
lead.innerText = new_phrase;
</script>
    <div class="content container">
    
	<div class="post">
	<h1 id="installing-rdkit-on-google-colab">Installing RDKit on Google Colab</h1>

<p><strong>EDIT:</strong> Try installing RDKit using pip</p>

<pre><code>!pip install rdkit-pypi

</code></pre>

<h2 id="old-method-still-works">Old Method (Still Works)</h2>

<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">&quot;Miniconda3-latest-Linux-x86_64.sh&quot;</span><span class="p">,</span>
        <span class="n">url_base</span><span class="o">=</span><span class="s2">&quot;https://repo.continuum.io/miniconda/&quot;</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">&quot;~&quot;</span><span class="p">,</span> <span class="s2">&quot;miniconda&quot;</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="s2">&quot;&quot;&quot;install rdkit from miniconda</span>
<span class="s2">   </span>
</code></pre>
</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>

	</div>
	<blockquote>If you have scrolled this far, consider subscribing to my mailing list <a href="https://listmonk.navan.dev/subscription/form">here.</a> You can subscribe to either a specific type of post you are interested in, or subscribe to everything with the "Everything" list.</blockquote>
	<script data-isso="https://comments.navan.dev/"
        src="https://comments.navan.dev/js/embed.min.js"></script>
	<section id="isso-thread">
	    <noscript>Javascript needs to be activated to view comments.</noscript>
	</section>

    </div>
    <script src="assets/manup.min.js"></script>
    <script src="/pwabuilder-sw-register.js"></script>    
</body>
</html>