Esempio n. 1
0
 def _addAtomTypesGroupBox(self, inPmGroupBox):
     """
     Creates a row of atom type buttons (i.e. sp3, sp2, sp and graphitic).
     
     @param inPmGroupBox: The parent group box to contain the atom type 
                          buttons.
     @type  inPmGroupBox: PM_GroupBox
     """
     self._atomTypesButtonGroup = \
         PM_ToolButtonGrid( inPmGroupBox, 
                            buttonList = self.getAtomTypesButtonList(),
                            label      = "Atomic hybrids:",
                            checkedId  = 0,
                            setAsDefault = True )
     #Increase the button width for atom hybrids so that 
     # button texts such as sp3(p), sp2(-), sp2(-.5) fit. 
     # This change can be removed once we have icons 
     # for the buttons with long text -- Ninad 2008-09-04
     self._atomTypesButtonGroup.setButtonSize(width = 44)
     
     # Horizontal spacer to keep buttons grouped close together.
     _hSpacer = QSpacerItem( 1, 32, 
                             QSizePolicy.Expanding, 
                             QSizePolicy.Fixed )
     
     self._atomTypesButtonGroup.gridLayout.addItem( _hSpacer, 0, 4, 1, 1 )
     
     
     
     self.connect( self._atomTypesButtonGroup.buttonGroup, 
                   SIGNAL("buttonClicked(int)"), 
                   self._setAtomType )
     
     self._updateAtomTypesButtons()
 def _addAtomTypesGroupBox(self, inPmGroupBox):
     """
     Creates a row of atom type buttons (i.e. sp3, sp2, sp and graphitic).
     
     @param inPmGroupBox: The parent group box to contain the atom type 
                          buttons.
     @type  inPmGroupBox: PM_GroupBox
     """
     self._atomTypesButtonGroup = \
         PM_ToolButtonGrid( inPmGroupBox, 
                            buttonList = self.getAtomTypesButtonList(),
                            label      = "Atomic hybrids:",
                            checkedId  = 0,
                            setAsDefault = True )
     
     # Horizontal spacer to keep buttons grouped close together.
     _hSpacer = QSpacerItem( 1, 32, 
                             QSizePolicy.Expanding, 
                             QSizePolicy.Fixed )
     
     self._atomTypesButtonGroup.gridLayout.addItem( _hSpacer, 0, 4, 1, 1 )
     
     self.connect( self._atomTypesButtonGroup.buttonGroup, 
                   SIGNAL("buttonClicked(int)"), 
                   self._setAtomType )
     
     self._updateAtomTypesButtons()
    def _addElementsGroupBox(self, inPmGroupBox):
        """
        Creates a grid of tool buttons containing all elements supported
        in NE1.

        @param inPmGroupBox: The parent group box to contain the element
                             buttons.
        @type  inPmGroupBox: PM_GroupBox
        """

        self._elementsButtonGroup = \
            PM_ToolButtonGrid( inPmGroupBox,
                               title        = "",
                               buttonList   = self.getElementsButtonList(),
                               checkedId    = self.element.eltnum,
                               setAsDefault = True
                               )

        self.connect(self._elementsButtonGroup.buttonGroup,
                     SIGNAL("buttonClicked(int)"), self.setElement)
Esempio n. 4
0
    def _addAtomTypesGroupBox(self, inPmGroupBox):
        """
        Creates a row of atom type buttons (i.e. sp3, sp2, sp and graphitic).
        
        @param inPmGroupBox: The parent group box to contain the atom type 
                             buttons.
        @type  inPmGroupBox: PM_GroupBox
        """
        self._atomTypesButtonGroup = \
            PM_ToolButtonGrid( inPmGroupBox,
                               buttonList = self.getAtomTypesButtonList(),
                               label      = "Atomic hybrids:",
                               checkedId  = 0,
                               setAsDefault = True )

        # Horizontal spacer to keep buttons grouped close together.
        _hSpacer = QSpacerItem(1, 32, QSizePolicy.Expanding, QSizePolicy.Fixed)

        self._atomTypesButtonGroup.gridLayout.addItem(_hSpacer, 0, 4, 1, 1)

        self.connect(self._atomTypesButtonGroup.buttonGroup,
                     SIGNAL("buttonClicked(int)"), self._setAtomType)

        self._updateAtomTypesButtons()
    def _addElementsGroupBox(self, inPmGroupBox):
        """
        Creates a grid of tool buttons containing all elements supported
        in NE1.

        @param inPmGroupBox: The parent group box to contain the element
                             buttons.
        @type  inPmGroupBox: PM_GroupBox
        """

        self._elementsButtonGroup = \
            PM_ToolButtonGrid( inPmGroupBox,
                               title        = "",
                               buttonList   = self.getElementsButtonList(),
                               checkedId    = self.element.eltnum,
                               setAsDefault = True
                               )

        self.connect( self._elementsButtonGroup.buttonGroup,
                      SIGNAL("buttonClicked(int)"),
                      self.setElement )
