/*
Returns Helix that has the largest number of contacts, besides
the Helix with the lowest twist angle
553554
public Helix getByLargestContactsNotLowestAngle() {
		double contacts = 0;
		Helix lowest = getByLowestAngle();
		// TODO why are there helices with almost identical helix parameters??
		double angle = lowest.getAngle() + 0.05;
		Helix largest = null;
		for (Helix helix: helices) {
			if (helix == lowest) {
				continue;
			}
			if (helix.getContacts() > contacts && helix.getAngle() > angle) {
				contacts = helix.getContacts();
				largest = helix;
			}
		}
		if (largest == null) {
			return lowest;
		}
		return largest;
	}
149985
function(meshGeom, vertAssoc, nucleotideAssoc, opts, 
                               traceIndex, chain) {
  var traces = chain.backboneTraces();
  var numVerts = _cartoonNumVerts(traces, opts.arcDetail * 4,
                                  opts.splineDetail);
  var numIndices = _cartoonNumIndices(traces, opts.arcDetail * 4,
                                      opts.splineDetail);
  // figure out which of the traces consist of nucleic acids. They require 
  // additional space for rendering the sticks.
  var nucleicAcidTraces = [];
  var vertForBaseSticks = opts.protoCyl.numVerts() + 
    2 * opts.protoSphere.numVerts();
  var indicesForBaseSticks = opts.protoCyl.numIndices() + 
    2 * opts.protoSphere.numIndices();
  for (var i = 0; i < traces.length; ++i) {
    var trace = traces[i];
    if (trace.residueAt(0).isNucleotide()) {
      nucleicAcidTraces.push(trace);
      // each DNA/RNA base gets a double-capped cylinder
      numVerts += trace.length() * vertForBaseSticks;
      numIndices += trace.length() * indicesForBaseSticks;
    }
  }
  meshGeom.addChainVertArray(chain, numVerts, numIndices);
  for (var ti = 0; ti < traces.length; ++ti) {
    traceIndex = _cartoonForSingleTrace(meshGeom, vertAssoc, traces[ti], 
                                        traceIndex, opts);
  }
  _addNucleotideSticks(meshGeom, nucleotideAssoc, nucleicAcidTraces, opts);
  return traceIndex;
}
969085
function linkedList (data, start, end, dim, clockwise) {
  var sum = 0,
    i, j, last

  // calculate original winding order of a polygon ring
  for (i = start, j = end - dim; i < end; i += dim) {
    sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1])
    j = i
  }

  // link points into circular doubly-linked list in the specified winding order
  if (clockwise === (sum > 0)) {
    for (i = start; i < end; i += dim) {
      last = insertNode(i, last)
    }
  } else {
    for (i = end - dim; i >= start; i -= dim) {
      last = insertNode(i, last)
    }
  }

  return last
}
1150741
private static int[] findLeftMostVertex(Contour contour) {
        int minx = contour.verts[0];
        int minz = contour.verts[2];
        int leftmost = 0;
        for (int i = 1; i < contour.nverts; i++) {
            int x = contour.verts[i * 4 + 0];
            int z = contour.verts[i * 4 + 2];
            if (x < minx || (x == minx && z < minz)) {
                minx = x;
                minz = z;
                leftmost = i;
            }
        }
        return new int[] { minx, minz, leftmost };
    }
776122
def bbox(self):
        
        from itertools import chain
        knots = [
            (knot.anchor[1], knot.anchor[0])
            for knot in chain.from_iterable(self.paths)
        ]
        if len(knots) == 0:
            return (0., 0., 1., 1.)
        x, y = zip(*knots)
        return (min(x), min(y), max(x), max(y))
1016110
def _pangledAnglet(self,t,angleperp,dangle,smallest):
        """"""
        if smallest: eigIndx= 0
        else: eigIndx= 1      
        if isinstance(angleperp,(int,float,numpy.float32,numpy.float64)):
            angleperp= numpy.array([angleperp])
            t= numpy.array([t])
        out= numpy.zeros_like(angleperp)
        tindx= t < self._tdisrupt
        out[tindx]=\
            numpy.exp(-0.5*angleperp[tindx]**2.\
                           /(t[tindx]**2.*self._sortedSigOEig[eigIndx]+self._sigangle2))/\
                           numpy.sqrt(t[tindx]**2.*self._sortedSigOEig[eigIndx]+self._sigangle2)\
                           *self.ptdAngle(t[t < self._tdisrupt],dangle)
        return out
862848
private Vertex[] getVertexesLineFirst()
    {
        Vertex[] vertexes = new Vertex[size];
        int i = 0;
        for (List<Vertex> vertexList : this.vertexes)
        {
            for (Vertex v : vertexList)
            {
                v.index = i;    // 设置id
                vertexes[i++] = v;
            }
        }

        return vertexes;
    }
105686
int[][] findNeighborIndicesSpatialHashing() {

		// looking at a typical protein case, number of neighbours are from ~10 to ~50, with an average of ~30
		int initialCapacity = 60;

		List<Contact> contactList = calcContacts();
		Map<Integer, List<Integer>> indices = new HashMap<>(atomCoords.length);
		for (Contact contact : contactList) {
			// note contacts are stored 1-way only, with j>i
			int i = contact.getI();
			int j = contact.getJ();

			List<Integer> iIndices;
			List<Integer> jIndices;
			if (!indices.containsKey(i)) {
				iIndices = new ArrayList<>(initialCapacity);
				indices.put(i, iIndices);
			} else {
				iIndices = indices.get(i);
			}
			if (!indices.containsKey(j)) {
				jIndices = new ArrayList<>(initialCapacity);
				indices.put(j, jIndices);
			} else {
				jIndices = indices.get(j);
			}

			double radius = radii[i] + probe + probe;
			double dist = contact.getDistance();
			if (dist < radius + radii[j]) {
				iIndices.add(j);
				jIndices.add(i);
			}
		}

		// convert map to array for fast access
		int[][] nbsIndices = new int[atomCoords.length][];
		for (Map.Entry<Integer, List<Integer>> entry : indices.entrySet()) {
			List<Integer> list = entry.getValue();
			int[] indicesArray = new int[list.size()];
			for (int i=0;i<entry.getValue().size();i++) indicesArray[i] = list.get(i);
			nbsIndices[entry.getKey()] = indicesArray;
		}

		// important: some atoms might have no neighbors at all: we need to initialise to empty arrays
		for (int i=0; i<nbsIndices.length; i++) {
			if (nbsIndices[i] == null) {
				nbsIndices[i] = new int[0];
			}
		}

		return nbsIndices;
	}
768960
public int maximumFringeImbalance()
    {
        int maxBal;
        GBSNode q = root();
        if (q.leftChild() == null)
        {
            maxBal = kFactor() - 1;
            if (maxBal < 3)
                maxBal = 3;
        }
        else
        {
            if ((kFactor() % 3) == 0)
                maxBal = kFactor() + 2;
            else
                maxBal = kFactor() + 1;
        }
        return maxBal;
    }
217815
public int knotAt(int x) {
		for (int i = 1; i < numKnots-1; i++)
			if (xKnots[i+1] > x)
				return i;
		return 1;
	}
299895
function getRotateDeg() {
      if (settings.rotateRatio === 0) {
        return 0;
      }

      if (Math.random() > settings.rotateRatio) {
        return 0;
      }

      if (rotationRange === 0) {
        return minRotation;
      }

      if (rotationSteps > 0) {
        // Min rotation + zero or more steps * span of one step
        return minRotation +
          Math.floor(Math.random() * rotationSteps) *
          rotationRange / (rotationSteps - 1);
      }
      else {
        return minRotation + Math.random() * rotationRange;
      }
    }
697161
private int getMaxOccurence(double massTo, int element_pos, int[] matrix, List<IIsotope> isoToCond_new) {
        double massIn = isoToCond_new.get(element_pos).getExactMass();
        double massToM = massTo;
        for (int i = 0; i < matrix.length; i++)
            if (i != element_pos) if (matrix[i] != 0) massToM -= isoToCond_new.get(i).getExactMass() * matrix[i];

        int value = (int) ((massToM + 1) / massIn);
        return value;
    }
1024311
Vector2d getRingCenterOfFirstRing(IRing ring, Vector2d bondVector, double bondLength) {
        int size = ring.getAtomCount();
        double radius = bondLength / (2 * Math.sin((Math.PI) / size));
        double newRingPerpendicular = Math.sqrt(Math.pow(radius, 2) - Math.pow(bondLength / 2, 2));
        /* get the angle between the x axis and the bond vector */
        double rotangle = GeometryUtil.getAngle(bondVector.x, bondVector.y);
        /*
         * Add 90 Degrees to this angle, this is supposed to be the new
         * ringcenter vector
         */
        rotangle += Math.PI / 2;
        return new Vector2d(Math.cos(rotangle) * newRingPerpendicular, Math.sin(rotangle) * newRingPerpendicular);
    }
