技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
data-featurization【数据与研究】Prepare and validate Chemprop CSV/NPZ inputs, SMILES/reaction columns, descriptors, atom/bond features, featurizers, datasets, dataloaders, and split APIs.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when a task is about Chemprop 2.2.3 data objects, CSV/NPZ input schemas, SMILES or reaction columns, descriptors, extra atom/bond arrays, graph or molecule featurizers, split construction, or dataloaders. Keep this sub-skill focused on getting data into Chemprop correctly; route downstream model fitting, checkpoint use, prediction, uncertainty, and atom/bond target semantics to sibling skills.
MoleculeDatapoint, ReactionDatapoint, MoleculeDataset, ReactionDataset, or MulticomponentDataset from Python.--no-header-row inputs..npz files for --descriptors-path, --atom-features-path, --atom-descriptors-path, --bond-features-path, or --bond-descriptors-path.morgan_binary, morgan_count, rdkit_2d, v1_rdkit_2d, v1_rdkit_2d_normalized, or charge.make_split_indices and applying them with split_data_by_indices.torch.utils.data.DataLoader objects with Chemprop’s build_dataloader.cuik-molmaker acceleration constraints and why it is not always available.| Situation | Use |
|---|---|
| CSV has one molecule column and row targets | --smiles-columns <col> and standard MoleculeDatapoint / MoleculeDataset patterns |
| CSV has no header row | --no-header-row; Chemprop treats column 0 as the default SMILES column unless explicit integer column labels are used through Python/pandas-compatible parsing |
| CSV has two or more molecule columns | pass all molecule columns to --smiles-columns; Python API uses one component dataset per column and wraps them in MulticomponentDataset |
| CSV has reaction SMILES | --reaction-columns <col> and ReactionDatapoint / ReactionDataset with CondensedGraphOfReactionFeaturizer |
| Extra row-level numeric descriptors | --descriptors-path descriptors.npz containing one 2D X_d array shaped n_rows x n_descriptors, or --descriptors-columns for descriptor columns in the CSV |
| Extra atom or bond features before message passing | .npz created with np.savez(path, *V_fs) or np.savez(path, *E_fs), one 2D array per row |
| Extra atom or bond descriptors after message passing | .npz created with np.savez(path, *V_ds) or np.savez(path, *E_ds), one 2D array per row |
| Need generated molecular descriptors | --molecule-featurizers morgan_binary, morgan_count, rdkit_2d, v1_rdkit_2d, v1_rdkit_2d_normalized, or charge |
| Need fast on-the-fly graph building | --use-cuikmolmaker-featurization only for single-component molecule data with the optional extra installed and unsupported flags avoided |
Use the bundled validator before training or prediction when a user reports shape or column errors:
python sub-skills/data-featurization/scripts/validate_chemprop_tabular_inputs.py \
--csv data.csv \
--smiles-columns smiles \
--target-columns target \
--descriptors-path descriptors.npz \
--atom-features-path atom_features.npz
For multicomponent data, validate one file with multiple SMILES columns and component-indexed feature paths:
python sub-skills/data-featurization/scripts/validate_chemprop_tabular_inputs.py \
--csv data.csv \
--smiles-columns solute solvent \
--component-descriptors 0 solute_descriptors.npz \
--component-descriptors 1 solvent_descriptors.npz
For reaction data, validate reaction column syntax and descriptor row counts:
python sub-skills/data-featurization/scripts/validate_chemprop_tabular_inputs.py \
--csv reactions.csv \
--reaction-columns rxn \
--descriptors-path reaction_descriptors.npz
For headerless CSVs, use zero-based column numbers in the validator and --no-header-row in Chemprop:
python sub-skills/data-featurization/scripts/validate_chemprop_tabular_inputs.py \
--csv no_header.csv \
--no-header-row \
--smiles-columns 0 \
--target-columns 1
The validator is intentionally conservative. It checks header/no-header handling, column presence, duplicate or overlapping column roles, nonempty SMILES/reaction/target/descriptor cells, reaction separator syntax, duplicate component feature indices, .npz loadability, expected row counts, descriptor matrix rank, and per-row atom/bond array rank. It does not replace RDKit chemistry validation or Chemprop training.
Chemprop 2.2.3 accepts these public construction signatures for the core data path:
MoleculeDatapoint(mol, y=None, weight=1.0, gt_mask=None, lt_mask=None, x_d=None, x_phase=None, name=None, V_f=None, E_f=None, V_d=None)
ReactionDatapoint(rct, pdt, y=None, weight=1.0, gt_mask=None, lt_mask=None, x_d=None, x_phase=None, name=None)
MoleculeDataset(data, featurizer=<factory>, n_workers=0)
MulticomponentDataset(datasets)
build_dataloader(dataset, batch_size=64, num_workers=0, class_balance=False, seed=None, shuffle=True, drop_last=None, **kwargs)
make_split_indices(mols, split="random", sizes=(0.8, 0.1, 0.1), seed=0, num_replicates=1, num_folds=None)
split_data_by_indices(data, train_indices=None, val_indices=None, test_indices=None)
Start with references/data-api.md for datapoints, datasets, dataloaders, split utilities, and batch fields.
Minimal molecule dataset pattern:
import numpy as np
from chemprop.data import MoleculeDatapoint, MoleculeDataset, build_dataloader
data = [MoleculeDatapoint.from_smi("CCO", y=np.array([1.2]))]
dset = MoleculeDataset(data)
loader = build_dataloader(dset, batch_size=32, shuffle=True, seed=0)
Minimal reaction dataset pattern:
import numpy as np
from chemprop.data import ReactionDatapoint, ReactionDataset
from chemprop.featurizers.molgraph import CondensedGraphOfReactionFeaturizer
data = [ReactionDatapoint.from_smi("[CH3:1][OH:2]>>[CH2:1]=[O:2]", y=np.array([0.3]))]
dset = ReactionDataset(data, featurizer=CondensedGraphOfReactionFeaturizer(mode_="reac_diff"))
Use references/featurizers.md for featurizer choices, dimensions, reaction modes, molecule descriptor registry names, and cuik-molmaker caveats.
Read references/extra-features-descriptors.md when a user asks how to create .npz files or why Chemprop says array lengths do not match.
Core meanings:
x_d / X_d: row-level extra descriptors concatenated after molecular aggregation; one vector per datapoint.V_f: per-atom features concatenated to atom features before message passing; one n_atoms x d_vf matrix per molecule.E_f: per-bond features concatenated to bond features before message passing; one n_bonds x d_ef matrix per molecule.V_d: per-atom descriptors concatenated after message passing; one n_atoms x d_vd matrix per molecule.E_d: per-bond descriptors for atom/bond specialized models; one n_bonds x d_ed matrix per molecule.For multicomponent CLI atom/bond paths, a single path means component 0. To attach atom/bond features or descriptors to multiple molecule columns, pass component-index/path pairs for each component. Row-level --descriptors-path is global to the datapoint row; do not use it for atom- or bond-indexed arrays.
make_split_indices(mols, split="random", sizes=(0.8, 0.1, 0.1), seed=0, num_replicates=1) returns train, validation, and test index lists grouped by replicate.random, random_with_repeated_smiles, scaffold_balanced, kennard_stone, and kmeans.split_data_by_indices(data, train_indices, val_indices, test_indices) handles molecule, reaction, and multicomponent datapoint collections.build_dataloader chooses the correct collate function for molecule, reaction, multicomponent, cuik-molmaker, or atom/bond datasets.class_balance=True is only appropriate for single-task classification labels and conflicts with ordinary regression assumptions.Use references/troubleshooting.md for detailed fixes. Fast triage:
reactants>agents>products or reactants>>products, and atom maps for reaction CGR tasks.--no-header-row; otherwise Chemprop treats the first row as headers and shifts data rows unexpectedly..npz mismatch: row count must match CSV rows; atom/bond matrices must match RDKit atom/bond counts in the same order.--smiles-columns for molecules, --reaction-columns with --rxn-mode/--reaction-mode for reactions, and component-indexed atom/bond paths for multicomponent inputs.--no-descriptor-scaling, --no-atom-feature-scaling, --no-atom-descriptor-scaling, --no-bond-feature-scaling, and --no-bond-descriptor-scaling preserve externally scaled inputs.cuik-molmaker errors: install the optional package and avoid unsupported settings such as reactions, multiple molecule components, --keep-h, --ignore-stereo, or --reorder-atoms.For later usability verification, include these difficult cases:
solute and solvent columns plus separate descriptor .npz files; assertions catch that one descriptor file has one fewer row than the CSV and that component index 2 is out of range.--multi-hot-atom-featurizer-mode V1 and v1_rdkit_2d_normalized, then asserts the skill explains why Chemprop v2 defaults differ from v1-compatible featurization.