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