276834
public function getMaxDepth()
    {
        $aSubvariants = $this->getMdSubvariants();

        if (!count($aSubvariants)) {
            return 0;
        }

        $iMaxDepth = 0;
        foreach ($aSubvariants as $oSubvariant) {
            if ($oSubvariant->getMaxDepth() > $iMaxDepth) {
                $iMaxDepth = $oSubvariant->getMaxDepth();
            }
        }

        return $iMaxDepth + 1;
    }
654532
def curve(self):
        """"""
        return HelicalCurve.pitch_and_radius(
            self.major_pitch, self.major_radius,
            handedness=self.major_handedness)
788605
public Helix getByLowestAngle() {
		double angle = Double.MAX_VALUE;
		Helix lowest = null;
		for (Helix helix: helices) {
			if (helix.getAngle() < angle) {
				angle = helix.getAngle();
				lowest = helix;
			}
		}
		return lowest;
	}
176171
public static void zeroTriangle( boolean upper , DMatrixRBlock A )
    {
        int blockLength = A.blockLength;

        if( upper ) {
            for( int i = 0; i < A.numRows; i += blockLength ) {
                int h = Math.min(blockLength,A.numRows-i);

                for( int j = i; j < A.numCols; j += blockLength ) {
                    int w = Math.min(blockLength,A.numCols-j);

                    int index = i*A.numCols + h*j;

                    if( j == i ) {
                        for( int k = 0; k < h; k++ ) {
                            for( int l = k+1; l < w; l++ ) {
                                A.data[index + w*k+l ] = 0;
                            }
                        }
                    } else {
                        for( int k = 0; k < h; k++ ) {
                            for( int l = 0; l < w; l++ ) {
                                A.data[index + w*k+l ] = 0;
                            }
                        }
                    }
                }
            }
        } else {
            for( int i = 0; i < A.numRows; i += blockLength ) {
                int h = Math.min(blockLength,A.numRows-i);

                for( int j = 0; j <= i; j += blockLength ) {
                    int w = Math.min(blockLength,A.numCols-j);

                    int index = i*A.numCols + h*j;

                    if( j == i ) {
                        for( int k = 0; k < h; k++ ) {
                            int z = Math.min(k,w);
                            for( int l = 0; l < z; l++ ) {
                                A.data[index + w*k+l ] = 0;
                            }
                        }
                    } else {
                        for( int k = 0; k < h; k++ ) {
                            for( int l = 0; l < w; l++ ) {
                                A.data[index + w*k+l ] = 0;
                            }
                        }
                    }
                }
            }
        }
    }