File formats/Scripting
Contents
File Formats for Scripting Jmol
Script input
Jmol reads script files, using not the load
command, but the script
command. These are plain-text files containing commands in the Jmol scripting language (in part common with Rasmol and Chime), that will modify the way the molecular model is shown. The file can have any extension (though .spt is the acknowledged standard).
For details on the scripting language, visit the Interactive Scripting Documentation.
In the Jmol application, you can also read a script file using the top menu, File > Open
.
In both the application and the signed applet, the pop-up menu Load > Script
.
Script output
The Jmol application and the signed applet can write a script file that will restore the current appearance and state of the model. The unsigned applet cannot save files, but can output the data to the console, from where they can be copied and then pasted and saved to a file by the user.
Using the application's top menu bar:
File > Export > Write State
write a filename and click on Save
.
Or you can use the button in the toolbar.
- In older versions of Jmol:
File > Export > Export Image or Script
- and in the
Image Type
drop-down list, chooseSPT
, write a filename and click onSave
.
Using the pop-up menu:
Save > Script with state
or Show > Current state
Inline formats
Molecular data are usually contained in an external file and loaded into Jmol using the load
command, but they can also be contained within the webpage (or fed into it using JavaScript or PHP, e.g. from a database).
In turn, script commands can also be contained in the molecular file.
To allow for this "inline" formats, several methods are implemented:
Please, note that these are advanced procedures. For normal needs, they can be avoided in favour of using normal scripting practices.
Molecular coordinates inline within a webpage
Can be done using direct instructions for the applet or, more easily, using functions in the Jmol.js library: jmolAppletInline, jmolLoadInline, jmolLoadInlineScript
.
Molecular coordinates inline within a script or script file
Can be done using the data "model"
command.
Script inline within a molecular coordinates file
Scripts can be included, in a single line, after a jmolscript:
tag (case-sensitive; the final colon is needed). This must be taken as a comment by the molecular file parser, so its location depends on the file format:
- In a PDB file, use
REMARK jmolscript:
in any line, followed by the script commands in the same line.
- (Several
REMARK jmolscript:
lines are also supported)
- In a MOL file (both v2000 and v3000), use
jmolscript:
in the third line, followed by the script commands in the same line. - In an XYZ file, use
jmolscript:
in the second line, followed by the script commands in the same line. - In a CIF file, use
#jmolscript:
followed by the script commands in the same line. It may be in any line as long as it does not interfere with the data structure, so it is better to put it either at the beginning or the end of the file.
In all cases, the script will be applied after the whole molecule has loaded and after whatever script commands may have been set using set defaultLoadScript
.