Metadata-Version: 2.4
Name: HSPiT
Version: 0.1.2
Summary: A toolkit for solvent optimization with  Hansen solubility parameters
Author-email: Emil Kongsbach <emil.cheme@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/Emil-Kongsbach/HSPiT
Project-URL: Repository, https://github.com/Emil-Kongsbach/HSPiT
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: scipy
Requires-Dist: scikit-learn
Requires-Dist: openpyxl
Requires-Dist: rdkit
Requires-Dist: tqdm
Requires-Dist: ugropy
Dynamic: license-file

# HSPiT Library
**Hansen Solubility Parameters in Theory (HSPiT)** — a Python library for modeling solvent/solute miscibility, mixture stability, and solvent selection among other features, using Hansen Solubility Parameters (HSPs).
## Install
HSPiT is pip installable, simply run in a terminal:
```
pip install HSPiT
```

## HSP based activity coefficient model
Computes the activity coefficients of species in a mixture based on diffirences in HSPs
```
from HSPiT import Regula

# Set system parameters
x_lst=[1/3,1/3,1/3]                         # NA
hsp_lst=[(10,10,10),(15,15,15),(20,20,20)]  # MPa^0.5
mvol_lst=[50,50,50]                         # cm^3/mol
T=298                                       #K

# Define mixture
mixture=Regula(x_lst, hsp_lst, mvol_lst,T)


# Get Hansen distance between components 0 and 1
mixture.ra(0,1)

# Get activity coefficient of all components in mixture
mixture.gamma_v()
```
## Stability analysis
The HSP-based activity coefficient can be used to perform a stability analysis of a mixture
```
from HSPiT import Regula

# Set system parameters
x_lst=[1/3,1/3,1/3]                         # NA
hsp_lst=[(10,10,10),(15,15,15),(20,20,20)]  # MPa^0.5
mvol_lst=[50,50,50]                         # cm^3/mol
T=298                                       #K

# Define mixture
mixture=Regula(x_lst, hsp_lst, mvol_lst,T)

# Stability analysis
mixture.is_stable_local() # computes local stability (spinodal)

mixture.is_stable_global() # computes global stability (binodal)

mixture.is_stable()  # computes local stability first (cheap), and only if that is True does it proceed to calculate global stability (expensive)


```


## Solvent optimizer for stable mixtures
Methods for obtaining the HSP parameters of an additive that is likely to stabilize a given mixture.
Method 1 is based on the activity coefficient model, and method 2 is based purely on geometric arguments in HSP+mvol space.
```
from HSPiT import Regula
from HSPiT import Nexus

# Set system parameters
x_lst=[1/3,1/3,1/3]                         # NA
hsp_lst=[(10,10,10),(15,15,15),(20,20,20)]  # MPa^0.5
mvol_lst=[50,50,50]                         # cm^3/mol
T=298                                       #K
N_max =1                                    # number of additives
phi_max=0.05                                # total volume fraction for all additives

# Define systems
mixture1=Regula(x_lst, hsp_lst, mvol_lst,T)   # Method 1
mixture2=Nexus(x_lst, hsp_lst, mvol_lst)      # Method 2

# Find optimal additive parameters
dd_add1,dp_add1,dh_add1, phi_add1 =           mixture1.optimize_additive(phi_max, N_max) # Method 1
dd_add2,dp_add2,dh_add2,mvol_add2, phi_add2 = mixture2.optimize_additive(phi_max, N_max) # Method 2

print(f"method 1: {dd_add1,dp_add1,dh_add1, phi_add1}")           # Method 1
print(f"method 2: {dd_add2,dp_add2,dh_add2,mvol_add2, phi_add2}") # Method 2
```



## Surrogate formulator
Forming surrogates with a reduced number of components representative of an original mixture.
A factor k is used to indicate the degree of prioritization for representation of outlying or isolated components in solubility space, as these are likely to have the greatest influence on mixture stability.
k=1 gives equal priority, and k>1 leads to increasingly higher priority in representing isolated components.
```
from HSPiT import surrogate

# Define system parameters
hsp_lst=[...]  # list with original HSP
mvol_lst=[...] # list with original molar volumes
phi_lst=[...]  # list with original volume fractions
k=...          # prioritization factor for isolated components
N_max=...      # number of surrogate representative points

# Returns parameters for surrogate formulation
hsp_lst,mvol_lst,phi_lst=surrogate(hsp_lst, mvol_lst, phi_lst, k, N_max)
```

## HSP predictor
### Group contribution method
This includes an implementation of the Stefanis-Panayiotou group contribution method.
The functional group data is embedded in the function. One needs only pass a SMILES string, and the function will automatically dissect it into its constituent functional groups and access the parameter values for use in the model.
Additionally, it will automatically trigger either the low or the high path discussed in the original publication.
```
from HSPiT import stefanis_gc

smiles="CCO"

dd,dp,dh=stefanis_gc(smiles)
```

### Fitting based on activity coefficients
This method utilizes the HSP-based activity coefficient model along with UNIFAC-Dortmund to fit the HSP for a target compound.
The HSP is the argument that minimizes the discrepancy between the two activity coefficient models, across a set of binary mixtures.


```
from HSPiT import hsp_fit

smiles = "CCO" # NA
mvol = 58.4    # cm^3/mol

# Returns the fitted HSP parameters
dd,dp,dh=hsp_fit(smiles,mvol)

```


# UNIFAC
 An implementation of the group contribution method of the Dortmund modification of UNIFAC. Calculates the activity coeficients of species in a mixture based on functional group parameters

 ```
 from HSPiT import Unifac_Dortmund

# Set system parameters
smiles_lst = ["CCO", "CC(=O)C","CC=CC"]     # NA
x_lst=[1/3, 1/3, 1/3]                       # NA
T=298                                       # K

mixture=Unifac_Dortmund(smiles_lst,x_lst,T)

# Returns activity coefficient of component 0 in the mixture, according to the order in which the components were passed.
print(mixture.gamma_singular(0))

# Returns activity coefficient of all components in the mixture according to the order in which componenets were passed
print(mixture.gamma_total())

# stability analysis
mixture.is_stable_local() # computes local stability (spinodal)

mixture.is_stable_global() # computes global stability (binodal)

mixture.is_stable()  # computes first local stability (cheap), and only if that is True it proceeds to calculate global stability (expensive)  

 ```
