### Launch local HTTP server for PyMOL examples Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/content/running.html Commands to start the local web server for serving PyMOL example files. ```bash cd ./modules/web/examples python justhttpd.py ``` ```bash ../../../../pymol -qc justhttpd.py ``` -------------------------------- ### Launch PyMOL HTTP server via command line Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/content/server.html Start the PyMOL web server as the main script during PyMOL launch. ```bash pymol $PYMOL_PATH/modules/web/pymolhttpd.py ``` -------------------------------- ### Launch PyMOL HTTP server from Python Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/content/server.html Import and start the PyMOL HTTP server within a custom Python script. ```python from pymol import pymolhttpd httpd = pymolhttpd.PymolHttpd(8080, "htdocs") httpd.start() ``` -------------------------------- ### PyMOL Command Execution Examples Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample11/index.html Examples of invoking the cmd function to perform various PyMOL operations. ```javascript cmd('set?name=suspend_updates', 'delete?name=all', 'reset', 'load?filename=$PYMOL_PATH/test/dat/1tii.pdb', 'show?representation=cartoon', 'show_as?representation=sticks&selection=chain A', 'orient?selection=chain A&animate=5', 'unset?name=suspend_updates') ``` ```javascript cmd('count_atoms') ``` ```javascript cmd('reinitialize') ``` -------------------------------- ### Initialize PyMOL and Load PDB in JavaScript Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample06/htdocs/index.html Creates a PyMOL object instance and assigns the command API to a global symbol. Use this to start controlling PyMOL from JavaScript. ```javascript var pymol = new PyMOL(); // create PyMOL object instance for server of this page ``` ```javascript var cmd = pymol.cmd; // assign a global symbol for the PyMOL cmd API ``` -------------------------------- ### Integrate PyMOL Commands with jQuery Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample16/index.html Examples showing how to use jQuery to trigger PyMOL commands via direct URLs or buffered command URLs. ```javascript $(document).ready(function() { $("a[name=load]").click(function() { try { $.getJSON(host+"/apply/pymol.cmd.load?filename=$PYMOL_PATH/test/dat/pept.pdb&_callback=?", callback1); } catch (e) { alert(e); } return false; // causes the HREF to not load a new page }); }); ``` ```javascript $(document).ready(function() { // this function assumes that a (global) pymol instance has already been created // and that there are already some commands in the command buffer. $("a[name=load]").click(function() { try { $.getJSON(host+pymol.getBufferURL()+"&_callback=?", callback1); } catch (e) { alert(e); } return false; // causes the HREF to not load a new page }); }); ``` -------------------------------- ### Load PDB, Show Cartoon, and Get Chains Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample14/index.html This function reinitializes PyMOL, loads a PDB file, sets the display style to cartoon, and then retrieves all polymer chains, passing them to the 'part2' function for coloring. This demonstrates a typical workflow for initial molecular visualization. ```javascript function part1() { cmd.reinitialize(); cmd.load("$PYMOL_PATH/test/dat/1tii.pdb"); cmd.show_as("cartoon"); cmd.get_chains(part2, "polymer"); } ``` -------------------------------- ### Load PDB File into PyMOL Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample05/htdocs/index.html Loads a PDB file into PyMOL using the 'load' command. Assumes PDB files are located in a specific example directory. ```javascript function loadPDB(code) { return cmd('load?filename=$PYMOL_PATH/modules/web/examples/data/'+code+'.pdb'); } ``` -------------------------------- ### Reinitializing PyMOL and Starting Command Cascade Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample12/index.html This function reinitializes PyMOL and then initiates a sequence of commands by calling another function. This serves as the entry point for the command cascade. ```javascript function part1() { cmd.reinitialize(part2); } ``` -------------------------------- ### PyMOL Startup Configuration (PWG) Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample15/index.html Defines PyMOL startup parameters using a simple key-value format. Options control aspects like window size, position, and quality. ```text port 8085 options -qxie -F 0 -X 10 -Y 50 -W 250 -H 250 ``` ```text port 8086 options -qxi -F 0 -X 10 -Y 350 -W 250 -H 250 ``` -------------------------------- ### Initialize jQuery PyMOL interaction Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample13/index.html Sets up the host URL and a callback function to display results in the DOM. ```javascript var pymolhost = "http://localhost:8083"; function callback1(result) { document.getElementById('result').innerHTML = "
"+result+""; } $(document).ready(function() { $("a[name=load]").click(function() { try { $.getJSON(pymolhost+"/apply/pymol.cmd.load?filename=$PYMOL_PATH/test/dat/pept.pdb&_callback=?", callback1); } catch (e) { alert(e); } return false; // causes the HREF to not load a new page }); $("a[name=delete]").click(function() { try { $.getJSON(pymolhost+"/apply/pymol.cmd.delete?name=pept&_callback=?", callback1); } catch (e) { alert(e); } return false; // causes the HREF to not load a new page }); $("a[name=get_names]").click(function() { try { $.getJSON(pymolhost+"/apply/pymol.cmd.get_names?type=objects&_callback=?", callback1); } catch (e) { alert(e); } return false; // causes the HREF to not load a new page }); $("a[name=badload]").click(function() { try { $.getJSON(pymolhost+"/apply/pymol.cmd.load?filename=$PYMOL_PATH/test/dat/pept.pdb"); } catch (e) { if (e.description == undefined) { alert(e); //Firefox } else { alert(e.description); //Explorer } } return false; // causes the HREF to not load a new page }); }); a.info { text-decoration:underline; background-color: transparent; } a{ text-decoration:none; padding: 1px; background-color: #dddddd } ``` -------------------------------- ### Rotate Molecule Around Axis Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample01/htdocs/api.html Rotates the molecule around a specified axis by a given angle. This example rotates around the X-axis by 45 degrees. ```python /apply/pymol.cmd.turn?axis=x&angle=45 ``` -------------------------------- ### Control Command Buffer and Execute Commands Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample16/index.html Demonstrates enabling the buffer, queuing commands, retrieving JSON/URL representations, and sending them to PyMOL. ```javascript function part1() { pymol.setBufferMode('on'); cmd.reinitialize(); cmd.load("$PYMOL_PATH/test/dat/1tii.pdb", "atestname"); cmd.show_as("cartoon"); cmd.get_chains("polymer"); jcmd = pymol.getBufferJSON(); show_message(jcmd); jurl = pymol.getBufferURL(); show_message(jurl); pymol.sendJSON(process_chains, jcmd); pymol.setBufferMode('off'); } ``` -------------------------------- ### PyMOL Basic Commands Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample01/htdocs/api.html This section covers fundamental PyMOL commands for initialization, loading structures, selecting atoms, and displaying representations. ```APIDOC ## POST /apply/pymol.cmd.reinitialize ### Description Reinitializes PyMOL to its default state. ### Method POST ### Endpoint /apply/pymol.cmd.reinitialize ### Parameters None ### Request Example (No request body needed) ### Response #### Success Response (200) (No specific response body defined, typically indicates success) #### Response Example (No specific response example provided) ``` ```APIDOC ## POST /apply/pymol.cmd.load ### Description Loads a molecular structure file into PyMOL. ### Method POST ### Endpoint /apply/pymol.cmd.load ### Query Parameters - **filename** (string) - Required - The path to the molecular structure file. ### Request Example (Query parameters are part of the URL) ### Response #### Success Response (200) (No specific response body defined, typically indicates success) #### Response Example (No specific response example provided) ``` ```APIDOC ## POST /apply/pymol.cmd.select ### Description Selects atoms based on a given selection criterion. ### Method POST ### Endpoint /apply/pymol.cmd.select ### Query Parameters - **name** (string) - Required - The name to assign to the selection. - **selection** (string) - Required - The selection criterion (e.g., atom indices, residue ranges). - **enable** (integer) - Optional - Whether to enable the selection (1 for enabled, 0 for disabled). - **quiet** (integer) - Optional - Controls the verbosity of the output. - **merge** (integer) - Optional - Whether to merge with existing selections. - **state** (integer) - Optional - The state to apply the selection to. - **domain** (string) - Optional - The domain to select. ### Request Example (Query parameters are part of the URL) ### Response #### Success Response (200) (No specific response body defined, typically indicates success) #### Response Example (No specific response example provided) ``` ```APIDOC ## POST /apply/pymol.cmd.show ### Description Shows a specific representation for selected atoms. ### Method POST ### Endpoint /apply/pymol.cmd.show ### Query Parameters - **representation** (string) - Required - The representation to show (e.g., spheres, cartoon). - **selection** (string) - Required - The selection of atoms to apply the representation to. ### Request Example (Query parameters are part of the URL) ### Response #### Success Response (200) (No specific response body defined, typically indicates success) #### Response Example (No specific response example provided) ``` ```APIDOC ## POST /apply/pymol.cmd.origin ### Description Sets the origin for a selection. ### Method POST ### Endpoint /apply/pymol.cmd.origin ### Query Parameters - **selection** (string) - Required - The selection of atoms to set the origin for. - **object** (string) - Optional - The object to use as the origin. - **position** (string) - Optional - The position to set the origin to. - **state** (integer) - Optional - The state to apply this to. ### Request Example (Query parameters are part of the URL) ### Response #### Success Response (200) (No specific response body defined, typically indicates success) #### Response Example (No specific response example provided) ``` ```APIDOC ## POST /apply/pymol.cmd.turn ### Description Rotates a selection around a specified axis. ### Method POST ### Endpoint /apply/pymol.cmd.turn ### Query Parameters - **axis** (string) - Required - The axis of rotation (x, y, or z). - **angle** (number) - Required - The angle of rotation in degrees. ### Request Example (Query parameters are part of the URL) ### Response #### Success Response (200) (No specific response body defined, typically indicates success) #### Response Example (No specific response example provided) ``` -------------------------------- ### Execute PyMOL Command Synchronously Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample05/htdocs/index.html Sends a synchronous GET request to PyMOL to execute a command and returns the JSON result. Handles potential PyMOL exceptions. ```javascript function cmd(suffix) { // apply synchronously and return JSON result req = newRequest(); req.open('get', '/apply/pymol.cmd.' + suffix + ( suffix.indexOf('?') < 0 ? '?' : '&') + "_ts=" + new Date().getTime(), false); // synchronous req.setRequestHeader("Accept", "application/json"); req.send(""); if (req.status == 500) { alert("PyMOL Exception:\n" + eval('(' + req.responseText + ')').join("\n")); return null; } return eval('(' + req.responseText + ')'); } ``` -------------------------------- ### Initialize PyMOL JavaScript API with Buffering Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample08/htdocs/index.html Enable the buffering system by passing 'on' as the third argument to the PyMOL constructor. ```javascript var pymol = new PyMOL(null, null, 'on'); // create PyMOL object with buffering enabled var cmd = pymol.cmd; // assign a global symbol for the PyMOL cmd API ``` -------------------------------- ### Initialize PyMOL Request Queue Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample03/htdocs/index.html Sets up the queue array and the active status flag for managing sequential command execution. ```javascript var pymol_queue = []; var pymol_active = false; ``` -------------------------------- ### Displaying and Getting Chains in PyMOL via JavaScript Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/sample12/index.html This function sets the display style to 'cartoon' and then retrieves all polymer chains, passing them to a callback function for further processing (e.g., coloring). ```javascript function part3(list) { cmd.show_as("cartoon"); cmd.get_chains(part4, "polymer"); } ``` -------------------------------- ### Specify PyMOL Launch Options Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/content/pwg.html The 'options' command allows you to pass specific launch options to PyMOL, such as quiet mode (-q) or window size (-W). ```plaintext options -q -W 250 ``` -------------------------------- ### Launch Python Module Source: https://github.com/schrodinger/pymol-open-source/blob/master/modules/web/examples/content/pwg.html Use the 'launch' command to import a Python module and execute its __launch__(cmd) function, allowing for programmatic control of PyMOL. ```plaintext launch