Utility method to dereference an bond pointer. If the bond is not
an {@link BondRef} it simply returns the input.

@param bond the bond
@return non-pointer bond
342346
public static IBond deref(IBond bond) {
        while (bond instanceof BondRef)
            bond = ((BondRef) bond).deref();
        return bond;
    }
295785
private IAtom getNextAtomWithAliphaticUnplacedNeigbors() {
        IBond bond;
        for (int f = 0; f < molecule.getBondCount(); f++) {
            bond = molecule.getBond(f);

            if (bond.getEnd().getFlag(CDKConstants.ISPLACED) && !bond.getBegin().getFlag(CDKConstants.ISPLACED)) {
                return bond.getEnd();
            }

            if (bond.getBegin().getFlag(CDKConstants.ISPLACED) && !bond.getEnd().getFlag(CDKConstants.ISPLACED)) {
                return bond.getBegin();
            }
        }
        return null;
    }
866619
public boolean areIntersected(IBond bond1, IBond bond2) {
        double x1 = 0, x2 = 0, x3 = 0, x4 = 0;
        double y1 = 0, y2 = 0, y3 = 0, y4 = 0;
        //Point2D.Double p1 = null, p2 = null, p3 = null, p4 = null;

        x1 = bond1.getBegin().getPoint2d().x;
        x2 = bond1.getEnd().getPoint2d().x;
        x3 = bond2.getBegin().getPoint2d().x;
        x4 = bond2.getEnd().getPoint2d().x;

        y1 = bond1.getBegin().getPoint2d().y;
        y2 = bond1.getEnd().getPoint2d().y;
        y3 = bond2.getBegin().getPoint2d().y;
        y4 = bond2.getEnd().getPoint2d().y;

        Line2D.Double line1 = new Line2D.Double(new Point2D.Double(x1, y1), new Point2D.Double(x2, y2));
        Line2D.Double line2 = new Line2D.Double(new Point2D.Double(x3, y3), new Point2D.Double(x4, y4));

        if (line1.intersectsLine(line2)) {
            logger.debug("Two intersecting bonds detected.");
            return true;
        }
        return false;
    }
58482
def remove_bond(self, particle_pair):
        
        from mbuild.port import Port
        if self.root.bond_graph is None or not self.root.bond_graph.has_edge(
                *particle_pair):
            warn("Bond between {} and {} doesn't exist!".format(*particle_pair))
            return
        self.root.bond_graph.remove_edge(*particle_pair)
        bond_vector = particle_pair[0].pos - particle_pair[1].pos
        if np.allclose(bond_vector, np.zeros(3)):
            warn("Particles {} and {} overlap! Ports will not be added."
                 "".format(*particle_pair))
            return
        distance = np.linalg.norm(bond_vector)
        particle_pair[0].parent.add(Port(anchor=particle_pair[0],
                                         orientation=-bond_vector,
                                         separation=distance / 2), 'port[$]')
        particle_pair[1].parent.add(Port(anchor=particle_pair[1],
                                         orientation=bond_vector,
                                         separation=distance / 2), 'port[$]')
563174
private static int nStereoBonds(List<IBond> bonds) {
        int count = 0;
        for (IBond bond : bonds) {
            IBond.Stereo stereo = bond.getStereo();
            switch (stereo) {
            // query bonds... no configuration possible
                case E_OR_Z:
                case UP_OR_DOWN:
                case UP_OR_DOWN_INVERTED:
                    return -1;
                case UP:
                case DOWN:
                case UP_INVERTED:
                case DOWN_INVERTED:
                    count++;
                    break;
            }
        }
        return count;
    }
292065
public static int convertBondStereo(IBond bond) {
        int value = 0;
        switch (bond.getStereo()) {
            case UP:
                value = 1;
                break;
            case UP_INVERTED:
                value = 1;
                break;
            case DOWN:
                value = 6;
                break;
            case DOWN_INVERTED:
                value = 6;
                break;
            case UP_OR_DOWN:
                value = 4;
                break;
            case UP_OR_DOWN_INVERTED:
                value = 4;
                break;
            case E_OR_Z:
                value = 3;
                break;
            default:
                value = 0;
        }
        return value;
    }
349340
private String encodeBondExpr(int bondIdx, int beg, int end) {
        IBond bond = mol.getBond(bondIdx);
        if (bond.getOrder() == null)
            return "";

        boolean bArom = bond.isAromatic();
        boolean aArom = mol.getAtom(beg).isAromatic() && mol.getAtom(end).isAromatic();
        switch (bond.getOrder()) {
            case SINGLE:
                if (bArom) {
                    return aArom ? "" : ":";
                } else {
                    return aArom ? "-" : "";
                }
            case DOUBLE:
                return bArom ? "" : "=";
            case TRIPLE:
                return "#";
            default:
                throw new IllegalArgumentException("Unsupported bond type: " + bond.getOrder());
        }
    }
