comparison select_points_SDF.py @ 7:309fd04bcfd2 draft

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