"obabel -o svg" - Molecule Picture in SVG

This section provides a quick introduction on Open Babel 'obabel -o svg' command to generate molecule picture in SVG (Scalable Vector Graphics) format.

If you want to visualize a molecule structure as a 2-Dimensional picture, SVG (Scalable Vector Graphics) is a better format than any other formats like PNG (Portable Network Graphics). This is because SVG pictures are truly scalable. They can be enlarged at any size without losing any resolution.

To learn how to generate a good SVG picture from a molecule structure with the Open Babel "obabel" command, you should look at the SVG help text as shown below:

herong$ obabel -H svg

svg  SVG 2D depiction
Scalable Vector Graphics 2D rendering of molecular structure.

When called from command line or GUI or otherwise via Convert(),
single molecules are displayed at a fixed scale, as in normal diagrams,
but multiple molecules are displayed in a table which expands to fill
the containing element, such as a browser window.
When WriteMolecule() is called directly, without going through
WriteChemObject, e.g. via OBConversion::Write(), a fixed size image by
default 200 x 200px containing a single molecule is written. The size
can be specified by the P output option.

Multiple molecules are displayed in a grid of dimensions specified by
the ``-xr`` and ``-xc`` options (number of rows and columns respectively
and ``--rows``, ``--cols`` with babel).
When displayed in most modern browsers, like Firefox, there is
javascript support for zooming (with the mouse wheel)
and panning (by dragging with the left mouse button).

If both ``-xr`` and ``-xc`` are specified, they define the maximum number of
molecules that are displayed.
If only one of them is displayed, then the other is calculated so that
ALL the molecules are displayed.
If neither are specified, all the molecules are output in an
approximately square table.

By default, 2D atom coordinates are generated (using gen2D) unless they
are already present. This can be slow with a large number of molecules.
(3D coordinates are ignored.) Include ``--gen2D`` explicitly if you wish
any existing 2D coordinates to be recalculated.

Write Options e.g. -xu
 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 attached hydrogens.
 a draw all carbon atoms
    So propane would display as H3C-CH2-CH3
 d do not display molecule name
 s use asymmetric double bonds
 t use thicker lines
 e embed molecule as CML
    OpenBabel can read the resulting svg file as a cml file.
 p# px Scale to bond length(single mol only)
 P# px Single mol in defined size image
    The General option --px # is an alternative to the above.
 c# number of columns in table
 cols# number of columns in table(not displayed in GUI)
 r# number of rows in table
 rows# number of rows in table(not displayed in GUI)
 N# max number objects to be output
 l draw grid lines
 h <condition><color> highlight mol if condition is met
    The condition can use descriptors and properties,
    See documentation on ``--filter`` option for details.
    Specifying the highlight color is optional.
 i add index to each atom
    These indices are those in sd or mol files and correspond to the
    order of atoms in a SMILES string.
 j do not embed javascript
    Javascript is not usually embedded if there is only one molecule,
    but it is if the rows and columns have been specified as 1: ``-xr1 -xc1``
 x omit XML declaration (not displayed in GUI)
    Useful if the output is to be embedded in another xml file.
 X All atoms are explicitly declared
    Useful if we don't want any extra hydrogens drawn to fill the valence.
 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.svg --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.
 S Ball and stick depiction of molecules
    Depicts the molecules as balls and sticks instead of the
    normal line style.

If the input molecule(s) contain explicit hydrogen, you could consider
improving the appearance of the diagram by adding an option ``-d`` to make
it implicit. Hydrogen on hetero atoms and on explicitly drawn C is
always shown.
For example, if input.smi had 10 molecules::

      obabel input.smi -O out.svg -xb -xC -xe

would produce a svg file with a black background, with no explicit
terminal carbon, and with an embedded cml representation of each
molecule. The structures would be in two rows of four and one row
of two.

 This format is Write-only

Note that there are some nice features are supported for SVG format

Table of Contents

 About This Book

 SMILES (Simplified Molecular-Input Line-Entry System)

 Open Babel: The Open Source Chemistry Toolbox

 Using Open Babel Command: "obabel"

Generating SVG Pictures with Open Babel

"obabel -o svg" - Molecule Picture in SVG

 "obabel -:... -o svg" - Generate SVG from SMILES

 "obabel ... -o svg -xi" - Show Atom Indices in SVG

 "obabel ... -o svg -xS" - Ball/Stick Depiction in SVG

 "obabel ... -o svg -xX" - Hide Implicit H in SVG

 "obabel ... -o svg -xC" - Hide Terminal C in SVG

 "obabel ... -o svg -xP300" - Control Image Size

 "obabel ... -o svg" - Two "svg" XML Tag Levels

 "obabel ... -o svg -xd" - Hide Molecule Name

 "babel ... -o svg -xd -xP300" - Open Babel 2.4 Bug

 Scale SVG Images using "viewBox" Attribute

 Substructure Search with Open Babel

 Similarity Search with Open Babel

 Fingerprint Index for Fastsearch with Open Babel

 Stereochemistry with Open Babel

 Command Line Tools Provided by Open Babel

 RDKit: Open-Source Cheminformatics Software

 rdkit.Chem.rdchem - The Core Module

 rdkit.Chem.rdmolfiles - Molecular File Module

 rdkit.Chem.rdDepictor - Compute 2D Coordinates

 rdkit.Chem.Draw - Handle Molecule Images

 Molecule Substructure Search with RDKit

 rdkit.Chem.rdmolops - Molecule Operations

 Daylight Fingerprint Generator in RDKit

 Morgan Fingerprint Generator in RDKit

 RDKit Performance on Substructure Search

 Introduction to Molecular Fingerprints

 OCSR (Optical Chemical Structure Recognition)

 AlphaFold - Protein Structure Prediction

 Resources and Tools

 Cheminformatics Related Terminologies

 References

 Full Version in PDF/EPUB