Computer Exercise 2 - Fysik
Computer Exercise 2 - Fysik
Computer Exercise 2 - Fysik
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
#!/usr/bin/env python<br />
from ase import *<br />
from ase.io import read<br />
from ase.optimize import BFGS<br />
from ase.io import PickleTrajectory<br />
import numpy as np<br />
from gpaw import GPAW<br />
atoms = read('C2H6.traj')<br />
calc=GPAW(mode='lcao', basis='dzp', h=0.2, xc='PBE', nbands=8, txt='out_task6.txt')<br />
atoms.set_calculator(calc)<br />
traj= PickleTrajectory('EthaneRotation.traj', 'w') # makes a trajectory file<br />
f = open('eigenvalues.txt','w') # Open a file for writing<br />
f.write('# angle eigenvalue1 eigenvalue 2 ...\n')<br />
maxstep=60<br />
for nsteps in range(maxstep):<br />
newatoms=atoms<br />
atoms2rot=atoms[2:5] #These are the H atoms that are supposed to be rotated<br />
angle=2*np.pi/(maxstep)<br />
rotvector = atoms[0]. position - atoms[1]. position<br />
atoms2rot.rotate(rotvector ,angle ,center='COM') #This rotates with angle around<br />
#the z-axis and the center of mass<br />
pos=atoms2rot.get_positions()<br />
for n in range(len(atoms2rot)):<br />
newatoms[n+2]. set_position(pos[n])<br />
newatoms.set_calculator(calc)<br />
traj.write(newatoms)<br />
eigenvalues = calc.get_eigenvalues()<br />
eigenvalues_s = ' '.join([str(i) for i in eigenvalues])<br />
angle_s = str(angle*(nsteps+1)*180/np.pi)<br />
# Write angle and eigenvalues to file<br />
f.write(angle_s + ' ' + eigenvalues_s + '\n')<br />
f.close() # close file<br />
Task 3<br />
Use the ag to look at the trajectory file. How much energy is required to rotate the ethane molecule? The<br />
experimental value of the barrier is 0.13 eV.<br />
To understand where the change in the conformational energy comes from we can plot the eigenvalues<br />
of the KS-system during the rotation. Here we use a script that plots the stored eigenvalues as a function of<br />
rotation. This you should not send to the queue, but instead run on the login node.<br />
#!/usr/bin/env python<br />
import numpy as np<br />
import pylab as plt<br />
data = np.loadtxt('eigenvalues.txt')<br />
angles = data[:,0]<br />
eigenvalues = data[:,1:]<br />
plt.plot(angles , eigenvalues , 'o-')<br />
plt.xlabel('Angle/[degrees]')<br />
plt.ylabel('K-S eigenvalues/[eV]')<br />
plt.show()<br />
How large is the change in eigenvalues (especially the HOMO level)? Given how the total energy is<br />
evaluated in normal DFT codes (see lecture notes) the conformational energy comes from the change in<br />
eigenvalues.<br />
6