annotate calc_vina_box_params.py @ 2:73c2c9774c2d draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
author bgruening
date Wed, 02 Oct 2019 12:49:11 -0400
parents 4f7c5cad3377
children 908880455b2d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
1 import numpy as np
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
2 from rdkit import Chem
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
3 from rdkit.Chem import rdShapeHelpers
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
4 import argparse
1
4f7c5cad3377 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents: 0
diff changeset
5 from random import randint
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
6
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
7
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
8 def get_params(options):
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
9 # make sure we have a mol file by initiating rdkit mol object from input
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
10 mol = Chem.MolFromMolFile(options.ligand_path)
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
11 if not mol:
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
12 raise IOError
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
13
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
14 # get rdkit conformer and compute x,y,z of top and bottom corner of confounding cuboid
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
15 conf = mol.GetConformer()
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
16 params = rdShapeHelpers.ComputeConfBox(conf)
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
17
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
18 # change tuples to arrays
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
19 coords1 = np.array(params[0])
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
20 coords2 = np.array(params[1])
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
21
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
22 # get the centre of the box
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
23 center = np.mean((coords1, coords2), axis=0)
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
24
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
25 # calculate box dimensions
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
26 dims = np.abs(coords1 - coords2)
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
27
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
28 # optionally add buffers in each direction - expansion
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
29 box_dims = [dims[0] + options.bufx, dims[1] + options.bufy, dims[2] + options.bufz]
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
30
2
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
31 optionalvals = ""
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
32
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
33
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
34 if options.seed != None:
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
35 optionalvals += "seed = " + str(options.seed) + "\n"
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
36 if options.exhaustiveness != None:
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
37 optionalvals += "exhaustiveness = " + str(options.exhaustiveness) + "\n"
1
4f7c5cad3377 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents: 0
diff changeset
38
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
39 with open(options.output, 'w') as f:
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
40 f.write(
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
41 """
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
42 size_x = {}
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
43 size_y = {}
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
44 size_z = {}
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
45 center_x = {}
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
46 center_y = {}
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
47 center_z = {}
2
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
48 {}""".format(box_dims[0], box_dims[1], box_dims[2], center[0], center[1], center[2], optionalvals)
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
49 )
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
50
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
51
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
52 if __name__ == "__main__":
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
53 parser = argparse.ArgumentParser(description="""
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
54 This tool calculates a confounding box around an input ligand (mol file), and uses it to
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
55 generate the input parameters for an autodock vina job. The output file can be fed into
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
56 the autodock vina tool as an alternative to creating the parameter file manually.
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
57
1
4f7c5cad3377 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents: 0
diff changeset
58 Optionally, you can include a 'buffer' in each of the x,y and z directions (in Å),
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
59 which will be added to the confounding box in the appropriate direction.
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
60 """)
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
61 parser.add_argument('--ligand', dest='ligand_path', help='The input ligand (mol file)')
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
62 parser.add_argument('--config', dest='output', help='The output file containing calculated params (txt)')
2
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
63 parser.add_argument('--exh', dest='exhaustiveness', type=int, help='Exhaustiveness of global search')
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
64 parser.add_argument('--bufx', dest='bufx', default=0, type=float, help='the buffer in the x direction '
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
65 '(float - in angs.)')
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
66 parser.add_argument('--bufy', dest='bufy', default=0, type=float, help='the buffer in the y direction '
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
67 '(float - in angs.)')
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
68 parser.add_argument('--bufz', dest='bufz', default=0, type=float, help='the buffer in the z direction '
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
69 '(float - in angs.)')
1
4f7c5cad3377 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents: 0
diff changeset
70 parser.add_argument('--seed', dest='seed', default=None, type=int, help='Random seed for reproducibility')
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
71
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
72 options = parser.parse_args()
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
73 get_params(options)