Skip to main content

Simple visualizer for molecules and isosurfaces with Plotly

Project description

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.

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

cotwo-1.1.1.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

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

cotwo-1.1.1-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file cotwo-1.1.1.tar.gz.

File metadata

  • Download URL: cotwo-1.1.1.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.20

File hashes

Hashes for cotwo-1.1.1.tar.gz
Algorithm Hash digest
SHA256 0be577cbcbab12f66cb29df88d1874eb02e64238147441f74382229c76f43276
MD5 c70adcf99b5bfe2dd1bc4072987dd8b0
BLAKE2b-256 d9b5f68b6b3552fdfb2368962c31645f200915dd2453537a9f081e5a1f3670d6

See more details on using hashes here.

File details

Details for the file cotwo-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: cotwo-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.20

File hashes

Hashes for cotwo-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 402c0c9b15b59455bd325e5e9c70e5ba50b1c49915c523a2bffa13b982ef2aa8
MD5 722065c38ba54a311194f5f94b4d6928
BLAKE2b-256 8115007e9cb4bfbf593720bc123055ee456420c0c6ff053d1f57047492e28f48

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