this method returns a bond bonded to this double bond
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;

    }
1063711
private Point2d reflect(Point2d p, IBond bond) {
        IAtom a = bond.getBegin();
        IAtom b = bond.getEnd();
        return reflect(p, a.getPoint2d().x, a.getPoint2d().y, b.getPoint2d().x, b.getPoint2d().y);
    }
452598
def bonds(lines, atoms):
    
    # Convert sdf style stereobond (see chem.model.bond.Bond)
    conv_stereo_table = {0: 0, 1: 1, 3: 3, 4: 3, 6: 2}
    results = {a: {} for a in atoms}
    for line in lines:
        bond = Bond()
        first = int(line[0:3])
        second = int(line[3:6])
        if first > second:
            bond.is_lower_first = 0
        order = int(line[6:9])
        if order < 4:
            bond.order = order
        bond.type = conv_stereo_table[int(line[9:12])]
        results[first][second] = {"bond": bond}
        results[second][first] = {"bond": bond}
    return results
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;
    }
564510
static Vector2d newUnitVector(final IAtom atom, final IBond bond) {
        return newUnitVector(atom.getPoint2d(), bond.getOther(atom).getPoint2d());
    }
183765
public boolean cyclic(IBond bond) {
        // XXX: linear search - but okay for now
        int u = container.indexOf(bond.getBegin());
        int v = container.indexOf(bond.getEnd());
        if (u < 0 || v < 0) throw new NoSuchElementException("atoms of the bond are not found in the container");
        return searcher.cyclic(u, v);
    }
1232455
def _add_1(self,  hydrogen_name,  heavy_atom,  bonds):
        
        
        residue = heavy_atom.parent
        ffld = self.ffld[self.selection[residue]]
        bnd_len = self.bondfield.length
        anchor = bonds[0]
                
        # If not linear
        if self.bondfield.nonlinear.has_key(ffld[(  residue.resname,  
                                                    heavy_atom.name)]['type']):
            # returns tuple of two atoms
            bonded = self._find_secondary_anchors(residue,  heavy_atom,  anchor)

            if bonded:
                # Phenolic hydrogens,  etc.
                if self.bondfield.planer.has_key(ffld[( residue.resname,  
                                                        anchor.name)]['type']):
                    secondary_anchor = bonded[0]
                   
                    p0 = heavy_atom.coord - anchor.coord
                    d2 = secondary_anchor.coord - anchor.coord
                    p1 = normalize(cross_product(d2,  p0))
                    p2 = normalize(cross_product(p0,  p1))                     
                    vector = scale(p2,  TRI_TAN)
                    vector = normalize(add(p0,  vector))
                    
                    hydrogen_coord = add(heavy_atom.coord, 
                                        scale(vector,  
                                              bnd_len[(ffld[(residue.resname, 
                                                             heavy_atom.name)]['type'], 
                                              ffld[(residue.resname,  
                                                    hydrogen_name)]['type'])]))
                
                else: # Ser,  Cys,  Thr hydroxyl hydrogens
                    secondary_anchor = bonded[0]
                    vector = anchor.coord - secondary_anchor.coord
                    hydrogen_coord = add(heavy_atom.coord, 
                                        scale(vector,  
                                              bnd_len[(ffld[(residue.resname,  heavy_atom.name)]['type'],  
                                              ffld[(residue.resname,  hydrogen_name)]['type'])]    ))
                    
            elif len(bonds):
                d2 = [1.0, 0, 0]
                p0 = heavy_atom.coord - anchor.coord
                p1 = normalize(cross_product(d2,  p0))
                vector = scale(p1,  TET_TAN)
                vector = normalize(add(p0,  vector))
                
                hydrogen_coord = add(heavy_atom.coord, 
                                     scale(  vector,  
                                             bnd_len[(ffld[(residue.resname,  heavy_atom.name)]['type'],  
                                             ffld[(residue.resname,  hydrogen_name)]['type'])]    ))
            else:
                hydrogen_coord = random_sphere(heavy_atom.coord, 
                                               bnd_len[ (ffld[(residue.resname,  heavy_atom.name)]['type'], 
                                                         ffld[(residue.resname,  hydrogen_name)]['type']) ])

        elif len(bonds): # linear sum...amide,  tbu,  etc
            vector = [0.0, 0.0, 0.0]
            if heavy_atom.name == 'N': # Fix to get previous atom O from peptide bond. Ugly.
                prev_res = list(residue.get_id())
                prev_res[1] -= 1
                prev_res = tuple(prev_res)
                if residue.parent.child_dict.has_key(prev_res):
                    prev_res = residue.parent.child_dict[prev_res]
                    bonds.append(prev_res.child_dict['O'])
            for b in bonds:
                d = heavy_atom.coord - b.coord
                vector = add(vector,  d)
            vector = normalize(vector)
            hydrogen_coord = add(heavy_atom.coord, 
                                 scale(vector, 
                                 bnd_len[(ffld[(residue.resname,  heavy_atom.name)]['type'], 
                                          ffld[(residue.resname,  hydrogen_name)]['type']) ]))
        else:
            hydrogen_coord = random_sphere(heavy_atom.coord, 
                                           bnd_len[ (ffld[(residue.resname,  heavy_atom.name)]['type'], 
                                                     ffld[(residue.resname,  hydrogen_name)]['type']) ])
        
        return hydrogen_coord
