Calculate the HBonds between different groups.
see Creighton page 147 f
Modified to use only the contact map
333700
private void calculateHBonds() {
		/**
		 * More efficient method for calculating C-Alpha pairs
		 */
		if (groups.length < 5) return;
		Iterator<AtomContact> otu = contactSet.iterator();
		while(otu.hasNext()){
			AtomContact ac = otu.next();
			Pair<Atom> pair = ac.getPair();
			Group g1 = pair.getFirst().getGroup();
			Group g2 = pair.getSecond().getGroup();
			// Now I need to get the index of the Group in the list groups
			int i = indResMap.get(g1.getResidueNumber());
			int j = indResMap.get(g2.getResidueNumber());
			// Now check this
			checkAddHBond(i,j);
			//"backwards" hbonds are not allowed
			if (j!=(i+1)) checkAddHBond(j,i);
		}
	}
1271081
def _annotate_groups(self):
        
        g = {}
        for x in self.metadata:
            g[x.id] = x

        idx = 0
        for x in self.metadata:
            if not hasattr(x, 'group'):
                x.group = idx
                idx += 1
            neighbors = set()
            for e in self.edges:
                if e.src == x.id:
                    neighbors.add(e.dst)
                if e.dst == x.id:
                    neighbors.add(e.src)
            for nb in neighbors:
                g[nb].group = min(x.group, getattr(g[nb], 'group', idx))

        # Assign the edges to the respective groups. Both "ends" of the edge
        # should share the same group so just use the first object's group.
        for e in self.edges:
            e.group = g[e.src].group

        self._max_group = idx
132305
def distance_to_contact(D, alpha=1):
    

    if callable(alpha):
        distance_function = alpha
    else:
        try:
            a = np.float64(alpha)

            def distance_function(x):
                return 1 / (x ** (1 / a))
        except TypeError:
            print("Alpha parameter must be callable or an array-like")
            raise
        except ZeroDivisionError:
            raise ValueError("Alpha parameter must be non-zero")

    m = np.max(distance_function(D[D != 0]))
    M = np.zeros(D.shape)
    M[D != 0] = distance_function(D[D != 0])
    M[D == 0] = m
    return M
330128
def _get_group_difference(self, sp_groups):
        """"""
        db_groups = set(Group.objects.all().values_list('name', flat=True))
        missing_from_db = set(sp_groups).difference(db_groups)
        missing_from_sp = db_groups.difference(sp_groups)

        return (missing_from_db, missing_from_sp)
945938
private void calcAxisFoldTypes() {
		axisTypes = new int[multiplicity];

		for (int i=0;i<this.transformations.size();i++){

			axisTypes[i] = getRotAxisType(transformations.get(i));

		}
	}
1282262
function ContactsGroupsMembersGet(options, groupId, contactId) {
    ActionAbstract.call(this, options);
    this._groupId = groupId;
    this._contactId = contactId;
}
1163465
private static BlocksGroup intersect(BlocksGroup group1, BlocksGroup group2) {
    BlocksGroup intersection = new BlocksGroup();
    List<Block> list1 = group1.blocks;
    List<Block> list2 = group2.blocks;
    int i = 0;
    int j = 0;
    while (i < list1.size() && j < list2.size()) {
      Block block1 = list1.get(i);
      Block block2 = list2.get(j);
      int c = RESOURCE_ID_COMPARATOR.compare(block1.getResourceId(), block2.getResourceId());
      if (c > 0) {
        j++;
        continue;
      }
      if (c < 0) {
        i++;
        continue;
      }
      if (c == 0) {
        c = block1.getIndexInFile() + 1 - block2.getIndexInFile();
      }
      if (c == 0) {
        // list1[i] == list2[j]
        i++;
        j++;
        intersection.blocks.add(block2);
      }
      if (c > 0) {
        // list1[i] > list2[j]
        j++;
      }
      if (c < 0) {
        // list1[i] < list2[j]
        i++;
      }
    }
    return intersection;
  }
