MolBasis
mfsigpythonnumpydescriptorsunits6 min read

From an mfsig file to a descriptor vector in Python

Open the mfsig file, print its top-level keys, check version and units against the docs page, then pull the nine descriptors into a numpy vector.

Updated November 28, 2026

Turning an mfsig file into a descriptor vector takes four steps. Load the file and print its top-level keys. Read the version and work out which units the file uses. Pull the nine kernel descriptors by name into a numpy array in a fixed order. Convert units if the file and the model disagree, then validate the result. The exact field names and nesting are defined on the docs page, which is the authority if anything in this guide and the file differ. The snippets below treat the file as JSON. Check the extension of your file and the format section of the docs page first.

Print the keys before you assume anything

An mfsig file is a structured document with named fields. Two things have changed between versions, the unit convention and the geometry recipe, and field placement can change too. So the first lines of any script should show what the file holds rather than assume it.

import json
from pathlib import Path

path = Path("molecule.mfsig.json")   # your file
with path.open() as fh:
    doc = json.load(fh)

print(type(doc).__name__)
print(sorted(doc.keys()) if isinstance(doc, dict) else len(doc))

Compare the printed keys with the field list on the docs page. If a key you expect is absent at the top level, it may be nested under a section such as a descriptors block or a metadata block. The helper in the next section searches the whole document, so nesting does not break the extraction, but you should still know where each field lives before trusting a value.

Check the version and the units

Find the version field and read it. The kernels on MolBasis were fitted on v0.91.1 files. In those files cavity_area_aa2 is in bohr² although the name says Ų, and the σ moments are in e/bohr². The current recipe v1.0.0 writes ångström units. The conversions are fixed numbers. One bohr² is 0.2800 Ų. A σ in e/Ų equals σ in e/bohr² times 3.571. The variance scales by the square, 12.75. Skewness and kurtosis are dimensionless and do not change. The guide on the bohr versus ångström units trap explains how the mislabelling arose, and the mfsig guide on units and unit errors covers the file side.

The geometry recipe also changed, from a single RDKit conformer relaxed with UFF to MMFF94s. There is no conversion factor for that. A current file gives different descriptor values from a v0.91.1 file for the same SMILES, and no kernel page states by how much.

Pull the nine descriptors

The nine kernel descriptors, in the order used throughout these guides, are listed in the code. HOMO and LUMO energies exist in the file but are not among them. The helper walks the document so that the fields are found wherever they are nested.

import numpy as np

NINE = ["cavity_area_aa2", "g_polar_kcal", "dipole_debye",
        "sigma_variance", "sigma_skewness", "sigma_kurtosis",
        "hb_donor_mass", "hb_acceptor_mass", "n_segments"]

def find(node, name):
    """Return the first value stored under `name` at any depth, else None."""
    if isinstance(node, dict):
        if name in node:
            return node[name]
        for value in node.values():
            hit = find(value, name)
            if hit is not None:
                return hit
    elif isinstance(node, list):
        for value in node:
            hit = find(value, name)
            if hit is not None:
                return hit
    return None

raw = {k: find(doc, k) for k in NINE}
missing = [k for k, v in raw.items() if v is None]
if missing:
    raise KeyError(f"not found, check /docs for current names: {missing}")

x = np.array([raw[k] for k in NINE], dtype=float)
version = str(find(doc, "version"))
print(version, x)

If KeyError fires, the field names in your file differ from the list, and the docs page tells you the current ones. Do not guess a mapping. A wrong mapping between two σ moments, for example variance and kurtosis, gives a vector that looks plausible and is wrong in every element that matters.

Two fields that need care

hb_donor_mass is always zero in the v0.91.1 production code path, because the function was called without the SMILES it needs. In a v0.91.1 file this element of the vector carries no information, and a kernel fitted on it fitted a constant. Keep the element in the vector for positional consistency, but do not read anything into it. The guide on the nine mfsig descriptors explains each field and its history. n_segments is an integer count of cavity segments and is the one descriptor with no unit question at all.

Convert, then validate

Convert only when the file and the model disagree. If you are reproducing a fit made on v0.91.1 files and your file is v0.91.1, leave the values as they are. If your file is v1.0.0 and the model expects bohr², convert the other way. The snippet converts a v0.91.1 vector to ångström units for the case where you are building your own kernel on current files and need the old file to match.

BOHR2_TO_AA2 = 0.2800
SIGMA_SCALE = 3.571              # e/bohr2 -> e/A2
VAR_SCALE = SIGMA_SCALE ** 2     # 12.75

def to_angstrom(x, version):
    y = x.copy()
    if version.startswith("0.91"):
        y[0] *= BOHR2_TO_AA2     # cavity_area_aa2
        y[3] *= VAR_SCALE        # sigma_variance
        # skewness, kurtosis, dipole, g_polar, hb masses, n_segments unchanged here
    return y

assert x[0] > 0 and x[8] > 0 and x[3] >= 0, "area, segment count and variance must be positive"
x_aa = to_angstrom(x, version)

The donor and acceptor masses are surface quantities too, and their unit treatment follows the area convention of the file. Check the docs page for their unit before scaling them, which is why the snippet leaves them untouched. The mfsig guide on validating a sigma-profile file covers checks at the file level. Two more belong here. The polar energy must be negative, and the dipole norm must not be negative.

From vector to prediction

With x in the right units and the right order, the vector feeds the procedure in how to apply a property kernel, which raises one or two elements to their exponents, z-scores them with training constants and multiplies by the coefficients. Those constants are not published for the MolBasis kernels, so the vector you have built can be used with your own fit or with constants obtained from the holder of the record, not with a kernel page alone. The vector is still worth building, because it is the input every kernel shares, and the unit check above is the step most often skipped.

Key points

  • Load the file and print the top-level keys before writing any extraction code. The docs page is the authority on field names.
  • Read the version. v0.91.1 files hold bohr² areas under an Ų name and e/bohr² σ. v1.0.0 files hold ångström units from a different geometry.
  • Pull the nine descriptors by name into a fixed order. HOMO and LUMO are in the file but are not kernel descriptors.
  • hb_donor_mass is zero in v0.91.1 production files. Keep the slot, ignore the value.
  • Convert only when file and model disagree, validate signs and positivity, and remember that coefficients are not published.

Questions people ask

What is the first thing to do with an mfsig file in Python?
Load it and print its top-level keys. Field names and nesting are defined on the MolBasis docs page and on mfsig.com, and they changed between versions. Looking at the keys before writing any extraction code prevents a silent mismatch between what you expect and what the file holds.
Which nine fields make up the kernel descriptor vector?
cavity_area_aa2, g_polar_kcal, dipole_debye, sigma_variance, sigma_skewness, sigma_kurtosis, hb_donor_mass, hb_acceptor_mass and n_segments. HOMO and LUMO energies are in the file but are not among the nine kernel descriptors.
Why does the area field end in aa2 if the value is in bohr²?
Because in v0.91.1 files the name was written for ångström squared but the value was stored in bohr squared. The findings page records this. Multiply by 0.2800 to get Ų. Current mfsig files write ångström values, so check the version field before converting.

Further reading

In practice: The coefficients of the kernels are not published, so no kernel can be evaluated from this site alone, and no figure here was recomputed except the separate blind benchmark. The guides say what can be done with what is available.

See the kernels themselves

Every kernel is shown with its held-out result, the number of molecules it rests on and what it cannot be trusted for.