Determination of the valence state of atoms in the semiempirical description of tetrahedral crystals