How to use the cclib.parser.utils.convertor function in cclib

To help you get started, we’ve selected a few cclib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cclib / cclib / cclib / parser / psi4parser.py View on Github external
def _parse_mosyms_moenergies(self, inputfile, spinidx):
        """Parse molecular orbital symmetries and energies from the
        'Post-Iterations' section.
        """
        line = next(inputfile)
        while line.strip():
            for i in range(len(line.split()) // 2):
                self.mosyms[spinidx].append(line.split()[i*2][-2:])
                moenergy = utils.convertor(float(line.split()[i*2+1]), "hartree", "eV")
                self.moenergies[spinidx].append(moenergy)
            line = next(inputfile)
        return
github cclib / cclib / test / regression.py View on Github external
def testQChem_QChem5_0_argon_out(logfile):
    """This job has unit specifications at the end of 'Total energy for
    state' lines.
    """
    assert logfile.data.metadata["package_version"] == "5.0.1"
    nroots = 12
    assert len(logfile.data.etenergies) == nroots
    state_0_energy = -526.6323968555
    state_1_energy = -526.14663738
    assert logfile.data.scfenergies[0] == convertor(state_0_energy, 'hartree', 'eV')
    assert abs(logfile.data.etenergies[0] - convertor(state_1_energy - state_0_energy, 'hartree', 'wavenumber')) < 1.0e-1
github cclib / cclib / cclib / parser / turbomoleparser.py View on Github external
if spin == 1 and title[0:11] == "$uhfmo_beta":
                    title = inputfile.next()
                    while title[0] == "#":
                        title = inputfile.next()

                while(title[0] != '$'):
                    temp=title.split()

                    orb_symm=temp[1]

                    try:
                        energy = float(temp[2][11:].replace("D", "E"))
                    except ValueError:
                        print(spin, ": ", title)

                    orb_en = utils.convertor(energy,"hartree","eV")

                    moenergies.append(orb_en)
                    single_mo = []
                    
                    while(len(single_mo)
github cclib / cclib / cclib / parser / nwchemparser.py View on Github external
if "Total MP2 energy" in line:
            self.metadata["methods"].append("MP2")
            mpenerg = float(line.split()[-1])
            if not hasattr(self, "mpenergies"):
                self.mpenergies = []
            self.mpenergies.append([])
            self.mpenergies[-1].append(utils.convertor(mpenerg, "hartree", "eV"))

        if "CCSD total energy / hartree" in line or "total CCSD energy:" in line:
            self.metadata["methods"].append("CCSD")
            ccenerg = float(line.split()[-1])
            if not hasattr(self, "ccenergies"):
                self.ccenergies = []
            self.ccenergies.append([])
            self.ccenergies[-1].append(utils.convertor(ccenerg, "hartree", "eV"))

        if "CCSD(T) total energy / hartree" in line:
            self.metadata["methods"].append("CCSD(T)")
            ccenerg = float(line.split()[-1])
            if not hasattr(self, "ccenergies"):
                self.ccenergies = []
            self.ccenergies.append([])
            self.ccenergies[-1].append(utils.convertor(ccenerg, "hartree", "eV"))

        # Static and dynamic polarizability.
        if "Linear Response polarizability / au" in line:
            if not hasattr(self, "polarizabilities"):
                self.polarizabilities = []
            polarizability = []
            line = next(inputfile)
            assert line.split()[0] == "Frequency"
github cclib / cclib / cclib / parser / qchemparser.py View on Github external
while not self.re_dashes_and_spaces.search(line) \
              and not 'Warning : Irrep of orbital' in line:
            if 'Occupied' in line or 'Virtual' in line:
                # A nice trick to find where the HOMO is.
                if 'Virtual' in line:
                    homo = len(energies) - 1
                line = next(inputfile)
            tokens = line.split()
            # If the line contains letters, it must be the MO
            # symmetries. Otherwise, it's the energies.
            if re.search("[a-zA-Z]", line):
                symbols.extend(tokens[1::2])
            else:
                for e in tokens:
                    try:
                        energy = utils.convertor(self.float(e), 'hartree', 'eV')
                    except ValueError:
                        energy = numpy.nan
                    energies.append(energy)
            line = next(inputfile)

        # MO symmetries are either not present or there is one for each MO
        # (energy).
        assert len(symbols) in (0, len(energies))

        return energies, symbols, homo
github cclib / cclib / cclib / parser / qchemparser.py View on Github external
while 'Translational Enthalpy' not in line:
                        if 'Has Mass' in line:
                            atommass = float(line.split()[6])
                            atommasses.append(atommass)
                        line = next(inputfile)
                    if not hasattr(self, 'atommasses'):
                        self.atommasses = numpy.array(atommasses)

                while line.strip():
                    line = next(inputfile)

                line = next(inputfile)
                assert 'Total Enthalpy' in line
                if not hasattr(self, 'enthalpy'):
                    enthalpy = float(line.split()[2])
                    self.enthalpy = utils.convertor(enthalpy,
                                                    'kcal/mol', 'hartree')
                line = next(inputfile)
                assert 'Total Entropy' in line
                if not hasattr(self, 'entropy'):
                    entropy = float(line.split()[2]) * self.temperature / 1000
                    # This is the *temperature dependent* entropy.
                    self.entropy = utils.convertor(entropy,
                                                   'kcal/mol', 'hartree')
                if not hasattr(self, 'freeenergy'):
                    self.freeenergy = self.enthalpy - self.entropy

        if line[:16] == ' Total job time:':
            self.metadata['success'] = True
github cclib / cclib / cclib / method / moments.py View on Github external
def _calculate_dipole(self, charges, coords, origin):
        """Calculate the dipole moment from the given atomic charges
        and their coordinates with respect to the origin.
        """
        transl_coords_au = convertor(coords - origin, 'Angstrom', 'bohr')
        dipole = numpy.dot(charges, transl_coords_au)

        return convertor(dipole, 'ebohr', 'Debye')
github cclib / cclib / src / cclib / io / wfxwriter.py View on Github external
def _mo_energies(self):
        """Section: Molecular Orbital Energies."""
        mo_energies = []
        alpha_elctrons = self._no_alpha_electrons()
        beta_electrons = self._no_beta_electrons()
        for mo_energy in self.ccdata.moenergies[0][:alpha_elctrons]:
            mo_energies.append(WFX_FIELD_FMT % (
                utils.convertor(mo_energy, 'eV', 'hartree')))
        if self.ccdata.mult > 1:
            for mo_energy in self.ccdata.moenergies[1][:beta_electrons]:
                mo_energies.append(WFX_FIELD_FMT % (
                    utils.convertor(mo_energy, 'eV', 'hartree')))
        return mo_energies
github cclib / cclib / src / cclib / method / volume.py View on Github external
        convert = lambda x : convertor(x, "Angstrom", "bohr")
        ans = []