Home

Awesome

Progres - Protein Graph Embedding Search

Build status

This repository contains the method from the pre-print:

It provides the progres Python package that lets you search structures against pre-embedded structural databases, score pairs of structures and pre-embed datasets for searching against. Searching typically takes 1-2 s and is much faster for multiple queries. For the AlphaFold database, initial data loading takes around a minute but subsequent searching takes a tenth of a second per query.

Currently SCOPe, CATH, ECOD, the whole PDB, the AlphaFold structures for 21 model organisms and the AlphaFold database TED domains are provided for searching against. Searching is done by domain but Chainsaw can be used to automatically split query structures into domains.

Installation

  1. Python 3.8 or later is required. The software is OS-independent.
  2. Install PyTorch 1.11 or later, PyTorch Scatter, PyTorch Geometric, FAISS and STRIDE as appropriate for your system. A GPU is not required but may provide speedup in certain situations. Example commands for Linux (and other operating systems, bar the STRIDE install):
conda create -n prog python=3.9
conda activate prog
conda install pytorch=1.11 faiss-cpu -c pytorch
conda install pytorch-scatter pyg -c pyg
conda install kimlab::stride
  1. Run pip install progres, which will also install Biopython, mmtf-python, einops and pydantic if they are not already present.
  2. The first time you search with the software the trained model and pre-embedded databases (~660 MB) will be downloaded to the package directory from Zenodo, which requires an internet connection. This can take a few minutes. You can set the environmental variable PROGRES_DATA_DIR to change where this data is stored, for example if you cannot write to the package directory. Remember to keep it set the next time you run Progres.
  3. The first time you search against the AlphaFold database TED domains the pre-embedded database (~33 GB) will be downloaded similarly. This can take a while. Make sure you have enough disk space!

Alternatively, a Docker file is available in the docker directory.

Usage

On Unix systems the executable progres will be added to the path during installation. On Windows you can call the bin/progres script with python if you can't access the executable.

Run progres -h to see the help text and progres {mode} -h to see the help text for each mode. The modes are described below but there are other options outlined in the help text. For example the -d flag sets the device to run on; this is cpu by default since this is often fastest for searching, but cuda will likely be faster when splitting domains with Chainsaw, searching many queries or embedding a dataset. Try both if performance is important.

Search a structure against a database

To search a PDB file query.pdb (which can be found in the data directory) against domains in the SCOPe database and print output:

progres search -q query.pdb -t scope95
# QUERY_NUM: 1
# QUERY: query.pdb
# DOMAIN_NUM: 1
# DOMAIN_SIZE: 150 residues (1-150)
# DATABASE: scope95
# PARAMETERS: minsimilarity 0.8, maxhits 100, chainsaw no, faiss no, progres v0.2.7
# HIT_N  DOMAIN   HIT_NRES  SIMILARITY  NOTES
      1  d1a6ja_       150      1.0000  d.112.1.1 - Nitrogen regulatory bacterial protein IIa-ntr {Escherichia coli [TaxId: 562]}
      2  d2a0ja_       146      0.9988  d.112.1.0 - automated matches {Neisseria meningitidis [TaxId: 122586]}
      3  d3urra1       151      0.9983  d.112.1.0 - automated matches {Burkholderia thailandensis [TaxId: 271848]}
      4  d3lf6a_       154      0.9971  d.112.1.1 - automated matches {Artificial gene [TaxId: 32630]}
      5  d3oxpa1       147      0.9968  d.112.1.0 - automated matches {Yersinia pestis [TaxId: 214092]}
...

Other tools for splitting query structures into domains include Merizo and SWORD2. You can also slice out domains manually using software such as the pdb_selres command from pdb-tools.

Interpreting the hit descriptions depends on the database being searched. The domain name often includes a reference to the corresponding PDB file, for example d1a6ja_ refers to PDB ID 1A6J chain A, and this can be opened in the RCSB PDB structure view to get a quick look. For the AlphaFold database TED domains, files can be downloaded from links such as this where AF-A0A6J8EXE6-F1 is the first part of the hit notes and is followed by the residue range of the domain.

Available databases

The available pre-embedded databases are:

