-
Notifications
You must be signed in to change notification settings - Fork 2
/
viewerFinal.html
160 lines (144 loc) · 4.79 KB
/
viewerFinal.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
<!DOCTYPE html>
<html>
<head>
<title>PDB Viewer</title>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0;
}
body {
background-color: #fff;
overflow: hidden;
}
#controls {
position: absolute;
margin: 5px;
}
input[type="button"] {
border: 0;
border-radius: 0;
background-color: #CCC;
padding: 10px;
font-size: 16px;
color: #333;
}
</style>
</head>
<body>
<div id="controls">
<input id="info" type="button" value="Info">
<input id="insert" type="button" value="New PDB">
<input id="reload" type="button" value="Reload">
</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r67/three.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/stats.js/r11/Stats.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js"></script>
<script src="assets/libs/THREEx.WindowResize.js"></script>
<script src="assets/libs/TrackballControls.js"></script>
<script src="assets/libs/builder.js"></script>
<script src='parserVDW.js'></script>
<script>
$(function () {
$('#info').on('click', showInfo);
$('#insert').on('click', loadPDB);
$('#reload').on('click', reload);
function showInfo() {
window.alert([
'Colors',
'S => Yellow',
'N => Blue',
'C => Black',
'O => Red',
'H => Gray',
'Cl => Green',
'F => Light Blue',
'K => Lilac',
'P => Orange'
].join('\n'));
};
function loadPDB() {
var id = prompt('insert PDB Id');
var base = 'http://rcsb.org/pdb/files/';
var ext = '.pdb';
var uri = base + id + ext;
$.get(uri)
.done(function(response) {
var atoms = clear(response);
addAtomsToScene(atoms);
})
.fail(function() {
alert('PDB ' + id + ' DOES NOT EXIST');
});
}
function reload () {
window.location.reload(true);
}
var scene = new THREE.Scene();
var atoms = new THREE.Object3D();
var axisHelper = new THREE.AxisHelper(1);
scene.add(axisHelper);
var width = window.innerWidth;
var height = window.innerHeight;
var aspect = width / height;
var camera = new THREE.PerspectiveCamera(45, aspect, 0.1, 100000);
camera.position.set(40, 40, 40);
camera.up = new THREE.Vector3(0, 1, 0);
camera.lookAt(scene.position);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(new THREE.Color(0xffffff));
renderer.setSize(width, height);
document.body.appendChild(renderer.domElement);
THREEx.WindowResize(renderer, camera);
var trackballControls = new THREE.TrackballControls(camera, renderer.domElement);
var maps = {
'H': THREE.ImageUtils.loadTexture("assets/textures/H_texture.png"),
'N': THREE.ImageUtils.loadTexture("assets/textures/N_texture.png"),
'C': THREE.ImageUtils.loadTexture("assets/textures/C_texture.png"),
'O': THREE.ImageUtils.loadTexture("assets/textures/O_texture.png"),
'S': THREE.ImageUtils.loadTexture("assets/textures/S_texture.png"),
'Cl': THREE.ImageUtils.loadTexture("assets/textures/Cl_texture.png"),
'F': THREE.ImageUtils.loadTexture("assets/textures/F_texture.png"),
'K': THREE.ImageUtils.loadTexture("assets/textures/K_texture.png"),
'P': THREE.ImageUtils.loadTexture("assets/textures/P_texture.png"),
'_': THREE.ImageUtils.loadTexture("assets/textures/g.png")
};
radii = {
'H': 1.20,
'N': 1.55,
'C': 1.70,
'O': 1.52,
'S': 1.80,
'Cl': 1.75,
'F': 1.47,
'K': 2.75,
'P': 1.80,
'_': 1.00
};
// add all atoms to scene
function addAtomsToScene(atoms) {
atoms.forEach(function (atom) {
var material = new THREE.SpriteMaterial({
map: maps[atom.type] || maps._,
useScreenCoordinates: false,
});
var radius = radii[atom.type] || radii._;
var sprite = new THREE.Sprite(material);
sprite.position.set(atom.x, atom.y, atom.z);
sprite.scale.set(radius*2, radius*2, 1.0);
scene.add(sprite);
});
}
function render() {
trackballControls.update();
requestAnimationFrame(render);
renderer.render(scene, camera);
}
render();
});
</script>
</body>
</html>