Esempio n. 6
0
 def __init__(self, 
              parentWidget, 
              title        = '',
              buttonList   = [],
              alignment    = None,
              label        = '',
              labelColumn  = 0,
              spanWidth    = False,
              checkedId    = -1, 
              setAsDefault = False,
              isAutoRaise  = True,
              isCheckable  = True
              ):
     """
     Appends a PM_ToolButtonRow widget to the bottom of I{parentWidget}, 
     the Property Manager dialog or group box.
     
     @param parentWidget: The parent group box containing this widget.
     @type  parentWidget: PM_GroupBox
     
     @param title: The group box title.
     @type  title: str
     
     @param buttonList: A list of I{button info lists}. There is one button
                        info list for each button in the grid. The button
                        info list contains the following items:
                        (notice that this list doesn't contain the 'row' 
                        which is seen in B{PM_ToolButtonGrid}.)
                         1. Button Type - in this case its 'ToolButton'(str),
                         2. Button Id (int), 
                         3. Button text (str),
                         4. Button icon path (str),
                         5. Button tool tip (str),
                         6. Column (int).        
     @type  buttonList: list
     
     @param alignment:  The alignment of the toolbutton row in the parent 
                        groupbox. Based on its value,spacer items is added 
                        to the grid layout of the parent groupbox. 
     @type  alignment:  str
     
     @param label:      The label for the toolbutton row. If present, it is 
                        added to the same grid layout as the rest of the 
                        toolbuttons, in column number E{0}.
     @type  label:      str
     
     @param labelColumn: The column in the parentWidget's grid layout to which
                         this widget's label will be added. The labelColum
                         can only be E{0} or E{1}
     @type  labelColumn: int
     
     @param spanWidth: If True, the widget and its label will span the width
                   of the group box. Its label will appear directly above
                   the widget (unless the label is empty) and is left justified.
     @type  spanWidth: bool (default False)
     
     @param checkedId:  Checked button id in the button group. Default value
                        is -1 that implies no button is checked. 
     @type  checkedId:  int
     
     @param setAsDefault: If True, sets the I{checkedId} specified by the
                         user as the  default checked
     @type  setAsDefault: boolean
          
     """     
     
     PM_ToolButtonGrid.__init__(self, 
                                parentWidget, 
                                title,
                                buttonList,
                                alignment,
                                label,
                                labelColumn,
                                spanWidth,
                                checkedId,
                                setAsDefault,
                                isAutoRaise,
                                isCheckable)
Esempio n. 7
0
    def __init__(self,
                 parentWidget,
                 title='',
                 buttonList=[],
                 alignment=None,
                 label='',
                 labelColumn=0,
                 spanWidth=False,
                 checkedId=-1,
                 setAsDefault=False,
                 isAutoRaise=True,
                 isCheckable=True):
        """
        Appends a PM_ToolButtonRow widget to the bottom of I{parentWidget}, 
        the Property Manager dialog or group box.
        
        @param parentWidget: The parent group box containing this widget.
        @type  parentWidget: PM_GroupBox
        
        @param title: The group box title.
        @type  title: str
        
        @param buttonList: A list of I{button info lists}. There is one button
                           info list for each button in the grid. The button
                           info list contains the following items:
                           (notice that this list doesn't contain the 'row' 
                           which is seen in B{PM_ToolButtonGrid}.)
                            1. Button Type - in this case its 'ToolButton'(str),
                            2. Button Id (int), 
                            3. Button text (str),
                            4. Button icon path (str),
                            5. Button tool tip (str),
                            6. Column (int).        
        @type  buttonList: list
        
        @param alignment:  The alignment of the toolbutton row in the parent 
                           groupbox. Based on its value,spacer items is added 
                           to the grid layout of the parent groupbox. 
        @type  alignment:  str
        
        @param label:      The label for the toolbutton row. If present, it is 
                           added to the same grid layout as the rest of the 
                           toolbuttons, in column number E{0}.
        @type  label:      str
        
        @param labelColumn: The column in the parentWidget's grid layout to which
                            this widget's label will be added. The labelColum
                            can only be E{0} or E{1}
        @type  labelColumn: int
        
        @param spanWidth: If True, the widget and its label will span the width
                      of the group box. Its label will appear directly above
                      the widget (unless the label is empty) and is left justified.
        @type  spanWidth: bool (default False)
        
        @param checkedId:  Checked button id in the button group. Default value
                           is -1 that implies no button is checked. 
        @type  checkedId:  int
        
        @param setAsDefault: If True, sets the I{checkedId} specified by the
                            user as the  default checked
        @type  setAsDefault: boolean
             
        """

        PM_ToolButtonGrid.__init__(self, parentWidget, title, buttonList,
                                   alignment, label, labelColumn, spanWidth,
                                   checkedId, setAsDefault, isAutoRaise,
                                   isCheckable)
