-
Notifications
You must be signed in to change notification settings - Fork 1
/
pymol-colouring.html
347 lines (300 loc) · 12.1 KB
/
pymol-colouring.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
<!DOCTYPE HTML>
<!--
Spectral by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>The Waudby Group | Pymol Colouring</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
</head>
<body class="is-preload">
<!-- Page Wrapper -->
<div id="page-wrapper">
<!-- Header -->
<header id="header">
<h1><a href="index.html">The Waudby Group</a></h1>
<nav id="nav">
<ul>
<li class="special">
<a href="#menu" class="menuToggle"><span>Menu</span></a>
<div id="menu">
<ul>
<li><a href="index.html"><i class="icon solid fa-home"></i> Home</a></li>
<li><a href="index.html#news"><i class="icon solid fa-newspaper"></i> News</a></li>
<li><a href="research.html"><i class="icon solid fa-flask"></i> Research</a></li>
<li><a href="teaching.html"><i class="icon solid fa-person-chalkboard"></i> Teaching</a></li>
<li><a href="publications.html"><i class="icon solid fa-book-open"></i> Publications</a></li>
<li><a href="software.html"><i class="icon solid fa-code"></i> Software</a></li>
<li><a href="facilities.html"><i class="icon solid fa-magnet"></i> Facilities</a></li>
<li><a href="team.html"><i class="icon solid fa-people-group"></i> Team</a></li>
<li><a href="contact.html"><i class="icon solid fa-envelope"></i> Contact</a></li>
<li><a href="https://osf.io/qbxch/wiki/home/"><i class="icon solid fa-user-lock"></i> Internal</a></li>
</ul>
</div>
</li>
</ul>
</nav>
</header>
<!-- Main -->
<article id="main">
<header>
<h2>Pymol gradient generator</h2>
<p>For colouring residues or atoms by numerical quantities</p>
</header>
<section class="wrapper style5">
<div class="inner">
<p>
<span class="image right"><img src="images/pymol-colouring-methyls.png" alt="Example results" style="width:300px;" /></span>
This tool generates scripts to project numerical data, such as chemical shift perturbations,
relaxation rates or order parameters, onto pdb structures according to the selected colour
scale. Users can input data either on a per-residue level (often suited to measurements of amide
groups) or according to named atoms. Named atoms will be highlighted with a spheres representation.
</p>
<p>
<b>Usage:</b> Open your pdb structure in pymol. Paste numerical data into the form below,
set minimum/maximum values and select the colour scale. Select 'Generate script and copy'
to copy the script to the clipboard, and paste this output into the pymol command window.
</p>
<h3>Colour schemes</h3>
<p>
Two-tone colour gradients are generated by linear interpolation in RGB space. Viridis, plasma
and magma gradients are generated with <a href="https://github.com/d3/d3-scale">D3js</a>. These
are designed to be colourblind-friendly and perceptually uniform.
</p>
<ul>
<li>
<b>Viridis:</b>
<div style="display:inline-block; width:200px; height:20px; background:linear-gradient(to left, rgb(253, 231, 37), rgb(94, 201, 98), rgb(33,145,140), rgb(59,82,139), rgb(68,1,84))"></div>
[D3js]
</li>
<li>
<b>Plasma:</b>
<div style="display:inline-block; width:200px; height:20px; background:linear-gradient(to left, rgb(240, 249, 33), rgb(248, 149, 64), rgb(204, 71, 120), rgb(126, 3, 168), rgb(13, 8, 135))"></div>
[D3js]
</li>
<li>
<b>Magma:</b>
<div style="display:inline-block; width:200px; height:20px; background:linear-gradient(to right, rgb(0,0,4), rgb(81,18,124), rgb(183,55,121), rgb(252,137,97), rgb(252,253,191))"></div>
[D3js]
</li>
<li>
<b>Yellow – Red:</b>
<div style="display:inline-block; width:200px; height:20px; background:linear-gradient(to right, rgb(255, 255, 0), rgb(255, 0, 0))"></div>
[1, 1, 0] – [1, 0, 0]
</li>
<li>
<b>Grey – Purple:</b>
<div style="display:inline-block; width:200px; height:20px; background:linear-gradient(to right, rgb(204, 204, 204), rgb(179, 0, 230))"></div>
[0.8, 0.8, 0.8] – [0.7, 0, 0.9]
</li>
<li>
<b>Oranges:</b>
<div style="display:inline-block; width:200px; height:20px; background:linear-gradient(to right, rgb(255, 240, 225), rgb(255, 103, 0))"></div>
[1, 0.94, 0.88] – [1, 0.39, 0]
</li>
</ul>
<h3>Script generator</h3>
<div class="row gtr-uniform">
<div class="col-6 col-12-small">
<input type="radio" id="residueInput" name="namingInput" value="residue" checked>
<label for="residueInput">Colour by residue</label>
</div>
<div class="col-6 col-12-small">
<input type="radio" id="atomInput" name="namingInput" value="atom">
<label for="atomInput">Colour by named atoms</label>
</div>
<div class="col-12 col-12-xsmall">
<label for="colorSelect">Select color scheme:</label>
<select id="colorSelect">
<option value="viridis">Viridis</option>
<option value="plasma">Plasma</option>
<option value="magma">Magma</option>
<option value="yellowred">Yellow - Red</option>
<option value="greypurple">Grey - Purple</option>
<option value="oranges">Oranges</option>
</select>
</div>
<div class="col-6 col-12-xsmall">
<label for="minInput">Minimum value:</label>
<input type="text" id="minInput" value="0" placeholder="Minimum value">
</div>
<div class="col-6 col-12-xsmall">
<label for="maxInput">Maximum value:</label>
<input type="text" id="maxInput" value="1" placeholder="Maximum value">
</div>
<div class="col-6 col-12-xsmall">
<input type="checkbox" id="reverseCheck">
<label for="reverseCheck">Reverse colors</label>
</div>
<div class="col-12">
<label for="dataInput">Enter data for colouring:</label>
<textarea id="dataInput" placeholder="" rows="6"></textarea>
</div>
<div class="col-12">
<ul class="actions">
<li><input type="button" value="Generate script and copy" class="primary" onclick="copyToClipboard()"/></li>
<li><input type="button" value="Generate script only" onclick="generateScript()"/></li>
</ul>
</div>
</div>
<p></p>
<h3>Output</h3>
<pre><code id="output">Generated script will appear here…</code>
</pre>
<script>
var dataInput = document.getElementById("dataInput");
dataInput.placeholder = 'residue_number value\ne.g.\n31 0.5\n32 1.0\n33 0.9';
// Update placeholder on radio change
document.querySelectorAll('input[name="namingInput"]').forEach(function(radio) {
radio.addEventListener('change', function() {
if(this.value === 'residue') {
dataInput.placeholder = 'residue_number value\ne.g.\n31 0.5\n32 1.0\n33 0.9';
} else if(this.value === 'atom') {
dataInput.placeholder = 'residue_numer atom_name value\ne.g.\n672 CD1 0.5\n745 CG1 1.0\n745 CG2 0.9';
}
});
});
// The main generating script
function generateScript() {
var colorbyresidue = document.getElementsByName("namingInput")[0].checked;
var colorscheme = document.getElementById("colorSelect").value;
var reverse = document.getElementById("reverseCheck").checked;
var min = document.getElementById("minInput").value;
var max = document.getElementById("maxInput").value;
var data = document.getElementById("dataInput").value;
var output = ''
if(colorbyresidue) {
output = colorByResidue(data, min, max, colorscheme, reverse)
} else {
output = colorByAtom(data, min, max, colorscheme, reverse)
}
document.getElementById("output").textContent = output;
}
function colorByResidue(data, min, max, colorscheme, reverse) {
var lines = data.split(/\r?\n/);
var output = 'hide\nshow cartoon\ncolor grey80\n';
for(var i = 0; i < lines.length; i++) {
var line = lines[i];
var columns = line.split(/\s+/);
var resi = parseInt(columns[0]);
var x = parseFloat(columns[1]);
phi = (x-min)/(max-min)
if(isNaN(phi)) {
continue;
}
if(phi<0) {
phi = 0;
} else if(phi>1) {
phi = 1;
}
rgb = getColor(phi, colorscheme, reverse)
output += `set_color res${resi}, [${rgb[0]}, ${rgb[1]}, ${rgb[2]}]\n`;
output += `color res${resi}, resi ${resi}\n`;
}
return output
}
function colorByAtom(data, min, max, colorscheme, reverse) {
var lines = data.split(/\r?\n/);
var output = 'hide\nshow cartoon\ncolor grey80\n';
for(var i = 0; i < lines.length; i++) {
var line = lines[i];
var columns = line.split(/\s+/);
var resi = parseInt(columns[0]);
var atom = columns[1]
var x = parseFloat(columns[2]);
phi = (x-min)/(max-min)
if(isNaN(phi)) {
continue;
}
if(phi<0) {
phi = 0;
} else if(phi>1) {
phi = 1;
}
rgb = getColor(phi, colorscheme, reverse)
output += `set_color atom${resi}${atom}, [${rgb[0]}, ${rgb[1]}, ${rgb[2]}]\n`;
output += `show sphere, resi ${resi} and name ${atom}\n`;
output += `color grey80, resi ${resi} and name ${atom}\n`;
output += `color atom${resi}${atom}, resi ${resi} and name ${atom}\n`;
}
return output
}
function getColor(phi, colorscheme, reverse) {
let red, green, blue
if(reverse) {
phi = 1 - phi
}
if(colorscheme === 'yellowred' | colorscheme === 'greypurple' | colorscheme === 'oranges') {
let r1, g1, b1, r2, g2, b2;
if(colorscheme === 'yellowred') {
r1 = 1; g1 = 1; b1 = 0;
r2 = 1; g2 = 0; b2 = 0;
} else if(colorscheme === 'greypurple') {
r1 = 0.8; g1 = 0.8; b1 = 0.8;
r2 = 0.7; g2 = 0; b2 = 0.9;
} else if(colorscheme === 'oranges') {
r1 = 1; g1 = 0.94; b1 = 0.88;
r2 = 1; g2 = 0.39; b2 = 0.;
}
red = (1 - phi) * r1 + phi * r2;
green = (1 - phi) * g1 + phi * g2;
blue = (1 - phi) * b1 + phi * b2;
} else {
let rgb
if(colorscheme === 'viridis') {
rgb = d3.rgb(d3.interpolateViridis(phi))
} else if(colorscheme === 'plasma') {
rgb = d3.rgb(d3.interpolatePlasma(phi))
} else if(colorscheme === 'magma') {
rgb = d3.rgb(d3.interpolateMagma(phi))
}
red = rgb.r
green = rgb.g
blue = rgb.b
}
return [red, green, blue]
}
function copyToClipboard() {
generateScript()
var text = document.getElementById("output").textContent;
navigator.clipboard.writeText(text);
}
</script>
</div>
</section>
</article>
<!-- Footer -->
<footer id="footer">
<ul class="icons">
<li><a rel="me" href="https://mstdn.science/@chriswaudby" class="icon brands fa-mastodon"><span class="label">Mastodon</span></a></li>
<li><a href="https://www.twitter.com/chris_waudby" class="icon brands fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="https://www.youtube.com/channel/UCIy84QJPphDhbNgPyIJZ5aA" class="icon brands fa-youtube"><span class="label">YouTube</span></a></li>
<li><a href="https://github.com/waudbygroup/" class="icon brands fa-github"><span class="label">Github</span></a></li>
<li><a href="contact.html" class="icon solid fa-envelope"><span class="label">Contact</span></a></li>
</ul>
<ul class="copyright">
<li>© Waudby Group 2024</li><li>Design: <a href="https://html5up.net">HTML5 UP</a></li>
</ul>
</footer>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/browser.min.js"></script>
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
<script src="https://kit.fontawesome.com/2ea35fb7c9.js" crossorigin="anonymous"></script>
<!-- D3 colour gradients -->
<script src= "https://d3js.org/d3.v4.min.js"></script>
<script src= "https://d3js.org/d3-color.v1.min.js"></script>
<script src= "https://d3js.org/d3-interpolate.v1.min.js"></script>
<script src= "https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
</body>
</html>