Browse files

Add serialization for vasp handlers. Update required pymatgen version.

  • Loading branch information...
1 parent b3e09b2 commit 6f0536c5ab1b512d8a787f0e0d5042ede9cae186 @shyuep shyuep committed Mar 24, 2013
Showing with 56 additions and 5 deletions.
  1. +34 −3 custodian/vasp/handlers.py
  2. +20 −0 custodian/vasp/tests/test_handlers.py
  3. +1 −1 requirements.txt
  4. +1 −1 setup.py
View
37 custodian/vasp/handlers.py
@@ -25,12 +25,14 @@
from pymatgen.io.vaspio.vasp_input import Poscar, VaspInput
from pymatgen.transformations.standard_transformations import \
PerturbStructureTransformation
+from pymatgen.serializers.json_coders import MSONable
+
from pymatgen.io.vaspio.vasp_output import Vasprun
from custodian.ansible.intepreter import Modder
from custodian.ansible.actions import FileActions, DictActions
-class VaspErrorHandler(ErrorHandler):
+class VaspErrorHandler(ErrorHandler, MSONable):
error_msgs = {
"tet": ["Tetrahedron method fails for NKPT<4",
@@ -99,8 +101,18 @@ def correct(self):
def __str__(self):
return "Vasp error"
+ @property
+ def to_dict(self):
+ return {"@module": self.__class__.__module__,
+ "@class": self.__class__.__name__,
+ "output_filename": self.output_filename}
+
+ @staticmethod
+ def from_dict(d):
+ return VaspErrorHandler(d["output_filename"])
+
-class UnconvergedErrorHandler(ErrorHandler):
+class UnconvergedErrorHandler(ErrorHandler, MSONable):
"""
Check if a run is converged
"""
@@ -135,8 +147,18 @@ def correct(self):
def __str__(self):
return "Run unconverged."
+ @property
+ def to_dict(self):
+ return {"@module": self.__class__.__module__,
+ "@class": self.__class__.__name__,
+ "output_filename": self.output_filename}
-class PoscarErrorHandler(ErrorHandler):
+ @staticmethod
+ def from_dict(d):
+ return VaspErrorHandler(d["output_filename"])
+
+
+class PoscarErrorHandler(ErrorHandler, MSONable):
def __init__(self, output_filename="vasp.out"):
self.output_filename = output_filename
@@ -168,6 +190,15 @@ def correct(self):
return {"errors": ["Rotation matrix"],
"actions": actions}
+ @property
+ def to_dict(self):
+ return {"@module": self.__class__.__module__,
+ "@class": self.__class__.__name__,
+ "output_filename": self.output_filename}
+
+ @staticmethod
+ def from_dict(d):
+ return VaspErrorHandler(d["output_filename"])
def backup():
error_num = 0
View
20 custodian/vasp/tests/test_handlers.py
@@ -53,6 +53,13 @@ def test_check_correct(self):
os.remove(os.path.join(test_dir, "error.2.tar.gz"))
+ def test_to_from_dict(self):
+ h = VaspErrorHandler("random_name")
+ h2 = VaspErrorHandler.from_dict(h.to_dict)
+ self.assertEqual(type(h2), type(h))
+ self.assertEqual(h2.output_filename, "random_name")
+
+
class UnconvergedErrorHandlerTest(unittest.TestCase):
def test_check_correct(self):
@@ -71,6 +78,12 @@ def test_check_correct(self):
'action': {'_set': {'ISTART': 1}}}])
os.remove(os.path.join(subdir, "error.1.tar.gz"))
+ def test_to_from_dict(self):
+ h = UnconvergedErrorHandler("random_name.xml")
+ h2 = UnconvergedErrorHandler.from_dict(h.to_dict)
+ self.assertEqual(type(h2), UnconvergedErrorHandler)
+ self.assertEqual(h2.output_filename, "random_name.xml")
+
class PoscarErrorHandlerTest(unittest.TestCase):
@@ -88,6 +101,13 @@ def test_check_correct(self):
shutil.copy("POSCAR.orig", "POSCAR")
os.remove("POSCAR.orig")
+ def test_to_from_dict(self):
+ h = PoscarErrorHandler("random_name.out")
+ h2 = PoscarErrorHandler.from_dict(h.to_dict)
+ self.assertEqual(type(h2), PoscarErrorHandler)
+ self.assertEqual(h2.output_filename, "random_name.out")
+
+
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()
View
2 requirements.txt
@@ -1 +1 @@
-pymatgen>=2.5.0
+pymatgen>=2.6.2
View
2 setup.py
@@ -14,7 +14,7 @@
packages=find_packages(),
version="0.2.4a",
install_requires=[],
- extras_require={"vasp": ["pymatgen>=2.5.0"]},
+ extras_require={"vasp": ["pymatgen>=2.6.2"]},
package_data={},
author="Shyue Ping Ong",
author_email="shyuep@gmail.com",

0 comments on commit 6f0536c

Please sign in to comment.