code: private void applyMDLValenceModel(IAtom atom, int explicitValence, int unpaired) {
  
          if (atom.getValency() != null) {
              if (atom.getValency() >= explicitValence)
                  atom.setImplicitHydrogenCount(atom.getValency() - (explicitValence - unpaired));
              else
                  atom.setImplicitHydrogenCount(0);
          } else {
              Integer element = atom.getAtomicNumber();
              if (element == null) element = 0;
  
              Integer charge = atom.getFormalCharge();
              if (charge == null) charge = 0;
  
              int implicitValence = MDLValence.implicitValence(element, charge, explicitValence);
              if (implicitValence < explicitValence) {
                  atom.setValency(explicitValence);
                  atom.setImplicitHydrogenCount(0);
              } else {
                  atom.setValency(implicitValence);
                  atom.setImplicitHydrogenCount(implicitValence - explicitValence);
              }
          }
      }
docs: Applies the MDL valence model to atoms using the explicit valence (bond
  order sum) and charge to determine the correct number of implicit
  hydrogens. The model is not applied if the explicit valence is less than
  0 - this is the case when a query bond was read for an atom.
  
  @param atom            the atom to apply the model to
  @param explicitValence the explicit valence (bond order sum)