Example #1
0
        import GFBloc_ReFreq
        om0 = 2*pi/(self.TimeMax - self.TimeMin)
        N = self.Npts
        gw = GFBloc_ReFreq.GFBloc_ReFreq(Indices = self.Indices,Beta = self.Beta,
                                         Statistic = self.Statistic,
                                         MeshArray = numpy.array([ om0*i for i in range (- (N/2),N/2)]))
        gw.setFromFourierOf(self)
        return gw
                
    #-----------------------------------------------------

    def _plot_(self, OptionsDict):
        """ Plot protocol. OptionsDict can contain : 
             * :param RI: 'R', 'I', 'RI' [ default] 
             * :param x_window: (xmin,xmax) or None [default]
             * :param Name: a string [default ='']. If not '', it remplaces the name of the function just for this plot.
        """
        M = [x for x in self.mesh]
        return self._plot_base( OptionsDict,  r'$t$', lambda name : r'%s$(t)$'%name, True, M)
 
#-----------------------------------------------------
#  Register the class for HDF_Archive
#-----------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class (GFBloc_ReTime)



 
Example #2
0
           # This is the function to be minimized, the diff between the original
           # data in values and the fitting function
           def fct(p):
             y_fct = 1.0*f_known
             for order in range(len_param):
               y_fct += p[order]*omegas**(1-len(known_coef[n1][n2])-order)
             y_fct -= values[n1,n2,:]
             return abs(y_fct)

           # Now call the minimizing function
           sol = leastsq(fct, p0, maxfev=1000*len_param)

           # Put the known and the new found moments in the tail
           for order in range(len(known_coef[n1][n2])):
             self._tail[order-1][indR,indL] = [[ known_coef[n1][n2][order] ]]
           for order, moment in enumerate(sol[0]):
             self._tail[len(known_coef[n1][n2])+order-1][indR,indL] = [[ moment ]]

       # Replace then end of the GF by the tail
       if replaceTail: self.replaceByTail(ninit);


#-----------------------------------------------------
#  Register the class for HDF_Archive
#-----------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class (GFBloc_ImFreq)


Example #3
0
    def InverseFourier(self, TimeMin=None):
        """
           Returns a GFBloc_ReTime containing the Inverse Fourier transform of self
           TimeMin is the minimal time. By default the time window is centered around 0
        """
        import GFBloc_ReTime
        (a, b), N = list(self.mesh)[0:2], len(self.mesh)
        om0 = b - a
        if TimeMin != None:
            TimeMax = TimeMin + 2 * pi / om0
        else:
            TimeMax = pi / om0
            TimeMin = -TimeMax
        gt = GFBloc_ReTime.GFBloc_ReTime(Indices=self.Indices,
                                         Beta=self.Beta,
                                         Statistic=self.Statistic,
                                         TimeMin=TimeMin,
                                         TimeMax=TimeMax,
                                         NTimeSlices=N)
        gt.setFromInverseFourierOf(self)
        return gt


#-----------------------------------------------------
#  Register the class for HDF_Archive
#-----------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class(GFBloc_ReFreq)
Example #4
0
                                       numpy.array([ (n+0.5)*Beta/Nmax for n in range(Nmax)]))
            for a in [ 'Beta', 'Statistic', 'NTimeSlices'] : 
                if a in d : del d[a]
        else : 
            assert d['Mesh'].TypeGF==GF_Type.Imaginary_Time, "You provided a wrong type of mesh !!"
            
        self._init_base__(d)
        self._init_before_injection__(*self._param_for_cons)
        del self._param_for_cons
                
    #-----------------------------------------------------

    def _plot_(self, OptionsDict):
        """ Plot protocol. OptionsDict can contain : 
             * :param RI: 'R', 'I', 'RI' [ default] 
             * :param x_window: (xmin,xmax) or None [default]
             * :param Name: a string [default ='']. If not '', it remplaces the name of the function just for this plot.
        """
        has_complex_value = False
        M = [x for x in self.mesh]
        return self._plot_base( OptionsDict,  r'$\tau$', lambda name : r'%s$(\tau)$'%name, has_complex_value , M)
 
#-----------------------------------------------------
#  Register the class for HDF_Archive
#-----------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class (GFBloc_ImTime)


