Пример #1
0
    def __init__(self, name, stru):
        """Initialize

        name    --  A name for this
        stru    --  A CCTBX structure instance.

        """
        ParameterSet.__init__(self, name)
        self.stru = stru
        self.addParameterSet(CCTBXUnitCellParSet(self))
        self.scatterers = []

        self._update = False

        cdict = {}
        for s in stru.scatterers():
            el = s.element_symbol()
            i = cdict.get(el, 0)
            sname = "%s%i" % (el, i)
            cdict[el] = i + 1
            scatterer = CCTBXScattererParSet(sname, self, i)
            self.addParameterSet(scatterer)
            self.scatterers.append(scatterer)

        # Constrain the lattice
        from diffpy.srfit.structure.sgconstraints import _constrainSpaceGroup
        symbol = self.getSpaceGroup()
        _constrainSpaceGroup(self, symbol)

        return
 def __init__(self, name):
     """Initialize the attributes."""
     Operator.__init__(self)
     ParameterSet.__init__(self, name)
     self.profile = None
     self.meta = {}
     return
Пример #3
0
    def __init__(self, name):
        ParameterSet.__init__(self, name)
        self.meta = {}

        # Initialize Operator attributes
        Operator.__init__(self, name, name, self.operation, -1, 1)
        return
Пример #4
0
    def __init__(self, name, stru):
        """Initialize

        name    --  A name for this
        stru    --  A CCTBX structure instance.

        """
        ParameterSet.__init__(self, name)
        self.stru = stru
        self.addParameterSet(CCTBXUnitCellParSet(self))
        self.scatterers = []

        self._update = False

        cdict = {}
        for s in stru.scatterers():
            el = s.element_symbol()
            i = cdict.get(el, 0)
            sname = "%s%i"%(el,i)
            cdict[el] = i+1
            scatterer = CCTBXScattererParSet(sname, self, i)
            self.addParameterSet(scatterer)
            self.scatterers.append(scatterer)

        # Constrain the lattice
        from diffpy.srfit.structure.sgconstraints import _constrainSpaceGroup
        symbol = self.getSpaceGroup()
        _constrainSpaceGroup(self, symbol)

        return
Пример #5
0
    def __init__(self, strups):
        """Initialize

        strups  --  The CCTBXCrystalParSet that contains the cctbx structure
                    and the unit cell we're wrapper.

        """
        ParameterSet.__init__(self, "unitcell")
        self.strups = strups
        self._latpars = list(self.strups.stru.unit_cell().parameters())

        self.addParameter(ParameterAdapter("a", None, self._latgetter(0),
            self._latsetter(0)))
        self.addParameter(ParameterAdapter("b", None, self._latgetter(1),
            self._latsetter(1)))
        self.addParameter(ParameterAdapter("c", None, self._latgetter(2),
            self._latsetter(2)))
        self.addParameter(ParameterAdapter("alpha", None, self._latgetter(3),
            self._latsetter(3)))
        self.addParameter(ParameterAdapter("beta", None, self._latgetter(4),
            self._latsetter(4)))
        self.addParameter(ParameterAdapter("gamma", None, self._latgetter(5),
            self._latsetter(5)))

        return
Пример #6
0
    def __init__(self, name):
        ParameterSet.__init__(self, name)
        self.meta = {}

        # Initialize Operator attributes
        Operator.__init__(self, name)
        return
Пример #7
0
    def __init__(self, lattice):
        """Initialize

        lattice --  A diffpy.Structure.Lattice instance

        """
        ParameterSet.__init__(self, "lattice")
        self.angunits = "deg"
        self.lattice = lattice
        l = lattice
        self.addParameter(
            ParameterAdapter("a", l, _latgetter("a"), _latsetter("a")))
        self.addParameter(
            ParameterAdapter("b", l, _latgetter("b"), _latsetter("b")))
        self.addParameter(
            ParameterAdapter("c", l, _latgetter("c"), _latsetter("c")))
        self.addParameter(
            ParameterAdapter("alpha", l, _latgetter("alpha"),
                             _latsetter("alpha")))
        self.addParameter(
            ParameterAdapter("beta", l, _latgetter("beta"),
                             _latsetter("beta")))
        self.addParameter(
            ParameterAdapter("gamma", l, _latgetter("gamma"),
                             _latsetter("gamma")))

        # Other setup
        self.__repr__ = l.__repr__
        return
