Skip to content

Commit 2003a56

Browse files
V4 (#35)
* Enhance README formatting for better visibility and structure * Add Peng-Robinson equation of state implementation and update changelog * Refactor PengRobinsonEOS integration in GCMC class and update fugacity coefficient calculation * Update GCMC class to set default fugacity coefficient and enhance docstring for clarity * Add fugacity coefficient parameters to GCMC initialization * Refactor GCMC initialization to streamline simulation parameters and enhance fugacity coefficient formatting * Add critical parameters for GCMC: criticalTemperature, criticalPressure, and acentricFactor * Update version to 0.4.0 and modify changelog for unreleased features * Fix fugacity coefficient assignment in GCMC class for clarity and correctness * Add functions to calculate perpendicular lengths and unit cell repetitions in utilities * Add functions for perpendicular lengths and unit cell calculations in utilities; update GCMC to utilize these functions * Add cutoff parameter to GCMC class for supercell check control; update changelog * Refactor framework setup in GCMC class to include supercell creation and perpendicular lengths calculation * Fix python on 3.10 * Print perpendicular lenghts on Widom * Reorganize import statements in GCMC, utilities, and Widom modules for clarity * Initialize ideal supercell in GCMC class and update framework setup to calculate supercell dimensions * Update README to improve description of MLP Adsorption package * Refactor enthalpy_of_adsorption function to use ase.units for gas constant * Add framework density calculation to GCMC class * Refactor framework density calculations in GCMC and Widom classes for consistency and clarity * Fix framework density calculation in GCMC and Widom classes * Add make_cubic function to transform structures into cubic supercells * Refactor import statements in gcmc and widom modules for consistency * Refactor random position using a numpy Generator in GCMC and Widom classes for reproducibility and clarity * Add note on reproducibility with numpy.random.Generator in changelog * Cosmetic changes by black * Refactor random operations into a new module for better organization and reusability * Remove the older vdw_overlap checks * Refactor check_overlap function to improve clarity by renaming return value and updating docstring * Enhance check_overlap function with return type annotation and performance note in docstring * Update changelog for module path corrections and enhanced clarity * Add base logger classes * Abstract the simulation to a BaseSimulator abstract the system state management and general simulation logic. * Refactor GCMC simulation logging by integrating GCMCLogger for improved output management and clarity * Add logging enhancements to simulation output management with GCMCLogger and WidomLogger * Refactor by black and isort * Remove unused imports from gcmc.py to clean up the code * Replace print methods with logger calls for improved output management in examples * Enhance WidomLogger output with detailed simulation start and end messages * Rename 'cutoff' parameter to 'cutoff_radius' for clarity and update output file paths in BaseSimulator, GCMC, and Widom classes. * Refactor calculations in Widom class for improved readability and maintainability * Remove unused import of VERSION from base_simulator.py to clean up the code * Remove unnecessary newline at the end of run_GeoOpt+GCMC.py for cleaner code * Add restart method to Widom class and update adsorbate atom references for clarity * Refactor index calculations in GCMC and improve formatting in Widom class for clarity * Refactor restart method in Widom class to streamline loading of internal energy data * Add the cuequivariance-torch on the environment. * Create a random_mol_insertion method to insert molecules easier * Add random seed to examples * Ensure that all random methods use the same generator * Apply black for code standardization * FIx * Add random seed handling to BaseSimulator and log it in BaseLogger * Fix random_translation * Add pyMSER integration for simulation equilibration and average uptake calculation * Black and isort formating * Remove unused import of enthalpy_of_adsorption from logger.py * Refactor crystalOptimization to store convergence status in a variable * Rename example * Fix error in optimization convergence check * Remove unused sys.path modification and streamline convergence print statement in crystalOptimization * Update README.md to include installation warning and enhance GCMC parameters * Add automatic supercell option and cutoff radius to GCMC and Widom classes; update examples accordingly * Add warning for non-ideal supercell size in logger header * Fix framework mass calculation to ensure it is a float * Refactor framework mass calculation to use a dedicated method for improved clarity and maintainability * Remove space * Update changelog to set release date for version 0.4.0
1 parent ebbe19c commit 2003a56

19 files changed

Lines changed: 1696 additions & 1042 deletions

File tree

CHANGELOG.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## Unreleased
3+
## v[X.Y.Z] - YYYY-MM-DD (Unreleased)
44

55
### New Features 🎉
66

@@ -12,7 +12,44 @@
1212

1313
### Removed 🗑️
1414

15-
## v[0.3.2] - 2025-08-05
15+
## v[0.4.0] - 2025-09-04
16+
17+
### New Features 🎉
18+
19+
- Added the Peng-Robinson equation of state (EOS) to the `mlp_adsorption.eos` module.
20+
- This allows for the calculation of fugacity coefficients and bulk phase density using the Peng-Robinson EOS.
21+
- Add functions to calculate perpendicular lengths and unit cell repetitions in `utilities`.
22+
- Add a new parameter `cutoff` on the `mlp.gcmc` class for controlling the supercell check based on a cutoff radius for the potential.
23+
- Add the `get_density` function to the `mlp_adsorption.utilities` module.
24+
- Add a `mlp_adsorption.utilities.make_cubic` function that can create a cubic (or close to) supercell from a given structure.
25+
- Now all movements are based on a `numpy.random.Generator` to ensure reproducibility. A `random_seed` can be provided to the `GCMC` and `Widom` classes for this purpose.
26+
- New module for checking the overlap between atoms (`mlp_adsorption.operations.check_overlap`)
27+
- A new `BaseSimulator` method created to abstract the system state management and general simulation logic.
28+
- Now all the output of the simulations are managed by a `mlp_adsorption.logger` instance. It introduces:
29+
- `BaseLogger`: A base class for logging simulation information, including restart and iteration details.
30+
- `GCMCLogger`: A logger specifically for GCMC simulations, extending `BaseLogger` with additional functionality.
31+
- `WidomLogger`: A logger specifically for Widom simulations, extending `BaseLogger` with additional functionality.
32+
- Now the `Widom` has a `restart` method to allow restarting a Widom simulation from a saved state. Since Widom does not insert adsorbates on the structure, it simply reads the existing list of insertion energies and use it to update the simulation statistics.
33+
- Now the code uses [pyMSER](https://github.com/IBM/pymser) to evaluate the equilibration of the simulation and calculate the average uptake and enthalpy of adsorption.
34+
35+
### Fixed 🐛
36+
37+
- Fix the framework density calculation on `GCMC` and `Widom` class.
38+
- Fix an error on the check if the optimization converged.
39+
40+
### Enhanced ✨
41+
42+
- Move the random operations (insertion, rotation, translation) to a separate `mlp_adsorption.operations.py` module for better organization and reusability.
43+
44+
### Documentation 📖
45+
46+
- Add the critical parameters to the examples.
47+
48+
### Removed 🗑️
49+
50+
- Old `mlp_adsorption.operations.vdw_overlap` and `mlp_adsorption.operations.vdw_overlap2` functions.
51+
52+
## v[0.3.2] - 2025-08-17
1653

1754
### New Features 🎉
1855

@@ -45,6 +82,8 @@
4582

4683
### Documentation 📖
4784

85+
- New examples are documented in the README file, providing clear instructions on how to run GCMC simulations and Widom insertion tests.
86+
4887
### Removed 🗑️
4988

5089
- Removed commented-out code for saving the system state in xyz format in the `gcmc.py` file to clean up the codebase.

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# MLP Adsorption
1+
# <span style="font-size:larger;">MLP Adsorption</span>
22

3-
This repository contains the MLP Adsorption package, which provides tools for molecular simulations and adsorption studies using machine learning potentials.
3+
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4+
5+
MLP Adsorption is a general purpose adsorption simulation toolbox built around the Atomic Simulation Environment (ASE), which provides tools for molecular simulations and adsorption studies using machine learning potentials, classical force fields, and other advanced techniques.
46

57
## Requirements
68

@@ -24,6 +26,10 @@ conda env create --file environment.yml
2426

2527
You can install the MLP Adsorption package using pip:
2628

29+
> **Warning**
30+
>
31+
> The code is not yet published on PyPI, so you need to install it directly from the GitHub repository.
32+
2733
```Shell
2834
pip install git+https://github.com/lipelopesoliveira/mlp_adsorption.git
2935
```
@@ -96,21 +102,26 @@ gcmc = GCMC(
96102
adsorbate_atoms=adsorbate,
97103
temperature=Temperature,
98104
pressure=pressure,
99-
fugacity_coeff=1,
100105
device=device,
101106
vdw_radii=vdw_radii,
102107
vdw_factor=0.6,
103108
save_frequency=1,
104109
debug=True,
105110
output_to_file=True,
111+
criticalTemperature=304.1282,
112+
criticalPressure=7377300.0,
113+
acentricFactor=0.22394,
114+
random_seed=42,
115+
cutoff_radius=6.0,
116+
automatic_supercell=True,
106117
)
107118

108119

109-
gcmc.print_introduction()
120+
gcmc.logger.print_header()
110121

111122
gcmc.run(MCSteps)
112123

113-
gcmc.print_finish()
124+
gcmc.logger.print_summary()
114125

115126
```
116127

environment.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: mlp_ads
22
channels:
33
- conda-forge
44
dependencies:
5-
- python>=3.10
5+
- python=3.10
66
- pip
77
- jupyter
88
- jupyterlab
@@ -16,5 +16,6 @@ dependencies:
1616
- simplejson
1717
- pip:
1818
- pymser
19+
- cuequivariance-torch
1920
- mace-torch
2021
- torch-dftd

examples/Basic/1-Widom/run_widom.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@
5050
vdw_radii=vdw_radii,
5151
debug=False,
5252
output_to_file=True,
53+
random_seed=42,
54+
cutoff_radius=6.0,
55+
automatic_supercell=True,
5356
)
5457

55-
widom.print_header()
58+
widom.logger.print_header()
5659

5760
widom.run(NSteps)
58-
widom.print_footer()
61+
widom.logger.print_summary()

examples/Basic/2-Rigid_GCMC/run_GCMC.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
dispersion=True,
2727
damping="zero", # choices: ["zero", "bj", "zerom", "bjm"]
2828
dispersion_xc="pbe",
29-
default_dtype="float32",
29+
default_dtype="float64",
3030
device=device,
3131
)
3232

@@ -51,18 +51,23 @@
5151
adsorbate_atoms=adsorbate,
5252
temperature=Temperature,
5353
pressure=pressure,
54-
fugacity_coeff=1,
5554
device=device,
5655
vdw_radii=vdw_radii,
5756
vdw_factor=0.6,
5857
save_frequency=1,
5958
debug=True,
6059
output_to_file=True,
60+
criticalTemperature=304.1282,
61+
criticalPressure=7377300.0,
62+
acentricFactor=0.22394,
63+
random_seed=42,
64+
cutoff_radius=6.0,
65+
automatic_supercell=True,
6166
)
6267

6368

64-
gcmc.print_introduction()
69+
gcmc.logger.print_header()
6570

6671
gcmc.run(MCSteps)
6772

68-
gcmc.print_finish()
73+
gcmc.logger.print_summary()

examples/Basic/3-Rigid_GCMC_Isotherm/run_GCMC_Isotherm.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,23 @@
6363
adsorbate_atoms=adsorbate,
6464
temperature=Temperature,
6565
pressure=pressure,
66-
fugacity_coeff=1,
6766
device=device,
6867
vdw_radii=vdw_radii,
6968
debug=False,
7069
output_to_file=True,
70+
criticalTemperature=304.1282,
71+
criticalPressure=7377300.0,
72+
acentricFactor=0.22394,
73+
cutoff_radius=6.0,
74+
automatic_supercell=True,
7175
)
7276

73-
gcmc.print_introduction()
77+
gcmc.logger.print_header()
7478

7579
if pressure > pressure_list[0]:
7680
print("Loading previous state for continuation...")
7781
output_dir = f"results_{Temperature:.2f}_{pressure_list[i-1]:.2f}"
7882
gcmc.load_state(os.path.join(output_dir, "GCMC_Trajectory.traj"))
7983

8084
gcmc.run(MCSteps)
81-
gcmc.print_finish()
85+
gcmc.logger.print_summary()

examples/Intermediate/1-Geometry_Optimization_GCMC/run_GeoOpt+GCMC.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ase.optimize import LBFGS
1212
from mace.calculators import mace_mp
1313

14-
from mlp_adsorption.ase_utils import crystalOptmization
14+
from mlp_adsorption.ase_utils import crystalOptimization
1515
from mlp_adsorption.gcmc import GCMC
1616

1717
warnings.filterwarnings("ignore", category=UserWarning)
@@ -37,7 +37,7 @@
3737
# Load the framework structure
3838
framework: ase.Atoms = read(FrameworkPath) # type: ignore
3939

40-
resultsDict, frameworkOpt = crystalOptmization(
40+
resultsDict, frameworkOpt = crystalOptimization(
4141
atoms_in=framework,
4242
calculator=model,
4343
optimizer=LBFGS, # type: ignore
@@ -59,7 +59,7 @@
5959
# Load the adsorbate structure
6060
adsorbate: ase.Atoms = read(AdsorbatePath) # type: ignore
6161

62-
resultsDict, adsorbateOpt = crystalOptmization(
62+
resultsDict, adsorbateOpt = crystalOptimization(
6363
atoms_in=adsorbate,
6464
calculator=model,
6565
optimizer=LBFGS, # type: ignore
@@ -94,18 +94,21 @@
9494
adsorbate_atoms=adsorbateOpt,
9595
temperature=Temperature,
9696
pressure=pressure,
97-
fugacity_coeff=1,
9897
device=device,
9998
vdw_radii=vdw_radii,
10099
vdw_factor=0.6,
101100
save_frequency=1,
102101
debug=True,
103102
output_to_file=True,
103+
criticalTemperature=304.1282,
104+
criticalPressure=7377300.0,
105+
acentricFactor=0.22394,
106+
cutoff_radius=6.0,
107+
automatic_supercell=True,
104108
)
105109

106-
107-
gcmc.print_introduction()
110+
gcmc.logger.print_header()
108111

109112
gcmc.run(MCSteps)
110113

111-
gcmc.print_finish()
114+
gcmc.logger.print_summary()
File renamed without changes.

examples/Intermediate/2.-MD_GCMC/run_MD_GCMC.py renamed to examples/Intermediate/2-MD_GCMC/run_MD_GCMC.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,25 @@
5151
adsorbate_atoms=adsorbate,
5252
temperature=Temperature,
5353
pressure=pressure,
54-
fugacity_coeff=1,
5554
device=device,
5655
vdw_radii=vdw_radii,
5756
vdw_factor=0.6,
5857
save_frequency=1,
5958
debug=True,
6059
output_to_file=True,
60+
criticalTemperature=304.1282,
61+
criticalPressure=7377300.0,
62+
acentricFactor=0.22394,
63+
cutoff_radius=6.0,
64+
automatic_supercell=True,
6165
)
6266

6367

64-
gcmc.print_introduction()
68+
gcmc.logger.print_header()
6569

6670
for j in range(5):
6771
gcmc.run(MCSteps)
6872
gcmc.npt(nsteps=MDSteps, time_step=0.5, mode="aniso_flex")
6973

7074
gcmc.run(MCSteps)
71-
gcmc.print_finish()
75+
gcmc.logger.print_summary()

0 commit comments

Comments
 (0)