Structural effects on the performance of 2D metal/semiconductor contacts and RRAM devices : first-principles and molecular dynamics studies