annotate select_points_SDF.py @ 1:8e214e52e461 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit dff183f4eb2d3df42917ec4fed0fbdb2ea11e19a"
author bgruening
date Thu, 21 May 2020 10:55:41 -0400
parents 7a4306d69801
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
1 import argparse
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
2
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
3 def get_coordinates(lines):
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
4 version = lines[3][34:39]
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
5 molecule = []
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
6 if version == 'V2000':
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
7 natom = int(lines[3][:3].strip())
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
8 for i in range(1, natom + 1):
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
9 temp = []
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
10 j = 3 + i
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
11 x = float(lines[j][:10].strip())
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
12 y = float(lines[j][11:20].strip())
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
13 z = float(lines[j][21:30].strip())
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
14 temp.extend([x, y, z])
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
15 molecule.append(temp)
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
16 else:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
17 read = 0
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
18 for line in lines:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
19 if "END ATOM" in line:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
20 read = 0
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
21 break
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
22 if read:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
23 temp = []
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
24 a = line.split(" ")
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
25 x, y, z = float(a[5]), float(a[6]), float(a[7])
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
26 temp.extend([x, y, z])
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
27 molecule.append(temp)
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
28 if "BEGIN ATOM" in line:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
29 read = 1
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
30 return molecule
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
31
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
32
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
33 def select_points(all_coordinates):
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
34 tol = 1.5
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
35 select = []
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
36
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
37 for molecule in all_coordinates:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
38 for coordinates in molecule:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
39 tv = 0
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
40 temp = []
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
41 x, y, z = coordinates
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
42 for record in select:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
43 xr, yr, zr = record
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
44 if xr-tol < x and x < xr+tol and \
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
45 yr-tol < y and y < yr+tol and \
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
46 zr-tol < z and z < zr+tol:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
47 tv = 1
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
48 break
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
49 if tv == 1:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
50 continue
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
51 temp.extend([x, y, z])
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
52 select.append(temp)
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
53 return select
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
54
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
55
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
56 def sdfout(centers, writer):
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
57 n = len(centers)
1
8e214e52e461 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit dff183f4eb2d3df42917ec4fed0fbdb2ea11e19a"
bgruening
parents: 0
diff changeset
58 writer.write("Frankenstein ligand\n00000000000000000000 3D\nCreated in Galaxy\n")
0
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
59 writer.write("%3d 0 0 0 0 0 0 0 0 0999 V2000\n" % n)
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
60 for record in centers:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
61 x, y, z = record
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
62 writer.write("%10.4f%10.4f%10.4f C 0 0 0 0 0 0 0 0 0 0 0 0\n" % (x, y, z))
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
63
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
64 writer.write("M END\n$$$$\n")
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
65
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
66
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
67 def main():
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
68 parser = argparse.ArgumentParser(description='RDKit screen')
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
69 parser.add_argument('-i', '--input',
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
70 help="Input file")
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
71 parser.add_argument('-o', '--output',
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
72 help="Base name for output file (no extension).")
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
73 args = parser.parse_args()
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
74
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
75 mol_coordinates = []
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
76 all_coordinates = []
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
77 with open(args.input) as file:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
78 for line in file:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
79 if line.strip() == '$$$$':
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
80 temp = get_coordinates(mol_coordinates)
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
81 all_coordinates.append(temp)
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
82 mol_coordinates.clear()
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
83 else:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
84 mol_coordinates.append(line)
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
85 centers = select_points(all_coordinates)
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
86 with open(args.output, 'w+') as writer:
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
87 sdfout(centers, writer)
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
88
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
89 if __name__ == "__main__":
7a4306d69801 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
90 main()