Skip to content

Commit

Permalink
Merge pull request #584 from pyiron/murn_conv
Browse files Browse the repository at this point in the history
Murnnaghan Convergence check
  • Loading branch information
sudarsan-surendralal committed Apr 14, 2022
2 parents 26daab1 + 973f0db commit 602374d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 35 deletions.
15 changes: 15 additions & 0 deletions pyiron_atomistics/atomistics/master/murnaghan.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,21 @@ def __init__(self, project, job_name):
self._debye_T = None
self._job_generator = MurnaghanJobGenerator(self)

def convergence_check(self) -> bool:
"""
Checks if the Murnaghan job has cnverged or not
Note: Currently, a 3rd order polynomial is fit to check if there is any convergence
Returns:
bool: True if the calculation is converged
"""
if super().convergence_check():
e_vol = self["output/equilibrium_volume"]
return e_vol is not None
else:
return False

@property
def fit(self):
return self.debye_model
Expand Down
26 changes: 18 additions & 8 deletions tests/atomistics/master/test_murnaghan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import matplotlib.pylab as plt
import numpy as np
from pyiron_atomistics.atomistics.structure.atoms import CrystalStructure
from pyiron_base._tests import TestWithProject
from pyiron_base._tests import TestWithCleanProject


def convergence_goal(self, **qwargs):
Expand All @@ -26,29 +26,41 @@ def convergence_goal(self, **qwargs):
return job_next


class TestMurnaghan(TestWithProject):
class TestMurnaghan(TestWithCleanProject):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.basis = CrystalStructure(
element="Fe", bravais_basis="fcc", lattice_constant=3.5
)

def test_interactive_run(self):
def setup_hessian_murn_job(self, num_points=5):
job = self.project.create_job('HessianJob', 'hessian')
job.set_reference_structure(self.basis)
job.set_elastic_moduli(1, 1)
job.set_force_constants(1)
job.server.run_mode.interactive = True
murn = job.create_job('Murnaghan', 'murn_hessian')
murn.input['num_points'] = 5
murn.input['num_points'] = num_points
murn.input['vol_range'] = 1e-5
return murn

def test_interactive_run(self):
murn = self.setup_hessian_murn_job(num_points=5)
murn.run()
self.assertAlmostEqual(self.basis.get_volume(), murn['output/equilibrium_volume'])

optimal = murn.get_structure()
self.assertAlmostEqual(optimal.get_volume(), murn['output/equilibrium_volume'],
msg="Output of get_structure should have equilibrium volume")
self.assertTrue(murn.convergence_check())

def test_non_converged_run(self):
# Use only 2 points which means there would not be any convergence
murn = self.setup_hessian_murn_job(num_points=2)
murn.run()
self.assertFalse(murn.convergence_check())
self.assertTrue(murn.status.not_converged)

def test_run(self):
job = self.project.create_job(
Expand All @@ -64,10 +76,8 @@ def test_run(self):
murn.ref_job = job_ser
murn.input['num_points'] = 3
murn.run()
self.assertTrue(murn.status.finished)

murn.remove()
job_ser.remove()
# This is not converged
self.assertTrue(murn.status.not_converged)

def test_fitting_routines(self):
ref_job = self.project.create.job.Lammps('ref')
Expand Down
9 changes: 4 additions & 5 deletions tests/atomistics/master/test_murnaghan_master_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pyiron_atomistics.atomistics.structure.atoms import CrystalStructure
from pyiron_base import Project
import unittest
from pyiron_base._tests import TestWithCleanProject


def convergence_goal(self, **qwargs):
Expand All @@ -25,7 +26,8 @@ def convergence_goal(self, **qwargs):
return ham_next


class TestMurnaghan(unittest.TestCase):
class TestMurnaghan(TestWithCleanProject):

@classmethod
def setUpClass(cls):
cls.file_location = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -60,10 +62,7 @@ def test_run(self):
murn.run()
self.assertFalse(ham.status.finished)
self.project.wait_for_job(murn, interval_in_s=5, max_iterations=50)
self.assertTrue(murn.status.finished)
murn.remove()
ham.remove()
self.project.remove(enable=True, enforce=True)
self.assertTrue(murn.status.not_converged)


if __name__ == "__main__":
Expand Down
44 changes: 22 additions & 22 deletions tests/atomistics/master/test_murnaghan_non_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
from pyiron_atomistics.atomistics.structure.atoms import CrystalStructure
from pyiron_base import Project
import unittest
from pyiron_base._tests import TestWithCleanProject


def run_modal_template(project, basis, is_non_modal=True):
ham = project.create_job(project.job_type.AtomisticExampleJob, "job_test")
ham.structure = basis
if is_non_modal:
ham.server.run_mode.non_modal = True
else:
ham.server.run_mode.modal = True
murn = project.create_job("Murnaghan", "murnaghan")
murn.ref_job = ham
murn.input["num_points"] = 3
if is_non_modal:
murn.server.run_mode.non_modal = True
else:
murn.run_mode.modal = True
return murn, ham


def convergence_goal(self, **qwargs):
Expand All @@ -25,7 +43,7 @@ def convergence_goal(self, **qwargs):
return ham_next


class TestMurnaghan(unittest.TestCase):
class TestMurnaghan(TestWithCleanProject):
@classmethod
def setUpClass(cls):
cls.file_location = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -47,29 +65,11 @@ def tearDownClass(cls):
project.remove(enable=True, enforce=True)

def test_run(self):
# Even though the test is completed successful
ham = self.project.create_job(
self.project.job_type.AtomisticExampleJob, "job_test"
)
ham.structure = self.basis
ham.server.run_mode.non_modal = True
job_ser = self.project.create_job(
self.project.job_type.SerialMaster, "murn_iter"
)
job_ser.append(ham)
job_ser.server.run_mode.non_modal = True
job_ser.set_goal(convergence_goal, eps=0.4)
murn = self.project.create_job("Murnaghan", "murnaghan")
murn.ref_job = job_ser
murn.input["num_points"] = 3
murn.server.run_mode.non_modal = True
murn, ham = run_modal_template(self.project, self.basis, is_non_modal=True)
murn.run()
self.assertFalse(job_ser.status.finished)
self.assertFalse(ham.status.finished)
self.project.wait_for_job(murn, interval_in_s=5, max_iterations=50)
self.assertTrue(murn.status.finished)
murn.remove()
job_ser.remove()
self.project.remove(enable=True, enforce=True)
self.assertTrue(murn.status.not_converged)


if __name__ == "__main__":
Expand Down

0 comments on commit 602374d

Please sign in to comment.