MC-exchange Python Package
The MC-exchange Python package has been developed to support the dynamic bond exchange reactions (BERs) during a molecular dynamics (MD) simulation run using LAMMPS (Large-scale Atomic/Molecular Massively Parallel Simulator) software. Using the LAMMPS Python package, a MD simulation can be run directly from a Python script, allowing an interface between Python and LAMMPS. The MC-exchange Python package uses this to gather the necessary data from the LAMMPS MD simulation, analyze the data, determine which bonds to exchanged, and finally communicate the altered bond data back to LAMMPS, where the actual bond exchange can take place.
These simulations are useful for studying the effects of dynamic bonds of associative covalently adaptive polymer networks.
The package is written with the ease of use in mind. However, users must be warned that a thorough understanding of the LAMMPS Python package is necessary to be able to gather the necessary bits of data prior to performing bond exchange reactions using the MC-exchange Python library.
General Use
The package can be installed from PyPI distribution archive using:
pip install MC-exchange
After successful installation of the MC-exchange Python package, it can be imported into a script as follows:
import MC_exchange as mc
The above statement imports all user-necessary functionalities of the package.
Package organization
The MC-exchange Python package is organized into modules. Currently, there are three modules dedicated to the base functionalities, and one module where these functionalities are combined to perform bond exchange reactions. The three base modules are calculations.py, data.py and neigh_list.py. All functions necessary to perform dynamic bond exchange reactions are imported direcly, thus the user does not need to search these modules for the required functionalities. Nevertheless, we provide a brief overview of the different modules, so that the user can better understand the structure of the library.
Base modules
Currently, three base modules are responsible for the primary functionalities of the package. data.py is the module responsible for gathering data from the LAMMPS simulations. calculations.py contains calculations that use the data obtained by the functions of data.py to compute properties that can be necessary during bond exchange reactions. Lastly, neigh_list.py contain the functionalities required to construct spacial neighbor lists using atom data.
Functionalities
Currently, in version 1.3.1, there are two main functions used to perform associative bond exchange reactions. Firstly,
the evaluate_bond_exchange() function is used to perform two types of bond exchange reactions between stickers of
any kind. The two types of bond exchange reactions allowed are bond shifts and bond swaps. The first is an 3-body
exchange reaction between a bonded sticker pair and a 'free' sticker where a single bond migrates, while the latter is a
4-body exchange between two pairs of bonded stickers requiring the rearrangement of two bonds. In either case, the
number of total bonds in the system does not change.
Secondly, the complementary_bond_exchange function, as the name suggests, allows reactions to occur between stickers
that are of different types (i.e., A-B crosslinks). In the function, these types can be defined according to LAMMPS'
numerical type convention under arguments sticker_types_A and sticker_types_B.
Both of the above mentioned bond exchange functions allow bond shifts and bond swaps to be turned on and off according to the user's requirements.
The software is designed such that it works when LAMMPS simulations are run parallel (i.e., on multiple processors).
Communication between processes is handled by the mpi4py Python package.
Exchange statistics
With return_stats=True, complementary_bond_exchange and evaluate_bond_exchange return a third element,
exchange_stats, a dictionary of counters summed over all MPI ranks (identical on every rank). Counts are int, sums
are float; X is shift or swap. Both functions use the same keys, with two differences for
evaluate_bond_exchange: n_options counts every candidate it evaluates (two per free sticker for a shift, the two
re-pairings for a swap) because it proposes the lowest-energy candidate rather than a random one, and the ΔE sums are
of ΔU scaled by alpha. In both functions, a proposal whose old and new configuration both contain a bond ≥ R0
(ΔE = ∞ − ∞) is rejected and counted in n_metropolis_rejected_X but not in n_proposed_overstretched.
| Key | Meaning |
|---|---|
n_shifts, n_swaps, total |
Successful reactions, after cross-rank conflict resolution |
n_sites |
Sticker neighbourhoods that proposed a trial move (one proposal per site) |
n_options |
Candidate moves enumerated across all sites |
n_proposed_X |
Proposals per mechanism |
n_proposed_overstretched |
Proposals with a new bond of length ≥ R0 (ΔE = +∞); always rejected and also counted in n_metropolis_rejected_X |
n_metropolis_rejected_X |
Proposals rejected by the Metropolis test |
n_accepted_local_X |
Proposals accepted on their rank, before conflict resolution |
n_conflict_rejected_X |
Locally accepted moves dropped because they share an atom with a move from another rank |
n_skipped_quarantined |
Sites skipped because their central sticker already reacted in this call |
sum_dE_proposed |
Sum of the finite ΔE of all proposals |
sum_dE_accepted |
Sum of the finite ΔE of the locally accepted moves |
The counters satisfy
n_sites = n_proposed_shift + n_proposed_swap
n_proposed_X = n_metropolis_rejected_X + n_accepted_local_X
n_accepted_local_X = n_conflict_rejected_X + n_shifts (or n_swaps)
so the acceptance can be split by cause: Metropolis acceptance n_accepted_local_X / n_proposed_X, conflict loss
n_conflict_rejected_X / n_accepted_local_X, overall acceptance n_X / n_proposed_X, and geometric loss
n_proposed_overstretched / n_sites. The mean ΔE of proposals is
sum_dE_proposed / (n_sites - n_proposed_overstretched). This is exact unless an existing bond is longer than R0
(LAMMPS bond_style fene allows this up to 2·R0 with a "FENE bond too long" warning). Such a move has ΔE = −∞, is
accepted, and is left out of both sums.
Example script
In order to run the following script...
Users are encouraged to clone the repository of this project to access all source files and example code.
To run the example script, make sure that the Python environment into which MC-exchange was installed is activated and you are located in the
src/example/ directory. To run the example script simply run the following command in the terminal:
mpiexec -np {n_procs} python3 loop.py
where {n_procs} is the number of parallel processes the user wishes to launch.
Note, this requires that the user has installed OpenMPI or MPICH to the local machine.
Developer
Balint Magyari: PhD Student at University of Naples Federico II
For any questions please contact balint.magyari@unina.it.
Metadata
Release files for MC-exchange 1.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mc_exchange-1.3.1.tar.gz | 37.3 kB | With provenance | Details for mc_exchange-1.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mc_exchange-1.3.1-py3-none-any.whl | Python 3 | none | any | Details for mc_exchange-1.3.1-py3-none-any.whl |
Total release size: 62.4 kB
Release files / mc_exchange-1.3.1.tar.gz
| Download URL | mc_exchange-1.3.1.tar.gz |
|---|---|
| Size | 37.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c7668ac384074e65044d792afee6fbb95547cec5389ef0d10cb7fb59940df8c4
|
|
BLAKE2b-256 checksum How to use checksums |
d03517c3e2efa104ea7b27b18a9bf20a69a62117278c81d7ad1d69d805817d5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / mc_exchange-1.3.1-py3-none-any.whl
| Download URL | mc_exchange-1.3.1-py3-none-any.whl |
|---|---|
| Size | 25.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
41f74662fca2081f53b0ea0c96708f976cf8353a800a4c4668b14c51a65fe2ac
|
|
BLAKE2b-256 checksum How to use checksums |
ff0a6964db044e539f96156d5af915f8712a590ad847d5f5b24564ed33cd5c64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logSecurity for MC-exchange 1.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mc_exchange-1.3.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.