How to use the qcelemental.constants.conversion_factor function in qcelemental

To help you get started, we’ve selected a few qcelemental 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 MolSSI / QCPortal / models / records.py View on Github external
units : str, optional
            Units to display the trajectory in.
        digits : int, optional
            The number of valid digits to show.
        relative : bool, optional
            If True, all energies are shifted by the lowest energy in the trajectory. Otherwise provides raw energies.
        return_figure : Optional[bool], optional
            If True, return the raw plotly figure. If False, returns a hosted iPlot. If None, return a iPlot display in
            Jupyter notebook and a raw plotly figure in all other circumstances.

        Returns
        -------
        plotly.Figure
            The requested figure.
        """
        cf = qcel.constants.conversion_factor("hartree", units)

        energies = np.array(self.energies)
        if relative:
            energies = energies - np.min(energies)

        trace = {"mode": "lines+markers", "x": list(range(1, len(energies) + 1)), "y": np.around(energies * cf, digits)}

        if relative:
            ylabel = f"Relative Energy [{units}]"
        else:
            ylabel = f"Absolute Energy [{units}]"

        custom_layout = {
            "title": "Geometry Optimization",
            "yaxis": {"title": ylabel, "zeroline": True},
            "xaxis": {
github MolSSI / QCEngine / qcengine / programs / qchem.py View on Github external
mobj_bbaa = re.search(r"\n\s*RI-MP2 ENERGY \(bb\|aa\)\s+=\s+" + NUMBER + r"\s+au\s*\n", outtext)
        if mobj_aaaa and mobj_bbbb:
            properties["mp2_opposite_spin_correlation_energy"] = float(mobj_aabb.group(1)) + float(mobj_bbaa.group(1))

        properties["calcinfo_natom"] = len(input_dict["molecule"]["symbols"])

        mobj = re.search(r"\n\s*(\d+)\s+" + NUMBER + "\s+" + NUMBER + r"\s+Convergence criterion met\s*\n", outtext)
        if mobj:
            properties["scf_iterations"] = int(mobj.group(1))

        mobj = re.search(
            r"\n\s+Dipole Moment \(Debye\)\s*\n\s+X\s+" + NUMBER + r"\s+Y\s+" + NUMBER + r"\s+Z\s+" + NUMBER + r"\s*\n",
            outtext,
        )
        if mobj:
            cf = constants.conversion_factor("debye", "e * bohr")
            properties["scf_dipole_moment"] = [float(mobj.group(i)) * cf for i in range(1, 4)]

        return properties, provenance
github MolSSI / QCPortal / collections / dataset.py View on Github external
else:
                        values = [np.array(v) for v in data.values]

                new_data[column_name] = pd.Series(values, index=data.index)[subset]
                units[column_name] = data.units
        else:
            for query in new_queries:
                query["native"] = False
            new_data, units = self._view.get_values(new_queries, subset)

        # convert units
        for query in new_queries:
            column_name = query["name"]
            metadata = {"native": False}
            try:
                new_data[column_name] *= constants.conversion_factor(units[column_name], self.units)
                metadata["units"] = self.units
            except (ValueError, TypeError) as e:
                # This is meant to catch pint.errors.DimensionalityError without importing pint, which is too slow.
                # In pint <=0.9, DimensionalityError is a ValueError.
                # In pint >=0.10, DimensionalityError is TypeError.
                if e.__class__.__name__ == "DimensionalityError":
                    metadata["units"] = units[column_name]
                else:
                    raise
            self._column_metadata[column_name].update(metadata)

        self._update_cache(new_data)
        return self.df.loc[subset, column_names]
github MolSSI / QCEngine / qcengine / programs / gamess / runner.py View on Github external
"DFT XC ENERGY": "scf_xc_energy",
            "ONE-ELECTRON ENERGY": "scf_one_electron_energy",
            "TWO-ELECTRON ENERGY": "scf_two_electron_energy",
            "SCF TOTAL ENERGY": "scf_total_energy",
            "MP2 CORRELATION ENERGY": "mp2_correlation_energy",
            "MP2 TOTAL ENERGY": "mp2_total_energy",
            "CCSD CORRELATION ENERGY": "ccsd_correlation_energy",
            "CCSD TOTAL ENERGY": "ccsd_total_energy",
            "CCSD(T) CORRELATION ENERGY": "ccsd_prt_pr_correlation_energy",
            "CCSD(T) TOTAL ENERGY": "ccsd_prt_pr_total_energy",
        }
        for qcvar in qcvars:
            if qcvar in qcvars_to_properties:
                output_data["properties"][qcvars_to_properties[qcvar]] = qcvars[qcvar]
        if {"SCF DIPOLE X", "SCF DIPOLE Y", "SCF DIPOLE Z"} & set(qcvars.keys()):
            conv = Decimal(qcel.constants.conversion_factor("debye", "e * bohr"))
            output_data["properties"]["scf_dipole_moment"] = [
                qcvars["SCF DIPOLE X"] * conv,
                qcvars["SCF DIPOLE Y"] * conv,
                qcvars["SCF DIPOLE Z"] * conv,
            ]
        output_data["success"] = True

        return AtomicResult(**{**input_model.dict(), **output_data})
github MolSSI / QCFractal / qcfractal / interface / collections / reaction_dataset.py View on Github external
names.append(qname)

            if force or not self._subset_in_cache(qname, subset):
                self._column_metadata[qname] = query
                new_queries.append(query)

        if not self._use_view(force):
            units: Dict[str, str] = {}
            for query in new_queries:
                qname = query.pop("name")
                data_complex = _query_apply_coeffients(stoich_complex, query)
                data_monomer = _query_apply_coeffients(stoich_monomer, query)

                data = data_complex - data_monomer

                new_data[qname] = data * constants.conversion_factor("hartree", self.units)
                query["name"] = qname
                units[qname] = self.units
        else:
            for query in new_queries:
                query["native"] = True
            new_data, units = self._view.get_values(new_queries)
            for query in new_queries:
                qname = query["name"]
                new_data[qname] = new_data[qname] * constants.conversion_factor(units[qname], self.units)

        for query in new_queries:
            qname = query["name"]
            self._column_metadata[qname].update({"native": True, "units": units[qname]})

        self._update_cache(new_data)
        return self.df.loc[subset, names]
github MolSSI / QCPortal / models / torsiondrive.py View on Github external
# Update minimum energy
            if v < min_energy:
                min_energy = v

        x = np.array(x)
        y = np.array(y)

        # Sort by angle
        sorter = np.argsort(x)
        x = x[sorter]
        y = y[sorter]
        if relative:
            y -= min_energy

        cf = constants.conversion_factor("hartree", units)
        trace = {"mode": "lines+markers", "x": x, "y": np.around(y * cf, digits)}
        # "name": "something"

        title = "TorsionDrive 1-D Plot"

        if relative:
            ylabel = f"Relative Energy [{units}]"
        else:
            ylabel = f"Absolute Energy [{units}]"

        custom_layout = {
            "title": title,
            "yaxis": {"title": ylabel, "zeroline": True},
            "xaxis": {"title": "Dihedral Angle [degrees]", "zeroline": False, "range": [x.min() - 10, x.max() + 10]},
        }
github MolSSI / QCFractal / qcfractal / interface / collections / reaction_dataset.py View on Github external
qname = query.pop("name")
                data_complex = _query_apply_coeffients(stoich_complex, query)
                data_monomer = _query_apply_coeffients(stoich_monomer, query)

                data = data_complex - data_monomer

                new_data[qname] = data * constants.conversion_factor("hartree", self.units)
                query["name"] = qname
                units[qname] = self.units
        else:
            for query in new_queries:
                query["native"] = True
            new_data, units = self._view.get_values(new_queries)
            for query in new_queries:
                qname = query["name"]
                new_data[qname] = new_data[qname] * constants.conversion_factor(units[qname], self.units)

        for query in new_queries:
            qname = query["name"]
            self._column_metadata[qname].update({"native": True, "units": units[qname]})

        self._update_cache(new_data)
        return self.df.loc[subset, names]
github MolSSI / QCFractal / qcfractal / interface / collections / dataset.py View on Github external
-------
        Series
            A pandas Series containing the request values.
        """
        data = self.get_contributed_values(key)

        # Annoying work around to prevent some pands magic
        if isinstance(next(iter(data.values.values())), (int, float)):
            values = data.values
        else:
            values = {k: [v] for k, v in data.values.items()}

        tmp_idx = pd.DataFrame.from_dict(values, orient="index", columns=[data.name])

        # Convert to numeric
        tmp_idx[tmp_idx.select_dtypes(include=['number']).columns] *= constants.conversion_factor(
            data.units, self.units)

        return tmp_idx
github MolSSI / QCFractal / qcfractal / interface / models / records.py View on Github external
----------
        units : str, optional
            Units to display the trajectory in.
        digits : int, optional
            The number of valid digits to show.
        relative : bool, optional
            If True, all energies are shifted by the lowest energy in the trajectory. Otherwise provides raw energies.
        return_figure : Optional[bool], optional
            If True, return the raw plotly figure. If False, returns a hosted iPlot. If None, return a iPlot display in Jupyter notebook and a raw plotly figure in all other circumstances.

        Returns
        -------
        plotly.Figure
            The requested figure.
        """
        cf = qcel.constants.conversion_factor("hartree", units)

        energies = np.array(self.energies)
        if relative:
            energies = energies - np.min(energies)

        trace = {
            "mode": "lines+markers",
            "x": list(range(1,
                            len(energies) + 1)),
            "y": np.around(energies * cf, digits)
        }

        if relative:
            ylabel = f"Relative Energy [{units}]"
        else:
            ylabel = f"Absolute Energy [{units}]"