def extract_data_from_tar_file(tar_file):
    with tarfile.open(tar_file, 'r:gz') as tar:
        tar.extractall()

    folder = tar_file.replace('.tar.gz', '')
    with cd(folder):
        tdout = GaussianOutput('td.log')
        td_exit = tdout.read_excitation_energies()
        td_triplet = [e for e in td_exit if 'triplet' in e[3].lower()][0][0]
        td_singlet = [e for e in td_exit if 'singlet' in e[3].lower()][0][0]

        tdaout = GaussianOutput('tda.log')
        tda_exit = tdaout.read_excitation_energies()
        tda_triplet = [e for e in tda_exit if 'triplet' in e[3].lower()][0][0]
        tda_singlet = [e for e in tda_exit if 'singlet' in e[3].lower()][0][0]

        nicssout = GaussianOutput('nics_singlet.log')
        # occasionally some jobs fail here
        if not nicssout.properly_terminated:
            return False
        nicss_mag = nicssout.read_magnetic_shielding()
        nicss_six_ring_above = (abs(nicss_mag[-8]['isotropic']) +
                                abs(nicss_mag[-6]['isotropic']))/2
        nicss_six_ring_below = (abs(nicss_mag[-7]['isotropic']) +
                                abs(nicss_mag[-5]['isotropic']))/2
        nicss_five_ring_above = (abs(nicss_mag[-4]['isotropic']) +
                                 abs(nicss_mag[-2]['isotropic']))/2
        nicss_five_ring_below = (abs(nicss_mag[-3]['isotropic']) +
                                 abs(nicss_mag[-1]['isotropic']))/2

        nicstout = GaussianOutput('nics_triplet.log')
        if not nicstout.properly_terminated:
            return False
        nicst_mag = nicstout.read_magnetic_shielding()
        nicst_six_ring_above = (abs(nicst_mag[-8]['isotropic']) +
                                abs(nicst_mag[-6]['isotropic']))/2
        nicst_six_ring_below = (abs(nicst_mag[-7]['isotropic']) +
                                abs(nicst_mag[-5]['isotropic']))/2
        nicst_five_ring_above = (abs(nicst_mag[-4]['isotropic']) +
                                 abs(nicst_mag[-2]['isotropic']))/2
        nicst_five_ring_below = (abs(nicst_mag[-3]['isotropic']) +
                                 abs(nicst_mag[-1]['isotropic']))/2

        data = {'td_singlet': td_singlet, 'td_triplet': td_triplet,
                'tda_singlet': tda_singlet, 'tda_triplet': tda_triplet,
                'nicss_six_ring_above': nicss_six_ring_above,
                'nicss_six_ring_below': nicss_six_ring_below,
                'nicss_five_ring_above': nicss_five_ring_above,
                'nicss_five_ring_below': nicss_five_ring_below,
                'nicst_six_ring_above': nicst_six_ring_above,
                'nicst_six_ring_below': nicst_six_ring_below,
                'nicst_five_ring_above': nicst_five_ring_above,
                'nicst_five_ring_below': nicst_five_ring_below}
    return data
Beispiel #2
0
def make_json(mol_dir, mol_name, json_file):
    """
    For a molecule directory, mol_dir, this finds the molecule name, frequencies
    value, and runtiime and places those into  json_file.
    """
    log_files = [x for x in os.listdir(mol_dir) if x.endswith('.log')]
    if len(log_files) > 0:
        log_fn = log_files[0]
        log_path = os.path.join(mol_dir, log_fn)
        mol = GaussianOutput(log_path)
        runtime = runtime_from_log(log_path)
        if mol.properly_terminated:
            charge = mol.charge
            try:
                excitations = mol.read_excitation_energies()
            except IndexError:
                excitations = None


            # Write json
            json_data = {"molecule_name": mol_name, "excitations": excitations, "charge": charge, "runtime": runtime}
            write_json(json_data, json_file)
            print("Data collected for {}".format(mol_name))
        else:
            print("Error. Calculation did not properly terminate for {}".format(mol_name))
    else:
        print("No log file for ", mol_name)
Beispiel #3
0
 def test_td(self):
     gau = GaussianOutput(os.path.join(test_dir, "so2_td.log"))
     transitions = gau.read_excitation_energies()
     self.assertEqual(len(transitions), 4)
     self.assertAlmostEqual(transitions[0], (3.9281, 315.64, 0.0054))
Beispiel #4
0
 def test_td(self):
     gau = GaussianOutput(os.path.join(test_dir, "so2_td.log"))
     transitions = gau.read_excitation_energies()
     self.assertEqual(len(transitions), 4)
     self.assertAlmostEqual(transitions[0], (3.9281, 315.64, 0.0054))