-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchimerax-test.html
228 lines (201 loc) · 7.86 KB
/
chimerax-test.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Minimal ChimeraX Test</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
.container {
max-width: 1000px;
margin: 0 auto;
padding: 20px;
}
h1 {
color: #333;
}
.viewer {
width: 100%;
height: 600px;
border: 1px solid #ccc;
background-color: #000;
margin: 20px 0;
position: relative;
overflow: hidden;
}
.controls {
background-color: #fff;
padding: 15px;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
button {
background-color: #3498db;
color: white;
border: none;
padding: 8px 15px;
border-radius: 4px;
cursor: pointer;
margin-right: 10px;
}
button:hover {
background-color: #2980b9;
}
#statusMessage {
padding: 10px;
margin: 10px 0;
border-radius: 4px;
display: none;
}
.success {
background-color: #d4edda;
color: #155724;
}
.error {
background-color: #f8d7da;
color: #721c24;
}
.info {
background-color: #d1ecf1;
color: #0c5460;
}
</style>
</head>
<body>
<div class="container">
<h1>Minimal ChimeraX Test</h1>
<div class="controls">
<button id="checkServerBtn">Check Server</button>
<button id="startChimeraXBtn">Start ChimeraX</button>
<button id="loadPdb1ubqBtn">Load 1UBQ</button>
<button id="loadPdb2vaaBtn">Load 2VAA</button>
<button id="takeSnapshotBtn">Take Snapshot</button>
<div id="statusMessage"></div>
</div>
<div class="viewer">
<iframe id="chimeraxIframe" src="http://localhost:9876" width="100%" height="100%" frameborder="0"></iframe>
</div>
</div>
<script>
// DOM Elements
const checkServerBtn = document.getElementById('checkServerBtn');
const startChimeraXBtn = document.getElementById('startChimeraXBtn');
const loadPdb1ubqBtn = document.getElementById('loadPdb1ubqBtn');
const loadPdb2vaaBtn = document.getElementById('loadPdb2vaaBtn');
const takeSnapshotBtn = document.getElementById('takeSnapshotBtn');
const statusMessage = document.getElementById('statusMessage');
const chimeraxIframe = document.getElementById('chimeraxIframe');
// Constants
const SERVER_URL = 'http://localhost:9876/api';
// Event listeners
checkServerBtn.addEventListener('click', checkServer);
startChimeraXBtn.addEventListener('click', startChimeraX);
loadPdb1ubqBtn.addEventListener('click', () => loadStructure('1ubq'));
loadPdb2vaaBtn.addEventListener('click', () => loadStructure('2vaa'));
takeSnapshotBtn.addEventListener('click', takeSnapshot);
// Check server status
async function checkServer() {
showStatus('Checking server connection...', 'info');
try {
const response = await fetch(`${SERVER_URL}/health`);
const data = await response.json();
if (data.status === 'success') {
showStatus('Server is running successfully!', 'success');
} else {
showStatus('Server returned an unexpected response', 'error');
}
} catch (error) {
console.error('Server error:', error);
showStatus(`Cannot connect to server: ${error.message}`, 'error');
}
}
// Start ChimeraX
async function startChimeraX() {
showStatus('Starting ChimeraX...', 'info');
try {
const response = await fetch(`${SERVER_URL}/chimerax/start`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
});
const data = await response.json();
if (data.status === 'success') {
showStatus(`ChimeraX started successfully! (PID: ${data.pid})`, 'success');
} else {
showStatus(`Failed to start ChimeraX: ${data.message}`, 'error');
}
} catch (error) {
console.error('Error starting ChimeraX:', error);
showStatus(`Error starting ChimeraX: ${error.message}`, 'error');
}
}
// Load structure
async function loadStructure(pdbId) {
showStatus(`Loading structure ${pdbId}...`, 'info');
try {
// Clear current session
await executeCommand('close session');
// Load the structure
await executeCommand(`open ${pdbId}`);
showStatus(`Structure ${pdbId} loaded successfully!`, 'success');
} catch (error) {
console.error('Error loading structure:', error);
showStatus(`Error loading structure: ${error.message}`, 'error');
}
}
// Take snapshot
async function takeSnapshot() {
showStatus('Taking snapshot...', 'info');
try {
const response = await fetch(`${SERVER_URL}/chimerax/snapshot`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
width: 800,
height: 600
})
});
const data = await response.json();
if (data.status === 'success') {
showStatus('Snapshot created successfully!', 'success');
// Reload the iframe to show the snapshot
chimeraxIframe.src = chimeraxIframe.src;
} else {
showStatus(`Failed to create snapshot: ${data.message}`, 'error');
}
} catch (error) {
console.error('Error taking snapshot:', error);
showStatus(`Error taking snapshot: ${error.message}`, 'error');
}
}
// Execute ChimeraX command
async function executeCommand(command) {
try {
const response = await fetch(`${SERVER_URL}/chimerax/command`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ command })
});
return await response.json();
} catch (error) {
console.error('Error executing command:', error);
throw error;
}
}
// Show status message
function showStatus(message, type) {
statusMessage.textContent = message;
statusMessage.className = type;
statusMessage.style.display = 'block';
console.log(`[${type.toUpperCase()}] ${message}`);
}
// Check server on load
window.addEventListener('DOMContentLoaded', checkServer);
</script>
</body>
</html>