Ejemplo n.º 1
0
 def test_class_registry(self):
     """check if instances are aliased by radiationType().
     """
     ltb = ScatteringFactorTable.createByType('LTB')
     self.assertTrue(type(ltb) is LocalTable)
     ltb2 = ScatteringFactorTable.createByType('localtable')
     self.assertTrue(type(ltb2) is LocalTable)
     return
 def test_class_registry(self):
     """check if instances are aliased by radiationType().
     """
     ltb = ScatteringFactorTable.createByType('LTB')
     self.assertTrue(type(ltb) is LocalTable)
     ltb2 = ScatteringFactorTable.createByType('localtable')
     self.assertTrue(type(ltb2) is LocalTable)
     return
Ejemplo n.º 3
0
    def fromComposition(cls, composition, sftb, q=0):
        """\
        Calculate average scattering factors from atom concentrations.

        Parameters
        ----------
        composition : dictionary or a list of (symbol, amount) pairs.
            The chemical composition for evaluating the average.  Atom
            symbols may repeat when it is a list of (symbol, amount) pairs.
        sftb : ScatteringFactorTable or str
            The ScatteringFactorTable object for looking up the values.
            When string use `ScatteringFactorTable.createByType` to create
            a new lookup table of the specified type.
        q : float or NumPy array (optional)
            The Q value in inverse Angstroms for which to lookup
            the scattering factor values.

        Returns
        -------
        SFAverage
            The calculated scattering factor averages.
        """
        from diffpy.srreal.scatteringfactortable import ScatteringFactorTable
        sfa = cls()
        sfa.composition = {}
        if isinstance(composition, dict):
            sfa.composition.update(composition)
        else:
            for smbl, cnt in composition:
                if not smbl in sfa.composition:
                    sfa.composition[smbl] = 0
                sfa.composition[smbl] += cnt
        sfa.f1sum = 0.0 * q
        sfa.f2sum = 0.0 * q
        # resolve the lookup table object `tb`
        tb = (sftb if not isinstance(sftb, str)
              else ScatteringFactorTable.createByType(sftb))
        for smbl, cnt in sfa.composition.items():
            sfq = tb.lookup(smbl, q)
            sfa.f1sum += cnt * sfq
            sfa.f2sum += cnt * sfq**2
            sfa.count += cnt
        denom = sfa.count if sfa.count > 0 else 1
        sfa.f1avg = sfa.f1sum / denom
        sfa.f2avg = sfa.f2sum / denom
        return sfa
Ejemplo n.º 4
0
 def test_ticker_override(self):
     """check Python override of ScatteringFactorTable.ticker.
     """
     from diffpy.srreal.pdfcalculator import PDFCalculator
     lsft = LocalTable()
     self.assertEqual(0, lsft.tcnt)
     et0 = lsft.ticker()
     self.assertEqual(1, lsft.tcnt)
     et1 = ScatteringFactorTable.ticker(lsft)
     self.assertEqual(1, lsft.tcnt)
     self.assertEqual(et0, et1)
     et0.click()
     self.assertEqual(et0, et1)
     # check that implicit ticker call from PDFCalculator is
     # handled by Python override of the ticker method.
     pc = PDFCalculator()
     pc.scatteringfactortable = lsft
     pc.ticker()
     self.assertEqual(2, lsft.tcnt)
     return
 def test_ticker_override(self):
     """check Python override of ScatteringFactorTable.ticker.
     """
     from diffpy.srreal.pdfcalculator import PDFCalculator
     lsft = LocalTable()
     self.assertEqual(0, lsft.tcnt)
     et0 = lsft.ticker()
     self.assertEqual(1, lsft.tcnt)
     et1 = ScatteringFactorTable.ticker(lsft)
     self.assertEqual(1, lsft.tcnt)
     self.assertEqual(et0, et1)
     et0.click()
     self.assertEqual(et0, et1)
     # check that implicit ticker call from PDFCalculator is
     # handled by Python override of the ticker method.
     pc = PDFCalculator()
     pc.scatteringfactortable = lsft
     pc.ticker()
     self.assertEqual(2, lsft.tcnt)
     return
 def setUp(self):
     self.sftx = ScatteringFactorTable.createByType('X')
     self.sftn = ScatteringFactorTable.createByType('N')
     return
 def setUp(self):
     self.sftx = ScatteringFactorTable.createByType('X')
     self.sftn = ScatteringFactorTable.createByType('N')
     return
Ejemplo n.º 8
0
 def tearDown(self):
     ScatteringFactorTable._deregisterType('localtable')
     return
Ejemplo n.º 9
0
 def setUp(self):
     self.sftx = ScatteringFactorTable.createByType('X')
     self.sftn = ScatteringFactorTable.createByType('N')
     LocalTable()._registerThisType()
     return
Ejemplo n.º 10
0
 def ticker(self):
     self.tcnt += 1
     return ScatteringFactorTable.ticker(self)
 def tearDown(self):
     ScatteringFactorTable._deregisterType('localtable')
     return
 def setUp(self):
     self.sftx = ScatteringFactorTable.createByType('X')
     self.sftn = ScatteringFactorTable.createByType('N')
     LocalTable()._registerThisType()
     return
 def ticker(self):
     self.tcnt += 1
     return ScatteringFactorTable.ticker(self)
Ejemplo n.º 14
0
        return copy.copy(self)

    def type(self):
        return "xrayneutral"

    def radiationType(self):
        return "XNEUTRAL"

    def _sfwater(self, q):
        fh = self.__sftxray._standardLookup("H", q)
        fo = self.__sftxray._standardLookup("O", q)
        return 2 * fh + fo

    def _standardLookup(self, smbl, q):
        smblbare = smbl.rstrip('+-012345678')
        if smblbare == 'D':
            rv = self._standardLookup('H', q)
        elif smblbare == 'Wa':
            rv = self._sfwater(q)
        else:
            rv = self.__sftxray._standardLookup(smblbare, q)
        return rv


# end of class SFTXrayNeutral

_sftb = SFTXrayNeutral()
ScatteringFactorTable._deregisterType(_sftb.type())
_sftb._registerThisType()
del _sftb