-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
480 lines (358 loc) · 12.4 KB
/
index.html
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<!--
slidedeck: A modification of the Google IO 2012 HTML5 slide template
URL: https://github.com/rmcgibbo/slidedeck
Based on https://github.com/francescolaffi/elastic-google-io-slides, and
ultimately:
Google IO 2012 HTML5 Slide Template
Authors: Eric Bidelman <ebidel@gmail.com>
Luke Mahe <lukem@google.com>
URL: https://code.google.com/p/io-2012-slides
-->
<!DOCTYPE html>
<html>
<head>
<title> Conformational Dynamics in MSMBuilder3</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<!--<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">-->
<!--<meta name="viewport" content="width=device-width, initial-scale=1.0">-->
<!--This one seems to work all the time, but really small on ipad-->
<!--<meta name="viewport" content="initial-scale=0.4">-->
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="stylesheet" media="all" href="theme/css/default.css">
<link rel="stylesheet" media="all" href="theme/css/custom.css">
<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="theme/css/phone.css">
<base target="_blank"> <!-- This amazingness opens all links in a new tab. -->
<script data-main="js/slides", src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js"></script>
<!-- MathJax support -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX", "output/HTML-CSS"],
showProcessingMessages: false,
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true
},
TeX: {
extensions: ["color.js"]
},
"HTML-CSS": { availableFonts: ["TeX"] }
});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<div style="display:hidden">
\[
\definecolor{data}{RGB}{18,110,213}
\definecolor{unknown}{RGB}{217,86,16}
\definecolor{learned}{RGB}{175,114,176}
\]
</div>
</head>
<body style="opacity: 0">
<slides class="layout-widescreen">
<slide class="title-slide segue nobackground">
<hgroup class="auto-fadein">
<h1> Conformational Dynamics in MSMBuilder3</h1>
<h2></h2>
<p> Kyle A. Beauchamp<br/> Updated Feb. 27, 2015 (msmbuilder v3.1)</p>
</hgroup>
</slide>
<slide >
<hgroup>
<h2>Old-School Analysis of MD Data</h2>
<h3></h3>
</hgroup>
<article ><ul>
<li>Analysis happens in walled gardens (Gromacs, Amber, VMD)</li>
<li>Exclusively command line interfaces, C and Fortran code</li>
<li>Duplication of statistical algorithms by non-experts (e.g. chemists)</li>
<li>Possible code maintainability issues?</li>
</ul></article>
</slide>
<slide >
<hgroup>
<h2>Jarvis Patrick Clustering in Gromacs</h2>
<h3><a href="https://github.com/gromacs/gromacs/blob/master/src/gromacs/gmxana/gmx_cluster.c">real code in gromacs</a></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="c">
static void jarvis_patrick(int n1, real **mat, int M, int P,
real rmsdcut, t_clusters *clust) {
t_dist *row;
t_clustid *c;
int **nnb;
int i, j, k, cid, diff, max;
gmx_bool bChange;
real **mcpy = NULL;
if (rmsdcut < 0) {
rmsdcut = 10000;
}
/* First we sort the entries in the RMSD matrix row by row.
* This gives us the nearest neighbor list.
*/
</pre></article>
</slide>
<slide >
<hgroup>
<h2>Jarvis Patrick Clustering in Gromacs (Cont.)</h2>
<h3></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="c">
// Five more pages of this
// You get the idea
// Also, how do we even use this function?
static void jarvis_patrick(int n1, real **mat, int M, int P,
real rmsdcut, t_clusters *clust);
</pre></article>
</slide>
<slide >
<hgroup>
<h2>Enter Data Science</h2>
<h3></h3>
</hgroup>
<article ><ul>
<li>Machine learning is mainstream now!</li>
<li>Thousands of experts are using machine learning approaches</li>
<li>Well-tested, performant, and facile implementations are available</li>
<li>Writing your own is not the way to go!<ul>
<li>E.g: is clustering <em>that</em> special and MD-specific such that
we need our own custom algorithms and implementations? No. </li>
</ul>
</li>
</ul></article>
</slide>
<slide >
<hgroup>
<h2>MSMBuilder3: Design</h2>
<h3></h3>
</hgroup>
<article ><div style="float:right; margin-top:-100px">
<img src="figures/flow-chart.png" height="600">
</div>
<p>Builds on <a href="http://scikit-learn.org/stable/">scikit-learn</a> idioms:</p>
<ul>
<li>Everything is a <code>Model</code>.</li>
<li>Models are <code>fit()</code> on data.</li>
<li>Models learn <code>attributes_</code>.</li>
<li><code>Pipeline()</code> concatenate models.</li>
<li>Use best-practices (cross-validation)</li>
</ul>
<footer class="source">
http://rmcgibbo.org/posts/whats-new-in-msmbuilder3/
</footer></article>
</slide>
<slide >
<hgroup>
<h2>Everything is a <code>Model()</code>!</h2>
<h3></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="python">
>>> import msmbuilder.cluster
>>> clusterer = msmbuilder.cluster.KMeans(n_clusters=4)
>>> import msmbuilder.decomposition
>>> tica = msmbuilder.decomposition.tICA(n_components=3)
>>> import msmbuilder.msm
>>> msm = msmbuilder.msm.MarkovStateModel()
</pre>
<p>Hyperparameters go in the constructor.</p>
<footer class="source">
Actually, everything is a <code>sklearn.base.BaseEstimator()</code>
</footer></article>
</slide>
<slide >
<hgroup>
<h2>Models <code>fit()</code> data!</h2>
<h3></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="python">
>>> import msmbuilder.cluster
>>> trajectories = [np.random.normal(size=(100, 3))]
>>> clusterer = msmbuilder.cluster.KMeans(n_clusters=4, n_init=10)
>>> clusterer.fit(trajectories)
>>> clusterer.cluster_centers_
array([[-0.22340896, 1.0745301 , -0.40222902],
[-0.25410827, -0.11611431, 0.95394687],
[ 1.34302485, 0.14004818, 0.01130485],
[-0.59773874, -0.82508303, -0.95703567]])
</pre>
<p>Estimated parameters <em>always</em> have trailing underscores!</p></article>
</slide>
<slide >
<hgroup>
<h2><code>fit()</code> acts on lists of sequences</h2>
<h3></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="python">
>>> import msmbuilder.msm
>>> trajectories = [np.array([0, 0, 0, 1, 1, 1, 0, 0])]
>>> msm = msmbuilder.msm.MarkovStateModel()
>>> msm.fit(trajectories)
>>> msm.transmat_
array([[ 0.75 , 0.25 ],
[ 0.33333333, 0.66666667]])
</pre>
<p>This is different from sklearn, which uses 2D arrays.</p></article>
</slide>
<slide >
<hgroup>
<h2>Models <code>transform()</code> data!</h2>
<h3></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="python">
>>> import msmbuilder.cluster
>>> trajectories = [np.random.normal(size=(100, 3))]
>>> clusterer = msmbuilder.cluster.KMeans(n_clusters=4, n_init=10)
>>> clusterer.fit(trajectories)
>>> Y = clusterer.transform(trajectories)
[array([5, 6, 6, 0, 5, 5, 1, 6, 1, 7, 5, 7, 4, 2, 2, 2, 5, 3, 0, 0, 1, 3, 0,
5, 5, 0, 4, 0, 0, 3, 4, 7, 3, 5, 5, 5, 6, 1, 1, 0, 0, 7, 4, 4, 2, 6,
1, 4, 2, 0, 2, 4, 4, 5, 2, 6, 3, 2, 0, 6, 3, 0, 7, 7, 7, 0, 0, 0, 3,
3, 2, 7, 6, 7, 2, 5, 1, 0, 3, 6, 3, 2, 0, 5, 0, 3, 4, 2, 5, 4, 1, 5,
5, 4, 3, 3, 7, 2, 1, 4], dtype=int32)]
</pre>
<p>Moving the data-items from one "space" / representation into another.</p></article>
</slide>
<slide >
<hgroup>
<h2><code>Pipeline()</code> concatenates models!</h2>
<h3></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="python">
>>> import msmbuilder.cluster, msmbuilder.msm
>>> from sklearn.pipeline import Pipeline
>>> trajectories = [np.random.normal(size=(100, 3))]
>>> clusterer = msmbuilder.cluster.KMeans(n_clusters=2, n_init=10)
>>> msm = msmbuilder.msm.MarkovStateModel()
>>> pipeline = Pipeline([("clusterer", clusterer), ("msm", msm)])
>>> pipeline.fit(trajectories)
>>> msm.transmat_
array([[ 0.53703704, 0.46296296],
[ 0.53333333, 0.46666667]])
</pre>
<p>Data "flows" through transformations in the pipeline.</p></article>
</slide>
<slide >
<hgroup>
<h2>Featurizing Trajectories</h2>
<h3></h3>
</hgroup>
<article ><p>Featurizers wrap MDTraj functions via the <code>transform()</code> function</p>
<div style="float:right;">
<img height=225 src=figures/rama.png />
</div>
<pre class="prettyprint" style="width:75%" data-lang="python">
>>> from msmbuilder.featurizer import DihedralFeaturizer
>>> from msmbuilder.example_datasets import fetch_alanine_dipeptide
>>> from matplotlib.pyplot import hexbin, plot
>>> trajectories = fetch_alanine_dipeptide()["trajectories"]
>>> featurizer = DihedralFeaturizer(
... ["phi", "psi"], sincos=False)
>>> X = featurizer.transform(trajectories)
>>> phi, psi = np.rad2deg(np.concatenate(X).T)
>>> hexbin(phi, psi)
</pre></article>
</slide>
<slide >
<hgroup>
<h2>Loading Trajectories</h2>
<h3></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="python">
>>> import glob
>>> import mdtraj as md
>>> filenames = glob.glob("./Trajectories/*.h5")
>>> trajectories = [md.load(filename) for filename in filenames]
</pre>
<p>Note: for big datasets, you can get fancy with <code>md.iterload</code>.</p></article>
</slide>
<slide >
<hgroup>
<h2>Old-school MSMs</h2>
<h3></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="python">
>>> from msmbuilder import example_datasets, cluster, msm, featurizer
>>> from sklearn.pipeline import make_pipeline
>>> dataset = example_datasets.alanine_dipeptide.fetch_alanine_dipeptide() # From Figshare!
>>> trajectories = dataset["trajectories"] # List of MDTraj Trajectory Objects
>>> clusterer = cluster.KCenters(n_clusters=10, metric="rmsd")
>>> msm_model = msm.MarkovStateModel()
>>> pipeline = make_pipeline(clusterer, msm_model)
>>> pipeline.fit(trajectories)
</pre></article>
</slide>
<slide >
<hgroup>
<h2>Old-school MSMs (contd.)</h2>
<h3></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="python">
# ...
>>> dih_featurizer = featurizer.DihedralFeaturizer(["phi", "psi"], sincos=False)
>>> X = dih_featurizer.transform(trajectories)
>>> phi, psi = np.rad2deg(np.concatenate(X).T)
>>> hexbin(phi, psi)
>>> phi, psi = np.rad2deg(dih_featurizer.transform([clusterer.cluster_centers_])[0].T)
>>> plot(phi, psi, 'w*', markersize=25)
</pre>
<p><center>
<img height=250 src="figures/rama-cluster-centers.png">
</center></p></article>
</slide>
<slide >
<hgroup>
<h2>Old-school MSMs (contd.)</h2>
<h3></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="python">
# ...
>>> clusterer.cluster_centers_.save("./cluster_centers.pdb")
</pre>
<p><center>
<img height=400 src="figures/ala_cluster_centers.png">
</center></p></article>
</slide>
<slide >
<hgroup>
<h2>Cross Validation</h2>
<h3></h3>
</hgroup>
<article ><pre class="prettyprint" data-lang="python">
from sklearn.cross_validation import KFold
cv = KFold(len(trajectories), n_folds=5)
for fold, (train_index, test_index) in enumerate(cv):
train_data = [trajectories[i] for i in train_index]
test_data = [trajectories[i] for i in test_index]
model.fit(train_data)
model.score(test_data)
</pre>
<p>Also scikit-learn's <code>GridSearchCV</code> and <code>RandomizedSearchCV</code>.</p></article>
</slide>
<slide class="thank-you-slide segue nobackground">
<!-- <aside class="gdbar right"><img src="images/google_developers_icon_128.png"></aside> -->
<article class="flexbox vleft auto-fadein">
<h2></h2>
<p></p>
</article>
<p data-config-contact class="auto-fadein"></p>
</p>
</slide>
<slide class="backdrop"></slide>
</slides>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!--[if IE]>
<script src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script>
<script>CFInstall.check({mode: 'overlay'});</script>
<![endif]-->
</body>
</html>