

def test_scf_gdm(self):
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm.inp'), os.path.join(scr_dir, 'hf_gdm.inp'))
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm.out'), os.path.join(scr_dir, 'hf_gdm.out'))
    h = QChemErrorHandler(input_file='hf_gdm.inp', output_file='hf_gdm.out')
    has_error = h.check()
    self.assertTrue(has_error)
    d = h.correct()
    self.assertEqual(d, {
        'errors': ['Bad SCF convergence', 'Geometry optimization failed', 'Molecular charge is not found'],
        'actions': ['increase_iter'],
    })
    with open(os.path.join(test_dir, 'hf_gdm_tried_0.inp')) as f:
        ref = [line.strip() for line in f.readlines()]
    with open(os.path.join(scr_dir, 'hf_gdm.inp')) as f:
        ans = [line.strip() for line in f.readlines()]
    ans = self._revert_scf_fix_strategy_to_version(ans, fix_version='1.0')
    self.assertEqual(ref, ans)
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm_tried_0.inp'), os.path.join(scr_dir, 'hf_gdm_tried_0.inp'))
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm.out'), os.path.join(scr_dir, 'hf_gdm.out'))
    h = QChemErrorHandler(input_file='hf_gdm_tried_0.inp', output_file='hf_gdm.out')
    has_error = h.check()
    self.assertTrue(has_error)
    d = h.correct()
    self.assertEqual(d, {
        'errors': ['Bad SCF convergence', 'Geometry optimization failed', 'Molecular charge is not found'],
        'actions': ['diis_gdm'],
    })
    with open(os.path.join(test_dir, 'hf_gdm_tried_1.inp')) as f:
        ref = [line.strip() for line in f.readlines()]
    with open(os.path.join(scr_dir, 'hf_gdm_tried_0.inp')) as f:
        ans = [line.strip() for line in f.readlines()]
    self.assertEqual(ref, ans)
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm_tried_1.inp'), os.path.join(scr_dir, 'hf_gdm_tried_1.inp'))
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm.out'), os.path.join(scr_dir, 'hf_gdm.out'))
    h = QChemErrorHandler(input_file='hf_gdm_tried_1.inp', output_file='hf_gdm.out')
    has_error = h.check()
    self.assertTrue(has_error)
    d = h.correct()
    self.assertEqual(d, {
        'errors': ['Bad SCF convergence', 'Geometry optimization failed', 'Molecular charge is not found'],
        'actions': ['gwh'],
    })
    with open(os.path.join(test_dir, 'hf_gdm_tried_2.inp')) as f:
        ref = [line.strip() for line in f.readlines()]
    with open(os.path.join(scr_dir, 'hf_gdm_tried_1.inp')) as f:
        ans = [line.strip() for line in f.readlines()]
    self.assertEqual(ref, ans)
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm_tried_2.inp'), os.path.join(scr_dir, 'hf_gdm_tried_2.inp'))
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm.out'), os.path.join(scr_dir, 'hf_gdm.out'))
    h = QChemErrorHandler(input_file='hf_gdm_tried_2.inp', output_file='hf_gdm.out')
    has_error = h.check()
    self.assertTrue(has_error)
    d = h.correct()
    self.assertEqual(d, {
        'errors': ['Bad SCF convergence', 'Geometry optimization failed', 'Molecular charge is not found'],
        'actions': ['rca'],
    })
    with open(os.path.join(test_dir, 'hf_gdm_tried_3.inp')) as f:
        ref = [line.strip() for line in f.readlines()]
    with open(os.path.join(scr_dir, 'hf_gdm_tried_2.inp')) as f:
        ans = [line.strip() for line in f.readlines()]
    self.assertEqual(ref, ans)
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm_tried_3.inp'), os.path.join(scr_dir, 'hf_gdm_tried_3.inp'))
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm.out'), os.path.join(scr_dir, 'hf_gdm.out'))
    h = QChemErrorHandler(input_file='hf_gdm_tried_3.inp', output_file='hf_gdm.out')
    has_error = h.check()
    self.assertTrue(has_error)
    d = h.correct()
    self.assertEqual(d, {
        'errors': ['Bad SCF convergence', 'Geometry optimization failed', 'Molecular charge is not found'],
        'actions': ['gdm'],
    })
    with open(os.path.join(test_dir, 'hf_gdm_tried_4.inp')) as f:
        ref = [line.strip() for line in f.readlines()]
    with open(os.path.join(scr_dir, 'hf_gdm_tried_3.inp')) as f:
        ans = [line.strip() for line in f.readlines()]
    self.assertEqual(ref, ans)
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm_tried_4.inp'), os.path.join(scr_dir, 'hf_gdm_tried_4.inp'))
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm.out'), os.path.join(scr_dir, 'hf_gdm.out'))
    h = QChemErrorHandler(input_file='hf_gdm_tried_4.inp', output_file='hf_gdm.out')
    has_error = h.check()
    self.assertTrue(has_error)
    d = h.correct()
    self.assertEqual(d, {
        'errors': ['Bad SCF convergence', 'Geometry optimization failed', 'Molecular charge is not found'],
        'actions': ['core+gdm'],
    })
    with open(os.path.join(test_dir, 'hf_gdm_tried_5.inp')) as f:
        ref = [line.strip() for line in f.readlines()]
    with open(os.path.join(scr_dir, 'hf_gdm_tried_4.inp')) as f:
        ans = [line.strip() for line in f.readlines()]
    self.assertEqual(ref, ans)
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm_tried_5.inp'), os.path.join(scr_dir, 'hf_gdm_tried_5.inp'))
    shutil.copyfile(os.path.join(test_dir, 'hf_gdm.out'), os.path.join(scr_dir, 'hf_gdm.out'))
    h = QChemErrorHandler(input_file='hf_gdm_tried_5.inp', output_file='hf_gdm.out')
    has_error = h.check()
    self.assertTrue(has_error)
    d = h.correct()
    self.assertEqual(d, {
        'errors': ['Bad SCF convergence', 'Geometry optimization failed', 'Molecular charge is not found'],
        'actions': None,
    })

dataset/ETHPy150Open materialsproject/custodian/custodian/qchem/tests/test_handlers.py QChemErrorHandlerTest.test_scf_gdm/original