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', 'done'] self.job2.local_path_to_output_file = os.path.join( arc_path, 'arc', 'testing', 'methylamine_conformer_1.out') self.job2.job_status = ['done', 'done'] 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_energy(job=self.job1, label=label, i=0) self.sched1.parse_conformer_energy(job=self.job2, label=label, i=1) expecting = [-251596443.5088726, -254221943.3698632] self.assertEqual(self.sched1.species_dict[label].conformer_energies, expecting) 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 = """N -0.75555952 -0.12937106 0.00000000 C 0.70855440 0.03887206 0.00000000 H 1.06395135 1.08711266 0.00000000 H 1.12732348 -0.45978507 0.88433277 H 1.12732348 -0.45978507 -0.88433277 H -1.16566701 0.32023496 0.81630508 H -1.16566701 0.32023496 -0.81630508 """ self.assertEqual(self.sched1.species_dict[label].initial_xyz, expecting) methylamine_conf_path = os.path.join( self.sched1.project_directory, 'output', 'Species', 'methylamine', 'geometry', '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 optimized at' 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.run_conformer_jobs() self.sched1.save_conformers_file(label='C2H6') c2h6_conf_path = os.path.join(self.sched1.project_directory, 'output', 'Species', 'C2H6', 'geometry', '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[1][0], 'C') self.assertEqual(lines[9], '\n') self.assertEqual(lines[17][0], 'H')
def check_converge_and_geom_consist(spc, job_types=['composite', 'freq'], basis_job='composite'): basis_xyz = None done = determine_convergence(spc[basis_job], basis_job, spc['ts']) if done: try: basis_xyz = parse_xyz_from_file(spc[basis_job]) except: pass else: if 'species' in spc \ and not spc['species'].check_xyz_isomorphism(xyz=basis_xyz): basis_xyz = None if not basis_xyz: return spc['geom'] = basis_xyz spc['final_xyz'] = basis_xyz spc['checkfile'] = '' spc['charge'], spc['multiplicity'] = parse_charge_and_mult(spc[basis_job]) try: spc['smiles'] = xyz_to_mol(spc['geom']).to_smiles() except: try: spc['smiles'] = molecules_from_xyz(spc['geom'], spc['multiplicity'], spc['charge'])[0].to_smiles() except: spc['smiles'] = '' logging.warning(f"Cannot generate SMILES for {spc['label']}") # Assume checkfile is located under the same dir and named check.chk check_path = os.path.join(os.path.dirname(spc[basis_job]), 'check.chk') if os.path.isfile(check_path): spc['checkfile'] = check_path for job_type in job_types: if job_type == basis_job: continue xyz_to_compare = None done = determine_convergence(spc[job_type], job_type, spc['ts']) if done: try: xyz_to_compare = parse_xyz_from_file(spc[job_type]) except: pass if not xyz_to_compare or not compare_confs(basis_xyz, xyz_to_compare): # It seems like only basis job is well done spc[job_type] = '' continue return spc
def xyz_to_mol(xyz): if isinstance(xyz, dict): string = xyz_to_xyz_file_format(xyz) elif isinstance(xyz, str): if not xyz[0].isdigit(): atom_num = len(xyz.splitlines()) string = f'{atom_num}\n\n' + xyz else: string = xyz elif os.path.isfile(xyz): string = xyz_to_xyz_file_format(parse_xyz_from_file(xyz)) else: raise ValueError(f'Invalid xyz input, got: {xyz}') molecule = pybel.readstring('xyz', string) mol = Molecule() from_ob_mol(mol, molecule.OBMol) return mol
def generate_geom_info(spc, xyz_file=None): if not 'geom' in spc: xyz_file = xyz_file or os.path.join(spc['directory'], 'xyz.txt') try: spc['geom'] = parse_xyz_from_file(xyz_file) except: return try: mol = xyz_to_mol(spc['geom']) except: return spc['smiles'] = mol.to_smiles() spc['mol'] = mol.to_adjacency_list() spc['bond_dict'] = enumerate_bonds(mol) spc['atom_dict'] = mol.get_element_count() spc['linear'] = is_linear(coordinates=np.array(spc['geom']['coords'])) spc['external_symmetry'], spc['optical_isomers'] = determine_symmetry( spc['geom']) return spc
def test_parse_xyz_from_file(self): """Test parsing xyz from a file""" path1 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'CH3C(O)O.gjf') path2 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'CH3C(O)O.xyz') path3 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'AIBN.gjf') path4 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'molpro.in') path5 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'qchem.in') path6 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'qchem_output.out') path7 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'TS.gjf') xyz1 = parser.parse_xyz_from_file(path1) xyz2 = parser.parse_xyz_from_file(path2) xyz3 = parser.parse_xyz_from_file(path3) xyz4 = parser.parse_xyz_from_file(path4) xyz5 = parser.parse_xyz_from_file(path5) xyz6 = parser.parse_xyz_from_file(path6) xyz7 = parser.parse_xyz_from_file(path7) self.assertEqual(xyz1.rstrip(), xyz2.rstrip()) self.assertTrue( 'C 1.40511900 0.21728200 0.07675200' in xyz1) self.assertTrue( 'O -0.79314200 1.04818800 0.18134200' in xyz1) self.assertTrue( 'H -0.43701200 -1.34990600 0.92900600' in xyz2) self.assertTrue( 'C 2.12217963 -0.66843078 1.04808732' in xyz3) self.assertTrue( 'N 2.41731872 -1.07916417 2.08039935' in xyz3) spc3 = ARCSpecies(label='AIBN', xyz=xyz3) self.assertEqual(len(spc3.mol.atoms), 24) self.assertTrue( 'S -0.4204682221 -0.3909949822 0.0245352116' in xyz4) self.assertTrue( 'N -1.99742564 0.38106573 0.09139807' in xyz5) self.assertTrue( 'N -1.17538406 0.34366165 0.03265021' in xyz6) self.assertEqual(len(xyz7.strip().splitlines()), 34)
def test_parse_xyz_from_file(self): """Test parsing xyz from a file""" path1 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'CH3C(O)O.gjf') path2 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'CH3C(O)O.xyz') path3 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'AIBN.gjf') path4 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'molpro.in') path5 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'qchem.in') path6 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'qchem_output.out') path7 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'TS.gjf') path8 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'formaldehyde_coords.xyz') path9 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'optim_traj_terachem.xyz') # test trajectories path10 = os.path.join(arc_path, 'arc', 'testing', 'xyz', 'ethane_minimize_terachem_output.out') path11 = os.path.join(arc_path, 'arc', 'testing', 'orca_example_opt.log') xyz1 = parser.parse_xyz_from_file(path1) xyz2 = parser.parse_xyz_from_file(path2) xyz3 = parser.parse_xyz_from_file(path3) xyz4 = parser.parse_xyz_from_file(path4) xyz5 = parser.parse_xyz_from_file(path5) xyz6 = parser.parse_xyz_from_file(path6) xyz7 = parser.parse_xyz_from_file(path7) xyz8 = parser.parse_xyz_from_file(path8) xyz9 = parser.parse_xyz_from_file(path9) xyz10 = parser.parse_xyz_from_file(path10) xyz11 = parser.parse_xyz_from_file(path11) self.assertEqual(xyz1, xyz2) xyz1_str = xyz_to_str(xyz1) xyz2_str = xyz_to_str(xyz2) xyz3_str = xyz_to_str(xyz3) xyz4_str = xyz_to_str(xyz4) xyz5_str = xyz_to_str(xyz5) xyz6_str = xyz_to_str(xyz6) xyz9_str = xyz_to_str(xyz9) xyz11_str = xyz_to_str(xyz11) self.assertTrue( 'C 1.40511900 0.21728200 0.07675200' in xyz1_str) self.assertTrue( 'O -0.79314200 1.04818800 0.18134200' in xyz1_str) self.assertTrue( 'H -0.43701200 -1.34990600 0.92900600' in xyz2_str) self.assertTrue( 'C 2.12217963 -0.66843078 1.04808732' in xyz3_str) self.assertTrue( 'N 2.41731872 -1.07916417 2.08039935' in xyz3_str) spc3 = ARCSpecies(label='AIBN', xyz=xyz3) self.assertEqual(len(spc3.mol.atoms), 24) self.assertTrue( 'S -0.42046822 -0.39099498 0.02453521' in xyz4_str) self.assertTrue( 'N -1.99742564 0.38106573 0.09139807' in xyz5_str) self.assertTrue( 'N -1.17538406 0.34366165 0.03265021' in xyz6_str) self.assertEqual(len(xyz7['symbols']), 34) self.assertEqual(len(xyz8['symbols']), 4) expected_xyz_9 = """N -0.67665958 0.74524340 -0.41319355 H -1.26179357 1.52577220 -0.13687665 H 0.28392722 1.06723640 -0.44163375 N -0.75345799 -0.33268278 0.51180786 H -0.97153041 -0.02416219 1.45398654 H -1.48669570 -0.95874053 0.20627423 N 2.28178508 -0.42455356 0.14404399 H 1.32677989 -0.80557411 0.33156013""" self.assertEqual(xyz9_str, expected_xyz_9) self.assertIsNone(xyz10) expected_xyz_11 = """C 0.00917900 -0.00000000 -0.00000000 O 1.20814900 -0.00000000 0.00000000 H -0.59436200 0.94730400 0.00000000 H -0.59436200 -0.94730400 0.00000000""" self.assertEqual(xyz11_str, expected_xyz_11)
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')
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 = """N -0.75555952 -0.12937106 0.00000000 C 0.70855440 0.03887206 0.00000000 H 1.06395135 1.08711266 0.00000000 H 1.12732348 -0.45978507 0.88433277 H 1.12732348 -0.45978507 -0.88433277 H -1.16566701 0.32023496 0.81630508 H -1.16566701 0.32023496 -0.81630508""" self.assertEqual(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 b3lyp/6-31g(d,p) EmpiricalDispersion=GD3BJ level' in lines[0]) self.assertEqual(lines[10], 'SMILES: CN\n') self.assertTrue('Relative Energy:' in lines[11]) self.assertEqual(lines[15][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='level1', 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[1][0], 'C') self.assertEqual(lines[9], '\n') self.assertEqual(lines[10], 'SMILES: CC\n')