Encodes the bond at index (bondIdx) to a SMARTS
expression that matches itself.

@param bondIdx bond index
@param beg     atom index of first atom
@param end     atom index of second atom
@return SMARTS bond expression
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());
        }
    }
500277
private int getNearestBondtoAGivenAtom(IAtomContainer mol, IAtom atom, IBond bond) {
        int nearestBond = 0;
        double[] values;
        double distance = 0;
        IAtom atom0 = bond.getBegin();
        List<IBond> bondsAtLeft = mol.getConnectedBondsList(atom0);
        int partial;
        for (int i = 0; i < bondsAtLeft.size(); i++) {
            IBond curBond = bondsAtLeft.get(i);
            values = calculateDistanceBetweenAtomAndBond(atom, curBond);
            partial = mol.indexOf(curBond);
            if (i == 0) {
                nearestBond = mol.indexOf(curBond);
                distance = values[0];
            } else {
                if (values[0] < distance) {
                    nearestBond = partial;
                }
            }
        }
        return nearestBond;

    }
259810
def lines(self):
        '''

        '''
        if "bonds" not in self.topology:
            return

        bond_start, bond_end = zip(*self.topology['bonds'])
        bond_start = np.array(bond_start)
        bond_end = np.array(bond_end)

        color_array = np.array([get_atom_color(t) for t in self.topology['atom_types']])
        lines = self.add_representation('lines', {'startCoords': self.coordinates[bond_start],
                                                  'endCoords': self.coordinates[bond_end],
                                                  'startColors': color_array[bond_start].tolist(),
                                                  'endColors': color_array[bond_end].tolist()})

        def update(self=self, lines=lines):
            bond_start, bond_end = zip(*self.topology['bonds'])
            bond_start = np.array(bond_start)
            bond_end = np.array(bond_end)

            self.update_representation(lines, {'startCoords': self.coordinates[bond_start],
                                                 'endCoords': self.coordinates[bond_end]})
        self.update_callbacks.append(update)
        self.autozoom(self.coordinates)
38094
public static int markRingAtomsAndBonds(IAtomContainer mol) {
        EdgeToBondMap bonds = EdgeToBondMap.withSpaceFor(mol);
        return markRingAtomsAndBonds(mol, GraphUtil.toAdjList(mol, bonds), bonds);
    }
1321836
private void checkBond(IAtomContainer atomContainer, int index) throws CDKException {
        IBond bond = atomContainer.getBond(index);

        if (bond != null && bond.getFlag(CDKConstants.SINGLE_OR_DOUBLE)) {
            try {
                oldBondOrder = bond.getOrder();
                bond.setOrder(IBond.Order.SINGLE);
                setMaxBondOrder(bond, atomContainer);
            } catch (CDKException e) {
                bond.setOrder(oldBondOrder);
                logger.debug(e);
            }
        }
    }
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;
    }
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;
    }
810488
private static IAtom findPiBondedOxygen(IAtomContainer container, IAtom atom) {
        for (IBond bond : container.getConnectedBondsList(atom)) {
            if (bond.getOrder() == IBond.Order.DOUBLE) {
                IAtom neighbor = bond.getOther(atom);
                int charge = neighbor.getFormalCharge() == null ? 0 : neighbor.getFormalCharge();
                if (neighbor.getAtomicNumber() == 8 && charge == 0) return neighbor;
            }
        }
        return null;
    }
105928
public double getBondLengthValue(String id1, String id2) {
        String dkey = "";
        if (pSet.containsKey(("bond" + id1 + ";" + id2))) {
            dkey = "bond" + id1 + ";" + id2;
        } else if (pSet.containsKey(("bond" + id2 + ";" + id1))) {
            dkey = "bond" + id2 + ";" + id1;
        } else {
            logger.warn("KEYError: Unknown distance key in pSet: " + id2 + ";" + id1
                               + " take default bond length: " + DEFAULT_BOND_LENGTH);
            return DEFAULT_BOND_LENGTH;
        }
        return ((Double) (pSet.get(dkey).get(0))).doubleValue();
    }
162430
private boolean isStereoBond(IBond bond) {
        return bond.getStereo() != IBond.Stereo.NONE && bond.getStereo() != (IBond.Stereo) CDKConstants.UNSET
                && bond.getStereo() != IBond.Stereo.E_Z_BY_COORDINATES;
    }
