### Web Services - Sample 07: Using a FORM with PyMOL Web Services

toggle iframe quit pymol (FireFox only: view page source)

Here we use an HTML FORM to show how buttons, checkboxes and other INPUT elements can be used with PyMOL Web Services. This load button is displayed by the following HTML code.

pept

    <FORM ACTION="/apply/pymol.cmd.load" TARGET=pymol_response_iframe>
    <INPUT TYPE=HIDDEN NAME=filename value="$PYMOL_PATH/test/dat/pept.pdb">
    <INPUT TYPE=SUBMIT VALUE="load"> pept
    </FORM>

In a FORM, the PyMOL command is the FORM's ACTION, and each PyMOL command argument is a seperate INPUT element. Here are a few other uses. Use the "view page source" link above to see the details of how this is done. Show pept as: sticks lines spheres cartoon pept

The previous example had a hard-coded filename, but the filename could be selected from a menu, as in:
Show all as: lines ribbon cartoon water

Finally, we see how a file can be uploaded to PyMOL. Using a FORM is currently the only way a file can be read from the local machine to be loaded into PyMOL using a web page. There are several essential differences when using a FORM intended to upload a file to PyMOL. These are:

- The METHOD=POST is required.
- The ENCTYPE=multipart/form-data is required.
- The command is read_pdbstr instead of load.
- Two arguments are required: pdb (the pdb "string") and name (the name to be used for the object).

    <FORM ACTION="/apply/pymol.cmd.read_pdbstr" TARGET=pymol_response_iframe
     METHOD=POST ENCTYPE="multipart/form-data"
    PDB File: <INPUT TYPE=FILE NAME="pdb">
    Name: <INPUT TYPE=TEXT NAME="name" VALUE="mypdb">
    <INPUT TYPE=SUBMIT VALUE="load">
    </FORM>

The above HTML displays the form below.

PDB File: Name: The checkboxes above that "Show all as:" will also continue to work. They have been coded to NOT use a selection keyword, and so they apply to all objects in PyMOL. However, they may not be in sync with the current PyMOL display. They can be toggled on and off to get them in sync.