Uni-Fold: Training your own deep protein-folding models.

Overview

Uni-Fold: Training your own deep protein-folding models.

This package provides and implementation of a trainable, Transformer-based deep protein folding model. We modified the open-source code of DeepMind AlphaFold v2.0 and provided code to train the model from scratch. See the reference and the repository of DeepMind AlphaFold v2.0. To train your own Uni-Fold models, please follow the steps below:

1. Install the environment.

Run the following code to install the dependencies of Uni-Fold:

  conda create -n unifold python=3.8.10 -y
  conda activate unifold
  ./install_dependencies.sh

Uni-Fold has been tested for Python 3.8.10, CUDA 11.1 and OpenMPI 4.1.1. We recommend using Conda >= 4.10 when installing the environment: using Conda with lower level may lead to some conflicts between packages.

2. Prepare data before training.

Before you start to train your own folding models, you shall prepare the features and labels of the training proteins. Features of proteins mainly include the amino acid sequence, MSAs and templates of proteins. These messages should be contained in a pickle file /features.pkl for each training protein. Uni-Fold provides scripts to process input FASTA files, relying on several external databases and tools. Labels are CIF files containing the structures of the proteins.

2.1 Datasets and external tools.

Uni-Fold adopts the same data processing pipeline as AlphaFold2. We kept the scripts of downloading corresponding databases for searching sequence homologies and templates in the AlphaFold2 repo. Use the command

  bash scripts/download_all_data.sh /path/to/database/directory

to download all required databases of Uni-Fold.

If you successfully installed the Conda environment in Section 1, external tools of search homogenous sequences and templates should be installed properly. As an alternative, you can customize the parameters of feature preparation script to refer to your own databases and tools.

2.2 Run the preparation code.

An example command of running the feature preparation pipeline would be

  python generate_pkl_features.py \
    --fasta_dir ./example_data/fasta \
    --output_dir ./out \
    --data_dir /path/to/database/directory \
    --num_workers 1

This command automatically processes all FASTA files under fasta_dir, and dumps the results to output_dir. Note that each FASTA file should contain only one sequence. The default number of cpu used in hhblits and jackhmmer are 4 and 8. You can modify them in unifold/data/tools/hhblits.py and unifold/data/tools/jackhmmer.py, respectively.

2.3 Organize your training data.

Uni-Fold uses the class DataSystem to automatically sample and load the training entries. To make everything goes right, you shall pay attention to how the training data is organized. Two directories should be established, one with input features (features.pkl files, referred as features_dir) and the other with labels (*.cif files, referred as mmcif_dir). The feature directory should have its files named as _ _ /features.pkl , and the label directory should have its files named as .cif . Users shall make sure that all proteins used for training have their corresponding labels. See ./example_data/features and ./example_data/mmcif for instances of features_dir and mmcif_dir.

3. Train Uni-Fold.

3.1 Configuration.

Before you conduct any actual training processes, please make sure that you correctly configured the code. Modify the training configurations in unifold/train/train_config.py. We annotated the default configurations to reproduce AlphaFold in the script. Specifically, modify the data setups in unifold/train/train_config.py:

"data": {
  "train": {
    "features_dir": "where/training/protein/features/are/stored/",
    "mmcif_dir": "where/training/mmcif/files/are/stored/",
    "sample_weights": "which/specifies/proteins/for/training.json"
  },
  "eval": {
    "features_dir": "where/validation/protein/features/are/stored/",
    "mmcif_dir": "where/validation/mmcif/files/are/stored/",
    "sample_weights": "which/specifies/proteins/for/training.json"
  }
}

The specified data should be contained in two folders, namely a features_dir and a mmcif_dir. Organizations of the two directories are introduced in Section 2.3. Meanwhile, if you want to specify the subset of training data under the directories, or assign customized sample weights for each protein, write a json file and feed its path to sample_weights. This is optional, as you can leave it as None (and the program will attempt to use all entries under features_dir with uniform weights). The json file should be a dictionary contains the basename of directories of protein features ([pdb_id]_[model_id]_[chain_id]) and the sample weight of each protein in the training process (integer or float), such as:

{"1am9_1_C": 82, "1amp_1_A": 291, "1aoj_1_A": 60, "1aoz_1_A": 552}

or for uniform sampling, simply using a list of protein entries suffices:

["1am9_1_C", "1amp_1_A", "1aoj_1_A", "1aoz_1_A"]

