In this paper, we propose a novel mesh-free method for solving nonconvex energy minimization problems for martensitic phase transitions and twinning in crystals using the deep learning approach. These problems pose significant challenges to analysis and computation because they involve multiwell gradient energies with large numbers of local minima, each involving a topologically complex microstructure of free boundaries with gradient jumps. We use the Deep Ritz method, which represents candidates for minimizers using parameter-dependent deep neural networks, and minimize the energy with respect to network parameters. The key feature of our method is a newly proposed activation function called SmReLU, which captures the structure of minimizers where traditional activation functions fail. Our mesh-free approach allows for the approximation of free boundaries, essential to this problem, without any special treatment, making it extremely simple to implement. We demonstrate the success of our method through numerous numerical computations.