# DISTAL Prediction Code

This folder is a standalone usage package for applying pretrained DISTAL
features to a user-defined property-prediction task. 

## Files

```text
UseCode/
  distal_property_prediction.py
  models/
    adaptive_denoising_resnet.pth
    student_encoder_best.pth
  examples/
    train_property.csv
    candidate_formulas.csv
  outputs/
  requirements.txt
```

## Input CSV Files

Prepare two CSV files:

1. A labeled training CSV with material formulas and known property values.

```text
formula,property
Si,1.12
GaAs,1.42
ZnO,3.30
```

2. A prediction CSV with formulas whose property values should be predicted.

```text
formula
MgO
Al2O3
BaTiO3
```

The formula column can be named `formula`, `pretty_comp`, `composition`, `comp`,
`material`, or `Material`. If the target column is not named `property`, pass it
with `--target_col`.

## Install Dependencies

```bash
pip install -r requirements.txt
```

## Quick Test

Run this short example from the `UseCode` directory:

```bash
python distal_property_prediction.py \
  --train_csv examples/train_property.csv \
  --predict_csv examples/candidate_formulas.csv \
  --formula_col formula \
  --target_col property \
  --output_csv outputs/example_predictions.csv \
  --bundle outputs/example_task_bundle.pt \
  --folds 3 \
  --max_epochs 20 \
  --patience 5
```

## Recommended Full Run

For a real dataset, use the default 10-fold ensemble:

```bash
python distal_property_prediction.py \
  --train_csv path/to/known_property_data.csv \
  --predict_csv path/to/candidate_formulas.csv \
  --formula_col formula \
  --target_col property \
  --output_csv outputs/predictions.csv \
  --bundle outputs/task_bundle.pt
```

The output CSV preserves the candidate rows and adds:

- `prediction`: ensemble mean prediction
- `ensemble_std`: standard deviation across fold models
- `parse_error`: formula parsing or descriptor-generation error, if any

The script generates the 145-dimensional composition descriptors with
`pymatgen` and `matminer`, keeps all 145 descriptor columns, constructs DISTAL
`z+x+s` features with the pretrained models, trains a task-specific predictor on
the labeled CSV, and predicts the candidate CSV.
