Ab initio theory of helix↔coil phase transition