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

This section provides a tutorial example on how to control molecule SVG image size using the Open Babel 'obabel ... -o svg -xPnnn' command.

The default behavior of Open Babel on scaling and centering SVG images is different depending on which release you are using.

With Open Babel 2.4 or newer the molecule SVG image is defaulted in the center of a 200x200 square.

With Open Babel 2.3 or older, the molecule SVG image is defaulted in a rectangular area calculated as the boundary boxing all atom's x and y coordinates.

If you want to place the molecule SVG image in the center of a given square area, you can use the "-o svg -xPnnn" option with the "obabel" command.

Here is how the "-xPnnn" option is described in Open Babel help document: "P# - px Single mol in defined size image The General option --px # is an alternative to the above."

For example, the following command generates a SVG picture of a carbon chain displayed in the center of a 300x300 square area.

herong$ obabel -:CCCCCCC -O carbon-chain-centered.svg -xC -xt -xP300

1 molecule converted

As a comparison, running the following command with Open Babel 2.3 generates a SVG picture of a carbon chain displayed in rectangular area just large enough to cover all carbon atoms.

herong$ obabel -version
Open Babel 2.3.1 -- Oct 13 2011 -- 15:14:48

herong$ obabel -:CCCCCCC -O carbon-chain-default.svg -xC -xt

1 molecule converted

Put both images, carbon-chain-default.svg and carbon-chain-centered.svg, in an HTML document with grey background, you see the differences:

Carbon Chain Molecule Scaled Up
Carbon Chain Molecule Scaled Up

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