annotate calc_vina_box_params.py @ 4:ad35eaa204ea draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
author bgruening
date Tue, 28 Jul 2020 08:16:17 -0400
parents 908880455b2d
children 668c60aa4799
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
3
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
7 def get_mol_from_file(fname, ftype):
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
8 if ftype in ['mol', 'sdf']:
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
9 mol = Chem.MolFromMolFile(options.ligand_path)
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
10 elif ftype == 'pdb':
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
11 mol = Chem.MolFromPDBFile(options.ligand_path)
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
12 elif ftype == 'mol2':
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
13 mol = Chem.MolFromMol2File(options.ligand_path)
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
14 else:
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
15 raise IOError
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
16 if not mol:
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
17 raise IOError
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
18 return mol
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
19
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
20 def get_params(options):
3
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
21 mol = get_mol_from_file(options.ligand_path, options.ftype)
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
22
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
23 # 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
24 conf = mol.GetConformer()
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
25 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
26
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
27 # 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
28 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
29 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
30
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
31 # 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
32 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
33
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
34 # calculate box dimensions
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
35 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
36
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
37 # 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
38 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
39
2
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
40 optionalvals = ""
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
41
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
42
73c2c9774c2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents: 1
diff changeset
43 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
44 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
45 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
46 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
47
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
48 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
49 f.write(
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 size_x = {}
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
52 size_y = {}
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
53 size_z = {}
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
54 center_x = {}
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
55 center_y = {}
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
56 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
57 {}""".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
58 )
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
59
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 if __name__ == "__main__":
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
62 parser = argparse.ArgumentParser(description="""
3
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
63 This tool calculates a confounding box around an input ligand, and uses it to
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
64 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
65 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
66
1
4f7c5cad3377 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents: 0
diff changeset
67 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
68 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
69 """)
3
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
70 parser.add_argument('--ligand', dest='ligand_path', help='The input ligand filepath.')
908880455b2d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit deb7ad38cefd13df312431b1138054a68381efdf"
bgruening
parents: 2
diff changeset
71 parser.add_argument('--ftype', dest='ftype', help='Filetype of the input ligand (mol, sdf, pdb, mol2)')
0
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
72 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
73 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
74 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
75 '(float - in angs.)')
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
76 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
77 '(float - in angs.)')
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
78 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
79 '(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
80 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
81
761762031eee planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a657ca32e9a470d710e483e9c3c2706726bec9a3
bgruening
parents:
diff changeset
82 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
83 get_params(options)