Thermodynamic Criterion for the Stability of Amorphous Intergranular Films in Covalent Materials.