<commit_before>#!/usr/bin/env python

import numpy
from xcfun_swig import *

class XcFunException(Exception):
    def __init__ (self, msg, code=1) :
       Exception.__init__(self, msg)
       self.error_code = code

def xc_new_functional() :
    return xc_new_functional_not_macro(XCFUN_API_VERSION)

def xc_eval_setup(fun, var, mode, order) :
    code = xc_eval_setup_swig (fun, var, mode, order)
    if code > 0 :
        raise XcFunException("Invalid options in xc_eval_setup", code)

def xc_eval(fun, density) :

     dens_len = xc_input_length(fun)
     output_len = xc_output_length(fun)

     if not ((density.shape[-1] == dens_len)) :
         raise XcFunException('wrong dimension of density argument')

     if len(density.shape) == 1 :
         output = numpy.zeros(output_len)
         xc_eval_swig (fun,  density, output)

     elif len(density.shape) == 2 :
         nr_points = density.shape[0]
         output = numpy.zeros((nr_points, output_len))
         xc_eval_vec_swig (fun, density, output)

     else :
         raise XcFunException('wrong shape of density argument')

     return output

class Functional(object) :
    """
    Python class representing an XCFun functional.
    """

    def __init__ (self, funcdict) :
        """
        Initialize the functional.

        funclist is a dictonary containing functional names and corresponding coefficients.
        Examples:
            lda_func = Functional({'LDA': 1.0})
            blyp_func = Functional({'BeckeX': 1.0, 'LYPC': 1.0})
        """
        self._func = xc_new_functional()
        for (name, weight) in funcdict.iteritems():
            xc_set(self._func, name, weight)

    def __del__ (self) :
        xc_free_functional(self._func)

    def eval_potential_n (self, density, densgrad=None, denshess=None) :
        """
        Evaluate the xc potential (spin-compensated case).<commit_msg>adding function to communicate the class of a functional<commit_after>#!/usr/bin/env python

import numpy
from xcfun_swig import *

class XcFunException(Exception):
    def __init__ (self, msg, code=1) :
       Exception.__init__(self, msg)
       self.error_code = code

def xc_new_functional() :
    return xc_new_functional_not_macro(XCFUN_API_VERSION)

def xc_eval_setup(fun, var, mode, order) :
    code = xc_eval_setup_swig (fun, var, mode, order)
    if code > 0 :
        raise XcFunException("Invalid options in xc_eval_setup", code)

def xc_eval(fun, density) :

     dens_len = xc_input_length(fun)
     output_len = xc_output_length(fun)

     if not ((density.shape[-1] == dens_len)) :
         raise XcFunException('wrong dimension of density argument')

     if len(density.shape) == 1 :
         output = numpy.zeros(output_len)
         xc_eval_swig (fun,  density, output)

     elif len(density.shape) == 2 :
         nr_points = density.shape[0]
         output = numpy.zeros((nr_points, output_len))
         xc_eval_vec_swig (fun, density, output)

     else :
         raise XcFunException('wrong shape of density argument')

     return output

class Functional(object) :
    """
    Python class representing an XCFun functional.
    """

    def __init__ (self, funcdict) :
        """
        Initialize the functional.

        funclist is a dictonary containing functional names and corresponding coefficients.
        Examples:
            lda_func = Functional({'LDA': 1.0})
            blyp_func = Functional({'BeckeX': 1.0, 'LYPC': 1.0})
        """
        self._func = xc_new_functional()
        for (name, weight) in funcdict.iteritems():
            xc_set(self._func, name, weight)

    def __del__ (self) :
        xc_free_functional(self._func)

    def get_type (self):
        if xc_is_metagga(self._func):
            return 2
        elif xc_is_gga(self._func):
            return 1
        else :
            return 0

    def eval_potential_n (self, density, densgrad=None, denshess=None) :
        """
        Evaluate the xc potential (spin-compensated case).
{'fraction_non_alphanumeric': 0.10112640801001252, 'fraction_numerical': 0.006758448060075094, 'mean_word_length': 2.6761729530818767, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2433534', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1254, 'n_words': 319}