Skip to content

UV Vis Absorption Spectrum🔗

scripts.spectra 🔗

Written by Rob Parrish

This script reads TeraChem TDDFT and/or FOMO output files and automatically plots absorption spectra.

Each individual excited state is given a color, with the overall spectrum plotted in black on top.

The script includes options to plot with Lorentzian or Gaussian broadening. To change it, modify the plot_spectra function to change:

Ostate += spectrum[state, 1] * lorentzian(E, spectrum[state, 0], delta)

to

Ostate += spectrum[state, 1] * gaussian(E, spectrum[state, 0], delta)

It also includes options to plot in eV or nm, with plot_spectra or plot_spectra_nm respectively.

Modify the following code block with appropriate paths for your system, choice of fomo or tddft for read_*_output, and choice of eV of nm for plot_*.

filenames = glob.glob("/path/to/*/filename*.out")
spectra = [read_fomo_outfile(x) for x in filenames]
spectra = [x for x in spectra if x is not None]
plot_spectra("spectra.pdf", spectra, E=np.linspace(5.0, 9.0, 1000), delta=0.10)

gaussian(x, x0, delta) 🔗

Source code in scripts/spectra.py
def gaussian(x, x0, delta):
    return np.exp(-np.power(x - x0, 2.0) / (2 * np.power(delta, 2.0)))

lorentzian(x, x0, delta) 🔗

Source code in scripts/spectra.py
def lorentzian(
    x,
    x0,
    delta,
):

    return 0.5 * delta / np.pi * 1.0 / ((x - x0) ** 2 + (0.5 * delta) ** 2)