Пример #8
0
 def __init__(self, name):
     """Initialize the attributes."""
     Operator.__init__(self)
     ParameterSet.__init__(self, name)
     self.profile = None
     self.meta = {}
     return
Пример #9
0
    def __init__(self, lattice):
        """Initialize

        lattice --  A diffpy.Structure.Lattice instance

        """
        ParameterSet.__init__(self, "lattice")
        self.angunits = "deg"
        self.lattice = lattice
        l = lattice
        self.addParameter(ParameterAdapter("a", l, _latgetter("a"),
            _latsetter("a")))
        self.addParameter(ParameterAdapter("b", l, _latgetter("b"),
            _latsetter("b")))
        self.addParameter(ParameterAdapter("c", l, _latgetter("c"),
            _latsetter("c")))
        self.addParameter(ParameterAdapter("alpha", l, _latgetter("alpha"),
            _latsetter("alpha")))
        self.addParameter(ParameterAdapter("beta", l, _latgetter("beta"),
            _latsetter("beta")))
        self.addParameter(ParameterAdapter("gamma", l, _latgetter("gamma"),
            _latsetter("gamma")))

        # Other setup
        self.__repr__ = l.__repr__
        return
Пример #10
0
    def __init__(self, strups):
        """Initialize

        strups  --  The CCTBXCrystalParSet that contains the cctbx structure
                    and the unit cell we're wrapper.

        """
        ParameterSet.__init__(self, "unitcell")
        self.strups = strups
        self._latpars = list(self.strups.stru.unit_cell().parameters())

        self.addParameter(
            ParameterAdapter("a", None, self._latgetter(0),
                             self._latsetter(0)))
        self.addParameter(
            ParameterAdapter("b", None, self._latgetter(1),
                             self._latsetter(1)))
        self.addParameter(
            ParameterAdapter("c", None, self._latgetter(2),
                             self._latsetter(2)))
        self.addParameter(
            ParameterAdapter("alpha", None, self._latgetter(3),
                             self._latsetter(3)))
        self.addParameter(
            ParameterAdapter("beta", None, self._latgetter(4),
                             self._latsetter(4)))
        self.addParameter(
            ParameterAdapter("gamma", None, self._latgetter(5),
                             self._latsetter(5)))

        return
Пример #11
0
    def __init__(self, name, strups, idx):
        """Initialize

        name    --  The name of this scatterer.
        strups  --  The CCTBXCrystalParSet that contains the cctbx structure
        idx     --  The index of the scatterer in the structure.

        """
        ParameterSet.__init__(self, name)
        self.strups = strups
        self.idx = idx

        # x, y, z, occupancy
        self.addParameter(
            ParameterAdapter("x", None, self._xyzgetter(0),
                             self._xyzsetter(0)))
        self.addParameter(
            ParameterAdapter("y", None, self._xyzgetter(1),
                             self._xyzsetter(1)))
        self.addParameter(
            ParameterAdapter("z", None, self._xyzgetter(2),
                             self._xyzsetter(2)))
        self.addParameter(
            ParameterAdapter("occupancy", None, self._getocc, self._setocc))
        self.addParameter(
            ParameterAdapter("Uiso", None, self._getuiso, self._setuiso))
        return
Пример #12
0
    def __init__(self, name):
        """Initialize the attributes."""
        ParameterSet.__init__(self, name)
        self.profile = None
        self.meta = {}

        # Operator attributes
        Operator.__init__(self, name, name, self.operation, 0, 1)
        return
