def test_helium(self): """ adjlist: Test that the adjlist reading and writing works with Helium. """ smiles = '[He]' inchi = 'InChI=1S/He' adjlist = '1 He u0 p1 c0' adjlist_old = '1 He 0' adjlist_intermediate = '1 He 0 1' mol_smiles = Molecule().from_smiles(smiles) mol_inchi = Molecule().from_inchi(inchi) mol = Molecule().from_adjacency_list(adjlist) mol_old = Molecule().from_adjacency_list(adjlist_old) mol_intermediate = Molecule().from_adjacency_list(adjlist_intermediate) # Isomorphic check self.assertTrue(mol_smiles.is_isomorphic(mol)) self.assertTrue(mol_smiles.is_isomorphic(mol_inchi)) self.assertTrue(mol_smiles.is_isomorphic(mol_old)) self.assertTrue(mol_smiles.is_isomorphic(mol_intermediate)) # Adjlist check self.assertEqual(mol_smiles.to_adjacency_list().strip(), adjlist) self.assertEqual(mol_inchi.to_adjacency_list().strip(), adjlist) self.assertEqual(mol.to_adjacency_list().strip(), adjlist) self.assertEqual(mol_old.to_adjacency_list().strip(), adjlist) self.assertEqual(mol_intermediate.to_adjacency_list().strip(), adjlist) self.assertEqual(mol.to_smiles(), smiles) self.assertEqual(mol.to_inchi(), 'InChI=1S/He')
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)
def test_aromatics(self): """Test that different aromatics representations returns different SMILES.""" mol1 = Molecule().from_adjacency_list(""" 1 O u0 p2 c0 {6,S} {9,S} 2 C u0 p0 c0 {3,D} {5,S} {11,S} 3 C u0 p0 c0 {2,D} {4,S} {12,S} 4 C u0 p0 c0 {3,S} {6,D} {13,S} 5 C u0 p0 c0 {2,S} {7,D} {10,S} 6 C u0 p0 c0 {1,S} {4,D} {7,S} 7 C u0 p0 c0 {5,D} {6,S} {8,S} 8 C u0 p0 c0 {7,S} {14,S} {15,S} {16,S} 9 H u0 p0 c0 {1,S} 10 H u0 p0 c0 {5,S} 11 H u0 p0 c0 {2,S} 12 H u0 p0 c0 {3,S} 13 H u0 p0 c0 {4,S} 14 H u0 p0 c0 {8,S} 15 H u0 p0 c0 {8,S} 16 H u0 p0 c0 {8,S} """) mol2 = Molecule().from_adjacency_list(""" 1 O u0 p2 c0 {6,S} {9,S} 2 C u0 p0 c0 {3,S} {5,D} {11,S} 3 C u0 p0 c0 {2,S} {4,D} {12,S} 4 C u0 p0 c0 {3,D} {6,S} {13,S} 5 C u0 p0 c0 {2,D} {7,S} {10,S} 6 C u0 p0 c0 {1,S} {4,S} {7,D} 7 C u0 p0 c0 {5,S} {6,D} {8,S} 8 C u0 p0 c0 {7,S} {14,S} {15,S} {16,S} 9 H u0 p0 c0 {1,S} 10 H u0 p0 c0 {5,S} 11 H u0 p0 c0 {2,S} 12 H u0 p0 c0 {3,S} 13 H u0 p0 c0 {4,S} 14 H u0 p0 c0 {8,S} 15 H u0 p0 c0 {8,S} 16 H u0 p0 c0 {8,S} """) mol3 = Molecule().from_adjacency_list(""" 1 O u0 p2 c0 {6,S} {9,S} 2 C u0 p0 c0 {3,B} {5,B} {11,S} 3 C u0 p0 c0 {2,B} {4,B} {12,S} 4 C u0 p0 c0 {3,B} {6,B} {13,S} 5 C u0 p0 c0 {2,B} {7,B} {10,S} 6 C u0 p0 c0 {1,S} {4,B} {7,B} 7 C u0 p0 c0 {5,B} {6,B} {8,S} 8 C u0 p0 c0 {7,S} {14,S} {15,S} {16,S} 9 H u0 p0 c0 {1,S} 10 H u0 p0 c0 {5,S} 11 H u0 p0 c0 {2,S} 12 H u0 p0 c0 {3,S} 13 H u0 p0 c0 {4,S} 14 H u0 p0 c0 {8,S} 15 H u0 p0 c0 {8,S} 16 H u0 p0 c0 {8,S} """) smiles1 = mol1.to_smiles() smiles2 = mol2.to_smiles() smiles3 = mol3.to_smiles() self.assertNotEqual(smiles1, smiles2) self.assertNotEqual(smiles2, smiles3) self.assertNotEqual(smiles1, smiles3)
def test_empty_molecule(self): """Test that we can safely return a blank identifier for an empty molecule.""" mol = Molecule() self.assertEqual(mol.to_smiles(), '') self.assertEqual(mol.to_inchi(), '')
def compare(self, adjlist, smiles): mol = Molecule().from_adjacency_list(adjlist) self.assertEquals(smiles, mol.to_smiles())