3
0
mirror of https://github.com/triqs/dft_tools synced 2024-10-31 19:23:45 +01:00

Add new python operators

For now they are called operators2.
This commit is contained in:
Michel Ferrero 2014-05-21 16:35:33 +02:00
parent df09891219
commit 76aa6120e9
2 changed files with 56 additions and 0 deletions

View File

@ -6,4 +6,5 @@ SET(PYTHON_SOURCES
install (FILES ${PYTHON_SOURCES} DESTINATION ${TRIQS_PYTHON_LIB_DEST}/operators) install (FILES ${PYTHON_SOURCES} DESTINATION ${TRIQS_PYTHON_LIB_DEST}/operators)
triqs_python_extension(operators2 operators)

View File

@ -0,0 +1,55 @@
from wrap_generator import *
# The operator class
op = class_(
py_type = "Operator",
c_type = "many_body_operator<double>",
is_printable= True,
arithmetic = ("algebra","double")
)
op.add_constructor(signature="()", doc="create zero operator")
# Complete the number_protocol
mbo = 'many_body_operator<double>'
scal = 'double'
# Allow + and - between scalar and operator
add = op.number_protocol['add']
add.add_overload (calling_pattern = "+", args = [(mbo,'x'), (scal,'y')], rtype = mbo)
add.add_overload (calling_pattern = "+", args = [(scal,'x'), (mbo,'y')], rtype = mbo)
sub = op.number_protocol['subtract']
sub.add_overload (calling_pattern = "-", args = [(mbo,'x'), (scal,'y')], rtype = mbo)
sub.add_overload (calling_pattern = "-", args = [(scal,'x'), (mbo,'y')], rtype = mbo)
# Allow unary - on an operator
neg = pyfunction(py_name = "__neg__")
neg.arity = 1
neg.add_overload (calling_pattern = "-", args = [(mbo,'x')], rtype = mbo)
op.number_protocol['negative'] = neg
# The many_body_operators module
module = module_(full_name = "operators2", doc = "Doc of my_module")
module.add_include("<triqs/operators/many_body_operator.hpp>")
module.add_include("<triqs/arrays.hpp>")
module.add_using("namespace triqs::utility")
module.add_class(op)
# Annihilation operators
module.add_function(name = "c", signature="many_body_operator<double>(std::string ind1)", doc="annihilation operator")
module.add_function(name = "c", signature="many_body_operator<double>(std::string ind1, std::string ind2)", doc="annihilation operator")
module.add_function(name = "c", signature="many_body_operator<double>(std::string ind1, int i)", doc="annihilation operator")
module.add_function(name = "c", signature="many_body_operator<double>(int i, std::string ind1)", doc="annihilation operator")
module.add_function(name = "c", signature="many_body_operator<double>(int i, int j)", doc="annihilation operator")
# Construction operators
module.add_function(name = "c_dag", signature="many_body_operator<double>(std::string ind1)", doc="annihilation operator")
module.add_function(name = "c_dag", signature="many_body_operator<double>(std::string ind1, std::string ind2)", doc="annihilation operator")
module.add_function(name = "c_dag", signature="many_body_operator<double>(std::string ind1, int i)", doc="annihilation operator")
module.add_function(name = "c_dag", signature="many_body_operator<double>(int i, std::string ind1)", doc="annihilation operator")
module.add_function(name = "c_dag", signature="many_body_operator<double>(int i, int j)", doc="annihilation operator")
# to generate the module code
if __name__ == '__main__' :
module.generate_code(mako_template = sys.argv[1], wrap_file = sys.argv[2])