Пример #13
0
    def __init__(self, name, atom):
        """Initialize

        atom    --  A diffpy.Structure.Atom instance

        """
        ParameterSet.__init__(self, name)
        self.atom = atom
        a = atom
        # x, y, z, occupancy
        self.addParameter(
            ParameterAdapter("x", a, _xyzgetter(0), _xyzsetter(0)))
        self.addParameter(
            ParameterAdapter("y", a, _xyzgetter(1), _xyzsetter(1)))
        self.addParameter(
            ParameterAdapter("z", a, _xyzgetter(2), _xyzsetter(2)))
        occupancy = ParameterAdapter("occupancy", a, attr="occupancy")
        self.addParameter(occupancy)
        self.addParameter(ParameterProxy("occ", occupancy))
        # U
        self.addParameter(ParameterAdapter("U11", a, attr="U11"))
        self.addParameter(ParameterAdapter("U22", a, attr="U22"))
        self.addParameter(ParameterAdapter("U33", a, attr="U33"))
        U12 = ParameterAdapter("U12", a, attr="U12")
        U21 = ParameterProxy("U21", U12)
        U13 = ParameterAdapter("U13", a, attr="U13")
        U31 = ParameterProxy("U31", U13)
        U23 = ParameterAdapter("U23", a, attr="U23")
        U32 = ParameterProxy("U32", U23)
        self.addParameter(U12)
        self.addParameter(U21)
        self.addParameter(U13)
        self.addParameter(U31)
        self.addParameter(U23)
        self.addParameter(U32)
        self.addParameter(ParameterAdapter("Uiso", a, attr="Uisoequiv"))
        # B
        self.addParameter(ParameterAdapter("B11", a, attr="B11"))
        self.addParameter(ParameterAdapter("B22", a, attr="B22"))
        self.addParameter(ParameterAdapter("B33", a, attr="B33"))
        B12 = ParameterAdapter("B12", a, attr="B12")
        B21 = ParameterProxy("B21", B12)
        B13 = ParameterAdapter("B13", a, attr="B13")
        B31 = ParameterProxy("B31", B13)
        B23 = ParameterAdapter("B23", a, attr="B23")
        B32 = ParameterProxy("B32", B23)
        self.addParameter(B12)
        self.addParameter(B21)
        self.addParameter(B13)
        self.addParameter(B31)
        self.addParameter(B23)
        self.addParameter(B32)
        self.addParameter(ParameterAdapter("Biso", a, attr="Bisoequiv"))

        # Other setup
        self.__repr__ = a.__repr__
        return
Пример #14
0
    def __init__(self, name, atom):
        """Initialize

        atom    --  A diffpy.Structure.Atom instance

        """
        ParameterSet.__init__(self, name)
        self.atom = atom
        a = atom
        # x, y, z, occupancy
        self.addParameter(ParameterAdapter("x", a, _xyzgetter(0),
            _xyzsetter(0)))
        self.addParameter(ParameterAdapter("y", a, _xyzgetter(1),
            _xyzsetter(1)))
        self.addParameter(ParameterAdapter("z", a, _xyzgetter(2),
            _xyzsetter(2)))
        occupancy = ParameterAdapter("occupancy", a, attr = "occupancy")
        self.addParameter(occupancy)
        self.addParameter(ParameterProxy("occ", occupancy))
        # U
        self.addParameter(ParameterAdapter("U11", a, attr = "U11"))
        self.addParameter(ParameterAdapter("U22", a, attr = "U22"))
        self.addParameter(ParameterAdapter("U33", a, attr = "U33"))
        U12 = ParameterAdapter("U12", a, attr = "U12")
        U21 = ParameterProxy("U21", U12)
        U13 = ParameterAdapter("U13", a, attr = "U13")
        U31 = ParameterProxy("U31", U13)
        U23 = ParameterAdapter("U23", a, attr = "U23")
        U32 = ParameterProxy("U32", U23)
        self.addParameter(U12)
        self.addParameter(U21)
        self.addParameter(U13)
        self.addParameter(U31)
        self.addParameter(U23)
        self.addParameter(U32)
        self.addParameter(ParameterAdapter("Uiso", a, attr = "Uisoequiv"))
        # B
        self.addParameter(ParameterAdapter("B11", a, attr = "B11"))
        self.addParameter(ParameterAdapter("B22", a, attr = "B22"))
        self.addParameter(ParameterAdapter("B33", a, attr = "B33"))
        B12 = ParameterAdapter("B12", a, attr = "B12")
        B21 = ParameterProxy("B21", B12)
        B13 = ParameterAdapter("B13", a, attr = "B13")
        B31 = ParameterProxy("B31", B13)
        B23 = ParameterAdapter("B23", a, attr = "B23")
        B32 = ParameterProxy("B32", B23)
        self.addParameter(B12)
        self.addParameter(B21)
        self.addParameter(B13)
        self.addParameter(B31)
        self.addParameter(B23)
        self.addParameter(B32)
        self.addParameter(ParameterAdapter("Biso", a, attr = "Bisoequiv"))

        # Other setup
        self.__repr__ = a.__repr__
        return
