mirror of
https://github.com/microsoft/foldingdiff.git
synced 2026-06-04 13:30:33 +08:00
Code to calculate lddt
This commit is contained in:
32
foldingdiff/lddt.py
Normal file
32
foldingdiff/lddt.py
Normal 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
26
scripts/run_docker_ost
Executable 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
|
||||
Reference in New Issue
Block a user