A general phase-field framework for predicting the structures and micromechanical properties of crystalline defects