##
##
## sarchitect designer 2.2 script to pick 3-D descriptors from a dataset and
## carry them into a child-datased labelled as "3D-descriptors"
##
## 
## Author: Shaillay Kumar Dogra
## Date: July 06, 2007
## editor@qsarworld.com
##
##
## Note - "Marked" columns are carried into the child-dataset.
##         This script doesn't control that.
##
##
## There could be various ways of picking descriptors:
##
## a) based on names; will have to type out all the 3-D descriptor names and 
##  handle exceptions if some not found (some subset not computed by ticking it off)
##
## b) look for first 3D descriptor ("DP01"), find its index; find index of last
## 3D descriptor ("Electro") and thus get handle of all 3D descriptor indices assuming them to 
## be in b/w these two - "DP01" & "Electro"
##
##
## Implementing latter option-b in this script
## 
## Will give an error message if start-point ('DP01') and/or stop-point ('Electro') is not found.
## Will not create a child dataset in such cases and give a message to that effect.
##
##
##


import script
from script.dataset import *
from script.algorithm import *
from script.project import *
from script.omega import createComponent, showDialog
from javax.swing import *
from math import *

node = getActiveProject().getActiveDatasetNode()
dataset = node.getDataset()

startcol = dataset.getColumn('DP01')
startindex = dataset.index(startcol)
#print startcol, startindex
if (startindex == -1):   # Happens if 'DP01' not found
	parent=script.tool.getTool().getFrame()
	mesg = "Start point 'DP01' not found!"
	JOptionPane.showMessageDialog(parent,mesg,"STATUS!",JOptionPane.INFORMATION_MESSAGE)


stopcol = dataset.getColumn('Electro')
stopindex = dataset.index(stopcol)
#print stopcol, stopindex
if (stopindex == -1):    # Happens if 'Electro' not found
	parent=script.tool.getTool().getFrame()
	mesg = "Stop point 'Electro' not found!"
	JOptionPane.showMessageDialog(parent,mesg,"STATUS!",JOptionPane.INFORMATION_MESSAGE)


colindex = [ ]

i = startindex
if (startindex != -1 and stopindex != -1): # Happens if start-point "DP01" and stop-point "Electro" was not found
	while i < (stopindex+1):
		colindex.append(i)
		i = i + 1


rowIndices=[i for i in range(dataset.getRowCount())]
colIndices= colindex
if (startindex != -1 and stopindex != -1): # Happens if start-point "DP01" and stop-point "Electro" was not found
	node.addChildDatasetNode("3D-Descriptors", rowIndices, colIndices)
	script.view.Table().show()
else:	
	parent=script.tool.getTool().getFrame()
	mesg = "No child-dataset created!"
	JOptionPane.showMessageDialog(parent,mesg,"STATUS!",JOptionPane.INFORMATION_MESSAGE)


##
## END
##
