How to determine stable electron states in ionic and covalent bonds? I'm working on a program that needs to determine if a bond between two or more elements will result in a stable state.  I understand at a high-level how to fill electron subshells using the Aufbau principle, but I also read that in some cases, electrons will jump from a lower energy shell or orbital to a higher one in order to maintain a stable state (Filling Electron Shells).

For example, if I want to determine if Hydrogen and Nitrogen will form a stable bond I would fill the shells for Nitrogen like so:



When adding Hydrogen, would the two electrons in the 2s shell jump to the 2p shell because with the one electron from Hydrogen the HN would then have a full 2p shell? Like this:



Or is this not a stable state? Would it require a large amount of energy to excite or promote those two 2s electrons to the 2p shell?

I'm trying to understand if there are rules or heuristics I can use to estimate if two ore more elements will bond (on there own w/o adding a large amount of energy to the system) using their valence electron configuration like this, or if there are too many exceptions, making it not a simple programming task to estimate this.
I'm trying to understand if there are rules or heuristics I can use to estimate if two ore more elements will bond


You should try to find good textbook/course about Molecular Orbital theory. As I recall, good university-level textbooks on general/inorganic chemistry dive into this aspect and make analysis for dimers of second row elements. This heuristics, however, are of limited usability: they can be used to explain differences in family of compounds with similar structure, but are virtually useless for predicting geometry in complicated cases. And yet, this is the best you can get without diving into quantum chemistry.

Here is quickly found link on the subject. http://chemed.chem.purdue.edu/genchem/topicreview/bp/ch8/mo.html#valence