implemented the gradient of the MtlOptEnergy class, test passed.