MarvinSketch and MarvinView can handle compressed molfiles that are typically five times smaller than their original, uncompressed version. This reduces the download time of HTML pages containing molecule applets.
Compressed molfiles can be created by choosing Edit / Source , then Format / Compressed Molfile in MarvinSketch or MarvinView. If you cannot find the Edit menu, then click on the upper left arrow in MarvinSketch, right click or double click the compound in MarvinView.
Code : csmol , cssdf , csrxn , csrdf
Extensions : .csmol , .cssdf , .csrxn , .csrdf
The chemaxon.formats.MdlCompressor
can compress or decompress MDL Molfiles, SDfiles, RGfiles and Rxnfiles in two ways:
In one step: if the input file contents are in a byte array or in a String.
MdlCompressor has two static methods that convert in one step:
The following flags can be specified:
COMPRESS
for compression
DECOMPRESS
for decompression
Molecule by molecule: using an InputStream and an OutputStream.
Note that there is a more general converter class in the Chemaxon class library (too general to be open source), chemaxon.formats.MolConverter, that is also a command line application (it has a main() method). In a Java program, it can be used similarly to MdlCompressor. Only the constructor differs:
Decompression:
At first you should include the file molcompress.js in the HTML page, in the following way:
Note that the JavaScript version of molCompress can only compress simple Molfiles. SDfiles, RGfiles and Rxnfiles are not supported.
Because of the difference of operating systems in text file formats, you might need a function that converts a string to DOS/Windows format:
In this example, an HTML text area is used to display the input and output of the molfile compression or decompression.
The second argument of molCompress()
must be true
for compression, false
for decompession.