def test_getFsSquared(self): generator = ReflectionGenerator(self.crystalStructure) hkls = generator.getUniqueHKLs(1.0, 10.0) fsSquared = generator.getFsSquared(hkls) self.assertEqual(len(fsSquared), len(hkls))
def _update_distributions_and_weights(self): crystal_structure = CrystalStructure(str(self._unit_cell), str(self._space_group), str(self._atoms)) reflection_generator = ReflectionGenerator(crystal_structure) # Calculate all unique reflections within the specified resolution limits, including structure factors unique_hkls = reflection_generator.getUniqueHKLs(self.d_min, self.d_max) structure_factors = reflection_generator.getFsSquared(unique_hkls) # Calculate multiplicities of the reflections point_group = crystal_structure.getSpaceGroup().getPointGroup() multiplicities = [len(point_group.getEquivalents(hkl)) for hkl in unique_hkls] # Calculate weights as F^2 * multiplicity and normalize so that Sum(weights) = 1 weights = np.array([x * y for x, y in zip(structure_factors, multiplicities)]) self._parameter_lock.acquire() self._peak_weights = weights / sum(weights) d_values = reflection_generator.getDValues(unique_hkls) self._peak_distributions = [partial(np.random.normal, loc=d, scale=self._relative_sigma * d) for d in d_values] self._parameter_lock.release()
class StructFactor(): def __init__(self, cif_file, qrange=[1, 6], unique=False): self.cif = cif_file self.qrange = qrange self.unique = unique self.structf() def structf(self): sample_ws = CreateSampleWorkspace() LoadCIF(sample_ws, self.cif) self.sample = sample_ws.sample().getCrystalStructure() self.generator = ReflectionGenerator(self.sample) if self.unique == True: hkls = self.generator.getUniqueHKLsUsingFilter( self.qrange[0], self.qrange[1], ReflectionConditionFilter.StructureFactor) else: hkls = self.generator.getHKLsUsingFilter( self.qrange[0], self.qrange[1], ReflectionConditionFilter.StructureFactor) pg = self.sample.getSpaceGroup().getPointGroup() df = pd.DataFrame(data=np.array(hkls), columns=list('hkl')) df['d(A)'] = self.generator.getDValues(hkls) df['F^2'] = self.generator.getFsSquared(hkls) df['hkl'] = hkls df['M'] = df['hkl'].map(lambda x: len(pg.getEquivalents(x))) df['II_powder'] = df['F^2'] * df['M'] df['q'] = 2 * np.pi / df['d(A)'] df['qh'] = df['h'].map(lambda x: np.sign(x) * 2 * np.pi / self. generator.getDValues([V3D(x, 0, 0)])[0]) df['qk'] = df['k'].map(lambda x: np.sign(x) * 2 * np.pi / self. generator.getDValues([V3D(0, x, 0)])[0]) df['ql'] = df['l'].map(lambda x: np.sign(x) * 2 * np.pi / self. generator.getDValues([V3D(0, 0, x)])[0]) self.data = df