Exemplo n.º 1
0
        
        X = [x.imag for x in self.mesh] if isinstance(self.mesh, meshes.MeshImFreq) \
            else [x for x in self.mesh]
        
        X, data = np.array(X), self.data
        if x_window:
            # the slice due to clip option x_window
            sl = clip_array(X, *x_window) if x_window else slice(len(X))
            X, data = X[sl],  data[sl, :, :]
        if flatten_y and data.shape[1:3] == (1, 1):
            data = data[:, 0, 0]
        return X, data

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

from h5.formats import register_class, register_backward_compatibility_method
register_class (Gf)

# A backward compatility function
def bckwd(hdf_scheme):
    # we know scheme is of the form GfM1_x_M2_s/tv3
    m, t= hdf_scheme[2:], '' # get rid of Gf
    for suffix in ['_s', 'Tv3', 'Tv4'] : 
        if m.endswith(suffix) :
            m, t = m[:-len(suffix)], suffix
            break
    return { 'mesh': 'Mesh'+m, 'indices': 'GfIndices'}

register_backward_compatibility_method("Gf", "Gf", bckwd)

Exemplo n.º 2
0
        return self.n_orbitals

    @property
    def OrbitalPositions(self):
        warnings.warn(
            "TBLattice.OrbitalPositions is deprecated; use TBLattice.orbital_positions instead.",
            DeprecationWarning)
        return self.orbital_positions

    @property
    def OrbitalNames(self):
        warnings.warn(
            "TBLattice.OrbitalNames is deprecated; use TBLattice.orbital_names instead.",
            DeprecationWarning)
        return self.orbital_names

    def hopping_dict(self):
        warnings.warn(
            "TBLattice.hopping_dict() is deprecated; use TBLattice.hoppings instead.",
            DeprecationWarning)
        return self.hoppings

    def hopping(self, k):
        warnings.warn(
            "TBLattice.hopping(k) is deprecated; use TBLattice.dispersion(k) instead.",
            DeprecationWarning)
        return hopping_stack(self, k)


register_class(TBLattice)
Exemplo n.º 3
0
                out += pc_txt
            else:
                str_value = str(value)

                # Cut things that take more than five rows
                str_value_lines = str_value.splitlines()
                max_lines = 10
                if len(str_value_lines) > max_lines:
                    str_value = '\n'.join(str_value_lines[:max_lines] +
                                          ['...'])

                out += ''.join([key, ' = ', str_value]) + '\n'
        return out

    def get_my_name(self):
        ans = []
        frame = inspect.currentframe().f_back
        tmp = dict(
            list(frame.f_globals.items()) + list(frame.f_locals.items()))
        for k, var in list(tmp.items()):
            if isinstance(var, self.__class__):
                if hash(self) == hash(var):
                    ans.append(k)
        return ans


# -- Register ParameterCollection in Triqs formats

from h5.formats import register_class
register_class(ParameterCollection)
Exemplo n.º 4
0
            element = getattr(self, el)
            for ish in range(len(element)):
                s += ' shell ' + str(ish) + '\n'

                def keyfun(el):
                    return '{}_{:05d}'.format(el[0], el[1])

                keys = sorted(list(element[ish].keys()), key=keyfun)
                for k in keys:
                    s += '  ' + str(k) + str(element[ish][k]) + '\n'
        s += "deg_shells\n"
        for ish in range(len(self.deg_shells)):
            s += ' shell ' + str(ish) + '\n'
            for l in range(len(self.deg_shells[ish])):
                s += '  equivalent group ' + str(l) + '\n'
                if isinstance(self.deg_shells[ish][l], dict):
                    for key, val in list(self.deg_shells[ish][l].items()):
                        s += '   ' + key + ('*' if val[1] else '') + ':\n'
                        s += '    ' + str(val[0]).replace('\n',
                                                          '\n    ') + '\n'
                else:
                    for key in self.deg_shells[ish][l]:
                        s += '   ' + key + '\n'
        s += "transformation\n"
        s += str(self.transformation)
        return s


from h5.formats import register_class
register_class(BlockStructure)
Exemplo n.º 5
0
        maxent_result = self._get_maxent_result(maxent_result)
        idx = slice(None) if element is None else element
        return (maxent_result.alpha,
                np.column_stack((maxent_result.chi2[idx],
                                 np.exp(np.polyval(self['linefit_params'][0], np.log(maxent_result.alpha))),
                                 np.exp(np.polyval(self['linefit_params'][1], np.log(maxent_result.alpha))))),
                dict(label=r'linefit {}'.format(self['name']),
                     x_label=r'$\alpha$',
                     y_label=r'linefit',
                     log_x=True,
                     log_y=True))