Esempio n. 8
0
 def _addGroupBoxes(self):
     """
     Add group boxes to the Property Manager.
     """
                     
     self.widgetSelectorGroupBox = PM_GroupBox(self, title = "PM Widget Selector" )
     self._loadWidgetSelectorGroupBox(self.widgetSelectorGroupBox)
     
     self.groupBoxes = []
     
     pmGroupBox = PM_GroupBox(self, title = "PM_CheckBox")
     self._loadPM_CheckBox(pmGroupBox)
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox = PM_GroupBox(self, title = "PM_ComboBox")
     self._loadPM_ComboBox(pmGroupBox)
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox = PM_GroupBox(self, title = "PM_DoubleSpinBox")
     self._loadPM_DoubleSpinBox(pmGroupBox)
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox =  PM_ElementChooser(self, title = "PM_ElementChooser")
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox = PM_GroupBox(self, title = "PM_LineEdit")
     self._loadPM_LineEdit(pmGroupBox)
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox = PM_GroupBox(self, title = "PM_ListWidget")
     self._loadPM_ListWidget(pmGroupBox)
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox = PM_GroupBox(self, title = "PM_PushButton")
     self._loadPM_PushButton(pmGroupBox)
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox = PM_GroupBox(self, title = "PM_RadioButton")
     self._loadPM_TextEdit(pmGroupBox)
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox = PM_RadioButtonList( self,
                                      title      = "PM_RadioButtonList", 
                                      buttonList = OPTIONS_BUTTON_LIST,
                                      checkedId  = 2 )
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox = PM_GroupBox(self, title = "PM_SpinBox")
     self._loadPM_SpinBox(pmGroupBox)
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox = PM_GroupBox(self, title = "PM_TextEdit")
     self._loadPM_TextEdit(pmGroupBox)
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox = PM_GroupBox(self, title = "PM_ToolButton")
     self._loadPM_ToolButton(pmGroupBox)
     self.groupBoxes.append(pmGroupBox)
     
     pmGroupBox = PM_ToolButtonGrid( self, 
                                     title        = "PM_ToolButtonGrid",
                                     buttonList   = TOOL_BUTTON_LIST,
                                     checkedId    = 6,
                                     setAsDefault = True )
     self.groupBoxes.append(pmGroupBox)
     
     self.widgetSelectorComboBox.clear()
     titles = self._getGroupBoxTitles()
     self.widgetSelectorComboBox.addItems(titles)
     
     self._updateGroupBoxes(0)
