forked from dyelar/grid-and-dock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-receptor-list
executable file
·59 lines (49 loc) · 1.86 KB
/
make-receptor-list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
#
# Copyright 2023 - University of Kansas - All rights reserved.
# Written by Matthew Copeland ([email protected])
#
# This file is licensed under the GNU Affero General Public License v3.0.
#
import sys
from pathlib import Path
import csv
def usage():
command = "make-receptor-list"
arguments = "directory-containing-receptor-and-grid-files receptor-list.txt"
print("Usage: ", command, arguments, "\n")
sys.exit(1)
def main():
argc = len(sys.argv)
if argc != 3 and "--help" not in sys.argv and "-h" not in sys.argv:
usage()
directory = sys.argv[1]
dir_path = Path(directory)
output_file = sys.argv[2]
receptors = []
grids_for_receptors = {}
if dir_path.exists() and dir_path.is_dir():
files = [x for x in dir_path.iterdir() if x.is_file() and not x.is_dir()]
for file in files:
if str(file.absolute()).endswith(".pdbqt"):
if file not in receptors:
receptors.append(file)
elif str(file).endswith(".gpf"):
receptor = str(file.absolute()).replace(".gpf", ".pdbqt")
receptors.append(receptor)
grids_for_receptors[receptor] = file.absolute()
else:
print("Unidentified file: ", str(file))
with open(output_file, "w") as output:
fieldnames = ["receptor-file", "reference-grid-parameter-file"]
writer = csv.DictWriter(output, delimiter=',', dialect='unix',
fieldnames=fieldnames)
writer.writeheader()
for receptor in grids_for_receptors:
entry = {"receptor-file": receptor,
"reference-grid-parameter-file": grids_for_receptors[receptor]}
writer.writerow(entry)
else:
usage()
if __name__ == '__main__':
main()