Skip to content

ChemicalShifts

ChemicalShifts

ChemicalShifts(data)

A tidy table of assigned chemical shifts (one row per atom).

Source code in makeshift/chemshift.py
def __init__(self, data):
    self.data = data
    self.entry = None

from_entry classmethod

from_entry(entry, reref=None, calc_csi=False)

Build from an NMRStarEntry's assigned_chemical_shifts saveframes.

Source code in makeshift/chemshift.py
@classmethod
def from_entry(cls, entry, reref=None, calc_csi=False):
    """Build from an NMRStarEntry's assigned_chemical_shifts saveframes."""
    frames = []
    for framecode, sf in entry.saveframe("assigned_chemical_shifts").items():
        loop = sf.get("_Atom_chem_shift")
        if not loop:
            continue
        cs = NMRStarEntry.loop_to_dataframe(loop)
        cs["name"] = sf.get("Name", ".")
        cs["ChemShift_ID"] = framecode
        cs = cls._clean(cs)
        sids = [r.get("Sample_ID") for r in sf.get("_Chem_shift_experiment", [])]
        sids = [s for s in sids if s and s not in (".", "?")]
        cs["Sample_ID"] = ",".join(dict.fromkeys(sids)) or pd.NA
        frames.append(cs)

    if not frames:
        raise ValueError(
            f"entry {entry.entry_id!r} has no assigned chemical shifts "
            "to build a ChemicalShifts from."
        )

    df = pd.concat(frames, ignore_index=True)
    df["Seq_ID"] = df["Seq_ID"].astype(int)

    obj = cls(df)
    obj.entry = entry
    if reref in ("panav", "lacs"):
        obj.reref(method=reref)
    if calc_csi:
        method = calc_csi if isinstance(calc_csi, str) else "wishart_94"
        obj.add_csi(method=method)
    return obj

reref

reref(method, cona=True)

Re-reference shifts in place via the LACS or PANAV routine.

For method="panav", also stores a CONA fragment-scan summary on self.reref_cona unless cona=False (CONA does not change offsets; skip it when only the correction matters).

Source code in makeshift/chemshift.py
def reref(self, method, cona=True):
    """
    Re-reference shifts in place via the LACS or PANAV routine.

    For ``method="panav"``, also stores a CONA fragment-scan summary on
    ``self.reref_cona`` unless ``cona=False`` (CONA does not change
    offsets; skip it when only the correction matters).
    """
    from .reref import compute_offsets, apply_offsets

    offsets, check, meta = compute_offsets(self.data, method, cona=cona)
    self.reref_method = method
    self.reref_offsets = offsets
    self.reref_check = check
    self.reref_cona = meta

    if not offsets or not any(v is not None for v in offsets.values()):
        warnings.warn(
            f"{method} re-referencing produced no offsets "
            "(insufficient backbone shifts or all fits failed); "
            "shifts left unchanged.",
            UserWarning,
        )
        return self

    self.data = apply_offsets(self.data, offsets)
    return self

add_csi

add_csi(method='wishart_94', assign_ss=True, raw=False)

Add Wishart chemical-shift index columns in place; returns self.

Default columns are ternary (-1 / 0 / +1). Pass raw=True to also store ppm deviations from the Wishart centers (csi_raw / {atom}_raw on csi_table).

Parameters:

Name Type Description Default
method str

'wishart_92' — 1Ha CSI (Wishart, Sykes & Richards 1992).

'wishart_94' (default) — HA + CA + CB + C' indices with density-filtered secondary structure and majority-rules consensus (Wishart & Sykes 1994).

'wishart_94_ha' / '_ca' / '_cb' / '_c' — single-nucleus 1994 protocol (CB is strand-only).

'wishart_94'
assign_ss bool

Run the stage-2 density filter (and consensus for wishart_94).

True
raw bool

If True, also add continuous observed − center deviations.

False
Notes

Ternary signs: HA +1 = strand / -1 = helix; CA and C' +1 = helix / -1 = strand; CB +1 = strand only. Consensus ss is H / E / C; csi mirrors that as +1 / -1 / 0. Per-residue detail is on self.csi_table.

LACS re-referencing does not use this method — it computes its own continuous CA-CB secondary shift via _csi_raw.

Source code in makeshift/chemshift.py
def add_csi(self, method="wishart_94", assign_ss=True, raw=False):
    """
    Add Wishart chemical-shift index columns in place; returns self.

    Default columns are ternary (-1 / 0 / +1). Pass ``raw=True`` to also
    store ppm deviations from the Wishart centers (``csi_raw`` /
    ``{atom}_raw`` on ``csi_table``).

    Parameters
    ----------
    method : str
        ``'wishart_92'`` — 1Ha CSI (Wishart, Sykes & Richards 1992).

        ``'wishart_94'`` (default) — HA + CA + CB + C' indices with
        density-filtered secondary structure and majority-rules consensus
        (Wishart & Sykes 1994).

        ``'wishart_94_ha'`` / ``'_ca'`` / ``'_cb'`` / ``'_c'`` — single-nucleus
        1994 protocol (CB is strand-only).
    assign_ss : bool
        Run the stage-2 density filter (and consensus for ``wishart_94``).
    raw : bool
        If True, also add continuous ``observed − center`` deviations.

    Notes
    -----
    Ternary signs: HA +1 = strand / -1 = helix; CA and C' +1 = helix /
    -1 = strand; CB +1 = strand only. Consensus ``ss`` is H / E / C;
    ``csi`` mirrors that as +1 / -1 / 0. Per-residue detail is on
    ``self.csi_table``.

    LACS re-referencing does **not** use this method — it computes its own
    continuous CA-CB secondary shift via ``_csi_raw``.
    """
    method = str(method).lower()
    if method not in self._CSI_METHODS:
        raise ValueError(
            f"unknown CSI method {method!r}; "
            f"choose from {tuple(self._CSI_METHODS)}"
        )
    self.csi_method = method

    from . import csi as wishart_csi

    atoms = self._CSI_METHODS[method]
    if atoms is None:
        atoms = wishart_csi._WISHART_ATOMS
    table = wishart_csi.wishart_table(
        self.data, atoms=atoms, assign_ss=assign_ss, raw=raw
    )
    self.csi_table = table
    by_seq = table.set_index("Seq_ID")

    if method == "wishart_94":
        for col in ("HA", "CA", "CB", "C"):
            if col in by_seq.columns:
                self.data[f"csi_{col.lower()}"] = self.data["Seq_ID"].map(
                    by_seq[col]
                )
        if "ss" in by_seq.columns:
            self.data["ss"] = self.data["Seq_ID"].map(by_seq["ss"])
        if "csi" in by_seq.columns:
            self.data["csi"] = self.data["Seq_ID"].map(by_seq["csi"])
        if raw and "CA_raw" in by_seq.columns:
            self.data["csi_raw"] = self.data["Seq_ID"].map(by_seq["CA_raw"])
    else:
        atom = atoms[0]
        self.data["csi"] = self.data["Seq_ID"].map(by_seq[atom])
        if raw:
            raw_col = f"{atom}_raw"
            if raw_col in by_seq.columns:
                self.data["csi_raw"] = self.data["Seq_ID"].map(by_seq[raw_col])
        if assign_ss and "ss" in by_seq.columns:
            self.data["ss"] = self.data["Seq_ID"].map(by_seq["ss"])
    return self