PNG 2D depiction (png)#

or add/extract chemical structures from a .png file

The PNG format has several uses. The most common is to generate a .png file for one or more molecules. 2D coordinates are generated if not present:

obabel mymol.smi -O image.png

Chemical structure data can be embedded in the .png file (in a tEXt chunk):

obabel mymol.mol -O image.png -xO molfile

The parameter of the -xO option specifies the format (“file”can be added). Note that if you intend to embed a 2D or 3D format, you may have to call --gen2d or --gen3d to generate the required coordinates if they are not present in the input.

Molecules can also be embedded in an existing PNG file:

obabel existing.png mymol1.smi mymol2.mol -O augmented.png -xO mol

Reading from a PNG file will extract any embedded chemical structure data:

obabel augmented.png -O contents.sdf

Read Options#

-y <additional chunk ID>

Look also in chunks with specified ID

Write Options#

-p <pixels>

image size, default 300

-w <pixels>

image width (or from image size)

-h <pixels>

image height (or from image size)

-c <num>

number of columns in table

-r <num>

number of rows in table

-N <num>

max number objects to be output

-u

no element-specific atom coloring

Use this option to produce a black and white diagram

-U

do not use internally-specified color

e.g. atom color read from cml or generated by internal code

-b <color>

background color, default white

e.g -xb yellow or -xb #88ff00 -xb none is transparent. Just -xb is black with white bonds. The atom symbol colors work with black and white backgrounds, but may not with other colors.

-B <color>

bond color, default black

e.g -xB yellow or -xB #88ff00

-C

do not draw terminal C (and attached H) explicitly

The default is to draw all hetero atoms and terminal C explicitly, together with their attched hydrogens.

-a

draw all carbon atoms

So propane would display as H3C-CH2-CH3

-d

do not display molecule name

-m

do not add margins to the image

This only applies if there is a single molecule to depict. Implies -xd.

-s

use asymmetric double bonds

-t

use thicker lines

-A

display aliases, if present

This applies to structures which have an alternative, usually shorter, representation already present. This might have been input from an A or S superatom entry in an sd or mol file, or can be generated using the –genalias option. For example:

obabel -:"c1cc(C=O)ccc1C(=O)O" -O out.png
       --genalias -xA

would add a aliases COOH and CHO to represent the carboxyl and aldehyde groups and would display them as such in the svg diagram. The aliases which are recognized are in data/superatom.txt, which can be edited.

-O <format ID>

Format of embedded text

For example, molfile or smi. If there is no parameter, input format is used.

-y <additional chunk ID>

Write to a chunk with specified ID

Comments#

If Cairo was not found when Open Babel was compiled, then the 2D depiction will be unavailable. However, it will still be possible to extract and embed chemical data in .png files.