A method for cluster recognition from nucleon distributions generated in calculations of relativistic collisions of light particles (protons, α-particles) with nuclei in the framework of the UrQMD model is proposed. The excitation energy of the clusters which is necessary to take into account for the de-excitation of the calculated fragments was estimated from empirical considerations. The approach was applied to calculate mass distributions of fragments in p + Fe collisions for different proton energies and showed a good correspondence to experimental results. The software implementation of the clustering method and a visualization of cluster formation substantially facilitate applications of the proposed method