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 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
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') LocalTable()._registerThisType() return