A formula and a crystal structure carry different information. This distinction determines which matminer featurizers you can use and what conclusions a feature table can support. This guide is for materials researchers comfortable with Python who need an inspectable baseline before training a model.

Composition describes ingredients; structure adds geometry

pymatgen.core.Composition stores elemental amounts. ElementProperty.from_preset("magpie") summarizes tabulated elemental properties using composition-weighted statistics. Those statistics describe the constituent elements, not a measured property of the compound. Identical composition cannot distinguish polymorphs using these features alone. See the ElementProperty implementation.

pymatgen.core.Structure adds lattice, atomic species and sites. DensityFeatures consumes a structure and can return density, volume per atom (vpa) and packing fraction. Formula alone cannot determine these values because it does not specify volume or arrangement. DensityFeatures source also checks whether the structure is ordered; different featurizers have different admissible inputs.

Available information Suitable starting point What remains unknown
Formula with meaningful stoichiometry Composition + Magpie statistics Crystal volume, polymorph and local environment
Traceable ordered crystal structure Structure + selected density features Whether the geometry represents the intended phase/conditions
Partial occupancy or ambiguous composition Record and resolve the representation first Whether the selected featurizer supports that disorder

Fix a version and preserve the feature schema

On 2026-10-18, PyPI metadata reports matminer 0.10.1 with Python >=3.11, while the hosted API pages identify themselves as 0.10.0rc0. Use the installed release’s API/source rather than assuming those labels are identical. Current source exposes from_preset, featurize, feature_labels and the explicit impute_nan option used below. Pin matminer, pymatgen and NumPy together after checking your environment; this article has not established their combined compatibility.

Save ordered labels alongside values. A changed preset, imputation policy or feature order changes the meaning of a column even if a file still loads. matminer’s code licence has BSD-style redistribution conditions; this does not settle the terms for a downloaded materials dataset or every bundled property source.

Minimal composition and structure example

The following makes a deliberately synthetic cubic two-site cell with pymatgen’s documented constructors. Its lattice parameter is illustrative, not a relaxed structure or reference crystal. No Materials Project request is involved. Code status: not executed. The output is a table of calculated descriptors, not a prediction or experimental measurement.

import numpy as np
from importlib.metadata import version
from pymatgen.core import Composition, Lattice, Structure
from matminer.featurizers.composition import ElementProperty
from matminer.featurizers.structure import DensityFeatures

composition = Composition("NaCl")
structure = Structure(Lattice.cubic(5.6), ["Na", "Cl"],
                      [[0, 0, 0], [0.5, 0.5, 0.5]])
magpie = ElementProperty.from_preset("magpie", impute_nan=False)
density = DensityFeatures(desired_features=["density", "vpa"])
comp_values = magpie.featurize(composition)
struct_values = density.featurize(structure)
assert len(comp_values) == len(magpie.feature_labels())
assert len(struct_values) == len(density.feature_labels())
assert np.isfinite(np.asarray(struct_values, dtype=float)).all()
expanded = structure.copy()
expanded.scale_lattice(2 * structure.volume)
expanded_values = dict(zip(density.feature_labels(), density.featurize(expanded)))
base_values = dict(zip(density.feature_labels(), struct_values))
assert np.isclose(expanded_values["density"], base_values["density"] / 2)
assert np.isclose(expanded_values["vpa"], base_values["vpa"] * 2)
print({p: version(p) for p in ("matminer", "pymatgen", "numpy")})
print(dict(zip(magpie.feature_labels(), comp_values)))
print(base_values)

The pymatgen core API supplies the lattice/structure objects; matminer consumes those objects. Running this example should produce labeled composition features and two labeled structure features. The assertions check length, finiteness and a geometric identity under doubled cell volume. They supply no expected measured value or model score.

Replace toy data with traceable records

For real work, read a structure with Structure.from_file(...) or another documented parser and preserve the original file hash. Record material/database ID, retrieval date, database release, formula, cell volume, occupancy, periodicity and any geometry relaxation. If structures come from the Materials Project API, that acquisition is a separate networked step with its own authentication and dataset conditions.

Reject parse errors explicitly. Check positive cell volume, nonempty sites, expected species, formula consistency and the selected featurizer’s preconditions. A CIF can be syntactically readable yet contain the wrong phase, occupancy or unit-cell interpretation. Do not invent a structure from a formula merely to satisfy an input type. Keep polymorphs and related measurements grouped according to the evaluation question.

Treat missing values as information

The example deliberately sets impute_nan=False so missing elemental data remain observable. This is different from filling a missing experimental target, and different from a later statistical imputer fitted on a training table. An exception, a valid NaN and an unavailable label require separate statuses.

For batch processing, the BaseFeaturizer API offers dataframe/multiple-input interfaces and error-handling options. If you opt to continue on errors, save the failure reason and record ID; do not treat an all-NaN row as a successful calculation. Decide whether to reject a record, drop a feature or fit an imputer using training data only. Apply that fitted policy unchanged to validation and test sets.

Prevent structure and preprocessing leakage

Freeze split IDs before fitting scalers, missing-value imputers or feature selection. Separate related structures according to the question; random rows from one material’s relaxation trajectory are not independent unseen materials. Also ask whether the structure would be available at prediction time: using a fully relaxed reference geometry when the intended task starts from formula alone changes the problem.

Check feature names and units before scoring a downstream model: density follows pymatgen’s mass/volume convention, volume per atom is in cubic ångströms for the standard structure representation, and packing fraction is dimensionless. Keep per-feature missingness and rejected-row counts in the report. Density is calculated from input mass and geometry; it does not validate an experimental density or prove thermodynamic stability.

Acceptance checklist

A usable feature artifact contains source IDs/hashes, raw and processed representations, pinned versions, featurizer configuration, ordered column names and units, missingness/error logs and split membership. Verify that feature and target rows align. The existing materials Recipe is a related discovery workflow, not evidence that this specific featurization pipeline has been executed or integrated with CARS.

Related ChemAI Atlas resources and workflows

Matminer · Pymatgen · Materials Project API

AI for Materials Science: Tools, Agents and Skills · Dataset Provenance and Licensing for Chemistry AI · CHGNet and Matbench Discovery: A Materials Model Evaluation Checklist

Materials Research Starter Stack

CARS

Sources and evidence status

Sources inspected on 2026-10-18. Primary documentation supports capability/API statements. Audit protocols are editorial proposals; no scientific validation or measured performance is reported.