Skip to main content

Chemistry Drawer


PyPI downloads license

Draw molecules with Plotly.

Make molecules look the way you want it!

The package provides global control of aesthetics with config, and allows for local control by specifying details for every atom, bond, and ring.

(Development still in progress. So there are some bugs. But its working pretty well so far!)


Installation

Pip installable package available.

pip install chemdraw

pypi: chemdraw



Dependencies

  • numpy (1.23.1)
    • Used for math
  • plotly (5.9.0)
    • Plots molecules
  • kaleido (0.1.0post1)
    • Converts plotly graphs to images (png, svg, etc.)
    • I am not using the most recent version of kaleido as it does not play nice with my computer. Try the newest version, but if you are having issues install this specific version.
  • rdkit (2022.3.4)
    • Convert SMILES to position coordinates.
  • Pillow (9.2.0)
    • Used for image manipulation.
  • scikit-learn (1.1.1)
    • Used to reorient molecules.


Examples:

(Image may be distorted from viewer, but real image is not.)

Basic Usage

import chemdraw

mol = "O=C(C)Oc1ccccc1C(=O)O"
drawer = chemdraw.Drawer(mol, title=mol)
fig = drawer.draw()
fig.show()

simple example


Grid

import chemdraw

molecules = [
    "CCCCCCCCCC",
    "CC(CC(CCC)C)CC",
    "CCC1CC1",
    "C([C@@H]1[C@H]([C@@H]([C@H]([C@H](O1)O)O)O)O)O",
    "O=C(C)Oc1ccccc1C(=O)O",
    "C1(CCC2)=C3C2=CC4=C5C3=C(CCC5CCC4)C=C1",
    "CC(C)(C)N(C)C(=O)C14C3C2C1C5C2C3C45C(=O)C69C8C7C6C%10C7C8C9%10",
    "CC3C(C(=O)OCC1=CCN2C1C(CC2)OC(=O)C(CC(=O)O3)(C(C)C)O)(C(C)C)O",
    "N#CCC1(CC(O1)C2=CC(=NC2=O)OC)O"
]

drawer = chemdraw.GridDrawer(molecules)
drawer.draw_png("example_2.png")

grid example


Atom, Bond, and Ring Numbers

Atom Numbers (black text)

Bond Numbers (gray text)

Ring Numbers (maroon text)

import chemdraw

mol = "C1(CCC2)=C3C2=CC4=C5C3=C(CCC5CCC4)C=C1"

config = chemdraw.Config()
config.atom_numbers.show = True
config.bond_numbers.show = True
config.ring_numbers.show = True

drawer = chemdraw.Drawer(mol, title=mol, config=config)
fig = drawer.draw()
fig.show()

atom bond example


Ring Highlights

import chemdraw

mol = "C1(CCC2)=C3C2=CC4=C5C3=C(CCC5CCC4)C=C1"

molecule = chemdraw.Molecule(mol)
for ring in molecule.rings:
  ring.highlight.show = True  # all rings are highlighted (with default highlight_color)
  if ring.aromatic:  # highlighted aromatic green
    ring.highlight.color = "rgba(0,255,0,0.5)"

drawer = chemdraw.Drawer(molecule, title=mol)
fig = drawer.draw()
fig.show()

ring highlights


Atom and Bond Highlights

import chemdraw

mol = "C1(CCC2)=C3C2=CC4=C5C3=C(CCC5CCC4)C=C1"

molecule = chemdraw.Molecule(mol)

# highlight outer ring bonds and atoms
bond_ids = [0, 1, 2, 19, 5, 6, 21, 15, 14, 13, 12, 11, 10, 16, 17, 18]
for id_ in bond_ids:
  molecule.bonds[id_].highlight.show = True
for atom in molecule.atoms:
  atom.highlight.show = True

# highlight inner bonds and atoms
accent_color = "rgb(252,186,63)"
molecule.bonds[8].highlight.show = True
molecule.bonds[8].highlight.color = accent_color
molecule.bonds[20].highlight.show = True
molecule.bonds[20].highlight.color = accent_color
atoms_ids = [4, 8, 9]
for id_ in atoms_ids:
  molecule.atoms[id_].highlight.color = accent_color

drawer = chemdraw.Drawer(molecule, title=mol)
fig = drawer.draw()
fig.show()

ring highlights


Polymers

From mole file

import chemdraw

mole_file_name = "ketcher_mol_file.txt"
mol = chemdraw.Molecule(mole_file=mole_file_name)

drawer = chemdraw.Drawer(mol)
fig = drawer.draw()
fig.show()

polymer

Add parenthesis to a SMILES

import chemdraw

mol = chemdraw.Molecule("OC(=O)CCCCC(=O)NCCCCCCN")
mol.add_parenthesis([0, 15], sub_script="n")

drawer = chemdraw.Drawer(mol)
fig = drawer.draw()
fig.show()

polymer2



Mole Files

You can also pass a file path to mole files into 'Molecule'. Support for V2000 only.

import chemdraw

mole_file_name = "examples/mol_files/poly_diblock.txt"
mol = chemdraw.Molecule(mole_file=mole_file_name)

molecule_drawer = chemdraw.Drawer(mol)
fig = molecule_drawer.draw()
fig.show()

More Info

For more information on how the code works see: chemdraw.README.md

Metadata

Release files for chemdraw 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chemdraw 0.0.6
File Size Uploaded
chemdraw-0.0.6.tar.gz 28.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chemdraw 0.0.6
File Interpreter ABI Platform
chemdraw-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 67.0 kB

Release files / chemdraw-0.0.6.tar.gz

Download URL chemdraw-0.0.6.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4f9c57fcb507f5b8ce0b6c3f889f0a9985bd02c3cf6e5564ff44cb87ab1f41a0
BLAKE2b-256 checksum
How to use checksums
850d15d965c93d21c2e311df6456d259867c1effe87f6943b4dec4b011d13a38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / chemdraw-0.0.6-py3-none-any.whl

Download URL chemdraw-0.0.6-py3-none-any.whl
Size 38.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
755639e6a21c575ba928501c096cc35e89e64a7f40ebb6d5b98ea7e2b6ea57c0
BLAKE2b-256 checksum
How to use checksums
3baa023cd5dde95aecf67ee0bb03a48a1ccbb0b4a84f12efb85e333f80d0a4ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page