Skip to content

Repository files navigation

中文 | Español | English

PyPIversion

Tip

Looking for a no-code version of HSPiPy? Get HSP Desktop

HSPiPy

Hansen Solubility Parameters in Python.

Introduction


HSPiPy is a Python library designed for calculating and visualizing Hansen Solubility Parameters (HSP). It provides machine-learning–friendly estimators, convenient data import, and plotting tools for analyzing solvent compatibility in materials science, polymers, and coatings.

Features


  • Read solvent data from multiple formats (CSV, HSD, HSDX)
  • Calculate Hansen Solubility Parameters using robust optimization methods
  • Support for single or multiple (up to 2) solubility spheres
  • Generate 2D and 3D visualizations of solubility spheres
  • Fully compatible with scikit-learn for machine learning workflows

Documentation


Installation


Install HSPiPy easily with pip:

pip install HSPiPy

Dependencies

  • numpy
  • pandas
  • matplotlib
  • scipy
  • scikit-learn

Usage


Reading HSP Data

To read HSP data from a file (CSV, HSD or HSDX), create an instance of the HSP class and use the read method:

fromhspipyimportHSPhsp=HSP()
hsp.read('path_to_your_hsp_file.csv')

Calculating HSP

Use the get method to calculate the Hansen Solubility Parameters (HSP) from your data:

# For a single sphere model (default)result=hsp.get(inside_limit=1)
# For a double sphere modelresult=hsp.get(inside_limit=1, n_spheres=2)

get() returns an HSPResult object. In a Jupyter notebook it renders as a formatted table automatically. In a script use print(result) or access attributes directly:

print(result.hsp) # fitted D, P, H center coordinatesprint(result.radius) # sphere radiusprint(result.accuracy) # classification accuracyprint(result.datafit) # DATAFIT valueprint(result.n_solvents_in) # number of good solventsprint(result.n_solvents_out) # number of bad solventsprint(result.n_total) # total solventsprint(result.n_wrong_in) # bad solvents inside sphere (false positives)print(result.n_wrong_out) # good solvents outside sphere (false negatives)

The inside_limit parameter defines the threshold score value to consider a solvent as "inside" the solubility sphere (default: inside_limit=1).

Visualizing HSP

Use the plot_3d and plot_2d methods to visualize the HSP data in 3D and 2D formats, respectively:

# Generate individual plotshsp.plot_3d()
hsp.plot_2d()
# Or generate both plots at oncehsp.plots()

3dHSP2dHSP

HSP class methods:

MethodDescription
read(path)Reads solvent data from a CSV, HSD, or HSDX file.
get(inside_limit=1, n_spheres=1)Fits HSP sphere(s) and returns an HSPResult object.
plot_3d()Plots the HSP data in 3D. Returns the figure.
plot_2d()Plots the HSP data in 2D. Returns the figure.
plots()Generates both 2D and 3D plots. Returns (fig_3d, fig_2d).

get() returns an HSPResult object. The following attributes are available on it and also set on the HSP instance after calling get():

AttributeDescription
result.hspNumpy array — Fitted HSP coordinates. Shape: (3,) for single-sphere (D, P, H), or (n_spheres, 3) for multiple spheres.
result.radiusFloat or array — Radius (or radii) of the solubility sphere(s).
result.errorFloat — Objective function value from the optimization (lower is better).
result.accuracyFloat — Classification accuracy of the fitted model on the dataset.
result.datafitFloat — DATAFIT value (geometric mean fitness; 1.0 = perfect classification).
result.n_solvents_inInt — Number of good solvents (0 < score <= inside_limit).
result.n_solvents_outInt — Number of bad solvents (score == 0 or score > inside_limit).
result.n_totalInt — Total number of solvents.
result.n_wrong_inInt — Bad solvents predicted inside the sphere (false positives).
result.n_wrong_outInt — Good solvents predicted outside the sphere (false negatives).
hsp.d, hsp.p, hsp.hFloat — Individual HSP components (δD, δP, δH). Single-sphere only; None for multi-sphere.
hsp.insideList — Solvents classified as inside the solubility sphere(s), with their HSP values and scores.
hsp.outsideList — Solvents classified as outside the solubility sphere(s), with their HSP values and scores.
hsp.gridPandas DataFrame — The full input dataset, standardized with columns: Solvent, D, P, H, and Score.

Using scikit-learn style estimator

importnumpyasnpfromhspipyimportHSPEstimator# Example dataset (D, P, H values with scores)X=np.array([
[16.0, 8.0, 5.0],
[18.0, 7.5, 9.0],
[20.0, 10.0, 12.0],
])
y=np.array([1, 1, 0]) # Inside/outside labels or scoresest=HSPEstimator(n_spheres=1)
est.fit(X, y)
print("Fitted HSP:", est.hsp_)
print("Accuracy:", est.score(X, y))

Contributing


Contributions are welcome! If you have any suggestions, feature requests, or bug reports, please open an issue on the GitHub repository.

Supporting HSPiPy


If HSPiPy is useful for your work, there are several ways to support its continued development.

🖥️ HSP Desktop (No-Code Version)

HSP Desktop is an affordable desktop application built on top of the HSPiPy engine, providing a fast and intuitive graphical interface for Hansen Solubility Parameter analysis.

It is ideal for users who:

  • Prefer a graphical interface over Python scripting
  • Need a fast, one-click workflow for HSP calculations
  • Want advanced visualization and solvent exploration tools

👉 https://g-npd.com/hsp

Purchasing HSP Desktop helps fund the continued development of HSPiPy, including new features, databases, documentation, and maintenance.

❤️ GitHub Sponsors

You can also support the project directly through GitHub Sponsors:

👉 https://github.com/sponsors/Gnpd

Every contribution helps keep HSPiPy free, open source, and actively maintained.

License


This library is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements


HSPiPy was inspired by the well-known HSP software suit Hansen Solubility Parameters in Practice (HSPiP) and by the HSP community.

About

Hansen Solubility Parameters in Python.

Topics

Resources

Stars

27 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages