comparison calc_vina_box_params.py @ 5:668c60aa4799 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit 26e9f1627e91a4be6bdc7e71cd44f1ea1701ee6f"
author bgruening
date Thu, 22 Jul 2021 14:04:57 +0000
parents 908880455b2d
children
comparison
equal deleted inserted replaced
4:ad35eaa204ea 5:668c60aa4799
1 import argparse
2
1 import numpy as np 3 import numpy as np
2 from rdkit import Chem 4 from rdkit import Chem
3 from rdkit.Chem import rdShapeHelpers 5 from rdkit.Chem import rdShapeHelpers
4 import argparse 6
5 from random import randint
6 7
7 def get_mol_from_file(fname, ftype): 8 def get_mol_from_file(fname, ftype):
8 if ftype in ['mol', 'sdf']: 9 if ftype in ["mol", "sdf"]:
9 mol = Chem.MolFromMolFile(options.ligand_path) 10 mol = Chem.MolFromMolFile(options.ligand_path, strictParsing=False, sanitize=False)
10 elif ftype == 'pdb': 11 elif ftype == "pdb":
11 mol = Chem.MolFromPDBFile(options.ligand_path) 12 mol = Chem.MolFromPDBFile(options.ligand_path, sanitize=False)
12 elif ftype == 'mol2': 13 elif ftype == "mol2":
13 mol = Chem.MolFromMol2File(options.ligand_path) 14 mol = Chem.MolFromMol2File(options.ligand_path, sanitize=False)
14 else: 15 else:
15 raise IOError 16 raise IOError
16 if not mol: 17 if not mol:
17 raise IOError 18 raise IOError
18 return mol 19 return mol
20
19 21
20 def get_params(options): 22 def get_params(options):
21 mol = get_mol_from_file(options.ligand_path, options.ftype) 23 mol = get_mol_from_file(options.ligand_path, options.ftype)
22 24
23 # get rdkit conformer and compute x,y,z of top and bottom corner of confounding cuboid 25 # get rdkit conformer and compute x,y,z of top and bottom corner of confounding cuboid
37 # optionally add buffers in each direction - expansion 39 # optionally add buffers in each direction - expansion
38 box_dims = [dims[0] + options.bufx, dims[1] + options.bufy, dims[2] + options.bufz] 40 box_dims = [dims[0] + options.bufx, dims[1] + options.bufy, dims[2] + options.bufz]
39 41
40 optionalvals = "" 42 optionalvals = ""
41 43
42 44 if options.seed is not None:
43 if options.seed != None:
44 optionalvals += "seed = " + str(options.seed) + "\n" 45 optionalvals += "seed = " + str(options.seed) + "\n"
45 if options.exhaustiveness != None: 46 if options.exhaustiveness is not None:
46 optionalvals += "exhaustiveness = " + str(options.exhaustiveness) + "\n" 47 optionalvals += "exhaustiveness = " + str(options.exhaustiveness) + "\n"
47 48
48 with open(options.output, 'w') as f: 49 with open(options.output, "w") as f:
49 f.write( 50 f.write(
50 """ 51 """
51 size_x = {} 52 size_x = {}
52 size_y = {} 53 size_y = {}
53 size_z = {} 54 size_z = {}
54 center_x = {} 55 center_x = {}
55 center_y = {} 56 center_y = {}
56 center_z = {} 57 center_z = {}
57 {}""".format(box_dims[0], box_dims[1], box_dims[2], center[0], center[1], center[2], optionalvals) 58 {}""".format(
59 box_dims[0],
60 box_dims[1],
61 box_dims[2],
62 center[0],
63 center[1],
64 center[2],
65 optionalvals,
66 )
58 ) 67 )
59 68
60 69
61 if __name__ == "__main__": 70 if __name__ == "__main__":
62 parser = argparse.ArgumentParser(description=""" 71 parser = argparse.ArgumentParser(
72 description="""
63 This tool calculates a confounding box around an input ligand, and uses it to 73 This tool calculates a confounding box around an input ligand, and uses it to
64 generate the input parameters for an autodock vina job. The output file can be fed into 74 generate the input parameters for an autodock vina job. The output file can be fed into
65 the autodock vina tool as an alternative to creating the parameter file manually. 75 the autodock vina tool as an alternative to creating the parameter file manually.
66 76
67 Optionally, you can include a 'buffer' in each of the x,y and z directions (in Å), 77 Optionally, you can include a 'buffer' in each of the x,y and z directions (in Å),
68 which will be added to the confounding box in the appropriate direction. 78 which will be added to the confounding box in the appropriate direction.
69 """) 79 """
70 parser.add_argument('--ligand', dest='ligand_path', help='The input ligand filepath.') 80 )
71 parser.add_argument('--ftype', dest='ftype', help='Filetype of the input ligand (mol, sdf, pdb, mol2)') 81 parser.add_argument(
72 parser.add_argument('--config', dest='output', help='The output file containing calculated params (txt)') 82 "--ligand", dest="ligand_path", help="The input ligand filepath."
73 parser.add_argument('--exh', dest='exhaustiveness', type=int, help='Exhaustiveness of global search') 83 )
74 parser.add_argument('--bufx', dest='bufx', default=0, type=float, help='the buffer in the x direction ' 84 parser.add_argument(
75 '(float - in angs.)') 85 "--ftype",
76 parser.add_argument('--bufy', dest='bufy', default=0, type=float, help='the buffer in the y direction ' 86 dest="ftype",
77 '(float - in angs.)') 87 help="Filetype of the input ligand (mol, sdf, pdb, mol2)",
78 parser.add_argument('--bufz', dest='bufz', default=0, type=float, help='the buffer in the z direction ' 88 )
79 '(float - in angs.)') 89 parser.add_argument(
80 parser.add_argument('--seed', dest='seed', default=None, type=int, help='Random seed for reproducibility') 90 "--config",
91 dest="output",
92 help="The output file containing calculated params (txt)",
93 )
94 parser.add_argument(
95 "--exh", dest="exhaustiveness", type=int, help="Exhaustiveness of global search"
96 )
97 parser.add_argument(
98 "--bufx",
99 dest="bufx",
100 default=0,
101 type=float,
102 help="the buffer in the x direction " "(float - in angs.)",
103 )
104 parser.add_argument(
105 "--bufy",
106 dest="bufy",
107 default=0,
108 type=float,
109 help="the buffer in the y direction " "(float - in angs.)",
110 )
111 parser.add_argument(
112 "--bufz",
113 dest="bufz",
114 default=0,
115 type=float,
116 help="the buffer in the z direction " "(float - in angs.)",
117 )
118 parser.add_argument(
119 "--seed",
120 dest="seed",
121 default=None,
122 type=int,
123 help="Random seed for reproducibility",
124 )
81 125
82 options = parser.parse_args() 126 options = parser.parse_args()
83 get_params(options) 127 get_params(options)