Пример #15
0
    def __init__(self, name):
        """Initialize the attributes."""
        ParameterSet.__init__(self, name)
        self.profile = None
        self.meta = {}

        # Operator attributes
        Operator.__init__(self, name, name, self.operation, 0, 1)
        return
Пример #16
0
    def __init__(self, name):
        """Initialization."""
        ParameterSet.__init__(self, name)
        self._eq = None
        self._reseq = None
        self.profile = None
        self._xname = None
        self._yname = None
        self._dyname = None

        self._generators = {}
        self._manage(self._generators)
        return
Пример #17
0
    def __init__(self, name):
        """Initialization."""
        ParameterSet.__init__(self, name)
        self._eq = None
        self._reseq = None
        self.profile = None
        self._xname = None
        self._yname = None
        self._dyname = None

        self._generators = {}
        self._manage(self._generators)
        return
Пример #18
0
    def _validate(self):
        """Validate my state.

        This performs ParameterSet validations.
        This does not validate the operation, since this could be costly. The
        operation should be validated with a containing equation.

        Raises AttributeError if validation fails.

        """
        ParameterSet._validate(self)

        return
Пример #19
0
    def _validate(self):
        """Validate my state.

        This performs ParameterSet validations.
        This does not validate the operation, since this could be costly. The
        operation should be validated with a containing equation.

        Raises AttributeError if validation fails.

        """
        ParameterSet._validate(self)

        return
Пример #20
0
    def _validate(self):
        """Validate my state.

        This performs profile validations.
        This performs ParameterSet validations.
        This does not validate the operation, since this could be costly. The
        operation should be validated with a containing equation.

        Raises SrFitError if validation fails.

        """
        if self.profile is None:
            raise SrFitError("profile is None")
        self.profile._validate()
        ParameterSet._validate(self)
        return
Пример #21
0
    def _validate(self):
        """Validate my state.

        This performs profile validations.
        This performs ParameterSet validations.
        This does not validate the operation, since this could be costly. The
        operation should be validated with a containing equation.

        Raises SrFitError if validation fails.

        """
        if self.profile is None:
            raise SrFitError("profile is None")
        self.profile._validate()
        ParameterSet._validate(self)
        return
Пример #22
0
    def testAddParameterSet(self):
        """Test the addParameterSet method."""
        parset2 = ParameterSet("parset2")
        p1 = Parameter("parset2", 1)

        self.parset.addParameterSet(parset2)
        self.assertTrue(self.parset.parset2 is parset2)

        self.assertRaises(ValueError, self.parset.addParameterSet, p1)

        p1.name = "p1"
        parset2.addParameter(p1)

        self.assertTrue(self.parset.parset2.p1 is p1)

        return
Пример #23
0
    def testAddParameterSet(self):
        """Test the addParameterSet method."""
        parset2 = ParameterSet("parset2")
        p1 = Parameter("parset2", 1)

        self.parset.addParameterSet(parset2)
        self.assertTrue(self.parset.parset2 is parset2)

        self.assertRaises(ValueError, self.parset.addParameterSet, p1)

        p1.name = "p1"
        parset2.addParameter(p1)

        self.assertTrue(self.parset.parset2.p1 is p1)

        return