plot_spectra(filename, spectra, E = array([3.5 , 3.5035035 , 3.50700701, 3.51051051, 3.51401401,3.51751752, 3.52102102, 3.52452452, 3.52802803, 3.53153153,3.53503504, 3.53853854, 3.54204204, 3.54554555, 3.54904905,3.55255255, 3.55605606, 3.55955956, 3.56306306, 3.56656657,3.57007007, 3.57357357, 3.57707708, 3.58058058, 3.58408408,3.58758759, 3.59109109, 3.59459459, 3.5980981 , 3.6016016 ,3.60510511, 3.60860861, 3.61211211, 3.61561562, 3.61911912,3.62262262, 3.62612613, 3.62962963, 3.63313313, 3.63663664,3.64014014, 3.64364364, 3.64714715, 3.65065065, 3.65415415,3.65765766, 3.66116116, 3.66466466, 3.66816817, 3.67167167,3.67517518, 3.67867868, 3.68218218, 3.68568569, 3.68918919,3.69269269, 3.6961962 , 3.6996997 , 3.7032032 , 3.70670671,3.71021021, 3.71371371, 3.71721722, 3.72072072, 3.72422422,3.72772773, 3.73123123, 3.73473473, 3.73823824, 3.74174174,3.74524525, 3.74874875, 3.75225225, 3.75575576, 3.75925926,3.76276276, 3.76626627, 3.76976977, 3.77327327, 3.77677678,3.78028028, 3.78378378, 3.78728729, 3.79079079, 3.79429429,3.7977978 , 3.8013013 , 3.8048048 , 3.80830831, 3.81181181,3.81531532, 3.81881882, 3.82232232, 3.82582583, 3.82932933,3.83283283, 3.83633634, 3.83983984, 3.84334334, 3.84684685,3.85035035, 3.85385385, 3.85735736, 3.86086086, 3.86436436,3.86786787, 3.87137137, 3.87487487, 3.87837838, 3.88188188,3.88538539, 3.88888889, 3.89239239, 3.8958959 , 3.8993994 ,3.9029029 , 3.90640641, 3.90990991, 3.91341341, 3.91691692,3.92042042, 3.92392392, 3.92742743, 3.93093093, 3.93443443,3.93793794, 3.94144144, 3.94494494, 3.94844845, 3.95195195,3.95545546, 3.95895896, 3.96246246, 3.96596597, 3.96946947,3.97297297, 3.97647648, 3.97997998, 3.98348348, 3.98698699,3.99049049, 3.99399399, 3.9974975 , 4.001001 , 4.0045045 ,4.00800801, 4.01151151, 4.01501502, 4.01851852, 4.02202202,4.02552553, 4.02902903, 4.03253253, 4.03603604, 4.03953954,4.04304304, 4.04654655, 4.05005005, 4.05355355, 4.05705706,4.06056056, 4.06406406, 4.06756757, 4.07107107, 4.07457457,4.07807808, 4.08158158, 4.08508509, 4.08858859, 4.09209209,4.0955956 , 4.0990991 , 4.1026026 , 4.10610611, 4.10960961,4.11311311, 4.11661662, 4.12012012, 4.12362362, 4.12712713,4.13063063, 4.13413413, 4.13763764, 4.14114114, 4.14464464,4.14814815, 4.15165165, 4.15515516, 4.15865866, 4.16216216,4.16566567, 4.16916917, 4.17267267, 4.17617618, 4.17967968,4.18318318, 4.18668669, 4.19019019, 4.19369369, 4.1971972 ,4.2007007 , 4.2042042 , 4.20770771, 4.21121121, 4.21471471,4.21821822, 4.22172172, 4.22522523, 4.22872873, 4.23223223,4.23573574, 4.23923924, 4.24274274, 4.24624625, 4.24974975,4.25325325, 4.25675676, 4.26026026, 4.26376376, 4.26726727,4.27077077, 4.27427427, 4.27777778, 4.28128128, 4.28478478,4.28828829, 4.29179179, 4.2952953 , 4.2987988 , 4.3023023 ,4.30580581, 4.30930931, 4.31281281, 4.31631632, 4.31981982,4.32332332, 4.32682683, 4.33033033, 4.33383383, 4.33733734,4.34084084, 4.34434434, 4.34784785, 4.35135135, 4.35485485,4.35835836, 4.36186186, 4.36536537, 4.36886887, 4.37237237,4.37587588, 4.37937938, 4.38288288, 4.38638639, 4.38988989,4.39339339, 4.3968969 , 4.4004004 , 4.4039039 , 4.40740741,4.41091091, 4.41441441, 4.41791792, 4.42142142, 4.42492492,4.42842843, 4.43193193, 4.43543544, 4.43893894, 4.44244244,4.44594595, 4.44944945, 4.45295295, 4.45645646, 4.45995996,4.46346346, 4.46696697, 4.47047047, 4.47397397, 4.47747748,4.48098098, 4.48448448, 4.48798799, 4.49149149, 4.49499499,4.4984985 , 4.502002 , 4.50550551, 4.50900901, 4.51251251,4.51601602, 4.51951952, 4.52302302, 4.52652653, 4.53003003,4.53353353, 4.53703704, 4.54054054, 4.54404404, 4.54754755,4.55105105, 4.55455455, 4.55805806, 4.56156156, 4.56506507,4.56856857, 4.57207207, 4.57557558, 4.57907908, 4.58258258,4.58608609, 4.58958959, 4.59309309, 4.5965966 , 4.6001001 ,4.6036036 , 4.60710711, 4.61061061, 4.61411411, 4.61761762,4.62112112, 4.62462462, 4.62812813, 4.63163163, 4.63513514,4.63863864, 4.64214214, 4.64564565, 4.64914915, 4.65265265,4.65615616, 4.65965966, 4.66316316, 4.66666667, 4.67017017,4.67367367, 4.67717718, 4.68068068, 4.68418418, 4.68768769,4.69119119, 4.69469469, 4.6981982 , 4.7017017 , 4.70520521,4.70870871, 4.71221221, 4.71571572, 4.71921922, 4.72272272,4.72622623, 4.72972973, 4.73323323, 4.73673674, 4.74024024,4.74374374, 4.74724725, 4.75075075, 4.75425425, 4.75775776,4.76126126, 4.76476476, 4.76826827, 4.77177177, 4.77527528,4.77877878, 4.78228228, 4.78578579, 4.78928929, 4.79279279,4.7962963 , 4.7997998 , 4.8033033 , 4.80680681, 4.81031031,4.81381381, 4.81731732, 4.82082082, 4.82432432, 4.82782783,4.83133133, 4.83483483, 4.83833834, 4.84184184, 4.84534535,4.84884885, 4.85235235, 4.85585586, 4.85935936, 4.86286286,4.86636637, 4.86986987, 4.87337337, 4.87687688, 4.88038038,4.88388388, 4.88738739, 4.89089089, 4.89439439, 4.8978979 ,4.9014014 , 4.9049049 , 4.90840841, 4.91191191, 4.91541542,4.91891892, 4.92242242, 4.92592593, 4.92942943, 4.93293293,4.93643644, 4.93993994, 4.94344344, 4.94694695, 4.95045045,4.95395395, 4.95745746, 4.96096096, 4.96446446, 4.96796797,4.97147147, 4.97497497, 4.97847848, 4.98198198, 4.98548549,4.98898899, 4.99249249, 4.995996 , 4.9994995 , 5.003003 ,5.00650651, 5.01001001, 5.01351351, 5.01701702, 5.02052052,5.02402402, 5.02752753, 5.03103103, 5.03453453, 5.03803804,5.04154154, 5.04504505, 5.04854855, 5.05205205, 5.05555556,5.05905906, 5.06256256, 5.06606607, 5.06956957, 5.07307307,5.07657658, 5.08008008, 5.08358358, 5.08708709, 5.09059059,5.09409409, 5.0975976 , 5.1011011 , 5.1046046 , 5.10810811,5.11161161, 5.11511512, 5.11861862, 5.12212212, 5.12562563,5.12912913, 5.13263263, 5.13613614, 5.13963964, 5.14314314,5.14664665, 5.15015015, 5.15365365, 5.15715716, 5.16066066,5.16416416, 5.16766767, 5.17117117, 5.17467467, 5.17817818,5.18168168, 5.18518519, 5.18868869, 5.19219219, 5.1956957 ,5.1991992 , 5.2027027 , 5.20620621, 5.20970971, 5.21321321,5.21671672, 5.22022022, 5.22372372, 5.22722723, 5.23073073,5.23423423, 5.23773774, 5.24124124, 5.24474474, 5.24824825,5.25175175, 5.25525526, 5.25875876, 5.26226226, 5.26576577,5.26926927, 5.27277277, 5.27627628, 5.27977978, 5.28328328,5.28678679, 5.29029029, 5.29379379, 5.2972973 , 5.3008008 ,5.3043043 , 5.30780781, 5.31131131, 5.31481481, 5.31831832,5.32182182, 5.32532533, 5.32882883, 5.33233233, 5.33583584,5.33933934, 5.34284284, 5.34634635, 5.34984985, 5.35335335,5.35685686, 5.36036036, 5.36386386, 5.36736737, 5.37087087,5.37437437, 5.37787788, 5.38138138, 5.38488488, 5.38838839,5.39189189, 5.3953954 , 5.3988989 , 5.4024024 , 5.40590591,5.40940941, 5.41291291, 5.41641642, 5.41991992, 5.42342342,5.42692693, 5.43043043, 5.43393393, 5.43743744, 5.44094094,5.44444444, 5.44794795, 5.45145145, 5.45495495, 5.45845846,5.46196196, 5.46546547, 5.46896897, 5.47247247, 5.47597598,5.47947948, 5.48298298, 5.48648649, 5.48998999, 5.49349349,5.496997 , 5.5005005 , 5.504004 , 5.50750751, 5.51101101,5.51451451, 5.51801802, 5.52152152, 5.52502503, 5.52852853,5.53203203, 5.53553554, 5.53903904, 5.54254254, 5.54604605,5.54954955, 5.55305305, 5.55655656, 5.56006006, 5.56356356,5.56706707, 5.57057057, 5.57407407, 5.57757758, 5.58108108,5.58458458, 5.58808809, 5.59159159, 5.5950951 , 5.5985986 ,5.6021021 , 5.60560561, 5.60910911, 5.61261261, 5.61611612,5.61961962, 5.62312312, 5.62662663, 5.63013013, 5.63363363,5.63713714, 5.64064064, 5.64414414, 5.64764765, 5.65115115,5.65465465, 5.65815816, 5.66166166, 5.66516517, 5.66866867,5.67217217, 5.67567568, 5.67917918, 5.68268268, 5.68618619,5.68968969, 5.69319319, 5.6966967 , 5.7002002 , 5.7037037 ,5.70720721, 5.71071071, 5.71421421, 5.71771772, 5.72122122,5.72472472, 5.72822823, 5.73173173, 5.73523524, 5.73873874,5.74224224, 5.74574575, 5.74924925, 5.75275275, 5.75625626,5.75975976, 5.76326326, 5.76676677, 5.77027027, 5.77377377,5.77727728, 5.78078078, 5.78428428, 5.78778779, 5.79129129,5.79479479, 5.7982983 , 5.8018018 , 5.80530531, 5.80880881,5.81231231, 5.81581582, 5.81931932, 5.82282282, 5.82632633,5.82982983, 5.83333333, 5.83683684, 5.84034034, 5.84384384,5.84734735, 5.85085085, 5.85435435, 5.85785786, 5.86136136,5.86486486, 5.86836837, 5.87187187, 5.87537538, 5.87887888,5.88238238, 5.88588589, 5.88938939, 5.89289289, 5.8963964 ,5.8998999 , 5.9034034 , 5.90690691, 5.91041041, 5.91391391,5.91741742, 5.92092092, 5.92442442, 5.92792793, 5.93143143,5.93493493, 5.93843844, 5.94194194, 5.94544545, 5.94894895,5.95245245, 5.95595596, 5.95945946, 5.96296296, 5.96646647,5.96996997, 5.97347347, 5.97697698, 5.98048048, 5.98398398,5.98748749, 5.99099099, 5.99449449, 5.997998 , 6.0015015 ,6.00500501, 6.00850851, 6.01201201, 6.01551552, 6.01901902,6.02252252, 6.02602603, 6.02952953, 6.03303303, 6.03653654,6.04004004, 6.04354354, 6.04704705, 6.05055055, 6.05405405,6.05755756, 6.06106106, 6.06456456, 6.06806807, 6.07157157,6.07507508, 6.07857858, 6.08208208, 6.08558559, 6.08908909,6.09259259, 6.0960961 , 6.0995996 , 6.1031031 , 6.10660661,6.11011011, 6.11361361, 6.11711712, 6.12062062, 6.12412412,6.12762763, 6.13113113, 6.13463463, 6.13813814, 6.14164164,6.14514515, 6.14864865, 6.15215215, 6.15565566, 6.15915916,6.16266266, 6.16616617, 6.16966967, 6.17317317, 6.17667668,6.18018018, 6.18368368, 6.18718719, 6.19069069, 6.19419419,6.1976977 , 6.2012012 , 6.2047047 , 6.20820821, 6.21171171,6.21521522, 6.21871872, 6.22222222, 6.22572573, 6.22922923,6.23273273, 6.23623624, 6.23973974, 6.24324324, 6.24674675,6.25025025, 6.25375375, 6.25725726, 6.26076076, 6.26426426,6.26776777, 6.27127127, 6.27477477, 6.27827828, 6.28178178,6.28528529, 6.28878879, 6.29229229, 6.2957958 , 6.2992993 ,6.3028028 , 6.30630631, 6.30980981, 6.31331331, 6.31681682,6.32032032, 6.32382382, 6.32732733, 6.33083083, 6.33433433,6.33783784, 6.34134134, 6.34484484, 6.34834835, 6.35185185,6.35535536, 6.35885886, 6.36236236, 6.36586587, 6.36936937,6.37287287, 6.37637638, 6.37987988, 6.38338338, 6.38688689,6.39039039, 6.39389389, 6.3973974 , 6.4009009 , 6.4044044 ,6.40790791, 6.41141141, 6.41491491, 6.41841842, 6.42192192,6.42542543, 6.42892893, 6.43243243, 6.43593594, 6.43943944,6.44294294, 6.44644645, 6.44994995, 6.45345345, 6.45695696,6.46046046, 6.46396396, 6.46746747, 6.47097097, 6.47447447,6.47797798, 6.48148148, 6.48498498, 6.48848849, 6.49199199,6.4954955 , 6.498999 , 6.5025025 , 6.50600601, 6.50950951,6.51301301, 6.51651652, 6.52002002, 6.52352352, 6.52702703,6.53053053, 6.53403403, 6.53753754, 6.54104104, 6.54454454,6.54804805, 6.55155155, 6.55505506, 6.55855856, 6.56206206,6.56556557, 6.56906907, 6.57257257, 6.57607608, 6.57957958,6.58308308, 6.58658659, 6.59009009, 6.59359359, 6.5970971 ,6.6006006 , 6.6041041 , 6.60760761, 6.61111111, 6.61461461,6.61811812, 6.62162162, 6.62512513, 6.62862863, 6.63213213,6.63563564, 6.63913914, 6.64264264, 6.64614615, 6.64964965,6.65315315, 6.65665666, 6.66016016, 6.66366366, 6.66716717,6.67067067, 6.67417417, 6.67767768, 6.68118118, 6.68468468,6.68818819, 6.69169169, 6.6951952 , 6.6986987 , 6.7022022 ,6.70570571, 6.70920921, 6.71271271, 6.71621622, 6.71971972,6.72322322, 6.72672673, 6.73023023, 6.73373373, 6.73723724,6.74074074, 6.74424424, 6.74774775, 6.75125125, 6.75475475,6.75825826, 6.76176176, 6.76526527, 6.76876877, 6.77227227,6.77577578, 6.77927928, 6.78278278, 6.78628629, 6.78978979,6.79329329, 6.7967968 , 6.8003003 , 6.8038038 , 6.80730731,6.81081081, 6.81431431, 6.81781782, 6.82132132, 6.82482482,6.82832833, 6.83183183, 6.83533534, 6.83883884, 6.84234234,6.84584585, 6.84934935, 6.85285285, 6.85635636, 6.85985986,6.86336336, 6.86686687, 6.87037037, 6.87387387, 6.87737738,6.88088088, 6.88438438, 6.88788789, 6.89139139, 6.89489489,6.8983984 , 6.9019019 , 6.90540541, 6.90890891, 6.91241241,6.91591592, 6.91941942, 6.92292292, 6.92642643, 6.92992993,6.93343343, 6.93693694, 6.94044044, 6.94394394, 6.94744745,6.95095095, 6.95445445, 6.95795796, 6.96146146, 6.96496496,6.96846847, 6.97197197, 6.97547548, 6.97897898, 6.98248248,6.98598599, 6.98948949, 6.99299299, 6.9964965 , 7. ]), delta = 0.05) 🔗

