##
##
## sarchitect designer 2.2 script to pick 2-D descriptors from 
## a dataset that contains the full set of descriptors and
## carry them into a child-datased labelled as "2D-descriptors"
## 
## Note - "Marked" columns are also carried on into the child-dataset.
##         This script doesn't control that.
##
##
## Author: Shaillay Kumar Dogra
## Date: July 06, 2007
## editor@qsarworld.com
##
##
## There could be various ways of picking 2D descriptors, like:
##
## a) based on names; will have to type out all the 444 2-D descriptor names and 
##  handle exceptions if some not found (say, some subset was not computed by ticking it off)
##
## b) look for first 2D descriptor ("numAtoms"), find its index; find index of last
## 2D descriptor ("Lop") and thus get handle of all the 2D descriptor indices assuming them to 
## be in b/w these two - "numAtoms" & "Lop"
##
## (ticking on/off the options that compute "numAtoms" & "Lop" will stop the script)
##
## Implementing latter option(b) in this script
## 
## Will give an error message if start-point ('numAtoms') and/or stop-point ('Lop') 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('numAtoms')
startindex = dataset.index(startcol)
#print startcol, startindex
if (startindex == -1):   # Happens if 'numAtoms' not found
	parent=script.tool.getTool().getFrame()
	mesg = "Start point 'numAtoms' not found!"
	JOptionPane.showMessageDialog(parent,mesg,"STATUS!",JOptionPane.INFORMATION_MESSAGE)


stopcol = dataset.getColumn('Lop')
stopindex = dataset.index(stopcol)
#print stopcol, stopindex
if (stopindex == -1):    # Happens if 'Lop' not found
	parent=script.tool.getTool().getFrame()
	mesg = "Stop point 'Lop' not found!"
	JOptionPane.showMessageDialog(parent,mesg,"STATUS!",JOptionPane.INFORMATION_MESSAGE)


colindex = [ ]

i = startindex
if (startindex != -1 and stopindex != -1): # Happens if start-point "numAtoms" and stop-point "Lop" 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 "numAtoms" and stop-point "Lop" was not found
	node.addChildDatasetNode("2D-Descriptors", rowIndices, colIndices)
	script.view.Table(rowHeight=80).show()
else:	
	parent=script.tool.getTool().getFrame()
	mesg = "No child-dataset created!"
	JOptionPane.showMessageDialog(parent,mesg,"STATUS!",JOptionPane.INFORMATION_MESSAGE)

##
## END
##

