Antimicrobial peptides (AMPs) emerge as a type of promising therapeutic compounds that exhibit broad spectrum antimicrobial activity with high specificity and good tolerability. However, current AI-based AMP design strategies, which primarily rely on learning the distribution of natural AMPs, fail to overcome the inherent trade-off between antimicrobial activity and toxicity, thereby hindering their clinical translation. In this work, we propose PepGen-FB, a novel multi-objective optimization method for optimizing desired properties for AMPs iteratively. It employs a curriculum learning-guided feedback mechanism to iteratively guide the generative model to \textcolor{red}{smoothly} optimize AMPs with improving antibacterial activity and decreasing toxicity. Comprehensive experiments demonstrate that the AMPs designed by PepGen-FB substantially outperform natural prototypes in achieving an optimal balance between high antimicrobial activity and low cytotoxicity, \textcolor{red}{improved the generation success rate from 7.1% to 96.2% compared to the ProGen2 model. Further motif analyses provide interpretative support for the optimization process. PepGen-FB enables the seamless integration of arbitrary black-box predictors while ensuring optimization stability through curriculum-guided feedback, which establishes a novel data-driven optimization paradigm.
This directory contains a protein/peptide sequence generation and screening pipeline built on top of ProGen2. Its main purpose is to:
- build an initial training set from
non_redundant_sequences.csv - score sequences with external property models, including toxicity, MIC, and perplexity
- fine-tune a ProGen2 backbone with LoRA
- iteratively generate new sequences and replace low-quality training samples with candidates that have higher MIC and lower toxicity
The full workflow is centered around main.py, while generate.py, pred_toxin.py, perplexity.py, and attribute_util/ provide supporting functionality.
main.py: main training script. Builds the initial scored dataset, runs LoRA fine-tuning, performs feedback-based replacement, and saves outputs.model.py: wraps the ProGen2 backbone and PEFT LoRA logic, and defines repetition suppression during sampling.generate.py: generates candidate sequences in batches and scores them with downstream property predictors.seq_dataloader.py: tokenizes amino acid sequences and converts them into ProGen2 input tensors.pred_toxin.py: predicts toxicity probabilities with the localtoxinpred3model.perplexity.py: computes sequence perplexity with ProGen2 plus a LoRA checkpoint.paint_physicochemical_properties.py: analyzes and visualizes physicochemical properties of training and generated sequences.data/: example data and training data.attribute_util/: AMP/MIC property models, utility code, sequence feature processing, and inference helpers.toxinpred3/: offline toxicity prediction package and model files.checkpoints/fb_epoch_0/: the trained LoRA model.
The execution flow in main.py is:
- Read the
Sequencecolumn fromdata/non_redundant_sequences.csv. - Predict toxicity scores with
pred_toxin.py. - Predict MIC scores with the model stored in
attribute_util/models/mic_classifier/. - Compute perplexity with
perplexity.py. - Save the scored dataset to
data/train.csv. - Tokenize and pad sequences with
seq_dataloader.py. - Fine-tune the
../progen2-largebackbone with LoRA. - For each feedback round:
- generate candidate sequences with
generate.py - compute MIC, toxicity, and perplexity for candidates
- filter candidates by threshold
- replace low-MIC or high-toxicity samples in the training set
- continue fine-tuning and save a new LoRA checkpoint
- generate candidate sequences with
data/non_redundant_sequences.csv- columns:
Sequence - purpose: initial sequence pool for training
- columns:
data/train.csv- columns:
SEQUENCE,TOXIN_predict,MIC_predict,Perplexity - purpose: scored training dataset
- columns:
data/Uniprot_0.csv- columns:
Name,Sequence - purpose: reference set used mainly by the physicochemical analysis script
- columns:
The code expects the ProGen2 backbone to be available in the sibling directory:
../progen2-large
The following files must be available there:
tokenizer.jsonconfiguration_progen.pymodeling_progen.py- the corresponding Hugging Face model weights and config files
If the directory layout changes, update the model_dir or tokenizer paths in model.py, seq_dataloader.py, and perplexity.py.
The repository already includes the required local model assets:
attribute_util/models/amp_classifier/attribute_util/models/mic_classifier/toxinpred3/model/toxinpred3.0_model.pkl
These are loaded directly at runtime and do not need to be downloaded.
Python 3.9 or 3.10 is recommended. The project depends on both:
- PyTorch / Transformers / PEFT
- TensorFlow / Keras
- scikit-learn and joblib
- pandas and numpy
Using an isolated virtual environment is recommended to avoid version conflicts between PyTorch and TensorFlow.
pip install -r requirements.txtIf you want to use the original toxinpred3 standalone script in addition to the wrapper inside pred_toxin.py, make sure the system also provides:
perl
From this directory:
python main.py \
--output_dir checkpoints/mul/ \
--max_length 50 \
--start_MIC_cutoff 0.70 \
--target_MIC_cutoff 0.90 \
--start_TOXIN_cutoff 0.55 \
--target_TOXIN_cutoff 0.33 \
--num_train_epochs 10 \
--feedback_epochs 7The main script will:
- generate or update
data/train.csv - save LoRA checkpoints under
checkpoints/.../fb_epoch_* - save scored candidate results to
result.csv
python generate.py --output_dir checkpoints/fbloraNote: in its __main__ block, generate.py initializes the model in "load existing LoRA checkpoint" mode, so --output_dir must point to an existing PEFT checkpoint.
python paint_physicochemical_properties.pyThis script reads data/train.csv and multiple experiment outputs under checkpoints/, then performs analysis and plotting with modlamp, matplotlib, and seaborn.
The main arguments in main.py are:
--output_dir: output directory for results and LoRA checkpoints--max_length: maximum sequence length for training and generation--start_MIC_cutoff: initial MIC threshold--target_MIC_cutoff: target MIC threshold--start_TOXIN_cutoff: initial toxicity threshold--target_TOXIN_cutoff: target toxicity threshold--lora_r,--lora_alpha,--lora_dropout: LoRA hyperparameters--num_train_epochs: number of epochs per training stage--feedback_epochs: number of feedback rounds--learning_rate: learning rate
Common outputs include:
data/train.csv: latest scored training datasetcheckpoints/.../fb_epoch_0: initial LoRA fine-tuning resultcheckpoints/.../fb_epoch_k/result.csv: scored generated sequences for feedback roundkcheckpoints/.../fb_epoch_k/train.csv: replaced training dataset for feedback roundk
main.py,generate.py, andperplexity.pyhard-code GPU device IDs such ascuda:2andcuda:4. Update them if your machine uses different device indices.perplexity.pyloads./checkpoints/mul/fb_epoch_0by default. If this directory does not exist, perplexity computation will fail unless you change the path or prepare that checkpoint first.seq_dataloader.pyuses a fixedDataLoaderconfiguration withbatch_size=64andnum_workers=8. You may need to reduce these values on systems with limited CPU or GPU resources.pred_toxin.pycreates temporary files namedtemp_seq.aacandtemp_seq.dpc, then removes them automatically after prediction.paint_physicochemical_properties.pyassumes that several experiment folders already exist undercheckpoints/, such asmic,mul, andtox_no_curri. The script will not run as-is if those results are missing.
For a smoother reproduction process, verify the following before running the project:
../progen2-largeis complete and readable- the model files under
attribute_util/models/are intact toxinpred3/model/toxinpred3.0_model.pklhas been extracted and is usable- your CUDA, GPU, and PyTorch setup is compatible
- hard-coded device IDs and checkpoint paths have been adjusted for your environment
toxinpred3/README.md: toxicity prediction package notesattribute_util/: source code are from HydrAMP