From 9b230fe4136cdbc5a45e0f6dfe72ef0c4e5e945a Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Wed, 20 Mar 2024 15:45:09 +0000 Subject: [PATCH 01/12] MAINT: Use the cmcrameri color scheme --- pypotlib/systems/cu_slab_h2.py | 12 ++++++------ pyproject.toml | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pypotlib/systems/cu_slab_h2.py b/pypotlib/systems/cu_slab_h2.py index 792d006..90e06e1 100644 --- a/pypotlib/systems/cu_slab_h2.py +++ b/pypotlib/systems/cu_slab_h2.py @@ -8,23 +8,22 @@ import numpy as np import matplotlib.pyplot as plt from ase.calculators.calculator import Calculator, all_changes +import cmcrameri.cm as cmc from pypotlib import cpot from pypotlib.aux import reshape_data FuncVal = namedtuple("FuncVal", ["x", "y", "energy"]) PltRange = namedtuple("PltRange", ["low", "high"]) -PlotPtPosData = namedtuple('PlotPtPosData', ['h2pos', 'pltpts']) -PlotPoints = namedtuple('PlotPoints', ['x_npt', 'y_npt']) +PlotPtPosData = namedtuple("PlotPtPosData", ["h2pos", "pltpts"]) +PlotPoints = namedtuple("PlotPoints", ["x_npt", "y_npt"]) + class CuH2PotSlab(Calculator): implemented_properties = ["energy", "forces"] discard_results_on_any_change = True - def __init__(self, - e_zero=FuncVal(x=0.752542, - y=5.0, - energy=-697.311695)): + def __init__(self, e_zero=FuncVal(x=0.752542, y=5.0, energy=-697.311695)): Calculator.__init__(self) self.cpot = cpot.CuH2Pot() self._ezero = e_zero @@ -88,6 +87,7 @@ def contour_plot(data, _max_val = 5, _nlvls=500): energy, levels=np.linspace(0, _max_val, _nlvls), extend="max", + cmap=cmc.batlow, ) # Add labels and title to the plot ax.set_xlabel("H-H distance") diff --git a/pyproject.toml b/pyproject.toml index 61727a4..09fe735 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ authors = [ dependencies = [ "numpy>=1.24.3", "ase>=3.22.1", + "cmcrameri>=1.8", ] requires-python = ">=3.8" readme = "README.md" From d70f70b985b6adcb9978193a1b9ab7de00c78f0c Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Wed, 20 Mar 2024 15:46:29 +0000 Subject: [PATCH 02/12] ENH: Add the option of scattering points --- pypotlib/systems/cu_slab_h2.py | 44 +++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/pypotlib/systems/cu_slab_h2.py b/pypotlib/systems/cu_slab_h2.py index 90e06e1..9c62d3e 100644 --- a/pypotlib/systems/cu_slab_h2.py +++ b/pypotlib/systems/cu_slab_h2.py @@ -1,6 +1,12 @@ -__all__ = ["CuH2PotSlab", "FuncVal", "PltRange", - "PlotPtPos", "contour_plot", "plt_data", - "set_slab_dist"] +__all__ = [ + "CuH2PotSlab", + "FuncVal", + "PltRange", + "PlotPtPos", + "contour_plot", + "plt_data", + "set_slab_dist", +] import warnings from collections import namedtuple @@ -42,6 +48,7 @@ def calculate( self.results["energy"] = energy - self._ezero.energy self.results["forces"] = forces + def set_slab_dist(atoms, dist): h_ind = np.where(np.asarray(atoms.get_chemical_symbols()) == "H")[0] n_hatoms = len(h_ind) @@ -50,12 +57,14 @@ def set_slab_dist(atoms, dist): cpos[-n_hatoms:, 2] = np.repeat(max_slab_z + dist, n_hatoms) atoms.set_positions(cpos) -def plt_data(_atms, hh_range=PltRange(low=0.4, high=3), - h2slab_range = PltRange(low=-0.05, high=5), - n_points=PlotPoints(x_npt=60, y_npt=60)): - h_dists = np.linspace( - hh_range.low, hh_range.high, n_points.x_npt - ) + +def plt_data( + _atms, + hh_range=PltRange(low=0.4, high=3), + h2slab_range=PltRange(low=-0.05, high=5), + n_points=PlotPoints(x_npt=60, y_npt=60), +): + h_dists = np.linspace(hh_range.low, hh_range.high, n_points.x_npt) slab_dists = np.linspace( h2slab_range.low, h2slab_range.high, n_points.y_npt ) @@ -76,7 +85,8 @@ def plt_data(_atms, hh_range=PltRange(low=0.4, high=3), ) return PlotPtPosData(h2pos=plt_h2pos, pltpts=plt_data) -def contour_plot(data, _max_val = 5, _nlvls=500): + +def contour_plot(data, _max_val=5, _nlvls=500, scatter_points=None): x, y, energy = reshape_data(data) # Create a contour plot of the energy surface fig, ax = plt.subplots() @@ -89,10 +99,22 @@ def contour_plot(data, _max_val = 5, _nlvls=500): extend="max", cmap=cmc.batlow, ) + # Scatter + if scatter_points is not None: + scatter_points = np.array(scatter_points) + ax.scatter( + scatter_points[:, 0], + scatter_points[:, 1], + marker="+", + color="gray", + ) + # Add labels and title to the plot ax.set_xlabel("H-H distance") ax.set_ylabel("Slab distance") - ax.set_title('Energy Surface Contour Plot\nShifted by the zero of the energy') + ax.set_title( + "Energy Surface Contour Plot\nShifted by the zero of the energy" + ) # Add a colorbar to the plot cbar = fig.colorbar(cs) # Show the plot From 03fe04b17318e1c52f67b978df02360580ccc7e5 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Wed, 20 Mar 2024 15:47:42 +0000 Subject: [PATCH 03/12] ENH: Add an function to get distances from a slab Given the HH and HCu distances along with the baseline configuration --- pypotlib/systems/cu_slab_h2.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pypotlib/systems/cu_slab_h2.py b/pypotlib/systems/cu_slab_h2.py index 9c62d3e..60dbbb5 100644 --- a/pypotlib/systems/cu_slab_h2.py +++ b/pypotlib/systems/cu_slab_h2.py @@ -58,6 +58,37 @@ def set_slab_dist(atoms, dist): atoms.set_positions(cpos) +def calculate_hh_and_hcu_distances(h_positions, ref_atoms): + """ + Calculate the H-H distance and the specific H(midpoint)-slab distance based on the reference configuration. + + Parameters: + - h_positions: A 6-element list or array with the coordinates of the H atoms [x1, y1, z1, x2, y2, z2]. + - ref_atoms: An ASE Atoms object containing the reference configuration, including H and Cu atoms. + + Returns: + - hh_distance: Distance between the two H atoms. + - hcu_distance: Distance from the H-H midpoint to the slab, considering the reference configuration. + """ + # Reshape h_positions to a 2x3 matrix for easier manipulation + h_positions_matrix = np.array(h_positions).reshape(2, 3) + + # Calculate H-H midpoint + midpoint = np.mean(h_positions_matrix, axis=0) + + # Calculate H-H distance + hh_distance = np.linalg.norm(h_positions_matrix[0] - h_positions_matrix[1]) + + # Determine the maximum Z position of Cu atoms in the reference configuration as the reference slab surface + cu_positions = ref_atoms.positions[ref_atoms.numbers == 29] + max_cu_z = np.max(cu_positions[:, 2]) + + # Calculate the distance from the H-H midpoint to the reference slab surface + hcu_distance = midpoint[2] - max_cu_z + + return hh_distance, hcu_distance + + def plt_data( _atms, hh_range=PltRange(low=0.4, high=3), From 0a4ca2bf84e51b6dda0eba0f1e72bb9d2b4bdc33 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Wed, 20 Mar 2024 15:48:21 +0000 Subject: [PATCH 04/12] DOC: Minor reword --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cb9621a..c361544 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ The easiest way is to use the environment file, compatible with `conda`, `mamba`, `micromamba` etc. ```bash -mamba env create -f environment.yml -mamba activate rgpotpy +micromamba env create -f environment.yml +micromamba activate rgpotpy pdm install ``` From b568a6604ee66b73808573bb5994cb3d3101ae9e Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Wed, 20 Mar 2024 16:35:51 +0000 Subject: [PATCH 05/12] MAINT: Bump to 3.9 and nightly numpy / scipy --- pyproject.toml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 09fe735..4978578 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,11 +9,11 @@ authors = [ ] # These are only if ase integration is requested, consider a group dependencies = [ - "numpy>=1.24.3", + "numpy>=2.0", "ase>=3.22.1", "cmcrameri>=1.8", ] -requires-python = ">=3.8" +requires-python = ">=3.9" readme = "README.md" license = {text = "MIT"} @@ -50,3 +50,10 @@ all = {composite = ["lint pypotlib/"]} [tool.black] line-length = 80 target-version = ['py310'] + +[[tool.pdm.source]] +name = "nightly-scientific-python" +url = "https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/" +verify_ssl = true +include_packages = ["scipy", "scipy-*", "numpy", "numpy-*"] +exclude_packages = ["*"] From 690625041ae53a8f2cacd9cf9dbc5776572c170a Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Wed, 20 Mar 2024 17:58:10 +0000 Subject: [PATCH 06/12] MAINT: Add dev matplotlib --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4978578..b19e008 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ dependencies = [ "numpy>=2.0", "ase>=3.22.1", "cmcrameri>=1.8", + "matplotlib>=3.9.0.dev0", ] requires-python = ">=3.9" readme = "README.md" @@ -55,5 +56,5 @@ target-version = ['py310'] name = "nightly-scientific-python" url = "https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/" verify_ssl = true -include_packages = ["scipy", "scipy-*", "numpy", "numpy-*"] +include_packages = ["scipy", "scipy-*", "numpy", "numpy-*", "matplotlib", "matplotlib-*"] exclude_packages = ["*"] From 956c90cb2a3c22dbf5bacac53be6fe6cf3840637 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 11 Apr 2024 13:53:33 +0000 Subject: [PATCH 07/12] BUG: Fix the windows aux issue Closes gh-1 --- meson.build | 2 +- pypotlib/{aux.py => _aux.py} | 0 pypotlib/systems/cu_slab_h2.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename pypotlib/{aux.py => _aux.py} (100%) diff --git a/meson.build b/meson.build index 5fbe894..c6530f1 100644 --- a/meson.build +++ b/meson.build @@ -61,7 +61,7 @@ py.install_sources([ # Adapters py.install_sources([ 'pypotlib/ase_adapters.py', - 'pypotlib/aux.py', + 'pypotlib/_aux.py', ], pure: false, subdir: 'pypotlib' diff --git a/pypotlib/aux.py b/pypotlib/_aux.py similarity index 100% rename from pypotlib/aux.py rename to pypotlib/_aux.py diff --git a/pypotlib/systems/cu_slab_h2.py b/pypotlib/systems/cu_slab_h2.py index 60dbbb5..5735c6f 100644 --- a/pypotlib/systems/cu_slab_h2.py +++ b/pypotlib/systems/cu_slab_h2.py @@ -17,7 +17,7 @@ import cmcrameri.cm as cmc from pypotlib import cpot -from pypotlib.aux import reshape_data +from pypotlib._aux import reshape_data FuncVal = namedtuple("FuncVal", ["x", "y", "energy"]) PltRange = namedtuple("PltRange", ["low", "high"]) From a313bef64da9c0360e47c035184848b510ea475d Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 11 Apr 2024 13:56:32 +0000 Subject: [PATCH 08/12] MAINT: Export the new function --- pypotlib/systems/cu_slab_h2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pypotlib/systems/cu_slab_h2.py b/pypotlib/systems/cu_slab_h2.py index 5735c6f..aeb257f 100644 --- a/pypotlib/systems/cu_slab_h2.py +++ b/pypotlib/systems/cu_slab_h2.py @@ -6,6 +6,7 @@ "contour_plot", "plt_data", "set_slab_dist", + "calculate_hh_and_hcu_distances", ] import warnings From 2f83d783ba54b19377aa4daca380a3becafae237 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Tue, 16 Apr 2024 22:23:55 +0000 Subject: [PATCH 09/12] MAINT: Add a title --- pypotlib/systems/cu_slab_h2.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pypotlib/systems/cu_slab_h2.py b/pypotlib/systems/cu_slab_h2.py index aeb257f..c7c74c5 100644 --- a/pypotlib/systems/cu_slab_h2.py +++ b/pypotlib/systems/cu_slab_h2.py @@ -118,7 +118,7 @@ def plt_data( return PlotPtPosData(h2pos=plt_h2pos, pltpts=plt_data) -def contour_plot(data, _max_val=5, _nlvls=500, scatter_points=None): +def contour_plot(data, _max_val=5, _nlvls=500, scatter_points=None, title=None): x, y, energy = reshape_data(data) # Create a contour plot of the energy surface fig, ax = plt.subplots() @@ -144,9 +144,12 @@ def contour_plot(data, _max_val=5, _nlvls=500, scatter_points=None): # Add labels and title to the plot ax.set_xlabel("H-H distance") ax.set_ylabel("Slab distance") - ax.set_title( - "Energy Surface Contour Plot\nShifted by the zero of the energy" - ) + if title: + ax.set_title(title) + else: + ax.set_title( + "Energy Surface Contour Plot\nShifted by the zero of the energy" + ) # Add a colorbar to the plot cbar = fig.colorbar(cs) # Show the plot From f121b8d9b694f7dd22ef5a7838bc6ba253834b8f Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Tue, 16 Apr 2024 22:24:01 +0000 Subject: [PATCH 10/12] BLD: Stay with numpy<2.x --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b19e008..d1b39a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ authors = [ ] # These are only if ase integration is requested, consider a group dependencies = [ - "numpy>=2.0", + "numpy", "ase>=3.22.1", "cmcrameri>=1.8", "matplotlib>=3.9.0.dev0", From 7b3ee8c606eab15972ed883c28c92c192bccd2b8 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Fri, 19 Apr 2024 18:12:26 +0000 Subject: [PATCH 11/12] MAINT: Don't move input atoms, cleanup --- pypotlib/systems/cu_slab_h2.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pypotlib/systems/cu_slab_h2.py b/pypotlib/systems/cu_slab_h2.py index c7c74c5..92b2205 100644 --- a/pypotlib/systems/cu_slab_h2.py +++ b/pypotlib/systems/cu_slab_h2.py @@ -91,8 +91,8 @@ def calculate_hh_and_hcu_distances(h_positions, ref_atoms): def plt_data( - _atms, - hh_range=PltRange(low=0.4, high=3), + atms, + hh_range=PltRange(low=0.4, high=3.8), h2slab_range=PltRange(low=-0.05, high=5), n_points=PlotPoints(x_npt=60, y_npt=60), ): @@ -100,6 +100,8 @@ def plt_data( slab_dists = np.linspace( h2slab_range.low, h2slab_range.high, n_points.y_npt ) + _atms = atms.copy() + _atms.calc = atms.calc h_ind = np.where(np.asarray(_atms.get_chemical_symbols()) == "H")[0] plt_data = [] # x, y, energy plt_h2pos = [] # h2 positions @@ -138,7 +140,7 @@ def contour_plot(data, _max_val=5, _nlvls=500, scatter_points=None, title=None): scatter_points[:, 0], scatter_points[:, 1], marker="+", - color="gray", + color="lightgray", ) # Add labels and title to the plot From 6d73bda179bd37abdcc77c3bdf9c32c85c73cad6 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 26 Sep 2024 20:15:03 +0000 Subject: [PATCH 12/12] MAINT: Use both --- pypotlib/systems/cu_slab_h2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypotlib/systems/cu_slab_h2.py b/pypotlib/systems/cu_slab_h2.py index 92b2205..352ddb3 100644 --- a/pypotlib/systems/cu_slab_h2.py +++ b/pypotlib/systems/cu_slab_h2.py @@ -130,7 +130,7 @@ def contour_plot(data, _max_val=5, _nlvls=500, scatter_points=None, title=None): y, energy, levels=np.linspace(0, _max_val, _nlvls), - extend="max", + extend="both", cmap=cmc.batlow, ) # Scatter