(Note: I know that the VSEPR method fails sometimes, and that there are exceptional molecules. The challenge is about the molecules which conform.)
Most people who have taken an introductory chemistry course know about molecules, and (probably) the VSEPR theory of chemical bonding. Basically, the theory predicts the shape of a molecule given three main properties:
A
: The central atom. You may assume this is the first element appearing in the chemical formula; for example, in CH4, you may assume the central atom is C.X
: The number of atoms bonded to the central atom A.E
: The number of "lone electron pairs" on the central atom. For the purposes of this challenge, the number of outer electrons A has is given by the last digit of the element's column number on the periodic table.- If A is bonded to an element X in column 17 of the periodic table, there will be a mutual sharing of electrons, so that A effectively has one additional electron for each atom of X attached to it. (This does not apply for elements such as O or S in column 16.)
Each bond requires two of these electrons. Leftover electrons not used in bonding with other atoms are found in pairs of two, called lone pairs. So E is the number of electrons not used in bonding by the central atom A divided by 2. (It may be assumed that input will always lead to A having an even number of electrons.)
For example, a molecule which has 1 lone pair and 3 atoms bonded to the main atom is AX3E1, which is the trigonal pyramidal configuration. (There is always only 1 central atom, so A never has a subscript.)
The Challenge
Your job is, given a string representing a covalent chemical compound, to output the shape of that molecule. "But wait!", exclaim the exasperated programmers, "you can't expect us to input all of the molecular data for every element!" Of course we can, but as that wouldn't be fun, we'll only consider the compounds formed by the following 7 elements:
Carbon C
Sulfur S
Oxygen O
Nitrogen N
Chlorine Cl
Bromine Br
Fluorine F
The input is any molecule composed of the above 7, such as CO2
or SF4
, that is in the form AXN
, where A and X are each one of the above seven element symbols, X is not C
or N
, and N is a number between 2 and 6 inclusive.
The output should be the name of the geometric shape of the molecule, for example "linear".
The following (don't get scared, I swear they're less than they seem!) is a list of all possible configurations along with their AXE number and a drawing of how they look (adapted from Wikipedia's nifty table):
Test Cases
CO2: CO2 -> linear
OF2: OF2 -> bent
CCl2: CCl2 -> bent
BrF3: BrF3 -> T-shaped
SF4: SF4 -> seesaw
Notes:
- We won't consider compounds in which the first element has a subscript other than 1, such as C2H4.
- Standard loopholes apply.
- This is a code golf, so the shortest answer wins (obviously)