def test_deduce_software(self): """Test deducing the ESS software""" self.job1.job_type = 'onedmin' self.job1.software = None self.job1.deduce_software() self.assertEqual(self.job1.software, 'onedmin') self.job1.job_type = 'orbitals' self.job1.software = None self.job1.deduce_software() self.assertEqual(self.job1.software, 'qchem') self.job1.job_type = 'composite' self.job1.software = None self.job1.deduce_software() self.assertEqual(self.job1.software, 'gaussian') # test the levels_ess dict from settings self.job1.job_type = 'opt' self.job1.level = Level(repr={'method': 'm06-2x', 'basis': '6-311g'}) self.job1.software = None self.job1.deduce_software() self.assertEqual(self.job1.software, 'qchem') self.job1.job_type = 'opt' self.job1.level = Level(repr={'method': 'ccsd(t)', 'basis': 'cc-pvtz'}) self.job1.method = 'ccsd(t)' self.job1.software = None self.job1.deduce_software() self.assertEqual(self.job1.software, 'molpro') self.job1.job_type = 'opt' self.job1.level = Level(repr={'method': 'wb97xd3', 'basis': '6-311g'}) self.job1.method = 'wb97xd' self.job1.software = None self.job1.deduce_software() self.assertEqual(self.job1.software, 'terachem') self.job1.job_type = 'scan' self.job1.level = Level(repr={'method': 'm062x', 'basis': '6-311g'}) self.job1.method = 'm062x' self.job1.software = None self.job1.deduce_software() self.assertEqual(self.job1.software, 'gaussian') # return to original value self.job1.level = Level(repr='b3lyp/6-31+g(d)') self.job1.method = 'b3lyp' self.job1.software = None self.job1.deduce_software() self.assertEqual(self.job1.software, 'gaussian')
def test_level(self): """Test setting up Level""" level_1 = Level(method='b3lyp', basis='def2tzvp', auxiliary_basis='aug-def2-svp', dispersion='gd3bj', software='gaussian') self.assertEqual(level_1.method, 'b3lyp') self.assertEqual(level_1.basis, 'def2tzvp') self.assertEqual(level_1.auxiliary_basis, 'aug-def2-svp') self.assertEqual(level_1.dispersion, 'gd3bj') self.assertEqual(level_1.software, 'gaussian') self.assertEqual( str(level_1), "b3lyp/def2tzvp, auxiliary_basis: aug-def2-svp, dispersion: gd3bj, software: gaussian (dft)" ) self.assertEqual(level_1.simple(), "b3lyp/def2tzvp")
def test_build(self): """Test bulding a Level object from a string or dict representation""" level_1 = Level(repr='wB97xd/def2-tzvp') self.assertEqual(level_1.method, 'wb97xd') self.assertEqual(level_1.basis, 'def2-tzvp') self.assertEqual(level_1.method_type, 'dft') self.assertEqual(str(level_1), 'wb97xd/def2-tzvp, software: gaussian (dft)') level_2 = Level(repr='CBS-QB3') self.assertEqual(level_2.method, 'cbs-qb3') self.assertIsNone(level_2.basis) self.assertEqual(level_2.software, 'gaussian') self.assertEqual(level_2.method_type, 'composite') self.assertEqual(str(level_2), 'cbs-qb3, software: gaussian (composite)') self.assertEqual(level_2.simple(), 'cbs-qb3') level_3 = Level( repr={ 'method': 'DLPNO-CCSD(T)', 'basis': 'def2-TZVp', 'auxiliary_basis': 'def2-tzvp/c', 'solvation_method': 'SMD', 'solvent': 'water', 'solvation_scheme_level': 'APFD/def2-TZVp' }) self.assertEqual(level_3.method, 'dlpno-ccsd(t)') self.assertEqual(level_3.basis, 'def2-tzvp') self.assertEqual(level_3.auxiliary_basis, 'def2-tzvp/c') self.assertEqual(level_3.solvation_method, 'smd') self.assertEqual(level_3.solvent, 'water') self.assertIsInstance(level_3.solvation_scheme_level, Level) self.assertEqual(level_3.solvation_scheme_level.method, 'apfd') self.assertEqual(level_3.solvation_scheme_level.basis, 'def2-tzvp') self.assertEqual( str(level_3), "dlpno-ccsd(t)/def2-tzvp, auxiliary_basis: def2-tzvp/c, solvation_method: smd, " "solvent: water, solvation_scheme_level: 'apfd/def2-tzvp, software: gaussian (dft)', " "software: orca (wavefunction)")
def test_lower(self): """Test the Level.lower() method""" level = Level(method='B3LYP', basis='6-311+G(3df,2p)', software='Gaussian', dispersion='empiricaldispersion=Gd3bj', solvation_method='SMD', solvent='Water', args={'KeyWord': 'IOP(99/33=1)'}) self.assertEqual(level.method, 'b3lyp') self.assertEqual(level.basis, '6-311+g(3df,2p)') self.assertEqual(level.software, 'gaussian') self.assertEqual(level.dispersion, 'empiricaldispersion=gd3bj') self.assertEqual(level.solvation_method, 'smd') self.assertEqual(level.solvent, 'water') self.assertEqual(level.args, { 'keyword': { 'general': 'iop(99/33=1)' }, 'block': {} })
def setUpClass(cls): """ A method that is run before all unit tests in this class. """ cls.maxDiff = None cls.ess_settings = { 'gaussian': ['server1', 'server2'], 'molpro': ['server2'], 'qchem': ['server1'], 'onedmin': ['server1'], 'orca': ['server1'], 'terachem': ['server1'] } cls.xyz_c = { 'symbols': ('C', ), 'isotopes': (12, ), 'coords': ((0.0, 0.0, 0.0), ) } cls.job1 = Job( project='arc_project_for_testing_delete_after_usage3', ess_settings=cls.ess_settings, species_name='tst_spc', xyz=cls.xyz_c, job_type='opt', level=Level(repr={ 'method': 'b3lyp', 'basis': '6-31+g(d)' }), multiplicity=1, fine=True, job_num=100, testing=True, project_directory=os.path.join(arc_path, 'Projects', 'project_test'), initial_time=datetime.datetime(2019, 3, 15, 19, 53, 7, 0), final_time='2019-3-15 19:53:08', ) cls.job1.determine_run_time()
def determine_scaling_factors( levels: List[Union[Level, dict, str]], ess_settings: Optional[dict] = None, init_log: Optional[bool] = True, ) -> list: """ Determine the zero-point energy, harmonic frequencies, and fundamental frequencies scaling factors for a given frequencies level of theory. Args: levels (list): A list of frequencies levels of theory for which scaling factors are determined. Entries are either Level instances, dictionaries, or simple string representations. If a single entry is given, it will be converted to a list. ess_settings (dict, optional): A dictionary of available ESS (keys) and a corresponding server list (values). init_log (bool, optional): Whether to initialize the logger. ``True`` to initialize. Should be ``True`` when called as a standalone, but ``False`` when called within ARC. Returns: list: The determined frequency scaling factors. """ if init_log: initialize_log(log_file='scaling_factor.log', project='Scaling Factors') if not isinstance(levels, (list, tuple)): levels = [levels] levels = [ Level(repr=level) if not isinstance(level, Level) else level for level in levels ] t0 = time.time() logger.info('\n\n\n') logger.info(HEADER) logger.info('\n\nstarting ARC...\n') # only run opt (fine) and freq job_types = initialize_job_types( dict()) # get the defaults, so no job type is missing job_types = {job_type: False for job_type in job_types.keys()} job_types['opt'], job_types['fine'], job_types['freq'] = True, True, True lambda_zpes, zpe_dicts, times = list(), list(), list() for level in levels: t1 = time.time() logger.info( f'\nComputing scaling factors at the {level} level of theory...\n\n' ) renamed_level = rename_level(str(level)) project = 'scaling_' + renamed_level project_directory = os.path.join(arc_path, 'Projects', 'scaling_factors', project) if os.path.isdir(project_directory): shutil.rmtree(project_directory) species_list = get_species_list() if level.method_type == 'composite': freq_level = None composite_method = level job_types['freq'] = False else: freq_level = level composite_method = None ess_settings = check_ess_settings(ess_settings or global_ess_settings) Scheduler(project=project, project_directory=project_directory, species_list=species_list, composite_method=composite_method, opt_level=freq_level, freq_level=freq_level, ess_settings=ess_settings, job_types=job_types, allow_nonisomorphic_2d=True) zpe_dict = dict() for spc in species_list: zpe_dict[spc.label] = parse_zpe( os.path.join(project_directory, 'output', 'Species', spc.label, 'geometry', 'freq.out')) * 1000 # convert to J/mol zpe_dicts.append(zpe_dict) lambda_zpes.append( calculate_truhlar_scaling_factors(zpe_dict=zpe_dict, level=str(level))) times.append(time_lapse(t1)) summarize_results(lambda_zpes=lambda_zpes, levels=[str(level) for level in levels], zpe_dicts=zpe_dicts, times=times, overall_time=time_lapse(t0)) logger.info('\n\n\n') logger.info(HEADER) harmonic_freq_scaling_factors = [ lambda_zpe * 1.014 for lambda_zpe in lambda_zpes ] return harmonic_freq_scaling_factors
def setUpClass(cls): """ A method that is run before all unit tests in this class. """ cls.maxDiff = None cls.ess_settings = { 'gaussian': ['server1'], 'molpro': ['server2', 'server1'], 'qchem': ['server1'] } cls.project_directory = os.path.join( arc_path, 'Projects', 'arc_project_for_testing_delete_after_usage3') cls.spc1 = ARCSpecies(label='methylamine', smiles='CN') cls.spc2 = ARCSpecies(label='C2H6', smiles='CC') xyz1 = """C 1.11424367 -0.01231165 -0.11493630 C -0.07257945 -0.17830906 -0.16010022 O -1.38500471 -0.36381519 -0.20928090 H 2.16904830 0.12689206 -0.07152274 H -1.82570782 0.42754384 -0.56130718""" cls.spc3 = ARCSpecies(label='CtripCO', smiles='C#CO', xyz=xyz1) xyz2 = { 'symbols': ('C', ), 'isotopes': (12, ), 'coords': ((0.0, 0.0, 0.0), ) } cls.job1 = Job(project='project_test', ess_settings=cls.ess_settings, species_name='methylamine', xyz=xyz2, job_type='conformer', conformer=0, level={ 'method': 'b97-d3', 'basis': '6-311+g(d,p)' }, multiplicity=1, project_directory=cls.project_directory, job_num=101) cls.job2 = Job(project='project_test', ess_settings=cls.ess_settings, species_name='methylamine', xyz=xyz2, job_type='conformer', conformer=1, level={ 'method': 'b97-d3', 'basis': '6-311+g(d,p)' }, multiplicity=1, project_directory=cls.project_directory, job_num=102) cls.job3 = Job(project='project_test', ess_settings=cls.ess_settings, species_name='C2H6', xyz=xyz2, job_type='freq', level={ 'method': 'wb97x-d3', 'basis': '6-311+g(d,p)' }, multiplicity=1, project_directory=cls.project_directory, software='qchem', job_num=103) cls.rmg_database = rmgdb.make_rmg_database_object() cls.job_types1 = { 'conformers': True, 'opt': True, 'fine_grid': False, 'freq': True, 'sp': True, 'rotors': False, 'orbitals': False, 'lennard_jones': False, } cls.sched1 = Scheduler( project='project_test', ess_settings=cls.ess_settings, species_list=[cls.spc1, cls.spc2, cls.spc3], composite_method=None, conformer_level=Level(repr=default_levels_of_theory['conformer']), opt_level=Level(repr=default_levels_of_theory['opt']), freq_level=Level(repr=default_levels_of_theory['freq']), sp_level=Level(repr=default_levels_of_theory['sp']), scan_level=Level(repr=default_levels_of_theory['scan']), ts_guess_level=Level(repr=default_levels_of_theory['ts_guesses']), rmg_database=cls.rmg_database, project_directory=cls.project_directory, testing=True, job_types=cls.job_types1, orbitals_level=default_levels_of_theory['orbitals'], adaptive_levels=None, )
def test_determine_adaptive_level(self): """Test the determine_adaptive_level() method""" # adaptive_levels get converted to ``Level`` objects in main, but here we skip main and test Scheduler directly adaptive_levels = { (1, 5): { ('opt', 'freq'): Level(repr='wb97xd/6-311+g(2d,2p)'), ('sp', ): Level(repr='ccsd(t)-f12/aug-cc-pvtz-f12') }, (6, 15): { ('opt', 'freq'): Level(repr='b3lyp/cbsb7'), ('sp', ): Level(repr='dlpno-ccsd(t)/def2-tzvp') }, (16, 30): { ('opt', 'freq'): Level(repr='b3lyp/6-31g(d,p)'), ('sp', ): Level(repr='wb97xd/6-311+g(2d,2p)') }, (31, 'inf'): { ('opt', 'freq'): Level(repr='b3lyp/6-31g(d,p)'), ('sp', ): Level(repr='b3lyp/6-311+g(d,p)') } } sched2 = Scheduler( project='project_test', ess_settings=self.ess_settings, species_list=[self.spc1, self.spc2], composite_method=None, conformer_level=default_levels_of_theory['conformer'], opt_level=default_levels_of_theory['opt'], freq_level=default_levels_of_theory['freq'], sp_level=default_levels_of_theory['sp'], scan_level=default_levels_of_theory['scan'], ts_guess_level=default_levels_of_theory['ts_guesses'], rmg_database=self.rmg_database, project_directory=self.project_directory, testing=True, job_types=self.job_types1, orbitals_level=default_levels_of_theory['orbitals'], adaptive_levels=adaptive_levels) original_level = Level(method='CBS-QB3') level1 = sched2.determine_adaptive_level( original_level_of_theory=original_level, job_type='opt', heavy_atoms=5) level2 = sched2.determine_adaptive_level( original_level_of_theory=original_level, job_type='freq', heavy_atoms=5) level3 = sched2.determine_adaptive_level( original_level_of_theory=original_level, job_type='opt', heavy_atoms=20) level4 = sched2.determine_adaptive_level( original_level_of_theory=original_level, job_type='composite', heavy_atoms=50) level5 = sched2.determine_adaptive_level( original_level_of_theory=original_level, job_type='orbitals', heavy_atoms=5) level6 = sched2.determine_adaptive_level( original_level_of_theory=original_level, job_type='sp', heavy_atoms=7) level7 = sched2.determine_adaptive_level( original_level_of_theory=original_level, job_type='sp', heavy_atoms=25) self.assertEqual(level1.simple(), 'wb97xd/6-311+g(2d,2p)') self.assertEqual(level2.simple(), 'wb97xd/6-311+g(2d,2p)') self.assertEqual(level3.simple(), 'b3lyp/6-31g(d,p)') self.assertEqual(level4.simple(), 'cbs-qb3') self.assertEqual(level5.simple(), 'cbs-qb3') self.assertEqual(level6.simple(), 'dlpno-ccsd(t)/def2-tzvp') self.assertEqual(level7.simple(), 'wb97xd/6-311+g(2d,2p)')
def test_conformers(self): """Test the parse_conformer_energy() and determine_most_stable_conformer() methods""" label = 'methylamine' self.job1.local_path_to_output_file = os.path.join( arc_path, 'arc', 'testing', 'methylamine_conformer_0.out') self.job1.job_status = [ 'done', { 'status': 'done', 'keywords': list(), 'error': '', 'line': '' } ] self.job2.local_path_to_output_file = os.path.join( arc_path, 'arc', 'testing', 'methylamine_conformer_1.out') self.job2.job_status = [ 'done', { 'status': 'done', 'keywords': list(), 'error': '', 'line': '' } ] self.sched1.job_dict[label] = dict() self.sched1.job_dict[label]['conformers'] = dict() self.sched1.job_dict[label]['conformers'][0] = self.job1 self.sched1.job_dict[label]['conformers'][1] = self.job2 self.sched1.species_dict[label].conformer_energies = [None, None] self.sched1.species_dict[label].conformers = [None, None] self.sched1.parse_conformer(job=self.job1, label=label, i=0) self.sched1.parse_conformer(job=self.job2, label=label, i=1) expecting = [-251596.4435088726, -254221.9433698632] self.assertAlmostEqual( self.sched1.species_dict[label].conformer_energies[0], expecting[0], 5) self.assertAlmostEqual( self.sched1.species_dict[label].conformer_energies[1], expecting[1], 5) self.sched1.species_dict[label].conformers[ 0] = parser.parse_xyz_from_file( self.job1.local_path_to_output_file) self.sched1.species_dict[label].conformers[ 1] = parser.parse_xyz_from_file( self.job2.local_path_to_output_file) self.sched1.determine_most_stable_conformer(label=label) expecting = { 'symbols': ('N', 'C', 'H', 'H', 'H', 'H', 'H'), 'isotopes': (14, 12, 1, 1, 1, 1, 1), 'coords': ((-0.75555952, -0.12937106, 0.0), (0.7085544, 0.03887206, 0.0), (1.06395135, 1.08711266, 0.0), (1.12732348, -0.45978507, 0.88433277), (1.12732348, -0.45978507, -0.88433277), (-1.16566701, 0.32023496, 0.81630508), (-1.16566701, 0.32023496, -0.81630508)) } self.assertTrue( almost_equal_coords_lists( self.sched1.species_dict[label].initial_xyz, expecting)) methylamine_conf_path = os.path.join( self.sched1.project_directory, 'output', 'Species', 'methylamine', 'geometry', 'conformers', 'conformers_after_optimization.txt') self.assertTrue(os.path.isfile(methylamine_conf_path)) with open(methylamine_conf_path, 'r') as f: lines = f.readlines() self.assertTrue( 'Conformers for methylamine, optimized at the wb97xd/def2svp level' in lines[0]) self.assertEqual(lines[11], 'SMILES: CN\n') self.assertTrue('Relative Energy:' in lines[12]) self.assertEqual(lines[16][0], 'N') self.sched1.output['C2H6'] = { 'info': '', 'paths': { 'composite': '', 'freq': '', 'geo': '' }, 'isomorphism': '', 'warnings': '', 'errors': '', 'job_types': { 'opt': False, 'composite': False, 'sp': False, 'fine_grid': False, 'freq': False, 'conformers': False }, 'convergence': True, 'conformers': '', 'restart': '' } self.sched1.run_conformer_jobs() save_conformers_file(project_directory=self.sched1.project_directory, label='C2H6', xyzs=self.sched1.species_dict['C2H6'].conformers, level_of_theory=Level(method='CBS-QB3'), multiplicity=1, charge=0) c2h6_conf_path = os.path.join(self.sched1.project_directory, 'output', 'Species', 'C2H6', 'geometry', 'conformers', 'conformers_before_optimization.txt') self.assertTrue(os.path.isfile(c2h6_conf_path)) with open(c2h6_conf_path, 'r') as f: lines = f.readlines() self.assertEqual(lines[0], 'conformer 0:\n') self.assertEqual(lines[1][0], 'C') self.assertEqual(lines[9], '\n') self.assertEqual(lines[10], 'SMILES: CC\n')
""" APIOxy levels module used for storing default levels of theory """ from arc.level import Level # Not implementing the "ML" and "0" levels LEVELS = {1: {'sp_level': Level(method='b3lyp', basis='6-31g(d,p)', ), 'opt_level': Level(method='b3lyp', basis='6-31g(d,p)', ), }, 2: {'sp_level': Level(method='wB97xd', basis='def2TZVP', solvation_method='SMD', solvent='water', ), 'opt_level': Level(method='wB97xd', basis='def2SVP', ), }, 3: {'sp_level': Level(method='DLPNO', basis='def2TZVP', auxiliary_basis='def2TZVP/C', args={'keyword': {'dlpno_threshold': 'normalPNO'}}, # solvation_method='COSMO/tzvpd-fine',
def test_deduce_software(self): """Test deducing an ESS by the level""" self.assertEqual( Level(method='B3LYP', basis='6-311g+(d,f)').software, 'gaussian') level_1 = Level(method='B3LYP/6-311g+(d,f)') level_1.deduce_software(job_type='onedmin') self.assertEqual(level_1.software, 'onedmin') self.assertEqual( Level(method='b3lyp', basis='6-311g+(d,f)').software, 'gaussian') level_2 = Level(method='b3lyp', basis='6-311g+(d,f)') level_2.deduce_software(job_type='orbitals') self.assertEqual(level_2.software, 'qchem') self.assertEqual( Level(method='B3LYP', basis='6-311g+(d,f)').software, 'gaussian') level_3 = Level(method='B3LYP', basis='6-311g+(d,f)') level_3.deduce_software(job_type='irc') self.assertEqual(level_3.software, 'gaussian') self.assertEqual( Level(method='DLPNO-CCSD(T)', basis='def2-tzvp').software, 'orca') self.assertEqual(Level(method='PM6').software, 'gaussian') self.assertEqual(Level(method='HF').software, 'gaussian') self.assertEqual( Level(method='CCSD(T)-F12', basis='aug-cc-pVTZ').software, 'molpro') self.assertEqual( Level(method='CISD', basis='aug-cc-pVTZ').software, 'molpro') self.assertEqual( Level(method='b3lyp', basis='6-311g+(d,f)').software, 'gaussian') self.assertEqual( Level(method='wb97x-d', basis='def2-tzvp').software, 'qchem') self.assertEqual( Level(method='wb97xd', basis='def2-tzvp').software, 'gaussian') self.assertEqual( Level(method='b97', basis='def2-tzvp').software, 'gaussian') self.assertEqual( Level(method='m06-2x', basis='def2-tzvp').software, 'qchem') self.assertEqual( Level(method='m062x', basis='def2-tzvp').software, 'gaussian') self.assertEqual( Level(method='b3p86', basis='6-311g+(d,f)').software, 'terachem') self.assertEqual( Level(method='new', basis='new', args={ 'keywords': { 'general': 'iop(99/33=1)' } }).software, 'gaussian')
def test_copy(self): """Test copying the object""" level_1 = Level(repr='wB97xd/def2-tzvp') level_2 = level_1.copy() self.assertIsNot(level_1, level_2) self.assertEqual(level_1.as_dict(), level_2.as_dict())
def test_to_arkane(self): """Test converting Level to LevelOfTheory""" level_1 = Level(repr='wB97xd/def2-tzvp') self.assertEqual( level_1.to_arkane_level_of_theory(), LevelOfTheory(method='wb97xd', basis='def2tzvp', software='gaussian')) self.assertEqual( level_1.to_arkane_level_of_theory(variant='freq'), LevelOfTheory(method='wb97xd', basis='def2tzvp', software='gaussian')) level_2 = Level(repr='CBS-QB3') self.assertEqual(level_2.to_arkane_level_of_theory(), LevelOfTheory(method='cbs-qb3', software='gaussian')) self.assertEqual(level_2.to_arkane_level_of_theory(variant='AEC'), LevelOfTheory(method='cbs-qb3', software='gaussian')) self.assertEqual(level_2.to_arkane_level_of_theory(variant='freq'), LevelOfTheory(method='cbs-qb3', software='gaussian')) self.assertEqual(level_2.to_arkane_level_of_theory(variant='BAC'), LevelOfTheory(method='cbs-qb3', software='gaussian')) self.assertIsNone( level_2.to_arkane_level_of_theory( variant='BAC', bac_type='m')) # might change in the future level_3 = Level( repr={ 'method': 'DLPNO-CCSD(T)', 'basis': 'def2-TZVp', 'auxiliary_basis': 'def2-tzvp/c', 'solvation_method': 'SMD', 'solvent': 'water', 'solvation_scheme_level': 'APFD/def2-TZVp' }) self.assertEqual( level_3.to_arkane_level_of_theory(), LevelOfTheory(method='dlpno-ccsd(t)', basis='def2tzvp', software='orca')) self.assertEqual( level_3.to_arkane_level_of_theory(comprehensive=True), LevelOfTheory(method='dlpnoccsd(t)', basis='def2tzvp', auxiliary_basis='def2tzvp/c', solvent='water', solvation_method='smd', software='orca'))