Main method to be called to resolve overlap situations.

@param  ac    The atomcontainer in which the atom or bond overlap exists
@param  sssr  A ring set for this atom container if one exists, otherwhise null
769252
public double resolveOverlap(IAtomContainer ac, IRingSet sssr) {

        Vector overlappingAtoms = new Vector();
        Vector overlappingBonds = new Vector();
        logger.debug("Start of resolveOverlap");
        double overlapScore = getOverlapScore(ac, overlappingAtoms, overlappingBonds);
        if (overlapScore > 0) {
            overlapScore = displace(ac, overlappingAtoms, overlappingBonds);
        }
        logger.debug("overlapScore = " + overlapScore);
        logger.debug("End of resolveOverlap");
        return overlapScore;
    }
13618
private boolean getPresenceOfNitro(IAtomContainer ac, IAtom atom) {
        List neighbours = ac.getConnectedAtomsList(atom);
        List second = null;
        IBond bond = null;
        //int counter = 0;
        for (int i = 0; i < neighbours.size(); i++) {
            IAtom neighbour = (IAtom) neighbours.get(i);
            if (neighbour.getSymbol().equals("N")) {
                second = ac.getConnectedAtomsList(neighbour);
                for (int b = 0; b < second.size(); b++) {
                    IAtom conAtom = (IAtom) second.get(b);
                    if (conAtom.getSymbol().equals("O")) {
                        bond = ac.getBond(neighbour, conAtom);
                        if (bond.getOrder() == IBond.Order.DOUBLE) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }
28637
public void setSS(java.util.Collection<String> sS) {
        if (sS == null) {
            this.sS = null;
            return;
        }

        java.util.List<String> sSCopy = new java.util.ArrayList<String>(sS.size());
        sSCopy.addAll(sS);
        this.sS = sSCopy;
    }
357800
public boolean allHeavyAtomsPlaced(IAtomContainer ac) {
        for (int i = 0; i < ac.getAtomCount(); i++) {
            if (isUnplacedHeavyAtom(ac.getAtom(i))) {
                return false;
            }
        }
        return true;
    }
1023038
public static Dcsn cs_qr(Dcs A, Dcss S) {
        double Rx[], Vx[], Ax[], x[], Beta[];
        int i, k, p, n, vnz, p1, top, m2, len, col, rnz, s[], leftmost[], Ap[], Ai[], parent[], Rp[], Ri[], Vp[], Vi[], w[], pinv[], q[];
        Dcs R, V;
        Dcsn N;
        if (!Dcs_util.CS_CSC(A) || S == null)
            return (null);
        n = A.n;
        Ap = A.p;
        Ai = A.i;
        Ax = A.x;
        q = S.q;
        parent = S.parent;
        pinv = S.pinv;
        m2 = S.m2;
        vnz = S.lnz;
        rnz = S.unz;
        leftmost = S.leftmost;
        w = new int[m2 + n]; /* get int workspace */
        x = new double[m2]; /* get double workspace */
        N = new Dcsn(); /* allocate result */
        s = w;
        int s_offset = m2; /* s is size n */
        for (k = 0; k < m2; k++)
            x[k] = 0; /* clear workspace x */
        N.L = V = Dcs_util.cs_spalloc(m2, n, vnz, true, false); /* allocate result V */
        N.U = R = Dcs_util.cs_spalloc(m2, n, rnz, true, false); /* allocate result R */
        N.B = Beta = new double[n]; /* allocate result Beta */
        Rp = R.p;
        Ri = R.i;
        Rx = R.x;
        Vp = V.p;
        Vi = V.i;
        Vx = V.x;
        for (i = 0; i < m2; i++)
            w[i] = -1; /* clear w, to mark nodes */
        rnz = 0;
        vnz = 0;
        for (k = 0; k < n; k++) /* compute V and R */
        {
            Rp[k] = rnz; /* R(:,k) starts here */
            Vp[k] = p1 = vnz; /* V(:,k) starts here */
            w[k] = k; /* add V(k,k) to pattern of V */
            Vi[vnz++] = k;
            top = n;
            col = q != null ? q[k] : k;
            for (p = Ap[col]; p < Ap[col + 1]; p++) /* find R(:,k) pattern */
            {
                i = leftmost[Ai[p]]; /* i = min(find(A(i,q))) */
                for (len = 0; w[i] != k; i = parent[i]) /* traverse up to k */
                {
                    s[s_offset + (len++)] = i;
                    w[i] = k;
                }
                while (len > 0)
                    s[s_offset + (--top)] = s[s_offset + (--len)]; /* push path on stack */
                i = pinv[Ai[p]]; /* i = permuted row of A(:,col) */
                x[i] = Ax[p]; /* x (i) = A(:,col) */
                if (i > k && w[i] < k) /* pattern of V(:,k) = x (k+1:m) */
                {
                    Vi[vnz++] = i; /* add i to pattern of V(:,k) */
                    w[i] = k;
                }
            }
            for (p = top; p < n; p++) /* for each i in pattern of R(:,k) */
            {
                i = s[s_offset + p]; /* R(i,k) is nonzero */
                Dcs_happly.cs_happly(V, i, Beta[i], x); /* apply (V(i),Beta(i)) to x */
                Ri[rnz] = i; /* R(i,k) = x(i) */
                Rx[rnz++] = x[i];
                x[i] = 0;
                if (parent[i] == k)
                    vnz = Dcs_scatter.cs_scatter(V, i, 0, w, null, k, V, vnz);
            }
            for (p = p1; p < vnz; p++) /* gather V(:,k) = x */
            {
                Vx[p] = x[Vi[p]];
                x[Vi[p]] = 0;
            }
            Ri[rnz] = k; /* R(k,k) = norm (x) */
            double[] beta = new double[1];
            beta[0] = Beta[k];
            Rx[rnz++] = Dcs_house.cs_house(Vx, p1, beta, vnz - p1); /* [v,beta]=house(x) */
            Beta[k] = beta[0];
        }
        Rp[n] = rnz; /* finalize R */
        Vp[n] = vnz; /* finalize V */
        return N;
    }
1301961
public static void removeAtomAndConnectedElectronContainers(IChemModel chemModel, IAtom atom) {
        ICrystal crystal = chemModel.getCrystal();
        if (crystal != null) {
            if (crystal.contains(atom)) {
                crystal.removeAtom(atom);
            }
            return;
        }
        IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
        if (moleculeSet != null) {
            MoleculeSetManipulator.removeAtomAndConnectedElectronContainers(moleculeSet, atom);
        }
        IReactionSet reactionSet = chemModel.getReactionSet();
        if (reactionSet != null) {
            ReactionSetManipulator.removeAtomAndConnectedElectronContainers(reactionSet, atom);
        }
    }
21674
public static Scsn cs_qr(Scs A, Scss S) {
        float Rx[], Vx[], Ax[], x[], Beta[];
        int i, k, p, n, vnz, p1, top, m2, len, col, rnz, s[], leftmost[], Ap[], Ai[], parent[], Rp[], Ri[], Vp[], Vi[], w[], pinv[], q[];
        Scs R, V;
        Scsn N;
        if (!Scs_util.CS_CSC(A) || S == null)
            return (null);
        n = A.n;
        Ap = A.p;
        Ai = A.i;
        Ax = A.x;
        q = S.q;
        parent = S.parent;
        pinv = S.pinv;
        m2 = S.m2;
        vnz = S.lnz;
        rnz = S.unz;
        leftmost = S.leftmost;
        w = new int[m2 + n]; /* get int workspace */
        x = new float[m2]; /* get float workspace */
        N = new Scsn(); /* allocate result */
        s = w;
        int s_offset = m2; /* s is size n */
        for (k = 0; k < m2; k++)
            x[k] = 0; /* clear workspace x */
        N.L = V = Scs_util.cs_spalloc(m2, n, vnz, true, false); /* allocate result V */
        N.U = R = Scs_util.cs_spalloc(m2, n, rnz, true, false); /* allocate result R */
        N.B = Beta = new float[n]; /* allocate result Beta */
        Rp = R.p;
        Ri = R.i;
        Rx = R.x;
        Vp = V.p;
        Vi = V.i;
        Vx = V.x;
        for (i = 0; i < m2; i++)
            w[i] = -1; /* clear w, to mark nodes */
        rnz = 0;
        vnz = 0;
        for (k = 0; k < n; k++) /* compute V and R */
        {
            Rp[k] = rnz; /* R(:,k) starts here */
            Vp[k] = p1 = vnz; /* V(:,k) starts here */
            w[k] = k; /* add V(k,k) to pattern of V */
            Vi[vnz++] = k;
            top = n;
            col = q != null ? q[k] : k;
            for (p = Ap[col]; p < Ap[col + 1]; p++) /* find R(:,k) pattern */
            {
                i = leftmost[Ai[p]]; /* i = min(find(A(i,q))) */
                for (len = 0; w[i] != k; i = parent[i]) /* traverse up to k */
                {
                    s[s_offset + (len++)] = i;
                    w[i] = k;
                }
                while (len > 0)
                    s[s_offset + (--top)] = s[s_offset + (--len)]; /* push path on stack */
                i = pinv[Ai[p]]; /* i = permuted row of A(:,col) */
                x[i] = Ax[p]; /* x (i) = A(:,col) */
                if (i > k && w[i] < k) /* pattern of V(:,k) = x (k+1:m) */
                {
                    Vi[vnz++] = i; /* add i to pattern of V(:,k) */
                    w[i] = k;
                }
            }
            for (p = top; p < n; p++) /* for each i in pattern of R(:,k) */
            {
                i = s[s_offset + p]; /* R(i,k) is nonzero */
                Scs_happly.cs_happly(V, i, Beta[i], x); /* apply (V(i),Beta(i)) to x */
                Ri[rnz] = i; /* R(i,k) = x(i) */
                Rx[rnz++] = x[i];
                x[i] = 0;
                if (parent[i] == k)
                    vnz = Scs_scatter.cs_scatter(V, i, 0, w, null, k, V, vnz);
            }
            for (p = p1; p < vnz; p++) /* gather V(:,k) = x */
            {
                Vx[p] = x[Vi[p]];
                x[Vi[p]] = 0;
            }
            Ri[rnz] = k; /* R(k,k) = norm (x) */
            float[] beta = new float[1];
            beta[0] = Beta[k];
            Rx[rnz++] = Scs_house.cs_house(Vx, p1, beta, vnz - p1); /* [v,beta]=house(x) */
            Beta[k] = beta[0];
        }
        Rp[n] = rnz; /* finalize R */
        Vp[n] = vnz; /* finalize V */
        return N;
    }
208466
public static DZcsd cs_scc(DZcs A)
	{
		int n, i, k, b, nb = 0, top, xi[], pstack[], p[], r[], Ap[], ATp[], rcopy[], Blk[] ;
		DZcs AT ;
		DZcsd D ;
		if (!CS_CSC (A)) return (null) ; 		/* check inputs */
		n = A.n ; Ap = A.p ;
		D = cs_dalloc (n, 0) ;				/* allocate result */
		AT = cs_transpose (A, false) ;			/* AT = A' */
		xi = new int [2*n+1] ;				/* get workspace */
		if (D == null || AT == null || xi == null)
			return (cs_ddone (D, AT, xi, false)) ;
		Blk = xi ; rcopy = xi ;
		int rcopy_offset = n ;
		pstack = xi ;
		int pstack_offset = n ;
		p = D.p ; r = D.r ; ATp = AT.p ;
		top = n ;
		for (i = 0 ; i < n ; i++)			/* first dfs(A) to find finish times (xi) */
		{
			if (!CS_MARKED (Ap, i))
			top = cs_dfs (i, A, top, xi, 0, pstack, pstack_offset, null, 0) ;
		}
		for (i = 0 ; i < n ; i++) CS_MARK (Ap, i) ;	/* restore A; unmark all nodes*/
		top = n ; nb = n ;
		for (k = 0 ; k < n ; k++)			/* dfs(A') to find strongly connnected comp */
		{
			i = xi [k] ;				/* get i in reverse order of finish times */
			if (CS_MARKED (ATp, i)) continue ;	/* skip node i if already ordered */
			r [nb--] = top ;			/* node i is the start of a component in p */
			top = cs_dfs (i, AT, top, p, 0, pstack, pstack_offset, null, 0) ;
		}
		r [nb] = 0 ;					/* first block starts at zero; shift r up */
		for (k = nb ; k <= n ; k++) r [k-nb] = r [k] ;
		D.nb = nb = n - nb ;				/* nb = # of strongly connected components */
		for (b = 0 ; b < nb ; b++)			/* sort each block in natural order */
		{
			for (k = r [b] ; k < r [b+1] ; k++) Blk [p [k]] = b ;
		}
		for (b = 0 ; b <= nb ; b++) rcopy [rcopy_offset + b] = r [b] ;
		for (i = 0 ; i < n ; i++) p [rcopy [rcopy_offset + Blk [i]]++] = i ;
		return (D) ;
	}
203059
private SSTableReader lookupSSTable(final ColumnFamilyStore cfs, Descriptor descriptor)
    {
        for (SSTableReader sstable : cfs.getSSTables())
        {
            if (sstable.descriptor.equals(descriptor))
                return sstable;
        }
        return null;
    }
865943
private static List<AtomNode> atomSegment(String sSentence, int start, int end)
    {
        if (end < start)
        {
            throw new RuntimeException("start=" + start + " < end=" + end);
        }
        List<AtomNode> atomSegment = new ArrayList<AtomNode>();
        int pCur = 0, nCurType, nNextType;
        StringBuilder sb = new StringBuilder();
        char c;


        //==============================================================================================
        // by zhenyulu:
        //
        // TODO: 使用一系列正则表达式将句子中的完整成分（百分比、日期、电子邮件、URL等）预先提取出来
        //==============================================================================================

        char[] charArray = sSentence.substring(start, end).toCharArray();
        int[] charTypeArray = new int[charArray.length];

        // 生成对应单个汉字的字符类型数组
        for (int i = 0; i < charArray.length; ++i)
        {
            c = charArray[i];
            charTypeArray[i] = CharType.get(c);

            if (c == '.' && i < (charArray.length - 1) && CharType.get(charArray[i + 1]) == CharType.CT_NUM)
                charTypeArray[i] = CharType.CT_NUM;
            else if (c == '.' && i < (charArray.length - 1) && charArray[i + 1] >= '0' && charArray[i + 1] <= '9')
                charTypeArray[i] = CharType.CT_SINGLE;
            else if (charTypeArray[i] == CharType.CT_LETTER)
                charTypeArray[i] = CharType.CT_SINGLE;
        }

        // 根据字符类型数组中的内容完成原子切割
        while (pCur < charArray.length)
        {
            nCurType = charTypeArray[pCur];

            if (nCurType == CharType.CT_CHINESE || nCurType == CharType.CT_INDEX ||
                nCurType == CharType.CT_DELIMITER || nCurType == CharType.CT_OTHER)
            {
                String single = String.valueOf(charArray[pCur]);
                if (single.length() != 0)
                    atomSegment.add(new AtomNode(single, nCurType));
                pCur++;
            }
            //如果是字符、数字或者后面跟随了数字的小数点“.”则一直取下去。
            else if (pCur < charArray.length - 1 && ((nCurType == CharType.CT_SINGLE) || nCurType == CharType.CT_NUM))
            {
                sb.delete(0, sb.length());
                sb.append(charArray[pCur]);

                boolean reachEnd = true;
                while (pCur < charArray.length - 1)
                {
                    nNextType = charTypeArray[++pCur];

                    if (nNextType == nCurType)
                        sb.append(charArray[pCur]);
                    else
                    {
                        reachEnd = false;
                        break;
                    }
                }
                atomSegment.add(new AtomNode(sb.toString(), nCurType));
                if (reachEnd)
                    pCur++;
            }
            // 对于所有其它情况
            else
            {
                atomSegment.add(new AtomNode(charArray[pCur], nCurType));
                pCur++;
            }
        }

//        logger.trace("原子分词:" + atomSegment);
        return atomSegment;
    }
344614
public IAtomContainer getPlacedAtomsInAtomContainer(IAtom atom, IAtomContainer ac) {

        List bonds = ac.getConnectedBondsList(atom);
        IAtomContainer connectedAtoms = atom.getBuilder().newInstance(IAtomContainer.class);
        IAtom connectedAtom = null;
        for (int i = 0; i < bonds.size(); i++) {
            connectedAtom = ((IBond) bonds.get(i)).getOther(atom);
            if (connectedAtom.getFlag(CDKConstants.ISPLACED)) {
                connectedAtoms.addAtom(connectedAtom);
            }
        }
        return connectedAtoms;
    }
415114
private static double getRmsd(int focusResn, int[] focusRes1, int[] focusRes2, AFPChain afpChain, Atom[] ca1, Atom[] ca2){



		Atom[] tmp1 = new Atom[focusResn];
		Atom[] tmp2 = new Atom[focusResn];

		for ( int i =0 ; i< focusResn;i++){
			tmp1[i] =       ca1[focusRes1[i]];
			tmp2[i] = (Atom)ca2[focusRes2[i]].clone();
			if (tmp1[i].getCoords() == null){
				System.err.println("tmp1 got null: " +i + " pos: " + focusRes1[i]);
			}
			if (tmp2[i].getCoords() == null){
				System.err.println("tmp1 got null: " +i + " pos: " + focusRes2[i]);
			}
			//XX
			//tmp2[i].setParent((Group) ca2[focusRes2[i]].getParent().clone());
		}
		double rmsd = 99;
		try {
			rmsd = getRmsd(tmp1,tmp2);

		} catch (Exception e){
			e.printStackTrace();
		}
		return rmsd;

	}
95591
@Override
    public DescriptorValue calculate(IAtomContainer ac) {
        ac = clone(ac); // don't mod original
        int rotatableBondsCount = 0;
        int degree0;
        int degree1;
        IRingSet ringSet;
        try {
            ringSet = new SpanningTree(ac).getBasicRings();
        } catch (NoSuchAtomException e) {
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult(
                    (int) Double.NaN), getDescriptorNames(), e);
        }
        for (IBond bond : ac.bonds()) {
            if (ringSet.getRings(bond).getAtomContainerCount() > 0) {
                bond.setFlag(CDKConstants.ISINRING, true);
            }
        }
        for (IBond bond : ac.bonds()) {
            IAtom atom0 = bond.getBegin();
            IAtom atom1 = bond.getEnd();
            if (atom0.getSymbol().equals("H") || atom1.getSymbol().equals("H")) continue;
            if (bond.getOrder() == Order.SINGLE) {
                if ((BondManipulator.isLowerOrder(ac.getMaximumBondOrder(atom0), IBond.Order.TRIPLE))
                        && (BondManipulator.isLowerOrder(ac.getMaximumBondOrder(atom1), IBond.Order.TRIPLE))) {
                    if (!bond.getFlag(CDKConstants.ISINRING)) {

                        if (excludeAmides && (isAmide(atom0, atom1, ac) || isAmide(atom1, atom0, ac))) {
                            continue;
                        }

                        // if there are explicit H's we should ignore those bonds
                        degree0 = ac.getConnectedBondsCount(atom0) - getConnectedHCount(ac, atom0);
                        degree1 = ac.getConnectedBondsCount(atom1) - getConnectedHCount(ac, atom1);
                        if ((degree0 == 1) || (degree1 == 1)) {
                            if (includeTerminals) {
                                rotatableBondsCount += 1;
                            }
                        } else {
                            rotatableBondsCount += 1;
                        }
                    }
                }
            }
        }
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult(
                rotatableBondsCount), getDescriptorNames());

    }
957521
private static double getRmsd(Atom[] catmp1, Atom[] catmp2) throws StructureException{

		Matrix4d trans = SuperPositions.superpose(Calc.atomsToPoints(catmp1),
				Calc.atomsToPoints(catmp2));

		Calc.transform(catmp2, trans);

		//   if ( showAlig) {
		//      StructureAlignmentJmol jmol = new StructureAlignmentJmol();
		//      jmol.setTitle("AFPCHainer: getRmsd" + rmsd);
		//
		//      Chain c1 = new ChainImpl();
		//      c1.setName("A");
		//      for ( Atom a : catmp1){
		//         c1.addGroup(a.getParent());
		//      }
		//
		//      Chain c2 = new ChainImpl();
		//      c2.setName("B");
		//      for ( Atom a : catmp2){
		//         c2.addGroup(a.getParent());
		//      }
		//
		//      Structure fake = new StructureImpl();
		//      fake.setPDBCode("AFPCHainer: getRmsd" + rmsd);
		//      List<Chain> model1 = new ArrayList<Chain>();
		//      model1.add(c1);
		//      List<Chain> model2 = new ArrayList<Chain>();
		//      model2.add(c2);
		//      fake.addModel(model1);
		//      fake.addModel(model2);
		//      fake.setNmr(true);
		//
		//      jmol.setStructure(fake);
		//      jmol.evalString("select *; backbone 0.4; wireframe off; spacefill off; " +
		//      "select not protein and not solvent; spacefill on;");
		//      jmol.evalString("select */1 ; color red; model 1; ");
		//
		//      // now show both models again.
		//      jmol.evalString("model 0;");
		//   }

		return Calc.rmsd(catmp1,catmp2);
	}
1204800
public ContainerWrapper findContainer(AppContextWrapper sc) {
		ContainerRegistryBuilder cb = (ContainerRegistryBuilder) sc.getAttribute(ContainerRegistryBuilder.APPLICATION_CONTEXT_ATTRIBUTE_NAME);
		if (cb == null)
			cb = prepare(sc);
		launch(sc, cb);
		return cb.getContainerWrapper();
	}
1240068
private double getTopologicalFactors(IAtomContainer atomContainer, IAtomContainer ac) {
        /* factor for separation of charge */
        int totalNCharge1 = AtomContainerManipulator.getTotalNegativeFormalCharge(atomContainer);
        int totalPCharge1 = AtomContainerManipulator.getTotalPositiveFormalCharge(atomContainer);

        double fQ = 1.0;
        if (totalNCharge1 != 0.0) {
            fQ = 0.5;
            for (int i = 0; i < atomContainer.getBondCount(); i++) {
                IBond bond = atomContainer.getBond(i);
                if (bond.getBegin().getFormalCharge() != 0.0 && bond.getEnd().getFormalCharge() != 0.0) {
                    fQ = 0.25;
                    break;
                }
            }
        }
        /* factor, if the number of covalents bonds is decreased */
        double fB = 1.0;

        int numBond1 = 0;
        int numBond2 = 0;
        for (int i = 0; i < atomContainer.getBondCount(); i++) {
            if (atomContainer.getBond(i).getOrder() == IBond.Order.DOUBLE) numBond1 += 1;
            if (ac.getBond(i).getOrder() == IBond.Order.DOUBLE) numBond2 += 1;
        }

        if (numBond1 < /* > */numBond2) fB = 0.8;

        double fPlus = 1.0;
        if (totalNCharge1 == 0.0 && totalPCharge1 == 0.0) fPlus = 0.1;

        /* aromatic */
        double fA = 1.0;
        try {
            if (Aromaticity.cdkLegacy().apply(ac)) if (!Aromaticity.cdkLegacy().apply(atomContainer)) fA = 0.3;
        } catch (CDKException e) {
            e.printStackTrace();
        }
        logger.debug("return " + fQ * fB * fPlus * fA + "= sp:" + fQ + ", dc:" + fB + ", fPlus:" + fPlus + ", fA:" + fA);

        return fQ * fB * fPlus * fA;
    }
247150
@Override
    public void setup(IAtomContainer atomContainer, Rectangle screen) {
        this.setScale(atomContainer);
        Rectangle2D bounds = BoundsCalculator.calculateBounds(atomContainer);
        this.modelCenter = new Point2d(bounds.getCenterX(), bounds.getCenterY());
        this.drawCenter = new Point2d(screen.getCenterX(), screen.getCenterY());
        this.setup();
    }