annotate dimorphite_dl.py @ 6:d68bf44e1f5c draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit a03b1b7b283901a1510562f1e6eba41f70afaac4"
author bgruening
date Mon, 23 Mar 2020 15:58:09 -0400
parents 414edd9ea77d
children a1c53f0533b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1 # Copyright 2018 Jacob D. Durrant
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
2 #
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
3 # Licensed under the Apache License, Version 2.0 (the "License");
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
4 # you may not use this file except in compliance with the License.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
5 # You may obtain a copy of the License at
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
6 #
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
7 # http://www.apache.org/licenses/LICENSE-2.0
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
8 #
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
9 # Unless required by applicable law or agreed to in writing, software
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
10 # distributed under the License is distributed on an "AS IS" BASIS,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
12 # See the License for the specific language governing permissions and
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
13 # limitations under the License.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
14
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
15 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
16 This script identifies and enumerates the possible protonation sites of SMILES
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
17 strings.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
18 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
19
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
20 from __future__ import print_function
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
21 import copy
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
22 import os
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
23 import argparse
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
24 import sys
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
25
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
26 try:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
27 # Python2
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
28 from StringIO import StringIO
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
29 except ImportError:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
30 # Python3
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
31 from io import StringIO
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
32
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
33 # Always let the user know a help file is available.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
34 print("\nFor help, use: python dimorphite_dl.py --help")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
35
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
36 # And always report citation information.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
37 print("\nIf you use Dimorphite-DL in your research, please cite:")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
38 print("Ropp PJ, Kaminsky JC, Yablonski S, Durrant JD (2019) Dimorphite-DL: An")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
39 print("open-source program for enumerating the ionization states of drug-like small")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
40 print("molecules. J Cheminform 11:14. doi:10.1186/s13321-019-0336-9.\n")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
41
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
42 try:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
43 import rdkit
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
44 from rdkit import Chem
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
45 from rdkit.Chem import AllChem
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
46 except:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
47 msg = "Dimorphite-DL requires RDKit. See https://www.rdkit.org/"
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
48 print(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
49 raise Exception(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
50
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
51 def main(params=None):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
52 """The main definition run when you call the script from the commandline.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
53
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
54 :param params: The parameters to use. Entirely optional. If absent,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
55 defaults to None, in which case argments will be taken from
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
56 those given at the command line.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
57 :param params: dict, optional
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
58 :return: Returns a list of the SMILES strings return_as_list parameter is
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
59 True. Otherwise, returns None.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
60 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
61
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
62 parser = ArgParseFuncs.get_args()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
63 args = vars(parser.parse_args())
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
64
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
65 # Add in any parameters in params.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
66 if params is not None:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
67 for k, v in params.items():
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
68 args[k] = v
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
69
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
70 # If being run from the command line, print out all parameters.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
71 if __name__ == "__main__":
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
72 print("\nPARAMETERS:\n")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
73 for k in sorted(args.keys()):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
74 print(k.rjust(13) + ": " + str(args[k]))
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
75 print("")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
76
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
77 if args["test"]:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
78 # Run tests.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
79 TestFuncs.test()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
80 else:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
81 # Run protonation
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
82 if "output_file" in args and args["output_file"] is not None:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
83 # An output file was specified, so write to that.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
84 with open(args["output_file"], "w") as file:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
85 for protonated_smi in Protonate(args):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
86 file.write(protonated_smi + "\n")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
87 elif "return_as_list" in args and args["return_as_list"] == True:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
88 return list(Protonate(args))
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
89 else:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
90 # No output file specified. Just print it to the screen.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
91 for protonated_smi in Protonate(args):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
92 print(protonated_smi)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
93
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
94 class MyParser(argparse.ArgumentParser):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
95 """Overwrite default parse so it displays help file on error. See
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
96 https://stackoverflow.com/questions/4042452/display-help-message-with-python-argparse-when-script-is-called-without-any-argu"""
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
97
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
98 def error(self, message):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
99 """Overwrites the default error message.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
100
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
101 :param message: The default error message.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
102 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
103
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
104 self.print_help()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
105 msg = "ERROR: %s\n\n" % message
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
106 print(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
107 raise Exception(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
108
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
109 def print_help(self, file=None):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
110 """Overwrite the default print_help function
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
111
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
112 :param file: Output file, defaults to None
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
113 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
114
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
115 print("")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
116
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
117 if file is None:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
118 file = sys.stdout
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
119 self._print_message(self.format_help(), file)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
120 print("""
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
121 examples:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
122 python dimorphite_dl.py --smiles_file sample_molecules.smi
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
123 python dimorphite_dl.py --smiles "CCC(=O)O" --min_ph -3.0 --max_ph -2.0
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
124 python dimorphite_dl.py --smiles "CCCN" --min_ph -3.0 --max_ph -2.0 --output_file output.smi
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
125 python dimorphite_dl.py --smiles_file sample_molecules.smi --pka_precision 2.0 --label_states
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
126 python dimorphite_dl.py --test""")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
127 print("")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
128
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
129 class ArgParseFuncs:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
130 """A namespace for storing functions that are useful for processing
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
131 command-line arguments. To keep things organized."""
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
132
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
133 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
134 def get_args():
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
135 """Gets the arguments from the command line.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
136
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
137 :return: A parser object.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
138 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
139
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
140 parser = MyParser(description="Dimorphite 1.2: Creates models of " +
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
141 "appropriately protonated small moleucles. " +
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
142 "Apache 2.0 License. Copyright 2018 Jacob D. " +
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
143 "Durrant.")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
144 parser.add_argument('--min_ph', metavar='MIN', type=float, default=6.4,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
145 help='minimum pH to consider (default: 6.4)')
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
146 parser.add_argument('--max_ph', metavar='MAX', type=float, default=8.4,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
147 help='maximum pH to consider (default: 8.4)')
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
148 parser.add_argument('--pka_precision', metavar='PRE', type=float, default=1.0,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
149 help='pKa precision factor (number of standard devations, default: 1.0)')
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
150 parser.add_argument('--smiles', metavar='SMI', type=str,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
151 help='SMILES string to protonate')
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
152 parser.add_argument('--smiles_file', metavar="FILE", type=str,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
153 help='file that contains SMILES strings to protonate')
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
154 parser.add_argument('--output_file', metavar="FILE", type=str,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
155 help='output file to write protonated SMILES (optional)')
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
156 parser.add_argument('--label_states', action="store_true",
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
157 help='label protonated SMILES with target state ' + \
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
158 '(i.e., "DEPROTONATED", "PROTONATED", or "BOTH").')
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
159 parser.add_argument('--test', action="store_true",
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
160 help='run unit tests (for debugging)')
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
161
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
162 return parser
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
163
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
164 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
165 def clean_args(args):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
166 """Cleans and normalizes input parameters
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
167
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
168 :param args: A dictionary containing the arguments.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
169 :type args: dict
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
170 :raises Exception: No SMILES in params.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
171 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
172
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
173 defaults = {'min_ph' : 6.4,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
174 'max_ph' : 8.4,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
175 'pka_precision' : 1.0,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
176 'label_states' : False,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
177 'test' : False}
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
178
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
179 for key in defaults:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
180 if key not in args:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
181 args[key] = defaults[key]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
182
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
183 keys = list(args.keys())
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
184 for key in keys:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
185 if args[key] is None:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
186 del args[key]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
187
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
188 if not "smiles" in args and not "smiles_file" in args:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
189 msg = "Error: No SMILES in params. Use the -h parameter for help."
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
190 print(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
191 raise Exception(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
192
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
193 # If the user provides a smiles string, turn it into a file-like StringIO
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
194 # object.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
195 if "smiles" in args:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
196 if isinstance(args["smiles"], str):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
197 args["smiles_file"] = StringIO(args["smiles"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
198
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
199 args["smiles_and_data"] = LoadSMIFile(args["smiles_file"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
200
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
201 return args
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
202
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
203 class UtilFuncs:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
204 """A namespace to store functions for manipulating mol objects. To keep
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
205 things organized."""
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
206
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
207 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
208 def neutralize_mol(mol):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
209 """All molecules should be neuralized to the extent possible. The user
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
210 should not be allowed to specify the valence of the atoms in most cases.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
211
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
212 :param rdkit.Chem.rdchem.Mol mol: The rdkit Mol objet to be neutralized.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
213 :return: The neutralized Mol object.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
214 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
215
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
216 # Get the reaction data
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
217 rxn_data = [
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
218 ['[Ov1-1:1]', '[Ov2+0:1]-[H]'], # To handle O- bonded to only one atom (add hydrogen).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
219 ['[#7v4+1:1]-[H]', '[#7v3+0:1]'], # To handle N+ bonded to a hydrogen (remove hydrogen).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
220 ['[Ov2-:1]', '[Ov2+0:1]'], # To handle O- bonded to two atoms. Should not be Negative.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
221 ['[#7v3+1:1]', '[#7v3+0:1]'], # To handle N+ bonded to three atoms. Should not be positive.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
222 ['[#7v2-1:1]', '[#7+0:1]-[H]'], # To handle N- Bonded to two atoms. Add hydrogen.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
223 # ['[N:1]=[N+0:2]=[N:3]-[H]', '[N:1]=[N+1:2]=[N+0:3]-[H]'], # To
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
224 # handle bad azide. Must be protonated. (Now handled elsewhere, before
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
225 # SMILES converted to Mol object.)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
226 ['[H]-[N:1]-[N:2]#[N:3]', '[N:1]=[N+1:2]=[N:3]-[H]'] # To handle bad azide. R-N-N#N should be R-N=[N+]=N
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
227 ]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
228
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
229 # Add substructures and reactions (initially none)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
230 for i, rxn_datum in enumerate(rxn_data):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
231 rxn_data[i].append(Chem.MolFromSmarts(rxn_datum[0]))
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
232 rxn_data[i].append(None)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
233
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
234 # Add hydrogens (respects valence, so incomplete).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
235 # Chem.calcImplicitValence(mol)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
236 mol.UpdatePropertyCache(strict=False)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
237 mol = Chem.AddHs(mol)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
238
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
239 while True: # Keep going until all these issues have been resolved.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
240 current_rxn = None # The reaction to perform.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
241 current_rxn_str = None
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
242
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
243 for i, rxn_datum in enumerate(rxn_data):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
244 reactant_smarts, product_smarts, substruct_match_mol, rxn_placeholder = rxn_datum
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
245 if mol.HasSubstructMatch(substruct_match_mol):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
246 if rxn_placeholder is None:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
247 current_rxn_str = reactant_smarts + '>>' + product_smarts
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
248 current_rxn = AllChem.ReactionFromSmarts(current_rxn_str)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
249 rxn_data[i][3] = current_rxn # Update the placeholder.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
250 else:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
251 current_rxn = rxn_data[i][3]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
252 break
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
253
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
254 # Perform the reaction if necessary
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
255 if current_rxn is None: # No reaction left, so break out of while loop.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
256 break
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
257 else:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
258 mol = current_rxn.RunReactants((mol,))[0][0]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
259 mol.UpdatePropertyCache(strict=False) # Update valences
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
260
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
261 # The mols have been altered from the reactions described above, we need
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
262 # to resanitize them. Make sure aromatic rings are shown as such This
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
263 # catches all RDKit Errors. without the catchError and sanitizeOps the
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
264 # Chem.SanitizeMol can crash the program.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
265 sanitize_string = Chem.SanitizeMol(
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
266 mol,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
267 sanitizeOps=rdkit.Chem.rdmolops.SanitizeFlags.SANITIZE_ALL,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
268 catchErrors = True
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
269 )
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
270
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
271 return mol if sanitize_string.name == "SANITIZE_NONE" else None
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
272
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
273 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
274 def convert_smiles_str_to_mol(smiles_str):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
275 """Given a SMILES string, check that it is actually a string and not a
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
276 None. Then try to convert it to an RDKit Mol Object.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
277
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
278 :param string smiles_str: The SMILES string.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
279 :return: A rdkit.Chem.rdchem.Mol object, or None if it is the wrong type or
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
280 if it fails to convert to a Mol Obj
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
281 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
282
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
283 # Check that there are no type errors, ie Nones or non-string
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
284 # A non-string type will cause RDKit to hard crash
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
285 if smiles_str is None or type(smiles_str) is not str:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
286 return None
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
287
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
288 # Try to fix azides here. They are just tricky to deal with.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
289 smiles_str = smiles_str.replace("N=N=N", "N=[N+]=N")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
290 smiles_str = smiles_str.replace("NN#N", "N=[N+]=N")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
291
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
292 # Now convert to a mol object. Note the trick that is necessary to
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
293 # capture RDKit error/warning messages. See
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
294 # https://stackoverflow.com/questions/24277488/in-python-how-to-capture-the-stdout-from-a-c-shared-library-to-a-variable
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
295 stderr_fileno = sys.stderr.fileno()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
296 stderr_save = os.dup(stderr_fileno)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
297 stderr_pipe = os.pipe()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
298 os.dup2(stderr_pipe[1], stderr_fileno)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
299 os.close(stderr_pipe[1])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
300
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
301 mol = Chem.MolFromSmiles(smiles_str)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
302
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
303 os.close(stderr_fileno)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
304 os.close(stderr_pipe[0])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
305 os.dup2(stderr_save, stderr_fileno)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
306 os.close(stderr_save)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
307
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
308 # Check that there are None type errors Chem.MolFromSmiles has sanitize on
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
309 # which means if there is even a small error in the SMILES (kekulize,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
310 # nitrogen charge...) then mol=None. ie.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
311 # Chem.MolFromSmiles("C[N]=[N]=[N]") = None this is an example of an
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
312 # nitrogen charge error. It is cased in a try statement to be overly
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
313 # cautious.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
314
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
315 return None if mol is None else mol
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
316
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
317 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
318 def eprint(*args, **kwargs):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
319 """Error messages should be printed to STDERR. See
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
320 https://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python"""
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
321
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
322 print(*args, file=sys.stderr, **kwargs)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
323
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
324 class LoadSMIFile(object):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
325 """A generator class for loading in the SMILES strings from a file, one at
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
326 a time."""
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
327
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
328 def __init__(self, filename):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
329 """Initializes this class.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
330
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
331 :param filename: The filename or file object (i.e., StringIO).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
332 :type filename: str or StringIO
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
333 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
334
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
335 if type(filename) is str:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
336 # It's a filename
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
337 self.f = open(filename, "r")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
338 else:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
339 # It's a file object (i.e., StringIO)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
340 self.f = filename
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
341
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
342 def __iter__(self):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
343 """Returns this generator object.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
344
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
345 :return: This generator object.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
346 :rtype: LoadSMIFile
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
347 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
348
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
349 return self
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
350
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
351 def __next__(self):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
352 """Ensure Python3 compatibility.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
353
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
354 :return: A dict, where the "smiles" key contains the canonical SMILES
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
355 string and the "data" key contains the remaining information
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
356 (e.g., the molecule name).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
357 :rtype: dict
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
358 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
359
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
360 return self.next()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
361
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
362 def next(self):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
363 """Get the data associated with the next line.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
364
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
365 :raises StopIteration: If there are no more lines left iin the file.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
366 :return: A dict, where the "smiles" key contains the canonical SMILES
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
367 string and the "data" key contains the remaining information
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
368 (e.g., the molecule name).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
369 :rtype: dict
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
370 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
371
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
372 line = self.f.readline()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
373
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
374 if line == "":
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
375 # EOF
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
376 self.f.close()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
377 raise StopIteration()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
378 return
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
379
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
380 # Divide line into smi and data
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
381 splits = line.split()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
382 if len(splits) != 0:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
383 # Generate mol object
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
384 smiles_str = splits[0]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
385
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
386 # Convert from SMILES string to RDKIT Mol. This series of tests is
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
387 # to make sure the SMILES string is properly formed and to get it
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
388 # into a canonical form. Filter if failed.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
389 mol = UtilFuncs.convert_smiles_str_to_mol(smiles_str)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
390 if mol is None:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
391 UtilFuncs.eprint("WARNING: Skipping poorly formed SMILES string: " + line)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
392 return self.next()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
393
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
394 # Handle nuetralizing the molecules. Filter if failed.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
395 mol = UtilFuncs.neutralize_mol(mol)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
396 if mol is None:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
397 UtilFuncs.eprint("WARNING: Skipping poorly formed SMILES string: " + line)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
398 return self.next()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
399
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
400 # Remove the hydrogens.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
401 try:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
402 mol = Chem.RemoveHs(mol)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
403 except:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
404 UtilFuncs.eprint("WARNING: Skipping poorly formed SMILES string: " + line)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
405 return self.next()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
406
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
407 if mol is None:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
408 UtilFuncs.eprint("WARNING: Skipping poorly formed SMILES string: " + line)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
409 return self.next()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
410
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
411 # Regenerate the smiles string (to standardize).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
412 new_mol_string = Chem.MolToSmiles(mol, isomericSmiles=True)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
413
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
414 return {
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
415 "smiles": new_mol_string,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
416 "data": splits[1:]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
417 }
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
418 else:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
419 # Blank line? Go to next one.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
420 return self.next()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
421
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
422 class Protonate(object):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
423 """A generator class for protonating SMILES strings, one at a time."""
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
424
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
425 def __init__(self, args):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
426 """Initialize the generator.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
427
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
428 :param args: A dictionary containing the arguments.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
429 :type args: dict
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
430 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
431
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
432 # Make the args an object variable variable.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
433 self.args = args
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
434
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
435 # A list to store the protonated SMILES strings associated with a
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
436 # single input model.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
437 self.cur_prot_SMI = []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
438
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
439 # Clean and normalize the args
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
440 self.args = ArgParseFuncs.clean_args(args)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
441
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
442 # Load the substructures that can be protonated.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
443 self.subs = ProtSubstructFuncs.load_protonation_substructs_calc_state_for_ph(
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
444 self.args["min_ph"], self.args["max_ph"], self.args["pka_precision"]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
445 )
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
446
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
447 def __iter__(self):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
448 """Returns this generator object.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
449
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
450 :return: This generator object.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
451 :rtype: Protonate
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
452 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
453
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
454 return self
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
455
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
456 def __next__(self):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
457 """Ensure Python3 compatibility.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
458
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
459 :return: A dict, where the "smiles" key contains the canonical SMILES
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
460 string and the "data" key contains the remaining information
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
461 (e.g., the molecule name).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
462 :rtype: dict
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
463 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
464
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
465 return self.next()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
466
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
467 def next(self):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
468 """Get the next protonated SMILES string.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
469
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
470 :raises StopIteration: If there are no more lines left iin the file.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
471 :return: TODO A dict, where the "smiles" key contains the canonical SMILES
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
472 string and the "data" key contains the remaining information
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
473 (e.g., the molecule name).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
474 :rtype: dict
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
475 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
476
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
477 # If there are any SMILES strings in self.cur_prot_SMI, just return
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
478 # the first one and update the list to include only the remaining.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
479 if len(self.cur_prot_SMI) > 0:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
480 first, self.cur_prot_SMI = self.cur_prot_SMI[0], self.cur_prot_SMI[1:]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
481 return first
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
482
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
483 # self.cur_prot_SMI is empty, so try to add more to it.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
484
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
485 # Get the next SMILES string from the input file.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
486 try:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
487 smile_and_datum = self.args["smiles_and_data"].next()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
488 except StopIteration:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
489 # There are no more input smiles strings...
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
490 raise StopIteration()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
491
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
492 smi = smile_and_datum["smiles"]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
493 data = smile_and_datum["data"] # Everything on SMILES line but the
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
494 # SMILES string itself (e.g., the
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
495 # molecule name).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
496
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
497 # Collect the data associated with this smiles (e.g., the molecule
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
498 # name).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
499 tag = " ".join(data)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
500
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
501 # sites is a list of (atom index, "PROTONATED|DEPROTONATED|BOTH").
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
502 # Note that the second entry indicates what state the site SHOULD be
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
503 # in (not the one it IS in per the SMILES string). It's calculated
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
504 # based on the probablistic distributions obtained during training.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
505 sites = ProtSubstructFuncs.get_prot_sites_and_target_states(smi, self.subs)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
506
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
507 new_smis = [smi]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
508 for site in sites:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
509 # Make a new smiles with the correct protonation state. Note that
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
510 # new_smis is a growing list. This is how multiple protonation
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
511 # sites are handled.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
512
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
513 # new_smis_to_perhaps_add = ProtSubstructFuncs.protonate_site(new_smis, site)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
514 new_smis = ProtSubstructFuncs.protonate_site(new_smis, site)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
515 # print(site, new_smis) # Good for debugging.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
516
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
517 # Only add new smiles if not already in the list.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
518 # for s in new_smis_to_perhaps_add:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
519 # if not s in new_smis:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
520 # new_smis.append(s)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
521
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
522 # In some cases, the script might generate redundant molecules.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
523 # Phosphonates, when the pH is between the two pKa values and the
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
524 # stdev value is big enough, for example, will generate two identical
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
525 # BOTH states. Let's remove this redundancy.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
526 new_smis = list(set(new_smis))
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
527
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
528 # Deprotonating protonated aromatic nitrogen gives [nH-]. Change this
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
529 # to [n-]. This is a hack.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
530 new_smis = [s.replace("[nH-]", "[n-]") for s in new_smis]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
531
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
532 # Sometimes Dimorphite-DL generates molecules that aren't actually
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
533 # possible. Simply convert these to mol objects to eliminate the bad
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
534 # ones (that are None).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
535 new_smis = [s for s in new_smis if UtilFuncs.convert_smiles_str_to_mol(s) is not None]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
536
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
537 # If there are no smi left, return the input one at the very least.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
538 # All generated forms have apparently been judged
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
539 # inappropriate/mal-formed.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
540 if len(new_smis) == 0:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
541 new_smis = [smi]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
542
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
543 # If the user wants to see the target states, add those
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
544 # to the ends of each line.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
545 if self.args["label_states"]:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
546 states = '\t'.join([x[1] for x in sites])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
547 new_lines = [x + "\t" + tag + "\t" + states for x in new_smis]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
548 else:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
549 new_lines = [x + "\t" + tag for x in new_smis]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
550
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
551 self.cur_prot_SMI = new_lines
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
552
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
553 return self.next()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
554
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
555 class ProtSubstructFuncs:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
556 """A namespace to store functions for loading the substructures that can
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
557 be protonated. To keep things organized."""
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
558
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
559 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
560 def load_protonation_substructs_calc_state_for_ph(min_ph=6.4, max_ph=8.4, pka_std_range=1):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
561 """A pre-calculated list of R-groups with protonation sites, with their
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
562 likely pKa bins.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
563
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
564 :param float min_ph: The lower bound on the pH range, defaults to 6.4.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
565 :param float max_ph: The upper bound on the pH range, defaults to 8.4.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
566 :param pka_std_range: Basically the precision (stdev from predicted pKa to
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
567 consider), defaults to 1.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
568 :return: A dict of the protonation substructions for the specified pH
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
569 range.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
570 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
571
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
572 subs = []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
573 pwd = os.path.dirname(os.path.realpath(__file__))
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
574
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
575 site_structures_file = "{}/{}".format(pwd, "site_substructures.smarts")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
576 with open(site_structures_file, 'r') as substruct:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
577 for line in substruct:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
578 line = line.strip()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
579 sub = {}
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
580 if line is not "":
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
581 splits = line.split()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
582 sub["name"] = splits[0]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
583 sub["smart"] = splits[1]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
584 sub["mol"] = Chem.MolFromSmarts(sub["smart"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
585
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
586 # NEED TO DIVIDE THIS BY 3s
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
587 pka_ranges = [splits[i:i+3] for i in range(2, len(splits)-1, 3)]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
588
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
589 prot = []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
590 for pka_range in pka_ranges:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
591 site = pka_range[0]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
592 std = float(pka_range[2]) * pka_std_range
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
593 mean = float(pka_range[1])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
594 protonation_state = ProtSubstructFuncs.define_protonation_state(
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
595 mean, std, min_ph, max_ph
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
596 )
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
597
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
598 prot.append([site, protonation_state])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
599
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
600 sub["prot_states_for_pH"] = prot
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
601 subs.append(sub)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
602 return subs
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
603
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
604 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
605 def define_protonation_state(mean, std, min_ph, max_ph):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
606 """Updates the substructure definitions to include the protonation state
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
607 based on the user-given pH range. The size of the pKa range is also based
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
608 on the number of standard deviations to be considered by the user param.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
609
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
610 :param float mean: The mean pKa.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
611 :param float std: The precision (stdev).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
612 :param float min_ph: The min pH of the range.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
613 :param float max_ph: The max pH of the range.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
614 :return: A string describing the protonation state.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
615 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
616
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
617 min_pka = mean - std
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
618 max_pka = mean + std
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
619
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
620 # This needs to be reassigned, and 'ERROR' should never make it past the
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
621 # next set of checks.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
622 if min_pka <= max_ph and min_ph <= max_pka:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
623 protonation_state = 'BOTH'
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
624 elif mean > max_ph:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
625 protonation_state = 'PROTONATED'
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
626 else:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
627 protonation_state = 'DEPROTONATED'
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
628
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
629 return protonation_state
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
630
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
631 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
632 def get_prot_sites_and_target_states(smi, subs):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
633 """For a single molecule, find all possible matches in the protonation
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
634 R-group list, subs. Items that are higher on the list will be matched
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
635 first, to the exclusion of later items.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
636
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
637 :param string smi: A SMILES string.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
638 :param list subs: Substructure information.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
639 :return: A list of protonation sites and their pKa bin. ('PROTONATED',
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
640 'BOTH', or 'DEPROTONATED')
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
641 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
642
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
643 # Convert the Smiles string (smi) to an RDKit Mol Obj
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
644 mol = UtilFuncs.convert_smiles_str_to_mol(smi)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
645
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
646 # Check Conversion worked
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
647 if mol is None:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
648 UtilFuncs.eprint("ERROR: ", smi)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
649 return []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
650
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
651 # Try to Add hydrogens. if failed return []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
652 try:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
653 mol = Chem.AddHs(mol)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
654 except:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
655 UtilFuncs.eprint("ERROR: ", smi)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
656 return []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
657
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
658 # Check adding Hs worked
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
659 if mol is None:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
660 UtilFuncs.eprint("ERROR: ", smi)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
661 return []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
662
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
663 ProtectUnprotectFuncs.unprotect_molecule(mol)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
664 protonation_sites = []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
665
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
666 for item in subs:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
667 smart = item["mol"]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
668 if mol.HasSubstructMatch(smart):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
669 matches = ProtectUnprotectFuncs.get_unprotected_matches(mol, smart)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
670 prot = item["prot_states_for_pH"]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
671 for match in matches:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
672 # We want to move the site from being relative to the
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
673 # substructure, to the index on the main molecule.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
674 for site in prot:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
675 proton = int(site[0])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
676 category = site[1]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
677 new_site = (match[proton], category, item["name"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
678
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
679 if not new_site in protonation_sites:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
680 # Because sites must be unique.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
681 protonation_sites.append(new_site)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
682
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
683 ProtectUnprotectFuncs.protect_molecule(mol, match)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
684
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
685 return protonation_sites
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
686
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
687 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
688 def protonate_site(smis, site):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
689 """Given a list of SMILES strings, we protonate the site.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
690
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
691 :param list smis: The list of SMILES strings.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
692 :param tuple site: Information about the protonation site.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
693 (idx, target_prot_state, prot_site_name)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
694 :return: A list of the appropriately protonated SMILES.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
695 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
696
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
697 # Decouple the atom index and its target protonation state from the site
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
698 # tuple
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
699 idx, target_prot_state, prot_site_name = site
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
700
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
701 # Initialize the output list
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
702 output_smis = []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
703
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
704 state_to_charge = {"DEPROTONATED": [-1],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
705 "PROTONATED": [0],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
706 "BOTH": [-1, 0]}
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
707
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
708 charges = state_to_charge[target_prot_state]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
709
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
710 # Now make the actual smiles match the target protonation state.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
711 output_smis = ProtSubstructFuncs.set_protonation_charge(smis, idx, charges, prot_site_name)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
712
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
713 return output_smis
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
714
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
715 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
716 def set_protonation_charge(smis, idx, charges, prot_site_name):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
717 """Sets the atomic charge on a particular site for a set of SMILES.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
718
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
719 :param list smis: A list of the SMILES strings.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
720 :param int idx: The index of the atom to consider.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
721 :param list charges: A list of the charges (ints) to assign at
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
722 this site.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
723 :param string prot_site_name: The name of the protonation site.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
724 :return: A list of the processed SMILES strings.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
725 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
726
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
727 # Sets up the output list and the Nitrogen charge
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
728 output = []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
729
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
730 for charge in charges:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
731 # The charge for Nitrogens is 1 higher than others (i.e., protonated
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
732 # state is positively charged).
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
733 nitro_charge = charge + 1
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
734
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
735 # But there are a few nitrogen moieties where the acidic group is the
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
736 # neutral one. Amides are a good example. I gave some thought re. how
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
737 # to best flag these. I decided that those nitrogen-containing
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
738 # moieties where the acidic group is neutral (rather than positively
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
739 # charged) will have "*" in the name.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
740 if "*" in prot_site_name:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
741 nitro_charge = nitro_charge - 1 # Undo what was done previously.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
742
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
743 for smi in smis:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
744
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
745 # Convert smilesstring (smi) into a RDKit Mol
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
746 mol = UtilFuncs.convert_smiles_str_to_mol(smi)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
747
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
748 # Check that the conversion worked, skip if it fails
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
749 if mol is None:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
750 continue
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
751
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
752 atom = mol.GetAtomWithIdx(idx)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
753
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
754 # Assign the protonation charge, with special care for Nitrogens
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
755 element = atom.GetAtomicNum()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
756 if element == 7:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
757 atom.SetFormalCharge(nitro_charge)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
758 else:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
759 atom.SetFormalCharge(charge)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
760
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
761 # Convert back to SMILE and add to output
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
762 out_smile = Chem.MolToSmiles(mol, isomericSmiles=True,canonical=True)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
763 output.append(out_smile)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
764
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
765 return output
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
766
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
767 class ProtectUnprotectFuncs:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
768 """A namespace for storing functions that are useful for protecting and
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
769 unprotecting molecules. To keep things organized. We need to identify and
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
770 mark groups that have been matched with a substructure."""
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
771
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
772 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
773 def unprotect_molecule(mol):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
774 """Sets the protected property on all atoms to 0. This also creates the
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
775 property for new molecules.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
776
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
777 :param rdkit.Chem.rdchem.Mol mol: The rdkit Mol object.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
778 :type mol: The rdkit Mol object with atoms unprotected.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
779 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
780
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
781 for atom in mol.GetAtoms():
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
782 atom.SetProp('_protected', '0')
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
783
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
784 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
785 def protect_molecule(mol, match):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
786 """Given a 'match', a list of molecules idx's, we set the protected status
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
787 of each atom to 1. This will prevent any matches using that atom in the
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
788 future.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
789
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
790 :param rdkit.Chem.rdchem.Mol mol: The rdkit Mol object to protect.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
791 :param list match: A list of molecule idx's.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
792 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
793
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
794 for idx in match:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
795 atom = mol.GetAtomWithIdx(idx)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
796 atom.SetProp('_protected', '1')
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
797
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
798 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
799 def get_unprotected_matches(mol, substruct):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
800 """Finds substructure matches with atoms that have not been protected.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
801 Returns list of matches, each match a list of atom idxs.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
802
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
803 :param rdkit.Chem.rdchem.Mol mol: The Mol object to consider.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
804 :param string substruct: The SMARTS string of the substructure ot match.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
805 :return: A list of the matches. Each match is itself a list of atom idxs.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
806 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
807
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
808 matches = mol.GetSubstructMatches(substruct)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
809 unprotected_matches = []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
810 for match in matches:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
811 if ProtectUnprotectFuncs.is_match_unprotected(mol, match):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
812 unprotected_matches.append(match)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
813 return unprotected_matches
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
814
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
815 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
816 def is_match_unprotected(mol, match):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
817 """Checks a molecule to see if the substructure match contains any
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
818 protected atoms.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
819
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
820 :param rdkit.Chem.rdchem.Mol mol: The Mol object to check.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
821 :param list match: The match to check.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
822 :return: A boolean, whether the match is present or not.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
823 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
824
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
825 for idx in match:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
826 atom = mol.GetAtomWithIdx(idx)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
827 protected = atom.GetProp("_protected")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
828 if protected == "1":
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
829 return False
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
830 return True
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
831
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
832 class TestFuncs:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
833 """A namespace for storing functions that perform tests on the code. To
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
834 keep things organized."""
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
835
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
836 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
837 def test():
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
838 """Tests all the 38 groups."""
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
839
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
840 smis = [
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
841 # [input smiles, pka, protonated, deprotonated, category]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
842 ["C#CCO", "C#CCO", "C#CC[O-]", "Alcohol"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
843 ["C(=O)N", "NC=O", "[NH-]C=O", "Amide"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
844 ["CC(=O)NOC(C)=O", "CC(=O)NOC(C)=O", "CC(=O)[N-]OC(C)=O", "Amide_electronegative"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
845 ["COC(=N)N", "COC(N)=[NH2+]", "COC(=N)N", "AmidineGuanidine2"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
846 ["Brc1ccc(C2NCCS2)cc1", "Brc1ccc(C2[NH2+]CCS2)cc1", "Brc1ccc(C2NCCS2)cc1", "Amines_primary_secondary_tertiary"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
847 ["CC(=O)[n+]1ccc(N)cc1", "CC(=O)[n+]1ccc([NH3+])cc1", "CC(=O)[n+]1ccc(N)cc1", "Anilines_primary"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
848 ["CCNc1ccccc1", "CC[NH2+]c1ccccc1", "CCNc1ccccc1", "Anilines_secondary"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
849 ["Cc1ccccc1N(C)C", "Cc1ccccc1[NH+](C)C", "Cc1ccccc1N(C)C", "Anilines_tertiary"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
850 ["BrC1=CC2=C(C=C1)NC=C2", "Brc1ccc2[nH]ccc2c1", "Brc1ccc2[n-]ccc2c1", "Indole_pyrrole"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
851 ["O=c1cc[nH]cc1", "O=c1cc[nH]cc1", "O=c1cc[n-]cc1", "Aromatic_nitrogen_protonated"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
852 ["C-N=[N+]=[N@H]", "CN=[N+]=N", "CN=[N+]=[N-]", "Azide"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
853 ["BrC(C(O)=O)CBr", "O=C(O)C(Br)CBr", "O=C([O-])C(Br)CBr", "Carboxyl"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
854 ["NC(NN=O)=N", "NC(=[NH2+])NN=O", "N=C(N)NN=O", "AmidineGuanidine1"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
855 ["C(F)(F)(F)C(=O)NC(=O)C", "CC(=O)NC(=O)C(F)(F)F", "CC(=O)[N-]C(=O)C(F)(F)F", "Imide"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
856 ["O=C(C)NC(C)=O", "CC(=O)NC(C)=O", "CC(=O)[N-]C(C)=O", "Imide2"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
857 ["CC(C)(C)C(N(C)O)=O", "CN(O)C(=O)C(C)(C)C", "CN([O-])C(=O)C(C)(C)C", "N-hydroxyamide"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
858 ["C[N+](O)=O", "C[N+](=O)O", "C[N+](=O)[O-]", "Nitro"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
859 ["O=C1C=C(O)CC1", "O=C1C=C(O)CC1", "O=C1C=C([O-])CC1", "O=C-C=C-OH"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
860 ["C1CC1OO", "OOC1CC1", "[O-]OC1CC1", "Peroxide2"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
861 ["C(=O)OO", "O=COO", "O=CO[O-]", "Peroxide1"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
862 ["Brc1cc(O)cc(Br)c1", "Oc1cc(Br)cc(Br)c1", "[O-]c1cc(Br)cc(Br)c1", "Phenol"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
863 ["CC(=O)c1ccc(S)cc1", "CC(=O)c1ccc(S)cc1", "CC(=O)c1ccc([S-])cc1", "Phenyl_Thiol"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
864 ["C=CCOc1ccc(C(=O)O)cc1", "C=CCOc1ccc(C(=O)O)cc1", "C=CCOc1ccc(C(=O)[O-])cc1", "Phenyl_carboxyl"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
865 ["COP(=O)(O)OC", "COP(=O)(O)OC", "COP(=O)([O-])OC", "Phosphate_diester"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
866 ["CP(C)(=O)O", "CP(C)(=O)O", "CP(C)(=O)[O-]", "Phosphinic_acid"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
867 ["CC(C)OP(C)(=O)O", "CC(C)OP(C)(=O)O", "CC(C)OP(C)(=O)[O-]", "Phosphonate_ester"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
868 ["CC1(C)OC(=O)NC1=O", "CC1(C)OC(=O)NC1=O", "CC1(C)OC(=O)[N-]C1=O", "Ringed_imide1"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
869 ["O=C(N1)C=CC1=O", "O=C1C=CC(=O)N1", "O=C1C=CC(=O)[N-]1", "Ringed_imide2"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
870 ["O=S(OC)(O)=O", "COS(=O)(=O)O", "COS(=O)(=O)[O-]", "Sulfate"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
871 ["COc1ccc(S(=O)O)cc1", "COc1ccc(S(=O)O)cc1", "COc1ccc(S(=O)[O-])cc1", "Sulfinic_acid"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
872 ["CS(N)(=O)=O", "CS(N)(=O)=O", "CS([NH-])(=O)=O", "Sulfonamide"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
873 ["CC(=O)CSCCS(O)(=O)=O", "CC(=O)CSCCS(=O)(=O)O", "CC(=O)CSCCS(=O)(=O)[O-]", "Sulfonate"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
874 ["CC(=O)S", "CC(=O)S", "CC(=O)[S-]", "Thioic_acid"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
875 ["C(C)(C)(C)(S)", "CC(C)(C)S", "CC(C)(C)[S-]", "Thiol"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
876 ["Brc1cc[nH+]cc1", "Brc1cc[nH+]cc1", "Brc1ccncc1", "Aromatic_nitrogen_unprotonated"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
877 ["C=C(O)c1c(C)cc(C)cc1C", "C=C(O)c1c(C)cc(C)cc1C", "C=C([O-])c1c(C)cc(C)cc1C", "Vinyl_alcohol"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
878 ["CC(=O)ON", "CC(=O)O[NH3+]", "CC(=O)ON", "Primary_hydroxyl_amine"]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
879 ]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
880
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
881 smis_phos = [
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
882 ["O=P(O)(O)OCCCC", "CCCCOP(=O)(O)O", "CCCCOP(=O)([O-])O", "CCCCOP(=O)([O-])[O-]", "Phosphate"],
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
883 ["CC(P(O)(O)=O)C", "CC(C)P(=O)(O)O", "CC(C)P(=O)([O-])O", "CC(C)P(=O)([O-])[O-]", "Phosphonate"]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
884 ]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
885
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
886 # Load the average pKa values.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
887 average_pkas = {l.split()[0].replace("*", ""):float(l.split()[3]) for l in open("site_substructures.smarts") if l.split()[0] not in ["Phosphate", "Phosphonate"]}
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
888 average_pkas_phos = {l.split()[0].replace("*", ""):[float(l.split()[3]), float(l.split()[6])] for l in open("site_substructures.smarts") if l.split()[0] in ["Phosphate", "Phosphonate"]}
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
889
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
890 print("Running Tests")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
891 print("=============")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
892 print("")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
893
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
894 print("Very Acidic (pH -10000000)")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
895 print("--------------------------")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
896 print("")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
897
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
898 args = {
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
899 "min_ph": -10000000,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
900 "max_ph": -10000000,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
901 "pka_precision": 0.5,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
902 "smiles": "",
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
903 "label_states": True
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
904 }
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
905
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
906 for smi, protonated, deprotonated, category in smis:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
907 args["smiles"] = smi
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
908 TestFuncs.test_check(args, [protonated], ["PROTONATED"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
909
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
910 for smi, protonated, mix, deprotonated, category in smis_phos:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
911 args["smiles"] = smi
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
912 TestFuncs.test_check(args, [protonated], ["PROTONATED"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
913
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
914 args["min_ph"] = 10000000
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
915 args["max_ph"] = 10000000
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
916
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
917 print("")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
918 print("Very Basic (pH 10000000)")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
919 print("------------------------")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
920 print("")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
921
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
922 for smi, protonated, deprotonated, category in smis:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
923 args["smiles"] = smi
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
924 TestFuncs.test_check(args, [deprotonated], ["DEPROTONATED"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
925
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
926 for smi, protonated, mix, deprotonated, category in smis_phos:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
927 args["smiles"] = smi
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
928 TestFuncs.test_check(args, [deprotonated], ["DEPROTONATED"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
929
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
930 print("")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
931 print("pH is Category pKa")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
932 print("------------------")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
933 print("")
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
934
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
935 for smi, protonated, deprotonated, category in smis:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
936 avg_pka = average_pkas[category]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
937
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
938 args["smiles"] = smi
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
939 args["min_ph"] = avg_pka
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
940 args["max_ph"] = avg_pka
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
941
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
942 TestFuncs.test_check(args, [protonated, deprotonated], ["BOTH"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
943
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
944 for smi, protonated, mix, deprotonated, category in smis_phos:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
945 args["smiles"] = smi
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
946
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
947 avg_pka = average_pkas_phos[category][0]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
948 args["min_ph"] = avg_pka
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
949 args["max_ph"] = avg_pka
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
950
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
951 TestFuncs.test_check(args, [mix, protonated], ["BOTH"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
952
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
953 avg_pka = average_pkas_phos[category][1]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
954 args["min_ph"] = avg_pka
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
955 args["max_ph"] = avg_pka
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
956
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
957 TestFuncs.test_check(args, [mix, deprotonated], ["DEPROTONATED", "DEPROTONATED"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
958
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
959 avg_pka = 0.5 * (average_pkas_phos[category][0] + average_pkas_phos[category][1])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
960 args["min_ph"] = avg_pka
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
961 args["max_ph"] = avg_pka
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
962 args["pka_precision"] = 5 # Should give all three
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
963
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
964 TestFuncs.test_check(args, [mix, deprotonated, protonated], ["BOTH", "BOTH"])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
965
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
966 @staticmethod
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
967 def test_check(args, expected_output, labels):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
968 """Tests most ionizable groups. The ones that can only loose or gain a single proton.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
969
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
970 :param args: The arguments to pass to protonate()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
971 :param expected_output: A list of the expected SMILES-strings output.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
972 :param labels: The labels. A list containing combo of BOTH, PROTONATED,
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
973 DEPROTONATED.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
974 :raises Exception: Wrong number of states produced.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
975 :raises Exception: Unexpected output SMILES.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
976 :raises Exception: Wrong labels.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
977 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
978
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
979 output = list(Protonate(args))
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
980 output = [o.split() for o in output]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
981
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
982 num_states = len(expected_output)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
983
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
984 if (len(output) != num_states):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
985 msg = args["smiles"] + " should have " + str(num_states) + \
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
986 " states at at pH " + str(args["min_ph"]) + ": " + str(output)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
987 print(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
988 raise Exception(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
989
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
990 if (len(set([l[0] for l in output]) - set(expected_output)) != 0):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
991 msg = args["smiles"] + " is not " + " AND ".join(expected_output) + \
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
992 " at pH " + str(args["min_ph"]) + " - " + str(args["max_ph"]) + \
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
993 "; it is " + " AND ".join([l[0] for l in output])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
994 print(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
995 raise Exception(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
996
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
997 if (len(set([l[1] for l in output]) - set(labels)) != 0):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
998 msg = args["smiles"] + " not labeled as " + " AND ".join(labels) + \
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
999 "; it is " + " AND ".join([l[1] for l in output])
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1000 print(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1001 raise Exception(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1002
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1003 ph_range = sorted(list(set([args["min_ph"], args["max_ph"]])))
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1004 ph_range_str = "(" + " - ".join("{0:.2f}".format(n) for n in ph_range) + ")"
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1005 print("(CORRECT) " + ph_range_str.ljust(10) + " " + args["smiles"] + " => " + " AND ".join([l[0] for l in output]))
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1006
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1007 def run(**kwargs):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1008 """A helpful, importable function for those who want to call Dimorphite-DL
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1009 from another Python script rather than the command line. Note that this
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1010 function accepts keyword arguments that match the command-line parameters
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1011 exactly. If you want to pass and return a list of RDKit Mol objects, import
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1012 run_with_mol_list() instead.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1013
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1014 :param **kwargs: For a complete description, run dimorphite_dl.py from the
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1015 command line with the -h option.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1016 :type kwargs: dict
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1017 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1018
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1019 # Run the main function with the specified arguments.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1020 main(kwargs)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1021
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1022 def run_with_mol_list(mol_lst, **kwargs):
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1023 """A helpful, importable function for those who want to call Dimorphite-DL
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1024 from another Python script rather than the command line. Note that this
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1025 function is for passing Dimorphite-DL a list of RDKit Mol objects, together
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1026 with command-line parameters. If you want to use only the same parameters
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1027 that you would use from the command line, import run() instead.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1028
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1029 :param mol_lst: A list of rdkit.Chem.rdchem.Mol objects.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1030 :type mol_lst: list
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1031 :raises Exception: If the **kwargs includes "smiles", "smiles_file",
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1032 "output_file", or "test" parameters.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1033 :return: A list of properly protonated rdkit.Chem.rdchem.Mol objects.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1034 :rtype: list
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1035 """
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1036
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1037 # Do a quick check to make sure the user input makes sense.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1038 for bad_arg in ["smiles", "smiles_file", "output_file", "test"]:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1039 if bad_arg in kwargs:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1040 msg = "You're using Dimorphite-DL's run_with_mol_list(mol_lst, " + \
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1041 "**kwargs) function, but you also passed the \"" + \
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1042 bad_arg + "\" argument. Did you mean to use the " + \
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1043 "run(**kwargs) function instead?"
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1044 print(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1045 raise Exception(msg)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1046
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1047 # Set the return_as_list flag so main() will return the protonated smiles
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1048 # as a list.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1049 kwargs["return_as_list"] = True
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1050
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1051 # Having reviewed the code, it will be very difficult to rewrite it so
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1052 # that a list of Mol objects can be used directly. Intead, convert this
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1053 # list of mols to smiles and pass that. Not efficient, but it will work.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1054 protonated_smiles_and_props = []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1055 for m in mol_lst:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1056 props = m.GetPropsAsDict()
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1057 kwargs["smiles"] = Chem.MolToSmiles(m, isomericSmiles=True)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1058 protonated_smiles_and_props.extend(
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1059 [(s.split("\t")[0], props) for s in main(kwargs)]
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1060 )
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1061
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1062 # Now convert the list of protonated smiles strings back to RDKit Mol
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1063 # objects. Also, add back in the properties from the original mol objects.
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1064 mols = []
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1065 for s, props in protonated_smiles_and_props:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1066 m = Chem.MolFromSmiles(s)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1067 if m:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1068 for prop, val in props.items():
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1069 if type(val) is int:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1070 m.SetIntProp(prop, val)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1071 elif type(val) is float:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1072 m.SetDoubleProp(prop, val)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1073 elif type(val) is bool:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1074 m.SetBoolProp(prop, val)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1075 else:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1076 m.SetProp(prop, str(val))
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1077 mols.append(m)
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1078 else:
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1079 UtilFuncs.eprint("WARNING: Could not process molecule with SMILES string " + s + " and properties " + str(props))
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1080
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1081 return mols
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1082
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1083 if __name__ == "__main__":
414edd9ea77d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1084 main()