""" catima python module ~~~~~~~~~~~ This module provides interface to the catima c++ library :copyright: (c) 2017 by Andrej Prochazka :licence: GNU Affero General Public License, see LICENCE for more details """ cimport catimac from enum import IntEnum import numpy cdef class Material: cdef catimac.Material cbase def __cinit__(self, elements=None, thickness=None, density=None): self.cbase = catimac.Material() if(elements and (isinstance(elements[0],float) or isinstance(elements[0],int))): self.cbase.add_element(elements[0],elements[1],elements[2]) if(elements and isinstance(elements[0],list)): for e in elements: self.cbase.add_element(e[0],e[1],e[2]) if(not thickness is None): self.thickness(thickness) if(not density is None): self.density(density) cdef from_c(self, catimac.Material &other): self.cbase = other cdef catimac.Material getc(self): cdef catimac.Material res res = self.cbase return res def copy(self): res = Material() res.cbase = self.cbase return res def add_element(self, a, z , s): self.cbase.add_element(a, z, s) def ncomponents(self): return self.cbase.ncomponents() def molar_mass(self): return self.cbase.M() def M(self): return self.cbase.M() def density(self, val=None): if(val is None): return self.cbase.density() else: return self.cbase.density(val) def thickness(self, val=None): if(val is None): return self.cbase.thickness() else: return self.cbase.thickness(val) class material(IntEnum): PLASTIC = 201 AIR = 202 CH2 = 203 LH2 = 204 LD2 = 205 WATER = 206 DIAMOND = 207 GLASS = 208 ALMG3 = 209 ARCO2_30 = 210 CF4 = 211 ISOBUTANE = 212 KAPTON = 213 MYLAR = 214 NAF = 215 P10 = 216 POLYOLEFIN = 217 CMO2 = 218 SUPRASIL = 219 HAVAR = 220 def get_material(int matid): res = Material() cdef catimac.Material cres = catimac.get_material(matid); res.from_c(cres) return res cdef class Target: cdef catimac.Target cbase def __cinit__(self,a,z): self.cbase.A = a self.cbase.Z = z def A(self): return self.cbase.A def Z(self): return self.cbase.Z cdef class Layers: cdef public: materials def __init__(self): self.materials=[] def add(self,Material m): self.materials.append(m.copy()) def num(self): return len(self.materials) def get(self, key): return self.materials[key] def __getitem__(self, key): if(isinstance(key,int) and key