Skip to content

Instantly share code, notes, and snippets.

@jarvist
Last active October 4, 2015 03:18
Show Gist options
  • Save jarvist/2569160 to your computer and use it in GitHub Desktop.
Save jarvist/2569160 to your computer and use it in GitHub Desktop.
(incorrect) and badly written convolve wavelength function for simulating absorb. spectra
import fileinput
import numpy as np
#expects input as:
#Energy(eV) Lambda(nm) OscillatorStrength
oscillators=[]
for line in fileinput.input():
oscillators.append(map(float, line.split()))
#print oscillators
broadening=0.025 #eV !
for wavelength in np.arange(200.,800.,1.):
cE=1239.84187/wavelength
synesthesia=0.
for oscillate in oscillators:
E,nm,strength=oscillate
synesthesia+= strength * np.exp(-(E-cE)**2/(2*broadening))
print wavelength, synesthesia
#!/usr/bin/python
from math import *
width=15.0
#states=input()
wavelength={}
os={}
#for i in range(states):
# wavelength[i],os[i]=[ float(x) for x in raw_input().split() ]
states=0
while 1:
try:
wavelength[states],os[states]=[ float(x) for x in raw_input().split() ]
states=states+1
except ValueError:
break
cwavelength=-2000.0
while cwavelength <= 5000.0:
strength=0.0
for i in range(states):
strength+=os[i]*exp( - (cwavelength-wavelength[i])*(cwavelength-wavelength[i]) / (2*width*width))
print cwavelength, strength
cwavelength+=1.0
@jarvist
Copy link
Author

jarvist commented Feb 1, 2013

I felt so disgusted that the most recent time I came to do this, I wrote a better program in Pytohn (better_convolve) which will actually do this in the correct domain (energy). Not sure if the Gaussian broadening is correct, that's meant to be a factor of kBT (25meV).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment