From 5d6e14d36a89ddb2cc199e682c59014260799aa3 Mon Sep 17 00:00:00 2001 From: Julian Self Date: Tue, 17 Apr 2018 12:10:10 -0700 Subject: [PATCH 1/3] Added PCM and Solvent sections to QChem input and tests --- pymatgen/io/qchem_io/inputs.py | 58 +++++++++++++++++++++-- pymatgen/io/qchem_io/tests/test_inputs.py | 44 ++++++++++++++++- 2 files changed, 98 insertions(+), 4 deletions(-) diff --git a/pymatgen/io/qchem_io/inputs.py b/pymatgen/io/qchem_io/inputs.py index 1560e41b64e..101a3468bb9 100644 --- a/pymatgen/io/qchem_io/inputs.py +++ b/pymatgen/io/qchem_io/inputs.py @@ -10,7 +10,7 @@ Classes for reading/manipulating/writing QChem ouput files. """ -__author__ = "Brandon Wood, Samuel Blau, Shyam Dwaraknath" +__author__ = "Brandon Wood, Samuel Blau, Shyam Dwaraknath, Julian Self" __copyright__ = "Copyright 2018, The Materials Project" __version__ = "0.1" __email__ = "b.wood@berkeley.edu" @@ -42,10 +42,12 @@ class QCInput(MSONable): Ex. opt = {"CONSTRAINT": ["tors 2 3 4 5 25.0", "tors 2 5 7 9 80.0"], "FIXED": ["2 XY"]} """ - def __init__(self, molecule, rem, opt=None): + def __init__(self, molecule, rem, opt=None, pcm=None, solvent=None): self.molecule = molecule self.rem = rem self.opt = opt + self.pcm = pcm + self.solvent = solvent def __str__(self): combined_list = [] @@ -59,6 +61,14 @@ def __str__(self): if self.opt: combined_list.append(self.opt_template(self.opt)) combined_list.append("") + # pcm section + if self.pcm: + combined_list.append(self.pcm_template(self.pcm)) + combined_list.append("") + # solvent section + if self.solvent: + combined_list.append(self.solvent_template(self.solvent)) + combined_list.append("") return '\n'.join(combined_list) @staticmethod @@ -78,9 +88,15 @@ def from_string(cls, string): rem = cls.read_rem(string) # only molecule and rem are necessary everything else is checked opt = None + pcm = None + solvent = None if "opt" in sections: opt = cls.read_opt(string) - return cls(molecule, rem, opt=opt) + if "pcm" in sections: + pcm = cls.read_pcm(string) + if "solvent" in sections: + solvent = cls.read_solvent(string) + return cls(molecule, rem, opt=opt, pcm=pcm, solvent=solvent) def write_file(self, filename): with open(filename, 'w') as f: @@ -148,6 +164,24 @@ def opt_template(opt): opt_list.append("$end") return '\n'.join(opt_list) + @staticmethod + def pcm_template(pcm): + pcm_list = [] + pcm_list.append("$pcm") + for key, value in pcm.items(): + pcm_list.append(" {key} = {value}".format(key=key, value=value)) + pcm_list.append("$end") + return '\n'.join(pcm_list) + + @staticmethod + def solvent_template(solvent): + solvent_list = [] + solvent_list.append("$solvent") + for key, value in solvent.items(): + solvent_list.append(" {key} = {value}".format(key=key, value=value)) + solvent_list.append("$end") + return '\n'.join(solvent_list) + @staticmethod def find_sections(string): patterns = {"sections": r"^\s*?\$([a-z]+)", "multiple_jobs": r"(@@@)"} @@ -236,3 +270,21 @@ def read_opt(string): string, header_pattern=cc_header, row_pattern=cc_row, footer_pattern=cc_footer) opt["CONNECT"] = [val[0] for val in cc_table[0]] return opt + + @staticmethod + def read_pcm(string): + header = r"^\s*\$pcm" + row = r"\s*(\S+)\s+=?\s+(\S+)" + footer = r"^\s*\$end" + pcm_table = read_table_pattern(string, header_pattern=header, row_pattern=row, footer_pattern=footer) + pcm = {key: val for key, val in pcm_table[0]} + return pcm + + @staticmethod + def read_solvent(string): + header = r"^\s*\$solvent" + row = r"\s*(\S+)\s+=?\s+(\S+)" + footer = r"^\s*\$end" + solvent_table = read_table_pattern(string, header_pattern=header, row_pattern=row, footer_pattern=footer) + solvent = {key: val for key, val in solvent_table[0]} + return solvent diff --git a/pymatgen/io/qchem_io/tests/test_inputs.py b/pymatgen/io/qchem_io/tests/test_inputs.py index fb255c405b4..98e1b9f6405 100644 --- a/pymatgen/io/qchem_io/tests/test_inputs.py +++ b/pymatgen/io/qchem_io/tests/test_inputs.py @@ -11,7 +11,7 @@ from pymatgen.util.testing import PymatgenTest from pymatgen.io.qchem_io.inputs import QCInput -__author__ = "Brandon Wood, Samuel Blau, Shyam Dwaraknath" +__author__ = "Brandon Wood, Samuel Blau, Shyam Dwaraknath, Julian Self" __copyright__ = "Copyright 2018, The Materials Project" __version__ = "0.1" __email__ = "b.wood@berkeley.edu" @@ -88,6 +88,21 @@ def test_opt_template(self): $end""" self.assertEqual(opt_actual, opt_test) + def test_pcm_template(self): + pcm_params = {"theory": "cpcm"} + pcm_test = QCInput.pcm_template(pcm_params) + pcm_actual = """$pcm + theory = cpcm +$end""" + self.assertEqual(pcm_actual, pcm_test) + + def test_solvent_template(self): + solvent_params = {"dielectric": "5.0"} + solvent_test = QCInput.solvent_template(solvent_params) + solvent_actual = """$solvent + dielectric = 5.0 +$end""" + def test_find_sections(self): str_single_job_input = """$molecule 0 1 @@ -473,6 +488,33 @@ def test_from_multi_jobs_file(self): self.assertEqual(molecule_2_actual, job_list_test[1].molecule) self.assertEqual(rem_2_actual, job_list_test[1].rem) + def test_read_pcm(self): + str_pcm = """I'm once again trying to break you! + + $pcm + theory = cpcm + radii = uff + vdwscale = 1.1 + $end""" + pcm_test = QCInput.read_pcm(str_pcm) + pcm_actual = { + "theory": "cpcm", + "radii": "uff", + "vdwscale": "1.1" + } + self.assertDictEqual(pcm_actual, pcm_test) + + def test_read_solvent(self): + str_solvent = """Once again, I'm trying to break you! + + $solvent + dielectric = 5.0 + $end""" + solvent_test = QCInput.read_solvent(str_solvent) + solvent_actual = { + "dielectric": "5.0", + } + self.assertDictEqual(solvent_actual, solvent_test) if __name__ == "__main__": unittest.main() From d0a677ab2cbd12f58943ea594460da3ddae9b942 Mon Sep 17 00:00:00 2001 From: Julian Self Date: Tue, 17 Apr 2018 14:37:01 -0700 Subject: [PATCH 2/3] Fixed indentation problem in test_inputs for solvent --- pymatgen/io/qchem_io/tests/test_inputs.py | 38 +++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/pymatgen/io/qchem_io/tests/test_inputs.py b/pymatgen/io/qchem_io/tests/test_inputs.py index 98e1b9f6405..e8cb79bf8cf 100644 --- a/pymatgen/io/qchem_io/tests/test_inputs.py +++ b/pymatgen/io/qchem_io/tests/test_inputs.py @@ -489,32 +489,32 @@ def test_from_multi_jobs_file(self): self.assertEqual(rem_2_actual, job_list_test[1].rem) def test_read_pcm(self): - str_pcm = """I'm once again trying to break you! - - $pcm - theory = cpcm - radii = uff - vdwscale = 1.1 - $end""" - pcm_test = QCInput.read_pcm(str_pcm) - pcm_actual = { + str_pcm = """I'm once again trying to break you! + +$pcm + theory = cpcm + radii = uff + vdwscale = 1.1 +$end""" + pcm_test = QCInput.read_pcm(str_pcm) + pcm_actual = { "theory": "cpcm", "radii": "uff", "vdwscale": "1.1" - } - self.assertDictEqual(pcm_actual, pcm_test) + } + self.assertDictEqual(pcm_actual, pcm_test) def test_read_solvent(self): - str_solvent = """Once again, I'm trying to break you! + str_solvent = """Once again, I'm trying to break you! - $solvent - dielectric = 5.0 - $end""" - solvent_test = QCInput.read_solvent(str_solvent) - solvent_actual = { +$solvent + dielectric = 5.0 +$end""" + solvent_test = QCInput.read_solvent(str_solvent) + solvent_actual = { "dielectric": "5.0", - } - self.assertDictEqual(solvent_actual, solvent_test) + } + self.assertDictEqual(solvent_actual, solvent_test) if __name__ == "__main__": unittest.main() From 8b81fdb744e02a547c58e16130ffa20ccb2d592b Mon Sep 17 00:00:00 2001 From: Julian Self Date: Tue, 17 Apr 2018 15:13:43 -0700 Subject: [PATCH 3/3] Fixed solvent in test --- pymatgen/io/qchem_io/tests/test_inputs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pymatgen/io/qchem_io/tests/test_inputs.py b/pymatgen/io/qchem_io/tests/test_inputs.py index e8cb79bf8cf..9914acfe5b2 100644 --- a/pymatgen/io/qchem_io/tests/test_inputs.py +++ b/pymatgen/io/qchem_io/tests/test_inputs.py @@ -102,6 +102,7 @@ def test_solvent_template(self): solvent_actual = """$solvent dielectric = 5.0 $end""" + self.assertEqual(solvent_actual, solvent_test) def test_find_sections(self): str_single_job_input = """$molecule