807546
private static boolean groupTogether(Object key1, Object key2, int groupLevel) {
        if (groupLevel == 0 || !(key1 instanceof List) || !(key2 instanceof List)) {
            return key1.equals(key2);
        }
        @SuppressWarnings("unchecked")
        List<Object> key1List = (List<Object>) key1;
        @SuppressWarnings("unchecked")
        List<Object> key2List = (List<Object>) key2;

        // if either key list is smaller than groupLevel and the key lists are different
        // sizes, they cannot be equal.
        if ((key1List.size() < groupLevel || key2List.size() < groupLevel) &&
                key1List.size() != key2List.size()) {
            return false;
        }

        int end = Math.min(groupLevel, Math.min(key1List.size(), key2List.size()));
        for (int i = 0; i < end; ++i) {
            if (key1List.get(i) != null && !key1List.get(i).equals(key2List.get(i)))
                return false;
            else if (key1List.get(i) == null && key2List.get(i) != null)
                return false;
        }
        return true;
    }
544236
private int calculateClosest(float base, float[] others) {

        int result = -1;
        float bestMatch = Float.MAX_VALUE;
        for (int count = 0; count < others.length; count++) {
            float difference = Math.abs(base - others[count]);
            if (difference < bestMatch) {
                // new best match found
                bestMatch = difference;
                result = count;
            }
            if (bestMatch == 0f) {
                // it does not get better then this
                break;
            }
        }
        return result;
    }
125218
def join_conn_groups( conns, descs, mat_ids, concat = False ):
    """"""

    el = dict_from_keys_init( descs, list )
    for ig, desc in enumerate( descs ):
        el[desc].append( ig )
    groups = [ii for ii in el.values() if ii]
##     print el, groups

    descs_out, conns_out, mat_ids_out = [], [], []
    for group in groups:
        n_ep = conns[group[0]].shape[1]

        conn = nm.zeros( (0, n_ep), nm.int32 )
        mat_id = nm.zeros( (0,), nm.int32 )
        for ig in group:
            conn = nm.concatenate( (conn, conns[ig]) )
            mat_id = nm.concatenate( (mat_id, mat_ids[ig]) )

        if concat:
            conn = nm.concatenate( (conn, mat_id[:,nm.newaxis]), 1 )
        else:
            mat_ids_out.append( mat_id )
        conns_out.append( conn )
        descs_out.append( descs[group[0]] )

    if concat:
        return conns_out, descs_out
    else:
        return conns_out, descs_out, mat_ids_out
106985
function (np, grs, adv, numGroups) {
  // the group size in here refers to the maximal reduced group size
  if (np < 2) {
    return 'needs at least 2 players';
  }
  if (grs < 2) {
    return 'group size must be at least 2';
  }
  if (adv >= grs) {
    return 'must advance less than the group size';
  }
  var isUnfilled = (np % numGroups) > 0;
  if (isUnfilled && adv >= grs - 1) {
    return 'must advance less than the smallest match size';
  }
  if (adv <= 0) {
    return 'must eliminate players each match';
  }
  return null;
}
400051
def cluster_number(self, data, maxgap): 
        '''

        '''

        data.sort()
        groups = [[data[0]]]
        for x in data[1:]:
            if abs(x - groups[-1][-1]) <= maxgap:
                groups[-1].append(x)
            else:
                groups.append([x])
        return groups
396496
def neighbors_of( p )
      Set.new.tap do |neighbors|
        i = index_mapping[p]
        (0..index_mapping.size-1).each do |j|
          neighbors.add(points[j]) if adjacency_matrix.lookup(i,j) <= eps
        end
      end
    end
509634
function(bgp, toJoin, newGroups, newGroupVars) {
        var acumGroups = [];
        var acumId = "";
        var acumVars = "";
        for(var gid in toJoin) {
            acumId = acumId+gid; // new group id
            acumGroups = acumGroups.concat(groups[gid]);
            acumVars = acumVars + groupVars[gid]; // @todo bug here? we were not adding...
        }

        acumVars = acumVars + vars.join("/") + "/";
        acumGroups.push(bgp);

        newGroups[acumId] = acumGroups;
        newGroupVars[acumId] = acumVars;
    }
