annotate convert_pdbqt_to_sdf.py @ 9:90ea16534012 draft default tip

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