A method for calculating surface stress and surface elastic constants by molecular dynamics: application to the surface of crystal and amorphous silicon