<commit_before>import numpy as np
import lxml.etree as lxml
import datetime
import sys

ryd2ev=13.605692
hrt2ev=2*ryd2ev
   

def readoscillatorstrength(filename):
	fs=[]
	sbool=False
	with open(filename,"r") as f:
		for line in f.readlines():
			if "====== singlet energies (eV) ======" in line:
				sbool=True
			elif sbool and "TrDipole length gauge" in line:
				fs.append(float(line.split()[-1]))

	return np.array(fs)
			

def readexcitonlogfile(filename,dft=False,qp=False,singlets=False,triplets=False):
	dftlist=[]
	gwa=[]
	qp=[]
	s=[]
	t=[]
	homo=None
	lumo=None
	tbool=False
	sbool=False
	qpbool=False
	dftenergy=None
	add=0
	with open(filename,"r") as f:
		for line in f.readlines():
			if "GWBSE" in line and ( "DBG" in line or "INF" in line):
				add=1
			if "QM energy[eV]" in line and dftenergy==None:
				dftenergy=float(line.split()[-1])
			elif "====== Perturbative quasiparticle energies (Hartree) ======" in line:
				conversion=hrt2ev
			elif "====== Perturbative quasiparticle energies (Rydberg) ======" in line:
				conversion=ryd2ev
			elif dft and "S-C" in line and "S-X" in line:
				entries=line.split()
				dftlist.append(conversion*float(entries[7]))
				gwa.append(conversion*float(entries[-1]))
				if "HOMO"==entries[2+add] and homo==None:
					homo=int(entries[4+add])-1
					#print entries
				if "LUMO"==entries[2+add] and lumo==None:
					lumo=int(entries[4+add])-1
					#print entries
			elif "====== Diagonalized quasiparticle energies" in line:
				qpbool=True
			elif qpbool and qp and "PQP" in line and "DQP" in line:
				qp.append(conversion*float(line.split()[-1]))
			elif "====== triplet energies (eV) ======" in line:
				tbool=True
			elif tbool and triplets and "T =" in line:
				t.append(float(line.split()[7+add]))
			elif "====== singlet energies (eV) ======" in line:
				sbool=True
			elif sbool and singlets and "S =" in line:
				s.append(float(line.split()[7+add]))
	results=[]
	if dft:
		results.append([homo,lumo,dftenergy])
		results.append(np.array(dftlist))
		results.append(np.array(gwa))
	else:
		results.append(None)
		results.append(None)
		results.append(None)
	if qp:
		results.append(np.array(qp))
	else:
		results.append(None)
	if singlets:
		results.append(np.array(s))
	else:
		results.append(None)
	if triplets:
		results.append(np.array(t))
	else:
		results.append(None)
	#print results
	return results

def readctstatepops(filename,excitontype="singlet"):
	fragA=[]
	fragB=[]
	frag=False
	tbool=False
	add=0
	namestring=""
	if excitontype=="singlet":
		namestring="S ="
	elif excitontype=="triplet":
		namestring="T ="
	else:
		print "ERROR: String {} not known for readctstatepops".format(excitonstring)
		sys.exit()
	with open(filename,"r") as f:
		for line in f.readlines():
			if "GWBSE" in line and ( "DBG" in line or "INF" in line):
				add=1
			if "====== {} energies (eV) ======".format(excitontype) in line:
				tbool=True
			elif tbool and namestring in line:
				frag=True
			elif tbool and frag and "Fragment A" in line:
				fragA.append(float(line.split()[12+add]))
			elif tbool and frag and "Fragment B" in line:
				fragB.append(float(line.split()[12+add]))
				
	result=np.array([fragA,fragB])
	return result
			

def getcouplingfromsplit(filename,states):
	dft=False
	singlets=False
	triplets=False
	coupling=[]
	for state in states:<commit_msg>added exciton reader for fragment analysis<commit_after>import numpy as np
import lxml.etree as lxml
import datetime
import sys

ryd2ev=13.605692
hrt2ev=2*ryd2ev
   

def readoscillatorstrength(filename):
	fs=[]
	sbool=False
	with open(filename,"r") as f:
		for line in f.readlines():
			if "====== singlet energies (eV) ======" in line:
				sbool=True
			elif sbool and "TrDipole length gauge" in line:
				fs.append(float(line.split()[-1]))

	return np.array(fs)
			

