Let's say we have a stuff that consists only of hydrogen (H), then we add a single atom of oxygen (O) and they interfere - we get a water molecule where atoms are arranged in a particular way. Then we add salt (NaCl) where Na may take some O and Cl may take some H.
What was described might be rough or incorrect, but I wonder what are all those factors that determine what elements interact and what molecule shape they form? Do all those factors boil down to something very basic (like atom mass, wave function, electron shells)? Is there a universal way of finding out what will be the shape (angles between atoms) and properties (electronegativity, pH, etc.) of an atom or a molecule?