-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect_tsp.py
33 lines (26 loc) · 1.27 KB
/
connect_tsp.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@author: zparteka
"""
import argparse
from modeling_scripts.modeling_operations.create_structure import load_points, save_pdb
from modeling_scripts.modeling_operations.create_structure import run_image_tsp
from scipy.spatial.distance import squareform, pdist
def main():
parser = argparse.ArgumentParser(
description="From unorganized set of points (--pdb) create a polymer like structure using greedy TSP solution.")
parser.add_argument('-p', '--pdb', help='PDB file with unorganized points', type=str, required=True)
parser.add_argument('-o', '--optimization_steps', type=int, default=10,
help="Maximum number of optimization run on TSP path. default=10")
args = parser.parse_args()
if args.pdb.endswith(".pdb"):
in_points = load_points(infile=args.pdb)
graph = squareform(pdist(in_points))
arranged_points = run_image_tsp(graph=graph, points=in_points, endpoints=None,
optimization_steps=args.optimization_steps)
save_pdb(points=arranged_points, filename=args.pdb[:-4] + "_tsp.pdb", connect=True)
else:
raise Exception("Points are required to be in .pdb format.")
if __name__ == '__main__':
main()