342346
public static IBond deref(IBond bond) {
        while (bond instanceof BondRef)
            bond = ((BondRef) bond).deref();
        return bond;
    }
754542
def _write_bond_information(gsd_file, structure):
    

    gsd_file.bonds.N = len(structure.bonds)

    unique_bond_types = set()
    for bond in structure.bonds:
        t1, t2 = bond.atom1.type, bond.atom2.type
        if t1 == '' or t2 == '':
            t1, t2 = bond.atom1.name, bond.atom2.name
        t1, t2 = sorted([t1, t2], key=natural_sort)
        try:
            bond_type = ('-'.join((t1, t2)))
        except AttributeError: # no forcefield applied, bond.type is None
            bond_type = ('-'.join((t1, t2)), 0.0, 0.0)
        unique_bond_types.add(bond_type)
    unique_bond_types = sorted(list(unique_bond_types), key=natural_sort)
    gsd_file.bonds.types = unique_bond_types

    bond_typeids = []
    bond_groups = []
    for bond in structure.bonds:
        t1, t2 = bond.atom1.type, bond.atom2.type
        if t1 == '' or t2 == '':
            t1, t2 = bond.atom1.name, bond.atom2.name
        t1, t2 = sorted([t1, t2], key=natural_sort)
        try:
            bond_type = ('-'.join((t1, t2)))
        except AttributeError: # no forcefield applied, bond.type is None
            bond_type = ('-'.join((t1, t2)), 0.0, 0.0)
        bond_typeids.append(unique_bond_types.index(bond_type))
        bond_groups.append((bond.atom1.idx, bond.atom2.idx))

    gsd_file.bonds.typeid = bond_typeids
    gsd_file.bonds.group = bond_groups
696233
static boolean isPlainBond(IBond bond) {
        return bond.getOrder() == IBond.Order.SINGLE
                && (bond.getStereo() == IBond.Stereo.NONE || bond.getStereo() == null);
    }
562364
private void stretch(IntStack stack, IAtom beg, IAtom end, double amount) {
        Point2d begPoint = beg.getPoint2d();
        Point2d endPoint = end.getPoint2d();

        if (begPoint.distance(endPoint) + amount > MAX_BOND_LENGTH)
            return;

        Vector2d vector = new Vector2d(endPoint.x - begPoint.x, endPoint.y - begPoint.y);
        vector.normalize();
        vector.scale(amount);

        for (int i = 0; i < stack.len; i++)
            atoms[stack.xs[i]].getPoint2d().add(vector);
    }
1283858
private void bendOrStretch(Collection<AtomPair> pairs) {

        // without checking which bonds have been bent/stretch already we
        // could end up repeating a lot of repeated work to no avail
        Map<IBond,AtomPair> bendVisit    = new HashMap<>();
        Map<IBond,AtomPair> stretchVisit = new HashMap<>();

        IntStack bendStack = new IntStack(atoms.length);
        IntStack stretchStack = new IntStack(atoms.length);

        for (AtomPair pair : pairs) {

            double score = congestion.score();

            // each attempt will be more aggressive/distorting
            for (pair.attempt = 1; pair.attempt <= 3; pair.attempt++) {

                bendStack.clear();
                stretchStack.clear();

                // attempt both bending and stretching storing the
                // best result in the provided buffer
                double bendScore    = bend(pair, bendStack, buffer1, bendVisit);
                double stretchScore = stretch(pair, stretchStack, buffer2, stretchVisit);

                // bending is better than stretching
                if (bendScore < stretchScore && bendScore < score) {
                    restoreCoords(bendStack, buffer1);
                    congestion.update(bendStack.xs, bendStack.len);
                    break;
                }

                // stretching is better than bending
                else if (bendScore > stretchScore && stretchScore < score) {
                    restoreCoords(stretchStack, buffer2);
                    congestion.update(stretchStack.xs, stretchStack.len);
                    break;
                }

            }
        }
    }
1038907
def restrict_bond_dict(self, bond_dict):
        
        return {j: bond_dict[j] & set(self.index) for j in self.index}
37670
private boolean isSP2Bond(IBond bond) {
        return bond.getAtomCount() == 2 && bond.getBegin().getHybridization() == Hybridization.SP2
               && bond.getEnd().getHybridization() == Hybridization.SP2;
    }