Пример #1
0
 /**
  * Checks if each next {@link ILigand} is different from the previous one according to the {@link
  * CIPLigandRule}. It assumes that the input is sorted based on that rule.
  *
  * @param ligands array of {@link ILigand} to check
  * @return true, if all ligands are different
  */
 @TestMethod("testCheckIfAllLigandsAreDifferent,testCheckIfAllLigandsAreDifferent_False")
 public static boolean checkIfAllLigandsAreDifferent(ILigand[] ligands) {
   for (int i = 0; i < (ligands.length - 1); i++) {
     if (cipRule.compare(ligands[i], ligands[i + 1]) == 0) return false;
   }
   return true;
 }
Пример #2
0
  /**
   * Obtain the permutation parity (-1,0,+1) to put the ligands in descending order (highest first).
   * A parity of 0 indicates two or more ligands were equivalent.
   *
   * @param ligands the ligands to sort
   * @return parity, odd (-1), even (+1) or none (0)
   */
  private static int permParity(final ILigand[] ligands) {

    // count the number of swaps made by insertion sort - if duplicates
    // are fount the parity is 0
    int swaps = 0;

    for (int j = 1, hi = ligands.length; j < hi; j++) {
      ILigand ligand = ligands[j];
      int i = j - 1;
      int cmp = 0;
      while ((i >= 0) && (cmp = cipRule.compare(ligand, ligands[i])) > 0) {
        ligands[i + 1] = ligands[i--];
        swaps++;
      }
      if (cmp == 0) // identical entries
      return 0;
      ligands[i + 1] = ligand;
    }

    // odd (-1) or even (+1)
    return (swaps & 0x1) == 0x1 ? -1 : +1;
  }