Example #5
0
    #-----------------------------------------------------

    def InverseFourier(self, TimeMin =None) : 
        """
           Returns a GFBloc_ReTime containing the Inverse Fourier transform of self
           TimeMin is the minimal time. By default the time window is centered around 0
        """
        import GFBloc_ReTime
        (a,b),N = list(self.mesh)[0:2], len(self.mesh)
        om0 = b-a
        if TimeMin !=None :
            TimeMax = TimeMin + 2* pi/om0
        else :
            TimeMax = pi/om0
            TimeMin = -TimeMax
        gt = GFBloc_ReTime.GFBloc_ReTime( Indices = self.Indices,Beta = self.Beta,
                                          Statistic = self.Statistic,
                                          TimeMin = TimeMin, TimeMax = TimeMax,NTimeSlices = N )
        gt.setFromInverseFourierOf(self)
        return gt


#-----------------------------------------------------
#  Register the class for HDF_Archive
#-----------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class (GFBloc_ReFreq)
 
 
Example #6
0
    def __reduce_to_dict__(self) : 
        return dict( [ (_my_str(n),v) for (n,v) in  enumerate (self.ob)])
    @classmethod
    def __factory_from_dict__(cls,D) :
        return tuple([x for (n,x) in sorted(D.items())])

class PythonDictWrap:
    def __init__(self,ob) : 
        self.ob = ob
    def __reduce_to_dict__(self) : 
        return dict( [ (str(n),v) for (n,v) in self.ob.items()])
    @classmethod
    def __factory_from_dict__(cls,D) :
        return dict([(n,x) for (n,x) in D.items()])

register_class (PythonListWrap)
register_class (PythonTupleWrap)
register_class (PythonDictWrap)

# -------------------------------------------
#
#  A view of a subgroup of the archive 
#
# --------------------------------------------

class HDF_Archive_group (HDF_Archive_group_basic_layer) : 
    """
    """
    _wrappedType = { type([]) : PythonListWrap, type(()) : PythonTupleWrap, type({}) : PythonDictWrap}
    _MaxLengthKey = 500
