# Chemistry Drawer
---
![PyPI](https://img.shields.io/pypi/v/chemdraw)
![downloads](https://static.pepy.tech/badge/chemdraw)
![license](https://img.shields.io/github/license/dylanwal/chemdraw)
Draw molecules with [Plotly](https://github.com/plotly/plotly.py).
**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](https://pypi.org/project/chemdraw/)
---
---
## Dependencies
* [numpy](https://github.com/numpy/numpy) (1.23.1)
* Used for math
* [plotly](https://github.com/plotly/plotly.py) (5.9.0)
* Plots molecules
* [kaleido](https://github.com/plotly/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](https://github.com/rdkit/rdkit) (2022.3.4)
* Convert SMILES to position coordinates.
* [Pillow](https://github.com/python-pillow/Pillow) (9.2.0)
* Used for image manipulation.
* [scikit-learn](https://github.com/scikit-learn/scikit-learn) (1.1.1)
* Used to reorient molecules.
---
---
# Examples:
(Image may be distorted from viewer, but real image is not.)
## Basic Usage
```python
import chemdraw
mol = "O=C(C)Oc1ccccc1C(=O)O"
drawer = chemdraw.Drawer(mol, title=mol)
fig = drawer.draw()
fig.show()
```
![simple example](./examples/imgs/simple.svg)
---
## Grid
```python
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](./examples/imgs/grid.png)
---
## Atom, Bond, and Ring Numbers
Atom Numbers (black text)
Bond Numbers (gray text)
Ring Numbers (maroon text)
```python
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](./examples/imgs/atom_bond_numbers.svg)
---
## Ring Highlights
```python
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](./examples/imgs/ring_highlights.svg)
---
## Atom and Bond Highlights
```python
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](./examples/imgs/highlights.svg)
---
## Polymers
From mole file
```python
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](./examples/imgs/polymer.svg)
Add parenthesis to a SMILES
```python
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](./examples/imgs/polymer2.svg)
---
---
# Mole Files
You can also pass a file path to mole files into 'Molecule'.
Support for V2000 only.
```python
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](https://github.com/dylanwal/chemdraw/tree/master/chemdraw)
Raw data
{
"_id": null,
"home_page": "https://github.com/dylanwal/chemdraw",
"name": "chemdraw",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Dylan Walsh",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/85/0d/15d965c93d21c2e311df6456d259867c1effe87f6943b4dec4b011d13a38/chemdraw-0.0.6.tar.gz",
"platform": "any",
"description": "# Chemistry Drawer\r\n\r\n---\r\n\r\n![PyPI](https://img.shields.io/pypi/v/chemdraw)\r\n![downloads](https://static.pepy.tech/badge/chemdraw)\r\n![license](https://img.shields.io/github/license/dylanwal/chemdraw)\r\n\r\nDraw molecules with [Plotly](https://github.com/plotly/plotly.py).\r\n\r\n**Make molecules look the way you want it!**\r\n\r\nThe package provides global control of aesthetics with `config`, and allows for local control by specifying details \r\nfor every atom, bond, and ring.\r\n\r\n\r\n(Development still in progress. So there are some bugs. But its working pretty well so far!)\r\n\r\n---\r\n\r\n## Installation\r\n\r\nPip installable package available.\r\n\r\n`pip install chemdraw`\r\n\r\n[pypi: chemdraw](https://pypi.org/project/chemdraw/)\r\n\r\n---\r\n---\r\n\r\n## Dependencies\r\n\r\n* [numpy](https://github.com/numpy/numpy) (1.23.1)\r\n * Used for math\r\n* [plotly](https://github.com/plotly/plotly.py) (5.9.0)\r\n * Plots molecules\r\n* [kaleido](https://github.com/plotly/Kaleido) (0.1.0post1)\r\n * Converts plotly graphs to images (png, svg, etc.)\r\n * I am not using the most recent version of kaleido as it does not play nice with my computer. Try the newest \r\n version, but if you are having issues install this specific version. \r\n* [rdkit](https://github.com/rdkit/rdkit) (2022.3.4)\r\n * Convert SMILES to position coordinates.\r\n* [Pillow](https://github.com/python-pillow/Pillow) (9.2.0)\r\n * Used for image manipulation.\r\n* [scikit-learn](https://github.com/scikit-learn/scikit-learn) (1.1.1)\r\n * Used to reorient molecules.\r\n\r\n---\r\n---\r\n\r\n# Examples:\r\n(Image may be distorted from viewer, but real image is not.)\r\n\r\n\r\n## Basic Usage\r\n```python\r\nimport chemdraw\r\n\r\nmol = \"O=C(C)Oc1ccccc1C(=O)O\"\r\ndrawer = chemdraw.Drawer(mol, title=mol)\r\nfig = drawer.draw()\r\nfig.show()\r\n```\r\n\r\n![simple example](./examples/imgs/simple.svg)\r\n\r\n---\r\n## Grid\r\n\r\n\r\n```python\r\nimport chemdraw\r\n\r\nmolecules = [\r\n \"CCCCCCCCCC\",\r\n \"CC(CC(CCC)C)CC\",\r\n \"CCC1CC1\",\r\n \"C([C@@H]1[C@H]([C@@H]([C@H]([C@H](O1)O)O)O)O)O\",\r\n \"O=C(C)Oc1ccccc1C(=O)O\",\r\n \"C1(CCC2)=C3C2=CC4=C5C3=C(CCC5CCC4)C=C1\",\r\n \"CC(C)(C)N(C)C(=O)C14C3C2C1C5C2C3C45C(=O)C69C8C7C6C%10C7C8C9%10\",\r\n \"CC3C(C(=O)OCC1=CCN2C1C(CC2)OC(=O)C(CC(=O)O3)(C(C)C)O)(C(C)C)O\",\r\n \"N#CCC1(CC(O1)C2=CC(=NC2=O)OC)O\"\r\n]\r\n\r\ndrawer = chemdraw.GridDrawer(molecules)\r\ndrawer.draw_png(\"example_2.png\")\r\n```\r\n\r\n![grid example](./examples/imgs/grid.png)\r\n\r\n---\r\n\r\n## Atom, Bond, and Ring Numbers\r\n\r\nAtom Numbers (black text) \r\n\r\nBond Numbers (gray text)\r\n\r\nRing Numbers (maroon text)\r\n\r\n```python\r\nimport chemdraw\r\n\r\nmol = \"C1(CCC2)=C3C2=CC4=C5C3=C(CCC5CCC4)C=C1\"\r\n\r\nconfig = chemdraw.Config()\r\nconfig.atom_numbers.show = True\r\nconfig.bond_numbers.show = True\r\nconfig.ring_numbers.show = True\r\n\r\ndrawer = chemdraw.Drawer(mol, title=mol, config=config)\r\nfig = drawer.draw()\r\nfig.show()\r\n\r\n```\r\n\r\n\r\n![atom bond example](./examples/imgs/atom_bond_numbers.svg)\r\n\r\n\r\n---\r\n\r\n## Ring Highlights\r\n\r\n```python\r\nimport chemdraw\r\n\r\nmol = \"C1(CCC2)=C3C2=CC4=C5C3=C(CCC5CCC4)C=C1\"\r\n\r\nmolecule = chemdraw.Molecule(mol)\r\nfor ring in molecule.rings:\r\n ring.highlight.show = True # all rings are highlighted (with default highlight_color)\r\n if ring.aromatic: # highlighted aromatic green\r\n ring.highlight.color = \"rgba(0,255,0,0.5)\"\r\n\r\ndrawer = chemdraw.Drawer(molecule, title=mol)\r\nfig = drawer.draw()\r\nfig.show()\r\n\r\n```\r\n\r\n![ring highlights](./examples/imgs/ring_highlights.svg)\r\n\r\n\r\n---\r\n## Atom and Bond Highlights\r\n\r\n```python\r\nimport chemdraw\r\n\r\nmol = \"C1(CCC2)=C3C2=CC4=C5C3=C(CCC5CCC4)C=C1\"\r\n\r\nmolecule = chemdraw.Molecule(mol)\r\n\r\n# highlight outer ring bonds and atoms\r\nbond_ids = [0, 1, 2, 19, 5, 6, 21, 15, 14, 13, 12, 11, 10, 16, 17, 18]\r\nfor id_ in bond_ids:\r\n molecule.bonds[id_].highlight.show = True\r\nfor atom in molecule.atoms:\r\n atom.highlight.show = True\r\n\r\n# highlight inner bonds and atoms\r\naccent_color = \"rgb(252,186,63)\"\r\nmolecule.bonds[8].highlight.show = True\r\nmolecule.bonds[8].highlight.color = accent_color\r\nmolecule.bonds[20].highlight.show = True\r\nmolecule.bonds[20].highlight.color = accent_color\r\natoms_ids = [4, 8, 9]\r\nfor id_ in atoms_ids:\r\n molecule.atoms[id_].highlight.color = accent_color\r\n\r\ndrawer = chemdraw.Drawer(molecule, title=mol)\r\nfig = drawer.draw()\r\nfig.show()\r\n```\r\n\r\n![ring highlights](./examples/imgs/highlights.svg)\r\n\r\n---\r\n## Polymers\r\n\r\nFrom mole file\r\n```python\r\nimport chemdraw\r\n\r\nmole_file_name = \"ketcher_mol_file.txt\"\r\nmol = chemdraw.Molecule(mole_file=mole_file_name)\r\n\r\ndrawer = chemdraw.Drawer(mol)\r\nfig = drawer.draw()\r\nfig.show()\r\n```\r\n\r\n![polymer](./examples/imgs/polymer.svg)\r\n\r\n\r\nAdd parenthesis to a SMILES\r\n\r\n```python\r\nimport chemdraw\r\n\r\nmol = chemdraw.Molecule(\"OC(=O)CCCCC(=O)NCCCCCCN\")\r\nmol.add_parenthesis([0, 15], sub_script=\"n\")\r\n\r\ndrawer = chemdraw.Drawer(mol)\r\nfig = drawer.draw()\r\nfig.show()\r\n```\r\n\r\n![polymer2](./examples/imgs/polymer2.svg)\r\n\r\n---\r\n---\r\n\r\n# Mole Files\r\n\r\nYou can also pass a file path to mole files into 'Molecule'. \r\nSupport for V2000 only.\r\n\r\n```python\r\nimport chemdraw\r\n\r\nmole_file_name = \"examples/mol_files/poly_diblock.txt\"\r\nmol = chemdraw.Molecule(mole_file=mole_file_name)\r\n\r\nmolecule_drawer = chemdraw.Drawer(mol)\r\nfig = molecule_drawer.draw()\r\nfig.show()\r\n```\r\n\r\n\r\n# More Info\r\n\r\nFor more information on how the code works see: \r\n[chemdraw.README.md](https://github.com/dylanwal/chemdraw/tree/master/chemdraw) \r\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Drawing molecules",
"version": "0.0.6",
"project_urls": {
"Homepage": "https://github.com/dylanwal/chemdraw"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3baa023cd5dde95aecf67ee0bb03a48a1ccbb0b4a84f12efb85e333f80d0a4ed",
"md5": "7534933b87253918137ffe0b3480ba61",
"sha256": "755639e6a21c575ba928501c096cc35e89e64a7f40ebb6d5b98ea7e2b6ea57c0"
},
"downloads": -1,
"filename": "chemdraw-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7534933b87253918137ffe0b3480ba61",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 38111,
"upload_time": "2024-08-27T14:54:07",
"upload_time_iso_8601": "2024-08-27T14:54:07.462827Z",
"url": "https://files.pythonhosted.org/packages/3b/aa/023cd5dde95aecf67ee0bb03a48a1ccbb0b4a84f12efb85e333f80d0a4ed/chemdraw-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "850d15d965c93d21c2e311df6456d259867c1effe87f6943b4dec4b011d13a38",
"md5": "cf01cf889465d1e357bec8093408621a",
"sha256": "4f9c57fcb507f5b8ce0b6c3f889f0a9985bd02c3cf6e5564ff44cb87ab1f41a0"
},
"downloads": -1,
"filename": "chemdraw-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "cf01cf889465d1e357bec8093408621a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 28842,
"upload_time": "2024-08-27T14:54:08",
"upload_time_iso_8601": "2024-08-27T14:54:08.736314Z",
"url": "https://files.pythonhosted.org/packages/85/0d/15d965c93d21c2e311df6456d259867c1effe87f6943b4dec4b011d13a38/chemdraw-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-27 14:54:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dylanwal",
"github_project": "chemdraw",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "chemdraw"
}