Temperature evolution of the electronic spectra

Temperature evolution of the electronic spectra

A. The cationic Methylene-Pyrene Isomers

This loads the global configuration from the global.json file of the parent directory.

import deMonPy

deMonPy.configure_from_file("../global.json")

This reads the first cationic methylene-pyrene isomer from its XYZ file; mpyren_1 keeps the last image.

from deMonPy.molden import read_XYZ

images, comm = read_XYZ("./data/methylpyren_1.xyz")
mpyren_1 = images[-1]

This optimizes isomer 1 at the SCC-DFTB level with a total charge of +1 (CHARGE), and writes the optimization trajectory.

from deMonPy.deMonNano import deMonNano

WORKDIR = ".run/tutorial-4/A/"

parameters_opt = {
    "DEMON_EXECUTABLE": EXECUTABLE,
    "BASIS": {"PTYPE": "BIO", "SKFILE": BASIS},
    "DEMON_PARAMETERS": {
        "ACTIVE": {"DFTB": {"SCC": True}, "CHARGE": 1.0},
    },
    "DEMON_MODULE": {"ACTIVE": {"OPT": {"MAX": 9999, "OUT": 1, "TRAJECTORY": True}}},
}

dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **parameters_opt)

dem.calculate(symbols=mpyren_1.symbols, positions=mpyren_1.positions)

Uncommented, this opens the optimization trajectory in a molecular viewer.

# view(dem.results["trajectory"])

B. The TD-DFTB

This retrieves the optimized geometry of isomer 1 from the results; it is the structure used for the TD-DFTB calculation that follows.

optimized_geometry_1 = dem.results["output_geometry"]
print("Optimized geometry : ", optimized_geometry_1)

This runs the TD-DFTB (linear-response) calculation on the optimized isomer 1, still at charge +1, to compute its electronic absorption spectrum.

from deMonPy.deMonNano import deMonNano

WORKDIR = ".run/tutorial-4/B/"

parameters_lresp = {
    "DEMON_EXECUTABLE": EXECUTABLE,
    "BASIS": {"PTYPE": "BIO", "SKFILE": BASIS},
    "DEMON_PARAMETERS": {
        "ACTIVE": {"DFTB": {"SCC": True}, "CHARGE": 1.0, "TD-DFTB": True},
    },
}

dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **parameters_lresp)

dem.calculate(symbols=optimized_geometry_1.symbols, positions=optimized_geometry_1.positions)

This stores the singlet and triplet results of the TD-DFTB calculation for isomer 1.

results = dem.results

iso1_singlet = results["singlet"]
iso1_triplet = results["triplet"]

C. Comparison with isomer 2

This reads the second isomer from its XYZ file, the same way as isomer 1.

from deMonPy.molden import read_XYZ

images, comm = read_XYZ("./data/methylpyren_2.xyz")
mpyren_2 = images[-1]

This optimizes isomer 2 with the same parameters_opt dictionary, i.e. SCC-DFTB at charge +1 with the trajectory written.

from deMonPy.deMonNano import deMonNano

WORKDIR = ".run/tutorial-4/C/"

dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **parameters_opt)

dem.calculate(symbols=mpyren_2.symbols, positions=mpyren_2.positions)

optimized_geometry_2 = dem.results["output_geometry"]

This runs the TD-DFTB calculation on the optimized isomer 2 and stores its singlet and triplet results, for the comparison with isomer 1.

dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **parameters_lresp)

dem.calculate(symbols=optimized_geometry_2.symbols, positions=optimized_geometry_2.positions)

results = dem.results

iso2_singlet = results["singlet"]
iso2_triplet = results["triplet"]

This reshapes the singlet spectra of the two isomers into NumPy tables with the w, oscillator, weight and energy columns of each transition, and prints them.

import numpy as np


def transform_to_table(data):
    table = []

    for elm in ["w", "oscillator", "weight", "energy"]:
        table.append([d[elm] for k, d in data.items()])
    return np.array(table).T


tab1 = transform_to_table(iso1_singlet)
tab2 = transform_to_table(iso2_singlet)

print("Singlet table in isomer 1 : \n", tab1)
print("Singlet table in isomer 2 : \n", tab2)

D. Temperature evolution

This defines the parameters for the temperature-evolution run: the TD-DFTB calculation with FRESP set to 10, which makes the response spectrum printed every 10 MD steps, combined with a molecular-dynamics module at 300 K (random velocities, 0.5 fs time step, 100 steps).

print(optimized_geometry_1)

parameters_mdlresp = {
    "DEMON_EXECUTABLE": EXECUTABLE,
    "BASIS": {"PTYPE": "BIO", "SKFILE": BASIS},
    "DEMON_PARAMETERS": {
        "ACTIVE": {"DFTB": {"SCC": True}, "CHARGE": 1, "TD-DFTB": {"FRESP": 10}},
    },
    "DEMON_MODULE": {
        "ACTIVE": {
            "MD": {
                "MDYNAMICS": {
                    "RANDOM": 300,
                },
                "TIMESTEP": 0.5,
                "MDSTEP": {"MAX": 100, "OUT": 1},
                "TRAJECTORY": True,
            }
        }
    },
}

This runs the combined dynamics / TD-DFTB calculation on the optimized isomer 1 and stores the results.

from deMonPy.deMonNano import deMonNano

WORKDIR = ".run/tutorial-4/D/"

dem = deMonNano(title="CALCULATION DEMONANO", workdir=WORKDIR, **parameters_mdlresp)

dem.calculate(symbols=optimized_geometry_1.symbols, positions=optimized_geometry_1.positions)

results = dem.results

This reads the spectrum_final.out file produced by the calculation and plots its two columns against each other — the electronic spectrum shown below.

import os

import matplotlib.pyplot as plt

src = os.path.join(WORKDIR, "spectrum_final.out")

with open(src, "r") as fd:
    lines = fd.readlines()

data = np.array([[float(l.split()[0]), float(l.split()[1])] for l in lines])

plt.plot(data[:, 0], data[:, 1])
plt.show()

Electronic spectrum of cationic methylene-pyrene isomer 1 from the temperature-evolution calculation Electronic spectrum of cationic methylene-pyrene isomer 1 from the temperature-evolution (TD-DFTB) calculation (spectrum_final.out).

Next steps

Tutorial 5 — Monte Carlo exploration closes the tutorial series with the Monte Carlo exploration of molecular clusters, including parallel tempering. The LRESP keyword page documents the linear-response option behind the TD-DFTB spectra, and the DeMonNanoPy Examples section includes a cationic pyrene dimer dissociation profile.