Esempio n. 1
0
  /**
   * Returns all residues relate to a BIRD molecule. Since BIRD molecules can span multiple internal
   * chains, we need to search all chains with a particular BIRD instance
   *
   * @param structure
   * @param chain
   * @return
   */
  private Residue[] getBirdResidues(Structure structure, Chain chain) {
    List<Residue> residues = new ArrayList<Residue>();
    Bird bird = chain.getBird();

    for (Chain c : structure.getStructureMap().getChains()) {
      Bird b = c.getBird();
      if (b != null && b.isSameInstance(bird)) {
        residues.addAll(c.getResidues());
      }
    }
    return residues.toArray(new Residue[residues.size()]);
  }
Esempio n. 2
0
 /**
  * Returns true if the initialLigand matches a PRD ID (i.e., PRD_000223)
  *
  * @param residue
  * @param initialLigand Specification of PRD molecule to be highlighted in Ligand Explorer upon
  *     startup
  * @return
  */
 private boolean isInitialBirdChain(Chain chain, String initialLigand) {
   if (chain.getClassification() == Classification.BIRD) {
     Residue r = chain.getResidue(0);
     if (r != null) {
       Bird bird = r.getBird();
       if (bird == null) {
         return false;
       }
       if (initialLigand.toUpperCase().startsWith("PRD_")) {
         return bird.getPrdId().equalsIgnoreCase(initialLigand);
       } else {
         String chainId = initialLigand.substring(0, 1);
         String prdId = initialLigand.substring(2, initialLigand.length());
         return chain.getAuthorChainId().equalsIgnoreCase(chainId)
             && bird.getPrdId().equalsIgnoreCase(prdId);
       }
     }
   }
   return false;
 }
