"""Which space-group differences a diffraction experiment could actually have decided. A merged dataset sees only (a) which reflections are equivalent in intensity - the rotation parts of the operations together with their negatives (Friedel's law), i.e. the Laue group in its real orientation - and (b) which are systematically absent. Two space groups agreeing on both cannot be told apart without solving the structure (or an anomalous signal strong enough to break Friedel's law). Two families: - same point group: body centring is the usual culprit - h+k+l=2n already forces h00: h=2n, so a 2_1 along <100> adds nothing (I222 = I212121); and the two hands of an enantiomorphic pair. - different point groups of one Laue class with the same absences: acentric vs centric (P2 vs P2/m, Pc vs P2/c, Pna21 vs Pnam) and the two acentric groups of one class (I41md vs I-42d). The comparison is made per setting: two numbers are related if some setting of the one agrees with some setting of the other (Pna21 matches Pnma as Pnam, not in the standard settings of both). """ import gemmi, collections _N = 7 _HKL = [(h, k, l) for h in range(-_N, _N+1) for k in range(-_N, _N+1) for l in range(-_N, _N+1) if (h, k, l) != (0, 0, 0)] def signature(sg): """What the intensities of a crystal in this space group (a gemmi.SpaceGroup, in its setting) can show: the Laue rotations, the centring and the absences.""" ops = sg.operations() rots = [tuple(map(tuple, op.rot)) for op in ops] return (frozenset(rots) | frozenset(tuple(tuple(-x for x in row) for row in r) for r in rots), frozenset(tuple(t) for t in ops.cen_ops), tuple(ops.is_systematically_absent(h) for h in _HKL)) _SIGS = collections.defaultdict(set) # number -> the signatures of its settings _by_sig = collections.defaultdict(set) for _sg in gemmi.spacegroup_table(): _s = signature(_sg) _SIGS[_sg.number].add(_s) _by_sig[_s].add(_sg.number) CLASS = collections.defaultdict(set) for _s in _by_sig.values(): for _n in _s: CLASS[_n] |= _s - {_n} def indistinguishable(a, b): """True if intensities alone could never have separated these two space groups (numbers), in some setting of each.""" return a == b or b in CLASS.get(a, ()) def same_intensities(sg, number): """True if some setting of space group `number` shows exactly what `sg` (a gemmi.SpaceGroup, in its own setting) shows: the same Laue rotations and the same absences.""" return signature(sg) in _SIGS[number] def point_group(n): return gemmi.find_spacegroup_by_number(n).point_group_hm() def enantiomorphic(a, b): """True if the pair differs only by hand - anomalous signal can break it, absences cannot.""" return (indistinguishable(a, b) and a != b and point_group(a) == point_group(b) and gemmi.find_spacegroup_by_number(a).is_enantiomorphic()) def describe(a, b): if a == b: return "match" if enantiomorphic(a, b): return "hand only (needs anomalous)" if indistinguishable(a, b): if point_group(a) == point_group(b): return "UNDECIDABLE from intensities" return "point group UNDECIDABLE from intensities (same Laue class and absences)" return "REAL difference (absences differ)" if __name__ == "__main__": seen = set() for n, s in sorted(CLASS.items()): s = frozenset(s | {n}) if len(s) < 2 or s in seen: continue seen.add(s) ns = sorted(s) print(" ", " = ".join("%d %s" % (i, gemmi.find_spacegroup_by_number(i).hm) for i in ns), " ->", "; ".join(describe(ns[0], i) for i in ns[1:]))