Code to calculate lddt

This commit is contained in:
Kevin Wu
2023-06-07 15:03:07 -07:00
parent e2d1a86cfd
commit 44e7b9f3b8
2 changed files with 58 additions and 0 deletions

32
foldingdiff/lddt.py Normal file
View File

@@ -0,0 +1,32 @@
"""
Code for computing lDDT scores.
"""
import os, sys
from pathlib import Path
import subprocess
import tempfile
import json
IMAGE = "2d07309e7a56" # Docker image from https://git.scicore.unibas.ch/schwede/openstructure/container_registry/
DOCKER_OST = Path(os.path.realpath(__file__)).parent.parent / "scripts/run_docker_ost"
assert DOCKER_OST.exists(), f"Cannot find docker wrapper script {DOCKER_OST}"
def lddt(query: Path, ref: Path) -> float:
"""Compute the lDDT between query and reference structures."""
with tempfile.NamedTemporaryFile(dir=os.getcwd()) as outfile:
cmd = f"{DOCKER_OST} {IMAGE} compare-structures -m {query} -r {ref} --lddt -o {os.path.basename(outfile.name)}"
subprocess.call(cmd, shell=True)
# outfile.seek(0)
data = json.loads(outfile.read().decode("utf-8"))
if "lddt" in data:
return data["lddt"]
return -1.0
if __name__ == "__main__":
print(lddt(Path(sys.argv[1]), Path(sys.argv[2])))

26
scripts/run_docker_ost Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
# end when error
set -e
image_name=$1
script_path=$2
if [[ ${#@} -lt 1 ]]; then
echo "Usage: run_docker_ost <IMAGE_NAME> [<SCRIPT_PATH>]"
exit 1
fi
if [[ -z ${script_path} ]]; then
docker run -ti --rm -v $(pwd):/home ${image_name}
else
if [[ -e $script_path ]]; then
abspath=$(readlink -f $script_path)
dirpath=$(dirname $abspath)
name=$(basename $script_path)
docker run --rm -v ${dirpath}:/home ${image_name} /home/${name} ${@:3}
else
# it is maybe an action if it does not exist
docker run --rm -v $(pwd):/home ${image_name} ${script_path} ${@:3}
fi
fi