Diagram API

Introduction

The ccdc.diagram module has functionality for generating 2D diagrams.

The main class of the ccdc.diagram module is ccdc.diagram.DiagramGenerator.

>>> from ccdc.io import EntryReader
>>> from ccdc.diagram import DiagramGenerator
>>> entry_reader = EntryReader('CSD')
>>> mol = entry_reader.molecule('ABEBUF')
>>> diagram_generator = DiagramGenerator()
>>> img = diagram_generator.image(mol)  # img is a PIL image

API

class ccdc.diagram.DiagramGenerator(settings=None)[source]

Diagram generator.

class Settings(_settings=None)[source]

Settings base class for diagram generation.

property background_color

The foreground color.

detect_intra_hbonds = False

Whether to detect intra-molecular hbonds.

property element_coloring

Color atomic labels.

explicit_polar_hydrogens = False

Whether to use explicit polar hydrogens.

property font_family

The name of the font family.

property font_italic

Whether the font is italic or not.

property font_size

The image font size.

property font_weight

The weight of the font.

property foreground_color

The foreground color.

property highlight_color

Color used for highlighting atoms and bonds.

property image_height

The image height.

property image_width

The image width.

property line_width

The image line width.

overwrite_existing_image = False

Whether to override the existing image of an entry.

property return_type

The image method return type.

shrink_symbols = True

Whether to replace particular substructures with functional group labels.

chemdraw_xml(molecule, file_name)[source]

Write a chemdraw XML file containing the 2D diagram of the molecule passed in.

Parameters:
Returns:

the text written to the file, or None

image(argument, highlight_atoms=None, label_atoms=None)[source]

Return an image or list of images according to arguments.

Parameters:
Returns:

a PIL image, or a list of PIL images. It may return None if the diagram generation failed.