https://pymolwiki.org/index.php?title=XML-RPC_server&feed=atom&action=history
XML-RPC server - Revision history
2024-03-29T12:08:41Z
Revision history for this page on the wiki
MediaWiki 1.35.7
https://pymolwiki.org/index.php?title=XML-RPC_server&diff=12798&oldid=prev
Speleo3: remove outdated information
2018-09-26T11:33:02Z
<p>remove outdated information</p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 11:33, 26 September 2018</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">PyMOL includes </del>a <del class="diffchange diffchange-inline">built-in </del>XML-RPC server <del class="diffchange diffchange-inline">which can be started from the command line (modules/pymol/rpc.py in the source code). This allows remote programs (not necessarily on the same computer) to connect and call functions in the running PyMOL instance</del>. <del class="diffchange diffchange-inline"> Starting the server is simple:</del></div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"><div style="background-color: #9f9; padding: 10px 20px; margin-bottom: 20px"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">This page describes </ins>a <ins class="diffchange diffchange-inline">custom user implementation of an </ins>XML-RPC server.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline"><source lang="bash"></del></div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">For PyMOL's built</ins>-<ins class="diffchange diffchange-inline">in server, see [[RPC]].</ins></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">pymol </del>-<del class="diffchange diffchange-inline">R</del></div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div></<ins class="diffchange diffchange-inline">div</ins>></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div></<del class="diffchange diffchange-inline">source</del>></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">Access to the XML-RPC </del>server <del class="diffchange diffchange-inline">is independent of PyMOL itself, so the client could be run from any Python program, not necessarily on the same computer. The simple example below shows how the client code might be written. </del></div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">This </ins>server will enable any method in the 'cmd' module to be called remotely, as well as custom methods of the "pymol_interface" class (several examples of which are shown below). Other modules (such as util) could be wrapped using the same trick.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline"><source lang="python"></del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">from xmlrpclib import ServerProxy</del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">pymol = ServerProxy(uri="http://localhost:9123/RPC2")</del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">pymol.load("model.pdb")</del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline"></source></del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">= A more advanced server =</del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">The main limitation of the built-in XML-RPC extension is that it requires all functions to be explicitly wrapped to be accessible via XML-RPC calls, which limits the flexibility. (It also appears to limit what custom methods can be wrapped.) An alternate design shown below </del>will enable any method in the 'cmd' module to be called remotely, as well as custom methods of the "pymol_interface" class (several examples of which are shown below). Other modules (such as util) could be wrapped using the same trick.</div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><source lang="python"></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><source lang="python"></div></td></tr>
</table>
Speleo3
https://pymolwiki.org/index.php?title=XML-RPC_server&diff=10471&oldid=prev
Natechols at 22:06, 23 January 2012
2012-01-23T22:06:52Z
<p></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 22:06, 23 January 2012</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>PyMOL includes a built-in XML-RPC server which can be started from the command line <del class="diffchange diffchange-inline">with the "-R" flag </del>(modules/pymol/rpc.py in the source code). This allows remote programs (not necessarily on the same computer) to connect and call functions in the running PyMOL instance. <del class="diffchange diffchange-inline">However, it requires all functions to be explicitly wrapped to be accessible via XML-RPC calls, which limits the flexibility. An alternate design shown below will enable any method in the 'cmd' module to be called remotely, as well as custom methods of the "pymol_interface" class (several examples of which are shown below). Other modules (such as util) could be wrapped using </del>the <del class="diffchange diffchange-inline">same trick.</del></div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>PyMOL includes a built-in XML-RPC server which can be started from the command line (modules/pymol/rpc.py in the source code). This allows remote programs (not necessarily on the same computer) to connect and call functions in the running PyMOL instance. <ins class="diffchange diffchange-inline">Starting </ins>the <ins class="diffchange diffchange-inline">server is simple:</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>= The server =</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"><source lang</ins>=<ins class="diffchange diffchange-inline">"bash"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">pymol -R</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"></source></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">Access to the XML-RPC server is independent of PyMOL itself, so the client could be run from any Python program, not necessarily on the same computer. </ins>The <ins class="diffchange diffchange-inline">simple example below shows how the client code might be written. </ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"><source lang="python"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">from xmlrpclib import ServerProxy</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">pymol = ServerProxy(uri="http://localhost:9123/RPC2")</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">pymol.load("model.pdb")</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"></source></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">= A more advanced </ins>server =</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">The main limitation of the built-in XML-RPC extension is that it requires all functions to be explicitly wrapped to be accessible via XML-RPC calls, which limits the flexibility. (It also appears to limit what custom methods can be wrapped.) An alternate design shown below will enable any method in the 'cmd' module to be called remotely, as well as custom methods of the "pymol_interface" class (several examples of which are shown below). Other modules (such as util) could be wrapped using the same trick.</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><source lang="python"></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><source lang="python"></div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l122" >Line 122:</td>
<td colspan="2" class="diff-lineno">Line 136:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></source></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></source></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">= </del>The client <del class="diffchange diffchange-inline">=</del></div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>The <ins class="diffchange diffchange-inline">corresponding </ins>client <ins class="diffchange diffchange-inline">code </ins>is <ins class="diffchange diffchange-inline">shown below; not surprisingly</ins>, <ins class="diffchange diffchange-inline">it is very simple to </ins>the example <ins class="diffchange diffchange-inline">above</ins>. Because of the use of getattr() to retrieve methods in the 'cmd' API, we do not need to explicitly wrap cmd.load(), cmd.show(), or cmd.hide() for this code to work<ins class="diffchange diffchange-inline">, and any other method in 'cmd' can be similarly accessed, as well as our custom methods</ins>.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">Access to the XML-RPC server </del>is <del class="diffchange diffchange-inline">independent of PyMOL itself</del>, <del class="diffchange diffchange-inline">so this part could be run from any Python program, not necessarily on </del>the <del class="diffchange diffchange-inline">same computer. The simple </del>example <del class="diffchange diffchange-inline">below shows how the client code might be written</del>. Because of the use of getattr() to retrieve methods in the 'cmd' API, we do not need to explicitly wrap cmd.load(), cmd.show(), or cmd.hide() for this code to work.</div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><source lang="python"></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><source lang="python"></div></td></tr>
</table>
Natechols
https://pymolwiki.org/index.php?title=XML-RPC_server&diff=10470&oldid=prev
Natechols at 22:00, 23 January 2012
2012-01-23T22:00:40Z
<p></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 22:00, 23 January 2012</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l134" >Line 134:</td>
<td colspan="2" class="diff-lineno">Line 134:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>pymol.load_current_model_and_maps("refined.pdb", "2mFo-DFc.ccp4", "mFo-DFc.ccp4")</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>pymol.load_current_model_and_maps("refined.pdb", "2mFo-DFc.ccp4", "mFo-DFc.ccp4")</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></source></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></source></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Category:Script_Library|XML-RPC server]]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Category:System_Scripts]]</ins></div></td></tr>
</table>
Natechols
https://pymolwiki.org/index.php?title=XML-RPC_server&diff=10468&oldid=prev
Natechols: Created page with "PyMOL includes a built-in XML-RPC server which can be started from the command line with the "-R" flag (modules/pymol/rpc.py in the source code). This allows remote programs (no..."
2012-01-23T21:58:26Z
<p>Created page with "PyMOL includes a built-in XML-RPC server which can be started from the command line with the "-R" flag (modules/pymol/rpc.py in the source code). This allows remote programs (no..."</p>
<p><b>New page</b></p><div>PyMOL includes a built-in XML-RPC server which can be started from the command line with the "-R" flag (modules/pymol/rpc.py in the source code). This allows remote programs (not necessarily on the same computer) to connect and call functions in the running PyMOL instance. However, it requires all functions to be explicitly wrapped to be accessible via XML-RPC calls, which limits the flexibility. An alternate design shown below will enable any method in the 'cmd' module to be called remotely, as well as custom methods of the "pymol_interface" class (several examples of which are shown below). Other modules (such as util) could be wrapped using the same trick.<br />
<br />
= The server =<br />
<br />
<source lang="python"><br />
<br />
from pymol import cmd, util<br />
from threading import Thread<br />
from SimpleXMLRPCServer import SimpleXMLRPCServer<br />
import cPickle<br />
import os<br />
import re<br />
import string<br />
<br />
def pymol_startup () :<br />
print "Loading PyMOL XML-RPC extensions"<br />
server = pymol_interface()<br />
<br />
class pymol_xmlrpc_server (SimpleXMLRPCServer) :<br />
def __init__ (self, addr, interface) :<br />
self.interface = interface<br />
SimpleXMLRPCServer.__init__(self, addr, logRequests=0)<br />
<br />
def _dispatch (self, method, params) :<br />
if not self.interface.enable_xmlrpc :<br />
return -1<br />
result = -1<br />
func = None<br />
if hasattr(self.interface, method) :<br />
func = getattr(self.interface, method)<br />
elif hasattr(cmd, method) :<br />
func = getattr(cmd, method)<br />
if not callable(func) :<br />
print "%s is not a callable object" % method<br />
else :<br />
result = func(*params)<br />
if result is None :<br />
result = -1<br />
return result<br />
<br />
class pymol_interface (object) :<br />
def __init__ (self) :<br />
self.enable_xmlrpc = True<br />
# the port can be set via an environment variable - although it could just as easily be passed to __init__<br />
port = string.atoi(os.environ.get("PYMOL_XMLRPC_PORT", "9123"))<br />
self._server = pymol_xmlrpc_server(("localhost", port), self)<br />
t = threading.Thread(target=self._server.serve_forever)<br />
t.setDaemon(1)<br />
t.start()<br />
print "Started XML-RPC server on port %d" % port<br />
<br />
def close_all (self) :<br />
cmd.delete("*")<br />
<br />
def disable_all (self) :<br />
cmd.disable("*")<br />
<br />
def load_current_model_and_maps (self,<br />
pdb_file,<br />
fwt_map,<br />
delfwt_map) :<br />
model_name = os.path.basename(os.path.splitext(pdb_file)[0])<br />
cmd.load(pdb_file, model_name, state=1)<br />
cmd.load(fwt_map, "2fofc", state=1, format="ccp4")<br />
cmd.load(delfwt_map, "fofc", state=1, format="ccp4")<br />
cmd.isomesh("m1", "2fofc", 1.0, model_name, 5.0)<br />
cmd.isomesh("m2", "fofc", 3.0, model_name, 5.0)<br />
cmd.isomesh("m3", "fofc", -3.0, model_name, 5.0)<br />
cmd.color("marine", "m1")<br />
cmd.color("green", "m2")<br />
cmd.color("red", "m3")<br />
<br />
def setup_roving (self, f_map="2fofc", diff_map="fofc") :<br />
cmd.set("roving_detail", 20)<br />
cmd.set("roving_isomesh", 20)<br />
cmd.set("roving_origin", 1)<br />
cmd.set("roving_sticks", 0)<br />
cmd.set("roving_ribbon", 0)<br />
cmd.set("roving_lines", 0)<br />
cmd.set("roving_spheres", 0)<br />
cmd.set("roving_nb_spheres", 0)<br />
cmd.set("roving_polar_contacts", 0)<br />
cmd.set("roving_polar_cutoff", 0)<br />
cmd.set("stick_radius", 0.12)<br />
cmd.set("roving_map1_name", f_map)<br />
cmd.set("roving_map1_level", 1)<br />
cmd.set("roving_map2_name", diff_map)<br />
cmd.set("roving_map3_name", diff_map)<br />
cmd.set("roving_map2_level", 3)<br />
cmd.set("roving_map3_level", -3)<br />
cmd.refresh()<br />
<br />
def refresh_maps (self, f_map="2fofc", diff_map="fofc") :<br />
cmd.isomesh("rov_m1", f_map, 1.0, "center", 20)<br />
cmd.isomesh("rov_m2", diff_map, 3.0, "center", 20)<br />
cmd.isomesh("rov_m3", diff_map, -3.0, "center", 20)<br />
cmd.color("skyblue", "rov_m1")<br />
cmd.color("green", "rov_m2")<br />
cmd.color("red", "rov_m3")<br />
<br />
def show_selection (self, selection_string, zoom=True): #"True") :<br />
cmd.hide("sticks")<br />
util.cbay()<br />
try :<br />
cmd.show("sticks", selection_string)<br />
except Exception, e :<br />
return "Invalid selection."<br />
cmd.color("white", selection_string)<br />
if zoom :<br />
cmd.zoom(selection_string, buffer=5)<br />
<br />
def recenter (self, x, y, z) :<br />
view = list(cmd.get_view())<br />
view[12] = x<br />
view[13] = y<br />
view[14] = z<br />
cmd.set_view(view)<br />
<br />
if __name__ == "pymol" : # optional, if the module will be a command line argument to pymol<br />
pymol_startup()<br />
<br />
</source><br />
<br />
= The client =<br />
<br />
Access to the XML-RPC server is independent of PyMOL itself, so this part could be run from any Python program, not necessarily on the same computer. The simple example below shows how the client code might be written. Because of the use of getattr() to retrieve methods in the 'cmd' API, we do not need to explicitly wrap cmd.load(), cmd.show(), or cmd.hide() for this code to work.<br />
<br />
<source lang="python"><br />
from xmlrpclib import ServerProxy<br />
pymol = ServerProxy(uri="http://localhost:9123/RPC2")<br />
pymol.load("model.pdb")<br />
pymol.show("cartoon")<br />
pymol.hide("lines")<br />
pymol.load_current_model_and_maps("refined.pdb", "2mFo-DFc.ccp4", "mFo-DFc.ccp4")<br />
</source></div>
Natechols