Macs in Chemistry

Insanely great science

 

Export from ChemBioDraw as a mol file (Updated 20 December 2013)

A number of publishers are seeking to add extra value to publications by including access to chemical structure information to aid searching and indexing. More details are included in this comment from Elsevier.

Elsevier would like to enrich online articles by visualising and providing details of chemical structures you define as the main chemical compounds described in your article. For this purpose, mol files of the key compounds can be uploaded in EES. Please use your preferred drawing tool to export chemical structures as mol files and ensure that they are well defined and do not contain aromtic bonds, R-Groups or other variables. Submitted mol files will be available for downloading from your online article on ScienceDirect. Furthermore, Elsevier will generate InChI keys from the mol files and include them in the online article, which increase the online searchability of your article e.g. in Google. InChI keys will also be used to link the article to additional data in Reaxys.

The mol file format is a very well established format, it has the advantage of being a human readable text format so if nothing else you can open and read them in any text editor. The molfile consists of some header information, the Connection Table (CT) containing atom info, then bond connections and types, it does not contain any display information so who the resulting structure looks will depend on the software used to open it. This does mean that you will need to keep your diagram, schemes etc in the native file format for your chemical drawing package and then export to mol file format on submission. Since you need to export each structure as an individual file this will become somewhat tedious, fortunately Brian Myers has written an applescript that greatly helps the process for ChemBioDraw users.

The script is shown below and there is a download link at the bottom of the page. A key element to the script is the use of “application id”, this avoids the need to alter the script for different versions of ChemBioDraw such at Std, Pro, or Ultra. However as of version 13 PerkinElmer now own Cambridgesoft so depending on the version you have you will need to edit the script.

tell application id "com.cambridgesoft.ChemDraw" --for ChemBioDraw version 12 or less

tell application id "com.perkinelmer.ChemDraw" --for ChemBioDraw version 13 or greater

Update

One of the issues with the original script that the mol file contains in its first line the incorrect title of the file (it appears to be the name of the document template).

When you just launched your ChemDraw application, or created a new document, the title would be “Untitled **”, such as "Untitled ACS Document 1996-1". When you save it as Mol file, its header block will inherit the current document title "Untitled ACS Document 1996-1".

Untitled ACS Document 1996-2
ChemDraw12201318592D

14 16  0  0  0  0  0  0  0  0999 V2000

It would be better to have the molfile title the same as the file name the user enters in the dialog box, one way to achieve this is to “edit” the file and then save again to the same file name. We can do this by adding a line to clean up the structure and then saving. Simply saving again does not work, the file needs to have changed.

try
save first document in (molAttachment) as "MDL Molfile”
--This is to ensure the title of the mol file is set correctly
do menu item "Clean Up Structure" of menu "Structure"
save first document in (molAttachment) as "MDL Molfile"
close first document saving no

If you now look at the mol file in a text editor you can see the title is set more appropriately.

Mol file1.mol
ChemDraw12201319082D

14 16  0  0  0  0  0  0  0  0999 V2000

This script very nicely demonstrates the power of applescript to automate repetitive tasks. To use the script simply select a structure in a ChemBioDraw scheme and then run the script, you will be prompted to provide a unique filename for the mol file, the script will then create the mol file for you.

SaveAsMolfile.scpt

--Created by Brian J. Myers based on Scripts provided by Chris Swain (www.macinchem.org)

--Copyright (c) 2013, Brian Myers
--All rights reserved.

--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are met: 

--1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
--2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 

--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
--ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
--WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
--DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
--ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
--(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
--LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
--ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
--(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


property target_path : path to desktop as string

set thenameResult to display dialog "Provide the name of the file to Send. The file will be saved to the Desktop" default answer "Mol file1"
set thefileName to text returned of thenameResult
--For a differnt format change the extension here ( mol, tiff, png, gif, pdf, msi, smd, cdxml, cdx, bmp, jpg, eps)  to coorespond with the format
set mol_file to target_path & thefileName & ".mol"
set myinfo to ""
my write_to_file(myinfo, mol_file, false)
set molAttachment to mol_file as alias


tell application id "com.cambridgesoft.ChemDraw" --for ChemBioDraw version 12 or less
  --tell application id "com.perkinelmer.ChemDraw" --If using a version since PerkinElmer took over
    activate
    if enabled of menu item "Copy" of menu "Edit" then
      do menu item "Copy" of menu "Edit"
        do menu item 1 of menu 2
        do menu item "Paste" of menu "Edit"
  else
      

        display dialog "Nothing selected, Select All?" buttons {"Cancel", "Select All"} default button 2
        if button returned of the result is "Select All" then
          do menu item "Select All" of menu "Edit"
            do menu item "Copy" of menu "Edit"
            do menu item 1 of menu 2
            do menu item "Paste" of menu "Edit"

      end if
  end if
    --Other formats that could be possible include:
    --MDL Molfile, TIFF, PNG, GIF, CML, PDF, MSI ChemNote, SMD 4.2 File, ChemDraw XML, ChemDraw, BMP,  JPEG, Encapsulated PostScript, and perhaps others
    try
      save first document in (molAttachment) as "MDL Molfile"
        --This is to ensure the title of the mol file is set correctly
        do menu item "Clean Up Structure" of menu "Structure"
        save first document in (molAttachment) as "MDL Molfile"
        close first document saving no
  on error
      display dialog "The Format of the file is not supported. Nothing was saved in the file."
        close first document saving no
  end try
end tell


--this is just a standard write to file and could be simplified
on write_to_file(this_data, target_file, append_data)
  try
      set the target_file to the target_file as text
        set the open_target_file to open for access file target_file with write permission
        if append_data is false then set eof of the open_target_file to 0
        write (this_data as international text) to the open_target_file starting at eof
        close access the open_target_file
        return true
  on error
      try
          close access file target_file
      end try
        return false
  end try
end write_to_file

The script can be downloaded from here SaveAsMolfile.scpt.zip

The Applescript section contains more tutorials, scripts and resources.