Esempio n. 9
0
class PM_ElementChooser(PM_MolecularModelingKit):
    """
    The PM_ElementChooser widget provides an Element Chooser widget,
    contained in its own group box, for a Property Manager dialog.
    
    A PM_ElementChooser is a selection widget that displays all elements, 
    including their atom types (atomic hybrids), supported in NE1. Methods
    are provided to set and get the selected element and atom type
    (e.g., L{setElement()}, L{getElement()}, L{getElementNumber()} and
    L{getElementSymbolAndAtomType()}).
    
    @cvar element: The current element.
    @type element: Elem
    
    @cvar atomType: The current atom type of the current element.
    @type atomType: str
    
    @see: B{elements.py}
    """
    def __init__(self,
                 parentWidget,
                 parentPropMgr=None,
                 title="",
                 element="Carbon",
                 elementViewer=None):
        """
        Appends a PM_ElementChooser widget to the bottom of I{parentWidget}, 
        a Property Manager dialog. (or as a sub groupbox for Atom Chooser 
        GroupBox.)
        
        @param parentWidget: The parent PM_Dialog or PM_groupBox containing this
                             widget.
        @type  parentWidget: PM_Dialog or PM_GroupBox
        
        @param parentPropMgr: The parent Property Manager 
        @type  parentPropMgr: PM_Dialog or None
        
        @param title: The button title on the group box containing the
                      Element Chooser.
        @type  title: str
        
        @param element: The initially selected element. It can be either an
                        element symbol or name.
        @type  element: str
        """

        PM_MolecularModelingKit.__init__(self, parentWidget, parentPropMgr,
                                         title, element, elementViewer)

    def _addGroupBoxes(self):
        """
        Add various groupboxes present inside the ElementChooser groupbox
        """
        self._addElementsGroupBox(self)
        self._addAtomTypesGroupBox(self)

    def _addAtomTypesGroupBox(self, inPmGroupBox):
        """
        Creates a row of atom type buttons (i.e. sp3, sp2, sp and graphitic).
        
        @param inPmGroupBox: The parent group box to contain the atom type 
                             buttons.
        @type  inPmGroupBox: PM_GroupBox
        """
        self._atomTypesButtonGroup = \
            PM_ToolButtonGrid( inPmGroupBox,
                               buttonList = self.getAtomTypesButtonList(),
                               label      = "Atomic hybrids:",
                               checkedId  = 0,
                               setAsDefault = True )

        # Horizontal spacer to keep buttons grouped close together.
        _hSpacer = QSpacerItem(1, 32, QSizePolicy.Expanding, QSizePolicy.Fixed)

        self._atomTypesButtonGroup.gridLayout.addItem(_hSpacer, 0, 4, 1, 1)

        self.connect(self._atomTypesButtonGroup.buttonGroup,
                     SIGNAL("buttonClicked(int)"), self._setAtomType)

        self._updateAtomTypesButtons()

    def _updateAtomTypesButtons(self):
        """
        Updates the hybrid buttons based on the currently selected 
        element button.
        """
        currentElementNumber = self.getElementNumber()

        if ELEMENT_ATOM_TYPES.has_key(currentElementNumber):
            elementAtomTypes = ELEMENT_ATOM_TYPES[currentElementNumber]
        else:
            # Selected element has no hybrids.
            elementAtomTypes = []
            self.atomType = ""

        for atomType in ATOM_TYPES:
            button = self._atomTypesButtonGroup.getButtonByText(atomType)
            if atomType in elementAtomTypes:
                button.show()
                if atomType == elementAtomTypes[0]:
                    # Select the first atomType button.
                    button.setChecked(True)
                    self.atomType = atomType
            else:
                button.hide()

        self._updateAtomTypesTitle()

    def _updateAtomTypesTitle(self):
        """
        Updates the title for the Atom Types group box.
        """
        title = "Atomic Hybrids for " + self.element.name + ":"
        self._atomTypesButtonGroup.setTitle(title)

    def _setAtomType(self, atomTypeIndex):
        """
        Set the current atom type.
        
        @param atomTypeIndex: The atom type index, where:
                              0 = sp3,
                              1 = sp2,
                              2 = sp,
                              3 = sp2(graphitic)
        @type  atomTypeIndex: int
        
        @note: Calling this method does not update the atom type buttons.
        """
        self.atomType = ATOM_TYPES[atomTypeIndex]
        self.updateElementViewer()

    def getElementsButtonList(self):
        """
        Return the list of buttons in the Element chooser.
        @return: List containing information about the element tool buttons
        @rtype:  list
        """
        return ELEMENTS_BUTTON_LIST

    def getAtomTypesButtonList(self):
        """
        Return the list of buttons for the various atom types (hybrids) of the 
        selected atom in the    Element  chooser.
        @return: List containing information about the toolbuttons for 
                 the atom types (hybrids) of the selected atom  in the element
                 chooser.
        @rtype:  list 
        
        """
        return ATOM_TYPES_BUTTON_LIST
    def _loadGroupBox1(self, inPmGroupBox):
        """
        Load widgets in the group box.
        """

        memberChoices = [
            "Custom", "Alpha helix", "Beta strand", "Pi helix", "3_10 helix",
            "Polyproline-II helix", "Fully extended"
        ]

        self.aaTypeComboBox= \
            PM_ComboBox( inPmGroupBox,
                         label        = "Conformation:",
                         choices      = memberChoices,
                         index        = 1,
                         setAsDefault = True,
                         spanWidth    = False )

        self.connect(self.aaTypeComboBox, SIGNAL("currentIndexChanged(int)"),
                     self._aaTypeChanged)

        self.phiAngleField = \
            PM_DoubleSpinBox( inPmGroupBox,
                              label        = "Phi angle:",
                              value        = self.phi,
                              setAsDefault = True,
                              minimum      = -180.0,
                              maximum      = 180.0,
                              singleStep   = 1.0,
                              decimals     = 1,
                              suffix       = " degrees")

        self.connect(self.phiAngleField, SIGNAL("valueChanged(double)"),
                     self._aaPhiAngleChanged)

        self.phiAngleField.setEnabled(False)

        self.psiAngleField = \
            PM_DoubleSpinBox( inPmGroupBox,
                              label        = "Psi angle:",
                              value        = self.psi,
                              setAsDefault = True,
                              minimum      = -180.0,
                              maximum      = 180.0,
                              singleStep   = 1.0,
                              decimals     = 1,
                              suffix       = " degrees" )

        self.connect(self.psiAngleField, SIGNAL("valueChanged(double)"),
                     self._aaPsiAngleChanged)

        self.psiAngleField.setEnabled(False)

        self.aaTypesButtonGroup = \
            PM_ToolButtonGrid( inPmGroupBox,
                               buttonList   = AA_BUTTON_LIST,
                               label        = "Amino acids",
                               checkedId    = self.current_amino_acid, # Glycine
                               setAsDefault = True )

        self.connect(self.aaTypesButtonGroup.buttonGroup,
                     SIGNAL("buttonClicked(int)"), self._setAminoAcidType)
        return
