/**
   * iterator over the Tokens in the given ring, starting with the token for the node owning start
   * (which does not have to be a Token in the ring)
   *
   * @param includeMin True if the minimum token should be returned in the ring even if it has no
   *     owner.
   */
  public static Iterator<Token> ringIterator(
      final ArrayList<Token> ring, Token start, boolean includeMin) {
    if (ring.isEmpty())
      return includeMin
          ? Iterators.singletonIterator(StorageService.getPartitioner().getMinimumToken())
          : Iterators.<Token>emptyIterator();

    final boolean insertMin = includeMin && !ring.get(0).isMinimum();
    final int startIndex = firstTokenIndex(ring, start, insertMin);
    return new AbstractIterator<Token>() {
      int j = startIndex;

      protected Token computeNext() {
        if (j < -1) return endOfData();
        try {
          // return minimum for index == -1
          if (j == -1) return StorageService.getPartitioner().getMinimumToken();
          // return ring token for other indexes
          return ring.get(j);
        } finally {
          j++;
          if (j == ring.size()) j = insertMin ? -1 : 0;
          if (j == startIndex)
            // end iteration
            j = -2;
        }
      }
    };
  }
 public static int firstTokenIndex(final ArrayList ring, Token start, boolean insertMin) {
   assert ring.size() > 0;
   // insert the minimum token (at index == -1) if we were asked to include it and it isn't a
   // member of the ring
   int i = Collections.binarySearch(ring, start);
   if (i < 0) {
     i = (i + 1) * (-1);
     if (i >= ring.size()) i = insertMin ? -1 : 0;
   }
   return i;
 }
Beispiel #3
0
 /*
  * Recursive descent into subclusters.
  */
 private static void flatten(ArrayList<Cluster> flattened, Collection<Cluster> clusters) {
   for (Cluster c : clusters) {
     flattened.add(c);
     final List<Cluster> subclusters = c.getSubclusters();
     if (!subclusters.isEmpty()) {
       flatten(flattened, subclusters);
     }
   }
 }
Beispiel #4
0
  public String toString(Molecule molecule) {
    // write header
    String returnString =
        String.format(
            "%%mem=%dGB\n%%nprocshared=%d\n#p geom=connect %s/genecp empiricaldispersion=gd3bj opt\n",
            mem, nprocshared, method);
    returnString += "\ntitle\n\n0 1\n";

    // write geometry
    returnString = returnString + molecule.getGJFstring() + "\n";

    // initialize some variables
    Atom fromAtom = null;
    Atom toAtom = null;
    Integer fromAtomNumber = 0;
    Integer toAtomNumber = 0;
    Double bondOrder = 0.0;
    DefaultWeightedEdge thisEdge = null;

    // read connectivity data into parallel arrays
    ArrayList<Integer> fromAtoms = new ArrayList<Integer>();
    ArrayList<Integer> toAtoms = new ArrayList<Integer>();
    ArrayList<Double> bondOrders = new ArrayList<Double>();
    ArrayList<Boolean> visited = new ArrayList<Boolean>();
    for (DefaultWeightedEdge e : molecule.connectivity.edgeSet()) {
      fromAtom = molecule.connectivity.getEdgeSource(e);
      fromAtomNumber = molecule.contents.indexOf(fromAtom) + 1;
      toAtom = molecule.connectivity.getEdgeTarget(e);
      toAtomNumber = molecule.contents.indexOf(toAtom) + 1;
      bondOrder = molecule.connectivity.getEdgeWeight(e);

      fromAtoms.add(fromAtomNumber);
      toAtoms.add(toAtomNumber);
      bondOrders.add(bondOrder);
      visited.add(false);
    }

    // write connectivity data
    for (int i = 0; i < molecule.contents.size(); i++) {
      returnString = returnString + (i + 1) + " ";
      for (int j = 0; j < fromAtoms.size(); j++) {
        if (fromAtoms.get(j) == i + 1 && visited.get(j) == false) {
          returnString =
              returnString + toAtoms.get(j) + " " + String.format("%.1f ", bondOrders.get(j));
          visited.set(j, true);
        }
        if (toAtoms.get(j) == i + 1 && visited.get(j) == false) {
          returnString =
              returnString + fromAtoms.get(j) + " " + String.format("%.1f ", bondOrders.get(j));
          visited.set(j, true);
        }
      }
      returnString = returnString + "\n";
    }

    // write footer
    returnString += String.format("\n@%s\n\n", basis);
    return returnString;
  }
 public static Token firstToken(final ArrayList<Token> ring, Token start) {
   return ring.get(firstTokenIndex(ring, start, false));
 }