diff --git a/xrayutilities/gridder.py b/xrayutilities/gridder.py index 446eee0b..61e76c3b 100644 --- a/xrayutilities/gridder.py +++ b/xrayutilities/gridder.py @@ -25,11 +25,6 @@ from . import config, cxrayutilities, utilities from .exception import InputError -try: # works in Python >3.4 - ABC = abc.ABC -except: # Python 2.7 - ABC = abc.ABCMeta('ABC', (object, ), {'__slots__': ()}) - def delta(min_value, max_value, n): """ @@ -75,7 +70,7 @@ def ones(*args): return numpy.ones(args, dtype=numpy.double) -class Gridder(ABC): +class Gridder(utilities.ABC): """ Basis class for gridders in xrayutilities. A gridder is a function mapping irregular spaced data onto a regular grid by binning the data into equally diff --git a/xrayutilities/materials/material.py b/xrayutilities/materials/material.py index 457916da..000cd7d7 100644 --- a/xrayutilities/materials/material.py +++ b/xrayutilities/materials/material.py @@ -23,7 +23,7 @@ materials their crystalline state is defined few materials are also included as amorphous which can be useful for calculation of their optical properties. """ - +import abc import copy import numbers import operator @@ -120,7 +120,7 @@ def Cijkl2Cij(cijkl): return cij -class Material(object): +class Material(utilities.ABC): """ base class for all Materials. common properties of amorphous and crystalline materials are described by this class from which Amorphous and @@ -176,10 +176,20 @@ def _getdensity(self): lam = property(_getlam) nu = property(_getnu) + @abc.abstractmethod def delta(self, en='config'): + """ + abstract method which every implementation of a Material has to + override + """ pass + @abc.abstractmethod def ibeta(self, en='config'): + """ + abstract method which every implementation of a Material has to + override + """ pass def chi0(self, en='config'): diff --git a/xrayutilities/simpack/darwin_theory.py b/xrayutilities/simpack/darwin_theory.py index 42e96e32..f614f6f1 100644 --- a/xrayutilities/simpack/darwin_theory.py +++ b/xrayutilities/simpack/darwin_theory.py @@ -14,7 +14,7 @@ # along with this program; if not, see . # # Copyright (C) 2016 Dominik Kriegner - +import abc import collections import copy import warnings @@ -24,7 +24,7 @@ from scipy.misc import derivative from . import LayerModel -from .. import materials +from .. import materials, utilities from ..math import heaviside @@ -112,7 +112,7 @@ def __init__(self, qz, qx=0, qy=0, **kwargs): super(LayerModel, self).__init__(exp, **kwargs) self.npoints = len(qz) - self.qz = qz + self.qz = numpy.asarray(qz) self.qinp = (qx, qy) if self.qinp != (0, 0): raise NotImplementedError('asymmetric CTR simulation is not yet ' @@ -242,7 +242,7 @@ def _recur_sim(self, nrep, ml, r, rbar, t, pol): return r, rbar, t -class DarwinModelAlloy(DarwinModel): +class DarwinModelAlloy(DarwinModel, utilities.ABC): """ extension of the DarwinModel for an binary alloy system were one parameter is used to determine the chemical composition @@ -251,11 +251,11 @@ class DarwinModelAlloy(DarwinModel): get_dperp_apar() method and define the substrate lattice parameter (asub). See the DarwinModelSiGe001 class for an implementation example. """ - @classmethod - def get_dperp_apar(cls, x, apar, r=1): + @abc.abstractmethod + def get_dperp_apar(self, x, apar, r=1): """ calculate inplane lattice parameter and the out of plane lattice plane - spacing (of the atomic planes!) from composition and relaxation + spacing (of the atomic planes!) from composition and relaxation. Parameters ---------- @@ -269,7 +269,7 @@ def get_dperp_apar(cls, x, apar, r=1): ------- dperp, apar """ - pass + raise NotImplementedError("abstract method needs to be overwritten") def make_monolayers(self, s): """ diff --git a/xrayutilities/simpack/models.py b/xrayutilities/simpack/models.py index 65209fd5..f2bfd12e 100644 --- a/xrayutilities/simpack/models.py +++ b/xrayutilities/simpack/models.py @@ -15,6 +15,8 @@ # # Copyright (C) 2016 Dominik Kriegner +import abc + import numpy import scipy.constants as constants import scipy.interpolate as interpolate @@ -124,7 +126,7 @@ def scale_simulation(self, y): return y * self.I0 + self.background -class LayerModel(Model): +class LayerModel(Model, utilities.ABC): """ generic model class from which further thin film models can be derived from """ @@ -150,6 +152,14 @@ def __init__(self, *args, **kwargs): self.lstack = LayerStack('Stack for %s' % self.__class__.__name__, *args) + @abc.abstractmethod + def simulate(self): + """ + abstract method that every implementation of a LayerModel has to + override + """ + pass + def _create_return(self, x, E, ai=None, af=None, Ir=None, rettype='intensity'): """ diff --git a/xrayutilities/utilities_noconf.py b/xrayutilities/utilities_noconf.py index 01a20e0b..fd5d08eb 100644 --- a/xrayutilities/utilities_noconf.py +++ b/xrayutilities/utilities_noconf.py @@ -20,6 +20,7 @@ this part of utilities does not need the config class """ +import abc import numbers import os.path @@ -28,6 +29,11 @@ from .exception import InputError +try: # works in Python >3.4 + ABC = abc.ABC +except: # Python 2.7 + ABC = abc.ABCMeta('ABC', (object, ), {'__slots__': ()}) + # python 2to3 compatibility try: basestring