Meanwhile, the configurations of models can be edited in unifold/model/config.py for users who want to customize their own folding models.

3.2 Run the training code!

To train the model on a single node without MPI, run

python train.py

You can also train the model using MPI (or workload managers that supports MPI, such as PBS or Slurm) by running:

mpirun -n <numer_of_gpus> python train.py

In either way, make sure you properly configurate the option use_mpi in unifold/train/train_config.py.

4. Inference with trained models.

4.1 Inference from features.pkl.

We provide the run_from_pkl.py script to support inferencing protein structures from features.pkl inputs. A demo command would be

python run_from_pkl.py \
  --pickle_dir ./example_data/features \
  --model_names model_2 \
  --model_paths /path/to/model_2.npz \
  --output_dir ./out

or

python run_from_pkl.py \
  --pickle_paths ./example_data/features/1ak0_1_A/features.pkl \
  --model_names model_2 \
  --model_paths /path/to/model_2.npz \
  --output_dir ./out

The command will generate structures of input features from different input models (in PDB format), the running time of each component, and corresponding residue-wise confidence score (predicted LDDT, or pLDDT).

4.2 Inference from FASTA files.

Essentially, inferencing the structures from given FASTA files includes two steps, i.e. generating the pickled features and predicting structures from them. We provided a script, run_from_fasta.py, as a more friendly user interface. An example usage would be

python run_from_pkl.py \
  --fasta_paths ./example_data/fasta/1ak0_1_A.fasta \
  --model_names model_2 \
  --model_paths /path/to/model_2.npz \
  --data_dir /path/to/database/directory
  --output_dir ./out

4.3 Generate MSA with MMseqs2.

It may take hours and much memory to generate MSA for sequences,especially for long sequences. In this condition, MMseqs2 may be a more efficient way. It can be used in the following way after it is installed:

# download and build database
mkdir mmseqs_db && cd mmseqs_db
wget http://wwwuser.gwdg.de/~compbiol/colabfold/uniref30_2103.tar.gz
wget http://wwwuser.gwdg.de/~compbiol/colabfold/colabfold_envdb_202108.tar.gz
tar xzvf uniref30_2103.tar.gz
tar xzvf colabfold_envdb_202108.tar.gz
mmseqs tsv2exprofiledb uniref30_2103 uniref30_2103_db
mmseqs tsv2exprofiledb colabfold_envdb_202108 colabfold_envdb_202108_db
mmseqs createindex uniref30_2103_db tmp
mmseqs createindex colabfold_envdb_202108_db tmp
cd ..

# MSA search
./scripts/colabfold_search.sh mmseqs "query.fasta" "mmseqs_db/" "result/" "uniref30_2103_db" "" "colabfold_envdb_202108_db" "1" "0" "1"

5. Changes from AlphaFold to Uni-Fold.

  • We implemented classes and methods for training and inference pipelines by adding scripts under unifold/train and unifold/inference.
  • We added scripts for installing the environment, training and inferencing.
  • Files under unifold/common, unifold/data and unifold/relax are minimally altered for re-structuring the repository.
  • Files under unifold/model are moderately altered to allow mixed-precision training.
  • We removed unused scripts in training AlphaFold model.

6. License and disclaimer.

6.1 Uni-Fold code license.

Copyright 2021 Beijing DP Technology Co., Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

6.2 Use of third-party software.

Use of the third-party software, libraries or code may be governed by separate terms and conditions or license provisions. Your use of the third-party software, libraries or code is subject to any such terms and you should check that you can comply with any applicable restrictions or terms and conditions before use.

6.3 Contributing to Uni-Fold.

Uni-Fold is an ongoing project. Our target is to design better protein folding models and to apply them in real scenarios. We welcome the community to join us in developing the repository together, including but not limited to 1) reports and fixes of bugs,2) new features and 3) better interfaces. Please refer to CONTRIBUTING.md for more information.

You might also like...
Unofficial TensorFlow implementation of Protein Interface Prediction using Graph Convolutional Networks.
Unofficial TensorFlow implementation of Protein Interface Prediction using Graph Convolutional Networks.

[TensorFlow] Protein Interface Prediction using Graph Convolutional Networks Unofficial TensorFlow implementation of Protein Interface Prediction usin

A denoising diffusion probabilistic model (DDPM) tailored for conditional generation of protein distograms
A denoising diffusion probabilistic model (DDPM) tailored for conditional generation of protein distograms