class PM_MolecularModelingKit(PM_GroupBox):
    """
    The PM_MolecularModelingKit widget provides an Atom Chooser widget,
    contained in its own group box, for a Property Manager dialog. (see
    subclasses for details)

    A PM_MolecularModelingKit is a selection widget that displays all elements,
    pseudo-atoms supported in NE1.

    @cvar element: The current element.
    @type element: Elem

    @cvar atomType: The current atom type of the current element.
    @type atomType: str

    @see: B{elements.py}
    @see: B{PM.PM_ElementChooser}
    """

    element = None
    atomType = ""
    _periodicTable = PeriodicTable
    viewerDisplay = diTUBES

    def __init__(
        self,
        parentWidget,
        parentPropMgr=None,
        title="Molecular Modeling Kit",
        element="",
        elementViewer=None,
    ):
        """
        Appends a AtomChooser widget (see subclasses) to the bottom of
        I{parentWidget}, a Property Manager dialog.
        (or as a sub groupbox for Atom Chooser  GroupBox.)

        @param parentWidget: The parent PM_Dialog or PM_groupBox containing this
                             widget.
        @type  parentWidget: PM_Dialog or PM_GroupBox

        @param parentPropMgr: The parent Property Manager
        @type  parentPropMgr: PM_Dialog or None

        @param title: The button title on the group box containing the
                      Element Chooser.
        @type  title: str

        @param element: The initially selected element. It can be either an
                        element symbol or name.
        @type  element: str
        """

        PM_GroupBox.__init__(self, parentWidget, title)

        self.element = self._periodicTable.getElement(element)
        self.elementViewer = elementViewer
        self.updateElementViewer()

        if parentPropMgr:
            self.parentPropMgr = parentPropMgr
        else:
            self.parentPropMgr = parentWidget

        self._addGroupBoxes()
        self.connect_or_disconnect_signals(True)

    def _addGroupBoxes(self):
        """
        Subclasses should add various groupboxes present inside the Atom chooser
        groupbox.

        AbstractMethod
        """
        raise AbstractMethod()

    def _addElementsGroupBox(self, inPmGroupBox):
        """
        Creates a grid of tool buttons containing all elements supported
        in NE1.

        @param inPmGroupBox: The parent group box to contain the element
                             buttons.
        @type  inPmGroupBox: PM_GroupBox
        """

        self._elementsButtonGroup = \
            PM_ToolButtonGrid( inPmGroupBox,
                               title        = "",
                               buttonList   = self.getElementsButtonList(),
                               checkedId    = self.element.eltnum,
                               setAsDefault = True
                               )

        self.connect(self._elementsButtonGroup.buttonGroup,
                     SIGNAL("buttonClicked(int)"), self.setElement)

    def _updateAtomTypesButtons(self):
        """
        Updates the hybrid buttons based on the currently selected
        element button.
        Subclasses should override this method
        """
        pass

    def restoreDefault(self):
        """
        Restores the default checked (selected) element and atom type buttons.
        """
        PM_GroupBox.restoreDefault(self)
        self._updateAtomTypesButtons()
        return

    def getElementNumber(self):
        """
        Returns the element number of the currently selected element.

        @return: Selected element number
        @rtype:  int
        """
        return self._elementsButtonGroup.checkedId()

    def getElementSymbolAndAtomType(self):
        """
        Returns the symbol and atom type of the currently selected element.

        @return: element symbol, atom type
        @rtype:  str, str
        """
        currentElementNumber = self.getElementNumber()
        element = self._periodicTable.getElement(currentElementNumber)
        return element.symbol, self.atomType

    def getElement(self):
        """
        Get the current element.

        @return: element
        @rtype:  Elem

        @see: B{element.py}
        """
        return self.element

    def setElement(self, elementNumber):
        """
        Set the current element in the MMKit to I{elementNumber}.

        @param elementNumber: Element number. (i.e. 6 = carbon)
        @type  elementNumber: int
        """
        self.element = self._periodicTable.getElement(elementNumber)
        self._updateAtomTypesButtons()
        self.updateElementViewer()
        self._updateParentPropMgr()
        return

    def updateElementViewer(self):
        """
        Update the view in the element viewer (if present)
        """
        if not self.elementViewer:
            return

        from graphics.widgets.ThumbView import MMKitView
        assert isinstance(self.elementViewer, MMKitView)
        self.elementViewer.resetView()
        self.elementViewer.changeHybridType(self.atomType)
        self.elementViewer.refreshDisplay(self.element, self.viewerDisplay)
        return

    def _updateParentPropMgr(self):
        """
        Update things in the parentWidget if necessary.
        (The parentWidget should be a property manager, although not necessary)
        Example: In Build Atoms Mode, the Property manager message groupbox
        needs to be updated if the element is changed in the element chooser.
        Similarly, the selection filter list should be updated in this mode.
        """

        parentPropMgrClass = self.parentPropMgr.__class__

        if hasattr(parentPropMgrClass, 'updateMessage'):
            try:
                self.parentPropMgr.updateMessage()
            except AttributeError:
                print_compact_traceback("Error calling updateMessage()")

        if hasattr(parentPropMgrClass, 'update_selection_filter_list'):
            try:
                self.parentPropMgr.update_selection_filter_list()
            except AttributeError:
                msg = "Error calling update_selection_filter_list()"
                print_compact_traceback(msg)

    def connect_or_disconnect_signals(self, isConnect):
        """
        Connect or disconnect widget signals sent to their slot methods.
        @param isConnect: If True the widget will send the signals to the slot
                          method.
        @type  isConnect: boolean
        """
        #Not implemented yet
        return

    def getElementsButtonList(self):
        """
        Subclasses should override this and return the list of buttons in the
        Atom chooser.
        """
        raise AbstractMethod()
