From e11145f88caebb44195e13a4555faecae52a8210 Mon Sep 17 00:00:00 2001 From: Stephan Schott Verdugo Date: Mon, 23 Jun 2025 15:18:20 +0200 Subject: [PATCH] Add CBCsrv mods to 17.10.2024 ColabFold --- colabfold/batch.py | 40 +++++++++++++++++++++++++++++++++++++++- colabfold/download.py | 2 +- colabfold/plot.py | 4 +++- colabfold/utils.py | 12 ++++++------ 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/colabfold/batch.py b/colabfold/batch.py index 2c571af9e..6eb076e48 100644 --- a/colabfold/batch.py +++ b/colabfold/batch.py @@ -318,6 +318,13 @@ def get(self, x: str, ext:str) -> Path: self.files[self.tag].append([x,ext,file]) return file + def exists(self, x: str, ext:str) -> Path: + file = self.result_dir.joinpath(f"{self.prefix}_{x}_{self.tag}.{ext}") + if file.is_file(): + return True + else: + return False + def set_tag(self, tag): self.tag = tag @@ -346,6 +353,7 @@ def predict_structure( save_single_representations: bool = False, save_pair_representations: bool = False, save_recycles: bool = False, + keep_existing_results: bool = True, ): """Predicts structure using AlphaFold for the given sequence.""" mean_scores = [] @@ -419,6 +427,32 @@ def callback(result, recycles): return_representations = save_all or save_single_representations or save_pair_representations + if keep_existing_results and files.exists("unrelaxed","pdb"): + logger.info(f"{tag} was found. Loading scores and skipping!") + if files.exists("scores","json"): + with files.get("scores","json").open("r") as handle: + _scores = json.load(handle) + if is_complex: + mean_scores.append(0.8 * _scores['iptm'] + 0.2 * _scores['ptm']) + else: + mean_scores.append(np.mean(_scores['plddt'])) + print_line = "" + conf.append({}) + for x,y in [["plddt","pLDDT"],["ptm","pTM"],["iptm","ipTM"]]: + if x in _scores: + if x == "plddt": + print_line += f" {y}={np.mean(_scores[x]):.3g}" + _scores["mean_plddt"] = np.mean(_scores[x]) + x = "mean_plddt" + else: + print_line += f" {y}={_scores[x]:.3g}" + conf[-1][x] = float(_scores[x]) + conf[-1]["print_line"] = print_line + files.get("unrelaxed","pdb") + continue + else: + logger.error(f"Scores file for {tag} not found") + # predict result, recycles = \ model_runner.predict(input_features, @@ -509,6 +543,9 @@ def callback(result, recycles): rank, metric = [],[] result_files = [] + if rank_by == "skip": + logger.info(f"Skipping ranking and exiting") + exit() logger.info(f"reranking models by '{rank_by}' metric") model_rank = np.array(mean_scores).argsort()[::-1] for n, key in enumerate(model_rank): @@ -1911,7 +1948,7 @@ def main(): help='Choose metric to rank the "--num-models" predicted models.', type=str, default="auto", - choices=["auto", "plddt", "ptm", "iptm", "multimer"], + choices=["auto", "plddt", "ptm", "iptm", "multimer", "skip"], ) output_group.add_argument( "--stop-at-score", @@ -2014,6 +2051,7 @@ def main(): version += f" ({commit})" logger.info(f"Running colabfold {version}") + logger.info(f"Version modded by SSchott to use CBCSrv local MMSeqs2 and keep existing results!") data_dir = Path(args.data or default_data_dir) diff --git a/colabfold/download.py b/colabfold/download.py index e313855d8..9cb7db68b 100644 --- a/colabfold/download.py +++ b/colabfold/download.py @@ -9,7 +9,7 @@ # The data dir location logic switches between a version with and one without "params" because alphafold # always internally joins "params". (We should probably patch alphafold) -default_data_dir = Path(appdirs.user_cache_dir(__package__ or "colabfold")) +default_data_dir = Path("/apps/local/cbclab/COLABFOLD/colabfold") def download(url, params_dir, size_queue, progress_queue): try: diff --git a/colabfold/plot.py b/colabfold/plot.py index 0fd23b07b..04276701b 100644 --- a/colabfold/plot.py +++ b/colabfold/plot.py @@ -1,7 +1,9 @@ from pathlib import Path import numpy as np -from matplotlib import pyplot as plt +import matplotlib +matplotlib.use('Agg') +import matplotlib.pyplot as plt def plot_predicted_alignment_error( diff --git a/colabfold/utils.py b/colabfold/utils.py index 20fe35fab..088101128 100644 --- a/colabfold/utils.py +++ b/colabfold/utils.py @@ -17,15 +17,15 @@ If you're sure you want to run without a GPU, pass `--cpu`""" -DEFAULT_API_SERVER = "https://api.colabfold.com" +DEFAULT_API_SERVER = "http://192.168.62.51:9091" ACCEPT_DEFAULT_TERMS = \ """ -WARNING: You are welcome to use the default MSA server, however keep in mind that it's a -limited shared resource only capable of processing a few thousand MSAs per day. Please -submit jobs only from a single IP address. We reserve the right to limit access to the -server case-by-case when usage exceeds fair use. If you require more MSAs: You can -precompute all MSAs with `colabfold_search` or host your own API and pass it to `--host-url` +WARNING: You are using the internal CBCSRV MMseqs2 server, with a local ColabFold 1.5.5 installation. +This server was last updated 22.10.2024. The databases or the ColabFold installation might be too old +at the time of use. Please be aware, and consider getting a newer version by youself if that is the case! +You can use the internal MMseqs2 server API by using http://192.168.62.51:9091 as the host url in the +colabfold_batch script. If the server does not respond, ask around! """ class TqdmHandler(logging.StreamHandler):