annotate select_points_SDF.py @ 7:7e5c2e4bc227 draft default tip

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
author bgruening
date Tue, 28 Jul 2020 08:44:40 -0400
parents 744a777e9f90
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
1 import argparse
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
2
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
3 def get_coordinates(lines):
82193638d0c5 "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]
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
5 molecule = []
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
6 if version == 'V2000':
82193638d0c5 "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())
82193638d0c5 "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):
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
9 temp = []
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
10 j = 3 + i
82193638d0c5 "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())
82193638d0c5 "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())
82193638d0c5 "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())
82193638d0c5 "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])
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
15 molecule.append(temp)
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
16 else:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
17 read = 0
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
18 for line in lines:
82193638d0c5 "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:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
20 read = 0
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
21 break
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
22 if read:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
23 temp = []
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
24 a = line.split(" ")
82193638d0c5 "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])
82193638d0c5 "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])
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
27 molecule.append(temp)
82193638d0c5 "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:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
29 read = 1
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
30 return molecule
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
31
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
32
82193638d0c5 "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):
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
34 tol = 1.5
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
35 select = []
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
36
82193638d0c5 "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:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
38 for coordinates in molecule:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
39 tv = 0
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
40 temp = []
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
41 x, y, z = coordinates
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
42 for record in select:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
43 xr, yr, zr = record
82193638d0c5 "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 \
82193638d0c5 "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 \
82193638d0c5 "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:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
47 tv = 1
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
48 break
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
49 if tv == 1:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
50 continue
82193638d0c5 "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])
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
52 select.append(temp)
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
53 return select
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
54
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
55
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
56 def sdfout(centers, writer):
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
57 n = len(centers)
6
744a777e9f90 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit dff183f4eb2d3df42917ec4fed0fbdb2ea11e19a"
bgruening
parents: 5
diff changeset
58 writer.write("Frankenstein ligand\n00000000000000000000 3D\nCreated in Galaxy\n")
5
82193638d0c5 "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)
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
60 for record in centers:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
61 x, y, z = record
82193638d0c5 "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))
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
63
82193638d0c5 "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")
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
65
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
66
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
67 def main():
82193638d0c5 "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')
82193638d0c5 "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',
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
70 help="Input file")
82193638d0c5 "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',
82193638d0c5 "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).")
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
73 args = parser.parse_args()
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
74
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
75 mol_coordinates = []
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
76 all_coordinates = []
82193638d0c5 "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:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
78 for line in file:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
79 if line.strip() == '$$$$':
82193638d0c5 "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)
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
81 all_coordinates.append(temp)
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
82 mol_coordinates.clear()
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
83 else:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
84 mol_coordinates.append(line)
82193638d0c5 "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)
82193638d0c5 "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:
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
87 sdfout(centers, writer)
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
88
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
89 if __name__ == "__main__":
82193638d0c5 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdock commit 6037a8c8d53839daad1b183e1ae0329862ac2c2c"
bgruening
parents:
diff changeset
90 main()