Package: partycls
partyclsis a Python package for cluster analysis of systems of interacting particles. By grouping particles that share similar structural or dynamical properties, partycls enables rapid and unsupervised exploration of the system's relevant features. It provides descriptors suitable for applications in condensed matter physics, such as structural analysis of disordered or partially ordered materials, and integrates the necessary tools of unsupervised learning into a streamlined workflow.HomepageFor more details and tutorials, visit the homepage at:https://www.jorisparet.com/partyclsQuick startThis quick example shows how to use partycls to identify grain boundaries in a polycrystalline system. The system configuration is stored in aXYZtrajectory file with a single frame. We use the local distribution of bond angles around each particle as a structural descriptor and perform a clustering using theK-Meansalgorithm.frompartyclsimportTrajectory,Workflowtraj=Trajectory('grains.xyz')wf=Workflow(traj,descriptor='ba',clustering='kmeans')wf.run()traj[0].show(color='label',backend='ovito')The results are also written to a set of files including a labeled trajectory file and additional information on the clustering results. The whole workflow can be tuned and customized, check out thetutorialsto see how and for further examples.Thanks to a flexible system of filters, partycls makes it easy to restrict the analysis to a given subset of particles based on arbitrary particle properties. Say we have a binary mixture composed of particles with types A and B, and we are only interested in analyzing the bond angles of B particles in a vertical slice:frompartyclsimportTrajectoryfrompartycls.descriptorsimportBondAngleDescriptortraj=Trajectory('trajectory.xyz')D=BondAngleDescriptor(traj)D.add_filter("species == 'B'")D.add_filter("x > 0.0")D.add_filter("x < 1.0")D.compute()# Angular correlations for the selected particlesprint(D.features)We can then perform a clustering based on these structural features and ask for 3 clusters:frompartyclsimportKMeansclustering=KMeans(n_clusters=3)clustering.fit(D.features)print('Cluster membership of the particles',clustering.labels)Main featuresTrajectory formatspartycls accepts several trajectory formats (including custom ones) either through its built-in trajectory reader or via third-party packages, such asMDTrajandatooms. The code is currently optimized for small and medium system sizes (of order 10⁴ particles). Multiple trajectory frames can be analyzed to extend the structural dataset.Structural descriptorspartycls implements various structural descriptors:Radial descriptorTetrahedral descriptorBond-angle descriptorSmoothed bond-angle descriptorBond-orientational descriptorSmoothed bond-orientational descriptorLocally averaged bond-orientational descriptorRadial bond-orientational descriptorCompactness descriptorCoordination descriptorMachine learningpartycls performs feature scaling, dimensionality reduction and cluster analysis using thescikit-learnpackage and additional built-in algorithms.Dependenciespartycls relies on several external packages, most of which only provide additional features and are not necessarily required.RequiredFortran compiler (e.g.gfortran)NumPyscikit-learnOptionalMDTraj(additional trajectory formats)atooms(additional trajectory formats)DScribe(additional descriptors)Matplotlib(visualization)OVITO< 3.7.0 (visualization)Py3DMol(interactive 3D visualization)pyvoroor itsmemory-optimized forkfor large systems (Voronoi neighbors and tessellation)tqdm(progress bars)DocumentationCheck thetutorialsto see various examples and detailed instructions on how to run the code, as well as an in-depth presentation of the built-in structural descriptors.For a more detailed documentation, you can check theAPI.InstallationFrom PyPIThe latest stable release is available onPyPI. Install it withpip:pipinstallpartyclsFrom sourceTo install the latest development version from source, clone the source code from the officialGitHub repositoryand install it with:gitclonehttps://github.com/jorisparet/partycls.gitcdpartycls
makeinstallRun the tests using:maketestor manually compile the Fortran sources and run the tests:cdpartycls/
f2py-c-mneighbors_wrapneighbors.f90cddescriptor/
f2py-c-mrealspace_wraprealspace.f90cd../../
pytesttests/Support and contributionIf you wish to contribute or report an issue, feel free tocontact usor to use theissue trackerandpull requestsfrom thecode repository.We largely follow theGitHub flowto integrate community contributions. In essence:Fork the repository.Create a feature branch frommaster.Unleash your creativity.Run the tests.Open a pull request.We also welcome contributions from other platforms, such as GitLab instances. Just let us know where to find your feature branch.Citing partyclsIf you use partycls in a scientific publication, please consider citing the following article:partycls: A Python package for structural clustering. Paret et al., (2021). Journal of Open Source Software, 6(67), 3723Bibtex entry:@article{Paret2021,
  doi = {10.21105/joss.03723},
  url = {https://doi.org/10.21105/joss.03723},
  year = {2021},
  publisher = {The Open Journal},
  volume = {6},
  number = {67},
  pages = {3723},
  author = {Joris Paret and Daniele Coslovich},
  title = {partycls: A Python package for structural clustering},
  journal = {Journal of Open Source Software}
}AuthorsJoris ParetDaniele Coslovich