view convert_pdbqt_to_sdf.py @ 7:7b2f205b3f68 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/autodock_vina commit ef86cfa5f7ab5043de420511211579d03df58645"
author bgruening
date Wed, 02 Oct 2019 12:49:30 -0400
parents 0ae768a0e5c0
children 7a871df65202
line wrap: on
line source

import pybel, openbabel
import sys


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()