@@ -1689,6 +1689,49 @@ def gaussian_function_vector(a_vec, mu_vec, sigma, num_points, x_min, x_max):
16891689 return x , sum_vec
16901690
16911691
1692+
1693+ def aux_pdos (c1 , atoms , pdos_files , margin , homo_occ , orbitals_cols , sigma , npoints , ave_pdos_convolved_all , labels ):
1694+ """
1695+ c1 - index of the atom kinds
1696+ atoms - the
1697+ pdos_files (list of strings): names of the files containing pdos data
1698+ shift (double): the amount of "padding" around the minimal and maximal values of the energy scale [units: eV]
1699+ homo_occ (double): occupancy of the HOMO: 2 - for non-polarized, 1 - for polarized
1700+ orbital_cols (list of lists of integers): integers that define which columns correspond to which types of orbitals
1701+ sigma (double): broadening of the pDOS
1702+ npoints (int): how many points to use to compte the convolved pDOS
1703+
1704+ """
1705+
1706+ pdos_ave = np .zeros (np .loadtxt (pdos_files [0 ]).shape )
1707+
1708+ cnt = len (pdos_files )
1709+ for c2 , pdos_file in enumerate (pdos_files ):
1710+ pdos_mat = np .loadtxt (pdos_file )
1711+ if c2 == 0 :
1712+ pdos_ave = np .zeros (pdos_mat .shape )
1713+ pdos_ave += pdos_mat
1714+ pdos_ave /= cnt
1715+
1716+ pdos_ave [:,1 ] *= units .au2ev
1717+ e_min = np .min (pdos_ave [:,1 ]) - margin
1718+ e_max = np .max (pdos_ave [:,1 ]) + margin
1719+ homo_level = np .max (np .where (pdos_ave [:,2 ]== homo_occ ))
1720+ homo_energy = pdos_ave [:,1 ][homo_level ]
1721+
1722+ for c3 , orbital_cols in enumerate (orbitals_cols ):
1723+ try :
1724+ sum_pdos_ave = np .sum (pdos_ave [:,orbital_cols ],axis = 1 )
1725+ ave_energy_grid , ave_pdos_convolved = gaussian_function_vector (sum_pdos_ave , pdos_ave [:,1 ], sigma ,npoints , e_min , e_max )
1726+ ave_pdos_convolved_all .append (ave_pdos_convolved )
1727+ pdos_label = F"{ atoms [1 ][c1 ]} , { orbitals [c3 ]} "
1728+ labels .append (pdos_label )
1729+ except :
1730+ pass
1731+
1732+ return ave_energy_grid , homo_energy , ave_pdos_convolved_all
1733+
1734+
16921735def pdos (params ):
16931736 """
16941737 This function computes the weighted pdos for a set of CP2K pdos files.
@@ -1705,6 +1748,7 @@ def pdos(params):
17051748 * npoints (integer): The number of grid points for convolution with Gaussian functions.
17061749 * sigma (float): The standard deviation value
17071750 * shift (float): The amount of shifting the grid from the minimum and maximum energy values.
1751+ * is_spin_polarized (int): 0 - non-spin-polarized, 1 - spin-polarized
17081752 Returns:
17091753 ave_energy_grid (nparray): The average energy grid for all pdos files
17101754 homo_energy (float): The value of HOMO energy in eV
@@ -1716,7 +1760,10 @@ def pdos(params):
17161760 # Critical parameters
17171761 critical_params = [ "path_to_all_pdos" , "atoms" ]
17181762 # Default parameters
1719- default_params = { "orbitals_cols" : [[3 ], range (4 ,7 ), range (7 ,12 ), range (12 ,19 )], "orbitals" : ['s' , 'p' , 'd' , 'f' ], "sigma" : 0.05 , "shift" : 2.0 , "npoints" : 2000 }
1763+ default_params = { "orbitals_cols" : [[3 ], range (4 ,7 ), range (7 ,12 ), range (12 ,19 )],
1764+ "orbitals" : ['s' , 'p' , 'd' , 'f' ],
1765+ "sigma" : 0.05 , "shift" : 2.0 , "npoints" : 2000 , "is_spin_polarized" : 0
1766+ }
17201767 # Check input
17211768 comn .check_input (params , default_params , critical_params )
17221769
@@ -1727,41 +1774,79 @@ def pdos(params):
17271774 npoints = params ['npoints' ]
17281775 sigma = params ['sigma' ]
17291776 shift = params ['shift' ]
1730-
1731- labels = []
1732- ave_pdos_convolved_all = []
1733-
1734- for c1 ,i in enumerate (atoms [0 ]):
1735- # Finding all the pdos files
1736- pdos_files = glob .glob (path_to_all_pdos + F'/*k{ i } *.pdos' )
1737- pdos_ave = np .zeros (np .loadtxt (pdos_files [0 ]).shape )
1738- cnt = len (pdos_files )
1739- for c2 , pdos_file in enumerate (pdos_files ):
1740- pdos_mat = np .loadtxt (pdos_file )
1741- if c2 == 0 :
1742- pdos_ave = np .zeros (pdos_mat .shape )
1743- pdos_ave += pdos_mat
1744- pdos_ave /= cnt
1745- pdos_ave [:,1 ] *= units .au2ev
1746- e_min = np .min (pdos_ave [:,1 ])- shift
1747- e_max = np .max (pdos_ave [:,1 ])+ shift
1748- homo_level = np .max (np .where (pdos_ave [:,2 ]== 2.0 ))
1749- homo_energy = pdos_ave [:,1 ][homo_level ]
1750- for c3 , orbital_cols in enumerate (orbitals_cols ):
1751- try :
1752- sum_pdos_ave = np .sum (pdos_ave [:,orbital_cols ],axis = 1 )
1753- ave_energy_grid , ave_pdos_convolved = gaussian_function_vector (sum_pdos_ave , pdos_ave [:,1 ], sigma ,
1777+ is_spin_polarized = params ["is_spin_polarized" ]
1778+
1779+
1780+ if is_spin_polarized == 0 : # non-polarized case
1781+ homo_occ = 2.0
1782+ labels = []
1783+ ave_pdos_convolved_all = []
1784+
1785+ for c1 ,i in enumerate (atoms [0 ]):
1786+ # Finding all the pdos files
1787+ pdos_files = glob .glob (path_to_all_pdos + F'/*k{ i } *.pdos' )
1788+
1789+ ave_energy_grid , homo_energy , ave_pdos_convolved_all = aux_pdos (c1 , atoms , pdos_files , shift , homo_occ , orbitals_cols , sigma , npoints , ave_pdos_convolved_all , labels )
1790+
1791+ """
1792+ # Finding all the pdos files
1793+ pdos_files = glob.glob(path_to_all_pdos+F'/*k{i}*.pdos')
1794+ pdos_ave = np.zeros(np.loadtxt(pdos_files[0]).shape)
1795+
1796+ cnt = len(pdos_files)
1797+ for c2, pdos_file in enumerate(pdos_files):
1798+ pdos_mat = np.loadtxt(pdos_file)
1799+ if c2==0:
1800+ pdos_ave = np.zeros(pdos_mat.shape)
1801+ pdos_ave += pdos_mat
1802+ pdos_ave /= cnt
1803+ pdos_ave[:,1] *= units.au2ev
1804+ e_min = np.min(pdos_ave[:,1])-shift
1805+ e_max = np.max(pdos_ave[:,1])+shift
1806+ homo_level = np.max(np.where(pdos_ave[:,2]==2.0))
1807+ homo_energy = pdos_ave[:,1][homo_level]
1808+ for c3, orbital_cols in enumerate(orbitals_cols):
1809+ try:
1810+ sum_pdos_ave = np.sum(pdos_ave[:,orbital_cols],axis=1)
1811+ ave_energy_grid, ave_pdos_convolved = gaussian_function_vector(sum_pdos_ave, pdos_ave[:,1], sigma,
17541812 npoints, e_min, e_max)
1755- ave_pdos_convolved_all .append (ave_pdos_convolved )
1756- pdos_label = atoms [1 ][c1 ]+ F', { orbitals [c3 ]} '
1757- labels .append (pdos_label )
1758- except :
1759- pass
1813+ ave_pdos_convolved_all.append(ave_pdos_convolved)
1814+ pdos_label = atoms[1][c1]+F', {orbitals[c3]}'
1815+ labels.append(pdos_label)
1816+ except:
1817+ pass
1818+ """
1819+
1820+ ave_pdos_convolved_all = np .array (ave_pdos_convolved_all )
1821+ ave_pdos_convolved_total = np .sum (ave_pdos_convolved_all , axis = 0 )
1822+
1823+ return ave_energy_grid , homo_energy , ave_pdos_convolved_all , labels , ave_pdos_convolved_total
1824+
1825+ else : # spin-polarized case
1826+ homo_occ = 1.0
1827+
1828+ labels_alp , labels_bet = [], []
1829+ ave_pdos_convolved_all_alp , ave_pdos_convolved_all_bet = [], []
1830+
1831+ for c1 ,i in enumerate (atoms [0 ]):
1832+ # Finding all the pdos files
1833+ pdos_files_alp = glob .glob (path_to_all_pdos + F'/*ALPHA*k{ i } *.pdos' )
1834+ pdos_files_bet = glob .glob (path_to_all_pdos + F'/*BETA*k{ i } *.pdos' )
1835+
1836+ ave_energy_grid_alp , homo_energy_alp , ave_pdos_convolved_all_alp = aux_pdos (c1 , atoms , pdos_files_alp , shift , homo_occ , orbitals_cols , sigma , npoints , ave_pdos_convolved_all_alp , labels_alp )
1837+
1838+ ave_energy_grid_bet , homo_energy_bet , ave_pdos_convolved_all_bet = aux_pdos (c1 , atoms , pdos_files_bet , shift , homo_occ , orbitals_cols , sigma , npoints , ave_pdos_convolved_all_bet , labels_bet )
1839+
1840+
1841+ ave_pdos_convolved_all_alp = np .array (ave_pdos_convolved_all_alp )
1842+ ave_pdos_convolved_total_alp = np .sum (ave_pdos_convolved_all_alp , axis = 0 )
1843+
1844+ ave_pdos_convolved_all_bet = np .array (ave_pdos_convolved_all_bet )
1845+ ave_pdos_convolved_total_bet = np .sum (ave_pdos_convolved_all_bet , axis = 0 )
17601846
1761- ave_pdos_convolved_all = np . array ( ave_pdos_convolved_all )
1762- ave_pdos_convolved_total = np . sum ( ave_pdos_convolved_all , axis = 0 )
1847+ return ave_energy_grid_alp , homo_energy_alp , ave_pdos_convolved_all_alp , labels_alp , ave_pdos_convolved_total_alp , \
1848+ ave_energy_grid_bet , homo_energy_bet , ave_pdos_convolved_all_bet , labels_bet , ave_pdos_convolved_total_bet
17631849
1764- return ave_energy_grid , homo_energy , ave_pdos_convolved_all , labels , ave_pdos_convolved_total
17651850
17661851
17671852def exc_analysis (params ):
0 commit comments