annotate dimorphite_dl.py @ 5:351fbd750a6d draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
author bgruening
date Wed, 17 Feb 2021 13:00:12 +0000
parents 193389d3a5f0
children 4beb3e026bbb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
351fbd750a6d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 1
diff changeset
1 # flake8: noqa
1
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
2 # Copyright 2018 Jacob D. Durrant
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
3 #
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
4 # Licensed under the Apache License, Version 2.0 (the "License");
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
5 # you may not use this file except in compliance with the License.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
6 # You may obtain a copy of the License at
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
7 #
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
8 # http://www.apache.org/licenses/LICENSE-2.0
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
9 #
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
10 # Unless required by applicable law or agreed to in writing, software
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
11 # distributed under the License is distributed on an "AS IS" BASIS,
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
13 # See the License for the specific language governing permissions and
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
14 # limitations under the License.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
15
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
16 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
17 This script identifies and enumerates the possible protonation sites of SMILES
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
18 strings.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
19 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
20
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
21 from __future__ import print_function
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
22 import os
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
23 import argparse
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
24 import sys
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
25
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
26 try:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
27 # Python2
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
28 from StringIO import StringIO
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
29 except ImportError:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
30 # Python3
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
31 from io import StringIO
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
32
193389d3a5f0 "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.
193389d3a5f0 "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")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
35
193389d3a5f0 "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.
193389d3a5f0 "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:")
193389d3a5f0 "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")
193389d3a5f0 "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")
193389d3a5f0 "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")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
41
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
42 try:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
43 import rdkit
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
44 from rdkit import Chem
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
46 except:
193389d3a5f0 "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/"
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
48 print(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
49 raise Exception(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
50
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
51 def main(params=None):
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
53
193389d3a5f0 "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,
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
57 :param params: dict, optional
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
59 True. Otherwise, returns None.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
60 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
61
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
62 parser = ArgParseFuncs.get_args()
193389d3a5f0 "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())
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
64
193389d3a5f0 "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.
193389d3a5f0 "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:
193389d3a5f0 "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():
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
68 args[k] = v
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
69
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
71 if __name__ == "__main__":
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
72 print("\nPARAMETERS:\n")
193389d3a5f0 "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()):
193389d3a5f0 "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]))
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
75 print("")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
76
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
77 if args["test"]:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
78 # Run tests.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
79 TestFuncs.test()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
80 else:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
81 # Run protonation
193389d3a5f0 "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:
193389d3a5f0 "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.
193389d3a5f0 "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:
193389d3a5f0 "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):
193389d3a5f0 "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")
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
88 return list(Protonate(args))
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
89 else:
193389d3a5f0 "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.
193389d3a5f0 "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):
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
92 print(protonated_smi)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
93
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
94 class MyParser(argparse.ArgumentParser):
193389d3a5f0 "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
193389d3a5f0 "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"""
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
97
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
98 def error(self, message):
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
100
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
102 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
103
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
104 self.print_help()
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
106 print(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
107 raise Exception(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
108
193389d3a5f0 "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):
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
111
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
113 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
114
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
115 print("")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
116
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
117 if file is None:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
118 file = sys.stdout
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
120 print("""
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
121 examples:
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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""")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
127 print("")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
128
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
129 class ArgParseFuncs:
193389d3a5f0 "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
193389d3a5f0 "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."""
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
132
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
133 @staticmethod
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
134 def get_args():
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
136
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
137 :return: A parser object.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
138 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
139
193389d3a5f0 "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 " +
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
141 "appropriately protonated small moleucles. " +
193389d3a5f0 "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. " +
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
143 "Durrant.")
193389d3a5f0 "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,
193389d3a5f0 "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)')
193389d3a5f0 "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,
193389d3a5f0 "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)')
193389d3a5f0 "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,
193389d3a5f0 "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)')
193389d3a5f0 "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,
193389d3a5f0 "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')
193389d3a5f0 "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,
193389d3a5f0 "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')
193389d3a5f0 "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,
193389d3a5f0 "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)')
193389d3a5f0 "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",
193389d3a5f0 "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 ' + \
193389d3a5f0 "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").')
193389d3a5f0 "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",
193389d3a5f0 "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)')
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
161
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
162 return parser
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
163
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
164 @staticmethod
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
165 def clean_args(args):
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
167
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
169 :type args: dict
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
171 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
172
193389d3a5f0 "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,
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
174 'max_ph' : 8.4,
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
175 'pka_precision' : 1.0,
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
176 'label_states' : False,
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
177 'test' : False}
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
178
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
179 for key in defaults:
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
181 args[key] = defaults[key]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
182
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
183 keys = list(args.keys())
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
184 for key in keys:
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
186 del args[key]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
187
193389d3a5f0 "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:
193389d3a5f0 "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."
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
190 print(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
191 raise Exception(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
192
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
194 # object.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
195 if "smiles" in args:
193389d3a5f0 "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):
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
198
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
200
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
201 return args
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
202
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
203 class UtilFuncs:
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
205 things organized."""
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
206
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
207 @staticmethod
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
208 def neutralize_mol(mol):
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
211
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
214 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
215
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
216 # Get the reaction data
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
217 rxn_data = [
193389d3a5f0 "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).
193389d3a5f0 "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).
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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.)
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
227 ]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
228
193389d3a5f0 "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)
193389d3a5f0 "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):
193389d3a5f0 "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]))
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
233
193389d3a5f0 "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).
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
235 # Chem.calcImplicitValence(mol)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
236 mol.UpdatePropertyCache(strict=False)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
237 mol = Chem.AddHs(mol)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
238
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
241 current_rxn_str = None
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
242
193389d3a5f0 "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):
193389d3a5f0 "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
193389d3a5f0 "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):
193389d3a5f0 "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:
193389d3a5f0 "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
193389d3a5f0 "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)
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
250 else:
193389d3a5f0 "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]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
252 break
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
253
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
256 break
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
257 else:
193389d3a5f0 "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]
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
260
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
265 sanitize_string = Chem.SanitizeMol(
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
266 mol,
193389d3a5f0 "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,
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
268 catchErrors = True
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
269 )
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
270
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
272
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
273 @staticmethod
193389d3a5f0 "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):
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
277
193389d3a5f0 "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.
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
281 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
282
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
286 return None
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
287
193389d3a5f0 "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.
193389d3a5f0 "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")
193389d3a5f0 "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")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
291
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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()
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
297 stderr_pipe = os.pipe()
193389d3a5f0 "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)
193389d3a5f0 "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])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
300
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
302
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
303 os.close(stderr_fileno)
193389d3a5f0 "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])
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
306 os.close(stderr_save)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
307
193389d3a5f0 "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
193389d3a5f0 "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,
193389d3a5f0 "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.
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
313 # cautious.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
314
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
316
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
317 @staticmethod
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
318 def eprint(*args, **kwargs):
193389d3a5f0 "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
193389d3a5f0 "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"""
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
321
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
323
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
324 class LoadSMIFile(object):
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
326 a time."""
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
327
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
328 def __init__(self, filename):
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
329 """Initializes this class.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
330
193389d3a5f0 "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).
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
333 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
334
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
336 # It's a filename
193389d3a5f0 "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")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
338 else:
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
340 self.f = filename
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
341
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
342 def __iter__(self):
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
343 """Returns this generator object.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
344
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
345 :return: This generator object.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
346 :rtype: LoadSMIFile
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
347 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
348
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
349 return self
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
350
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
351 def __next__(self):
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
352 """Ensure Python3 compatibility.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
353
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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).
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
357 :rtype: dict
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
358 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
359
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
360 return self.next()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
361
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
362 def next(self):
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
364
193389d3a5f0 "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.
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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).
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
369 :rtype: dict
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
370 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
371
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
372 line = self.f.readline()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
373
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
374 if line == "":
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
375 # EOF
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
376 self.f.close()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
377 raise StopIteration()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
378 return
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
379
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
381 splits = line.split()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
382 if len(splits) != 0:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
383 # Generate mol object
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
384 smiles_str = splits[0]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
385
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
390 if mol is None:
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
392 return self.next()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
393
193389d3a5f0 "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.
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
396 if mol is None:
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
398 return self.next()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
399
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
400 # Remove the hydrogens.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
401 try:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
402 mol = Chem.RemoveHs(mol)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
403 except:
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
405 return self.next()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
406
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
407 if mol is None:
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
409 return self.next()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
410
193389d3a5f0 "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).
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
413
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
414 return {
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
415 "smiles": new_mol_string,
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
416 "data": splits[1:]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
417 }
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
418 else:
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
420 return self.next()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
421
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
422 class Protonate(object):
193389d3a5f0 "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."""
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
424
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
425 def __init__(self, args):
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
426 """Initialize the generator.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
427
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
429 :type args: dict
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
430 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
431
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
433 self.args = args
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
434
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
436 # single input model.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
437 self.cur_prot_SMI = []
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
438
193389d3a5f0 "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
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
441
193389d3a5f0 "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.
193389d3a5f0 "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(
193389d3a5f0 "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"]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
445 )
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
446
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
447 def __iter__(self):
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
448 """Returns this generator object.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
449
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
450 :return: This generator object.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
451 :rtype: Protonate
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
452 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
453
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
454 return self
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
455
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
456 def __next__(self):
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
457 """Ensure Python3 compatibility.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
458
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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).
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
462 :rtype: dict
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
463 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
464
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
465 return self.next()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
466
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
467 def next(self):
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
469
193389d3a5f0 "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.
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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).
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
474 :rtype: dict
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
475 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
476
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "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:
193389d3a5f0 "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:]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
481 return first
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
482
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
484
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
486 try:
193389d3a5f0 "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()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
488 except StopIteration:
193389d3a5f0 "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...
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
490 raise StopIteration()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
491
193389d3a5f0 "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"]
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
495 # molecule name).
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
496
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
498 # name).
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
499 tag = " ".join(data)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
500
193389d3a5f0 "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").
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
506
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
507 new_smis = [smi]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
508 for site in sites:
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
511 # sites are handled.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
512
193389d3a5f0 "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)
193389d3a5f0 "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)
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
516
193389d3a5f0 "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.
193389d3a5f0 "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:
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
520 # new_smis.append(s)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
521
193389d3a5f0 "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.
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "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))
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
527
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "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]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
531
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
534 # ones (that are None).
193389d3a5f0 "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]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
536
193389d3a5f0 "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.
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
539 # inappropriate/mal-formed.
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
541 new_smis = [smi]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
542
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "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"]:
193389d3a5f0 "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])
193389d3a5f0 "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]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
548 else:
193389d3a5f0 "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]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
550
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
552
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
553 return self.next()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
554
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
555 class ProtSubstructFuncs:
193389d3a5f0 "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
193389d3a5f0 "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."""
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
558
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
559 @staticmethod
193389d3a5f0 "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):
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
562 likely pKa bins.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
563
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
567 consider), defaults to 1.
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
569 range.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
570 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
571
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
572 subs = []
193389d3a5f0 "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__))
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
574
193389d3a5f0 "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")
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
577 for line in substruct:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
578 line = line.strip()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
579 sub = {}
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
580 if line is not "":
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
581 splits = line.split()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
582 sub["name"] = splits[0]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
583 sub["smart"] = splits[1]
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
585
193389d3a5f0 "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
193389d3a5f0 "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)]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
588
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
589 prot = []
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
591 site = pka_range[0]
193389d3a5f0 "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
193389d3a5f0 "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])
193389d3a5f0 "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(
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
596 )
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
597
193389d3a5f0 "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])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
599
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
601 subs.append(sub)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
602 return subs
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
603
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
604 @staticmethod
193389d3a5f0 "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):
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
609
193389d3a5f0 "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.
193389d3a5f0 "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).
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
615 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
616
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
617 min_pka = mean - std
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
618 max_pka = mean + std
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
619
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
621 # next set of checks.
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
623 protonation_state = 'BOTH'
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
624 elif mean > max_ph:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
625 protonation_state = 'PROTONATED'
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
626 else:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
627 protonation_state = 'DEPROTONATED'
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
628
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
629 return protonation_state
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
630
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
631 @staticmethod
193389d3a5f0 "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):
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
636
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "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',
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
640 'BOTH', or 'DEPROTONATED')
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
641 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
642
193389d3a5f0 "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
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
645
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
646 # Check Conversion worked
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
647 if mol is None:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
648 UtilFuncs.eprint("ERROR: ", smi)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
649 return []
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
650
193389d3a5f0 "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 []
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
652 try:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
653 mol = Chem.AddHs(mol)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
654 except:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
655 UtilFuncs.eprint("ERROR: ", smi)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
656 return []
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
657
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
658 # Check adding Hs worked
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
659 if mol is None:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
660 UtilFuncs.eprint("ERROR: ", smi)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
661 return []
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
662
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
663 ProtectUnprotectFuncs.unprotect_molecule(mol)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
664 protonation_sites = []
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
665
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
666 for item in subs:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
667 smart = item["mol"]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
668 if mol.HasSubstructMatch(smart):
193389d3a5f0 "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)
193389d3a5f0 "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"]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
671 for match in matches:
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
674 for site in prot:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
675 proton = int(site[0])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
676 category = site[1]
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
678
193389d3a5f0 "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:
193389d3a5f0 "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.
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
682
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
684
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
685 return protonation_sites
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
686
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
687 @staticmethod
193389d3a5f0 "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):
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
690
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "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)
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
695 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
696
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
698 # tuple
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
700
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
701 # Initialize the output list
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
702 output_smis = []
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
703
193389d3a5f0 "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],
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
705 "PROTONATED": [0],
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
706 "BOTH": [-1, 0]}
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
707
193389d3a5f0 "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]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
709
193389d3a5f0 "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.
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
712
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
713 return output_smis
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
714
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
715 @staticmethod
193389d3a5f0 "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):
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
718
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
722 this site.
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
725 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
726
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
728 output = []
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
729
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
730 for charge in charges:
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
732 # state is positively charged).
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
733 nitro_charge = charge + 1
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
734
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "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:
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
742
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
743 for smi in smis:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
744
193389d3a5f0 "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
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
747
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
749 if mol is None:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
750 continue
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
751
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
752 atom = mol.GetAtomWithIdx(idx)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
753
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
755 element = atom.GetAtomicNum()
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
756 if element == 7:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
757 atom.SetFormalCharge(nitro_charge)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
758 else:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
759 atom.SetFormalCharge(charge)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
760
193389d3a5f0 "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
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
763 output.append(out_smile)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
764
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
765 return output
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
766
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
767 class ProtectUnprotectFuncs:
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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."""
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
771
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
772 @staticmethod
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
773 def unprotect_molecule(mol):
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
775 property for new molecules.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
776
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
779 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
780
193389d3a5f0 "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():
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
782 atom.SetProp('_protected', '0')
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
783
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
784 @staticmethod
193389d3a5f0 "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):
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
788 future.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
789
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
792 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
793
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
794 for idx in match:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
795 atom = mol.GetAtomWithIdx(idx)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
796 atom.SetProp('_protected', '1')
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
797
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
798 @staticmethod
193389d3a5f0 "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):
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
802
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
806 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
807
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
808 matches = mol.GetSubstructMatches(substruct)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
809 unprotected_matches = []
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
810 for match in matches:
193389d3a5f0 "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):
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
812 unprotected_matches.append(match)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
813 return unprotected_matches
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
814
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
815 @staticmethod
193389d3a5f0 "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):
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
818 protected atoms.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
819
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
823 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
824
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
825 for idx in match:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
826 atom = mol.GetAtomWithIdx(idx)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
827 protected = atom.GetProp("_protected")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
828 if protected == "1":
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
829 return False
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
830 return True
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
831
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
832 class TestFuncs:
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
834 keep things organized."""
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
835
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
836 @staticmethod
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
837 def test():
193389d3a5f0 "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."""
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
839
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
840 smis = [
193389d3a5f0 "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]
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"],
193389d3a5f0 "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"]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
879 ]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
880
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
881 smis_phos = [
193389d3a5f0 "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"],
193389d3a5f0 "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"]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
884 ]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
885
193389d3a5f0 "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.
193389d3a5f0 "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"]}
193389d3a5f0 "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"]}
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
889
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
890 print("Running Tests")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
891 print("=============")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
892 print("")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
893
193389d3a5f0 "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)")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
895 print("--------------------------")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
896 print("")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
897
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
898 args = {
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
899 "min_ph": -10000000,
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
900 "max_ph": -10000000,
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
901 "pka_precision": 0.5,
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
902 "smiles": "",
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
903 "label_states": True
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
904 }
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
905
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
907 args["smiles"] = smi
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
909
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
911 args["smiles"] = smi
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
913
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
914 args["min_ph"] = 10000000
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
915 args["max_ph"] = 10000000
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
916
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
917 print("")
193389d3a5f0 "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)")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
919 print("------------------------")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
920 print("")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
921
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
923 args["smiles"] = smi
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
925
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
927 args["smiles"] = smi
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
929
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
930 print("")
193389d3a5f0 "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")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
932 print("------------------")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
933 print("")
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
934
193389d3a5f0 "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:
193389d3a5f0 "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]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
937
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
938 args["smiles"] = smi
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
941
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
943
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
945 args["smiles"] = smi
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
946
193389d3a5f0 "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]
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
950
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
952
193389d3a5f0 "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]
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
956
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
958
193389d3a5f0 "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])
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
963
193389d3a5f0 "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"])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
965
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
966 @staticmethod
193389d3a5f0 "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):
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
969
193389d3a5f0 "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()
193389d3a5f0 "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.
193389d3a5f0 "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,
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
973 DEPROTONATED.
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
976 :raises Exception: Wrong labels.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
977 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
978
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
979 output = list(Protonate(args))
193389d3a5f0 "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]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
981
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
983
193389d3a5f0 "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):
193389d3a5f0 "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) + \
193389d3a5f0 "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)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
987 print(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
988 raise Exception(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
989
193389d3a5f0 "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):
193389d3a5f0 "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) + \
193389d3a5f0 "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"]) + \
193389d3a5f0 "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])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
994 print(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
995 raise Exception(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
996
193389d3a5f0 "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):
193389d3a5f0 "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) + \
193389d3a5f0 "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])
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1000 print(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1001 raise Exception(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1002
193389d3a5f0 "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"]])))
193389d3a5f0 "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) + ")"
193389d3a5f0 "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]))
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1006
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1007 def run(**kwargs):
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1013
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1016 :type kwargs: dict
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1017 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1018
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1020 main(kwargs)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1021
193389d3a5f0 "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):
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1028
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1030 :type mol_lst: list
193389d3a5f0 "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",
193389d3a5f0 "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.
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1034 :rtype: list
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1035 """
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1036
193389d3a5f0 "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.
193389d3a5f0 "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"]:
193389d3a5f0 "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:
193389d3a5f0 "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, " + \
193389d3a5f0 "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 \"" + \
193389d3a5f0 "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 " + \
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1043 "run(**kwargs) function instead?"
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1044 print(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1045 raise Exception(msg)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1046
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1048 # as a list.
193389d3a5f0 "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
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1050
193389d3a5f0 "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
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1054 protonated_smiles_and_props = []
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1056 props = m.GetPropsAsDict()
193389d3a5f0 "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)
193389d3a5f0 "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(
193389d3a5f0 "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)]
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1060 )
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1061
193389d3a5f0 "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
193389d3a5f0 "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.
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1064 mols = []
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1066 m = Chem.MolFromSmiles(s)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1067 if m:
193389d3a5f0 "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():
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1070 m.SetIntProp(prop, val)
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1072 m.SetDoubleProp(prop, val)
193389d3a5f0 "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:
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1074 m.SetBoolProp(prop, val)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1075 else:
193389d3a5f0 "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))
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1077 mols.append(m)
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1078 else:
193389d3a5f0 "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))
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1080
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1081 return mols
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1082
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1083 if __name__ == "__main__":
193389d3a5f0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 20df7e562341cd30e89a14d6bde9054956fadc06"
bgruening
parents:
diff changeset
1084 main()