992825
public double spread(Front front, Front referenceFront) {
    PointDistance distance = new EuclideanDistance() ;

    // STEP 1. Sort normalizedFront and normalizedParetoFront;
    front.sort(new LexicographicalPointComparator());
    referenceFront.sort(new LexicographicalPointComparator());

    // STEP 2. Compute df and dl (See specifications in Deb's description of the metric)
    double df = distance.compute(front.getPoint(0), referenceFront.getPoint(0)) ;
    double dl = distance.compute(front.getPoint(front.getNumberOfPoints() - 1),
        referenceFront.getPoint(referenceFront.getNumberOfPoints() - 1)) ;

    double mean = 0.0;
    double diversitySum = df + dl;

    int numberOfPoints = front.getNumberOfPoints() ;

    // STEP 3. Calculate the mean of distances between points i and (i - 1).
    // (the points are in lexicografical order)
    for (int i = 0; i < (numberOfPoints - 1); i++) {
      mean += distance.compute(front.getPoint(i), front.getPoint(i + 1));
    }

    mean = mean / (double) (numberOfPoints - 1);

    // STEP 4. If there are more than a single point, continue computing the
    // metric. In other case, return the worse value (1.0, see metric's description).
    if (numberOfPoints > 1) {
      for (int i = 0; i < (numberOfPoints - 1); i++) {
        diversitySum += Math.abs(distance.compute(front.getPoint(i),
            front.getPoint(i + 1)) - mean);
      }
      return diversitySum / (df + dl + (numberOfPoints - 1) * mean);
    } else {
      return 1.0;
    }
  }
714849
def fiGroupFromLinkageGroup(matchArr, arrPos, groupId, timeKey, massKey):
    
    fgi = Fgi(groupId)
    matchArr['isAnnotated'][arrPos]

    minT = numpy.min(matchArr[timeKey][arrPos])
    maxT = numpy.max(matchArr[timeKey][arrPos])
    minM = numpy.min(matchArr[massKey][arrPos])
    maxM = numpy.max(matchArr[massKey][arrPos])

    fgi.isValid = True
    fgi.specfiles = matchArr['specfile'][arrPos].tolist()
    fgi.featureIds = matchArr['id'][arrPos].tolist()
    fgi.isAnnotated = numpy.any(matchArr['isAnnotated'][arrPos])
    fgi.coordinates = ((minT, maxT), (minM, maxM))
    #fgi.clusterType = clusterType

    return fgi
1285839
function( data ){

            var bodies = this.getTargets()
                ,dt = data.dt
                ,bodyA
                ,bodyB
                ,collisions = []
                ,ret
                ,prevContacts = this.prevContacts || {}
                ,contactList = {}
                ,pairHash = Physics.util.pairHash
                ,hash
                ;

            for ( var j = 0, l = bodies.length; j < l; j++ ){

                bodyA = bodies[ j ];

                for ( var i = j + 1; i < l; i++ ){

                    bodyB = bodies[ i ];

                    ret = checkPair( bodyA, bodyB );

                    if ( ret instanceof Array ){

                        for ( var k = 0, r, ll = ret.length; k < ll; k++ ){
                            r = ret[k];
                            if ( r ){
                                hash = pairHash( bodyA.uid, bodyB.uid );
                                contactList[ hash ] = true;
                                r.collidedPreviously = prevContacts[ hash ];
                                collisions.push( r );
                            }
                        }

                    } else if ( ret ){
                        hash = pairHash( bodyA.uid, bodyB.uid );
                        contactList[ hash ] = true;
                        ret.collidedPreviously = prevContacts[ hash ];

                        collisions.push( ret );
                    }
                }
            }

            this.prevContacts = contactList;

            if ( collisions.length ){

                this._world.emit( this.options.channel, {
                    collisions: collisions
                });
            }
        }