985556
static public SimpleGraph getMoleculeGraph(IAtomContainer molecule) {
        SimpleGraph graph = new SimpleGraph();
        for (int i = 0; i < molecule.getAtomCount(); i++) {
            IAtom atom = molecule.getAtom(i);
            graph.addVertex(atom);
        }

        for (int i = 0; i < molecule.getBondCount(); i++) {
            IBond bond = molecule.getBond(i);

            /*
             * int order = (int) bond.getOrder(); for (int j=0; j<order; j++) {
             * graph.addEdge(bond.getAtoms()[0], bond.getAtoms()[1]); }
             */
            graph.addEdge(bond.getBegin(), bond.getEnd());
        }
        return graph;
    }
1231075
private SgroupBracket newCrossingBracket(IBond bond, Multimap<IBond,Sgroup> bonds, Map<IBond,Integer> counter, boolean vert) {
        final IAtom beg = bond.getBegin();
        final IAtom end = bond.getEnd();
        final Point2d begXy = beg.getPoint2d();
        final Point2d endXy = end.getPoint2d();
        final Vector2d lenOffset = new Vector2d(endXy.x-begXy.x, endXy.y-begXy.y);
        final Vector2d bndCrossVec = new Vector2d(-lenOffset.y, lenOffset.x);
        lenOffset.normalize();
        bndCrossVec.normalize();
        bndCrossVec.scale(((0.9 * bondLength)) / 2);

        final List<Sgroup> sgroups = new ArrayList<>(bonds.get(bond));

        // bond in sgroup, place it in the middle of the bond
        if (sgroups.size() == 1) {
            lenOffset.scale(0.5 * bondLength);
        }
        // two sgroups, place one near start and one near end
        else if (sgroups.size() == 2) {
            boolean flip = !sgroups.get(counter.get(bond)).getAtoms().contains(beg);
            if (counter.get(bond) == 0) {
                lenOffset.scale(flip ? 0.75 : 0.25 * bondLength); // 75 or 25% along
                counter.put(bond, 1);
            } else {
                lenOffset.scale(flip ? 0.25 : 0.75 * bondLength); // 25 or 75% along
            }
        }
        else {
            double step = bondLength / (1 + sgroups.size());
            int idx = counter.get(bond) + 1;
            counter.put(bond, idx);
            lenOffset.scale((idx * step) * bondLength);
        }

        // vertical bracket
        if (vert) {
            return new SgroupBracket(begXy.x + lenOffset.x, begXy.y + lenOffset.y + bndCrossVec.length(),
                                     begXy.x + lenOffset.x, begXy.y + lenOffset.y - bndCrossVec.length());
        } else {
            return new SgroupBracket(begXy.x + lenOffset.x + bndCrossVec.x, begXy.y + lenOffset.y + bndCrossVec.y,
                                     begXy.x + lenOffset.x - bndCrossVec.x, begXy.y + lenOffset.y - bndCrossVec.y);
        }
    }
394538
private static int countAlignedBonds(IAtomContainer mol) {
        final double ref = Math.toRadians(30);
        final double diff = Math.toRadians(1);
        int count = 0;
        for (IBond bond : mol.bonds()) {
            Point2d beg = bond.getBegin().getPoint2d();
            Point2d end = bond.getEnd().getPoint2d();
            if (beg.x > end.x) {
                Point2d tmp = beg;
                beg = end;
                end = tmp;
            }
            Vector2d vec = new Vector2d(end.x - beg.x, end.y - beg.y);
            double angle = Math.atan2(vec.y, vec.x);

            if (Math.abs(angle) - ref < diff) {
                count++;
            }
        }
        return count;
    }
759921
private int getBondPosition(IBond bond, IAtomContainer container) {
        for (int i = 0; i < container.getBondCount(); i++) {
            if (bond.equals(container.getBond(i))) {
                return i;
            }
        }
        return -1;
    }
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;
    }
278004
private Set<IChemObject> getAromatics(IAtomContainer mol) {
        Set<IChemObject> oldArom = new HashSet<>();
        for (IAtom atom : mol.atoms())
            if (atom.getFlag(CDKConstants.ISAROMATIC))
                oldArom.add(atom);
        for (IBond bond : mol.bonds())
            if (bond.getFlag(CDKConstants.ISAROMATIC))
                oldArom.add(bond);
        return oldArom;
    }
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;
    }
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;
    }
535406
private static IAtom getOtherAtom(IAtomContainer mol, IAtom atom, IAtom other) {
        List<IBond> bonds = mol.getConnectedBondsList(atom);
        if (bonds.size() != 2)
            return null;
        if (bonds.get(0).contains(other))
            return bonds.get(1).getOrder() == IBond.Order.DOUBLE
                   ? bonds.get(1).getOther(atom) : null;
        return bonds.get(0).getOrder() == IBond.Order.DOUBLE
                    ? bonds.get(0).getOther(atom) : null;
    }
112611
def _get_slave(self, dpid, port):
        """"""
        result = None
        for bond in self._bonds:
            if dpid in bond:
                if port in bond[dpid]:
                    result = bond[dpid][port]
                    break
        return result