class PM_MolecularModelingKit( PM_GroupBox ):
    """
    The PM_MolecularModelingKit widget provides an Atom Chooser widget,
    contained in its own group box, for a Property Manager dialog. (see
    subclasses for details)

    A PM_MolecularModelingKit is a selection widget that displays all elements,
    pseudo-atoms supported in NE1.

    @cvar element: The current element.
    @type element: Elem

    @cvar atomType: The current atom type of the current element.
    @type atomType: str

    @see: B{elements.py}
    @see: B{PM.PM_ElementChooser}
    """

    element        = None
    atomType       = ""
    _periodicTable = PeriodicTable
    viewerDisplay = diTUBES

    def __init__(self,
                 parentWidget,
                 parentPropMgr   = None,
                 title           = "Molecular Modeling Kit",
                 element         = "",
                 elementViewer   =  None,
                 ):
        """
        Appends a AtomChooser widget (see subclasses) to the bottom of
        I{parentWidget}, a Property Manager dialog.
        (or as a sub groupbox for Atom Chooser  GroupBox.)

        @param parentWidget: The parent PM_Dialog or PM_groupBox containing this
                             widget.
        @type  parentWidget: PM_Dialog or PM_GroupBox

        @param parentPropMgr: The parent Property Manager
        @type  parentPropMgr: PM_Dialog or None

        @param title: The button title on the group box containing the
                      Element Chooser.
        @type  title: str

        @param element: The initially selected element. It can be either an
                        element symbol or name.
        @type  element: str
        """

        PM_GroupBox.__init__(self, parentWidget, title)

        self.element = self._periodicTable.getElement(element)
        self.elementViewer = elementViewer
        self.updateElementViewer()

        if parentPropMgr:
            self.parentPropMgr = parentPropMgr
        else:
            self.parentPropMgr = parentWidget

        self._addGroupBoxes()
        self.connect_or_disconnect_signals(True)

    def _addGroupBoxes(self):
        """
        Subclasses should add various groupboxes present inside the Atom chooser
        groupbox.

        AbstractMethod
        """
        raise AbstractMethod()

    def _addElementsGroupBox(self, inPmGroupBox):
        """
        Creates a grid of tool buttons containing all elements supported
        in NE1.

        @param inPmGroupBox: The parent group box to contain the element
                             buttons.
        @type  inPmGroupBox: PM_GroupBox
        """

        self._elementsButtonGroup = \
            PM_ToolButtonGrid( inPmGroupBox,
                               title        = "",
                               buttonList   = self.getElementsButtonList(),
                               checkedId    = self.element.eltnum,
                               setAsDefault = True
                               )

        self.connect( self._elementsButtonGroup.buttonGroup,
                      SIGNAL("buttonClicked(int)"),
                      self.setElement )


    def _updateAtomTypesButtons(self):
        """
        Updates the hybrid buttons based on the currently selected
        element button.
        Subclasses should override this method
        """
        pass


    def restoreDefault(self):
        """
        Restores the default checked (selected) element and atom type buttons.
        """
        PM_GroupBox.restoreDefault(self)
        self._updateAtomTypesButtons()
        return

    def getElementNumber(self):
        """
        Returns the element number of the currently selected element.

        @return: Selected element number
        @rtype:  int
        """
        return self._elementsButtonGroup.checkedId()

    def getElementSymbolAndAtomType(self):
        """
        Returns the symbol and atom type of the currently selected element.

        @return: element symbol, atom type
        @rtype:  str, str
        """
        currentElementNumber = self.getElementNumber()
        element = self._periodicTable.getElement(currentElementNumber)
        return element.symbol, self.atomType

    def getElement(self):
        """
        Get the current element.

        @return: element
        @rtype:  Elem

        @see: B{element.py}
        """
        return self.element

    def setElement(self, elementNumber):
        """
        Set the current element in the MMKit to I{elementNumber}.

        @param elementNumber: Element number. (i.e. 6 = carbon)
        @type  elementNumber: int
        """
        self.element = self._periodicTable.getElement(elementNumber)
        self._updateAtomTypesButtons()
        self.updateElementViewer()
        self._updateParentPropMgr()
        return

    def updateElementViewer(self):
        """
        Update the view in the element viewer (if present)
        """
        if not self.elementViewer:
            return

        from graphics.widgets.ThumbView import MMKitView
        assert isinstance(self.elementViewer, MMKitView)
        self.elementViewer.resetView()
        self.elementViewer.changeHybridType(self.atomType)
        self.elementViewer.refreshDisplay(self.element, self.viewerDisplay)
        return

    def _updateParentPropMgr(self):
        """
        Update things in the parentWidget if necessary.
        (The parentWidget should be a property manager, although not necessary)
        Example: In Build Atoms Mode, the Property manager message groupbox
        needs to be updated if the element is changed in the element chooser.
        Similarly, the selection filter list should be updated in this mode.
        """

        parentPropMgrClass = self.parentPropMgr.__class__

        if hasattr(parentPropMgrClass, 'updateMessage'):
            try:
                self.parentPropMgr.updateMessage()
            except AttributeError:
                print_compact_traceback("Error calling updateMessage()")

        if hasattr(parentPropMgrClass, 'update_selection_filter_list'):
            try:
                self.parentPropMgr.update_selection_filter_list()
            except AttributeError:
                msg = "Error calling update_selection_filter_list()"
                print_compact_traceback(msg)


    def connect_or_disconnect_signals(self, isConnect):
        """
        Connect or disconnect widget signals sent to their slot methods.
        @param isConnect: If True the widget will send the signals to the slot
                          method.
        @type  isConnect: boolean
        """
        #Not implemented yet
        return

    def getElementsButtonList(self):
        """
        Subclasses should override this and return the list of buttons in the
        Atom chooser.
        """
        raise AbstractMethod()
