##
##
## sarchitect designer 2.2 script to get MACCS Keys (length 166) in individual columns
##
## INPUT: 'Molecule'/'Structure'/'Optimized Structures' column; 
##         this would be used by backend to compute MACCS Keys (166 bit-length) 
##
## 	  'Identifier' column for some formatted table-view
##
## 
## OUTPUT: MACCS Keys in a (total_rows X 166_column) table view.
##
##
## Shaillay Kumar Dogra
## Feb 20, 2007
##
##

from script.omega import createComponent, showDialog
from javax.swing import *

dataset = script.project.getActiveDataset()

strCol = dataset.getColumn('Structure') ## change this according to your data
id_col = dataset.getColumn('Identifier') ## change this according to your data

result = script.algorithm.ComputeMACCSKey(structure=strCol).execute(displayResult=0)
keys = result['maccskeymatrix']
#print keys[0]

rows = [ ]
for colIdx in range(len(keys[0])):
	col = [ ]
	for rowIdx in range(len(keys)):
		val = keys[rowIdx][colIdx]
		col.append(val)
	#print col
	new_col = script.dataset.createIntColumn("Key" + str([colIdx+1]), col)
	rows.append(new_col)

## end of for loop


## create dataset, launch view
tmpset = script.dataset.createDataset("Keys", [id_col])
for i in range(len(rows)):
	tmpset.addColumn(rows[i])

view = script.view.Table(dataset=tmpset,rowHeight=20)
view.__state__['enableExportColumns'] = 1
view.show()


## report completion
parent=script.tool.getTool().getFrame()
mesg = "Done With Script Execution."
JOptionPane.showMessageDialog(parent,mesg,"STATUS!",JOptionPane.INFORMATION_MESSAGE)


##
## END
##