RoseTTAFold2NA (RF2NA)
repository·main·Indexed 18 days ago
https://github.com/uw-ipd/rosettafold2naA deep learning framework for predicting the structures of complexes involving proteins and nucleic acids (RNA and DNA). The repository includes the RF2NA prediction pipeline, instructions for downloading required sequence and structure databases (UniRef30, BFD, Rfam, etc.), and an implementation of the SE(3)-Transformer, an equivariant Graph Neural Network built with PyTorch and DGL for processing 3D points and graphs.
What's inside RoseTTAFold2NA
- This repository provides scripts and recipes for training the SE(3)-Transformer model to achieve state-of-the-art accuracy. The content is maintained and tested by NVIDIA. It includes details on model architecture, default configurations, feature support (including mixed precision training), and performance benchmarking for both training and inference on NVIDIA hardware (e.g., DGX A100, DGX-1).
What is the SE(3)-Transformer model?
mainThe SE(3)-Transformer is a Graph Neural Network (GNN) that uses a variant of self-attention for processing 3D points and graphs. It is equivariant under continuous 3D roto-translations (SE(3)), meaning that if the input graphs or point sets rotate or undergo proper rigid transformations, the model outputs either remain invariant or transform predictably with the input.
Key characteristics include:
- Architecture: Consists of stacked layers of equivariant graph self-attention and equivariant normalization, followed by a Tensor Field Network (TFN) convolution to obtain invariant features. It typically functions as a graph-to-scalar network using graph pooling (mean or max).
- Implementation: Built using PyTorch and the Deep Graph Library (DGL), utilizing the
e3nnlibrary for computing spherical harmonics and Clebsch–Gordan coefficients. - Capabilities: Supports edge features of any degree (1D, 3D, 5D, etc.) and is optimized for high throughput and low memory consumption.
How to enable TF32 on NVIDIA Ampere GPUs
mainTensorFloat-32 (TF32) is a math mode for NVIDIA A100 GPUs that provides up to 10x speedups for matrix operations compared to single-precision (FP32) on older architectures. It is more robust than FP16 for models requiring high dynamic range.
TF32 is enabled by default in the NVIDIA Ampere GPU architecture within this implementation.
Understand SE(3)-Transformer feature terminology
mainWhen working with the model, the following terms define the data structures and mathematical properties:
- Degree (type): A positive integer describing how a feature transforms under 3D rotation. A feature of degree $d$ has a dimensionality of $2d+1$.
- Degree 0: 1D scalars (rotation invariant).
- Degree 1: 3D vectors (rotate via 3D rotation matrices).
- Degree 2: 5D vectors (rotate via Wigner-D matrices).
- Fiber: A representation of a set of features of different degrees. In this repository, a fiber is represented as a
dictwhere keys are degrees and values are the number of channels. - Multiplicity: The number of channels associated with a feature of a specific type.
- Equivariance: A property where applying a symmetry transformation to the input and then the function produces the same result as applying the function and then the transformation.
- Degree (type): A positive integer describing how a feature transforms under 3D rotation. A feature of degree $d$ has a dimensionality of $2d+1$.
Install RoseTTAFold2NA
mainTo install RoseTTAFold2NA, follow these steps to clone the repository, set up the Conda environment, install the SE(3)-Transformer dependency, and download the pre-trained weights.
1. Clone the repository
git clone https://github.com/uw-ipd/RoseTTAFold2NA.git cd RoseTTAFold2NA2. Create Conda environment
Use the provided
RF2na-linux.ymlto create the environment:conda env create -f RF2na-linux.yml3. Install SE(3)-Transformer
You must install NVIDIA's SE(3)-Transformer using the version provided within this repository:
conda activate RF2NA cd SE3Transformer pip install --no-cache-dir -r requirements.txt python setup.py install cd ..4. Download pre-trained weights
Download the weights into the
networkdirectory:cd network wget https://files.ipd.uw.edu/dimaio/RF2NA_apr23.tgz tar xvfz RF2NA_apr23.tgz ls weights/ # Verify the 1.1GB weights file is present cd ..git clone https://github.com/uw-ipd/RoseTTAFold2NA.git cd RoseTTAFold2NA conda env create -f RF2na-linux.yml conda activate RF2NA cd SE3Transformer pip install --no-cache-dir -r requirements.txt python setup.py install cd .. cd network wget https://files.ipd.uw.edu/dimaio/RF2NA_apr23.tgz tar xvfz RF2NA_apr23.tgz cd ..Quick Start Guide for SE(3)-Transformer
mainFollow these steps to clone the repository, build the Docker container, and run training and inference using default parameters on the QM9 dataset.
- Clone the repository
- Build the Docker container
- Start an interactive session (mounts a
resultsdirectory for output) - Run training via
scripts/train.sh - Run inference via
scripts/predict.sh
# 1. Clone git clone https://github.com/NVIDIA/DeepLearningExamples cd DeepLearningExamples/PyTorch/DrugDiscovery/SE3Transformer # 2. Build docker build -t se3-transformer . # 3. Run container mkdir -p results docker run -it --runtime=nvidia --shm-size=8g --ulimit memlock=-1 --ulimit stack=67108864 --rm -v ${PWD}/results:/results se3-transformer:latest # 4. Train bash scripts/train.sh # 5. Predict bash scripts/predict.shDownload sequence and structure databases
mainRoseTTAFold2NA requires several large databases for sequence and structure information. Follow these commands to download and prepare them:
UniRef30 [46G]
wget http://wwwuser.gwdg.de/~compbiol/uniclust/2020_06/UniRef30_2020_06_hhsuite.tar.gz mkdir -p UniRef30_2020_06 tar xfz UniRef30_2020_06_hhsuite.tar.gz -C ./UniRef30_2020_06BFD [272G]
wget https://bfd.mmseqs.com/bfd_metaclust_clu_complete_id30_c90_final_seq.sorted_opt.tar.gz mkdir -p bfd tar xfz bfd_metaclust_clu_complete_id30_c90_final_seq.sorted_opt.tar.gz -C ./bfdStructure Templates
wget https://files.ipd.uw.edu/pub/RoseTTAFold/pdb100_2021Mar03.tar.gz tar xfz pdb100_2021Mar03.tar.gzRNA Databases
Rfam [300M]
mkdir -p RNA cd RNA wget ftp://ftp.ebi.ac.uk/pub/databases/Rfam/CURRENT/Rfam.full_region.gz wget ftp://ftp.ebi.ac.uk/pub/databases/Rfam/CURRENT/Rfam.cm.gz gunzip Rfam.cm.gz cmpress Rfam.cmRNAcentral [12G]
# Inside RNA directory wget ftp://ftp.ebi.ac.uk/pub/databases/RNAcentral/current_release/rfam/rfam_annotations.tsv.gz wget ftp://ftp.ebi.ac.uk/pub/databases/RNAcentral/current_release/id_mapping/id_mapping.tsv.gz wget ftp://ftp.ebi.ac.uk/pub/databases/RNAcentral/current_release/sequences/rnacentral_species_specific_ids.fasta.gz ../input_prep/reprocess_rnac.pl id_mapping.tsv.gz rfam_annotations.tsv.gz gunzip -c rnacentral_species_specific_ids.fasta.gz | makeblastdb -in - -dbtype nucl -parse_seqids -out rnacentral.fasta -title "RNACentral"nt [151G]
update_blastdb.pl --decompress nt# Example for UniRef30 wget http://wwwuser.gwdg.de/~compbiol/uniclust/2020_06/UniRef30_2020_06_hhsuite.tar.gz mkdir -p UniRef30_2020_06 tar xfz UniRef30_2020_06_hhsuite.tar.gz -C ./UniRef30_2020_06Extend SE(3)-Transformer with custom datasets
mainTo use the network on a new dataset, extend the
DataModuleclass inse3_transformer/data_loading/data_module.py.Your custom collate function must return a tuple containing:
- A (batched)
DGLGraphobject - A dictionary of node features (
{'{degree}': tensor}) - A dictionary of edge features (
{'{degree}': tensor}) - (Optional) Precomputed bases as a dictionary
- Labels as a tensor
After implementing the data module, you must modify
training.pyandinference.pyto utilize your new class.- A (batched)
Setup SE(3)-Transformer environment
mainTo run SE(3)-Transformer, you need an environment with NVIDIA Docker and a PyTorch 21.07+ NGC container. The model is optimized for NVIDIA GPUs with Volta, Turing, or Ampere architectures.
Requirements
- NVIDIA Docker
- PyTorch 21.07+ NGC container
- Supported GPUs: NVIDIA Volta, Turing, or Ampere architectures.
How to enable Mixed Precision (AMP) training
mainThis implementation supports Automatic Mixed Precision (AMP) using PyTorch's native package. AMP allows for FP16 training with FP32 master weights, providing significant speedups on NVIDIA Volta, Turing, and Ampere GPU architectures by leveraging Tensor Cores.
To enable mixed precision during training or inference, use the
--ampflag in your execution command.# Example usage (flag name provided in documentation) python train_script.py --ampTroubleshoot memory allocation errors in Dataloader
mainIf you encounter the error
OSError: [Errno 12] Cannot allocate memoryduring Dataloader iterator creation (specifically duringfork()), it is likely caused by the--precompute_basesflag.To resolve this without increasing RAM or Swap, disable bases precomputation by using one of the following methods:
- Remove the
--precompute_basesflag from your command. - Set the flag to false:
--precompute_bases false.
# Example fix: disable precompute_bases python train.py --precompute_bases false ...- Remove the
Run training with Multi-GPU/Multi-node support
mainThe training script supports the PyTorch elastic launcher. To train on all available GPUs with Automatic Mixed Precision (AMP) enabled, use
torch.distributed.runto launch these3_transformer.runtime.trainingmodule.python -m torch.distributed.run --nnodes=1 --nproc_per_node=gpu --module se3_transformer.runtime.training --amp