Advertisement
UHLI_REMO

makefile.txt (pdos)

Nov 26th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. from math import pi, sqrt
  4. import numpy as np
  5.  
  6. class pdos:
  7. """ Projected electronic density of states from CP2K output files
  8.  
  9. Attributes
  10. ----------
  11. atom: str
  12. the name of the atom where the DoS is projected
  13. iterstep: int
  14. the iteration step from the CP2K job
  15. efermi: float
  16. the energy of the Fermi level [a.u]
  17. e: float
  18. (eigenvalue - efermi) in eV
  19. occupation: int
  20. 1 for occupied state or 0 for unoccupied
  21. pdos: nested list of float
  22. projected density of states on each orbital for each eigenvalue
  23. [[s1, p1, d1,....], [s2, p2, d2,...],...]
  24. s: pdos in s orbitals
  25. p: pdos in p orbitals
  26. d: pdos in d orbitals
  27. .
  28. .
  29. .
  30. tpdos: list of float
  31. sum of all the orbitals PDOS
  32.  
  33. Methods
  34. -------
  35. smearing(self,npts, width)
  36. return the smeared tpdos
  37. """
  38.  
  39. def __init__(self, infilename):
  40. """Read a CP2K .pdos file and build a pdos instance
  41.  
  42. Parameters
  43. ----------
  44. infilename: str
  45. pdos output from CP2K.
  46.  
  47. """
  48. input_file = open(infilename, 'r')
  49.  
  50. firstline = input_file.readline().strip().split()
  51. secondline = input_file.readline().strip().split()
  52.  
  53. # Kind of atom
  54. self.atom = firstline[6]
  55. #iterationstep
  56. self.iterstep = int(firstline[12][:-1]) #[:-1] delete ","
  57. # Energy of the Fermi level
  58. self.efermi = float(firstline[15])
  59.  
  60. # it keeps just the orbital names
  61. secondline[0:5] = []
  62. self.orbitals = secondline
  63.  
  64. lines = input_file.readlines()
  65.  
  66. eigenvalue = []
  67. self.occupation = []
  68. data = []
  69. self.pdos = []
  70. for index, line in enumerate(lines):
  71. data.append(line.split())
  72. data[index].pop(0)
  73. eigenvalue.append(float(data[index].pop(0)))
  74. self.occupation.append(int(float(data[index].pop(0))))
  75. self.pdos.append([float(i) for i in data[index]])
  76.  
  77. self.e = [(x-self.efermi)*27.211384523 for x in eigenvalue]
  78.  
  79. self.tpdos = []
  80. for i in self.pdos:
  81. self.tpdos.append(sum(i))
  82.  
  83. def __add__(self, other):
  84. """Return the sum of two PDOS objects"""
  85. sumtpdos = [i+j for i,j in zip(self.tpdos,other.tpdos)]
  86. return sumtpdos
  87.  
  88. def delta(self,emin,emax,npts,energy,width):
  89. """Return a delta-function centered at energy
  90.  
  91. Parameters
  92. ----------
  93. emin: float
  94. minimun eigenvalue
  95. emax: float
  96. maximun eigenvalue
  97. npts: int
  98. Number of points in the smeared pdos
  99. energy: float
  100. energy where the gaussian is centered
  101. width: float
  102. dispersion parameter
  103.  
  104. Return
  105. ------
  106. delta: numpy array
  107. array of delta function values
  108.  
  109. """
  110.  
  111. energies = np.linspace(emin, emax, npts)
  112. x = -((energies - energy) / width)**2
  113. return np.exp(x) / (sqrt(pi) * width)
  114.  
  115. def smearing(self,npts, width,):
  116. """Return a gaussian smeared DOS"""
  117.  
  118. d = np.zeros(npts)
  119. emin = min(self.e)
  120. emax = max(self.e)
  121. for e, pd in zip(self.e,self.tpdos):
  122. d +=pd*self.delta(emin,emax,npts,e,width)
  123.  
  124. return d
  125.  
  126. def sum_tpdos(tpdos1, tpdos2):
  127. """Return the sum of two PDOS"""
  128. return [i+j for i,j in zip(tpdos1,tpdos2)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement