How to use the qcengine.compute function in qcengine

To help you get started, we’ve selected a few qcengine 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 psi4 / psi4 / tests / pytests / test_qcng_dftd3_mp2d.py View on Github external
if 'qcmol' in request.node.name:
        mol = subject
    else:
        mol = subject.to_schema(dtype=2)

    resinp = {
        'schema_name': 'qcschema_input',
        'schema_version': 1,
        'molecule': mol,
        'driver': 'gradient',
        'model': {
            'method': inp['name']
        },
        'keywords': {},
    }
    jrec = qcng.compute(resinp, 'mp2d', raise_error=True)
    jrec = jrec.dict()

    #assert len(jrec['extras']['qcvars']) == 8

    assert compare_values(expected, jrec['extras']['qcvars']['CURRENT ENERGY'], atol=1.e-7)
    assert compare_values(expected, jrec['extras']['qcvars']['DISPERSION CORRECTION ENERGY'], atol=1.e-7)
    assert compare_values(expected, jrec['extras']['qcvars'][inp['lbl'] + ' DISPERSION CORRECTION ENERGY'], atol=1.e-7)

    assert compare_values(gexpected, jrec['extras']['qcvars']['CURRENT GRADIENT'], atol=1.e-7)
    assert compare_values(gexpected, jrec['extras']['qcvars']['DISPERSION CORRECTION GRADIENT'], atol=1.e-7)
    assert compare_values(
    gexpected, jrec['extras']['qcvars'][inp['lbl'] + ' DISPERSION CORRECTION GRADIENT'], atol=1.e-7)
github psi4 / psi4 / tests / pytests / test_qcng_dftd3.py View on Github external
if 'qcmol' in request.node.name:
        mol = subject
    else:
        mol = subject.to_schema(dtype=2)

    resinp = {
        'schema_name': 'qcschema_input',
        'schema_version': 1,
        'molecule': mol,
        'driver': 'gradient',
        'model': {
            'method': inp['name']
        },
        'keywords': {},
    }
    jrec = qcng.compute(resinp, 'dftd3', raise_error=True)
    jrec = jrec.dict()

    assert len(jrec['extras']['qcvars']) == 8

    assert compare_values(expected, jrec['extras']['qcvars']['CURRENT ENERGY'], atol=1.e-7)
    assert compare_values(expected, jrec['extras']['qcvars']['DISPERSION CORRECTION ENERGY'], atol=1.e-7)
    assert compare_values(expected, jrec['extras']['qcvars']['2-BODY DISPERSION CORRECTION ENERGY'], atol=1.e-7)
    assert compare_values(expected, jrec['extras']['qcvars'][inp['lbl'] + ' DISPERSION CORRECTION ENERGY'], atol=1.e-7)

    assert compare_values(gexpected, jrec['extras']['qcvars']['CURRENT GRADIENT'], atol=1.e-7)
    assert compare_values(gexpected, jrec['extras']['qcvars']['DISPERSION CORRECTION GRADIENT'], atol=1.e-7)
    assert compare_values(gexpected, jrec['extras']['qcvars']['2-BODY DISPERSION CORRECTION GRADIENT'], atol=1.e-7)
    assert compare_values(
        gexpected, jrec['extras']['qcvars'][inp['lbl'] + ' DISPERSION CORRECTION GRADIENT'], atol=1.e-7)
github psi4 / psi4 / tests / pytests / test_qcng_dftd3_mp2d.py View on Github external
def test_3():
    sys = qcel.molparse.from_string(seneyne)['qm']

    resinp = {
        'schema_name': 'qcschema_input',
        'schema_version': 1,
        'molecule': qcel.molparse.to_schema(sys, dtype=2),
        'driver': 'energy',
        'model': {
            'method': 'b3lyp',
        },
        'keywords': {
            'level_hint': 'd3bj'
        },
    }
    res = qcng.compute(resinp, 'dftd3', raise_error=True)
    res = res.dict()

    #res = dftd3.run_dftd3_from_arrays(molrec=sys, name_hint='b3lyp', level_hint='d3bj')
    assert compare('B3LYP-D3(BJ)', _compute_key(res['extras']['local_keywords']), 'key')
github psi4 / psi4 / tests / pytests / test_qcng_dftd3_mp2d.py View on Github external
def test_dftd3_task(method):
    json_data = {"molecule": qcng.get_molecule("eneyne"), "driver": "energy", "model": {"method": method}}

    ret = qcng.compute(json_data, "dftd3", raise_error=True, return_dict=True)

    assert ret["driver"] == "energy"
    assert "provenance" in ret
    assert "normal termination of dftd3" in ret["stdout"]

    for key in ["cpu", "hostname", "username", "wall_time"]:
        assert key in ret["provenance"]

    assert ret["success"] is True
github psi4 / psi4 / tests / pytests / test_qcng_dftd3.py View on Github external
if 'qcmol' in request.node.name:
        mol = subject
    else:
        mol = subject.to_schema(dtype=2)

    resinp = {
        'schema_name': 'qcschema_input',
        'schema_version': 1,
        'molecule': mol,
        'driver': 'energy', #gradient',
        'model': {
            'method': inp['name']
        },
        'keywords': {},
    }
    jrec = qcng.compute(resinp, 'mp2d', raise_error=True)
    jrec = jrec.dict()

    #assert len(jrec['extras']['qcvars']) == 8

    assert compare_values(expected, jrec['extras']['qcvars']['CURRENT ENERGY'], atol=1.e-7)
    assert compare_values(expected, jrec['extras']['qcvars']['DISPERSION CORRECTION ENERGY'], atol=1.e-7)
    assert compare_values(expected, jrec['extras']['qcvars'][inp['lbl'] + ' DISPERSION CORRECTION ENERGY'], atol=1.e-7)
github hjkgrp / MultirefPredict / MultirefPredict / fonbased_diagnostic.py View on Github external
def computeFon(self, method, basis=None):
        # Caculate energy for the whole molecule
        molecule_task = self.FonTask(self.molecule, self.program, method,basis)

        molecule_result = qcengine.compute(molecule_task, self.program)
        if self.record:
            filename = self.rundir + "/" + self.diagnostic_type + "_" \
                       + self.molname + "_" + method + "_" + "whole" + ".json"
            qcres_to_json(molecule_result, filename)
        if not molecule_result.success:
            raise RuntimeError("Quantum chemistry calculation failed.")
        print("FON calculation finished. Harvesting FON info.")
        self.fons = self.harvestFon(molecule_result)
github leeping / geomeTRIC / geometric / engine.py View on Github external
def calc_new(self, coords, dirname):
        import qcengine
        new_schema = deepcopy(self.schema)
        new_schema["molecule"]["geometry"] = coords.tolist()
        new_schema.pop("program", None)
        ret = qcengine.compute(new_schema, self.program, return_dict=True)
        # store the schema_traj for run_json to pick up
        self.schema_traj.append(ret)
        if ret["success"] is False:
            raise QCEngineAPIEngineError("QCEngineAPI computation did not execute correctly. Message: " + ret["error"]["error_message"])
        # Unpack the energy and gradient
        energy = ret["properties"]["return_energy"]
        gradient = np.array(ret["return_result"])
        return {'energy':energy, 'gradient':gradient}
github hjkgrp / MultirefPredict / MultirefPredict / ccbased_diagnostic.py View on Github external
def computeCCSDT(self):
        print("")
        print("Preparing CCSD(T) calculation")
        method = "ccsd(t)"
        basis = "cc-pvdz"
        if self.program != "psi4":
            raise ValueError("Support for packages other than psi4 is to be done\n")

        # Caculate energy for the whole molecule
        molecule_task = qcelemental.models.ResultInput(
            molecule=self.molecule,
            driver="energy",
            model={"method": method, "basis": basis},
        )
        print("Evaluating the energy of the whole molecule...")
        self.result = qcengine.compute(molecule_task, "psi4")
        print("self.result:", self.result)
        if not self.result.success:
            raise RuntimeError("Quantum chemistry calculation failed.")
        if self.record:
            filename = self.rundir + "/" + self.diagnostic_type + "_" + self.molname + "_" + "ccsd(t)" + "_" + "whole" + ".json"
            qcres_to_json(self.result, filename=filename)
github hjkgrp / MultirefPredict / MultirefPredict / ebased_diagnostic.py View on Github external
qcres_to_json(molecule_result, filename=filename)
        if not molecule_result.success:
            raise RuntimeError("Quantum chemistry calculation failed.")
        molecule_energy = molecule_result.return_result
        print("Final energy of the molecule (Hartree): {:.8f}".format(molecule_energy))

        print("Evaluating the energy of the atomization limit of the molecule...")
        if not self.atomized:
            self.mol2atoms()

        # Calculate energy for each unique atom at the atomization limit
        for symbol in self.atomized:
            atom_result = None
            if self.program == "terachem" and symbol == "H":
                 atom_task = self.energyTask(self.atomized[symbol]["molecule"], method, "psi4")
                 atom_result = qcengine.compute(atom_task, "psi4")
            else:
                 atom_task = self.energyTask(self.atomized[symbol]["molecule"], method, self.program)
                 atom_result = qcengine.compute(atom_task, self.program)
            if not atom_result.success:
                raise RuntimeError("Quantum chemistry calculation failed.")
            if self.record:
                filename = self.rundir + "/" + self.diagnostic_type + "_"\
                           + self.molname + "_" + method + "_" + symbol + ".json"
                qcres_to_json(atom_result, filename=filename)
            atom_energy = atom_result.return_result
            print("Final energy of atom ", symbol, " (Hartree): {:.8f}".format(atom_energy))
            self.atomized[symbol]["energy"] = atom_energy

        # Calculate BE
        BE = 0
        for symbol in self.atomized:
github psi4 / psi4 / psi4 / driver / procrouting / empirical_dispersion.py View on Github external
**{
                    'driver': 'gradient',
                    'model': {
                        'method': self.fctldash,
                        'basis': '(auto)',
                    },
                    'keywords': {
                        'level_hint': self.dashlevel,
                        'params_tweaks': self.dashparams,
                        'dashcoeff_supplement': self.dashcoeff_supplement,
                        'verbose': 1,
                    },
                    'molecule': molecule.to_schema(dtype=2),
                    'provenance': p4util.provenance_stamp(__name__),
                })
            jobrec = qcng.compute(resi, self.engine, raise_error=True,
                                  local_options={"scratch_directory": core.IOManager.shared_object().get_default_path()})

            dashd_part = core.Matrix.from_array(
                np.array(jobrec.extras['qcvars']['DISPERSION CORRECTION GRADIENT']).reshape(-1, 3))
            if wfn is not None:
                for k, qca in jobrec.extras['qcvars'].items():
                    if 'CURRENT' not in k:
                        wfn.set_variable(k, p4util.plump_qcvar(qca, k))

            if self.fctldash in ['hf3c', 'pbeh3c']:
                gcp_part = gcp.run_gcp(molecule, self.fctldash, verbose=False, dertype=1)
                dashd_part.add(gcp_part)

            return dashd_part
        else:
            return self.disp.compute_gradient(molecule)