Esempio n. 13
0
class PM_ElementChooser( PM_MolecularModelingKit ):
    """
    The PM_ElementChooser widget provides an Element Chooser widget,
    contained in its own group box, for a Property Manager dialog.
    
    A PM_ElementChooser is a selection widget that displays all elements, 
    including their atom types (atomic hybrids), supported in NE1. Methods
    are provided to set and get the selected element and atom type
    (e.g., L{setElement()}, L{getElement()}, L{getElementNumber()} and
    L{getElementSymbolAndAtomType()}).
    
    @cvar element: The current element.
    @type element: Elem
    
    @cvar atomType: The current atom type of the current element.
    @type atomType: str
    
    @see: B{elements.py}
    """
    
    def __init__(self, 
                 parentWidget, 
                 parentPropMgr   = None,
                 title           = "",
                 element         = "Carbon",
                 elementViewer   =  None
                 ):
        """
        Appends a PM_ElementChooser widget to the bottom of I{parentWidget}, 
        a Property Manager dialog. (or as a sub groupbox for Atom Chooser 
        GroupBox.)
        
        @param parentWidget: The parent PM_Dialog or PM_groupBox containing this
                             widget.
        @type  parentWidget: PM_Dialog or PM_GroupBox
        
        @param parentPropMgr: The parent Property Manager 
        @type  parentPropMgr: PM_Dialog or None
        
        @param title: The button title on the group box containing the
                      Element Chooser.
        @type  title: str
        
        @param element: The initially selected element. It can be either an
                        element symbol or name.
        @type  element: str
        """
        
        PM_MolecularModelingKit.__init__( self, 
                                          parentWidget, 
                                          parentPropMgr,
                                          title,
                                          element,
                                          elementViewer)
        
           
    def _addGroupBoxes(self):
        """
        Add various groupboxes present inside the ElementChooser groupbox
        """
        self._addElementsGroupBox(self)
        self._addAtomTypesGroupBox(self)

    def _addAtomTypesGroupBox(self, inPmGroupBox):
        """
        Creates a row of atom type buttons (i.e. sp3, sp2, sp and graphitic).
        
        @param inPmGroupBox: The parent group box to contain the atom type 
                             buttons.
        @type  inPmGroupBox: PM_GroupBox
        """
        self._atomTypesButtonGroup = \
            PM_ToolButtonGrid( inPmGroupBox, 
                               buttonList = self.getAtomTypesButtonList(),
                               label      = "Atomic hybrids:",
                               checkedId  = 0,
                               setAsDefault = True )
        #Increase the button width for atom hybrids so that 
        # button texts such as sp3(p), sp2(-), sp2(-.5) fit. 
        # This change can be removed once we have icons 
        # for the buttons with long text -- Ninad 2008-09-04
        self._atomTypesButtonGroup.setButtonSize(width = 44)
        
        # Horizontal spacer to keep buttons grouped close together.
        _hSpacer = QSpacerItem( 1, 32, 
                                QSizePolicy.Expanding, 
                                QSizePolicy.Fixed )
        
        self._atomTypesButtonGroup.gridLayout.addItem( _hSpacer, 0, 4, 1, 1 )
        
        
        
        self.connect( self._atomTypesButtonGroup.buttonGroup, 
                      SIGNAL("buttonClicked(int)"), 
                      self._setAtomType )
        
        self._updateAtomTypesButtons()
        
    def _updateAtomTypesButtons(self):
        """
        Updates the hybrid buttons based on the currently selected 
        element button.
        """
        currentElementNumber = self.getElementNumber()
        
        if ELEMENT_ATOM_TYPES.has_key(currentElementNumber):
            elementAtomTypes = ELEMENT_ATOM_TYPES[currentElementNumber]
        else:
            # Selected element has no hybrids.
            elementAtomTypes = []
            self.atomType = ""
            
        for atomType in ATOM_TYPES:
            button = self._atomTypesButtonGroup.getButtonByText(atomType)
            if atomType in elementAtomTypes:
                button.show()
                if atomType == elementAtomTypes[0]:
                    # Select the first atomType button.
                    button.setChecked(True)
                    self.atomType = atomType                    
            else:
                button.hide()
                
        self._updateAtomTypesTitle()
                
    def _updateAtomTypesTitle(self):
        """
        Updates the title for the Atom Types group box.
        """
        title = "Atomic Hybrids for " + self.element.name + ":"
        self._atomTypesButtonGroup.setTitle(title)
        
    def _setAtomType(self, atomTypeIndex):
        """
        Set the current atom type.
        
        @param atomTypeIndex: The atom type index, where:
                              0 = sp3,
                              1 = sp2,
                              2 = sp,
                              3 = sp2(graphitic)
        @type  atomTypeIndex: int
        
        @note: Calling this method does not update the atom type buttons.
        """
        self.atomType = ATOM_TYPES[atomTypeIndex]
        self.updateElementViewer()
    
    def getElementsButtonList(self):
        """
        Return the list of buttons in the Element chooser.
        @return: List containing information about the element tool buttons
        @rtype:  list
        """
        return ELEMENTS_BUTTON_LIST
    
    def getAtomTypesButtonList(self):
        """
        Return the list of buttons for the various atom types (hybrids) of the 
        selected atom in the    Element  chooser.
        @return: List containing information about the toolbuttons for 
                 the atom types (hybrids) of the selected atom  in the element
                 chooser.
        @rtype:  list 
        
        """
        return ATOM_TYPES_BUTTON_LIST        
