File size: 8,863 Bytes
709e90e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | ---
license: mit
tasks:
- protein-structure-prediction
frameworks:
- pytorch
language:
- en
- zh
tags:
- OneScience
- Life Sciences
- Protein Language Model
- Protein Structure Prediction
- Variant Effect Prediction
- ESM
huggingface:
model: OneScience-Sugon/ESM
data_path: data/
---
<p align="center">
<strong>
<span style="font-size: 30px;">ESM</span>
</strong>
</p>
# Model Introduction
ESM (Evolutionary Scale Modeling) is a family of protein language models released by Meta AI / FAIR. It can be used for protein representation extraction, structure prediction, variant effect scoring, and fixed-backbone sequence design.
Paper: Evolutionary-scale prediction of atomic-level protein structure with a language model
https://www.science.org/doi/10.1126/science.ade2574
# Model Description
This model package provides PyTorch inference support for ESM-1, ESM-2, MSA Transformer, ESMFold, ESM-1v, and ESM-IF1, together with adaptations for running on DCUs. Sample data is distributed with the Hugging Face model repository `OneScience-Sugon/ESM`.
# Use Cases
| Scenario | Description |
| :---: | :--- |
| Protein representation extraction | Takes a FASTA file as input and outputs per-token, mean-pooled, BOS, or contact representations |
| Protein structure prediction | Takes one or more amino acid sequences as input and outputs corresponding PDB structure files |
| Variant effect scoring | Takes a wild-type sequence and a DMS mutation table as input and outputs mutation effect scores |
| Fixed-backbone sequence design | Takes a PDB / CIF structure and chain ID as input and samples candidate sequences that satisfy the backbone constraints |
| Structure-conditioned sequence scoring | Takes a structure and candidate sequences as input and computes their conditional log-likelihoods |
| Hugging Face / OneCode execution | After downloading the model project, quickly verifies that the scripts run correctly in a life-sciences runtime environment |
# Usage Guide
## 1. OneCode Usage
Try one-click AI4S development in the OneCode online environment:
[Try one-click AI4S development](https://web-2069360198568017922-iaaj.ksai.scnet.cn:58043/home)
## 2. Manual Installation and Usage
**Hardware Requirements**
- GPU or DCU is recommended.
- A CPU can be used for import checks and lightweight configuration tests; full training and inference will be slow.
- DCU users must install DTK in advance. DTK 25.04.2 or later is recommended, or a OneScience-recommended version matching the current cluster.
**Environment Check**
- NVIDIA GPU:
```bash
nvidia-smi
```
- Hygon DCU:
```bash
hy-smi
```
### Download the Model Package
```bash
hf download --model OneScience-Sugon/ESM --local-dir ./ESM
cd ESM
```
This model package includes a small set of sample data that can be used directly to validate the default workflow.
### Install the Runtime Environment
**DCU Environment**
```bash
# Activate DTK and CONDA first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
# uv installation supported
pip install onescience[bio-dcu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai
```
```bash
# If required libraries cannot be found, activate the CUDA compatibility environment as follows:
source ${ROCM_PATH}/cuda/env.sh
export LD_LIBRARY_PATH="$CONDA_PREFIX/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="$CONDA_PREFIX/lib/python3.11/site-packages/fastpt/torch/lib:$LD_LIBRARY_PATH"
```
After installation, return to the model package directory:
```bash
cd ./ESM
```
### Training and Inference Data Overview
The FASTA, PDB / CIF, and DMS files used in the ESM examples are distributed with the [Hugging Face model repository OneScience-Sugon/ESM](https://huggingface.co/OneScience-Sugon/ESM). After downloading the complete model package, the files are available under `data/`. This model package does not include a training entry point; the data is intended for example inference and workflow validation. You can also download only the data directory:
```bash
hf download --model OneScience-Sugon/ESM ESM/data --local-dir ./data
```
### Model Weights
The repository includes multiple ESM model checkpoints under `weight/`; select the appropriate checkpoint for inference.
### Preparing Weights
Place the required ESM weights in the following directory:
```text
weight/
checkpoints/
esm2_t6_8M_UR50D.pt
esmfold_3B_v1.pt
esm1v_t33_650M_UR90S_1.pt
esm_if1_gvp4_t16_142M_UR50.pt
...
```
When using a shared runtime environment, you can specify the weights location through an environment variable:
```bash
export ESM_WEIGHT_DIR=/path/to/esm/weight
```
The default example uses:
- `weight/checkpoints/esm2_t6_8M_UR50D.pt`
The ESMFold, ESM-1v, and ESM-IF1 examples require their respective weights to be available.
### Default Example
```bash
bash scripts/infer.sh
```
The default example reads `data/fasta/few_proteins.fasta`, extracts protein representations using `esm2_t6_8M_UR50D.pt`, and saves the results to `outputs/embeddings/`.
### Sequence Representation Extraction
```bash
python scripts/extract.py \
weight/checkpoints/esm2_t6_8M_UR50D.pt \
data/fasta/few_proteins.fasta \
outputs/embeddings \
--include mean per_tok \
--repr_layers 6
```
### ESMFold Structure Prediction
```bash
python scripts/fold.py \
-i data/fasta/few_proteins.fasta \
-o outputs/pdb \
--model-dir weight \
--cpu-only
```
The output directory will contain one or more `.pdb` files. For production GPU / DCU inference, remove `--cpu-only` and configure `--chunk-size` or `--max-tokens-per-batch` according to the available accelerator memory.
You can also explicitly enable ESMFold via the default script:
```bash
RUN_ESMFOLD=1 bash scripts/infer.sh
```
### Inverse Folding — Sequence Sampling
```bash
python scripts/inverse_folding/sample_sequences.py \
data/inverse_folding/5YH2.pdb \
--chain A \
--outpath outputs/sampled_seqs.fasta \
--num-samples 1 \
--nogpu
```
### Inverse Folding — Sequence Scoring
```bash
python scripts/inverse_folding/score_log_likelihoods.py \
data/inverse_folding/5YH2.pdb \
data/inverse_folding/5YH2_mutated_seqs.fasta \
--chain A \
--outpath outputs/sequence_scores.csv \
--nogpu
```
### Variant Effect Prediction
Variant effect prediction requires a wild-type sequence that is consistent with the mutation annotations in the DMS table:
```bash
python scripts/variant_prediction/predict.py \
--model-location esm1v_t33_650M_UR90S_1 \
--sequence "${ESM_VARIANT_SEQUENCE}" \
--dms-input data/variant_prediction/BLAT_ECOLX_Ranganathan2015.csv \
--mutation-col mutant \
--dms-output outputs/variant_prediction.csv \
--offset-idx 24 \
--scoring-strategy wt-marginals
```
# Data Format
Sample data is stored under `data/` by default:
```text
data/
fasta/
few_proteins.fasta
some_proteins.fasta
inverse_folding/
5YH2.pdb
5YH2.cif
5YH2_mutated_seqs.fasta
example.json
variant_prediction/
BLAT_ECOLX_Ranganathan2015.csv
rho_pp.csv
aggregated_rho.csv
aggregated_rho_round3.csv
```
In this structure:
- FASTA files are used for sequence representation extraction and structure prediction.
- PDB / CIF files are used for inverse folding sampling and structure-conditioned sequence scoring.
- Variant effect prediction CSV files must include a mutation column. The default column name is `mutant`, and mutations use notation such as `A123B`.
- For custom DMS data, the wild-type amino acid at each mutated position in the sequence provided via `--sequence` must match the corresponding mutation annotation.
# Verification
Static import check:
```bash
python scripts/check_import_boundaries.py
```
Syntax check:
```bash
python -B -c "import ast, pathlib; [ast.parse(p.read_text(encoding='utf-8'), filename=str(p)) for root in ['model', 'scripts', 'tests'] for p in pathlib.Path(root).rglob('*.py')]"
```
# OneScience Official Information
| Platform | OneScience Main Repository | Skills Repository |
| --- | --- | --- |
| Gitee | https://gitee.com/onescience-ai/onescience | https://gitee.com/onescience-ai/oneskills |
| GitHub | https://github.com/onescience-ai/OneScience | https://github.com/onescience-ai/oneskills |
# Citation & License
- This repository is adapted from the open-source ESM model to support DCUs.
- The ESM source code is licensed under the MIT License; see `LICENSE`. For the usage terms governing model weights and data, refer to the documentation provided by the respective publishers.
- For scientific use, please cite the corresponding original ESM paper for each submodel used. For ESM-2 / ESMFold, cite: [Evolutionary-scale prediction of atomic-level protein structure with a language model](https://www.science.org/doi/10.1126/science.ade2574).
|