Mercurial > repos > bgruening > autodock_vina
annotate convert_pdbqt_to_sdf.py @ 8:7a871df65202 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
author | bgruening |
---|---|
date | Tue, 28 Jul 2020 08:13:41 -0400 |
parents | 0ae768a0e5c0 |
children | 90ea16534012 |
rev | line source |
---|---|
6
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
1 import sys |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
2 |
8
7a871df65202
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
bgruening
parents:
6
diff
changeset
|
3 from openbabel import pybel, openbabel |
6
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
4 |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
5 def main(): |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
6 if len(sys.argv) == 3: |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
7 process(sys.argv[1], sys.argv[2]) |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
8 else: |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
9 print("Usage: convert_pdbqt_to_sdf.py <input-pdbqt-file> <output-sdf-file>") |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
10 exit(1) |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
11 |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
12 def add_property(mol, prop_name, prop_value): |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
13 newData = openbabel.OBPairData() |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
14 newData.SetAttribute(prop_name) |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
15 newData.SetValue(prop_value) |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
16 mol.OBMol.CloneData(newData) |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
17 |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
18 def process(input, output): |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
19 docked = pybel.readfile('pdbqt', input) |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
20 sdf = pybel.Outputfile("sdf", output, overwrite=True) |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
21 for mol in docked: |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
22 if mol.OBMol.HasData('REMARK'): |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
23 remark = mol.OBMol.GetData('REMARK').GetValue() |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
24 lines = remark.splitlines() |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
25 tokens = lines[0].split() |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
26 |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
27 # add the score property |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
28 add_property(mol, "SCORE", tokens[2]) |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
29 # add the first RMSD property |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
30 add_property(mol, "RMSD_LB", tokens[3]) |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
31 # add the second RMSD property |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
32 add_property(mol, "RMSD_UB", tokens[4]) |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
33 |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
34 sdf.write(mol) |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
35 |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
36 sdf.close() |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
37 |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
38 if __name__ == "__main__": |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
39 main() |
0ae768a0e5c0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit a2f6034a691af458e3df662e36d7f05617982bdc
bgruening
parents:
diff
changeset
|
40 |