All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gennbo.NBOSearch Maven / Gradle / Ivy

There is a newer version: 14.31.10
Show newest version
/* $RCSfile$
 * $Author: hansonr $
 * $Date: 2014-12-13 22:43:17 -0600 (Sat, 13 Dec 2014) $
 * $Revision: 20162 $
 *
 * Copyright (C) 2002-2005  The Jmol Development Team
 *
 * Contact: [email protected]
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package org.gennbo;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javajs.util.PT;
import javajs.util.SB;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;

import org.jmol.modelset.Atom;

class NBOSearch extends NBOView {

  protected NBOSearch(NBODialog dialog) {
    super(dialog);
  }

  private final static int KEYWD_WEBHELP = 0;

  private final static int KEYWD_NPA = 1;
  private final static int KEYWD_NBO = 2;
  private final static int KEYWD_BEND = 3;
  private final static int KEYWD_E2PERT = 4;
  private final static int KEYWD_NLMO = 5;

  // Note: The next three are not in the order the buttons are presented
  private final static int KEYWD_NRT = 6;
  private final static int KEYWD_STERIC = 7;
  private final static int KEYWD_CMO = 8;

  private final static int KEYWD_DIPOLE = 9;
  private final static int KEYWD_OPBAS = 10;
  private final static int KEYWD_BAS1BAS2 = 11;

  /**
   * keywords in order of PRESENTATION
   * 
   */
  private final static String[] keywordNames = { "NPA", "NBO", "BEND", "E2",
      "NLMO", "NRT", "STERIC", "CMO", "DIPOLE", "OPBAS", "B1B2" };

  /**
   * @return name of the keyword
   */
  private String getKeyword() {
    return getKeywordName(keywordID);
  }

  /**
   * map button index to NBO keyword numbers.
   */
  private final static int[] btnIndexToNBOKeyword = new int[] { KEYWD_NPA,
      KEYWD_NBO, KEYWD_BEND, KEYWD_E2PERT, KEYWD_NLMO, KEYWD_CMO, KEYWD_NRT,
      KEYWD_STERIC, // these three are shifted 
      KEYWD_DIPOLE, KEYWD_OPBAS, KEYWD_BAS1BAS2 };

  private String getKeywordButtonLabel(int ibtn) {
    return (ibtn == 3 ? "E2PERT" : getKeywordName(btnIndexToNBOKeyword[ibtn]));
  }

  
  private static final int MODE_SEARCH_VALUE       = 14;
  private static final int MODE_SEARCH_LIST_MO     = 24;
  private static final int MODE_SEARCH_ATOM_VALUES = 34;
  private static final int MODE_SEARCH_BOND_VALUES = 44;
  private static final int MODE_SEARCH_LIST        = 54;
  private static final int MODE_SEARCH_LIST_LABEL  = 64;


  /**
   * * does not include "HELP" (0)
   * 
   * @param ikeywd
   * @return name for the specified keyword ID
   */
  private String getKeywordName(int ikeywd) {
    return keywordNames[ikeywd - 1];
  }

  /**
   * Return the NBOServe keyword for a given SEARCH option; allows for a
   * different presentation ordering in Jmol relative to actual numbers in
   * NBOServe
   * 
   * @param index
   *        the button index
   * @return the NBO keyword number for this option
   */
  protected final static int getNboKeywordNumber(int index) {
    return (btnIndexToNBOKeyword[index]);
  }

  protected final static String[] keyW = {
      "NPA    : Atomic and NAO properties",
      "NBO    : Natural Lewis Structure and\n NBO properties",
      "BEND   : NHO directionality and\n bond-bending",
      "E2PERT : 2nd-order energtics of NBO\n donor-acceptor interactions",
      "NLMO   : NLMO properties",
      "CMO    : NBO-based character of canonical\n molecular orbitals",
      "NRT    : Natural Resonance Theory\n weightings and bond orders",
      "STERIC : Total/pairwise contributions\n to steric exchange energy",
      "DIPOLE : L/NL contributions to electric\n dipole moment",
      "OPBAS  : Matrix elements of chosen operator   \n in chosen basis set",
      "B1B2   : Transformation matrix between\n chosen basis sets" };

  protected final static String[] npa = { "NPA Atomic Properties:",
      "  (1) NPA atomic charge", "  (2) NPA atomic spin density",
      "  (3) NEC atomic electron configuration",
      "NPA Molecular Unit Properties:", "  (4) NPA molecular unit charge",
      "  (5) NPA molecular unit spin density", "NAO Orbital Properties:",
      "  (6) NAO label", "  (7) NAO orbital population",
      "  (8) NAO orbital energy", "  (9) NAO orbital spin density",
      "  (10) NMB minimal basis %-accuracy", "Display Options:",
      "  (11) Display atomic charges" }, nbo = { "NBO Orbital Properties:",
      "  (1) NBO orbital label", "  (2) NBO orbital population",
      "  (3) NBO orbital energy", "  (4) NBO ionicity",
      "Natural Lewis Structure Properties:", "  (5) NLS rho(NL)",
      "  (6) NLS %-rho(L)" }, bend = { "NHO Orbital Prperties:",
      "  (1) NHO orbital label", "  (2) NHO orbital population",
      "  (3) NHO orbital energy", "  (4) NHO hybrid composition",
      "  (5) NHO direction angles",
      "  (6) NHO bending deviation from line of centers",
      "  (7) Strongest bending deviation for any NHO" }, e2 = {
      "E2 Values for Selected Donor-Acceptor NBOs:",
      "  (1) E(2) interaction for current d/a NBOs",
      "  (2) Strongest E(2) interaction for current d-NBO",
      "  (3) Strongest E(2) interaction for current a-NBO",
      "  (4) Strongest E(2) interaction for any d/a NBOs",
      "Intermolecular E2 Options:",
      "  (5) Strongest intermolecular E(2) for current unit",
      "  (6) Strongest intermolecular E(2) for any units" }, nlmo = {
      "NLMO Orbital Properties:", "  (1) NLMO orbital label",
      "  (2) NLMO population", "  (3) NLMO orbital energy",
      "  (4) NLMO %-NBO parentage", "NLMO Delocalization Tail Properties:",
      "  (5) NLMO delocalization tail population",
      "  (6) NLMO delocalization tail NBO components" }, nrt = {
      "Atom (A) Properties:", "  (1) atomic valency (total)",
      "  (2) atomic covalency", "  (3) atomic electrovalency",
      "Bond [A-A'] Properties:", "  (4) bond order (total)",
      "  (5) covalent bond order", "  (6) electrovalent bond order",
      "Resonance Structure Properties:", "  (7) RS weighting",
      "  (8) RS rho(NL) (reference structures only)", "Display Options:",
      "  (9) Display NRT atomic valencies", "  (10) Display NRT bond orders" },
      steric = { "Total Steric Exchange Energy (SXE) Estimates:",
          "  (1) Total SXE", "  (2) Sum of pairwise (PW-SXE) contributions",
          "Selected PW-SXE contributions:",
          "  (3) PW-SXE for current d-d' NLMOs",
          "  (4) Strongest PW-SXE for current d NLMO",
          "Intra- and intermolecular options:",
          "  (5) Strongest PW-SXE within current unit",
          "  (6) Strongest PW-SXE within any unit",
          "  (7) Strongest PW-SXE between any units" }, mo = {
          "Character of current MO (c):", "  (1) Current MO energy and type",
          "  (2) Bonding character of current MO",
          "  (3) Nonbonding character of current MO",
          "  (4) Antibonding character of current MO",
          "NBO (n) %-contribution to selected MO (c):",
          "  (5) %-contribution of current NBO to current MO",
          "  (6) Largest %-contribution to current MO from any NBO",
          "  (7) Largest %-contribution of current NBO to any MO" }, dip = {
          "Total Dipole Properties:", "  (1) Total dipole moment",
          "  (2) Total L-type (Lewis) dipole",
          "  (3) Total NL-type (resonance) dipole",
          "Bond [NBO/NLMO] Dipole Properties:",
          "  (4) Dipole moment of current NLMO",
          "  (5) L-type (NBO bond dipole) contribution",
          "  (6) NL-type (resonance dipole) contribution",
          "Molecular Unit Dipole Properties:",
          "  (7) Dipole moment of current molecular unit",
          "  (8) L-type contribution to unit dipole",
          "  (9) NL-type contribution to unit dipole" }, op = {
          " in position 1, then the offset will be 0

    switch (keywordID) {
    case KEYWD_NPA:
      orb1 = comboSearchOrb2;
      unit1 = comboUnit1;
      if (op < 6 || op > 10) {
        // only 6-10 use orbital 1
        orb1 = null;
        if (op > 10) {
          isLabelAtom = true;
          op = 12;
        } else if (op <= 3) {
          // ops 1-3 use atom1
          atom1 = comboAtom1;
        }
      }
      break;
    case KEYWD_NBO:
    case KEYWD_BEND:
    case KEYWD_NLMO:
      // just orb1
      break;
    case KEYWD_E2PERT:
      labelOrb1 = "d_NBO_1";
      labelOrb2 = "a_NBO";
      orb2 = comboSearchOrb2;
      ComboBoxModel x = orb1.getModel();
      System.out.println(x.getSize());
      offset2 = orb1.getModel().getSize() - 1;
      break;
    case KEYWD_NRT:
      orb1 = null;
      switch (op) {
      case 4:
      case 5:
      case 6:
        atom2 = comboAtom2;
        //$FALL-THROUGH$
      case 1:
      case 2:
      case 3:
        atom1 = comboAtom1;
        break;
      case 9:
        isLabelAtom = true;
        break;
      case 10:
        isLabelBonds = true;
        break;
      case 7:
      case 8:
        doShowResonanceStructure(comboUnit1.getSelectedIndex());
        break;
      default:
        break;
      }
      unit1 = comboUnit1;
      labelUnit1 = "RES_STR";
      break;
    case KEYWD_STERIC:
      labelOrb1 = "d_NBO_1";
      labelOrb2 = "d_NBO_2";
      orb2 = comboSearchOrb2;
      unit1 = comboUnit1;
      switch (op) {
      case 1:
      case 2:
      case 3:
        break;
      default:
        orb1 = null;
        //$FALL-THROUGH$
      case 4:
        orb2 = null;
        break;
      }
      break;
    case KEYWD_CMO:
      // op 7 requires only an NBO selection
      labelOrb1 = "NBO";
      if (op != 5 && op != 7) 
        orb1 = null;      
      // only  ops 5 and 7 require an NBO selection
      labelOrb2 = "CMO";
      orb2 = (op == 7 ? null : comboSearchOrb2);
      break;
    case KEYWD_DIPOLE:
      unit1 = comboUnit1;
      break;
    case KEYWD_OPBAS:
      labelOrb1 = "ROW";
      labelOrb2 = "COLUMN";
      orb2 = comboSearchOrb2;
      NBOUtil.postAddGlobalI(sb, "OPERATOR", operator, null);
      NBOUtil.postAddGlobalI(sb, "BAS_1", 1, comboBasis1);
      break;
    case KEYWD_BAS1BAS2:
      labelOrb1 = "ROW";
      labelOrb2 = "COLUMN";
      orb2 = comboSearchOrb2;
      NBOUtil.postAddGlobalI(sb, "BAS_1", 1, comboBasis1);
      NBOUtil.postAddGlobalI(sb, "BAS_2", 1, comboBasis2);
      break;
    }

    JComboBox cb = null;
    boolean isOK = (
           (atom1 == null || (cb = atom1).getSelectedIndex() > 0)
        && (atom2 == null || (cb = atom2).getSelectedIndex() > 0)
        && (orb1 == null || (cb = orb1).getSelectedIndex() > 0)
        && (orb2 == null || (cb = orb2).getSelectedIndex() > 0));
    if (!isOK) {
      dialog.logError(cb.getItemAt(0));
      return;
    }
    if (orb1 != null)
      NBOUtil.postAddGlobalI(sb, labelOrb1, offset1, orb1);
    if (orb2 != null)
      NBOUtil.postAddGlobalI(sb, labelOrb2, offset2, orb2);
    if (atom1 != null)
      NBOUtil.postAddGlobalI(sb, labelAtom1, 0, atom1);
    if (atom2 != null)
      NBOUtil.postAddGlobalI(sb, labelAtom2, 0, atom2);
    if (unit1 != null)
      NBOUtil.postAddGlobalI(sb, labelUnit1, 1, unit1);
    NBOUtil.postAddGlobalI(sb, "OPT_" + getKeyword(), op, null);

    if (needRelabel) {
      dialog
          .runScriptQueued("select add {*}.bonds; color bonds lightgrey; select none; measurements off");
      showLewisStructure();
      needRelabel = false;
    }
    if (isLabelAtom) {
      needRelabel = true;
      postNBO_s(sb, MODE_SEARCH_ATOM_VALUES, null, "Getting labels", false);
    } else if (isLabelBonds) {
      needRelabel = true;
      dialog
          .runScriptQueued("select add {*}.bonds; color bonds [170,170,170]; select none");
      postNBO_s(sb, MODE_SEARCH_BOND_VALUES, null,
          "Getting bonds list", false);
    } else {
      postNBO_s(sb, MODE_SEARCH_VALUE, null, "Getting value...", true);
    }
  }

  private boolean secondPick = true;

  /**
   * Runs when list is finished being sent by nboServe -E2PERT: orbital
   * numbering of second list offset by length of first -NPA, STERIC, DIPOLE:
   * checks for more than 1 unit -NRT: gets res structure info
   * 
   * @param cb
   */
  protected void processReturnedSearchList(JComboBox cb) {
    DefaultComboBoxModel list = (DefaultComboBoxModel) cb
        .getModel();
    switch (keywordID) {
    case KEYWD_E2PERT:
      if (cb == comboSearchOrb2) {
        //Relabel a-nbo to correct orbital number
        int offset = comboSearchOrb1.getModel().getSize() - 1; // list includes "");
      else if (cb == comboSearchOrb1 || cb == comboSearchOrb2)
        list.addElement("