Esempio n. 14
0
    def _loadGroupBox1(self, inPmGroupBox):
        """
        Load widgets in the group box.
        """

        memberChoices = [
            "Custom", "Alpha helix", "Beta strand", "Pi helix", "3_10 helix",
            "Polyproline-II helix", "Fully extended"
        ]

        self.aaTypeComboBox= \
            PM_ComboBox( inPmGroupBox,
                         label        = "Conformation :",
                         choices      = memberChoices,
                         index        = 1,
                         setAsDefault = True,
                         spanWidth    = False )

        self.connect(self.aaTypeComboBox, SIGNAL("currentIndexChanged(int)"),
                     self._aaTypeChanged)

        self.phiAngleField = \
            PM_DoubleSpinBox( inPmGroupBox,
                              label        = "Phi angle :",
                              value        = -57.0,
                              setAsDefault = True,
                              minimum      = -180.0,
                              maximum      = 180.0,
                              singleStep   = 1.0,
                              decimals     = 1,
                              suffix       = " degrees")

        self.connect(self.phiAngleField, SIGNAL("valueChanged(double)"),
                     self._aaPhiAngleChanged)

        self.phiAngleField.setEnabled(False)

        self.psiAngleField = \
            PM_DoubleSpinBox( inPmGroupBox,
                              label        = "Psi angle :",
                              value        = -47.0,
                              setAsDefault = True,
                              minimum      = -180.0,
                              maximum      = 180.0,
                              singleStep   = 1.0,
                              decimals     = 1,
                              suffix       = " degrees" )

        self.connect(self.psiAngleField, SIGNAL("valueChanged(double)"),
                     self._aaPsiAngleChanged)

        self.psiAngleField.setEnabled(False)


        self.invertChiralityPushButton = \
            PM_PushButton( inPmGroupBox,
                           text         = 'Invert chirality' ,
                           spanWidth    = False
                       )

        self.connect(self.invertChiralityPushButton, SIGNAL("clicked()"),
                     self._aaChiralityChanged)

        self.aaTypesButtonGroup = \
            PM_ToolButtonGrid( inPmGroupBox,
                               buttonList = AA_BUTTON_LIST,
                               label      = "Amino acids :",
                               checkedId  = 0,
                               setAsDefault = True )

        self.connect(self.aaTypesButtonGroup.buttonGroup,
                     SIGNAL("buttonClicked(int)"), self._setAminoAcidType)

        self.sequenceEditor = \
            PM_TextEdit( inPmGroupBox,
                         label      = "Sequence",
                         spanWidth = True )

        self.sequenceEditor.insertHtml("", False, 4, 10, True)

        self.sequenceEditor.setReadOnly(True)

        self.startOverButton = \
            PM_PushButton( inPmGroupBox,
                           label     = "",
                           text      = "Start Over",
                           spanWidth = True,
                           setAsDefault = True )

        self.connect(self.startOverButton, SIGNAL("clicked()"),
                     self._startOverClicked)