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:
        obj.add_csi()
    return obj

reref

reref(method)

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

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

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

    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()

Add csi_raw and csi columns in place; returns self.

Source code in makeshift/chemshift.py
def add_csi(self):
    """Add ``csi_raw`` and ``csi`` columns in place; returns self."""
    atoms = self.data["Atom_ID"].unique()
    if "CA" not in atoms or "CB" not in atoms:
        warnings.warn("CA and/or CB missing from Atom_ID; cannot calculate CSI",
                      UserWarning)
        return self
    self.data["csi_raw"] = self.data.apply(self._csi_raw, axis=1)
    self.data["csi"] = self.data.apply(
        lambda r: self._csi_index(r["csi_raw"], r["Comp_ID"]), axis=1
    ).astype(float)
    return self