In [1]:
import numpy as np
import sys
import matplotlib.pyplot as plt
import os
import scipy.constants as ct
import lxml.etree as lxml
import sqlite3
from mpl_toolkits.mplot3d import Axes3D
%matplotlib inline
Ryd2eV=13.605692
epsilon=3
bohr2m=5.2917721092E-11
In [2]:
def readSqlall(sqlname):
sqlstatement = "SELECT eSinglet FROM segments"
con = sqlite3.connect(sqlname)
with con:
cur = con.cursor()
cur.execute(sqlstatement)
rows = cur.fetchall()
sqlall=(np.array(rows)[:,0])
return sqlall
def writeEnergies(sqlname,energies):
con = sqlite3.connect(sqlname)
with con:
cur = con.cursor()
for i in range(energies.size):
sqlstatement = "UPDATE segments SET UxXnNs={} WHERE id={}".format(energies[i],i+1)
cur.execute(sqlstatement)
def readorb(filename):
trdip=False
energy=False
with open(filename,"r") as f:
lines=f.readlines()
for line in lines:
if "Singlet1[eV]:" in line:
energy=float(line.split()[3])
if "Singlet1 x y z" in line:
#print line
a=line.split()
x=float(a[7])
y=float(a[8])
z=float(a[9])
trdip=bohr2m*np.array([x,y,z])*np.sqrt(2)
return trdip,energy
In [3]:
#files1=os.listdir("logfiles2")
files1=[]
files2=[]
senergies=readSqlall("system_individualmps.sql")
energies=[]
for i in range(1,1569):
files1.append("molecule_{}.orb.log".format(i))
#files2=os.listdir("espfits")
hbar=ct.physical_constants['Planck constant over 2 pi in eV s'][0]
lifetimes=[]
for filename,sitenergy in zip(files1,senergies):
#print filename
trp,energy=readorb("logfiles2/"+filename)
energies.append(energy)
omega=(energy+sitenergy)/hbar
lifetime=(3*ct.c**2)/(np.sqrt(epsilon)*4*ct.alpha*omega**3*np.dot(trp,trp))
lifetimes.append(lifetime)
lifetimes=np.array(lifetimes)
energies=np.array(energies)
print np.std(energies),np.mean(energies),np.std(senergies),np.average(senergies)
print np.average(lifetimes)
print np.std(lifetimes)
In [4]:
#writeEnergies("system_individualmps.sql",energies)
In [5]:
n, bins, patches = plt.hist(lifetimes, 50, facecolor='green')
plt.xlabel('lifetime [s]')
plt.ylabel('Counts')
plt.savefig("lifetimedistribution.svg")
plt.show()
print lifetimes.shape
In [7]:
root = lxml.Element("lifetimes")
for i,tau in zip(range(1,1569),lifetimes):
entry=lxml.Element("site",id="{}".format(i))
entry.text="{:1.6e}".format(tau)
root.append(entry)
with open("lifetimes.xml", 'w') as f:
f.write(lxml.tostring(root, pretty_print=True))
In [6]:
total=energies+senergies
n=plt.hist((total-np.mean(total)),50,label="combined std={:1.2f}".format(np.std(total)))
n=plt.hist((energies-np.mean(energies)),50,label="conformational disorder std={:1.2f}".format(np.std(energies)))
n=plt.hist((senergies-np.mean(senergies)),50,label="estatic disorder std={:1.2f}".format(np.std(senergies)))
plt.ylabel('Counts')
plt.xlabel('deviation from average siteenergy [eV]')
plt.savefig("siteenergies.svg")
plt.legend()
plt.show()
In [ ]: