Package org.jmol.api

Examples of org.jmol.api.JmolNode


    Vector3f[] vNorms = new Vector3f[nPoints * 2];
    int nNorms = 0;
    float maxDev = (float) (1 - cutoff * 5);
    //System.out.println("using maxDev=" + maxDev);
    for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
      JmolNode ringAtom = atoms[i];
      JmolEdge[] bonds = ringAtom.getEdges();
      if (bonds.length < 3)
        continue;
      if (bonds.length > 3)
        return false;
/*     
      // uncomment these next lines to exclude quinone and nucleic acid bases
      for (int k = bonds.length; --k >= 0;) {
        int iAtom = ringAtom.getBondedAtomIndex(k);
        if (!bsSelected.get(iAtom))
          continue;
        if (!bs.get(iAtom) && bonds[k].getOrder() == JmolConstants.BOND_COVALENT_DOUBLE)
          return false;
      }
*/
    }
    for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
      JmolNode ringAtom = atoms[i];
      JmolEdge[] bonds = ringAtom.getEdges();
      // if more than three connections, ring cannot be fully conjugated
      // identify substituent and two ring atoms
      int iSub = -1;
      int r1 = -1;
      int r2 = -1;
      for (int k = bonds.length; --k >= 0;) {
        int iAtom = ringAtom.getBondedAtomIndex(k);
        if (!bsSelected.get(iAtom))
          continue;
        if (!bs.get(iAtom))
          iSub = iAtom;
        else if (r1 < 0)
View Full Code Here


    String s;
    List vLinks = new ArrayList();
    try {
      int len = 0;
      for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
        JmolNode a = atoms[i];
        String ch = a.getGroup1('?');
        String groupType = a.getGroupType();
        boolean unknown = (ch.equals("?"));
        if (end != null) {
          if (sb.length() > 0)
            sb.append(end);
          end = null;
          len = 0;
          if (groupType.length() > 0) {
            char id = a.getChainID();
            if (id != '\0') {
              s = "//* chain " + id + " " + groupType + " " + a.getResno() + " *// ";
              len = s.length();
              sb.append(s);
            }
            sb.append("~").append(groupType.charAt(0)).append("~");
            len++;
          } else {
            s = getSmilesComponent(a, bs, true);
            if (s.equals(lastComponent)) {
              end = "";
            } else {
              lastComponent = s;
              groupType = a.getGroup3(true);
              if (groupType != null)
                sb.append("//* ").append(groupType).append(" *//");
              sb.append(s);
              end = ".\n";
            }
            continue;
          }
        }
        if (len >= 75) {
          sb.append("\n  ");
          len = 2;
        }
        if (unknown) {
          addBracketedBioName(sb, a, groupType.length() > 0 ? ".0" : null);
        } else {
          sb.append(ch);
        }
        len++;
        int i0 = a.getOffsetResidueAtom("0", 0);
        if (addCrossLinks) {
          a.getCrossLinkLeadAtomIndexes(vLinks);
          for (int j = 0; j < vLinks.size(); j++) {
            sb.append(":");
            s = getRingCache(i0, ((Integer) vLinks.get(j)).intValue(),
                htRingsSequence);
            sb.append(s);
            len += 1 + s.length();
          }
          vLinks.clear();
        }
        a.setGroupBits(bsIgnore);
        bs.andNot(bsIgnore);
        int i2 = a.getOffsetResidueAtom("0", 1);
        if (i2 < 0 || !bs.get(i2)) {
          sb.append(" //* ").append(a.getResno()).append(" *//");      
          if (i2 < 0 && (i2 = bs.nextSetBit(i + 1)) < 0)
            break;
          if (len > 0)
            end = ".\n";
        }
View Full Code Here

        (BitSet) bs.clone(), null, -1, true, false);
    bs.andNot(bsSelected);
    bsIncludingH = (BitSet) bsSelected.clone();
    for (int j = bsSelected.nextSetBit(0); j >= 0; j = bsSelected
        .nextSetBit(j + 1)) {
      JmolNode a = atoms[j];
      if (a.getElementNumber() == 1 && a.getIsotopeNumber() == 0)
        bsSelected.clear(j);
    }
    if (bsSelected.cardinality() > 2) {
      SmilesSearch search = null;
      search = SmilesParser.getMolecule("A[=&@]A", true);
View Full Code Here

    // as having been done already so as not to do twice.
    // The bonds we are marking will be bits in bsBondsUp or bsBondsDn
   
    for (int i = bsSelected.nextSetBit(0); i >= 0; i = bsSelected
        .nextSetBit(i + 1)) {
      JmolNode atom1 = atoms[i];
      JmolEdge[] bonds = atom1.getEdges();
      for (int k = 0; k < bonds.length; k++) {
        JmolEdge bond = bonds[k];
        int index = bond.getIndex();
        if (bsDone.get(index))
          continue;
        JmolNode atom2 = bond.getOtherAtom(atom1);
        if (bond.getCovalentOrder() != 2
            || SmilesSearch.isRingBond(ringSets, i, atom2.getIndex()))
          continue;
        bsDone.set(index);
        JmolEdge b0 = null;
        JmolNode a0 = null;
        int i0 = 0;
        JmolNode[] atom12 = new JmolNode[] { atom1, atom2 };
        if (Logger.debugging)
          Logger.debug(atom1 + " == " + atom2);
        int edgeCount = 1;
       
        // OK, so we have a double bond. Only looking at single bonds around it.
       
        // First pass: just see if there is an already-assigned bond direction
        // and collect the edges in an array.
       
        for (int j = 0; j < 2 && edgeCount > 0 && edgeCount < 3; j++) {
          edgeCount = 0;
          JmolNode atomA = atom12[j];
          JmolEdge[] bb = atomA.getEdges();
          for (int b = 0; b < bb.length; b++) {
            if (bb[b].getCovalentOrder() != 1)
              continue;
            edges[j][edgeCount++] = bb[b];
            if (getBondStereochemistry(bb[b], atomA) != '\0') {
              b0 = bb[b];
              i0 = j;
            }
          }
        }
        if (edgeCount == 3 || edgeCount == 0)
          continue;
       
        // If no bond around this double bond is already marked, we assign it UP.
       
        if (b0 == null) {
          i0 = 0;
          b0 = edges[i0][0];
          bsBondsUp.set(b0.getIndex());
        }
       
        // The character '/' or '\\' is assigned based on a
        // geometric reference to the reference bond. Initially
        // this comes in in reference to the double bond, but
        // when we save the bond, we are saving the correct
        // character for the bond itself -- based on its
        // "direction" from atom 1 to atom 2. Then, when
        // creating the SMILES string, we use the atom on the
        // left as the reference to get the correct character
        // for the string itself. The only tricky part, I think.
        // SmilesSearch.isDiaxial is just a simple method that
        // does the dot products to determine direction. In this
        // case we are looking simply for vA.vB < 0,meaning
        // "more than 90 degrees apart" (ab, and cd)
        // Parity errors would be caught here, but I doubt you
        // could ever get that with a real molecule.
       
        char c0 = getBondStereochemistry(b0, atom12[i0]);
        a0 = b0.getOtherAtom(atom12[i0]);
        for (int j = 0; j < 2; j++)
          for (int jj = 0; jj < 2; jj++) {
            JmolEdge b1 = edges[j][jj];
            if (b1 == null || b1 == b0)
              continue;
            int bi = b1.getIndex();
            JmolNode a1 = b1.getOtherAtom(atom12[j]);
            char c1 = getBondStereochemistry(b1, atom12[j]);

            //   c1 is FROM the double bond:
            //   
            //    a     b
            //     \   /
            //      C=C       /a /b  \c \d
            //     /   \
            //    c     d

            boolean isOpposite = SmilesSearch.isDiaxial(atom12[i0], atom12[j],
                a0, a1, vTemp, 0);
            if (c1 == '\0' || (c1 != c0) == isOpposite) {
              boolean isUp = (c0 == '\\' && isOpposite || c0 == '/'
                  && !isOpposite);
              if (isUp == (b1.getAtomIndex1() != a1.getIndex()))
                bsBondsUp.set(bi);
              else
                bsBondsDn.set(bi);
            } else {
              Logger.error("BOND STEREOCHEMISTRY ERROR");
            }
            if (Logger.debugging)
              Logger.debug(getBondStereochemistry(b0, atom12[0]) + " "
                  + a0.getIndex() + " " + a1.getIndex() + " "
                  + getBondStereochemistry(b1, atom12[j]));
          }
      }
    }
  }
View Full Code Here

    int nH = 0;
    List v = new ArrayList();
    JmolEdge bond0 = null;
    JmolEdge bondPrev = null;
    JmolEdge[] bonds = atom.getEdges();
    JmolNode aH = null;
    int stereoFlag = (isAromatic ? 10 : 0);
    JmolNode[] stereo = new JmolNode[7];
    if (Logger.debugging)
      Logger.debug(sb.toString());

    // first look through the bonds for the best
    // continuation -- bond0 -- and count hydrogens
    // and create a list of bonds to process.

    if (bonds != null)
      for (int i = bonds.length; --i >= 0;) {
        JmolEdge bond = bonds[i];
        if (!bond.isCovalent())
          continue;
        JmolNode atom1 = bonds[i].getOtherAtom(atom);
        int index1 = atom1.getIndex();
        if (index1 == prevIndex) {
          bondPrev = bonds[i];
          continue;
        }
        boolean isH = (atom1.getElementNumber() == 1 && atom1
            .getIsotopeNumber() == 0);
        if (!bsIncludingH.get(index1)) {
          if (!isH && allowConnectionsToOutsideWorld
              && bsSelected.get(atomIndex))
            bsToDo.set(index1);
          else
            continue;
        }
        if (isH) {
          aH = atom1;
          nH++;
          if (nH > 1)
            stereoFlag = 10;
        } else {
          v.add(bonds[i]);
        }
      }

    // order of listing is critical for stereochemistry:
    //
    // 1) previous atom
    // 2) bond to previous atom
    // 3) atom symbol
    // 4) hydrogen atoms
    // 5) branches
    // 6) rings

    // add the bond to the previous atom

    String strBond = null;
    if (sp2Atoms == null)
      sp2Atoms = new JmolNode[5];
    if (bondPrev == null) {
    } else {
      strBond = SmilesBond.getBondOrderString(bondPrev.getCovalentOrder());
      if (prevSp2Atoms == null)
        sp2Atoms[nSp2Atoms++] = prevAtom;
      else
        nSp2Atoms = 2;
    }
    nSp2Atoms += nH;

    // get bond0
    int nMax = 0;
    BitSet bsBranches = new BitSet();
    if (allowBranches)
      for (int i = 0; i < v.size(); i++) {
        JmolEdge bond = (JmolEdge) v.get(i);
        JmolNode a = bond.getOtherAtom(atom);
        int n = a.getCovalentBondCount() - a.getCovalentHydrogenCount();
        int order = bond.getCovalentOrder();
        if (order == 1 && n == 1 && i < v.size() - (bond0 == null ? 1 : 0)) {
          bsBranches.set(bond.getIndex());
        } else if ((order > 1 || n > nMax)
            && !htRings.containsKey(getRingKey(a.getIndex(), atomIndex))) {
          nMax = (order > 1 ? 1000 + order : n);
          bond0 = bond;
        }
      }
    JmolNode atomNext = (bond0 == null ? null : bond0.getOtherAtom(atom));
    int orderNext = (bond0 == null ? 0 : bond0.getCovalentOrder());

    if (stereoFlag < 7 && bondPrev != null) {
      if (bondPrev.getCovalentOrder() == 2 && orderNext == 2
          && prevSp2Atoms != null && prevSp2Atoms[1] != null) {
        // allene continuation
        stereo[stereoFlag++] = prevSp2Atoms[0];
        stereo[stereoFlag++] = prevSp2Atoms[1];
      } else {
        stereo[stereoFlag++] = prevAtom;
      }
    }

    if (stereoFlag < 7 && nH == 1)
      stereo[stereoFlag++] = aH;

    boolean deferStereo = (orderNext == 1 && prevSp2Atoms == null);
    char chBond = getBondStereochemistry(bondPrev, prevAtom);

    // now construct the branches part

    StringBuffer sMore = new StringBuffer();
    for (int i = 0; i < v.size(); i++) {
      JmolEdge bond = (JmolEdge) v.get(i);
      if (!bsBranches.get(bond.getIndex()))
        continue;
      JmolNode a = bond.getOtherAtom(atom);
      StringBuffer s2 = new StringBuffer();
      s2.append("(");
      prevAtom = atom;
      prevSp2Atoms = null;
      JmolEdge bond0t = bond0;
      getSmiles(s2, a, allowConnectionsToOutsideWorld, allowBranches);
      bond0 = bond0t;
      s2.append(")");
      if (sMore.indexOf(s2.toString()) >= 0)
        stereoFlag = 10;
      sMore.append(s2);
      v.remove(i--);
      if (stereoFlag < 7)
        stereo[stereoFlag++] = a;
      if (nSp2Atoms < 5)
        sp2Atoms[nSp2Atoms++] = a;
    }

    // from here on, prevBondAtoms and prevAtom must not be used.   

    // process the bond to the next atom
    // and cancel any double bond stereochemistry if nec.

    int index2 = (orderNext == 2 ? atomNext.getIndex() : -1);
    if (nH > 1 || isAromatic || index2 < 0
        || SmilesSearch.isRingBond(ringSets, atomIndex, index2)) {
      nSp2Atoms = -1;
    }
    if (nSp2Atoms < 0) {
      sp2Atoms = null;
    }

    // output section

    if (strBond != null || chBond != '\0') {
      if (chBond != '\0') {
        strBond = "" + chBond;
      }
      sb.append(strBond);
    }

    // now process any rings

    String atat = null;
    if (!allowBranches && (v.size() == 5 || v.size() == 6))
      atat = sortInorganic(atom, v);
    for (int i = 0; i < v.size(); i++) {
      JmolEdge bond = (JmolEdge) v.get(i);
      if (bond == bond0)
        continue;
      JmolNode a = bond.getOtherAtom(atom);
      String s = getRingCache(atomIndex, a.getIndex(), htRings);
      strBond = SmilesBond.getBondOrderString(bond.getOrder());
      if (!deferStereo) {
        chBond = getBondStereochemistry(bond, atom);
        if (chBond != '\0') {
          strBond = "" + chBond;
View Full Code Here

  private String sortInorganic(JmolNode atom, List v) {
    int atomIndex = atom.getIndex();
    int n = v.size();
    List axialPairs = new ArrayList();
    List bonds = new ArrayList();
    JmolNode a1, a2;
    JmolEdge bond1, bond2;
    BitSet bsDone = new BitSet();
    JmolEdge[] pair0 = null;
    JmolNode[] stereo = new JmolNode[6];
    boolean isOK = true; // AX6 or AX5
View Full Code Here

   * @param nAtoms
   * @param v
   * @return        String
   */
  private static String getStereoFlag(JmolNode atom0, JmolNode[] atoms, int nAtoms, VTemp v) {
    JmolNode atom1 = atoms[0];
    JmolNode atom2 = atoms[1];
    JmolNode atom3 = atoms[2];
    JmolNode atom4 = atoms[3];
    JmolNode atom5 = atoms[4];
    JmolNode atom6 = atoms[5];
    int chiralClass = SmilesAtom.STEREOCHEMISTRY_TETRAHEDRAL;
    switch (nAtoms) {
    default:
    case 5:
    case 6:
View Full Code Here

        }
      }
    }
    if (needRingData) {
      for (int i = bsSelected.nextSetBit(0); i >= 0; i = bsSelected.nextSetBit(i + 1)) {
        JmolNode atom = jmolAtoms[i];
        JmolEdge[] bonds = atom.getEdges();
        if (bonds != null)
          for (int k = bonds.length; --k >= 0;)
            if (ringCounts[atom.getBondedAtomIndex(k)] > 0)
              ringConnections[i]++;
      }
    }
  }
View Full Code Here

   */
  private final boolean checkMatch(SmilesAtom patternAtom, int atomNum,
                                   int iAtom, boolean firstAtomOnly)
      throws InvalidSmilesException {

    JmolNode jmolAtom;
    JmolEdge[] jmolBonds;
    if (patternAtom == null) {
      // first atom in pattern
      if (nestedBond == null)
        bsFound.clear();
      else
        bsReturn.clear();
    } else {
      // check for requested selection or not-selection

      if (bsFound.get(iAtom) || !bsSelected.get(iAtom))
        return true;

      jmolAtom = jmolAtoms[iAtom];

      if (!isRingCheck) {
        // check atoms
        if (patternAtom.atomsOr != null) {
          for (int ii = 0; ii < patternAtom.nAtomsOr; ii++)
            if (!checkMatch(patternAtom.atomsOr[ii], atomNum, iAtom,
                firstAtomOnly))
              return false;
          return true;
        }

        if (patternAtom.primitives == null) {
          if (!checkPrimitiveAtom(patternAtom, iAtom))
            return true;
        } else {
          for (int i = 0; i < patternAtom.nPrimitives; i++)
            if (!checkPrimitiveAtom(patternAtom.primitives[i], iAtom))
              return true;
        }
      }
      // Check bonds

      jmolBonds = jmolAtom.getEdges();
      for (int i = patternAtom.getBondCount(); --i >= 0;) {
        SmilesBond patternBond = patternAtom.getBond(i);
        // Check only if the current atom is the second atom of the bond
        if (patternBond.getAtomIndex2() != patternAtom.index)
          continue;
View Full Code Here

  }

  private boolean continueMatch(int atomNum, int iAtom, boolean firstAtomOnly)
      throws InvalidSmilesException {

    JmolNode jmolAtom;
    JmolEdge[] jmolBonds;

    if (++atomNum < atomCount) {

      // so far, so good... not done yet... on to the next position...

      SmilesAtom newPatternAtom = patternAtoms[atomNum];
      // For all the pattern bonds for this atom...
      // find the bond to atoms already assigned.
      // If it is not there, then it means this is a
      // new component.

      // the nestedBond may be set to previous search
      SmilesBond newPatternBond = (iAtom >= 0 ? newPatternAtom.getBondTo(null)
          : atomNum == 0 ? nestedBond : null);
      if (newPatternBond == null) {

        // Option 1: we are processing "."
        // run through all unmatched and unbonded-to-match
        // selected Jmol atoms to see if there is a match.

        BitSet bs = (BitSet) bsFound.clone();
        if (newPatternAtom.notBondedIndex >= 0) {
          SmilesAtom pa = patternAtoms[newPatternAtom.notBondedIndex];
          JmolNode a = jmolAtoms[pa.getMatchingAtom()];
          if (pa.bioType == '\0') {
            // clear out all atoms connected to the last atom only
            jmolBonds = a.getEdges();
            for (int k = 0; k < jmolBonds.length; k++)
              bs.set(jmolBonds[k].getOtherAtom(a).getIndex());
          } else {
            // clear out adjacent residues
            int ii = a.getOffsetResidueAtom("0", 1);
            if (ii >= 0)
              bs.set(ii);
            ii = a.getOffsetResidueAtom("0", -1);
            if (ii >= 0)
              bs.set(ii);
          }
        }
        boolean skipGroup = (iAtom >= 0 && newPatternAtom.isBioAtom && (newPatternAtom.atomName == null || newPatternAtom.residueChar != null));
View Full Code Here

TOP

Related Classes of org.jmol.api.JmolNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.