Using validity

Using validity#

The smact_validity function from the smact.screening module is used to validate chemical compositions according to the chemical rules. A composition is considered valid if it passes two key tests:

  1. Charge Neutrality Test: Ensures that the composition is charge-balanced.

  2. Pauling Electronegativity Test: Ensures that the elements in the composition have appropriate electronegativity differences.

In this example, we apply the smact_validity function to a list of chemical compounds extracted from a dataset.

import pandas as pd
from smact.screening import smact_validity
import re

# Dataset
data = ["NaCl", "K2O", "Fe2O3", "C12H22O11", "CsO8"]

# Create a DataFrame with compound data
df = pd.DataFrame(data, columns=["Compound"])

# Apply smact_validity to check if compounds are valid according to SMACT rules
df["smact_allowed"] = df["Compound"].apply(smact_validity)

# Display the filtered and validated DataFrame
print(df)

# Calculate and display the fraction of valid compounds
fractions = df["smact_allowed"].value_counts(normalize=True)
print(fractions)
    Compound  smact_allowed
0       NaCl           True
1        K2O           True
2      Fe2O3           True
3  C12H22O11          False
4       CsO8          False
smact_allowed
True     0.6
False    0.4
Name: proportion, dtype: float64

Mixed-Valence Compounds#

Some compounds contain elements in multiple oxidation states simultaneously. For example, magnetite (Fe3O4) contains both Fe²⁺ and Fe³⁺ ions. By default, smact_validity assumes each element has a single oxidation state, which causes these compounds to fail validation.

The mixed_valence parameter enables validation of such compounds by allowing elements in MIXED_VALENCE_ELEMENTS (transition metals, lanthanides, actinides) to adopt different oxidation states for each atom.

# Mixed-valence compounds
mixed_valence_compounds = ["Fe3O4", "Mn3O4", "Co3O4", "U3O8"]

print("Without mixed_valence flag:")
for compound in mixed_valence_compounds:
    result = smact_validity(compound, mixed_valence=False)
    print(f"  {compound}: {result}")

print("\nWith mixed_valence=True:")
for compound in mixed_valence_compounds:
    result = smact_validity(compound, mixed_valence=True)
    print(f"  {compound}: {result}")

print("\nExplanation:")
print("Fe3O4 (magnetite) = Fe²⁺ + 2×Fe³⁺ + 4×O²⁻ = +2 + 6 - 8 = 0 (charge balanced)")