def test_determine_model_chemistry_and_freq_scale_factor(self): """Test determining the model chemistry and the frequency scaling factor""" arc0 = ARC(project='arc_model_chemistry_test', level_of_theory='CBS-QB3') self.assertEqual(str(arc0.arkane_level_of_theory), "cbs-qb3, software: gaussian (composite)") self.assertEqual(arc0.freq_scale_factor, 1.00386) # 0.99 * 1.014 = 1.00386 arc1 = ARC(project='arc_model_chemistry_test', level_of_theory='cbs-qb3-paraskevas') self.assertEqual(str(arc1.arkane_level_of_theory), 'cbs-qb3-paraskevas, software: gaussian (composite)') self.assertEqual(arc1.freq_scale_factor, 1.00386) # 0.99 * 1.014 = 1.00386 self.assertEqual(arc1.bac_type, 'p') arc2 = ARC(project='arc_model_chemistry_test', level_of_theory='ccsd(t)-f12/cc-pvtz-f12//m06-2x/cc-pvtz') self.assertEqual( str(arc2.arkane_level_of_theory), 'ccsd(t)-f12/cc-pvtz-f12, software: molpro (wavefunction)') self.assertEqual(arc2.freq_scale_factor, 0.955) arc3 = ARC(project='arc_model_chemistry_test', sp_level='ccsd(t)-f12/cc-pvtz-f12', opt_level='wb97xd/def2tzvp') self.assertEqual( str(arc3.arkane_level_of_theory), 'ccsd(t)-f12/cc-pvtz-f12, software: molpro (wavefunction)') self.assertEqual(arc3.freq_scale_factor, 0.988)
def test_check_project_name(self): """Test project name invalidity""" with self.assertRaises(InputError): ARC(project='ar c') with self.assertRaises(InputError): ARC(project='ar:c') with self.assertRaises(InputError): ARC(project='ar<c') with self.assertRaises(InputError): ARC(project='ar%c')
def test_check_project_name(self): """Test project name invalidity""" ess_settings = {} with self.assertRaises(InputError): ARC(project='ar c', ess_settings=ess_settings) with self.assertRaises(InputError): ARC(project='ar:c', ess_settings=ess_settings) with self.assertRaises(InputError): ARC(project='ar<c', ess_settings=ess_settings) with self.assertRaises(InputError): ARC(project='ar%c', ess_settings=ess_settings)
def test_as_dict(self): """Test the as_dict() method of ARC""" spc1 = ARCSpecies(label='spc1', smiles=str('CC'), generate_thermo=False) arc0 = ARC(project='arc_test', job_types=self.job_types1, initial_trsh='scf=(NDump=30)', arc_species_list=[spc1], level_of_theory='ccsd(t)-f12/cc-pvdz-f12//b3lyp/6-311+g(3df,2p)') restart_dict = arc0.as_dict() expected_dict = {'composite_method': '', 'conformer_level': 'b3lyp/6-31g(d,p) empiricaldispersion=gd3bj', 'ts_guess_level': 'b3lyp/6-31g(d,p) empiricaldispersion=gd3bj', 'opt_level': 'b3lyp/6-311+g(3df,2p)', 'freq_level': 'b3lyp/6-311+g(3df,2p)', 'freq_scale_factor': 0.967, 'initial_trsh': 'scf=(NDump=30)', 'max_job_time': 120, 'model_chemistry': 'ccsd(t)-f12/cc-pvdz-f12//b3lyp/6-311+g(3df,2p)', 'output': {}, 'project': 'arc_test', 'running_jobs': {}, 'reactions': [], 'scan_level': '', 'sp_level': 'ccsd(t)-f12/cc-pvdz-f12', 'job_memory': 14, 'job_types': {'1d_rotors': False, 'conformers': True, 'fine': False, 'freq': True, 'onedmin': False, 'opt': True, 'orbitals': False, 'sp': True}, 't_min': None, 't_max': None, 't_count': None, 'use_bac': True, 'confs_to_dft': 5, 'allow_nonisomorphic_2d': False, 'calc_freq_factor': True, 'ess_settings': {'gaussian': ['local', 'server2'], 'onedmin': ['server1'], 'molpro': ['server2'], 'qchem': ['server1']}, 'species': [{'bond_corrections': {'C-C': 1, 'C-H': 6}, 'arkane_file': None, 'E0': None, 'charge': 0, 'external_symmetry': None, 'optical_isomers': None, 'generate_thermo': False, 'is_ts': False, 'label': 'spc1', 'long_thermo_description': "Bond corrections: {'C-C': 1, 'C-H': 6}\n", 'mol': '1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}\n2 C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}\n3 H u0 p0 c0 {1,S}\n4 H u0 p0 c0 {1,S}\n5 H u0 p0 c0 {1,S}\n6 H u0 p0 c0 {2,S}\n7 H u0 p0 c0 {2,S}\n8 H u0 p0 c0 {2,S}\n', 'multiplicity': 1, 'neg_freqs_trshed': [], 'number_of_rotors': 0, 'rotors_dict': {}, 'force_field': 'MMFF94', 't1': None}], } self.assertEqual(restart_dict, expected_dict)
def test_determine_model_chemistry_and_freq_scale_factor(self): """Test determining the model chemistry and the frequency scaling factor""" arc0 = ARC(project='arc_model_chemistry_test_0', level_of_theory='CBS-QB3') self.assertEqual(arc0.model_chemistry, 'cbs-qb3') self.assertEqual(arc0.freq_scale_factor, 1.00386) # 0.99 * 1.014 = 1.00386 arc1 = ARC(project='arc_model_chemistry_test_1', level_of_theory='CBS-QB3-Paraskevas') self.assertEqual(arc1.model_chemistry, 'cbs-qb3-paraskevas') self.assertEqual(arc1.freq_scale_factor, 1.00386) # 0.99 * 1.014 = 1.00386 arc2 = ARC(project='arc_model_chemistry_test_2', level_of_theory='ccsd(t)-f12/cc-pvtz-f12//m06-2x/cc-pvtz') self.assertEqual(arc2.model_chemistry, 'ccsd(t)-f12/cc-pvtz-f12//m06-2x/cc-pvtz') self.assertEqual(arc2.freq_scale_factor, 0.955) arc3 = ARC(project='arc_model_chemistry_test_2', sp_level='ccsd(t)-f12/cc-pvtz-f12', opt_level='wb97x-d/aug-cc-pvtz') self.assertEqual(arc3.model_chemistry, 'ccsd(t)-f12/cc-pvtz-f12//wb97x-d/aug-cc-pvtz') self.assertEqual(arc3.freq_scale_factor, 0.988)
def test_as_dict(self): """Test the as_dict() method of ARC""" self.maxDiff = None ess_settings = {} spc1 = ARCSpecies(label='spc1', smiles=str('CC'), generate_thermo=False) arc0 = ARC(project='arc_test', ess_settings=ess_settings, scan_rotors=False, initial_trsh='scf=(NDump=30)', arc_species_list=[spc1]) restart_dict = arc0.as_dict() expected_dict = {'composite_method': '', 'conformer_level': 'b97-d3/6-311+g(d,p)', 'ts_guess_level': 'b3lyp/6-31+g(d,p)', 'ess_settings': {'ssh': True}, 'fine': True, 'opt_level': 'wb97xd/6-311++g(d,p)', 'freq_level': 'wb97xd/6-311++g(d,p)', 'generate_conformers': True, 'initial_trsh': 'scf=(NDump=30)', 'max_job_time': 120, 'model_chemistry': 'ccsd(t)-f12/cc-pvtz-f12', 'output': {}, 'project': 'arc_test', 'running_jobs': {}, 'reactions': [], 'scan_level': '', 'scan_rotors': False, 'sp_level': 'ccsd(t)-f12/cc-pvtz-f12', 't_min': None, 't_max': None, 't_count': None, 'use_bac': True, 'visualize_orbitals': True, 'allow_nonisomorphic_2d': False, 'species': [{'bond_corrections': {'C-C': 1, 'C-H': 6}, 'arkane_file': None, 'E0': None, 'charge': 0, 'external_symmetry': None, 'optical_isomers': None, 'final_xyz': '', 'generate_thermo': False, 'is_ts': False, 'label': u'spc1', 'long_thermo_description': "Bond corrections: {'C-C': 1, 'C-H': 6}\n", 'mol': '1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}\n2 C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}\n3 H u0 p0 c0 {1,S}\n4 H u0 p0 c0 {1,S}\n5 H u0 p0 c0 {1,S}\n6 H u0 p0 c0 {2,S}\n7 H u0 p0 c0 {2,S}\n8 H u0 p0 c0 {2,S}\n', 'multiplicity': 1, 'neg_freqs_trshed': [], 'number_of_rotors': 0, 'rotors_dict': {}, 't1': None}], } self.assertEqual(restart_dict, expected_dict)
def test_from_dict(self): """Test the from_dict() method of ARC""" restart_dict = {'composite_method': '', 'conformer_level': 'b97-d3/6-311+g(d,p)', 'ess_settings': {'gaussian': 'server1', 'molpro': 'server1', 'qchem': u'server1', 'ssh': True}, 'fine': True, 'freq_level': 'wb97x-d3/6-311+g(d,p)', 'generate_conformers': True, 'initial_trsh': 'scf=(NDump=30)', 'model_chemistry': 'ccsd(t)-f12/cc-pvtz-f12', 'opt_level': 'wb97x-d3/6-311+g(d,p)', 'output': {}, 'project': 'arc_test', 'rxn_list': [], 'scan_level': '', 'scan_rotors': False, 'sp_level': 'ccsdt-f12/cc-pvqz-f12', 'species': [{'bond_corrections': {'C-C': 1, 'C-H': 6}, 'charge': 1, 'conformer_energies': [], 'conformers': [], 'external_symmetry': 1, 'final_xyz': '', 'generate_thermo': False, 'is_ts': False, 'label': 'testing_spc1', 'mol': '1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}\n2 C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}\n3 H u0 p0 c0 {1,S}\n4 H u0 p0 c0 {1,S}\n5 H u0 p0 c0 {1,S}\n6 H u0 p0 c0 {2,S}\n7 H u0 p0 c0 {2,S}\n8 H u0 p0 c0 {2,S}\n', 'multiplicity': 1, 'neg_freqs_trshed': [], 'number_of_rotors': 0, 'opt_level': '', 'optical_isomers': 1, 'rotors_dict': {}, 'xyzs': []}], 'use_bac': True} arc1 = ARC(project='wrong', ess_settings=dict()) project = 'arc_project_for_testing_delete_after_usage1' project_directory = os.path.join(arc_path, 'Projects', project) arc1.from_dict(input_dict=restart_dict, project='testing_from_dict', project_directory=project_directory) self.assertEqual(arc1.project, 'testing_from_dict') self.assertTrue('arc_project_for_testing_delete_after_usage' in arc1.project_directory) self.assertTrue(arc1.fine) self.assertFalse(arc1.scan_rotors) self.assertEqual(arc1.sp_level, 'ccsdt-f12/cc-pvqz-f12') self.assertEqual(arc1.arc_species_list[0].label, 'testing_spc1') self.assertFalse(arc1.arc_species_list[0].is_ts) self.assertEqual(arc1.arc_species_list[0].charge, 1)
def test_add_hydrogen_for_bde(self): """Test the add_hydrogen_for_bde method""" spc0 = ARCSpecies(label='spc0', smiles='CC', compute_thermo=False) arc0 = ARC( project='arc_test', job_types=self.job_types1, species=[spc0], level_of_theory='ccsd(t)-f12/cc-pvdz-f12//b3lyp/6-311+g(3df,2p)') arc0.add_hydrogen_for_bde() self.assertEqual(len(arc0.species), 1) spc1 = ARCSpecies(label='spc1', smiles='CC', compute_thermo=False, bdes=['all_h']) arc1 = ARC( project='arc_test', job_types=self.job_types1, species=[spc1], level_of_theory='ccsd(t)-f12/cc-pvdz-f12//b3lyp/6-311+g(3df,2p)') arc1.add_hydrogen_for_bde() self.assertEqual(len(arc1.species), 2) self.assertIn('H', [spc.label for spc in arc1.species])
def test_determine_unique_species_labels(self): """Test the determine_unique_species_labels method""" spc0 = ARCSpecies(label='spc0', smiles='CC', compute_thermo=False) spc1 = ARCSpecies(label='spc1', smiles='CC', compute_thermo=False) spc2 = ARCSpecies(label='spc2', smiles='CC', compute_thermo=False) arc0 = ARC( project='arc_test', job_types=self.job_types1, species=[spc0, spc1, spc2], level_of_theory='ccsd(t)-f12/cc-pvdz-f12//b3lyp/6-311+g(3df,2p)') self.assertEqual(arc0.unique_species_labels, ['spc0', 'spc1', 'spc2']) spc3 = ARCSpecies(label='spc0', smiles='CC', compute_thermo=False) arc0.species.append(spc3) with self.assertRaises(ValueError): arc0.determine_unique_species_labels()
def test_restart_bde(self): """Test restarting ARC and attaining reaction a rate coefficient""" restart_path = os.path.join(ARC_PATH, 'arc', 'testing', 'restart', '3_restart_bde', 'restart.yml') input_dict = read_yaml_file(path=restart_path) arc1 = ARC(**input_dict) arc1.execute() report_path = os.path.join(ARC_PATH, 'Projects', 'test_restart_bde', 'output', 'BDE_report.txt') with open(report_path, 'r') as f: lines = f.readlines() self.assertIn(' BDE report for anilino_radical:\n', lines) self.assertIn(' (1, 9) N - H 353.92\n', lines) self.assertIn(' (3, 4) C - H 454.12\n', lines) self.assertIn(' (5, 10) C - H 461.75\n', lines)
def main(): # Parse the command-line arguments (requires the argparse module) args = parse_command_line_arguments() input_file = args.file input_dict = read_file(input_file) project_directory = os.path.abspath(os.path.dirname(args.file)) try: input_dict['project'] except KeyError: print('A project name must be provided!') verbose = logging.INFO if args.debug: verbose = logging.DEBUG elif args.quiet: verbose = logging.WARNING input_dict['verbose'] = input_dict['verbose'] if 'verbose' in input_dict else verbose arc_object = ARC(input_dict=input_dict, project_directory=project_directory) arc_object.execute()
def test_globalize_paths(self): """Test modifying a YAML file's contents to correct absolute file paths""" project_directory = os.path.join(ARC_PATH, 'arc', 'testing', 'restart', '4_globalized_paths') restart_path = os.path.join(project_directory, 'restart_paths.yml') input_dict = read_yaml_file(path=restart_path, project_directory=project_directory) input_dict['project_directory'] = project_directory ARC(**input_dict) globalized_restart_path = os.path.join(project_directory, 'restart_paths_globalized.yml') content = read_yaml_file( globalized_restart_path ) # not giving a project directory, this is tested in common self.assertEqual(content['output']['restart'], 'Restarted ARC at 2020-02-28 12:51:14.446086; ') self.assertIn( 'ARC/arc/testing/restart/4_globalized_paths/calcs/Species/HCN/freq_a38229/output.out', content['output']['spc']['paths']['freq']) self.assertNotIn('gpfs/workspace/users/user', content['output']['spc']['paths']['freq'])
def test_restart_rate(self): """Test restarting ARC and attaining reaction a rate coefficient""" restart_path = os.path.join(ARC_PATH, 'arc', 'testing', 'restart', '2_restart_rate', 'restart.yml') input_dict = read_yaml_file(path=restart_path) project = 'arc_project_for_testing_delete_after_usage_restart_rate' project_directory = os.path.join(ARC_PATH, 'Projects', project) input_dict['project'], input_dict[ 'project_directory'] = project, project_directory arc1 = ARC(**input_dict) arc1.execute() kinetics_library_path = os.path.join(project_directory, 'output', 'RMG libraries', 'kinetics', 'reactions.py') with open(kinetics_library_path, 'r') as f: got_rate = False for line in f.readlines(): if "Arrhenius(A=(0.0636958,'cm^3/(mol*s)'), n=4.07981, Ea=(57.5474,'kJ/mol')" in line: got_rate = True break self.assertTrue(got_rate)
def test_from_dict_specific_job(self): """Test the from_dict() method of ARC""" restart_dict = { 'specific_job_type': 'bde', 'project': 'unit_test_specific_job', 'project_directory': os.path.join(arc_path, 'Projects', 'unit_test_specific_job'), } arc1 = ARC(**restart_dict) job_type_expected = { 'conformers': False, 'opt': True, 'freq': True, 'sp': True, 'rotors': False, 'orbitals': False, 'bde': True, 'onedmin': False, 'fine': True, 'irc': False } self.assertEqual(arc1.job_types, job_type_expected)
def test_restart(self): """ Test restarting ARC through the ARC class in main.py via the input_dict argument of the API Rather than through ARC.py. Check that all files are in place and tst file content. """ restart_path = os.path.join(arc_path, 'arc', 'testing', 'restart(H,H2O2,N2H3,CH3CO2).yml') project = 'arc_project_for_testing_delete_after_usage2' project_directory = os.path.join(arc_path, 'Projects', project) arc1 = ARC(project=project, ess_settings=dict(), input_dict=restart_path, project_directory=project_directory) arc1.execute() with open(os.path.join(project_directory, 'output', 'thermo.info'), 'r') as f: thermo_sft_ccsdtf12_bac = False for line in f.readlines(): if 'thermo_DFT_CCSDTF12_BAC' in line: thermo_sft_ccsdtf12_bac = True break self.assertTrue(thermo_sft_ccsdtf12_bac) with open(os.path.join(project_directory, 'arc_project_for_testing_delete_after_usage2.info'), 'r') as f: sts, n2h3, oet, lot, ap = False, False, False, False, False for line in f.readlines(): if 'Considered the following species and TSs:' in line: sts = True elif 'Species N2H3' in line: n2h3 = True elif 'Overall time since project initiation:' in line: oet = True elif 'Levels of theory used:' in line: lot = True elif 'ARC project arc_project_for_testing_delete_after_usage2' in line: ap = True self.assertTrue(sts) self.assertTrue(n2h3) self.assertTrue(oet) self.assertTrue(lot) self.assertTrue(ap) with open(os.path.join(project_directory, 'arc.log'), 'r') as f: aei, ver, git, spc, rtm, ldb, therm, src, ter = False, False, False, False, False, False, False, False, False for line in f.readlines(): if 'ARC execution initiated on' in line: aei = True elif '# Version:' in line: ver = True elif 'The current git HEAD for ARC is:' in line: git = True elif 'Considering species: CH3CO2_rad' in line: spc = True elif 'All jobs for species N2H3 successfully converged. Run time: 1:16:03' in line: rtm = True elif 'Loading the RMG database...' in line: ldb = True elif 'Thermodynamics for H2O2:' in line: therm = True elif 'Sources of thermoproperties determined by RMG for the parity plots:' in line: src = True elif 'ARC execution terminated on' in line: ter = True self.assertTrue(aei) self.assertTrue(ver) self.assertTrue(git) self.assertTrue(spc) self.assertTrue(rtm) self.assertTrue(ldb) self.assertTrue(therm) self.assertTrue(src) self.assertTrue(ter) self.assertTrue(os.path.isfile(os.path.join(project_directory, 'output', 'thermo_parity_plots.pdf'))) with open(os.path.join(project_directory, 'output', 'Species', 'H2O2', 'species_dictionary.txt'), 'r') as f: lines = f.readlines() adj_list = str(''.join([line for line in lines if (line and 'H2O2' not in line)])) mol1 = Molecule().fromAdjacencyList(adj_list) self.assertEqual(mol1.toSMILES(), str('OO')) thermo_library_path = os.path.join(project_directory, 'output', 'RMG libraries', 'thermo', 'arc_project_for_testing_delete_after_usage2.py') new_thermo_library_path = os.path.join(settings['database.directory'], 'thermo', 'libraries', 'arc_project_for_testing_delete_after_usage2.py') # copy the generated library to RMG-database shutil.copyfile(thermo_library_path, new_thermo_library_path) db = RMGDatabase() db.load( path=settings['database.directory'], thermoLibraries=[str('arc_project_for_testing_delete_after_usage2')], transportLibraries=[], reactionLibraries=[], seedMechanisms=[], kineticsFamilies='none', kineticsDepositories=[], statmechLibraries=None, depository=False, solvation=False, testing=True, ) spc2 = Species().fromSMILES(str('CC([O])=O')) spc2.generate_resonance_structures() spc2.thermo = db.thermo.getThermoData(spc2) self.assertAlmostEqual(spc2.getEnthalpy(298), -178003.44650359568, 1) self.assertAlmostEqual(spc2.getEntropy(298), 283.5983103176096, 1) self.assertAlmostEqual(spc2.getHeatCapacity(1000), 118.99753808225603, 1) self.assertTrue('arc_project_for_testing_delete_after_usage2' in spc2.thermo.comment) # delete the generated library from RMG-database os.remove(new_thermo_library_path)
def test_as_dict(self): """Test the as_dict() method of ARC""" spc1 = ARCSpecies( label='spc1', smiles='CC', compute_thermo=False, ) arc0 = ARC( project='arc_test', job_types=self.job_types1, species=[spc1], level_of_theory='ccsd(t)-f12/cc-pvdz-f12//b3lyp/6-311+g(3df,2p)', three_params=False, ) arc0.freq_level.args['keyword']['general'] = 'scf=(NDump=30)' restart_dict = arc0.as_dict() long_thermo_description = restart_dict['species'][0][ 'long_thermo_description'] self.assertIn('Bond corrections:', long_thermo_description) self.assertIn("'C-C': 1", long_thermo_description) self.assertIn("'C-H': 6", long_thermo_description) expected_dict = { 'T_count': 50, 'T_max': None, 'T_min': None, 'allow_nonisomorphic_2d': False, 'arkane_level_of_theory': { 'basis': 'cc-pvdz-f12', 'method': 'ccsd(t)-f12', 'method_type': 'wavefunction', 'software': 'molpro' }, 'calc_freq_factor': True, 'compute_transport': False, 'conformer_level': { 'basis': 'def2svp', 'compatible_ess': ['gaussian', 'terachem'], 'method': 'wb97xd', 'method_type': 'dft', 'software': 'gaussian' }, 'e_confs': 5.0, 'ess_settings': { 'gaussian': ['local', 'server2'], 'molpro': ['server2'], 'onedmin': ['server1'], 'orca': ['local'], 'qchem': ['server1'], 'terachem': ['server1'] }, 'freq_level': { 'basis': '6-311+g(3df,2p)', 'method': 'b3lyp', 'method_type': 'dft', 'software': 'gaussian' }, 'freq_scale_factor': 0.967, 'irc_level': { 'basis': 'def2tzvp', 'compatible_ess': ['gaussian', 'terachem'], 'method': 'wb97xd', 'method_type': 'dft', 'software': 'gaussian' }, 'job_memory': 14, 'job_types': { 'bde': True, 'conformers': True, 'fine': False, 'freq': True, 'irc': True, 'onedmin': False, 'opt': True, 'orbitals': False, 'rotors': False, 'sp': True }, 'kinetics_adapter': 'Arkane', 'max_job_time': 120, 'n_confs': 10, 'opt_level': { 'basis': '6-311+g(3df,2p)', 'method': 'b3lyp', 'method_type': 'dft', 'software': 'gaussian' }, 'output': {}, 'project': 'arc_test', 'reactions': [], 'running_jobs': {}, 'sp_level': { 'basis': 'cc-pvdz-f12', 'method': 'ccsd(t)-f12', 'method_type': 'wavefunction', 'software': 'molpro' }, 'species': [{ 'arkane_file': None, 'bond_corrections': { 'C-C': 1, 'C-H': 6 }, 'charge': 0, 'compute_thermo': False, 'consider_all_diastereomers': True, 'force_field': 'MMFF94s', 'is_ts': False, 'label': 'spc1', 'long_thermo_description': long_thermo_description, 'mol': '1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}\n' '2 C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}\n' '3 H u0 p0 c0 {1,S}\n' '4 H u0 p0 c0 {1,S}\n' '5 H u0 p0 c0 {1,S}\n' '6 H u0 p0 c0 {2,S}\n' '7 H u0 p0 c0 {2,S}\n' '8 H u0 p0 c0 {2,S}\n', 'multiplicity': 1, 'number_of_rotors': 0 }], 'thermo_adapter': 'Arkane', 'three_params': False } # import pprint # left intentionally for debugging # print(pprint.pprint(restart_dict)) self.assertEqual(restart_dict, expected_dict)
def test_determine_model_chemistry_for_job_types(self): """Test determining the model chemistry specification dictionary for job types""" # Test conflicted inputs: specify both level_of_theory and composite_method with self.assertRaises(InputError): ARC(project='test', level_of_theory='ccsd(t)-f12/cc-pvtz-f12//wb97x-d/aug-cc-pvtz', composite_method='cbs-qb3') # Test illegal level of theory specification (method contains multiple slashes) with self.assertRaises(ValueError): ARC(project='test', level_of_theory= 'dlpno-mp2-f12/D/cc-pVDZ(fi/sf/fw)//b3lyp/G/def2svp') # Test illegal job level specification (method contains multiple slashes) with self.assertRaises(ValueError): ARC(project='test', opt_level='b3lyp/d/def2tzvp/def2tzvp/c') # Test illegal job level specification (method contains empty space) with self.assertRaises(ValueError): ARC(project='test', opt_level='b3lyp/def2tzvp def2tzvp/c') # Test direct job level specification conflicts with level of theory specification with self.assertRaises(InputError): ARC(project='test', level_of_theory='b3lyp/sto-3g', opt_level='wb97xd/def2tzvp') # Test deduce levels from default method from settings.py arc1 = ARC(project='test') self.assertEqual(arc1.opt_level.simple(), 'wb97xd/def2tzvp') self.assertEqual(arc1.freq_level.simple(), 'wb97xd/def2tzvp') self.assertEqual(arc1.sp_level.simple(), 'ccsd(t)-f12/cc-pvtz-f12') # Test deduce levels from composite method specification arc2 = ARC(project='test', composite_method='cbs-qb3') self.assertIsNone(arc2.opt_level) self.assertIsNone(arc2.sp_level) self.assertIsNone(arc2.orbitals_level) self.assertEqual(arc2.freq_level.simple(), 'b3lyp/cbsb7') self.assertEqual(arc2.scan_level.simple(), 'b3lyp/cbsb7') self.assertEqual(arc2.composite_method.simple(), 'cbs-qb3') # Test deduce levels from level of theory specification arc3 = ARC( project='test', level_of_theory='ccsd(t)-f12/cc-pvtz-f12//wb97m-v/def2tzvpd') self.assertEqual(arc3.opt_level.simple(), 'wb97m-v/def2tzvpd') self.assertEqual(arc3.freq_level.simple(), 'wb97m-v/def2tzvpd') self.assertEqual(arc3.sp_level.simple(), 'ccsd(t)-f12/cc-pvtz-f12') self.assertEqual(arc3.scan_level.simple(), 'wb97m-v/def2tzvpd') self.assertIsNone(arc3.orbitals_level) arc4 = ARC(project='test', opt_level='wb97x-d3/6-311++G(3df,3pd)', freq_level='m062x/def2-tzvpp', sp_level='ccsd(t)f12/aug-cc-pvqz', calc_freq_factor=False) self.assertEqual(arc4.opt_level.simple(), 'wb97x-d3/6-311++g(3df,3pd)') self.assertEqual(arc4.freq_level.simple(), 'm062x/def2-tzvpp') self.assertEqual(arc4.sp_level.simple(), 'ccsd(t)f12/aug-cc-pvqz') # Test deduce freq level from opt level arc7 = ARC(project='test', opt_level='wb97xd/aug-cc-pvtz', calc_freq_factor=False) self.assertEqual(arc7.opt_level.simple(), 'wb97xd/aug-cc-pvtz') self.assertEqual(arc7.freq_level.simple(), 'wb97xd/aug-cc-pvtz') # Test a level not supported by Arkane does not raise error if compute_thermo is False arc8 = ARC(project='test', sp_level='method/unsupported', calc_freq_factor=False, compute_thermo=False) self.assertEqual(arc8.sp_level.simple(), 'method/unsupported') self.assertEqual(arc8.freq_level.simple(), 'wb97xd/def2tzvp') # Test a level not supported by Arkane does raise an error if compute_thermo is True (default) with self.assertRaises(ValueError): ARC(project='test', sp_level='method/unsupported', calc_freq_factor=False) # Test dictionary format specification with auxiliary basis and DFT dispersion arc9 = ARC(project='test', opt_level={}, freq_level={ 'method': 'B3LYP/G', 'basis': 'cc-pVDZ(fi/sf/fw)', 'auxiliary_basis': 'def2-svp/C', 'dispersion': 'DEF2-tzvp/c' }, sp_level={ 'method': 'DLPNO-CCSD(T)-F12', 'basis': 'cc-pVTZ-F12', 'auxiliary_basis': 'aug-cc-pVTZ/C cc-pVTZ-F12-CABS' }, calc_freq_factor=False, compute_thermo=False) self.assertEqual(arc9.opt_level.simple(), 'wb97xd/def2tzvp') self.assertEqual( str(arc9.freq_level), 'b3lyp/g/cc-pvdz(fi/sf/fw), auxiliary_basis: def2-svp/c, ' 'dispersion: def2-tzvp/c, software: gaussian (dft)') self.assertEqual( str(arc9.sp_level), 'dlpno-ccsd(t)-f12/cc-pvtz-f12, auxiliary_basis: aug-cc-pvtz/c cc-pvtz-f12-cabs, ' 'software: orca (wavefunction)') # Test using default frequency and orbital level for composite job, also forbid rotors job arc10 = ARC(project='test', composite_method='cbs-qb3', calc_freq_factor=False, job_types={ 'rotors': False, 'orbitals': True }) self.assertEqual(arc10.freq_level.simple(), 'b3lyp/cbsb7') self.assertIsNone(arc10.scan_level) self.assertEqual(arc10.orbitals_level.simple(), 'b3lyp/cbsb7') # Test using specified frequency, scan, and orbital for composite job arc11 = ARC(project='test', composite_method='cbs-qb3', freq_level='wb97xd/6-311g', scan_level='apfd/def2svp', orbitals_level='hf/sto-3g', job_types={'orbitals': True}, calc_freq_factor=False) self.assertEqual(arc11.scan_level.simple(), 'apfd/def2svp') self.assertEqual(arc11.freq_level.simple(), 'wb97xd/6-311g') self.assertEqual(arc11.orbitals_level.simple(), 'hf/sto-3g') # Test using default frequency and orbital level for job specified from level of theory, also forbid rotors job arc12 = ARC(project='test', level_of_theory='b3lyp/sto-3g', calc_freq_factor=False, job_types={ 'rotors': False, 'orbitals': True }, compute_thermo=False) self.assertIsNone(arc12.scan_level) self.assertEqual(arc12.orbitals_level.simple(), 'wb97x-d3/def2tzvp') # Test using specified scan level arc13 = ARC(project='test', level_of_theory='b3lyp/sto-3g', calc_freq_factor=False, scan_level='apfd/def2svp', job_types={'rotors': True}, compute_thermo=False) self.assertEqual(arc13.scan_level.simple(), 'apfd/def2svp') # Test specifying semi-empirical and force-field methods using dictionary arc14 = ARC(project='test', opt_level={'method': 'AM1'}, freq_level={'method': 'PM6'}, sp_level={'method': 'AMBER'}, calc_freq_factor=False, compute_thermo=False) self.assertEqual(arc14.opt_level.simple(), 'am1') self.assertEqual(arc14.freq_level.simple(), 'pm6') self.assertEqual(arc14.sp_level.simple(), 'amber')
def test_from_dict(self): """Test the from_dict() method of ARC""" restart_dict = { 'composite_method': '', 'conformer_level': 'b97-d3/6-311+g(d,p)', 'freq_level': 'wb97x-d3/6-311+g(d,p)', 'freq_scale_factor': 0.96, 'opt_level': 'wb97x-d3/6-311+g(d,p)', 'output': {}, 'project': 'testing_from_dict', 'reactions': [], 'scan_level': '', 'sp_level': 'ccsd(t)-f12/cc-pvqz-f12', 'species': [{ 'bond_corrections': { 'C-C': 1, 'C-H': 6 }, 'charge': 1, 'conformer_energies': [], 'conformers': [], 'external_symmetry': 1, 'compute_thermo': False, 'is_ts': False, 'label': 'testing_spc1', 'mol': '1 C u0 p0 c0 {2,S} {3,S} {4,S} {5,S}\n2 C u0 p0 c0 {1,S} {6,S} {7,S} {8,S}' '\n3 H u0 p0 c0 {1,S}\n4 H u0 p0 c0 {1,S}\n5 H u0 p0 c0 {1,S}\n6 H u0 p0 ' 'c0 {2,S}\n7 H u0 p0 c0 {2,S}\n8 H u0 p0 c0 {2,S}\n', 'multiplicity': 1, 'neg_freqs_trshed': [], 'number_of_rotors': 0, 'opt_level': '', 'optical_isomers': 1, 'rotors_dict': {}, 'xyzs': [] }], 'three_params': False, 'project_directory': os.path.join( arc_path, 'Projects', 'arc_project_for_testing_delete_after_usage_test_from_dict'), } arc1 = ARC(project='wrong', freq_scale_factor=0.95) self.assertEqual(arc1.freq_scale_factor, 0.95) # user input arc2 = ARC(**restart_dict) self.assertEqual(arc2.freq_scale_factor, 0.96) # loaded from the restart dict self.assertEqual(arc2.project, 'testing_from_dict') self.assertIn('arc_project_for_testing_delete_after_usage', arc2.project_directory) self.assertTrue(arc2.job_types['fine']) self.assertTrue(arc2.job_types['rotors']) self.assertEqual(arc2.sp_level.simple(), 'ccsd(t)-f12/cc-pvqz-f12') self.assertEqual(arc2.level_of_theory, '') self.assertEqual(arc2.species[0].label, 'testing_spc1') self.assertFalse(arc2.species[0].is_ts) self.assertEqual(arc2.species[0].charge, 1) self.assertFalse(arc2.three_params)
def test_restart_thermo(self): """ Test restarting ARC through the ARC class in main.py via the input_dict argument of the API Rather than through ARC.py. Check that all files are in place and the log file content. """ restart_path = os.path.join(ARC_PATH, 'arc', 'testing', 'restart', '1_restart_thermo', 'restart.yml') input_dict = read_yaml_file(path=restart_path) project = 'arc_project_for_testing_delete_after_usage_restart_thermo' project_directory = os.path.join(ARC_PATH, 'Projects', project) input_dict['project'], input_dict[ 'project_directory'] = project, project_directory arc1 = ARC(**input_dict) arc1.execute() self.assertEqual(arc1.freq_scale_factor, 0.988) self.assertTrue( os.path.isfile( os.path.join(project_directory, 'output', 'thermo.info'))) with open(os.path.join(project_directory, 'output', 'thermo.info'), 'r') as f: thermo_dft_ccsdtf12_bac = False for line in f.readlines(): if 'thermo_DFT_CCSDTF12_BAC' in line: thermo_dft_ccsdtf12_bac = True break self.assertTrue(thermo_dft_ccsdtf12_bac) with open( os.path.join( project_directory, 'arc_project_for_testing_delete_after_usage_restart_thermo.info' ), 'r') as f: sts, n2h3, oet, lot, ap = False, False, False, False, False for line in f.readlines(): if 'Considered the following species and TSs:' in line: sts = True elif 'Species N2H3' in line: n2h3 = True elif 'Overall time since project initiation:' in line: oet = True elif 'Levels of theory used:' in line: lot = True elif 'ARC project arc_project_for_testing_delete_after_usage_restart_thermo' in line: ap = True self.assertTrue(sts) self.assertTrue(n2h3) self.assertTrue(oet) self.assertTrue(lot) self.assertTrue(ap) with open(os.path.join(project_directory, 'arc.log'), 'r') as f: aei, ver, git, spc, rtm, ldb, therm, src, ter =\ False, False, False, False, False, False, False, False, False for line in f.readlines(): if 'ARC execution initiated on' in line: aei = True elif '# Version:' in line: ver = True elif 'The current git HEAD for ARC is:' in line: git = True elif 'Considering species: CH3CO2_rad' in line: spc = True elif 'All jobs for species N2H3 successfully converged. Run time' in line: rtm = True elif 'Loading the RMG database...' in line: ldb = True elif 'Thermodynamics for H2O2' in line: therm = True elif 'Sources of thermoproperties determined by RMG for the parity plots:' in line: src = True elif 'ARC execution terminated on' in line: ter = True self.assertTrue(aei) self.assertTrue(ver) self.assertTrue(git) self.assertTrue(spc) self.assertTrue(rtm) self.assertTrue(ldb) self.assertTrue(therm) self.assertTrue(src) self.assertTrue(ter) self.assertTrue( os.path.isfile( os.path.join(project_directory, 'output', 'thermo_parity_plots.pdf'))) status = read_yaml_file( os.path.join(project_directory, 'output', 'status.yml')) self.assertEqual( status['CH3CO2_rad']['isomorphism'], 'opt passed isomorphism check; ' 'Conformers optimized and compared at b3lyp/6-31g(d,p) empiricaldispersion=gd3bj; ' ) self.assertTrue(status['CH3CO2_rad']['job_types']['sp']) with open( os.path.join(project_directory, 'output', 'Species', 'H2O2', 'arkane', 'species_dictionary.txt'), 'r') as f: lines = f.readlines() adj_list = '' for line in lines: if 'H2O2' not in line: adj_list += line if line == '\n': break mol1 = Molecule().from_adjacency_list(adj_list) self.assertEqual(mol1.to_smiles(), 'OO') thermo_library_path = os.path.join( project_directory, 'output', 'RMG libraries', 'thermo', 'arc_project_for_testing_delete_after_usage_restart_thermo.py') new_thermo_library_path = os.path.join( rmg_settings['database.directory'], 'thermo', 'libraries', 'arc_project_for_testing_delete_after_usage_restart_thermo.py') # copy the generated library to RMG-database shutil.copyfile(thermo_library_path, new_thermo_library_path) db = RMGDatabase() db.load( path=rmg_settings['database.directory'], thermo_libraries=[ 'arc_project_for_testing_delete_after_usage_restart_thermo' ], transport_libraries=[], reaction_libraries=[], seed_mechanisms=[], kinetics_families='none', kinetics_depositories=[], statmech_libraries=None, depository=False, solvation=False, testing=True, ) spc2 = Species(smiles='CC([O])=O') spc2.generate_resonance_structures() spc2.thermo = db.thermo.get_thermo_data(spc2) self.assertAlmostEqual(spc2.get_enthalpy(298), -212439.26998495663, 1) self.assertAlmostEqual(spc2.get_entropy(298), 283.3972662956835, 1) self.assertAlmostEqual(spc2.get_heat_capacity(1000), 118.751379824224, 1) self.assertTrue( 'arc_project_for_testing_delete_after_usage_restart_thermo' in spc2.thermo.comment) # delete the generated library from RMG-database os.remove(new_thermo_library_path)