Пример #24
0
    def _validate(self):
        """Validate my state.

        This performs profile validations.
        This performs ProfileGenerator validations.
        This validates _eq.
        This validates _reseq and residual.

        Raises SrFitError if validation fails.

        """
        self.profile._validate()
        ParameterSet._validate(self)

        # Try to get the value of eq.
        from diffpy.srfit.equation.visitors import validate
        try:
            validate(self._eq)
        except ValueError as e:
            raise SrFitError(e)
        if self._eq is None:
            raise SrFitError("_eq is None")

        val = None
        try:
            val = self._eq()
        except TypeError as e:
            raise SrFitError("_eq cannot be evaluated: %s"%e)

        if val is None:
            raise SrFitError("_eq evaluates to None")

        # Try to get the value for residual
        try:
            validate(self._reseq)
        except ValueError as e:
            raise SrFitError(e)
        try:
            val = self.residual()
        except TypeError:
            raise SrFitError("residual cannot be evaluated")
        if val is None:
            raise SrFitError("residual evaluates to None")
        return
Пример #25
0
    def _validate(self):
        """Validate my state.

        This performs profile validations.
        This performs ProfileGenerator validations.
        This validates _eq.
        This validates _reseq and residual.

        Raises AttributeError if validation fails.

        """
        self.profile._validate()
        ParameterSet._validate(self)

        # Try to get the value of eq.
        from diffpy.srfit.equation.visitors import validate
        try:
            validate(self._eq)
        except ValueError, e:
            raise AttributeError(e)
Пример #26
0
    def _validate(self):
        """Validate my state.

        This performs profile validations.
        This performs ProfileGenerator validations.
        This validates _eq.
        This validates _reseq and residual.

        Raises SrFitError if validation fails.

        """
        self.profile._validate()
        ParameterSet._validate(self)

        # Try to get the value of eq.
        from diffpy.srfit.equation.visitors import validate
        try:
            validate(self._eq)
        except ValueError, e:
            raise SrFitError(e)
Пример #27
0
class TestParameterSet(unittest.TestCase):
    def setUp(self):
        self.parset = ParameterSet("test")
        return

    def testAddParameterSet(self):
        """Test the addParameterSet method."""
        parset2 = ParameterSet("parset2")
        p1 = Parameter("parset2", 1)

        self.parset.addParameterSet(parset2)
        self.assertTrue(self.parset.parset2 is parset2)

        self.assertRaises(ValueError, self.parset.addParameterSet, p1)

        p1.name = "p1"
        parset2.addParameter(p1)

        self.assertTrue(self.parset.parset2.p1 is p1)

        return
Пример #28
0
class TestParameterSet(unittest.TestCase):

    def setUp(self):
        self.parset = ParameterSet("test")
        return

    def testAddParameterSet(self):
        """Test the addParameterSet method."""
        parset2 = ParameterSet("parset2")
        p1 = Parameter("parset2", 1)

        self.parset.addParameterSet(parset2)
        self.assertTrue(self.parset.parset2 is parset2)

        self.assertRaises(ValueError, self.parset.addParameterSet, p1)

        p1.name = "p1"
        parset2.addParameter(p1)

        self.assertTrue(self.parset.parset2.p1 is p1)

        return
Пример #29
0
    def __init__(self, name, strups, idx):
        """Initialize

        name    --  The name of this scatterer.
        strups  --  The CCTBXCrystalParSet that contains the cctbx structure
        idx     --  The index of the scatterer in the structure.

        """
        ParameterSet.__init__(self, name)
        self.strups = strups
        self.idx = idx

        # x, y, z, occupancy
        self.addParameter(ParameterAdapter("x", None, self._xyzgetter(0),
            self._xyzsetter(0)))
        self.addParameter(ParameterAdapter("y", None, self._xyzgetter(1),
            self._xyzsetter(1)))
        self.addParameter(ParameterAdapter("z", None, self._xyzgetter(2),
            self._xyzsetter(2)))
        self.addParameter(ParameterAdapter("occupancy", None, self._getocc,
            self._setocc))
        self.addParameter(ParameterAdapter("Uiso", None, self._getuiso,
            self._setuiso))
        return
Пример #30
0
 def setUp(self):
     self.parset = ParameterSet("test")
     return
Пример #31
0
 def setUp(self):
     self.parset = ParameterSet("test")
     return