We describe a method based on linear programming, for deducing the correct bond orders in small molecules, which only needs the sigma bonds connectivity and atom symbols as input. The procedure checks whether the current structure can be written as a valid Lewis structure by assigning double and triple bonds by translating the octet equations into an integer linear program that is solved by an external solver. The procedure was intensively tested on some ligands from the protein data bank as well as some other exotic molecules, for which first the hydrogen topology is generated by a standard procedure from literature. The most stable Lewis structure is retained for which hydrogen coordinates are generated.