Example #7
0
        """
        assert callable(Function), "Function is not callable"
        self.Function,self.xmin,self.xmax = Function,xmin,xmax
        try :
            e = Function(0.001)
            len(numpy.array(e).shape) ==1
        except :
            raise RuntimeError , "Value of the function must be a 1d-array"
        self.__f(Npts) # compute arrays
        DOS.__init__(self,self.eps,self.rho,Name) 
        
    #-------------------------------------------------------------
    
    def __reduce__(self) : 
        return  self.__class__, (self.Function,self.xmin, self.xmax, len(self.eps), self.Name)
    
    #-------------------------------------------------------------
  
    def __f(self,N) :
        r = (self.xmax - self.xmin)/float(N-1)
        self.eps  = numpy.array( [self.xmin + r* i for i in range(N) ] )
        self.rho  = numpy.array( [self.Function(e) for e in self.eps])

#-----------------------------------------------------
#  Register the class for HDF_Archive
#-----------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class (DOS)

Example #8
0
    def __init__(self,l=None) :
        if l : 
          self.b = l

    def __str__(self): 
        return """
        b = %s"""%(self.a,self.b)

    def __write_hdf5__(self,archive, path) : 
        archive.write("%s"%path,self.b)

    def __read_hdf5__(self,archive, path) : 
        self.b = archive.read ("%s"%path)

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class (test_p2)
register_class (test_p2B)

h = HDF_Archive('ExampleTestH5-2.output.h5','w')

t1 = test_p2(1)
t2 = test_p2(2)
h['t'] = t1
h['t'] = t2
h['B'] = test_p2B(123)

h = HDF_Archive('ExampleTestH5-2.output.h5','r')
print h['t']
print h['B']

        
        return self.__class__( 
                Indices = list(self.Indices),
                Mesh  = self.mesh,
                Data = self._data.array.conjugate(), 
                Tail = self._tail.conjugate(self.mesh.TypeGF==GF_Type.Imaginary_Frequency),
                Name = self.Name+'*', 
                Note = self.Note)

    #-----------------------------------------------------

    # Put it out a a free funciton in a module. Nothing to do here...
    # why is this here ???
    def Delta(self) :
        """Computes Delta from self ...."""
        if self.mesh.TypeGF not in [GF_Type.Real_Frequency, GF_Type.Imaginary_Frequency] :
            raise RuntimeError, "Can not compute Delta for this GF"
        G0 = self if self._tail.OrderMin <=-1 else inverse(self)
        tmp = G0.copy()
        tmp <<= GF_Initializers.A_Omega_Plus_B(G0._tail[-1], G0._tail[0])
        tmp -= G0
        return tmp

#-----------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class (TailGF)
register_class (MeshGF)


Example #10
0
    #-----------------------------------------------------

    def copy_and_truncate(self, Nleg):
        """ Copies the Legendre Green's function and truncates it down

        Parameters
        ----------
        Nleg : int
          remaining number of Legendre coefficients after truncation
        """
        new_g = self.__class__(IndicesL = self._IndicesL,
                               IndicesR = self._IndicesR,
                               Beta = self.Beta,
                               Statistic = self.Statistic,
                               NLegendreCoeffs = Nleg,
                               Name = self.Name, Note = self.Note)
        new_g._data.array[:,:,:] = self._data.array[:,:,0:Nleg]
        new_g.determine_tail()
        return new_g


#-----------------------------------------------------
#  Register the class for HDF_Archive
#-----------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class (GFBloc_ImLegendre)


Example #11
0
    def __check_attr(self,ATTR) :
        if not hasattr(self._first(), ATTR ) :
           raise RuntimeError, "The blocks of this Green Function do not possess the %s method"%ATTR

    def invert(self) : 
       """Inverse all the blocks"""
       self.__check_attr("invert")
       for i,g in self : g.invert()

    def Delta(self) :
       """Compute Delta from G0"""
       self.__check_attr("Delta")
       return self.__class__( Name_Block_Generator = [ (n, g.Delta()) for n,g in self], Copy=False)

    def transpose(self):
       """Transpose of the GF"""
       self.__check_attr("transpose")
       return self.__class__( Name_Block_Generator = [ (n, g.transpose()) for n,g in self], Copy=False)

    def conjugate(self):
       """Conjugate of the GF"""
       self.__check_attr("conjugate")
       return self.__class__( Name_Block_Generator = [ (n, g.conjugate()) for n,g in self], Copy=False)

#---------------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class (GF)

Example #12
0
File: DOS.py Project: xydeng/TRIQS
        self.Function, self.xmin, self.xmax = Function, xmin, xmax
        try:
            e = Function(0.001)
            len(numpy.array(e).shape) == 1
        except:
            raise RuntimeError, "Value of the function must be a 1d-array"
        self.__f(Npts)  # compute arrays
        DOS.__init__(self, self.eps, self.rho, Name)

    #-------------------------------------------------------------

    def __reduce__(self):
        return self.__class__, (self.Function, self.xmin, self.xmax,
                                len(self.eps), self.Name)

    #-------------------------------------------------------------

    def __f(self, N):
        r = (self.xmax - self.xmin) / float(N - 1)
        self.eps = numpy.array([self.xmin + r * i for i in range(N)])
        self.rho = numpy.array([self.Function(e) for e in self.eps])


#-----------------------------------------------------
#  Register the class for HDF_Archive
#-----------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class

register_class(DOS)
Example #13
0
                # data in values and the fitting function
                def fct(p):
                    y_fct = 1.0 * f_known
                    for order in range(len_param):
                        y_fct += p[order] * omegas**(
                            1 - len(known_coef[n1][n2]) - order)
                    y_fct -= values[n1, n2, :]
                    return abs(y_fct)

                # Now call the minimizing function
                sol = leastsq(fct, p0, maxfev=1000 * len_param)

                # Put the known and the new found moments in the tail
                for order in range(len(known_coef[n1][n2])):
                    self._tail[order - 1][indR,
                                          indL] = [[known_coef[n1][n2][order]]]
                for order, moment in enumerate(sol[0]):
                    self._tail[len(known_coef[n1][n2]) + order -
                               1][indR, indL] = [[moment]]

        # Replace then end of the GF by the tail
        if replaceTail: self.replaceByTail(ninit)


#-----------------------------------------------------
#  Register the class for HDF_Archive
#-----------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class(GFBloc_ImFreq)
Example #14
0
            Indices=list(self.Indices),
            Mesh=self.mesh,
            Data=self._data.array.conjugate(),
            Tail=self._tail.conjugate(
                self.mesh.TypeGF == GF_Type.Imaginary_Frequency),
            Name=self.Name + '*',
            Note=self.Note)

    #-----------------------------------------------------

    # Put it out a a free funciton in a module. Nothing to do here...
    # why is this here ???
    def Delta(self):
        """Computes Delta from self ...."""
        if self.mesh.TypeGF not in [
                GF_Type.Real_Frequency, GF_Type.Imaginary_Frequency
        ]:
            raise RuntimeError, "Can not compute Delta for this GF"
        G0 = self if self._tail.OrderMin <= -1 else inverse(self)
        tmp = G0.copy()
        tmp <<= GF_Initializers.A_Omega_Plus_B(G0._tail[-1], G0._tail[0])
        tmp -= G0
        return tmp


#-----------------------------------------------------

from pytriqs.Base.Archive.HDF_Archive_Schemes import register_class
register_class(TailGF)
register_class(MeshGF)