Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Jablonski Diagram plot #23

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,10 @@ diagram.fig.show()
```
If you use the command `diagram.plot()` now all the changes will be overwritten, so these minor adjustment must be done after.

## Plot Jablonski-diagram
An example is provided in the tests directory

![alt tag](https://github.com/lenhanpham/PyEnergyDiagrams/blob/master/md_images/Ir-complex-Jablonski-diagram.png)

### Contributors
Thanks to Kalyan Jyoti Kalita for the arrow functionality and O2-AC, agrass15268 for bug fixing.
63 changes: 63 additions & 0 deletions energydiagram/extracttddft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
@author Le Nhan Pham
@website https://lenhanpham.github.io/
@create date 2023-01-30 21:37:41
@modify date 2023-01-30 21:37:41
"""


def extractTd(file):
"""
This fucntion is used when tdddft 50-50 is used in the input of Gaussian
"""
ss = 'Excitation energies and oscillator strengths'
with open(file, 'r') as f:
numSstates = 0
numTstates = 0
Senergies, Tenergies, Sstates, Tstates = [], [], [], []
for line in f:
if 'Excited State' in line:
tempState = line.split()[3].split('-')[0]
tempEnergy =float(line.split()[4])
if float(tempState) == 3.000:
Tenergies.append(tempEnergy)
numTstates += 1
Tstates.append(numTstates)
elif float(tempState) == 1.000:
Senergies.append(float(line.split()[4]))
numSstates += 1
Sstates.append(numSstates)

singlets = dict(zip(Sstates, Senergies))
triplets = dict(zip(Tstates, Tenergies))

return singlets, triplets

def extractData2files(tdFile,):
"""
This function is used when TDDFT runs for singlet and triplet are run separately
"""
ss = 'Excitation energies and oscillator strengths'
with open(tdFile, 'r') as f:
numSstates = 0
numTstates = 0
Senergies, Sstates, Tenergies, Tstates = [], [], [], []
for line in f:
if 'Excited State' in line:
tempState = line.split()[3].split("-")[0]
tempEnergy =float(line.split()[4])
if str(tempState) == "Singlet":
Senergies.append(tempEnergy)
numSstates += 1
Sstates.append(numSstates)
elif str(tempState) == "Triplet":
Tenergies.append(tempEnergy)
numTstates += 1
Tstates.append(numTstates)

singlets = dict(zip(Sstates, Senergies))
triplets = dict(zip(Tstates,Tenergies))
if str(tempState) == "Singlet":
return singlets
else:
return triplets
Binary file added md_images/Ir-complex-Jablonski-diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,910 changes: 1,910 additions & 0 deletions tests/Ir-complex-singlet-trans-restricted.log

Large diffs are not rendered by default.

1,702 changes: 1,702 additions & 0 deletions tests/Ir-complex-singlet-trans-tddft-singlet.log

Large diffs are not rendered by default.

1,724 changes: 1,724 additions & 0 deletions tests/Ir-complex-singlet-trans-tddft-triplets.log

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions tests/Jablonski-diagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
@author Le Nhan Pham
@website https://lenhanpham.github.io/
@create date 2023-01-30 21:38:25
@modify date 2023-01-30 21:38:25
"""


import os, sys
file_path = 'E:\Projects\Martin-reaction\SET\SET\Ir-complex\def2tzvpd\energydiagram'
sys.path.append(os.path.dirname(file_path))

import matplotlib.pyplot as plt
from energydiagram import ED, extracttddft

output="Ir-complex-Jablonski-diagram"
singletLog ='Ir-complex-singlet-trans-tddft-singlet'
tripletLog ='Ir-complex-singlet-trans-tddft-triplets'

singlets = extracttddft.extractData2files(singletLog+".log")
triplets = extracttddft.extractData2files(tripletLog+".log")


diagram = ED(aspect='auto')
diagram.right_text_fontsize='xx-small'
diagram.bottom_text_fontsize='xx-small'
diagram.top_text_fontsize='xx-small'
diagram.left_text_fontsize='xx-small'

diagram.add_level(0,bottom_text='',top_text='0.00', right_text='S0',position=0, color = 'k') #'S0'
diagram.add_level(singlets[1],bottom_text=str(round(singlets[1],2)),top_text='', right_text='S1',position=0, color = 'k') #'S0'
diagram.add_level(triplets[1],bottom_text=str(round(triplets[1],2)),top_text='', right_text='T1',position=1, color = 'g') #'T0'

singlets.pop(1)
for singlet in singlets:
diagram.add_level(singlets[singlet],bottom_text='',top_text='',right_text='',position=0, color = 'k') #'S1'

triplets.pop(1)
for triplet in triplets:
diagram.add_level(triplets[triplet],bottom_text='',top_text='',right_text='',position=1, color = 'g') #'T1'

diagram.offset = 0.03





diagram.plot() # this is the default ylabel

diagram.ax.set_ylabel("Energy / eV")
diagram.ax.set_xlabel("Electronic state")


#diagram.fig.set_figwidth(10)
diagram.ax.axes.get_xaxis().set_visible(True)
diagram.ax.axes.xaxis.set_ticklabels([])
diagram.ax.axes.set_xticks([], minor=False)
diagram.ax.spines['bottom'].set_visible(True)
plt.savefig(output + '.pdf')
plt.savefig(output + '.svg')