Denoising Diffusion Probabilistic Model for Proteins Implementation of Denoising Diffusion Probabilistic Model in Pytorch. It is a new approach to gen

7th place solution of Human Protein Atlas - Single Cell Classification on Kaggle

kaggle-hpa-2021-7th-place-solution Code for 7th place solution of Human Protein Atlas - Single Cell Classification on Kaggle. A description of the met

Implementation and replication of ProGen, Language Modeling for Protein Generation, in Jax

ProGen - (wip) Implementation and replication of ProGen, Language Modeling for Protein Generation, in Pytorch and Jax (the weights will be made easily

Graph-based community clustering approach to extract protein domains from a predicted aligned error matrix
Graph-based community clustering approach to extract protein domains from a predicted aligned error matrix

Using a predicted aligned error matrix corresponding to an AlphaFold2 model , returns a series of lists of residue indices, where each list corresponds to a set of residues clustering together into a pseudo-rigid domain.

A package to predict protein inter-residue geometries from sequence data

trRosetta This package is a part of trRosetta protein structure prediction protocol developed in: Improved protein structure prediction using predicte

A Protein-RNA Interface Predictor Based on Semantics of Sequences
A Protein-RNA Interface Predictor Based on Semantics of Sequences

PRIP PRIP:A Protein-RNA Interface Predictor Based on Semantics of Sequences installation gensim==3.8.3 matplotlib==3.1.3 xgboost==1.3.3 prettytable==2

Official implementation of
Official implementation of "Generating 3D Molecules for Target Protein Binding"

Generating 3D Molecules for Target Protein Binding This is the official implementation of the GraphBP method proposed in the following paper. Meng Liu

Implementation of a protein autoregressive language model, but with autoregressive infilling objective (editing subsequences capability)
Implementation of a protein autoregressive language model, but with autoregressive infilling objective (editing subsequences capability)

Protein GLM (wip) Implementation of a protein autoregressive language model, but with autoregressive infilling objective (editing subsequences capabil

Owner
DeepModeling
Define the future of scientific computing together
DeepModeling
Implementation of the GVP-Transformer, which was used in the paper "Learning inverse folding from millions of predicted structures" for de novo protein design alongside Alphafold2

GVP Transformer (wip) Implementation of the GVP-Transformer, which was used in the paper Learning inverse folding from millions of predicted structure

Phil Wang 19 May 6, 2022
A graph neural network (GNN) model to predict protein-protein interactions (PPI) with no sample features

A graph neural network (GNN) model to predict protein-protein interactions (PPI) with no sample features

null 2 Jul 25, 2022
Using this codebase as a tool for my own research. Making some modifications to the original repo for my own purposes.

For SwapNet Create a list.txt file containing all the images to process. This can be done with the GNU find command: find path/to/input/folder -name '

Andrew Jong 2 Nov 10, 2021
Predicting lncRNA–protein interactions based on graph autoencoders and collaborative training

Predicting lncRNA–protein interactions based on graph autoencoders and collaborative training Code for our paper "Predicting lncRNA–protein interactio

zhanglabNKU 1 Nov 29, 2022
Generative Models for Graph-Based Protein Design

Graph-Based Protein Design This repo contains code for Generative Models for Graph-Based Protein Design by John Ingraham, Vikas Garg, Regina Barzilay

John Ingraham 159 Dec 15, 2022
Codes and models for the paper "Learning Unknown from Correlations: Graph Neural Network for Inter-novel-protein Interaction Prediction".

GNN_PPI Codes and models for the paper "Learning Unknown from Correlations: Graph Neural Network for Inter-novel-protein Interaction Prediction". Lear

Ursa Zrimsek 2 Dec 14, 2022
RITA is a family of autoregressive protein models, developed by LightOn in collaboration with the OATML group at Oxford and the Debora Marks Lab at Harvard.

RITA: a Study on Scaling Up Generative Protein Sequence Models RITA is a family of autoregressive protein models, developed by a collaboration of Ligh

LightOn 69 Dec 22, 2022
A colab notebook for training Stylegan2-ada on colab, transfer learning onto your own dataset.

Stylegan2-Ada-Google-Colab-Starter-Notebook A no thrills colab notebook for training Stylegan2-ada on colab. transfer learning onto your own dataset h

Harnick Khera 66 Dec 16, 2022
A geometric deep learning pipeline for predicting protein interface contacts.

A geometric deep learning pipeline for predicting protein interface contacts.

null 44 Dec 30, 2022