-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
539 lines (460 loc) · 23 KB
/
index.html
File metadata and controls
539 lines (460 loc) · 23 KB
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>MolView</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://chemapps.stolaf.edu/jmol/jsmol/JSmol.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
font-family: Roboto, sans-serif;
}
.container {
display: flex;
height: 100vh;
width: 100vw;
}
#appdiv {
flex: 1;
background: #ffffff;
display: flex;
align-items: left;
justify-content: left;
min-width: 0;
}
.controls {
width: min(400px, 30vw);
max-width: 500px;
min-width: 300px;
padding: 20px;
background: white;
border-left: 1px solid #ddd;
overflow-y: auto;
}
.control-group {
margin-bottom: 20px;
padding: 15px;
background: #f9f9f9;
border-radius: 5px;
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
}
.load-group {
display: block;
}
.control-group h3 {
margin: 0;
color: #333;
font-size: clamp(12px, 1.5vw, 14px);
font-weight: bold;
white-space: nowrap;
}
.load-group h3 {
margin-bottom: 5px;
}
button, input[type="radio"] {
margin: 5px 0;
cursor: pointer;
}
input[type="file"], input[type="text"] {
width: 100%;
max-width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: clamp(12px, 1.5vw, 14px);
box-sizing: border-box;
}
button, input[type="button"] {
padding: 8px 12px;
background: #e1e3e1;
color: rgb(11, 3, 3);
border: none;
border-radius: 4px;
font-size: clamp(13px, 1.5vw, 15px);
margin: 3px;
}
button:hover, input[type="button"]:hover {
background: #589f5b;
}
label {
margin-left: 5px;
font-size: clamp(11px, 1.5vw, 13px);
}
/* Mobile responsiveness */
@media (max-width: 768px) {
.container {
flex-direction: column;
}
.controls {
width: 100vw;
max-width: 100vw;
min-width: unset;
border-left: none;
border-top: 1px solid #ddd;
max-height: 50vh;
}
#appdiv {
height: 50vh;
}
}
</style>
</head>
<body>
<script>
var MP_PROXY_SERVER = "https://mp-proxy-1067494591843.us-central1.run.app/"; // Change this if you host your own proxy server
var defaultZoomLevel = 70;
var myJmol = 'myJmol';
var Info = {
width: $(window).width() * 0.8,
height: $(window).height() * 1.0 - 6,
use: "HTML5",
j2sPath: "https://chemapps.stolaf.edu/jmol/jsmol/j2s",
serverURL: "https://chemapps.stolaf.edu/jmol/jsmol/php/jsmol.php",
script: `set antialiasDisplay;`,
readyFunction: function(applet) {
console.log("JSmol ready!");
}
};
function default_render() {
// Set default display parameters
return `
// Reset view and clear previous selections
reset;
// Set default zoom level
zoom ${defaultZoomLevel};
// Enable anti-aliasing for smoother rendering
set antialiasDisplay true;
spacefill off;
wireframe off;
cartoons off;
// Select all protein chains
select protein;
// Render proteins in cartoon representation
cartoon only;
color structure;
select not protein;
// Render non-protein molecules (ligands, ions, etc.) in ball-and-stick
spacefill 23%;
wireframe 0.15;
color cpk;
`;
}
$(document).ready(function() {
$("#appdiv").html(Jmol.getAppletHtml(myJmol, Info));
Jmol.script(myJmol, `load examples/theobromine.sdf; ${default_render()}; set picking ATOM; select none; set display selected; set selecthalo true;`); // Load a default structure
});
</script>
<div class="container">
<div id="appdiv">Loading...</div>
<div class="controls">
<h2 style="margin-top: 0;">Controls</h2>
<div class="control-group load-group">
<h3>Upload File</h3>
<input type="file" id="file-input" accept=".xyz,.pdb,.mol,.sdf,.cif" style="display: none;" onchange="handleFileUpload(event)">
<input type="text" id="file-name-display" placeholder=".xyz,.pdb,.mol,.sdf,.cif" readonly style="width: 50%; margin-right: 5px;">
<script type="text/javascript">
function handleFileUpload(event) {
const file = event.target.files[0];
if (!file) return;
document.getElementById('file-name-display').value = file.name;
const reader = new FileReader();
reader.onload = function(e) {
const fileContent = e.target.result;
const fileName = file.name;
// Load the file content into JSmol
Jmol.script(myJmol, `load DATA "${fileName}"\n${fileContent}\nEND "${fileName}"; ${default_render()}`);
console.log("Loaded file:", fileName);
};
reader.readAsText(file);
}
function openFileDialog() {
document.getElementById('file-input').click();
}
Jmol.jmolButton(myJmol, "javascript openFileDialog()", "Choose File");
</script>
</div>
<div class="control-group load-group">
<h3>Load Structure</h3>
<div style="margin-bottom: 10px;">
<label><input type="radio" name="load-source" value="pdb" checked onchange="updatePlaceholder()"> Protein Data Bank</label>
<label><input type="radio" name="load-source" value="mp" onchange="updatePlaceholder()"> Materials Project</label>
<label><input type="radio" name="load-source" value="pubchem" onchange="updatePlaceholder()"> PubChem</label>
</div>
<input type="text" id="structure-id" placeholder="Enter PDB code (e.g., 1crn)" style="width: 62%; margin-right: 5px;">
<script type="text/javascript">
function updatePlaceholder() {
var source = document.querySelector('input[name="load-source"]:checked').value;
var input = document.getElementById('structure-id');
if (source === 'pdb') {
input.placeholder = "Enter PDB code (e.g., 1crn)";
} else if (source === 'mp') {
input.placeholder = "Enter MP ID (e.g., mp-149)";
} else if (source === 'pubchem') {
input.placeholder = "Enter name or CID (e.g., aspirin)";
}
}
async function loadStructure() {
var structureId = document.getElementById('structure-id').value.trim();
if (!structureId) return;
var source = document.querySelector('input[name="load-source"]:checked').value;
if (source === 'pdb') {
Jmol.script(myJmol, `load =${structureId}; ${default_render()}`);
} else if (source === 'mp') {
try {
const response = await fetch(`${MP_PROXY_SERVER}/mp/${structureId}`);
const cifContent = await response.text();
if (cifContent && !cifContent.includes('error')) {
Jmol.script(myJmol, `load DATA "${structureId}.cif"\n${cifContent}\nEND "${structureId}.cif"; ${default_render()}`);
console.log("Loaded from Materials Project:", structureId);
} else {
alert("Structure not found: " + structureId);
}
} catch (error) {
console.error("Error:", error);
alert("Error loading structure. Check console for details.");
}
} else if (source === 'pubchem') {
Jmol.script(myJmol, `load :${structureId}; ${default_render()}`); // PubChem supports name and CID directly
}
}
Jmol.jmolButton(myJmol, "javascript loadStructure()", "Load");
</script>
</div>
<div class="load-group control-group">
<h3>Load Trajectory</h3>
<div style="margin-bottom: 10px;">
<label style="display: block; margin-bottom: 5px;">Topology (.xyz,.pdb,.mol,.sdf,.cif):</label>
<input type="file" id="topology-input" accept=".xyz,.pdb,.mol,.sdf,.cif" style="display: none;">
<input type="text" id="topology-name-display" placeholder=".xyz, .pdb, .mol, .sdf, .cif" readonly style="width: 50%; margin-right: 5px;">
<script type="text/javascript">
function openTopologyDialog() {
document.getElementById('topology-input').click();
}
Jmol.jmolButton(myJmol, "javascript openTopologyDialog()", "Choose File");
</script>
</div>
<div style="margin-bottom: 10px;">
<label style="display: block; margin-bottom: 5px;">Trajectory (.dcd, .xtc, .trr):</label>
<input type="file" id="trajectory-input" accept=".dcd,.xtc,.trr,.xyz" style="display: none;">
<input type="text" id="trajectory-name-display" placeholder=".dcd, .xtc, .trr, .xyz" readonly style="width: 50%; margin-right: 5px;">
<script type="text/javascript">
function openTrajectoryDialog() {
document.getElementById('trajectory-input').click();
}
Jmol.jmolButton(myJmol, "javascript openTrajectoryDialog()", "Choose File");
</script>
</div>
<script type="text/javascript">
let topologyData = null;
let topologyFileName = null;
document.getElementById('topology-input').addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
document.getElementById('topology-name-display').value = file.name;
const reader = new FileReader();
reader.onload = function(event) {
topologyData = event.target.result;
topologyFileName = file.name;
console.log("Topology loaded:", topologyFileName);
};
reader.readAsText(file);
});
document.getElementById('trajectory-input').addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
if (!topologyData) {
alert("Please load topology file first!");
return;
}
document.getElementById('trajectory-name-display').value = file.name;
const reader = new FileReader();
reader.onload = function(event) {
const trajectoryData = event.target.result;
const trajectoryFileName = file.name;
// Then load trajectory coordinates
Jmol.script(myJmol, `load trajectory DATA "${trajectoryFileName}"\n${trajectoryData}\nEND "${trajectoryFileName}" coord "${topologyFileName}"; ${default_render()}`);
// Alternative way to get frame count
const frameCount = Jmol.evaluate(myJmol, '{*}.length');
console.log(`Loaded trajectory with ${frameCount} frames`);
// Show trajectory controls
document.getElementById('trajectory-controls').style.display = 'block';
// Update slider
const slider = document.getElementById('frame-slider');
slider.max = frameCount;
slider.value = 1;
document.getElementById('frame-display').textContent = `Frame: 1 / ${frameCount}`;
};
// Read as binary for .dcd, .xtc, .trr
if (file.name.endsWith('.dcd') || file.name.endsWith('.xtc') || file.name.endsWith('.trr')) {
reader.readAsArrayBuffer(file);
} else {
reader.readAsText(file);
}
});
</script>
</div>
<div id="trajectory-controls" style="display: none;">
<div class="control-group">
<h3>Frame Navigation</h3>
<div style="display: flex; align-items: center; gap: 10px; width: 100%;">
<input type="range" id="frame-slider" min="1" max="100" value="1"
style="flex: 1;" oninput="updateFrame(this.value)">
<span id="frame-display" style="min-width: 100px; font-size: 12px;">Frame: 1 / 100</span>
</div>
<script type="text/javascript">
function updateFrame(frameNum) {
Jmol.script(myJmol, `frame ${frameNum}`);
const maxFrames = document.getElementById('frame-slider').max;
document.getElementById('frame-display').textContent = `Frame: ${frameNum} / ${maxFrames}`;
}
Jmol.jmolButton(myJmol, "javascript updateSliderToFirst()", "First");
Jmol.jmolButton(myJmol, "javascript decrementFrame()", "◀");
Jmol.jmolButton(myJmol, "javascript incrementFrame()", "▶");
Jmol.jmolButton(myJmol, "javascript updateSliderToLast()", "Last");
function updateSliderToFirst() {
document.getElementById('frame-slider').value = 1;
updateFrame(1);
}
function incrementFrame() {
let currentFrame = parseInt(document.getElementById('frame-slider').value);
const maxFrames = document.getElementById('frame-slider').max;
if (currentFrame < maxFrames) {
currentFrame += 1;
document.getElementById('frame-slider').value = currentFrame;
updateFrame(currentFrame);
}
}
function decrementFrame() {
let currentFrame = parseInt(document.getElementById('frame-slider').value);
if (currentFrame > 1) {
currentFrame -= 1;
document.getElementById('frame-slider').value = currentFrame;
updateFrame(currentFrame);
}
}
function updateSliderToLast() {
const maxFrames = document.getElementById('frame-slider').max;
document.getElementById('frame-slider').value = maxFrames;
updateFrame(maxFrames);
}
</script>
</div>
<div class="control-group">
<h3>Animation</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "animation on", "Play");
Jmol.jmolButton(myJmol, "animation off", "Pause");
Jmol.jmolButton(myJmol, "animation mode loop", "Loop");
Jmol.jmolButton(myJmol, "animation mode palindrome", "Palindrome");
</script>
</div>
<div class="control-group">
<h3>Animation Speed</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "animation fps 5", "Slow (5 fps)");
Jmol.jmolButton(myJmol, "animation fps 10", "Medium (10 fps)");
Jmol.jmolButton(myJmol, "animation fps 20", "Fast (20 fps)");
</script>
</div>
</div>
<div class="control-group">
<h3>Atom Selection & Deletion</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "select none", "Clear Selection");
Jmol.jmolButton(myJmol, "select within(2.0, selected)", "Expand Selection (2Å)");
Jmol.jmolButton(myJmol, "save state _beforeDelete; delete selected", "Delete Selected");
Jmol.jmolButton(myJmol, "restore state _beforeDelete; set picking ATOM;", "Undo Deletion");
</script>
</div>
<div class="control-group">
<h3>Atom Labels</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "var temp = {selected}; select *; label %a; select @temp", "Show");
Jmol.jmolButton(myJmol, "var temp = {selected}; select *; label off; select @temp", "Hide");
</script>
</div>
<div class="control-group">
<h3>Save Image & Structure</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "write image PNG 'molecule.png'", ".png");
Jmol.jmolButton(myJmol, "var temp = {selected}; select *; write xyz 'molecule.xyz'; select @temp", ".xyz");
Jmol.jmolButton(myJmol, "var temp = {selected}; select *; write pdb 'molecule.pdb'; select @temp", ".pdb");
Jmol.jmolButton(myJmol, "var temp = {selected}; select *; write mol 'molecule.mol'; select @temp", ".mol");
Jmol.jmolButton(myJmol, "var temp = {selected}; select *; write sdf 'molecule.sdf'; select @temp", ".sdf");
Jmol.jmolButton(myJmol, "var temp = {selected}; select *; write cif 'molecule.cif'; select @temp", ".cif");
</script>
</div>
<div class="control-group">
<h3>Display Type</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "var temp = {selected}; select *; spacefill 23%; wireframe 0.15; select @temp", "Ball & Stick");
Jmol.jmolButton(myJmol, "var temp = {selected}; select *; wireframe -0.1; select @temp", "Wire");
Jmol.jmolButton(myJmol, "var temp = {selected}; select *; spacefill only; select @temp", "Spacefill");
</script>
</div>
<div class="control-group">
<h3>Isosurface</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "var temp = {selected}; select *; isosurface vdw; select @temp", "Show");
Jmol.jmolButton(myJmol, "isosurface off", "Hide");
</script>
</div>
<div class="control-group">
<h3>Color Scheme</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "color cpk", "CPK (Default)");
Jmol.jmolButton(myJmol, "color rasmol", "RasMol");
Jmol.jmolButton(myJmol, "color chain", "By Chain");
Jmol.jmolButton(myJmol, "color structure", "By Structure");
Jmol.jmolButton(myJmol, "color group", "By Group");
</script>
</div>
<div class="control-group">
<h3>Display Mode</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "cartoon only", "Ribbon Only");
Jmol.jmolButton(myJmol, "cartoon off; wireframe 0.15; spacefill 23%", "Atoms Only");
Jmol.jmolButton(myJmol, "cartoon on; wireframe 0.15; spacefill 23%", "Both");
</script>
</div>
<div class="control-group">
<h3>Background Color</h3>
<input type="color" id="bg-color-picker" style="margin-left: 10px;" value="#ffffff" onchange="var hex = this.value; var r = parseInt(hex.substr(1,2), 16); var g = parseInt(hex.substr(3,2), 16); var b = parseInt(hex.substr(5,2), 16); Jmol.script(myJmol, 'background [' + r + ',' + g + ',' + b + ']')">
</div>
<div class="control-group">
<h3>Rendering Quality</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "set antialiasDisplay true", "High");
Jmol.jmolButton(myJmol, "set antialiasDisplay false", "Low");
</script>
</div>
<div class="control-group">
<h3>View Controls</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, `reset; zoom ${defaultZoomLevel}`, "Reset View");
</script>
</div>
<div class="control-group">
<h3>Spin Controls</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "spin on", "Start Spinning");
Jmol.jmolButton(myJmol, "spin off", "Stop Spinning");
</script>
</div>
<div class="control-group">
<h3>Zoom Controls</h3>
<script type="text/javascript">
Jmol.jmolButton(myJmol, "zoom *1.5", "Zoom In");
Jmol.jmolButton(myJmol, "zoom /1.5", "Zoom Out");
Jmol.jmolButton(myJmol, `zoom ${defaultZoomLevel}`, "Reset Zoom");
</script>
</div>
</div>
</div>
</body>
</html>