NameDescriptionNumber of domainsSearch time (1 query)Search time (100 queries)
scope95ASTRAL set of SCOPe 2.08 domains clustered at 95% seq ID35,3711.35 s2.81 s
scope40ASTRAL set of SCOPe 2.08 domains clustered at 40% seq ID15,1271.32 s2.36 s
cath40S40 non-redundant domains from CATH 23/11/2231,8841.38 s2.79 s
ecod70F70 representative domains from ECOD develop28771,6351.46 s3.82 s
pdb100All PDB protein chains as of 02/08/24 split into domains with Chainsaw1,177,1522.90 s27.3 s
af21orgAlphaFold structures for 21 model organisms split into domains by CATH-Assign338,2582.21 s11.0 s
aftedAlphaFold database structures split into domains by TED and clustered at 50% sequence identity53,344,20967.7 s73.1 s

Search time is for a 150 residue protein (d1a6ja_ in PDB format) on an Intel i9-10980XE CPU with 256 GB RAM and PyTorch 1.11. Times are given for 1 or 100 queries. Note that afted uses exhaustive FAISS searching. This doesn't change the hits that are found, but the similarity score will differ by a small amount - see the paper.

Calculate the score between two structures

To calculate the Progres score between two protein domains:

progres score struc_1.pdb struc_2.pdb
0.7265280485153198

The order of the domains does not affect the score. A score of 0.8 or higher indicates the same fold.

Pre-embed a dataset to search against

To embed a dataset of structures, allowing it to be searched against:

progres embed -l filepaths.txt -o searchdb.pt

Again, the structures should correspond to single protein domains. The embeddings are stored as Float16, which has no noticeable effect on search performance.

As an example, you can run the above command from the data directory to generate a database with two structures.

Python library

progres can also be used in Python, allowing it to be integrated into other methods:

import progres as pg

# Search as above, returns a list where each entry is a dictionary for a query
# A generator is also available as pg.progres_search_generator
results = pg.progres_search(querystructure="query.pdb", targetdb="scope95")
results[0].keys() # dict_keys(['query_num', 'query', 'query_size', 'database', 'minsimilarity',
                  #            'maxhits', 'domains', 'hits_nres', 'similarities', 'notes'])

# Score as above, returns a float (similarity score 0 to 1)
pg.progres_score("struc_1.pdb", "struc_2.pdb")

# Pre-embed as above, saves a dictionary
pg.progres_embed(structurelist="filepaths.txt", outputfile="searchdb.pt")
import torch
torch.load("searchdb.pt").keys() # dict_keys(['ids', 'embeddings', 'nres', 'notes'])

# Read a structure file into a PyTorch Geometric graph
graph = pg.read_graph("query.pdb")
graph # Data(x=[150, 67], edge_index=[2, 2758], coords=[150, 3])

# Embed a single structure
embedding = pg.embed_structure("query.pdb")
embedding.shape # torch.Size([128])

# Load and reuse the model for speed
model = pg.load_trained_model()
embedding = pg.embed_structure("query.pdb", model=model)

# Embed Cα coordinates and search with the embedding
# This is useful for using progres in existing pipelines that give out Cα coordinates
# queryembeddings should have shape (128) or (n, 128)
#   and should be normalised across the 128 dimension
coords = pg.read_coords("query.pdb")
embedding = pg.embed_coords(coords) # Can take a list of coords or a tensor of shape (nres, 3)
results = pg.progres_search(queryembeddings=embedding, targetdb="scope95")

# Get the similarity score (0 to 1) between two embeddings
# The distance (1 - similarity) is also available as pg.embedding_distance
score = pg.embedding_similarity(embedding, embedding)
score # tensor(1.) in this case since they are the same embedding

# Get all-v-all similarity scores between 1000 embeddings
embs = torch.nn.functional.normalize(torch.randn(1000, 128), dim=1)
scores = pg.embedding_similarity(embs.unsqueeze(0), embs.unsqueeze(1))
scores.shape # torch.Size([1000, 1000])

Scripts

Datasets and scripts for benchmarking (including for other methods), FAISS index generation and training are in the scripts directory. The trained model and pre-embedded databases are available on Zenodo.

Notes

The implementation of the E(n)-equivariant GNN uses EGNN PyTorch. We also include code from SupContrast and Chainsaw.

Please open issues or get in touch with any feedback. Contributions via pull requests are welcome.