-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
143 lines (126 loc) · 4.49 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSmol -- Jmol/HTML5 Demo</title>
<script type="text/javascript" src="JSmol/JSmol.min.js"></script>
<script type="text/javascript">
// Set up variables and configurations
var jmolApplet0;
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const LP = urlParams.get("LP");
const moleculeName = urlParams.get('molecule');
const localFile = `structuresSDF/${moleculeName}.sdf`;
const pubChemSearch = `:${moleculeName}`;
// Debugging configuration
Jmol.debugCode = (queryString.indexOf("debugcode") >= 0);
// Applet ready callback
function jmol_isReady(applet) {
document.title = `${applet._id} - Jmol ${___JmolVersion}`;
Jmol._getElement(applet, "appletdiv").style.border = "1px solid blue";
}
// Jmol Info object
var Info = {
width: 300,
height: 300,
debug: false,
color: "0xFFFFFF",
use: "HTML5",
j2sPath: "JSmol/j2s",
readyFunction: jmol_isReady,
disableJ2SLoadMonitor: true,
disableInitialConsole: true,
allowJavaScript: true
};
// Function to load the molecule, either from the local file or from PubChem
function loadMolecule() {
// Check if the local .sdf file exists
fetch(localFile, { method: 'HEAD' })
.then(response => {
if (response.ok) {
// If the file exists, load it
Jmol.script(jmolApplet0, `load ${localFile}`);
} else {
// If the file does not exist, search PubChem
Jmol.script(jmolApplet0, `load ${pubChemSearch}`);
}
})
.catch(error => {
// If any error occurs (e.g., network issues), fall back to PubChem
console.error('Error checking file:', error);
Jmol.script(jmolApplet0, `load ${pubChemSearch}`);
});
}
// Measurement functions
function toggleMeasurement(id, scriptTrue, scriptFalse) {
const isChecked = document.getElementById(id).checked;
const script = isChecked ? scriptTrue : scriptFalse;
Jmol.script(jmolApplet0, script);
}
function angles() {
toggleMeasurement("angles", "measure ALLCONNECTED (*)(*)(*)", "measure DELETE ALLCONNECTED (*)(*)(*)");
}
function MEP() {
toggleMeasurement("MEP",
"if ({atomno < 10}.partialcharge == 0) {calculate partialcharge}; isosurface vdw map mep translucent",
"isosurface delete"
);
}
function bond_dipoles() {
toggleMeasurement("bond_dipoles", "dipole bonds width 0.1", "dipole bonds delete");
}
function molecular_dipole() {
toggleMeasurement("molecular_dipole", "dipole molecular width 0.1", "dipole molecular delete");
}
function LPs() {
toggleMeasurement("LPs", LP, "lcaocartoon lonePair delete");
}
// Initialize the Jmol applet and load the molecule
function initializeJmol() {
jmolApplet0 = Jmol.getApplet("jmolApplet0", Info);
loadMolecule(); // Load the molecule after the applet is initialized
}
</script>
</head>
<body>
<table>
<tr>
<td>
<input type="checkbox" id="angles" onchange="angles()">
<label for="angles">Bond Angles</label>
<br>
<div id="dipoles_div">
<input type="checkbox" id="bond_dipoles" onchange="bond_dipoles()">
<label for="bond_dipoles">Bond Dipoles</label>
<br>
<input type="checkbox" id="molecular_dipole" onchange="molecular_dipole()">
<label for="molecular_dipole">Molecular Dipole</label>
<br>
</div>
<div id="MEP_div">
<input type="checkbox" id="MEP" onchange="MEP()">
<label for="MEP">MEP</label>
<br>
</div>
<div id="LP_div">
<input type="checkbox" id="LPs" onchange="LPs()">
<label for="LPs">Lone Pairs</label>
</div>
</td>
<td>
<script type="text/javascript">
// Initialize the Jmol applet and load the molecule
initializeJmol();
</script>
</td>
</tr>
</table>
<script type="text/javascript">
// Hide unused divs based on URL parameters
if (LP == null) document.getElementById("LP_div").style.display = "none";
if (urlParams.get("MEP") == null) document.getElementById("MEP_div").style.display = "none";
if (urlParams.get("dipoles") == null) document.getElementById("dipoles_div").style.display = "none";
</script>
</body>
</html>