From 63629eac565ae52399ef76157e793abed2e9b5ff Mon Sep 17 00:00:00 2001 From: sudarsan1989 Date: Tue, 8 Feb 2022 17:08:21 +0100 Subject: [PATCH 1/9] Collect fit putput and set status if unconverged --- pyiron_atomistics/atomistics/master/murnaghan.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyiron_atomistics/atomistics/master/murnaghan.py b/pyiron_atomistics/atomistics/master/murnaghan.py index c360f5eab..0f5a73d57 100644 --- a/pyiron_atomistics/atomistics/master/murnaghan.py +++ b/pyiron_atomistics/atomistics/master/murnaghan.py @@ -770,9 +770,11 @@ def collect_output(self): for key, val in self._output.items(): hdf5_out[key] = val if self.input["fit_type"] == "polynomial": - self.fit_polynomial(fit_order=self.input["fit_order"]) + fit_output = self.fit_polynomial(fit_order=self.input["fit_order"]) else: - self._fit_eos_general(fittype=self.input["fit_type"]) + fit_output = self._fit_eos_general(fittype=self.input["fit_type"]) + if fit_output is None: + self.status.not_converged = True def plot(self, num_steps=100, plt_show=True): if not self.status.finished: From ac726f20645ebd5fea64d7b0dba5a1c48adb2547 Mon Sep 17 00:00:00 2001 From: sudarsan1989 Date: Tue, 8 Feb 2022 17:22:06 +0100 Subject: [PATCH 2/9] Revert "Collect fit putput and set status if unconverged" This reverts commit 63629eac565ae52399ef76157e793abed2e9b5ff. --- pyiron_atomistics/atomistics/master/murnaghan.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pyiron_atomistics/atomistics/master/murnaghan.py b/pyiron_atomistics/atomistics/master/murnaghan.py index 0f5a73d57..c360f5eab 100644 --- a/pyiron_atomistics/atomistics/master/murnaghan.py +++ b/pyiron_atomistics/atomistics/master/murnaghan.py @@ -770,11 +770,9 @@ def collect_output(self): for key, val in self._output.items(): hdf5_out[key] = val if self.input["fit_type"] == "polynomial": - fit_output = self.fit_polynomial(fit_order=self.input["fit_order"]) + self.fit_polynomial(fit_order=self.input["fit_order"]) else: - fit_output = self._fit_eos_general(fittype=self.input["fit_type"]) - if fit_output is None: - self.status.not_converged = True + self._fit_eos_general(fittype=self.input["fit_type"]) def plot(self, num_steps=100, plt_show=True): if not self.status.finished: From 3e2c125d6801f305e847b6a8e24ed012521db122 Mon Sep 17 00:00:00 2001 From: sudarsan1989 Date: Tue, 8 Feb 2022 17:32:03 +0100 Subject: [PATCH 3/9] Nitpick: Getting rid of annoying print statement --- pyiron_atomistics/atomistics/master/murnaghan.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyiron_atomistics/atomistics/master/murnaghan.py b/pyiron_atomistics/atomistics/master/murnaghan.py index c360f5eab..d0ccdab8a 100644 --- a/pyiron_atomistics/atomistics/master/murnaghan.py +++ b/pyiron_atomistics/atomistics/master/murnaghan.py @@ -743,7 +743,6 @@ def collect_output(self): erg_lst, vol_lst, err_lst, id_lst = [], [], [], [] for job_id in self.child_ids: ham = self.project_hdf5.inspect(job_id) - print("job_id: ", job_id, ham.status) if "energy_tot" in ham["output/generic"].list_nodes(): energy = ham["output/generic/energy_tot"][-1] elif "energy_pot" in ham["output/generic"].list_nodes(): From 96f6fc079888a0914d9b5ceb15d09d69751e84bb Mon Sep 17 00:00:00 2001 From: sudarsan1989 Date: Tue, 8 Feb 2022 17:39:17 +0100 Subject: [PATCH 4/9] Allow plot function to take in an axis object --- .../atomistics/master/murnaghan.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pyiron_atomistics/atomistics/master/murnaghan.py b/pyiron_atomistics/atomistics/master/murnaghan.py index d0ccdab8a..e1204d5c6 100644 --- a/pyiron_atomistics/atomistics/master/murnaghan.py +++ b/pyiron_atomistics/atomistics/master/murnaghan.py @@ -773,7 +773,7 @@ def collect_output(self): else: self._fit_eos_general(fittype=self.input["fit_type"]) - def plot(self, num_steps=100, plt_show=True): + def plot(self, num_steps=100, plt_show=True, ax=None): if not self.status.finished: raise ValueError( "Job must be successfully run, before calling this method." @@ -782,6 +782,9 @@ def plot(self, num_steps=100, plt_show=True): import matplotlib.pylab as plt except ImportError: import matplotlib.pyplot as plt + + if ax is None: + ax = plt.subplot(111) if not self.fit_dict: if self.input["fit_type"] == "polynomial": self.fit_polynomial(fit_order=self.input["fit_order"]) @@ -796,8 +799,8 @@ def plot(self, num_steps=100, plt_show=True): if self.input["fit_type"] == "polynomial": p_fit = np.poly1d(self.fit_dict["poly_fit"]) least_square_error = self.fit_module.get_error(vol_lst, erg_lst, p_fit) - plt.title("Murnaghan: error: " + str(least_square_error)) - plt.plot( + ax.set_title("Murnaghan: error: " + str(least_square_error)) + ax.plot( x_i, p_fit(x_i), "-", @@ -813,7 +816,7 @@ def plot(self, num_steps=100, plt_show=True): eng_fit_lst = fitfunction( parameters=[E0, B0, BP, V0], vol=x_i, fittype=self.input["fit_type"] ) - plt.plot( + ax.plot( x_i, eng_fit_lst, "-", @@ -822,12 +825,13 @@ def plot(self, num_steps=100, plt_show=True): linewidth=3, ) - plt.plot(vol_lst, erg_lst, "x", color=color, markersize=20) - plt.legend() - plt.xlabel("Volume ($\AA^3$)") - plt.ylabel("energy (eV)") + ax.plot(vol_lst, erg_lst, "x", color=color, markersize=20) + ax.legend() + ax.set_xlabel("Volume ($\AA^3$)") + ax.set_ylabel("energy (eV)") if plt_show: plt.show() + return ax def _get_structure(self, frame=-1, wrap_atoms=True): """ From 9442e4c7c2a741b3d6d31aa7623c8d772d149723 Mon Sep 17 00:00:00 2001 From: sudarsan1989 Date: Thu, 10 Feb 2022 15:25:06 +0100 Subject: [PATCH 5/9] Additional plot features --- .../atomistics/master/murnaghan.py | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/pyiron_atomistics/atomistics/master/murnaghan.py b/pyiron_atomistics/atomistics/master/murnaghan.py index e1204d5c6..0e64f27a8 100644 --- a/pyiron_atomistics/atomistics/master/murnaghan.py +++ b/pyiron_atomistics/atomistics/master/murnaghan.py @@ -773,7 +773,7 @@ def collect_output(self): else: self._fit_eos_general(fittype=self.input["fit_type"]) - def plot(self, num_steps=100, plt_show=True, ax=None): + def plot(self, num_steps=100, plt_show=True, ax=None, plot_kwargs=None): if not self.status.finished: raise ValueError( "Job must be successfully run, before calling this method." @@ -793,7 +793,24 @@ def plot(self, num_steps=100, plt_show=True, ax=None): df = self.output_to_pandas() vol_lst, erg_lst = df["volume"].values, df["energy"].values x_i = np.linspace(np.min(vol_lst), np.max(vol_lst), num_steps) - color = "blue" + + if plot_kwargs is None: + plot_kwargs = {} + + if "color" in plot_kwargs.keys(): + color = plot_kwargs["color"] + del plot_kwargs["color"] + else: + color = "blue" + + if "marker" in plot_kwargs.keys(): + del plot_kwargs["marker"] + + if "label" in plot_kwargs.keys(): + label = plot_kwargs["label"] + del plot_kwargs["label"] + else: + label = self.input["fit_type"] if self.fit_dict is not None: if self.input["fit_type"] == "polynomial": @@ -804,9 +821,10 @@ def plot(self, num_steps=100, plt_show=True, ax=None): x_i, p_fit(x_i), "-", - label=self.input["fit_type"], + label=label, color=color, linewidth=3, + **plot_kwargs, ) else: V0 = self.fit_dict["volume_eq"] @@ -820,12 +838,13 @@ def plot(self, num_steps=100, plt_show=True, ax=None): x_i, eng_fit_lst, "-", - label=self.input["fit_type"], + label=label, color=color, linewidth=3, + **plot_kwargs, ) - ax.plot(vol_lst, erg_lst, "x", color=color, markersize=20) + ax.plot(vol_lst, erg_lst, "x", color=color, markersize=20, **plot_kwargs) ax.legend() ax.set_xlabel("Volume ($\AA^3$)") ax.set_ylabel("energy (eV)") From 4daf53514aee111d4bb2dea2b175d11d7746931d Mon Sep 17 00:00:00 2001 From: sudarsan1989 Date: Tue, 15 Feb 2022 09:40:22 +0100 Subject: [PATCH 6/9] Don't `plt.show()` if axis defined --- pyiron_atomistics/atomistics/master/murnaghan.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyiron_atomistics/atomistics/master/murnaghan.py b/pyiron_atomistics/atomistics/master/murnaghan.py index 0e64f27a8..1d80e403e 100644 --- a/pyiron_atomistics/atomistics/master/murnaghan.py +++ b/pyiron_atomistics/atomistics/master/murnaghan.py @@ -785,6 +785,8 @@ def plot(self, num_steps=100, plt_show=True, ax=None, plot_kwargs=None): if ax is None: ax = plt.subplot(111) + else: + plt_show = False if not self.fit_dict: if self.input["fit_type"] == "polynomial": self.fit_polynomial(fit_order=self.input["fit_order"]) From 74219f6362f0c2f7a4b8d53c1c63384320826b83 Mon Sep 17 00:00:00 2001 From: sudarsan1989 Date: Tue, 15 Feb 2022 09:55:42 +0100 Subject: [PATCH 7/9] A little testing --- tests/atomistics/master/test_murnaghan.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/atomistics/master/test_murnaghan.py b/tests/atomistics/master/test_murnaghan.py index a04ae447f..d5a766d80 100644 --- a/tests/atomistics/master/test_murnaghan.py +++ b/tests/atomistics/master/test_murnaghan.py @@ -3,9 +3,8 @@ # Distributed under the terms of "New BSD License", see the LICENSE file. import unittest - +import matplotlib import numpy as np - from pyiron_atomistics.atomistics.structure.atoms import CrystalStructure from pyiron_base._tests import TestWithProject @@ -90,7 +89,7 @@ def test_fitting_routines(self): murn._hdf5["output/equilibrium_volume"] = 448.4033384110422 murn.status.finished = True - murn.plot(plt_show=False) + self.assertIsInstance(murn.plot(plt_show=True), matplotlib.axes.Axes) with self.subTest(msg="standard polynomial fit"): self.assertAlmostEqual(-90.71969974284912, murn.equilibrium_energy) self.assertAlmostEqual(448.1341230545222, murn.equilibrium_volume) From 4f1e427f4ed7a6401d7780176fcc43f7d879bffe Mon Sep 17 00:00:00 2001 From: sudarsan1989 Date: Tue, 15 Feb 2022 10:30:28 +0100 Subject: [PATCH 8/9] Extend test --- tests/atomistics/master/test_murnaghan.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/atomistics/master/test_murnaghan.py b/tests/atomistics/master/test_murnaghan.py index d5a766d80..3f3709d34 100644 --- a/tests/atomistics/master/test_murnaghan.py +++ b/tests/atomistics/master/test_murnaghan.py @@ -4,6 +4,7 @@ import unittest import matplotlib +import matplotlib.pylab as plt import numpy as np from pyiron_atomistics.atomistics.structure.atoms import CrystalStructure from pyiron_base._tests import TestWithProject @@ -90,6 +91,11 @@ def test_fitting_routines(self): murn.status.finished = True self.assertIsInstance(murn.plot(plt_show=True), matplotlib.axes.Axes) + _, ax_list = plt.subplots(ncols=2, nrows=1) + for i, ax in enumerate(ax_list): + ax = murn.plot(ax=ax, plot_kwargs={"color": "black", "label": f"plot{i}", "marker": "x"}) + ax.set_title(f"Axis {i+1}") + self.assertEqual(len(ax.lines), 2) with self.subTest(msg="standard polynomial fit"): self.assertAlmostEqual(-90.71969974284912, murn.equilibrium_energy) self.assertAlmostEqual(448.1341230545222, murn.equilibrium_volume) From 9245b21d42c92734bde71ea02825eaa0738a9457 Mon Sep 17 00:00:00 2001 From: sudarsan1989 Date: Tue, 15 Feb 2022 18:32:21 +0100 Subject: [PATCH 9/9] trying to fix windows and macos tests --- tests/atomistics/master/test_murnaghan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/atomistics/master/test_murnaghan.py b/tests/atomistics/master/test_murnaghan.py index 3f3709d34..30fdcd8dd 100644 --- a/tests/atomistics/master/test_murnaghan.py +++ b/tests/atomistics/master/test_murnaghan.py @@ -90,7 +90,7 @@ def test_fitting_routines(self): murn._hdf5["output/equilibrium_volume"] = 448.4033384110422 murn.status.finished = True - self.assertIsInstance(murn.plot(plt_show=True), matplotlib.axes.Axes) + self.assertIsInstance(murn.plot(plt_show=False), matplotlib.axes.Axes) _, ax_list = plt.subplots(ncols=2, nrows=1) for i, ax in enumerate(ax_list): ax = murn.plot(ax=ax, plot_kwargs={"color": "black", "label": f"plot{i}", "marker": "x"})