Source code in scripts/spectra.py
def plot_spectra(
    filename,
    spectra,
    E=np.linspace(3.5, 7.0, 1000),
    delta=0.05,
):

    Nspectra = len(spectra)
    Nstate = spectra[0].shape[0]

    Ostates = []
    for state in range(Nstate):
        Ostate = np.zeros_like(E)
        for spectrum in spectra:
            Ostate += spectrum[state, 1] * lorentzian(E, spectrum[state, 0], delta)
        Ostate /= Nspectra
        Ostates.append(Ostate)

    Ototal = np.zeros_like(E)
    for Ostate in Ostates:
        Ototal += Ostate

    cmap = matplotlib.cm.get_cmap("jet")
    colors = [cmap(float(x) / (Nstate - 1)) for x in reversed(list(range(Nstate)))]

    plt.clf()
    for Oind, Ostate in enumerate(Ostates):
        plt.plot(E, Ostate, color=colors[Oind])

    plt.plot(E, Ototal, "-k")
    plt.xlabel(r"$\Delta E$ [eV]")
    plt.ylabel("Cross Section [-]")
    plt.savefig(filename)

plot_spectra_nm(filename, spectra, E = array([3.5 , 3.5035035 , 3.50700701, 3.51051051, 3.51401401,3.51751752, 3.52102102, 3.52452452, 3.52802803, 3.53153153,3.53503504, 3.53853854, 3.54204204, 3.54554555, 3.54904905,3.55255255, 3.55605606, 3.55955956, 3.56306306, 3.56656657,3.57007007, 3.57357357, 3.57707708, 3.58058058, 3.58408408,3.58758759, 3.59109109, 3.59459459, 3.5980981 , 3.6016016 ,3.60510511, 3.60860861, 3.61211211, 3.61561562, 3.61911912,3.62262262, 3.62612613, 3.62962963, 3.63313313, 3.63663664,3.64014014, 3.64364364, 3.64714715, 3.65065065, 3.65415415,3.65765766, 3.66116116, 3.66466466, 3.66816817, 3.67167167,3.67517518, 3.67867868, 3.68218218, 3.68568569, 3.68918919,3.69269269, 3.6961962 , 3.6996997 , 3.7032032 , 3.70670671,3.71021021, 3.71371371, 3.71721722, 3.72072072, 3.72422422,3.72772773, 3.73123123, 3.73473473, 3.73823824, 3.74174174,3.74524525, 3.74874875, 3.75225225, 3.75575576, 3.75925926,3.76276276, 3.76626627, 3.76976977, 3.77327327, 3.77677678,3.78028028, 3.78378378, 3.78728729, 3.79079079, 3.79429429,3.7977978 , 3.8013013 , 3.8048048 , 3.80830831, 3.81181181,3.81531532, 3.81881882, 3.82232232, 3.82582583, 3.82932933,3.83283283, 3.83633634, 3.83983984, 3.84334334, 3.84684685,3.85035035, 3.85385385, 3.85735736, 3.86086086, 3.86436436,3.86786787, 3.87137137, 3.87487487, 3.87837838, 3.88188188,3.88538539, 3.88888889, 3.89239239, 3.8958959 , 3.8993994 ,3.9029029 , 3.90640641, 3.90990991, 3.91341341, 3.91691692,3.92042042, 3.92392392, 3.92742743, 3.93093093, 3.93443443,3.93793794, 3.94144144, 3.94494494, 3.94844845, 3.95195195,3.95545546, 3.95895896, 3.96246246, 3.96596597, 3.96946947,3.97297297, 3.97647648, 3.97997998, 3.98348348, 3.98698699,3.99049049, 3.99399399, 3.9974975 , 4.001001 , 4.0045045 ,4.00800801, 4.01151151, 4.01501502, 4.01851852, 4.02202202,4.02552553, 4.02902903, 4.03253253, 4.03603604, 4.03953954,4.04304304, 4.04654655, 4.05005005, 4.05355355, 4.05705706,4.06056056, 4.06406406, 4.06756757, 4.07107107, 4.07457457,4.07807808, 4.08158158, 4.08508509, 4.08858859, 4.09209209,4.0955956 , 4.0990991 , 4.1026026 , 4.10610611, 4.10960961,4.11311311, 4.11661662, 4.12012012, 4.12362362, 4.12712713,4.13063063, 4.13413413, 4.13763764, 4.14114114, 4.14464464,4.14814815, 4.15165165, 4.15515516, 4.15865866, 4.16216216,4.16566567, 4.16916917, 4.17267267, 4.17617618, 4.17967968,4.18318318, 4.18668669, 4.19019019, 4.19369369, 4.1971972 ,4.2007007 , 4.2042042 , 4.20770771, 4.21121121, 4.21471471,4.21821822, 4.22172172, 4.22522523, 4.22872873, 4.23223223,4.23573574, 4.23923924, 4.24274274, 4.24624625, 4.24974975,4.25325325, 4.25675676, 4.26026026, 4.26376376, 4.26726727,4.27077077, 4.27427427, 4.27777778, 4.28128128, 4.28478478,4.28828829, 4.29179179, 4.2952953 , 4.2987988 , 4.3023023 ,4.30580581, 4.30930931, 4.31281281, 4.31631632, 4.31981982,4.32332332, 4.32682683, 4.33033033, 4.33383383, 4.33733734,4.34084084, 4.34434434, 4.34784785, 4.35135135, 4.35485485,4.35835836, 4.36186186, 4.36536537, 4.36886887, 4.37237237,4.37587588, 4.37937938, 4.38288288, 4.38638639, 4.38988989,4.39339339, 4.3968969 , 4.4004004 , 4.4039039 , 4.40740741,4.41091091, 4.41441441, 4.41791792, 4.42142142, 4.42492492,4.42842843, 4.43193193, 4.43543544, 4.43893894, 4.44244244,4.44594595, 4.44944945, 4.45295295, 4.45645646, 4.45995996,4.46346346, 4.46696697, 4.47047047, 4.47397397, 4.47747748,4.48098098, 4.48448448, 4.48798799, 4.49149149, 4.49499499,4.4984985 , 4.502002 , 4.50550551, 4.50900901, 4.51251251,4.51601602, 4.51951952, 4.52302302, 4.52652653, 4.53003003,4.53353353, 4.53703704, 4.54054054, 4.54404404, 4.54754755,4.55105105, 4.55455455, 4.55805806, 4.56156156, 4.56506507,4.56856857, 4.57207207, 4.57557558, 4.57907908, 4.58258258,4.58608609, 4.58958959, 4.59309309, 4.5965966 , 4.6001001 ,4.6036036 , 4.60710711, 4.61061061, 4.61411411, 4.61761762,4.62112112, 4.62462462, 4.62812813, 4.63163163, 4.63513514,4.63863864, 4.64214214, 4.64564565, 4.64914915, 4.65265265,4.65615616, 4.65965966, 4.66316316, 4.66666667, 4.67017017,4.67367367, 4.67717718, 4.68068068, 4.68418418, 4.68768769,4.69119119, 4.69469469, 4.6981982 , 4.7017017 , 4.70520521,4.70870871, 4.71221221, 4.71571572, 4.71921922, 4.72272272,4.72622623, 4.72972973, 4.73323323, 4.73673674, 4.74024024,4.74374374, 4.74724725, 4.75075075, 4.75425425, 4.75775776,4.76126126, 4.76476476, 4.76826827, 4.77177177, 4.77527528,4.77877878, 4.78228228, 4.78578579, 4.78928929, 4.79279279,4.7962963 , 4.7997998 , 4.8033033 , 4.80680681, 4.81031031,4.81381381, 4.81731732, 4.82082082, 4.82432432, 4.82782783,4.83133133, 4.83483483, 4.83833834, 4.84184184, 4.84534535,4.84884885, 4.85235235, 4.85585586, 4.85935936, 4.86286286,4.86636637, 4.86986987, 4.87337337, 4.87687688, 4.88038038,4.88388388, 4.88738739, 4.89089089, 4.89439439, 4.8978979 ,4.9014014 , 4.9049049 , 4.90840841, 4.91191191, 4.91541542,4.91891892, 4.92242242, 4.92592593, 4.92942943, 4.93293293,4.93643644, 4.93993994, 4.94344344, 4.94694695, 4.95045045,4.95395395, 4.95745746, 4.96096096, 4.96446446, 4.96796797,4.97147147, 4.97497497, 4.97847848, 4.98198198, 4.98548549,4.98898899, 4.99249249, 4.995996 , 4.9994995 , 5.003003 ,5.00650651, 5.01001001, 5.01351351, 5.01701702, 5.02052052,5.02402402, 5.02752753, 5.03103103, 5.03453453, 5.03803804,5.04154154, 5.04504505, 5.04854855, 5.05205205, 5.05555556,5.05905906, 5.06256256, 5.06606607, 5.06956957, 5.07307307,5.07657658, 5.08008008, 5.08358358, 5.08708709, 5.09059059,5.09409409, 5.0975976 , 5.1011011 , 5.1046046 , 5.10810811,5.11161161, 5.11511512, 5.11861862, 5.12212212, 5.12562563,5.12912913, 5.13263263, 5.13613614, 5.13963964, 5.14314314,5.14664665, 5.15015015, 5.15365365, 5.15715716, 5.16066066,5.16416416, 5.16766767, 5.17117117, 5.17467467, 5.17817818,5.18168168, 5.18518519, 5.18868869, 5.19219219, 5.1956957 ,5.1991992 , 5.2027027 , 5.20620621, 5.20970971, 5.21321321,5.21671672, 5.22022022, 5.22372372, 5.22722723, 5.23073073,5.23423423, 5.23773774, 5.24124124, 5.24474474, 5.24824825,5.25175175, 5.25525526, 5.25875876, 5.26226226, 5.26576577,5.26926927, 5.27277277, 5.27627628, 5.27977978, 5.28328328,5.28678679, 5.29029029, 5.29379379, 5.2972973 , 5.3008008 ,5.3043043 , 5.30780781, 5.31131131, 5.31481481, 5.31831832,5.32182182, 5.32532533, 5.32882883, 5.33233233, 5.33583584,5.33933934, 5.34284284, 5.34634635, 5.34984985, 5.35335335,5.35685686, 5.36036036, 5.36386386, 5.36736737, 5.37087087,5.37437437, 5.37787788, 5.38138138, 5.38488488, 5.38838839,5.39189189, 5.3953954 , 5.3988989 , 5.4024024 , 5.40590591,5.40940941, 5.41291291, 5.41641642, 5.41991992, 5.42342342,5.42692693, 5.43043043, 5.43393393, 5.43743744, 5.44094094,5.44444444, 5.44794795, 5.45145145, 5.45495495, 5.45845846,5.46196196, 5.46546547, 5.46896897, 5.47247247, 5.47597598,5.47947948, 5.48298298, 5.48648649, 5.48998999, 5.49349349,5.496997 , 5.5005005 , 5.504004 , 5.50750751, 5.51101101,5.51451451, 5.51801802, 5.52152152, 5.52502503, 5.52852853,5.53203203, 5.53553554, 5.53903904, 5.54254254, 5.54604605,5.54954955, 5.55305305, 5.55655656, 5.56006006, 5.56356356,5.56706707, 5.57057057, 5.57407407, 5.57757758, 5.58108108,5.58458458, 5.58808809, 5.59159159, 5.5950951 , 5.5985986 ,5.6021021 , 5.60560561, 5.60910911, 5.61261261, 5.61611612,5.61961962, 5.62312312, 5.62662663, 5.63013013, 5.63363363,5.63713714, 5.64064064, 5.64414414, 5.64764765, 5.65115115,5.65465465, 5.65815816, 5.66166166, 5.66516517, 5.66866867,5.67217217, 5.67567568, 5.67917918, 5.68268268, 5.68618619,5.68968969, 5.69319319, 5.6966967 , 5.7002002 , 5.7037037 ,5.70720721, 5.71071071, 5.71421421, 5.71771772, 5.72122122,5.72472472, 5.72822823, 5.73173173, 5.73523524, 5.73873874,5.74224224, 5.74574575, 5.74924925, 5.75275275, 5.75625626,5.75975976, 5.76326326, 5.76676677, 5.77027027, 5.77377377,5.77727728, 5.78078078, 5.78428428, 5.78778779, 5.79129129,5.79479479, 5.7982983 , 5.8018018 , 5.80530531, 5.80880881,5.81231231, 5.81581582, 5.81931932, 5.82282282, 5.82632633,5.82982983, 5.83333333, 5.83683684, 5.84034034, 5.84384384,5.84734735, 5.85085085, 5.85435435, 5.85785786, 5.86136136,5.86486486, 5.86836837, 5.87187187, 5.87537538, 5.87887888,5.88238238, 5.88588589, 5.88938939, 5.89289289, 5.8963964 ,5.8998999 , 5.9034034 , 5.90690691, 5.91041041, 5.91391391,5.91741742, 5.92092092, 5.92442442, 5.92792793, 5.93143143,5.93493493, 5.93843844, 5.94194194, 5.94544545, 5.94894895,5.95245245, 5.95595596, 5.95945946, 5.96296296, 5.96646647,5.96996997, 5.97347347, 5.97697698, 5.98048048, 5.98398398,5.98748749, 5.99099099, 5.99449449, 5.997998 , 6.0015015 ,6.00500501, 6.00850851, 6.01201201, 6.01551552, 6.01901902,6.02252252, 6.02602603, 6.02952953, 6.03303303, 6.03653654,6.04004004, 6.04354354, 6.04704705, 6.05055055, 6.05405405,6.05755756, 6.06106106, 6.06456456, 6.06806807, 6.07157157,6.07507508, 6.07857858, 6.08208208, 6.08558559, 6.08908909,6.09259259, 6.0960961 , 6.0995996 , 6.1031031 , 6.10660661,6.11011011, 6.11361361, 6.11711712, 6.12062062, 6.12412412,6.12762763, 6.13113113, 6.13463463, 6.13813814, 6.14164164,6.14514515, 6.14864865, 6.15215215, 6.15565566, 6.15915916,6.16266266, 6.16616617, 6.16966967, 6.17317317, 6.17667668,6.18018018, 6.18368368, 6.18718719, 6.19069069, 6.19419419,6.1976977 , 6.2012012 , 6.2047047 , 6.20820821, 6.21171171,6.21521522, 6.21871872, 6.22222222, 6.22572573, 6.22922923,6.23273273, 6.23623624, 6.23973974, 6.24324324, 6.24674675,6.25025025, 6.25375375, 6.25725726, 6.26076076, 6.26426426,6.26776777, 6.27127127, 6.27477477, 6.27827828, 6.28178178,6.28528529, 6.28878879, 6.29229229, 6.2957958 , 6.2992993 ,6.3028028 , 6.30630631, 6.30980981, 6.31331331, 6.31681682,6.32032032, 6.32382382, 6.32732733, 6.33083083, 6.33433433,6.33783784, 6.34134134, 6.34484484, 6.34834835, 6.35185185,6.35535536, 6.35885886, 6.36236236, 6.36586587, 6.36936937,6.37287287, 6.37637638, 6.37987988, 6.38338338, 6.38688689,6.39039039, 6.39389389, 6.3973974 , 6.4009009 , 6.4044044 ,6.40790791, 6.41141141, 6.41491491, 6.41841842, 6.42192192,6.42542543, 6.42892893, 6.43243243, 6.43593594, 6.43943944,6.44294294, 6.44644645, 6.44994995, 6.45345345, 6.45695696,6.46046046, 6.46396396, 6.46746747, 6.47097097, 6.47447447,6.47797798, 6.48148148, 6.48498498, 6.48848849, 6.49199199,6.4954955 , 6.498999 , 6.5025025 , 6.50600601, 6.50950951,6.51301301, 6.51651652, 6.52002002, 6.52352352, 6.52702703,6.53053053, 6.53403403, 6.53753754, 6.54104104, 6.54454454,6.54804805, 6.55155155, 6.55505506, 6.55855856, 6.56206206,6.56556557, 6.56906907, 6.57257257, 6.57607608, 6.57957958,6.58308308, 6.58658659, 6.59009009, 6.59359359, 6.5970971 ,6.6006006 , 6.6041041 , 6.60760761, 6.61111111, 6.61461461,6.61811812, 6.62162162, 6.62512513, 6.62862863, 6.63213213,6.63563564, 6.63913914, 6.64264264, 6.64614615, 6.64964965,6.65315315, 6.65665666, 6.66016016, 6.66366366, 6.66716717,6.67067067, 6.67417417, 6.67767768, 6.68118118, 6.68468468,6.68818819, 6.69169169, 6.6951952 , 6.6986987 , 6.7022022 ,6.70570571, 6.70920921, 6.71271271, 6.71621622, 6.71971972,6.72322322, 6.72672673, 6.73023023, 6.73373373, 6.73723724,6.74074074, 6.74424424, 6.74774775, 6.75125125, 6.75475475,6.75825826, 6.76176176, 6.76526527, 6.76876877, 6.77227227,6.77577578, 6.77927928, 6.78278278, 6.78628629, 6.78978979,6.79329329, 6.7967968 , 6.8003003 , 6.8038038 , 6.80730731,6.81081081, 6.81431431, 6.81781782, 6.82132132, 6.82482482,6.82832833, 6.83183183, 6.83533534, 6.83883884, 6.84234234,6.84584585, 6.84934935, 6.85285285, 6.85635636, 6.85985986,6.86336336, 6.86686687, 6.87037037, 6.87387387, 6.87737738,6.88088088, 6.88438438, 6.88788789, 6.89139139, 6.89489489,6.8983984 , 6.9019019 , 6.90540541, 6.90890891, 6.91241241,6.91591592, 6.91941942, 6.92292292, 6.92642643, 6.92992993,6.93343343, 6.93693694, 6.94044044, 6.94394394, 6.94744745,6.95095095, 6.95445445, 6.95795796, 6.96146146, 6.96496496,6.96846847, 6.97197197, 6.97547548, 6.97897898, 6.98248248,6.98598599, 6.98948949, 6.99299299, 6.9964965 , 7. ]), delta = 0.05) 🔗

