In this paper a new method for identifying the phases contained in a system composed of atoms/molecules is introduced. The method is rooted in graph theory and combines atom centered symmetry functions, adjacency matrices and clustering algorithms to identify regions of space where the properties of the system constituents can be considered uniform. We show how this method can be used to define collective variables and how these collective variables can be used to enhance the sampling of nucleation events. We then show how this method can be used to analyze simulations of crystal nucleation and growth by using it to analyze simulations of the nucleation of the molecular crystal urea and simulations of nucleation in a semiconducting alloy. The semiconducting alloy example we discuss is particular challenging as multiple nucleation centers are formed. We show, however, that our algorithm is able to detect the grain boundaries in the resulting polycrystal.