code: private double bondsUsed(IAtom atom, IAtomContainer atomContainer) throws CDKException {
          int bondsToAtom = 0;
          for (IBond bond : atomContainer.bonds())
              if (bond.contains(atom)) bondsToAtom += BondManipulator.destroyBondOrder(bond.getOrder());
          int implicitHydrogens;
          if (atom.getImplicitHydrogenCount() == CDKConstants.UNSET || atom.getImplicitHydrogenCount() == null) {
              // Will probably only work with group 13-18, and not for helium...
              if (atom.getValency() == CDKConstants.UNSET || atom.getValency() == null)
                  throw new CDKException("Atom " + atom.getAtomTypeName() + " has not got the valency set.");
              if (atom.getFormalNeighbourCount() == CDKConstants.UNSET || atom.getFormalNeighbourCount() == null)
                  throw new CDKException("Atom " + atom.getAtomTypeName()
                          + " has not got the formal neighbour count set.");
              implicitHydrogens = (8 - atom.getValency()) - atom.getFormalNeighbourCount();
              String warningMessage = "Number of implicite hydrogens not set for atom " + atom.getAtomTypeName()
                      + ". Estimated it to: " + implicitHydrogens;
              logger.warn(warningMessage);
          } else
              implicitHydrogens = atom.getImplicitHydrogenCount();
  
          double charge;
          if (atom.getCharge() == CDKConstants.UNSET)
              if (atom.getFormalCharge() == CDKConstants.UNSET) {
                  charge = 0;
                  String warningMessage = "Neither charge nor formal charge is set for atom " + atom.getAtomTypeName()
                          + ". Estimate it to: 0";
                  logger.warn(warningMessage);
              } else
                  charge = atom.getFormalCharge();
          else
              charge = atom.getCharge();
          return bondsToAtom - charge + implicitHydrogens;
      }
docs: A small help method that count how many bonds an atom has, regarding
  bonds due to its charge and to implicit hydrogens.
  
  @param atom The atom to check
  @param atomContainer The atomContainer containing the atom
  @return The number of bonds that the atom has
  @throws CDKException