def readexcitonlogfile(filename,dft=False,qp=False,singlets=False,triplets=False):
	dftlist=[]
	gwa=[]
	qp=[]
	s=[]
	t=[]
	homo=None
	lumo=None
	tbool=False
	sbool=False
	qpbool=False
	dftenergy=None
	add=0
	with open(filename,"r") as f:
		for line in f.readlines():
			if "GWBSE" in line and ( "DBG" in line or "INF" in line):
				add=1
			if "QM energy[eV]" in line and dftenergy==None:
				dftenergy=float(line.split()[-1])
			elif "====== Perturbative quasiparticle energies (Hartree) ======" in line:
				conversion=hrt2ev
			elif "====== Perturbative quasiparticle energies (Rydberg) ======" in line:
				conversion=ryd2ev
			elif dft and "S-C" in line and "S-X" in line:
				entries=line.split()
				dftlist.append(conversion*float(entries[7]))
				gwa.append(conversion*float(entries[-1]))
				if "HOMO"==entries[2+add] and homo==None:
					homo=int(entries[4+add])-1
					#print entries
				if "LUMO"==entries[2+add] and lumo==None:
					lumo=int(entries[4+add])-1
					#print entries
			elif "====== Diagonalized quasiparticle energies" in line:
				qpbool=True
			elif qpbool and qp and "PQP" in line and "DQP" in line:
				qp.append(conversion*float(line.split()[-1]))
			elif "====== triplet energies (eV) ======" in line:
				tbool=True
			elif tbool and triplets and "T =" in line:
				t.append(float(line.split()[7+add]))
			elif "====== singlet energies (eV) ======" in line:
				sbool=True
			elif sbool and singlets and "S =" in line:
				s.append(float(line.split()[7+add]))
	results=[]
	if dft:
		results.append([homo,lumo,dftenergy])
		results.append(np.array(dftlist))
		results.append(np.array(gwa))
	else:
		results.append(None)
		results.append(None)
		results.append(None)
	if qp:
		results.append(np.array(qp))
	else:
		results.append(None)
	if singlets:
		results.append(np.array(s))
	else:
		results.append(None)
	if triplets:
		results.append(np.array(t))
	else:
		results.append(None)
	#print results
	return results

def readctstatepops(filename,excitontype="singlet"):
	fragA=[]
	fragB=[]
	frag=False
	tbool=False
	add=0
	namestring=""
	if excitontype=="singlet":
		namestring="S ="
	elif excitontype=="triplet":
		namestring="T ="
	else:
		print "ERROR: String {} not known for readctstatepops".format(excitonstring)
		sys.exit()
	with open(filename,"r") as f:
		for line in f.readlines():
			if "GWBSE" in line and ( "DBG" in line or "INF" in line):
				add=1
			if "====== {} energies (eV) ======".format(excitontype) in line:
				tbool=True
			elif tbool and namestring in line:
				frag=True
			elif tbool and frag and "Fragment A" in line:
				fragA.append(float(line.split()[12+add]))
			elif tbool and frag and "Fragment B" in line:
				fragB.append(float(line.split()[12+add]))
				
	result=np.array([fragA,fragB])
	return result

def readctstatedist(filename,excitontype="singlet"):
	hole=[]
	electron=[]
	frag=False
	tbool=False
	add=0
	namestring=""
	if excitontype=="singlet":
		namestring="S ="
	elif excitontype=="triplet":
		namestring="T ="
	else:
		print "ERROR: String {} not known for readctstatepops".format(excitonstring)
		sys.exit()
	with open(filename,"r") as f:
		for line in f.readlines():
			if "GWBSE" in line and ( "DBG" in line or "INF" in line):
				add=1
			if "====== {} energies (eV) ======".format(excitontype) in line:
				tbool=True
			elif tbool and namestring in line:
				frag=True
			elif tbool and frag and "Fragment A" in line:
				hole.append(float(line.split()[6+add].strip("%")))
				electron.append(float(line.split()[8+add].strip("%")))
				
	result=np.array([hole,electron])
	return result
			

def getcouplingfromsplit(filename,states):
	dft=False
	singlets=False
	triplets=False
	coupling=[]
	for state in states:
{'fraction_non_alphanumeric': 0.15929675013319125, 'fraction_numerical': 0.009856153436334577, 'mean_word_length': 4.232752613240418, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5411443', 'n_tokens_mistral': 3239, 'n_tokens_neox': 2820, 'n_words': 680}