Exporting or saving molecular model files from Jmol
Although Jmol was designed as a viewer, it has now capabilities to save files for the displayed molecular model (or a subset of it).
Jmol can export the currently selected set of atoms to a file in
- XYZ format
- PDB format
- MOL v2000 format (single model)
- MOL v3000 format (single model)
- SDF v2000 format (single or multiple models)
The last 3 are according to the official format specification from MDL-Accelrys-Symyx.
The syntax (see reference documentation) is like this:
All of the above commands will save the original cooordinates of each atom as they were in the input file.
There is also the choice (only in MOL format) of saving the transformed coordinates as they are in the current state of the model:
|commands (synonymous)||export the currently selected set of atoms,
with transformed coordinates, using this format:
write coord myFile.mol write coord mol myFile.myExt
write coord v3000 myFile.myExt
This function in the Jmol Scripting Language allows to place the output of the write command into a variable, rather than saving to a file. The data can later be loaded using
load var a.
show() below, as an alternative.
First parameter in the function is the format, second if needed is some qualifier, both matching what would be used in the command.
show() chemical function
The same information that would be exported to a file may be put into a variable using this function. It uses the NCI CACTVS Resolver web service for format conversion, and hence it needs a live internet connection to work.
- Available since Jmol version 14.6.0
- Note: If only a subset of the full model has been selected, only that subset will be included in the exported model. Since the procedure involves a query to the Resolver, and their server tries to interpret it as a full molecule, the result may then not be what you expect. Example:
select _N; show("chemical mol")returns mol-formatted data for ammonia, no matter which was the original molecule containing several N atoms.
Formats available are:
||XML-compliant version of ChemDraw's native file format||
||Cerius II from Accelrys/MSI|
||CHARMM (Chemistry at HARvard Macromolecular Mechanics)||
||Crystallographic Information File||
||Chemical Markup Language|
||HIV / HIN format from Hyperchem||
||from the JME/JSME Molecular Editor||
||Marvin format, from ChemAxon||
||from Protein DataBank, but nonstandard||
||Symyx MDL, V3000||
||SYBYL Line Notation||
||the traditional XYZ format|
The syntax is like this:
d = show("chemical xyz") d = show("chemical mol") d = show("chemical hyperchem")
The result (text string as the value of the variable) may then be displayed, processed, or even may be written to a file using
write var d myFile.hin. In this way, Jmol is in fact exporting file formats that it cannot export natively, by using the format conversion server at NCI.
These are available:
File > Save > Save a copy of file
File > Save > Save as PNG/JMOL (image+zip)
File > Save > Save JVXL isosurface
File > Export > Export PNG+JMOL image
The 2nd and 4th are equivalent and contain, packed in a single file, a snapshot PNG image, the coordinates file and the state script file.
The pop-up menu entry will svae the last isosurface selected or generated. More flexibility is allowed by using the
write isosurface command.
Saving Jmol-specific files
Special image files PNGJ
Jmol can export to a PNG file that, in addition of a snapshot of the current molecular rendering, includes the state with all the information of rendering style (PNG) and, optionally, the data of the molecular model (PNGJ). These files appear as regular image files to any software but, when loaded back in Jmol (or drag-and-dropped) will reproduce the exact state of the 3D molecular model.
(The extra non-image information is included in a metadata area allowed by the png format)
Here are the basic commands; for additional options, see the documentation
write image png "myFileName"
|saves to disk a snapshot image of the current display, including also the state (notes 1, 2 and 3)|
write "myFileName" as png
|does the same as the above one|
set imageState off; write image png "myFileName"
|saves to disk a snapshot image of the current display, without the state (note 2)|
write image pngj "myFileName"
|saves to disk a snapshot image of the current display, including also the model, state and any files involved in the rendering (note 1)|
write "myFileName" as pngj
|does the same as the above one|
- (*) Note 1: if the specified file extension is not png, the file will still be a valid png image file, but it may or not be recognized by any software and may not be recognized by Jmol.
- Note 2: by default, molecular state is included in the file, unless
set imageStatehas been previously set to
- Note 3: in the case of png files (not pngj), the molecular model file and any isosurface files involved must be in the same folder as the png file in order for the state to be interpreted.
New feature: Allows replacement of PNG data in PNGJ (available since version 14.31.34)
write "fileA.png" as pngj;saves a file containing both the image, the model data and the state
a = load("fileA.png",true);loads the file contents into a (binary) variable
b = load("fileB.png");loads a regular image file into another (binary) variable
a._IMAGE_ = b._DATA_;puts the binary data making image "B" into the image section of data from file "A" (replacing the existing image data)
write var a "fileC.png";saves the new combination stored in variable "a", i.e. molecular data from file "A" and image from file "B", into a new PNGJ file