CAMP-RL is a deep learning project for antimicrobial peptide (AMP) sequence generation and optimization. The main model is a conditional Transformer-VAE that learns latent representations of peptide sequences, then applies reinforcement learning with AMP/MIC classifier rewards to bias generated sequences toward desired antimicrobial and MIC-related properties.
- Train a Transformer-VAE on amino acid sequences.
- Use
amp_labelandmic_labelas conditional controls during reconstruction and generation. - Use pretrained AMP/MIC classifiers as reward models during RL fine-tuning.
- Evaluate reconstruction quality with token accuracy and average Levenshtein distance.
- Generate candidate antimicrobial peptide sequences from random latent vectors.
CAMP-RL/
├── main.py # Main entry: VAE pretraining + RL fine-tuning + evaluation
├── model.py # Transformer-VAE, VAE loss, RL loss
├── data_loader.py # CSV dataset loading and peptide tokenization
├── evaluate_vae.py # Reconstruction evaluation and sequence generation
├── utils.py # Batch utilities, loss plotting, helper functions
├── discriminator.py # Discriminator-related model code
├── data/
│ ├── train_dataset.csv # Training set
│ ├── test_dataset.csv # Test set
│ ├── val_dataset.csv # Validation set
│ └── mic_data.csv # MIC classifier training data
├── classifier_utils/
│ ├── classifiers.py # AMP/MIC classifier model and training script
│ ├── AMP_Classifier.pt # AMP classifier weights
│ └── MIC_Classifier.pt # MIC classifier weights
├── attribute_util/ # Post-generation attribute evaluation utilities
├── checkpoints/ # Training logs and model checkpoints
├── cd-hit/ # Sequence clustering/deduplication utilities
└── plddt/ # pLDDT results and visualization files
Python 3.8/3.9 with a CUDA-enabled PyTorch environment is recommended for training. Core dependencies:
pip install torch pandas numpy matplotlib scikit-learn python-LevenshteinIf you need to run the post-generation attribute evaluation tools under attribute_util/, you may also need:
pip install tensorflow keras keras-preprocessing tensorflow-probability biopython modlamp seaborn tqdm joblibNote: some code under attribute_util/ imports modules using amp as the package name. Run those scripts from the attribute_util/ directory, or add that directory to PYTHONPATH.
data_loader.py expects the training/test CSV files to contain at least the following columns:
| Column | Description |
|---|---|
sequence |
Amino acid sequence. Supported alphabet: ACDEFGHIKLMNPQRSTVWY |
amp_label |
AMP activity label. Usually 1 for positive samples and 0 for negative samples |
mic_label |
MIC-related binary label. Usually 1 if the MIC threshold condition is satisfied, otherwise 0 |
Example:
sequence,amp_label,mic_label
VTSWSLCTPGCTSPGGGSNCSFCC,1,0
MQIFVKTLTGKTITLEVEA,0,0Enter the project directory:
cd ./CAMP-RLRun the full training pipeline:
python main.pymain.py performs the following steps:
- Load
./data/train_dataset.csvand./data/test_dataset.csv. - Train the conditional Transformer-VAE.
- Save pretrained weights to
./checkpoints/<timestamp>/Pretrain_VAE.pt. - Evaluate reconstruction on the test set.
- Fine-tune the model with AMP/MIC classifier rewards.
- Save RL-fine-tuned weights to
./checkpoints/<timestamp>/RL_VAE.pt.
Training logs are written to:
checkpoints/<timestamp>/training.log
If your machine uses a different GPU index, or if you want to run on CPU or another GPU, update this line before training.
Transformer_VAE in model.py contains:
- token embedding and sinusoidal positional encoding;
- a Transformer encoder for input sequence encoding;
- latent mean/log variance layers for sampling latent vector
z; - conditional control by concatenating
z,amp_label, andmic_label; - a Transformer decoder for autoregressive reconstruction/generation.
evaluate_vae.py provides a generate function that samples candidate sequences from random latent vectors and scores them with AMP/MIC models from attribute_util.
The script currently calls:
generate("generated", "./checkpoints/RL_VAE.pt")However, main.py saves checkpoints under a timestamped directory:
./checkpoints/<timestamp>/RL_VAE.pt
Before running generation separately, update the path to the actual trained checkpoint, or copy the checkpoint to ./checkpoints/RL_VAE.pt.
Generated sequences are appended to:
CAMP_RL_positive.csv
classifier_utils/classifiers.py can train the AMP and MIC classifiers:
cd classifier_utils
python classifiers.pyThis script:
- trains the AMP classifier from
Classifier_train.csv; - builds MIC classifier data from
../data/mic_data.csvplus AMP negative samples; - saves
AMP_Classifier.ptandMIC_Classifier.pt.
The main training pipeline depends on these two weight files. If they are missing, main.py will fail when loading the classifiers.
- Run
main.pyfrom theCAMP-RL/directory because many paths are relative. - The current code does not use command-line arguments. Data paths, epochs, and model hyperparameters are edited directly in source files.
- Each
main.pyrun creates a newcheckpoints/<timestamp>/directory. - The default checkpoint path in
evaluate_vae.pydoes not exactly match the timestamped path used bymain.py; adjust it manually when running generation or standalone evaluation. plt.show()may block or fail on headless servers. If this happens, set the matplotlib backend toAggat the beginning of the script.- The repository contains
__pycache__, training logs, model weights, and notebook outputs. Clean them as needed before packaging or releasing the project.