Esempio n. 3
0
  public LigandSideBar(LXDocumentFrame mainFrame) {
    super();

    final StructureModel model = LigandExplorer.sgetModel();

    if (!model.hasStructures()) {
      this.setBackground(LXDocumentFrame.sidebarColor);
      this.setLayout(new BorderLayout());

      final JPanel pdbPanel = new JPanel();
      pdbPanel.setLayout(new FlowLayout());
      pdbPanel.setBackground(LXDocumentFrame.sidebarColor);

      final JLabel pdbLabel = new JLabel("PDB id");
      pdbLabel.setFont(pdbLabel.getFont().deriveFont(Font.BOLD));
      pdbLabel.setBackground(LXDocumentFrame.sidebarColor);

      mainFrame.getPdbIdList().setBackground(LXDocumentFrame.sidebarColor);

      pdbPanel.add(pdbLabel);
      pdbPanel.add(mainFrame.getPdbIdList());

      this.add(pdbPanel, BorderLayout.NORTH);

    } else {
      this.ligandList = this.getLigandList(model.getStructures().get(0));

      final Comparator<Chain> chainComparator =
          new Comparator<Chain>() {
            public int compare(Chain c1, Chain c2) {
              return c1.getAuthorChainId().compareTo(c2.getAuthorChainId());
            }
          };
      Collections.sort(ligandList, chainComparator);

      this.setLayout(null);

      final JLabel centerView = new JLabel("Choose a ligand to analyze...");
      centerView.setFont(centerView.getFont().deriveFont(Font.BOLD + Font.ITALIC));
      this.add(centerView);

      if (this.ligandList.size() > 0) {
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Ligands:");
        ligandJList = new JTree(root);
        ligandJList
            .getSelectionModel()
            .setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
        ligandJList.setCellRenderer(new LigandTreeCellRenderer());
        ligandJList.setExpandsSelectedPaths(true);
        ligandJList.setRootVisible(false);
        ligandJList.setShowsRootHandles(true);

        String chainId = "";
        DefaultMutableTreeNode chainNode = null;
        DefaultMutableTreeNode birdNode = null;
        Bird prevBird = null;

        for (Chain chain : ligandList) {
          // create new node only if chain id is different from previous chain id
          if (!chain.getAuthorChainId().equals(chainId)) {
            //		chainNode = new DefaultMutableTreeNode(chain);
            chainNode = new DefaultMutableTreeNode(chain.getAuthorChainId());
            root.add(chainNode);
            chainId = chain.getAuthorChainId();
          }
          if (chain.getClassification() == Residue.Classification.LIGAND) {
            for (Residue residue : chain.getResidues()) {
              chainNode.add(new DefaultMutableTreeNode(residue));
            }
          } else if (chain.getClassification() == Residue.Classification.BIRD) {
            Bird currBird = chain.getBird();
            if (prevBird == null && currBird != null) {
              birdNode = new DefaultMutableTreeNode(chain);
              chainNode.add(birdNode);
              prevBird = currBird;
            } else if (!prevBird.isSameInstance(currBird)) {
              birdNode = new DefaultMutableTreeNode(chain);
              chainNode.add(birdNode);
              prevBird = currBird;
            }
            for (Residue residue : chain.getResidues()) {
              birdNode.add(new DefaultMutableTreeNode(residue));
            }
          } else if (chain.hasModifiedResidues()) {
            for (Residue residue : chain.getModifiedResidues()) {
              chainNode.add(new DefaultMutableTreeNode(residue));
            }
          }
        }

        ligandJList
            .getSelectionModel()
            .addTreeSelectionListener(
                new TreeSelectionListener() {
                  public void valueChanged(TreeSelectionEvent e) {
                    applyButton.doClick();
                    Structure structure = AppBase.sgetModel().getStructures().get(0);
                    if (structure.getStructureMap().getSurfaceCount() > 0) {
                      LigandExplorer.sgetGlGeometryViewer().ligandViewWithSurface(structure);
                    } else {
                      LigandExplorer.sgetGlGeometryViewer().ligandView(structure);
                    }
                  }
                });

        ligandScroller = new JScrollPane(this.ligandJList);

        add(ligandScroller);
      } else centerView.setText("No ligands in this structure");

      final JLabel displayView = new JLabel("Choose interactions & thresholds...");
      displayView.setFont(displayView.getFont().deriveFont(Font.BOLD + Font.ITALIC));
      this.add(displayView);

      final JCheckBox hydrophilicBox = new JCheckBox(InteractionConstants.hydrogenBondType);
      final LegendPanel hydrophilicPanel =
          new LegendPanel(InteractionConstants.hydrogenBondColor, LXDocumentFrame.sidebarColor);
      final FloatLimitField philicFLF2 = new FloatLimitField("3.3");
      this.add(hydrophilicBox);
      this.add(philicFLF2);
      this.add(hydrophilicPanel);

      final JCheckBox hydrophobicBox = new JCheckBox(InteractionConstants.hydrophobicType);
      final LegendPanel hydrophobicPanel =
          new LegendPanel(InteractionConstants.hydrophobicBondColor, LXDocumentFrame.sidebarColor);
      final FloatLimitField phobicFLF2 = new FloatLimitField("3.9");
      this.add(hydrophobicBox);
      this.add(phobicFLF2);
      this.add(hydrophobicPanel);

      final JCheckBox l_h2o_pBox = new JCheckBox(InteractionConstants.waterMediatedType);
      l_h2o_pBox.setBackground(LXDocumentFrame.sidebarColor);
      final LegendPanel l_h2o_pPanel =
          new LegendPanel(InteractionConstants.waterMediatedColor, LXDocumentFrame.sidebarColor);
      l_h2o_pBox.setBackground(LXDocumentFrame.sidebarColor);
      final FloatLimitField l_h2o_pFLF2 = new FloatLimitField("3.3");
      this.add(l_h2o_pBox);
      this.add(l_h2o_pFLF2);
      this.add(l_h2o_pPanel);

      final JCheckBox otherBox = new JCheckBox(InteractionConstants.metalInteractionType);
      final LegendPanel otherPanel =
          new LegendPanel(InteractionConstants.metalInteractionColor, LXDocumentFrame.sidebarColor);
      final FloatLimitField otherFLF2 = new FloatLimitField("3.5");
      this.add(otherBox);
      this.add(otherFLF2);
      this.add(otherPanel);

      final JCheckBox neighborBox = new JCheckBox(InteractionConstants.neighborInteractionType);
      final FloatLimitField neighborFLF1 = new FloatLimitField("4.0");
      this.add(neighborBox);
      this.add(neighborFLF1);

      // new: added this separator
      final JSeparator separator = new JSeparator();
      this.add(separator);

      final JCheckBox distanceBox = new JCheckBox("Label interactions by distance");
      distanceBox.setBackground(LXDocumentFrame.sidebarColor);
      distanceBox.setSelected(true);
      this.add(distanceBox);

      //			System.out.println("Adding BindingSiteSurfacePanel");
      final JPanel surfacePanel = new BindingSiteSurfacePanel(hasMacromoleculeChain());
      surfacePanel.setBackground(LXDocumentFrame.sidebarColor);
      this.add(surfacePanel);

      // this button should eventually be removed. Its still used
      // to fire some update events
      applyButton = new JButton("Apply");
      this.add(applyButton);

      this.setLayout(
          new LayoutManager() {
            public void addLayoutComponent(String arg0, Component arg1) {}

            private Dimension layoutSize = null;

            public void layoutContainer(Container parent) {
              final int visualBuffer = 3;
              Insets parentInsets = parent.getInsets();

              if (ligandList == null || ligandList.size() == 0) {
                Dimension preferred = centerView.getPreferredSize();
                centerView.setBounds(
                    parentInsets.left + visualBuffer,
                    parentInsets.top + visualBuffer,
                    preferred.width,
                    preferred.height);
              } else {
                Dimension step1Preferred = centerView.getPreferredSize();
                Dimension step2Preferred = displayView.getPreferredSize();
                ;
                Dimension hydrophilicBoxPreferred = hydrophilicBox.getPreferredSize();
                Dimension hydrophobicBoxPreferred = hydrophobicBox.getPreferredSize();
                Dimension l_h2o_pBoxPreferred = l_h2o_pBox.getPreferredSize();
                Dimension otherBoxPreferred = otherBox.getPreferredSize();
                Dimension neighborBoxPreferred = neighborBox.getPreferredSize();
                Dimension distancePreferred = distanceBox.getPreferredSize();
                Dimension hydrophilicFLF2Preferred = philicFLF2.getPreferredSize();
                Dimension hydrophobicFLF2Preferred = phobicFLF2.getPreferredSize();
                Dimension l_h2o_pFLF2Preferred = l_h2o_pFLF2.getPreferredSize();
                Dimension otherFLF2Preferred = otherFLF2.getPreferredSize();
                Dimension neighborFLF1Preferred = neighborFLF1.getPreferredSize();
                Dimension separatorPreferred = separator.getPreferredSize();
                Dimension surfacePanelPreferred = surfacePanel.getPreferredSize();

                int parentHeight = parent.getHeight();
                int parentWidth = parent.getWidth();
                int fullWidth =
                    parentWidth - parentInsets.left - parentInsets.right - visualBuffer * 2;

                int listHeight =
                    parentHeight
                        - parentInsets.top
                        - parentInsets.bottom
                        - (step1Preferred.height
                            + step2Preferred.height
                            + hydrophilicBoxPreferred.height
                            + hydrophobicBoxPreferred.height
                            + l_h2o_pBoxPreferred.height
                            + otherBoxPreferred.height
                            + neighborBoxPreferred.height
                            + separatorPreferred.height
                            + distancePreferred.height
                            + surfacePanelPreferred.height
                            + visualBuffer * 13);

                int curY = parentInsets.top + visualBuffer;
                int curX = parentInsets.left + visualBuffer;
                int maxWidth = 0;

                centerView.setBounds(curX, curY, step1Preferred.width, step1Preferred.height);
                curY += step1Preferred.height + visualBuffer;
                maxWidth = step1Preferred.width;

                ligandScroller.setBounds(curX, curY, fullWidth, listHeight);
                curY += listHeight + visualBuffer;

                displayView.setBounds(curX, curY, step2Preferred.width, step2Preferred.height);
                curY += step2Preferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, step2Preferred.width);

                int maxCheckboxWidth = 0;
                int hydrophilicBoxStartY = curY;
                hydrophilicBox.setBounds(
                    curX, curY, hydrophilicBoxPreferred.width, hydrophilicBoxPreferred.height);
                curY += hydrophilicBoxPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, hydrophilicBoxPreferred.width);
                maxCheckboxWidth = Math.max(maxCheckboxWidth, hydrophilicBoxPreferred.width);

                int hydrophobicBoxStartY = curY;
                hydrophobicBox.setBounds(
                    curX, curY, hydrophobicBoxPreferred.width, hydrophobicBoxPreferred.height);
                curY += hydrophobicBoxPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, hydrophobicBoxPreferred.width);
                maxCheckboxWidth = Math.max(maxCheckboxWidth, hydrophobicBoxPreferred.width);

                int l_h2o_pBoxStartY = curY;
                l_h2o_pBox.setBounds(
                    curX, curY, l_h2o_pBoxPreferred.width, l_h2o_pBoxPreferred.height);
                curY += l_h2o_pBoxPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, l_h2o_pBoxPreferred.width);
                maxCheckboxWidth = Math.max(maxCheckboxWidth, l_h2o_pBoxPreferred.width);

                int otherBoxStartY = curY;
                otherBox.setBounds(curX, curY, otherBoxPreferred.width, otherBoxPreferred.height);
                curY += otherBoxPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, otherBoxPreferred.width);
                maxCheckboxWidth = Math.max(maxCheckboxWidth, otherBoxPreferred.width);

                int neighborBoxStartY = curY;
                neighborBox.setBounds(
                    curX, curY, neighborBoxPreferred.width, neighborBoxPreferred.height);
                curY += neighborBoxPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, neighborBoxPreferred.width);
                maxCheckboxWidth = Math.max(maxCheckboxWidth, neighborBoxPreferred.width);

                // now align the constraint boxes to a grid defined by the check boxes.
                final int legendWidth = 50;
                curX += maxCheckboxWidth + visualBuffer * 2;
                neighborFLF1.setBounds(
                    curX,
                    neighborBoxStartY,
                    neighborFLF1Preferred.width,
                    neighborFLF1Preferred.height);
                philicFLF2.setBounds(
                    curX,
                    hydrophilicBoxStartY,
                    hydrophilicFLF2Preferred.width,
                    hydrophilicFLF2Preferred.height);
                phobicFLF2.setBounds(
                    curX,
                    hydrophobicBoxStartY,
                    hydrophobicFLF2Preferred.width,
                    hydrophobicFLF2Preferred.height);
                l_h2o_pFLF2.setBounds(
                    curX,
                    l_h2o_pBoxStartY,
                    l_h2o_pFLF2Preferred.width,
                    l_h2o_pFLF2Preferred.height);
                otherFLF2.setBounds(
                    curX, otherBoxStartY, otherFLF2Preferred.width, otherFLF2Preferred.height);
                curX += philicFLF2.getWidth() + visualBuffer;
                hydrophilicPanel.setBounds(
                    curX, hydrophilicBoxStartY, legendWidth, hydrophilicFLF2Preferred.height);
                hydrophobicPanel.setBounds(
                    curX, hydrophobicBoxStartY, legendWidth, hydrophobicFLF2Preferred.height);
                l_h2o_pPanel.setBounds(
                    curX, l_h2o_pBoxStartY, legendWidth, l_h2o_pFLF2Preferred.height);
                otherPanel.setBounds(curX, otherBoxStartY, legendWidth, otherFLF2Preferred.height);
                curX = parentInsets.left + visualBuffer;

                separator.setBounds(
                    curX, curY, separatorPreferred.width, separatorPreferred.height);
                curY += separatorPreferred.height + 3 * visualBuffer;
                maxWidth = Math.max(maxWidth, separatorPreferred.width);

                distanceBox.setBounds(
                    curX, curY, distancePreferred.width, distancePreferred.height);
                curY += distancePreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, distancePreferred.width);

                surfacePanel.setBounds(
                    curX, curY, surfacePanelPreferred.width, surfacePanelPreferred.height);
                curY += surfacePanelPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, surfacePanelPreferred.width);

                //							this.layoutSize.width = maxWidth + parentInsets.left + parentInsets.right +
                // visualBuffer * 2;

                // TODO check width on Mac OSX
                this.layoutSize.width =
                    maxWidth + parentInsets.left + parentInsets.right + visualBuffer * 2;
              }
            }

            public Dimension minimumLayoutSize(Container parent) {
              if (this.layoutSize == null) {
                this.layoutSize = new Dimension();
                this.layoutContainer(parent);
              }
              return this.layoutSize;
            }

            public Dimension preferredLayoutSize(Container parent) {
              if (this.layoutSize == null) {
                this.layoutSize = new Dimension();
                this.layoutContainer(parent);
              }
              return this.layoutSize;
            }

            public void removeLayoutComponent(Component comp) {}
          });

      // set colors and initial state
      this.setBackground(LXDocumentFrame.sidebarColor);
      hydrophilicBox.setBackground(LXDocumentFrame.sidebarColor);
      hydrophilicBox.setSelected(false);
      hydrophobicBox.setBackground(LXDocumentFrame.sidebarColor);
      hydrophobicBox.setSelected(false);
      otherBox.setBackground(LXDocumentFrame.sidebarColor);
      otherBox.setSelected(false);
      neighborBox.setBackground(LXDocumentFrame.sidebarColor);
      neighborBox.setSelected(false);

      // separator is not visible, why ??
      separator.setBackground(Color.BLACK);
      separator.setForeground(Color.BLACK);
      separator.setVisible(true);

      interactionListener =
          new InteractionListener(
              l_h2o_pBox,
              hydrophilicBox,
              hydrophobicBox,
              otherBox,
              neighborBox,
              distanceBox,
              l_h2o_pFLF2,
              philicFLF2,
              phobicFLF2,
              otherFLF2,
              neighborFLF1);

      applyButton.addActionListener(interactionListener);
      hydrophilicBox.addActionListener(interactionListener);
      hydrophobicBox.addActionListener(interactionListener);
      l_h2o_pBox.addActionListener(interactionListener);
      otherBox.addActionListener(interactionListener);
      neighborBox.addActionListener(interactionListener);
      distanceBox.addActionListener(interactionListener);

      // add action listener to the distance threshold text boxes
      l_h2o_pFLF2.addActionListener(interactionListener);
      philicFLF2.addActionListener(interactionListener);
      phobicFLF2.addActionListener(interactionListener);
      otherFLF2.addActionListener(interactionListener);
      neighborFLF1.addActionListener(interactionListener);
      ;
    }
  }