Molecular structure#

import matplotlib.pyplot as plt
import numpy as np
import py3Dmol
import veloxchem as vlx
from pyscf import gto, scf, tools

The structure of a molecular system can be visualized with py3Dmol, using an xyz-file:

thymine_xyz = """15
*
 C     0.095722    -0.037785    -1.093615
 C    -0.011848     1.408694    -1.113404
 C    -0.204706     2.048475     0.052807
 N    -0.302595     1.390520     1.249226
 C    -0.214596     0.023933     1.378238
 N    -0.017387    -0.607231     0.171757
 O     0.270287    -0.735594    -2.076393
 C     0.098029     2.096194    -2.424990
 H     1.052976     1.874860    -2.891573
 H     0.002157     3.170639    -2.310554
 H    -0.671531     1.743694    -3.104794
 O    -0.301905    -0.554734     2.440234
 H    -0.292790     3.119685     0.106201
 H     0.053626    -1.612452     0.215637
 H    -0.446827     1.892203     2.107092
"""

viewer = py3Dmol.view(width=400, height=300)
# black outline for nicer-looking figures
viewer.setViewStyle({"style": "outline", "color": "black", "width": 0.1})
viewer.addModel(thymine_xyz)
# visualize with the stick option - can also consider spheres and more
viewer.setStyle({"stick": {}})
# rotate for a better initial view
viewer.rotate(-90, "y")
viewer.show()

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol

This creates a dynamic view which can be rotated and zoomed in and out.

Alternatively, PDF-files can be loaded directly from the PDB-library, and illustrated with different models (here looking at an XRD structure of photosystem II):

viewer = py3Dmol.view(
    query="pdb:6W1O", viewergrid=(1, 3), width=800, height=300, linked=False
)
viewer.setStyle({"cartoon": {"color": "spectrum"}}, viewer=(0, 1))
viewer.setStyle({"cartoon": {}}, viewer=(0, 2))
viewer.addStyle({"elem": "Mn"}, {"sphere": {"color": "red"}}, viewer=(0, 2))
viewer.addStyle({"elem": "Ca"}, {"sphere": {"color": "yellow"}}, viewer=(0, 2))
viewer.show()

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol

Here we illustrate this by line structure, and more cartoonish image with and without coloring different strands differently. To the right we see white ribbons with manganese and calcium atoms colored in red and yellow, respectively. These shows the position of the oxygen-evolving complex of photosystem II, which is the site of water-splitting and oxygen generation.