Skip to main content

Drawing molecules

Project description

ChemDraw


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



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",
    "O1CCCCC1C",
    "C1=CC=CC=C1C",
    "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")

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.DrawerConfig()
config.atom_numbers.show = True
config.bond_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"

config = chemdraw.DrawerConfig()
config.ring_highlights.show = True

molecule = chemdraw.Molecule(mol)
for ring in molecule.rings:
  ring.highlight = 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, config=config)
fig = drawer.draw()
fig.show()

ring highlights


Atom and Bond Highlights

import chemdraw

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

config = chemdraw.DrawerConfig()
config.highlights.show = True

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 = True
for atom in molecule.atoms:
    atom.highlight = True

# highlight inner bonds and atoms
accent_color = "rgb(252,186,63)"
molecule.bonds[8].highlight = True
molecule.bonds[8].highlight_color = accent_color
molecule.bonds[20].highlight = 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, config=config)
fig = drawer.draw()
fig.show()

ring highlights

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chemdraw-0.0.3.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chemdraw-0.0.3-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file chemdraw-0.0.3.tar.gz.

File metadata

  • Download URL: chemdraw-0.0.3.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for chemdraw-0.0.3.tar.gz
Algorithm Hash digest
SHA256 92c985a7f4b64405b47b987ebcd125b0029e12a7959e3e9b5fd478cd472718a6
MD5 12cf3374b2f664ffa4834dd0268ad0c2
BLAKE2b-256 0766d52d47cc3a080edeefa0a9b63951fb849bc3453e771f2501a17f81911c0a

See more details on using hashes here.

File details

Details for the file chemdraw-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: chemdraw-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for chemdraw-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5d9452265840cae1b866d64481286992a3f21a017dbe82b993d091a9ed0defc6
MD5 d8108e24339ec5f6a414355180ad559a
BLAKE2b-256 6aa5ab7698147cffba4a21276ed42163edd72baa2bd7eb53f9ddc29aa7fb7c78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page