Source code in scripts/spectra.py
def plot_spectra_nm(
    filename,
    spectra,
    E=np.linspace(3.5, 7.0, 1000),
    delta=0.05,
):
    Nspectra = len(spectra)
    Nstate = spectra[0].shape[0]

    Ostates = []
    for state in range(Nstate):
        Ostate = np.zeros_like(E)
        for spectrum in spectra:
            Ostate += spectrum[state, 1] * lorentzian(E, spectrum[state, 0], delta)
        Ostate /= Nspectra
        Ostates.append(Ostate)

    Ototal = np.zeros_like(E)
    for Ostate in Ostates:
        Ototal += Ostate

    cmap = matplotlib.cm.get_cmap("jet")
    colors = [cmap(float(x) / (Nstate - 1)) for x in reversed(list(range(Nstate)))]

    nm = (1239.84193) / E

    plt.clf()
    for Oind, Ostate in enumerate(Ostates):
        plt.plot(nm, Ostate, color=colors[Oind])

    plt.plot(nm, Ototal, "-k")
    plt.xlabel(r"$\lambda$ [nm]")
    plt.ylabel("Cross Section [-]")
    plt.savefig(filename)

read_fomo_outfile(filename) 🔗

Source code in scripts/spectra.py
def read_fomo_outfile(filename):

    lines = open(filename).readlines()

    if len([x for x, y in enumerate(lines) if re.match(r"^\s+Job finished", y)]) == 0:
        return None

    Es = []
    re_ex = re.compile(r"^\s*(\d+)\s+singlet\s+\S+\s+\S+\s+(\S+)\s+\S+\s*$")
    for line in lines:
        mobj = re.match(re_ex, line)
        if mobj:
            Es.append(float(mobj.group(2)))
            assert int(mobj.group(1)) == len(Es) + 1

    Os = []
    re_osc = re.compile(r"^\s*1\s+->\s+(\d+)\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)\s*$")
    for line in lines:
        mobj = re.match(re_osc, line)
        if mobj:
            Os.append(float(mobj.group(2)))
            assert int(mobj.group(1)) == len(Os) + 1
    assert len(Os) == len(Es)

    return np.array([[x, y] for x, y in zip(Es, Os)])

read_tddft_outfile(filename) 🔗

Source code in scripts/spectra.py
def read_tddft_outfile(filename):

    lines = open(filename).readlines()

    if len([x for x, y in enumerate(lines) if re.match(r"^\s+Job finished", y)]) == 0:
        return None

    lines = lines[
        (
            [
                x
                for x, y in enumerate(lines)
                if re.match(r"^\s+Final Excited State Results:", y)
            ][0]
            + 4
        ) :
    ]
    vals = []
    for line in lines:
        mobj = re.match(r"^\s*(\d+)\s+\S+\s+(\S+)\s+(\S+)", line)
        if mobj:
            vals.append([float(mobj.group(2)), float(mobj.group(3))])
            assert int(mobj.group(1)) == len(vals)
    return np.array(vals)