mfsig.com
pythonmatplotlibnumpyhistogram4 min read

Plotting a σ-profile in Python with numpy and matplotlib

Bin the per-segment σ values of a .mfsig file by segment area with numpy, then draw the histogram with matplotlib. The result is a raw σ-profile.

Updated November 28, 2026

To plot a σ-profile from a .mfsig file, read the per-segment σ values and areas, bin the σ values with numpy using the areas as weights, and draw the result with matplotlib as a step plot. The usual grid runs from -0.03 to +0.03 e/Ų in steps of 0.001 e/Ų. What you get is the raw sigma profile, with sharper peaks than the averaged profiles seen in COSMO-RS papers, and that difference matters.

What the plot shows

The horizontal axis is the screening charge density σ in e/Ų. The vertical axis is surface area in Ų per bin, or a fraction of the total area if you normalise. The curve says how much of the molecular surface carries each value of σ. Non-polar surface sits near zero. Hydrogen-bond donor hydrogens sit at strongly negative σ, because the conductor answers their positive partial charge with negative screening charge. Acceptor atoms sit at strongly positive σ. The sign convention guide explains this in more detail, and the binning guide explains why the bin width is a modelling choice rather than a detail.

From segments to bins

import json
import numpy as np

with open("ethanol.mfsig", encoding="utf-8") as fh:
    doc = json.load(fh)
print(list(doc))                          # confirm the key names first

seg = doc[SEGMENT_KEY]                    # names: see /anatomy
sigma = np.array([s[SIGMA_KEY] for s in seg])      # e/Å^2
area = np.array([s[AREA_KEY] for s in seg])        # Å^2

edges = np.arange(-0.030, 0.030 + 1e-9, 0.001)     # 60 bins of 0.001 e/Å^2
profile, edges = np.histogram(sigma, bins=edges, weights=area)
centres = 0.5 * (edges[:-1] + edges[1:])

print("total area binned:", profile.sum(), "of", area.sum())

The last line tells you whether any segment fell outside the grid. For neutral molecules nearly all area lies within ±0.03 e/Ų. For ions some area lies beyond, and you either widen the grid or report the clipped fraction.

The weights argument is what makes this a σ-profile. Without it numpy counts segments, and a large flat segment on a methyl group weighs the same as a tiny segment near a hydroxyl oxygen. With it each segment contributes its area, and the histogram is the distribution of surface over σ.

Drawing it

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(6, 3.5))
ax.step(centres, profile, where="mid", linewidth=1.5)
ax.axvline(-0.0082, color="grey", linestyle=":", linewidth=1)
ax.axvline(+0.0082, color="grey", linestyle=":", linewidth=1)
ax.set_xlabel("σ (e/Ų)")
ax.set_ylabel("area per bin (Ų)")
ax.set_xlim(-0.03, 0.03)
ax.set_title(doc[IDENTITY_KEY][SMILES_KEY])
fig.tight_layout()
fig.savefig("ethanol_sigma_profile.png", dpi=150)

The step plot is the honest representation of a histogram. A smooth line through bin centres suggests a resolution the data does not have. The two dotted lines mark ±0.0082 e/Ų, the hydrogen-bond threshold Klamt introduced in COSMO-RS. Area beyond them is the surface that can take part in hydrogen bonding in that model.

Reading the picture, with ethanol as the example

Ethanol has a hydroxyl group on an ethyl tail. The profile shows a tall block of area around zero from the CH3 and CH2 hydrogens and carbons. A small peak sits at negative σ beyond the threshold from the single O-H hydrogen, which has little area but a strong charge. A larger peak sits at positive σ from the oxygen lone-pair region. The asymmetry between the two polar peaks, little donor area and more acceptor area, is a signature of alcohols that the alkanes versus alcohols guide develops.

Because the σ values are raw, these polar peaks are sharper and sit further out than in a published averaged profile. Averaging over neighbouring segments pulls extreme values towards the mean. If you intend to compare with a COSMO-RS profile from the literature, apply the averaging step first and say so on the figure. The raw σ in a .mfsig file is not the averaged σ-profile that COSMO-RS or COSMO-SAC parameterisations expect, and must not be passed to them as such.

Overlaying two molecules, and what to normalise

To compare molecules of different size, divide each profile by its total area before plotting, so that both curves integrate to one. To compare how much polar surface each molecule brings to a contact, plot the absolute areas instead. Both are legitimate, they answer different questions, and the axis label must say which one was chosen. Use one colour per molecule, a legend with the SMILES or a trivial name, and the same grid for every curve on the figure. The comparing guide turns these pictures into numbers.

A note on reproducibility of the figure

Write the recipe version from the method block and the content hash from the file into the figure caption or its metadata. A σ-profile figure without a recipe is a picture of an unknown calculation. With the recipe and the hash, anyone can fetch the same file and draw the same curve.

Key points

  • A σ-profile plot is a histogram of segment area over σ. Weight the bins by segment area, never by segment count.
  • Use the conventional grid, -0.03 to +0.03 e/Ų in steps of 0.001, so your plot compares with published ones by eye.
  • Draw it as a step plot and mark ±0.0082 e/Ų, the COSMO-RS hydrogen-bond threshold.
  • The values in a .mfsig file are raw per-segment σ. The plot is sharper than an averaged σ-profile, and the two must not be confused.
  • Normalise by total area to compare shapes, keep absolute areas to compare how much polar surface each molecule offers.

Questions people ask

Which bin width should I use for a σ-profile plot?
The usual choice in the COSMO-RS literature is 0.001 e/Ų over the range from -0.03 to +0.03 e/Ų, which gives sixty bins. Use it unless you have a reason not to, so that your plot can be compared with published profiles by eye.
Why does my plot look spikier than the σ-profiles in papers?
Because the values in a .mfsig file are raw screening charge densities per segment, not averaged. Published COSMO-RS profiles are smoothed by averaging each segment with its neighbours before binning. The raw histogram is the honest starting point, and the smoothing is a separate, documented step.
Should the histogram be weighted by area or by count?
By area. A σ-profile is the distribution of surface area over σ, so each segment contributes its area to its bin. Weighting by count treats a large and a small segment the same and distorts the profile.

Further reading

In practice: A .mfsig file is JSON and reads with the standard library. Ordering is done on the site or through the API described in the docs, and AI agents can read the published samples through the MCP server at /mcp.

Generate a σ-profile from your SMILES

Free converter for a profile you already have, a reference-grade DFT run with its provenance record when it has to be defensible.