From 33ebef206edfc34c6a5be293df92d65b311cceeb Mon Sep 17 00:00:00 2001 From: Calvin Pieters Date: Mon, 5 Jun 2023 22:31:56 +0300 Subject: [PATCH] Created GaussianTests for trsh inputs and Readjusted gaussian writing input file Fixed trsh_ess_test for Gaussian --- arc/job/adapters/gaussian.py | 10 +- arc/job/adapters/gaussian_test.py | 435 ++++++++++++++++++++++-------- arc/job/trsh_test.py | 2 +- 3 files changed, 326 insertions(+), 121 deletions(-) diff --git a/arc/job/adapters/gaussian.py b/arc/job/adapters/gaussian.py index c82d3524a0..b6a9491aaa 100644 --- a/arc/job/adapters/gaussian.py +++ b/arc/job/adapters/gaussian.py @@ -230,14 +230,12 @@ def write_input_file(self) -> None: input_dict['memory'] = self.input_file_memory input_dict['method'] = self.level.method input_dict['multiplicity'] = self.multiplicity + input_dict['xyz'] = xyz_to_str(self.xyz) input_dict['scan_trsh'] = self.args['keyword']['scan_trsh'] if 'scan_trsh' in self.args['keyword'] else '' input_dict['trsh'] = self.args['trsh']['trsh'] if 'trsh' in self.args['trsh'] else '' - input_dict['xyz'] = xyz_to_str(self.xyz) - if 'Acc2E=14' in input_dict['trsh']: - input_dict['trsh'] = input_dict['trsh'].replace('Acc2E=14', '') - if 'checkfile=None' in input_dict['trsh']: - input_dict['trsh'] = input_dict['trsh'].replace('checkfile=None', '') - integral_algorithm = 'Acc2E=14' if (self.args.get('trsh') and self.args['trsh'].get('trsh') and 'Acc2E=14' in self.args['trsh']['trsh']) else 'Acc2E=12' + input_dict['trsh'] = ' '.join(input_dict['trsh']) if isinstance(input_dict['trsh'], list) else input_dict['trsh'] + input_dict['trsh'] = input_dict['trsh'].replace('int=(Acc2E=14)', '') if 'Acc2E=14' in input_dict['trsh'] else input_dict['trsh'] + integral_algorithm = 'Acc2E=14' if self.args.get('trsh', {}).get('trsh') and any('int=(Acc2E=14)' in element for element in self.args['trsh']['trsh']) else 'Acc2E=12' if self.level.basis is not None: input_dict['slash_1'] = '/' diff --git a/arc/job/adapters/gaussian_test.py b/arc/job/adapters/gaussian_test.py index 1ddaafe40f..dcf52395dd 100644 --- a/arc/job/adapters/gaussian_test.py +++ b/arc/job/adapters/gaussian_test.py @@ -27,109 +27,109 @@ def setUpClass(cls): A method that is run before all unit tests in this class. """ cls.maxDiff = None - # cls.job_1 = GaussianAdapter(execution_type='incore', - # job_type='composite', - # level=Level(method='cbs-qb3-paraskevas'), - # project='test', - # project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), - # species=[ARCSpecies(label='spc1', xyz=['O 0 0 1'])], - # testing=True, - # args={'keyword': {'general': 'IOp(1/12=5,3/44=0)'}}, - # ) - # cls.job_2 = GaussianAdapter(execution_type='queue', - # job_type='opt', - # level=Level(method='wb97xd', - # basis='def2-TZVP', - # solvation_method='SMD', - # solvent='Water'), - # project='test', - # project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), - # species=[ARCSpecies(label='spc1', xyz=['O 0 0 1']), - # ARCSpecies(label='spc2', xyz=['O 0 0 2'])], - # testing=True, - # ) - # cls.job_3 = GaussianAdapter(execution_type='queue', - # job_type='opt', - # level=Level(method='wb97xd', - # basis='def2-TZVP', - # solvation_method='SMD', - # solvent='Water'), - # project='test', - # project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), - # species=[ARCSpecies(label='spc1', xyz=['O 0 0 1'])], - # testing=True, - # ) - # spc_4 = ARCSpecies(label='ethanol', xyz=["""C 1.1658210 -0.4043550 0.0000000 - # C 0.0000000 0.5518050 0.0000000 - # O -1.1894600 -0.2141940 0.0000000 - # H -1.9412580 0.3751850 0.0000000 - # H 2.1054020 0.1451160 0.0000000 - # H 1.1306240 -1.0387850 0.8830320 - # H 1.1306240 -1.0387850 -0.8830320 - # H 0.0476820 1.1930570 0.8835910 - # H 0.0476820 1.1930570 -0.8835910"""], - # directed_rotors={'brute_force_sp': [[1, 2], [2, 3]]}) - # spc_4.determine_rotors() # also calls initialize_directed_rotors() - # cls.job_4 = GaussianAdapter(execution_type='queue', - # job_type='scan', - # level=Level(method='wb97xd', - # basis='def2-TZVP'), - # project='test', - # project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), - # species=[spc_4], - # rotor_index=0, - # testing=True, - # args={'block': {'general': 'additional\ngaussian\nblock'}}, - # ) - # cls.job_5 = GaussianAdapter(execution_type='queue', - # job_type='freq', - # level=Level(method='wb97xd', - # basis='def2-TZVP'), - # project='test', - # project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), - # species=[ARCSpecies(label='birad singlet', - # xyz=['O 0 0 1'], - # multiplicity=1, - # number_of_radicals=2)], - # testing=True, - # ) - # cls.job_6 = GaussianAdapter(execution_type='queue', - # job_type='optfreq', - # level=Level(method='wb97xd', - # basis='def2-TZVP'), - # project='test', - # project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), - # species=[ARCSpecies(label='anion', xyz=['O 0 0 1'], charge=-1, is_ts=False)], - # testing=True, - # ) - # cls.job_7 = GaussianAdapter(execution_type='queue', - # job_type='irc', - # level=Level(method='wb97xd', - # basis='def2-TZVP'), - # project='test', - # project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), - # species=[ARCSpecies(label='IRC', xyz=['O 0 0 1'], is_ts=True)], - # irc_direction='reverse', - # testing=True, - # ) - # cls.job_8 = GaussianAdapter(execution_type='queue', - # job_type='composite', - # level=Level(method='cbs-qb3-paraskevas'), - # project='test', - # project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), - # species=[ARCSpecies(label='spc1', xyz=['O 0 0 1'])], - # testing=True, - # args={'keyword': {'general': 'IOp(1/12=5,3/44=0)'}}, - # ) - # cls.job_9 = GaussianAdapter(execution_type='local', - # job_type='optfreq', - # level=Level(method='wb97xd', - # basis='def2-TZVP'), - # project='test', - # project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), - # species=[ARCSpecies(label='anion', xyz=['O 0 0 1'], charge=-1, is_ts=False)], - # testing=True, - # ) + cls.job_1 = GaussianAdapter(execution_type='incore', + job_type='composite', + level=Level(method='cbs-qb3-paraskevas'), + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[ARCSpecies(label='spc1', xyz=['O 0 0 1'])], + testing=True, + args={'keyword': {'general': 'IOp(1/12=5,3/44=0)'}}, + ) + cls.job_2 = GaussianAdapter(execution_type='queue', + job_type='opt', + level=Level(method='wb97xd', + basis='def2-TZVP', + solvation_method='SMD', + solvent='Water'), + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[ARCSpecies(label='spc1', xyz=['O 0 0 1']), + ARCSpecies(label='spc2', xyz=['O 0 0 2'])], + testing=True, + ) + cls.job_3 = GaussianAdapter(execution_type='queue', + job_type='opt', + level=Level(method='wb97xd', + basis='def2-TZVP', + solvation_method='SMD', + solvent='Water'), + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[ARCSpecies(label='spc1', xyz=['O 0 0 1'])], + testing=True, + ) + spc_4 = ARCSpecies(label='ethanol', xyz=["""C 1.1658210 -0.4043550 0.0000000 + C 0.0000000 0.5518050 0.0000000 + O -1.1894600 -0.2141940 0.0000000 + H -1.9412580 0.3751850 0.0000000 + H 2.1054020 0.1451160 0.0000000 + H 1.1306240 -1.0387850 0.8830320 + H 1.1306240 -1.0387850 -0.8830320 + H 0.0476820 1.1930570 0.8835910 + H 0.0476820 1.1930570 -0.8835910"""], + directed_rotors={'brute_force_sp': [[1, 2], [2, 3]]}) + spc_4.determine_rotors() # also calls initialize_directed_rotors() + cls.job_4 = GaussianAdapter(execution_type='queue', + job_type='scan', + level=Level(method='wb97xd', + basis='def2-TZVP'), + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[spc_4], + rotor_index=0, + testing=True, + args={'block': {'general': 'additional\ngaussian\nblock'}}, + ) + cls.job_5 = GaussianAdapter(execution_type='queue', + job_type='freq', + level=Level(method='wb97xd', + basis='def2-TZVP'), + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[ARCSpecies(label='birad singlet', + xyz=['O 0 0 1'], + multiplicity=1, + number_of_radicals=2)], + testing=True, + ) + cls.job_6 = GaussianAdapter(execution_type='queue', + job_type='optfreq', + level=Level(method='wb97xd', + basis='def2-TZVP'), + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[ARCSpecies(label='anion', xyz=['O 0 0 1'], charge=-1, is_ts=False)], + testing=True, + ) + cls.job_7 = GaussianAdapter(execution_type='queue', + job_type='irc', + level=Level(method='wb97xd', + basis='def2-TZVP'), + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[ARCSpecies(label='IRC', xyz=['O 0 0 1'], is_ts=True)], + irc_direction='reverse', + testing=True, + ) + cls.job_8 = GaussianAdapter(execution_type='queue', + job_type='composite', + level=Level(method='cbs-qb3-paraskevas'), + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[ARCSpecies(label='spc1', xyz=['O 0 0 1'])], + testing=True, + args={'keyword': {'general': 'IOp(1/12=5,3/44=0)'}}, + ) + cls.job_9 = GaussianAdapter(execution_type='local', + job_type='optfreq', + level=Level(method='wb97xd', + basis='def2-TZVP'), + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[ARCSpecies(label='anion', xyz=['O 0 0 1'], charge=-1, is_ts=False)], + testing=True, + ) cls.job_10 = GaussianAdapter(execution_type='local', job_type='optfreq', level=Level(method='wb97xd'), @@ -138,7 +138,7 @@ def setUpClass(cls): project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), species=[ARCSpecies(label='anion', xyz=['O 0 0 1'], charge=-1, is_ts=False)], testing=True, - args={'trsh': {'trsh': 'Acc2E=14'}}, + args={'trsh': {'trsh': ['int=(Acc2E=14)']}}, ) # Need to setup trsh for job_11 @@ -162,7 +162,17 @@ def setUpClass(cls): num_heavy_atoms, cpu_cores, ess_trsh_methods) args = {'keyword': {}, 'block': {}} if trsh_keyword: - args['trsh'] = {'trsh': trsh} + args['trsh'] = {'trsh': trsh_keyword} + spc_11 = ARCSpecies(label='ethanol', xyz=["""C 1.1658210 -0.4043550 0.0000000 + C 0.0000000 0.5518050 0.0000000 + O -1.1894600 -0.2141940 0.0000000 + H -1.9412580 0.3751850 0.0000000 + H 2.1054020 0.1451160 0.0000000 + H 1.1306240 -1.0387850 0.8830320 + H 1.1306240 -1.0387850 -0.8830320 + H 0.0476820 1.1930570 0.8835910 + H 0.0476820 1.1930570 -0.8835910"""], + directed_rotors={'brute_force_sp': [[1, 2], [2, 3]]}) cls.job_11 = GaussianAdapter(execution_type='local', job_type='optfreq', level=Level(method='wb97xd'), @@ -170,10 +180,96 @@ def setUpClass(cls): ess_trsh_methods=ess_trsh_methods, project='test', project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), - species=[ARCSpecies(label='anion', xyz=['O 0 0 1'], charge=-1, is_ts=False)], + species=[spc_11], testing=True, args=args ) + # Gaussian: test 1 + job_status = {'keywords': ['SCF']} + output_errors, ess_trsh_methods, remove_checkfile, level_of_theory, software, job_type, fine, trsh_keyword, \ + memory, shift, cpu_cores, couldnt_trsh = trsh.trsh_ess_job(label, level_of_theory, server, job_status, + job_type, software, fine, memory_gb, + num_heavy_atoms, cpu_cores, ess_trsh_methods) + + args = {'keyword': {}, 'block': {}} + if trsh_keyword: + args['trsh'] = {'trsh': trsh_keyword} + cls.job_12 = GaussianAdapter(execution_type='local', + job_type='optfreq', + level=Level(method='wb97xd'), + fine=True, + ess_trsh_methods=ess_trsh_methods, + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[spc_11], + testing=True, + args=args + ) + + job_status = {'keywords': ['SCF']} + output_errors, ess_trsh_methods, remove_checkfile, level_of_theory, software, job_type, fine, trsh_keyword, \ + memory, shift, cpu_cores, couldnt_trsh = trsh.trsh_ess_job(label, level_of_theory, server, job_status, + job_type, software, fine, memory_gb, + num_heavy_atoms, cpu_cores, ess_trsh_methods) + + args = {'keyword': {}, 'block': {}} + if trsh_keyword: + args['trsh'] = {'trsh': trsh_keyword} + cls.job_13 = GaussianAdapter(execution_type='local', + job_type='optfreq', + level=Level(method='wb97xd'), + fine=True, + ess_trsh_methods=ess_trsh_methods, + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[spc_11], + testing=True, + args=args + ) + + job_status = {'keywords': ['SCF']} + output_errors, ess_trsh_methods, remove_checkfile, level_of_theory, software, job_type, fine, trsh_keyword, \ + memory, shift, cpu_cores, couldnt_trsh = trsh.trsh_ess_job(label, level_of_theory, server, job_status, + job_type, software, fine, memory_gb, + num_heavy_atoms, cpu_cores, ess_trsh_methods) + + args = {'keyword': {}, 'block': {}} + if trsh_keyword: + args['trsh'] = {'trsh': trsh_keyword} + cls.job_14 = GaussianAdapter(execution_type='local', + job_type='optfreq', + level=Level(method='wb97xd'), + fine=True, + ess_trsh_methods=ess_trsh_methods, + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[spc_11], + testing=True, + args=args + ) + + job_status = {'keywords': ['InternalCoordinateError']} + job_type_15 = 'opt' # Need to switch job types for this error + output_errors, ess_trsh_methods, remove_checkfile, level_of_theory, software, job_type, fine, trsh_keyword, \ + memory, shift, cpu_cores, couldnt_trsh = trsh.trsh_ess_job(label, level_of_theory, server, job_status, + job_type_15, software, fine, memory_gb, + num_heavy_atoms, cpu_cores, ess_trsh_methods) + + args = {'keyword': {}, 'block': {}} + if trsh_keyword: + args['trsh'] = {'trsh': trsh_keyword} + cls.job_15 = GaussianAdapter(execution_type='local', + job_type='opt', + level=Level(method='wb97xd'), + fine=True, + ess_trsh_methods=ess_trsh_methods, + project='test', + project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'), + species=[spc_11], + testing=True, + args=args + ) + def test_set_cpu_and_mem(self): """Test assigning number of cpu's and memory""" self.job_8.input_file_memory = None @@ -289,11 +385,11 @@ def test_write_input_file(self): anion - -1 2 - O 0.00000000 0.00000000 1.00000000 +-1 2 +O 0.00000000 0.00000000 1.00000000 - """ +""" self.assertEqual(content_6, job_6_expected_input_file) self.job_7.write_input_file() @@ -387,7 +483,6 @@ def test_trsh_write_input_file(self): """ self.assertEqual(content_10, job_10_expected_input_file) - self.job_11.write_input_file() with open(os.path.join(self.job_11.local_path, input_filenames[self.job_11.job_adapter]), 'r') as f: content_11 = f.read() @@ -395,16 +490,128 @@ def test_trsh_write_input_file(self): %mem=14336mb %NProcShared=8 -#P opt=(calcfc, tight, maxstep=5) uwb97xd scf=(tight, direct) integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=xqc +#P opt=(calcfc, tight, maxstep=5) guess=mix wb97xd scf=(tight, direct) integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=xqc -anion +ethanol --1 2 -O 0.00000000 0.00000000 1.00000000 +0 1 +C 1.16582100 -0.40435500 0.00000000 +C 0.00000000 0.55180500 0.00000000 +O -1.18946000 -0.21419400 0.00000000 +H -1.94125800 0.37518500 0.00000000 +H 2.10540200 0.14511600 0.00000000 +H 1.13062400 -1.03878500 0.88303200 +H 1.13062400 -1.03878500 -0.88303200 +H 0.04768200 1.19305700 0.88359100 +H 0.04768200 1.19305700 -0.88359100 """ + self.assertEqual(content_11, job_11_expected_input_file) + + self.job_12.write_input_file() + with open(os.path.join(self.job_12.local_path, input_filenames[self.job_12.job_adapter]), 'r') as f: + content_12 = f.read() + job_12_expected_input_file = """%chk=check.chk +%mem=14336mb +%NProcShared=8 +#P opt=(calcfc, tight, maxstep=5) guess=mix wb97xd scf=(tight, direct) integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=xqc scf=(qc,nosymm) + +ethanol + +0 1 +C 1.16582100 -0.40435500 0.00000000 +C 0.00000000 0.55180500 0.00000000 +O -1.18946000 -0.21419400 0.00000000 +H -1.94125800 0.37518500 0.00000000 +H 2.10540200 0.14511600 0.00000000 +H 1.13062400 -1.03878500 0.88303200 +H 1.13062400 -1.03878500 -0.88303200 +H 0.04768200 1.19305700 0.88359100 +H 0.04768200 1.19305700 -0.88359100 + + +""" + self.assertEqual(content_12, job_12_expected_input_file) + + self.job_13.write_input_file() + with open(os.path.join(self.job_13.local_path, input_filenames[self.job_13.job_adapter]), 'r') as f: + content_13 = f.read() + job_13_expected_input_file = """%chk=check.chk +%mem=14336mb +%NProcShared=8 + +#P opt=(calcfc, tight, maxstep=5) guess=mix wb97xd scf=(tight, direct) integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=xqc scf=(qc,nosymm,NDump=30) + +ethanol + +0 1 +C 1.16582100 -0.40435500 0.00000000 +C 0.00000000 0.55180500 0.00000000 +O -1.18946000 -0.21419400 0.00000000 +H -1.94125800 0.37518500 0.00000000 +H 2.10540200 0.14511600 0.00000000 +H 1.13062400 -1.03878500 0.88303200 +H 1.13062400 -1.03878500 -0.88303200 +H 0.04768200 1.19305700 0.88359100 +H 0.04768200 1.19305700 -0.88359100 + + +""" + self.assertEqual(content_13, job_13_expected_input_file) + + self.job_14.write_input_file() + with open(os.path.join(self.job_14.local_path, input_filenames[self.job_14.job_adapter]), 'r') as f: + content_14 = f.read() + job_14_expected_input_file = """%chk=check.chk +%mem=14336mb +%NProcShared=8 + +#P opt=(calcfc, tight, maxstep=5) guess=mix wb97xd scf=(tight, direct) integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=xqc scf=(qc,nosymm,NDump=30,NoDIIS) + +ethanol + +0 1 +C 1.16582100 -0.40435500 0.00000000 +C 0.00000000 0.55180500 0.00000000 +O -1.18946000 -0.21419400 0.00000000 +H -1.94125800 0.37518500 0.00000000 +H 2.10540200 0.14511600 0.00000000 +H 1.13062400 -1.03878500 0.88303200 +H 1.13062400 -1.03878500 -0.88303200 +H 0.04768200 1.19305700 0.88359100 +H 0.04768200 1.19305700 -0.88359100 + + +""" + self.assertEqual(content_14, job_14_expected_input_file) + + self.job_15.write_input_file() + with open(os.path.join(self.job_15.local_path, input_filenames[self.job_15.job_adapter]), 'r') as f: + content_15 = f.read() + job_15_expected_input_file = """%chk=check.chk +%mem=14336mb +%NProcShared=8 + +#P opt=(calcfc, tight, maxstep=5) guess=mix wb97xd scf=(tight, direct) integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=xqc opt=(cartesian,nosymm) scf=(qc,nosymm,NDump=30,NoDIIS) + +ethanol + +0 1 +C 1.16582100 -0.40435500 0.00000000 +C 0.00000000 0.55180500 0.00000000 +O -1.18946000 -0.21419400 0.00000000 +H -1.94125800 0.37518500 0.00000000 +H 2.10540200 0.14511600 0.00000000 +H 1.13062400 -1.03878500 0.88303200 +H 1.13062400 -1.03878500 -0.88303200 +H 0.04768200 1.19305700 0.88359100 +H 0.04768200 1.19305700 -0.88359100 + + +""" + self.assertEqual(content_15, job_15_expected_input_file) @classmethod def tearDownClass(cls): diff --git a/arc/job/trsh_test.py b/arc/job/trsh_test.py index 461d085824..932ad427d1 100644 --- a/arc/job/trsh_test.py +++ b/arc/job/trsh_test.py @@ -293,7 +293,7 @@ def test_trsh_ess_job(self): num_heavy_atoms, cpu_cores, ess_trsh_methods) self.assertTrue(remove_checkfile) - self.assertEqual(trsh_keyword, 'opt=(cartesian,nosymm)') + self.assertEqual(trsh_keyword, ['opt=(cartesian,nosymm)', 'int=(Acc2E=14)'] ) # Test Q-Chem software = 'qchem'