view 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
line wrap: on
line source

import sys

from openbabel import pybel, openbabel

def main():
	if len(sys.argv) == 3:
		process(sys.argv[1], sys.argv[2])
	else:
		print("Usage: convert_pdbqt_to_sdf.py <input-pdbqt-file> <output-sdf-file>")
		exit(1)

def add_property(mol, prop_name, prop_value):
	newData = openbabel.OBPairData() 
	newData.SetAttribute(prop_name)
	newData.SetValue(prop_value) 
	mol.OBMol.CloneData(newData)

def process(input, output):
	docked = pybel.readfile('pdbqt', input)
	sdf = pybel.Outputfile("sdf", output, overwrite=True)
	for mol in docked:
		if mol.OBMol.HasData('REMARK'):
			remark = mol.OBMol.GetData('REMARK').GetValue()
			lines = remark.splitlines()
			tokens = lines[0].split()
		
			# add the score property
			add_property(mol, "SCORE", tokens[2]) 
			# add the first RMSD property
			add_property(mol, "RMSD_LB", tokens[3])
			# add the second RMSD property
			add_property(mol, "RMSD_UB", tokens[4])

		sdf.write(mol)

	sdf.close()

if __name__ == "__main__":
    main()