try:
    from h5.formats import register_class
    register_class(AnalyzerResult)
except ImportError:  # notriqs
    pass


class Analyzer(object):
    r""" Analyzer base class

    The base class for analyzing the values :math:`A_{\alpha}` and getting
    the one true (:math:`\alpha`-independent) solution from the data.
    """

    def __init__(self, name=None, **kwargs):
        if name is None:
            self.name = self.__class__.__name__
        else:
Exemplo n.º 6
0
        r = []
        for bn, g in self:
            initial_dict = opt_dict.copy()
            r += g._plot_(initial_dict)
        self.name, name_kept = self.name, opt_dict.pop('name', self.name)
        first_g_name = self._first().name
        ylabel = r[0]['ylabel'].replace(
            first_g_name, self.name) if first_g_name else self.name
        for dic in r:
            dic['ylabel'] = ylabel  # replace the ylabel of the elements to a single ylabel
        self.name = name_kept
        return r

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

    def zero(self):
        for i, g in self:
            g.zero()

    def __check_attr(self, attr):
        if not hasattr(self._first(), attr):
            raise RuntimeError(
                "The blocks of this Green's Function do not possess the %s method"
                % attr)


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

from h5.formats import register_class
register_class(Block2Gf)
Exemplo n.º 7
0
        return self._zero_elements

    @saved
    def use_hermiticity(self):
        return self._use_hermiticity

    @saved
    def complex_elements(self):
        return self._complex_elements

    @property
    def data(self):
        """ Get a :py:class:`.MaxEntResultData` data object

        that can be saved to h5-files.
        """
        # in order to make sure that everything is saved
        try:
            d = self.__reduce_to_dict__()
            return MaxEntResultData.__factory_from_dict__(
                "MaxEntResultData", d)
        except AttributeError as e:
            raise Exception(e)


try:
    from h5.formats import register_class
    register_class(MaxEntResultData)
except ImportError:  # notriqs
    pass
Exemplo n.º 8
0
                                                 constant_shift)

        self._calculate_Gaux_iw()

    def _calculate_Gaux_iw(self):
        def _calculate_gaux_iw(g):
            g[1] << Omega + self._constant_shift[g[0]] - g[1]
            g[1].invert()

        self.Gaux_iw = self.S_iw.copy()
        list(map(_calculate_gaux_iw,
                 self.Gaux_iw)) if self._BlockGf else _calculate_gaux_iw(
                     ('0', self.Gaux_iw))

    def _calculate_S_w(self):
        def _calculate_s_w(s):
            s[1] << Omega + self._constant_shift[s[0]] - inverse(s[1])

        self.S_w = self.Gaux_w.copy()
        list(map(_calculate_s_w,
                 self.S_w)) if self._BlockGf else _calculate_s_w(
                     ('0', self.S_w))


try:
    from h5.formats import register_class
    register_class(InversionSigmaContinuator)
    register_class(DirectSigmaContinuator)
except ImportError:  # notriqs
    pass
Exemplo n.º 9
0
    def __repr__(self):
        """ """
        return "MeshProduct of :" + ', '.join(repr(x) for x in self._mlist)

    def __str__(self):
        """ """
        return ', '.join(str(x) for x in self._mlist)

   #-----------------------------  IO  -----------------------------------

    def __reduce__(self):
        return call_factory_from_dict, (self.__class__, "", self.__reduce_to_dict__())

    def __reduce_to_dict__(self):
        return dict (('MeshComponent%s'%i, m) for i,m in enumerate(self._mlist))

    # @classmethod
    # def __factory_from_dict__(cls, l):
        # return cls(*l)

    @classmethod
    def __factory_from_dict__(cls, name, d):
        return cls(*(d['MeshComponent%s'%i] for i in range(len(d)))) #.values())


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

from h5.formats import register_class
register_class (MeshProduct)

Exemplo n.º 10
0
Arquivo: dos.py Projeto: DerWeh/triqs
        """
        assert callable(function), "function is not callable"
        self.function,self.x_min,self.x_max = function,x_min,x_max
        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(n_pts) # compute arrays
        DOS.__init__(self,self.eps,self.rho,name) 
        
    #-------------------------------------------------------------
    
    def __reduce__(self) : 
        return  self.__class__, (self.function,self.x_min, self.x_max, len(self.eps), self.name)
    
    #-------------------------------------------------------------
  
    def __f(self,N) :
        r = (self.x_max - self.x_min)/float(N-1)
        self.eps  = numpy.array( [self.x_min + r* i for i in range(N) ] )
        self.rho  = numpy.array( [self.function(e) for e in self.eps])

#-----------------------------------------------------
#  Register the class for HDFArchive
#-----------------------------------------------------

from h5.formats import register_class
register_class (DOS)