1233548
public static boolean isValidDoubleBondConfiguration(IAtomContainer container, IBond bond) {
        //org.openscience.cdk.interfaces.IAtom[] atoms = bond.getAtoms();
        List<IAtom> connectedAtoms = container.getConnectedAtomsList(bond.getBegin());
        IAtom from = null;
        for (IAtom connectedAtom : connectedAtoms) {
            if (!connectedAtom.equals(bond.getEnd())) {
                from = connectedAtom;
            }
        }
        boolean[] array = new boolean[container.getBondCount()];
        for (int i = 0; i < array.length; i++) {
            array[i] = true;
        }
        if (isStartOfDoubleBond(container, bond.getBegin(), from, array)
                && isEndOfDoubleBond(container, bond.getEnd(), bond.getBegin(), array)
                && !bond.getFlag(CDKConstants.ISAROMATIC)) {
            return (true);
        } else {
            return (false);
        }
    }
406492
private IBond getNextBondWithUnplacedRingAtom() {
        for (IBond bond : molecule.bonds()) {
            IAtom beg = bond.getBegin();
            IAtom end = bond.getEnd();
            if (beg.getPoint2d() != null && end.getPoint2d() != null) {
                if (end.getFlag(CDKConstants.ISPLACED) && !beg.getFlag(CDKConstants.ISPLACED) && beg.isInRing()) {
                    return bond;
                }
                if (beg.getFlag(CDKConstants.ISPLACED) && !end.getFlag(CDKConstants.ISPLACED) && end.isInRing()) {
                    return bond;
                }
            }
        }
        return null;
    }
1182360
@Override
    public ValidationReport validateBond(IBond subject) {
        ValidationReport report = new ValidationReport();
        // only consider two atom bonds
        if (subject.getAtomCount() == 2) {
            double distance = subject.getBegin().getPoint3d().distance(subject.getEnd().getPoint3d());
            if (distance > 3.0) { // should really depend on the elements
                ValidationTest badBondLengthError = new ValidationTest(subject,
                        "Bond length cannot exceed 3 Angstroms.",
                        "A bond length typically is between 0.5 and 3.0 Angstroms.");
                report.addError(badBondLengthError);
            }
        }
        return report;
    }
564595
public static IAtomContainer getRelevantAtomContainer(IChemModel chemModel, IBond bond) {
        IAtomContainer result = null;
        if (chemModel.getMoleculeSet() != null) {
            IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
            result = MoleculeSetManipulator.getRelevantAtomContainer(moleculeSet, bond);
            if (result != null) {
                return result;
            }
        }
        if (chemModel.getReactionSet() != null) {
            IReactionSet reactionSet = chemModel.getReactionSet();
            return ReactionSetManipulator.getRelevantAtomContainer(reactionSet, bond);
        }
        // This should never happen.
        return null;
    }
233679
private List<IBond> heavyBonds(final List<IBond> bonds) {
        final List<IBond> heavy = new ArrayList<IBond>(bonds.size());
        for (final IBond bond : bonds) {
            if (!(bond.getBegin().getSymbol().equals("H") && bond.getEnd().getSymbol().equals("H"))) {
                heavy.add(bond);
            }
        }
        return heavy;
    }
527297
@Override
    public List<IAtom> getConnectedAtomsList(IAtom atom) {
        List<IAtom> atomsList = new ArrayList<IAtom>();
        for (int i = 0; i < bondCount; i++) {
            if (bonds[i].contains(atom)) atomsList.add(bonds[i].getOther(atom));
        }
        return atomsList;
    }
665458
public static int convertBondOrder(IBond bond) {
        int value = 0;
        switch (bond.getOrder()) {
            case QUADRUPLE:
                value = 4;
                break;
            case TRIPLE:
                value = 3;
                break;
            case DOUBLE:
                value = 2;
                break;
            case SINGLE:
                value = 1;
                break;
            default:
                value = 0;
        }
        return value;
    }
1179936
public double calculateBondPolarizability(IAtomContainer atomContainer, IBond bond) {
        double polarizabilitiy = 0;
        IAtomContainer acH = atomContainer.getBuilder().newInstance(IAtomContainer.class, atomContainer);
        addExplicitHydrogens(acH);
        if (bond.getAtomCount() == 2) {
            polarizabilitiy += getKJPolarizabilityFactor(acH, bond.getBegin());
            polarizabilitiy += getKJPolarizabilityFactor(acH, bond.getEnd());
        }
        return (polarizabilitiy / 2);
    }
248370
public int getEnergies(IBond bond) {
        int dKJPerMol = -1;
        for (Map.Entry<Integer, BondEnergy> entry : bondEngergies.entrySet()) {
            BondEnergy bondEnergy = entry.getValue();
            if (bondEnergy.matches(bond)) {
                dKJPerMol = bondEnergy.getEnergy();
            }
        }
        return dKJPerMol;
    }
680757
@Override
    public double getBondOrderSum(IAtom atom) {
        double count = 0;
        for (int i = 0; i < bondCount; i++) {
            if (bonds[i].contains(atom)) {
                if (bonds[i].getOrder() == IBond.Order.SINGLE) {
                    count += 1;
                } else if (bonds[i].getOrder() == IBond.Order.DOUBLE) {
                    count += 2;
                } else if (bonds[i].getOrder() == IBond.Order.TRIPLE) {
                    count += 3;
                } else if (bonds[i].getOrder() == IBond.Order.QUADRUPLE) {
                    count += 4;
                }
            }
        }
        return count;
    }