Skip to main content

cotwo

(like, carbon dioxide)

Render molecules with Plotly.

Installation

pip install cotwo

or

uv add cotwo

Features

  • Read and display structures from XYZ files
  • Read and display structures from SMILES strings
  • Plot smooth isosurfaces from cube files

Usage

Use the "Molecule" class to instanciate an object from either an XYZ file (give the path) or a SMILES string:

from cotwo import Molecule

# From an XYZ file
methane = Molecule.from_file("methane.xyz")

# From an output file
ethanol = Molecule.from_file("ethanol.out")

# From a SMILES string
caffeine = Molecule.from_smiles("CN1C=NC2=C1C(=O)N(C(=O)N2C)C")
# Display a basic 3D visualization of the molecule
caffeine.show()

# Create a Plotly figure
fig = caffeine.create_fig()

The Molecule class can visualize molecular orbitals and spin densities by generating and displaying isosurfaces:

# First, create the cube file for a specific molecular orbital
# (requires orca_plot to be installed)
mo_file = molecule.create_molecular_orbital("calculation.gbw", 42)  # HOMO orbital, for example

# Display the molecule with the molecular orbital isosurface
molecule.show_with_isosurface(
    mo_file,
    isovalue=0.03,  # Adjust the isosurface threshold
    colors=("#FF4081", "#1E88E5"),  # Custom colors for positive/negative phases
)
# Load a molecule from an optimization calculation output
optimized = Molecule.from_file("optimized.xyz")

# Generate and visualize the HOMO-LUMO gap
homo_file = optimized.create_molecular_orbital("calculation.gbw", "42a")  # HOMO
lumo_file = optimized.create_molecular_orbital("calculation.gbw", "43a")  # LUMO

# View HOMO
optimized.show_with_isosurface(homo_file, colors=("#FF4081", "#1E88E5"))

# View LUMO
optimized.show_with_isosurface(lumo_file, colors=("#FF9800", "#2979FF"))

Roadmap

Since creating the meshes and the isosurfaces is computationally heavy, a neat feature would be the possibility to precompute several isosurfaces and keep them in memory. This way multiple densities can be inspected in short succession without the computational overhead.

In the same vein, it would be cool to load a directory and then be able to select from the available .cube files. One could also compute the verticies and faces of the isosurfaces and store them separately, then loading would be much faster. That said, it's kind of beyond the scope of this project - best to keep it lightweigth and focused on only the actual rendering.

Metadata

Release files for cotwo 1.2.0

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

Source distribution (sdist)

Source distribution for cotwo 1.2.0
File Size Uploaded
cotwo-1.2.0.tar.gz 33.3 kB Details

Built distribution (wheel)

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

Total release size: 51.2 kB

Release files / cotwo-1.2.0.tar.gz

Download URL cotwo-1.2.0.tar.gz
Size 33.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d3634958d814bdb30b65f87f577f49bd11113d86379ec1be41f16f615b6960e6
BLAKE2b-256 checksum
How to use checksums
c933b6632985cd2e5922db8b4f38f94256d00726d5ef8afe07d388063b2372d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.20

Release files / cotwo-1.2.0-py3-none-any.whl

Download URL cotwo-1.2.0-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ec622deb69c157055c35aa5d9467604f23355d1ab0b57c4c4c69d2b2ba0cab4
BLAKE2b-256 checksum
How to use checksums
4528886fee999d94a3046af78a5eff593224ac3f11178d5aa2689d5cc4301fa8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.20

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.11

2 release files

1.1.10

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.1

2 release files

0.1.0

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