Mercurial > repos > bgruening > openbabel_remduplicates
annotate ob_genProp.py @ 15:f3099132512d draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
| author | bgruening | 
|---|---|
| date | Thu, 15 Aug 2024 10:54:17 +0000 | 
| parents | d44de092fef3 | 
| children | 
| rev | line source | 
|---|---|
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
2 """ | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
3 Input: Molecular input file. | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
4 Output: Physico-chemical properties are computed and stored as metadata in the sdf output file. | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
5 Copyright 2012, Bjoern Gruening and Xavier Lucas | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
6 """ | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
7 import argparse | 
| 
13
 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 
bgruening 
parents: 
12 
diff
changeset
 | 
8 import sys | 
| 
 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 
bgruening 
parents: 
12 
diff
changeset
 | 
9 | 
| 
 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 
bgruening 
parents: 
12 
diff
changeset
 | 
10 import cheminfolib | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
11 import openbabel | 
| 
13
 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 
bgruening 
parents: 
12 
diff
changeset
 | 
12 from openbabel import pybel | 
| 
15
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
13 | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
14 openbabel.obErrorLog.StopLogging() | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
15 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
16 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
17 def parse_command_line(argv): | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
18 parser = argparse.ArgumentParser() | 
| 
15
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
19 parser.add_argument("--iformat", default="sdf", help="input file format") | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
20 parser.add_argument("-i", "--input", required=True, help="input file name") | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
21 parser.add_argument( | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
22 "--oformat", default="sdf", choices=["sdf", "table"], help="output file format" | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
23 ) | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
24 parser.add_argument( | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
25 "--header", | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
26 type=bool, | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
27 help="Include the header as the first line of the output table", | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
28 ) | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
29 parser.add_argument("-o", "--output", required=True, help="output file name") | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
30 return parser.parse_args() | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
31 | 
| 
13
 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 
bgruening 
parents: 
12 
diff
changeset
 | 
32 | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
33 def compute_properties(args): | 
| 
15
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
34 if args.oformat == "sdf": | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
35 outfile = pybel.Outputfile(args.oformat, args.output, overwrite=True) | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
36 else: | 
| 
15
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
37 outfile = open(args.output, "w") | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
38 if args.header: | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
39 mol = next(pybel.readfile(args.iformat, args.input)) | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
40 metadata = cheminfolib.get_properties_ext(mol) | 
| 
15
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
41 outfile.write( | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
42 "%s\n" % "\t".join([cheminfolib.ColumnNames[key] for key in metadata]) | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
43 ) | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
44 | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
45 for mol in pybel.readfile(args.iformat, args.input): | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
46 if mol.OBMol.NumHvyAtoms() > 5: | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
47 metadata = cheminfolib.get_properties_ext(mol) | 
| 
15
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
48 if args.oformat == "sdf": | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
49 [ | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
50 mol.data.update({cheminfolib.ColumnNames[key]: metadata[key]}) | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
51 for key in metadata | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
52 ] | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
53 outfile.write(mol) | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
54 else: | 
| 
15
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
55 outfile.write( | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
56 "%s\n" % ("\t".join([str(metadata[key]) for key in metadata])) | 
| 
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
57 ) | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
58 outfile.close() | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
59 | 
| 
13
 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 
bgruening 
parents: 
12 
diff
changeset
 | 
60 | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
61 def __main__(): | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
62 """ | 
| 
15
 
f3099132512d
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
 
bgruening 
parents: 
13 
diff
changeset
 | 
63 Physico-chemical properties are computed and stored as metadata in the sdf output file | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
64 """ | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
65 args = parse_command_line(sys.argv) | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
66 compute_properties(args) | 
| 
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
67 | 
| 
13
 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 
bgruening 
parents: 
12 
diff
changeset
 | 
68 | 
| 
 
d44de092fef3
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
 
bgruening 
parents: 
12 
diff
changeset
 | 
69 if __name__ == "__main__": | 
| 
0
 
112341e4fc94
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
70 __main__() | 
