Ejemplo n.º 1
0
    def read(self, filename, mesh=None, vfactor=1.0): #volume factor is used to determine the actual volume of 2D materials like graphene
        r=h5py.File(filename)
        all_ts=r['temperature'].value
        if self._ts==None:
            self._ts=all_ts
        for t in self._ts:
            if not t in all_ts:
                print_error_message("The temperatures you have chosen are beyond the range")
        t_pos=np.where(self._ts.reshape(-1,1)==all_ts)[1]
        self._frequency=r['frequency'].value
        self._natom=self._frequency.shape[-1]/3
        assert self._natom == self._cell.get_number_of_atoms(),\
            "natom in POSCAR:%d, natom in kappa file%d"%(self._natom, self._cell.get_number_of_atoms())

        self._gamma=r['gamma'].value[:,t_pos,:]
        self._kappa=r['kappa'].value[:,t_pos,:] * vfactor
        if mesh==None:
            self._mesh=np.rint([np.power(r['weight'].value.sum(), 1./3.),]*3).astype("intc")
        else:
            self._mesh=mesh
        self._heat_capacity=r['heat_capacity'].value[:,t_pos]
        self._weight=r['weight'].value

        if np.prod(self._mesh) != self._weight.sum():
            print "The mesh generated is not consistend with the one read from %s" %filename
            print "You can manually specify the mesh in the command line (--mesh)"
            sys.exit(1)
        rec_lat = np.linalg.inv(self._frame)
        qs=r['qpoint'].value
        self._qpoints=np.dot(rec_lat, qs.T).T
        self._gv=r['group_velocity'].value
        if "gamma_N" in r.keys() and "gamma_U" in r.keys():
            self._gamma_N=r['gamma_N'].value[:,t_pos,:]
            self._gamma_U=r['gamma_U'].value[:,t_pos,:]
        r.close()
Ejemplo n.º 2
0
 def set_iso_gamma(self, filename):
     if filename is not None:
         self._iso_gamma=np.zeros_like(self._gamma)
         f=h5py.File(filename)
         if "temperature" in f.keys():
             all_ts = f['temperature'][:]
             for t in self._ts:
                 if not t in all_ts:
                     print_error_message("The temperature %f you specified is not commensurate with those in the iso_gamma file"%t)
             t_pos=np.where(self._ts.reshape(-1,1)==all_ts)[1]
             gamma_iso=f['gamma_iso'].value[:,t_pos,:]
             assert gamma_iso.shape[0] == self._frequency.shape[0], "The gamma array in the isotope file should be the same as the one in kappa file"
             self._iso_gamma = gamma_iso
         else:
             gamma_iso = f['gamma_iso'].value
             assert gamma_iso.shape == self._frequency.shape, "The gamma array in the isotope file should be the same as the one in kappa file"
             for i, t in enumerate(self._ts):
                 self._iso_gamma[:,i,:]=gamma_iso
         f.close()
Ejemplo n.º 3
0
 def cast_one(self):
     if self._screen is None:
         print_error_message("The casting parameter is set incorrectly!")
     self._cast = np.zeros((self._seg, 2), dtype="double")
     if self._dest != "K":
         desti = self._projector * self._tc._weight.reshape(-1, 1)
     else:
         desti = self._projector
     pro = self._screen
     assert desti.shape == pro.shape, "Shape of %2s and shape of %2s does not match" % (
         self._dest, self._property)
     if self._is_fix_sigma:
         self._real_sigma = self._sigma
     else:
         self._real_sigma = self._sigma * (pro.max() - pro.min()) / 100
     self._cast[:, 0] = allocate_space(pro,
                                       self._seg,
                                       is_log=self._is_log[0],
                                       sigma=self._real_sigma)
     if self._lang == "C":
         try:
             import _kthin as kt
             kt.distribution(pro.copy(), desti.copy(), self._cast,
                             self._real_sigma)
             pass
         except ImportError:
             print_warning_message(
                 "the C module _kthin is not imported, python is used instead"
             )
             distribution_py(pro,
                             desti.copy(),
                             self._cast,
                             sigma=self._real_sigma)
     elif self._lang == "P":
         distribution_py(pro, desti, self._cast, sigma=self._real_sigma)
     if self._is_cumulative:
         x = self._cast[:, 0]
         y = self._cast[:, 1]
         self._cast[0, 1] = 0
         self._cast[1:, 1] = np.cumsum(
             (x[1:] - x[:-1]) * (y[1:] + y[:-1]) / 2)
Ejemplo n.º 4
0
 def __init__(self, kbulk, rough=None, specularity=None, group_velocity=None, language="C"):
     self.copy(kbulk)
     self._gamma_bulk=kbulk._gamma
     self._kbulk=kbulk
     self.set_heat_capacity()
     if group_velocity is not None:
         self.get_gv_from(group_velocity)
     else:
         print_error_message("gv shift file is not provided")
     self._is_rough=False
     self._rough=None
     self._language=language
     if specularity==None:
         if rough==None:
             self._specularity=np.array([0.])
         else:
             self._is_rough=True
             self._rough=rough
             self._specularity=None
     else:
         self._specularity=specularity
Ejemplo n.º 5
0
 def statistical_distribution(self):
     if self._screen is None:
         print_error_message("The casting parameter is set incorrectly!")
     self._cast = np.zeros((self._seg, 2), dtype="double")
     if self._dest != "K":
         desti = self._projector * self._tc._weight.reshape(-1, 1)
     else:
         desti = self._projector
     pro = self._screen
     assert desti.shape == pro.shape, "Shape of %2s and shape of %2s does not match" % (
         self._dest, self._property)
     xseg = allocate_space(pro, self._seg, is_log=self._is_log[0])
     yseg = np.zeros_like(xseg)
     self._cast[:, 0] = xseg
     for i in np.arange(1, self._seg):
         yseg[i] = desti[np.where((xseg[i - 1] <= pro)
                                  & (pro < xseg[i]))].sum()
     if self._is_cumulative:
         self._cast[:, 1] = np.cumsum(yseg)
     else:
         self._cast[:, 1] = yseg