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.4.0, associative bond exchange reactions are performed by complementary_bond_exchange().
Two types of bond exchange reactions are allowed between stickers: bond shifts and bond swaps. The first is a
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.
By default any sticker may bond to any other sticker (any-pairing mode). To restrict reactions to stickers of
different types (i.e., A-B crosslinks), give the LAMMPS atom types of the two groups as sticker_types_A and
sticker_types_B.
evaluate_bond_exchange() is deprecated and will be removed in version 2.0.0. It now forwards to
complementary_bond_exchange() in any-pairing mode, so its trial move is drawn at random from all candidates instead of
being the lowest-energy one; its alpha and P_coeff arguments are ignored.
Bond shifts and bond swaps can each be turned on and off with bond_shift and bond_swap.
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 returns 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. In any-pairing mode n_options counts two candidates per bonded pair and free sticker for a shift (the free
sticker may bond to either partner) and the two re-pairings for a swap; in A/B mode one each. 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. At T = 0 only moves with ΔE ≤ 0 are accepted.
| 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.4.0
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.4.0.tar.gz | 35.7 kB | With provenance | Details for mc_exchange-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mc_exchange-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for mc_exchange-1.4.0-py3-none-any.whl |
Total release size: 59.7 kB
Release files / mc_exchange-1.4.0.tar.gz
| Download URL | mc_exchange-1.4.0.tar.gz |
|---|---|
| Size | 35.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b4c2312c95b4018382194cfbccfb8fc279a2bb96466d1a37315b320a9ca60f0
|
|
BLAKE2b-256 checksum How to use checksums |
cc512ddc8cdde263a34234eecc663b8dab72e775b7faa53ac51461e89d8d2c52
|
| 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.4.0-py3-none-any.whl
| Download URL | mc_exchange-1.4.0-py3-none-any.whl |
|---|---|
| Size | 24.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a8645ed7a9f40ac78f90007c1ee2ef9dc03d52a7cdaa705612e62d2cefba17b
|
|
BLAKE2b-256 checksum How to use checksums |
b6fe8e296a48f913f81f8d88355a3e590d5f414354b71122220ef37690269b1b
|
| 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.4.0
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.4.0.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.