98 lines
2.8 KiB
HTML
98 lines
2.8 KiB
HTML
<html>
|
|||
|
|
<head>
|
||
|
|
<meta http-equiv="Pragma" content="no-cache"/>
|
||
|
|
<meta http-equiv="Cache-Control" content="no-cache"/>
|
||
|
|
<meta http-equiv="Expires" content="-1" />
|
||
|
|
<title>Web Services - Sample 06: Using the JavaScript API</title>
|
||
|
|
|
||
|
|
<style><!--
|
||
|
|
a{text-decoration:none;
|
||
|
|
padding: 1px;
|
||
|
|
background-color: #dddddd}
|
||
|
|
--></style>
|
||
|
|
|
||
|
|
<script src="json2.js"></script>
|
||
|
|
<script src="pymol.js"></script>
|
||
|
|
|
||
|
|
<script type="text/javascript">
|
||
|
|
|
||
|
|
var pymol = new PyMOL(); // create PyMOL object instance for server of this page
|
||
|
|
|
||
|
|
var cmd = pymol.cmd; // assign a global symbol for the PyMOL cmd API
|
||
|
|
|
||
|
|
function demoLoop() {
|
||
|
|
cmd.reinitialize();
|
||
|
|
cmd.load("$PYMOL_PATH/test/dat/1tii.pdb");
|
||
|
|
cmd.show_as("cartoon");
|
||
|
|
list = cmd.get_chains("polymer");
|
||
|
|
for(var i=0;i<list.length;i++) {
|
||
|
|
cmd.color("auto","chain "+list[i]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
|
||
|
|
<h3>Web Services - Sample 06: Using the JavaScript API</h3>
|
||
|
|
|
||
|
|
<a href="javascript:void(0)" onclick="window.open('view-source:' + location.href)">view page source</a>
|
||
|
|
|
||
|
|
<a href="/apply/_quit">quit pymol</a>
|
||
|
|
|
||
|
|
(FireFox only: <a href="javascript:void(0)" onclick="window.open('view-source:' + location.href)">view page source</a>)
|
||
|
|
|
||
|
|
<p>The PyMOL JavaScript API re-exposes PyMOL's Python programming
|
||
|
|
interface directly to the JavaScript layer in an object-oriented way.</p>
|
||
|
|
|
||
|
|
<pre>
|
||
|
|
var pymol = new PyMOL(); // create PyMOL object instance for server of this page
|
||
|
|
|
||
|
|
var cmd = pymol.cmd; // assign a global symbol for the PyMOL cmd API
|
||
|
|
</pre>
|
||
|
|
|
||
|
|
<pre>
|
||
|
|
<a href="javascript:void(0)" onclick="cmd.load('$PYMOL_PATH/test/dat/pept.pdb')">cmd.load('$PYMOL_PATH/test/dat/pept.pdb)</a>
|
||
|
|
|
||
|
|
<a href="javascript:void(0)" onclick="cmd.zoom('pept///1/',0,0,0,1)">cmd.zoom('pept///1/',0,0,0,1)</a>
|
||
|
|
|
||
|
|
<a href="javascript:void(0)" onclick="cmd.zoom('pept',0,0,0,2)">cmd.zoom('all',0,0,0,2)</a>
|
||
|
|
|
||
|
|
</pre>
|
||
|
|
|
||
|
|
<p>This eliminates the need for encoding your PyMOL commands as URL query
|
||
|
|
strings and makes it possible to write JavaScript programs in your web page
|
||
|
|
which control PyMOL in much the same way Python programs do.</p>
|
||
|
|
|
||
|
|
<table>
|
||
|
|
<tr>
|
||
|
|
<th align="left"><b>Python (inside PyMOL)</b></th>
|
||
|
|
<th width="50"> </th>
|
||
|
|
<th align="left"><b>JavaScript (inside Browser)</b></th>
|
||
|
|
</tr>
|
||
|
|
<tr>
|
||
|
|
<td valign="top"><pre>cmd.reinitialize()
|
||
|
|
cmd.load("$PYMOL_PATH/test/dat/1tii.pdb")
|
||
|
|
cmd.show_as("cartoon")
|
||
|
|
list = cmd.get_chains("polymer")
|
||
|
|
for chain in list:
|
||
|
|
cmd.color("auto","chain "+chain)
|
||
|
|
</td><td> </td>
|
||
|
|
<td valign="top"><pre>cmd.reinitialize();
|
||
|
|
cmd.load("$PYMOL_PATH/test/dat/1tii.pdb");
|
||
|
|
cmd.show_as("cartoon");
|
||
|
|
list = cmd.get_chains("polymer");
|
||
|
|
for(var i=0;i<list.length;i++) {
|
||
|
|
cmd.color("auto","chain "+list[i]);
|
||
|
|
}
|
||
|
|
</pre>
|
||
|
|
<a href="javascript:void(0)" onClick="demoLoop()">Run this program</a>
|
||
|
|
</td>
|
||
|
|
</tr>
|
||
|
|
</table>
|
||
|
|
|
||
|
|
<a href="javascript:void(0)" onClick="pymol.cmd.show('sticks','blah')">throw exception</a>
|
||
|
|
|
||
|
|
</body>
|
||
|
|
</html>
|