Mercurial > repos > bgruening > openbabel_remove_protonation_state
annotate ob_addh.py @ 8:fe39528c032e draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 72df8ae9b8fd9910b3d24aa0836b9b3c9d43f4fb
| author | bgruening | 
|---|---|
| date | Fri, 10 May 2019 07:41:53 -0400 | 
| parents | 6f511affb852 | 
| children | e946a539ddf7 | 
| rev | line source | 
|---|---|
| 
0
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
2 """ | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
3 Input: Molecule file | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
4 Output: Molecule file with hydrogen atoms added at the target pH. | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
5 """ | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
6 import sys, os | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
7 import argparse | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
8 import openbabel | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
9 openbabel.obErrorLog.StopLogging() | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
10 import pybel | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
11 | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
12 def parse_command_line(argv): | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
13 parser = argparse.ArgumentParser() | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
14 parser.add_argument('--iformat', type=str, default='sdf' , help='input file format') | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
15 parser.add_argument('-i', '--input', type=str, required=True, help='input file name') | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
16 parser.add_argument('-o', '--output', type=str, required=True, help='output file name') | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
17 parser.add_argument('--polar', action="store_true", default=False, help='Add hydrogen atoms only to polar atoms') | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
18 parser.add_argument('--pH', type=float, default="7.4", help='Specify target pH value') | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
19 return parser.parse_args() | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
20 | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
21 def addh(args): | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
22 outfile = pybel.Outputfile(args.iformat, args.output, overwrite=True) | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
23 for mol in pybel.readfile(args.iformat, args.input): | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
24 if mol.OBMol.NumHvyAtoms() > 5: | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
25 mol.removeh() | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
26 mol.OBMol.AddHydrogens(args.polar, True, args.pH) | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
27 outfile.write(mol) | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
28 outfile.close() | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
29 | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
30 def __main__(): | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
31 """ | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
32 Add hydrogen atoms at a certain pH value | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
33 """ | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
34 args = parse_command_line(sys.argv) | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
35 addh(args) | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
36 | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
37 if __name__ == "__main__" : | 
| 
 
6f511affb852
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
38 __main__() | 
