class NwInputTest(unittest.TestCase): def setUp(self): tasks = [ NwTask.dft_task(mol, operation="optimize", xc="b3lyp", basis_set="6-31++G*"), NwTask.dft_task(mol, operation="freq", xc="b3lyp", basis_set="6-31++G*"), NwTask.dft_task(mol, operation="energy", xc="b3lyp", basis_set="6-311++G**"), NwTask.dft_task( mol, charge=mol.charge + 1, operation="energy", xc="b3lyp", basis_set="6-311++G**", ), NwTask.dft_task( mol, charge=mol.charge - 1, operation="energy", xc="b3lyp", basis_set="6-311++G**", ), ] self.nwi = NwInput( mol, tasks, geometry_options=["units", "angstroms", "noautoz"], memory_options="total 1000 mb", ) self.nwi_symm = NwInput( mol, tasks, geometry_options=["units", "angstroms", "noautoz"], symmetry_options=["c1"], ) def test_str(self): ans = """memory total 1000 mb geometry units angstroms noautoz C 0.0 0.0 0.0 H 0.0 0.0 1.089 H 1.026719 0.0 -0.363 H -0.51336 -0.889165 -0.363 H -0.51336 0.889165 -0.363 end title "H4C1 dft optimize" charge 0 basis cartesian C library "6-31++G*" H library "6-31++G*" end dft mult 1 xc b3lyp end task dft optimize title "H4C1 dft freq" charge 0 basis cartesian C library "6-31++G*" H library "6-31++G*" end dft mult 1 xc b3lyp end task dft freq title "H4C1 dft energy" charge 0 basis cartesian C library "6-311++G**" H library "6-311++G**" end dft mult 1 xc b3lyp end task dft energy title "H4C1 dft energy" charge 1 basis cartesian C library "6-311++G**" H library "6-311++G**" end dft mult 2 xc b3lyp end task dft energy title "H4C1 dft energy" charge -1 basis cartesian C library "6-311++G**" H library "6-311++G**" end dft mult 2 xc b3lyp end task dft energy """ self.assertEqual(str(self.nwi), ans) ans_symm = """geometry units angstroms noautoz symmetry c1 C 0.0 0.0 0.0 H 0.0 0.0 1.089 H 1.026719 0.0 -0.363 H -0.51336 -0.889165 -0.363 H -0.51336 0.889165 -0.363 end title "H4C1 dft optimize" charge 0 basis cartesian C library "6-31++G*" H library "6-31++G*" end dft mult 1 xc b3lyp end task dft optimize title "H4C1 dft freq" charge 0 basis cartesian C library "6-31++G*" H library "6-31++G*" end dft mult 1 xc b3lyp end task dft freq title "H4C1 dft energy" charge 0 basis cartesian C library "6-311++G**" H library "6-311++G**" end dft mult 1 xc b3lyp end task dft energy title "H4C1 dft energy" charge 1 basis cartesian C library "6-311++G**" H library "6-311++G**" end dft mult 2 xc b3lyp end task dft energy title "H4C1 dft energy" charge -1 basis cartesian C library "6-311++G**" H library "6-311++G**" end dft mult 2 xc b3lyp end task dft energy """ self.assertEqual(str(self.nwi_symm), ans_symm) def test_to_from_dict(self): d = self.nwi.as_dict() nwi = NwInput.from_dict(d) self.assertIsInstance(nwi, NwInput) # Ensure it is json-serializable. json.dumps(d) d = self.nwi_symm.as_dict() nwi_symm = NwInput.from_dict(d) self.assertIsInstance(nwi_symm, NwInput) json.dumps(d) def test_from_string_and_file(self): nwi = NwInput.from_file(os.path.join(test_dir, "ch4.nw")) self.assertEqual(nwi.tasks[0].theory, "dft") self.assertEqual(nwi.memory_options, "total 1000 mb stack 400 mb") self.assertEqual(nwi.tasks[0].basis_set["C"], "6-31++G*") self.assertEqual(nwi.tasks[-1].basis_set["C"], "6-311++G**") # Try a simplified input. str_inp = """start H4C1 geometry units angstroms C 0.0 0.0 0.0 H 0.0 0.0 1.089 H 1.026719 0.0 -0.363 H -0.51336 -0.889165 -0.363 H -0.51336 0.889165 -0.363 end title "H4C1 dft optimize" charge 0 basis cartesian H library "6-31++G*" C library "6-31++G*" end dft xc b3lyp mult 1 end task scf optimize title "H4C1 dft freq" charge 0 task scf freq title "H4C1 dft energy" charge 0 basis cartesian H library "6-311++G**" C library "6-311++G**" end task dft energy title "H4C1 dft energy" charge 1 dft xc b3lyp mult 2 end task dft energy title "H4C1 dft energy" charge -1 task dft energy """ nwi = NwInput.from_string(str_inp) self.assertEqual(nwi.geometry_options, ["units", "angstroms"]) self.assertEqual(nwi.tasks[0].theory, "scf") self.assertEqual(nwi.tasks[0].basis_set["C"], "6-31++G*") self.assertEqual(nwi.tasks[-1].theory, "dft") self.assertEqual(nwi.tasks[-1].basis_set["C"], "6-311++G**") str_inp_symm = str_inp.replace( "geometry units angstroms", "geometry units angstroms\n symmetry c1") nwi_symm = NwInput.from_string(str_inp_symm) self.assertEqual(nwi_symm.geometry_options, ["units", "angstroms"]) self.assertEqual(nwi_symm.symmetry_options, ["c1"]) self.assertEqual(nwi_symm.tasks[0].theory, "scf") self.assertEqual(nwi_symm.tasks[0].basis_set["C"], "6-31++G*") self.assertEqual(nwi_symm.tasks[-1].theory, "dft") self.assertEqual(nwi_symm.tasks[-1].basis_set["C"], "6-311++G**")
class NwInputTest(unittest.TestCase): def setUp(self): tasks = [ NwTask.dft_task(mol, operation="optimize", xc="b3lyp", basis_set="6-31++G*"), NwTask.dft_task(mol, operation="freq", xc="b3lyp", basis_set="6-31++G*"), NwTask.dft_task(mol, operation="energy", xc="b3lyp", basis_set="6-311++G**"), NwTask.dft_task(mol, charge=mol.charge + 1, operation="energy", xc="b3lyp", basis_set="6-311++G**"), NwTask.dft_task(mol, charge=mol.charge - 1, operation="energy", xc="b3lyp", basis_set="6-311++G**") ] self.nwi = NwInput(mol, tasks, geometry_options=["units", "angstroms", "noautoz"], memory_options="total 1000 mb") self.nwi_symm = NwInput(mol, tasks, geometry_options=["units", "angstroms", "noautoz"], symmetry_options=["c1"]) def test_str(self): ans = """memory total 1000 mb geometry units angstroms noautoz C 0.0 0.0 0.0 H 0.0 0.0 1.089 H 1.026719 0.0 -0.363 H -0.51336 -0.889165 -0.363 H -0.51336 0.889165 -0.363 end title "H4C1 dft optimize" charge 0 basis C library "6-31++G*" H library "6-31++G*" end dft mult 1 xc b3lyp end task dft optimize title "H4C1 dft freq" charge 0 basis C library "6-31++G*" H library "6-31++G*" end dft mult 1 xc b3lyp end task dft freq title "H4C1 dft energy" charge 0 basis C library "6-311++G**" H library "6-311++G**" end dft mult 1 xc b3lyp end task dft energy title "H4C1 dft energy" charge 1 basis C library "6-311++G**" H library "6-311++G**" end dft mult 2 xc b3lyp end task dft energy title "H4C1 dft energy" charge -1 basis C library "6-311++G**" H library "6-311++G**" end dft mult 2 xc b3lyp end task dft energy """ self.assertEqual(str(self.nwi), ans) ans_symm = """geometry units angstroms noautoz symmetry c1 C 0.0 0.0 0.0 H 0.0 0.0 1.089 H 1.026719 0.0 -0.363 H -0.51336 -0.889165 -0.363 H -0.51336 0.889165 -0.363 end title "H4C1 dft optimize" charge 0 basis C library "6-31++G*" H library "6-31++G*" end dft mult 1 xc b3lyp end task dft optimize title "H4C1 dft freq" charge 0 basis C library "6-31++G*" H library "6-31++G*" end dft mult 1 xc b3lyp end task dft freq title "H4C1 dft energy" charge 0 basis C library "6-311++G**" H library "6-311++G**" end dft mult 1 xc b3lyp end task dft energy title "H4C1 dft energy" charge 1 basis C library "6-311++G**" H library "6-311++G**" end dft mult 2 xc b3lyp end task dft energy title "H4C1 dft energy" charge -1 basis C library "6-311++G**" H library "6-311++G**" end dft mult 2 xc b3lyp end task dft energy """ self.assertEqual(str(self.nwi_symm), ans_symm) def test_to_from_dict(self): d = self.nwi.as_dict() nwi = NwInput.from_dict(d) self.assertIsInstance(nwi, NwInput) #Ensure it is json-serializable. json.dumps(d) d = self.nwi_symm.as_dict() nwi_symm = NwInput.from_dict(d) self.assertIsInstance(nwi_symm, NwInput) json.dumps(d) def test_from_string_and_file(self): nwi = NwInput.from_file(os.path.join(test_dir, "ch4.nw")) self.assertEqual(nwi.tasks[0].theory, "dft") self.assertEqual(nwi.memory_options, "total 1000 mb stack 400 mb") self.assertEqual(nwi.tasks[0].basis_set["C"], "6-31++G*") self.assertEqual(nwi.tasks[-1].basis_set["C"], "6-311++G**") #Try a simplified input. str_inp = """start H4C1 geometry units angstroms C 0.0 0.0 0.0 H 0.0 0.0 1.089 H 1.026719 0.0 -0.363 H -0.51336 -0.889165 -0.363 H -0.51336 0.889165 -0.363 end title "H4C1 dft optimize" charge 0 basis H library "6-31++G*" C library "6-31++G*" end dft xc b3lyp mult 1 end task scf optimize title "H4C1 dft freq" charge 0 task scf freq title "H4C1 dft energy" charge 0 basis H library "6-311++G**" C library "6-311++G**" end task dft energy title "H4C1 dft energy" charge 1 dft xc b3lyp mult 2 end task dft energy title "H4C1 dft energy" charge -1 task dft energy """ nwi = NwInput.from_string(str_inp) self.assertEqual(nwi.geometry_options, ['units', 'angstroms']) self.assertEqual(nwi.tasks[0].theory, "scf") self.assertEqual(nwi.tasks[0].basis_set["C"], "6-31++G*") self.assertEqual(nwi.tasks[-1].theory, "dft") self.assertEqual(nwi.tasks[-1].basis_set["C"], "6-311++G**") str_inp_symm = str_inp.replace("geometry units angstroms", "geometry units angstroms\n symmetry " "c1") nwi_symm = NwInput.from_string(str_inp_symm) self.assertEqual(nwi_symm.geometry_options, ['units', 'angstroms']) self.assertEqual(nwi_symm.symmetry_options, ['c1']) self.assertEqual(nwi_symm.tasks[0].theory, "scf") self.assertEqual(nwi_symm.tasks[0].basis_set["C"], "6-31++G*") self.assertEqual(nwi_symm.tasks[-1].theory, "dft") self.assertEqual(nwi_symm.tasks[-1].basis_set["C"], "6-311++G**")