Esempio n. 1
0
    def parse_output(self, outfiles: Dict[str, str], input_model: 'ResultInput') -> 'Result':

        # gamessmol, if it exists, is dinky, just a clue to geometry of gamess results
        qcvars, gamessgrad, gamessmol = harvest(input_model.molecule, outfiles["stdout"])

        if gamessgrad is not None:
            qcvars['CURRENT GRADIENT'] = gamessgrad

        qcvars = unnp(qcvars, flat=True)

        output_data = {
            'schema_name': 'qcschema_output',
            'molecule': gamessmol,
            'schema_version': 1,
            'extras': {},
            'properties': {
                'nuclear_repulsion_energy': gamessmol.nuclear_repulsion_energy(),
            },
            'return_result': qcvars[f'CURRENT {input_model.driver.upper()}'],
            'stdout': outfiles["stdout"],
        }

        # got to even out who needs plump/flat/Decimal/float/ndarray/list
        output_data['extras']['qcvars'] = {
            k.upper(): float(v) if isinstance(v, Decimal) else v
            for k, v in qcel.util.unnp(qcvars, flat=True).items()
        }

        output_data['success'] = True

        return Result(**{**input_model.dict(), **output_data})
Esempio n. 2
0
    def parse_output(self, outfiles: Dict[str, str],
                     input_model: "AtomicInput") -> "AtomicResult":

        # gamessmol, if it exists, is dinky, just a clue to geometry of gamess results
        qcvars, gamessgrad, gamessmol = harvest(input_model.molecule,
                                                outfiles["stdout"])

        if gamessgrad is not None:
            qcvars["CURRENT GRADIENT"] = gamessgrad

        qcvars = unnp(qcvars, flat=True)

        output_data = {
            "schema_name": "qcschema_output",
            "molecule": gamessmol,
            "schema_version": 1,
            "extras": {},
            "properties": {
                "nuclear_repulsion_energy":
                gamessmol.nuclear_repulsion_energy()
            },
            "return_result": qcvars[f"CURRENT {input_model.driver.upper()}"],
            "stdout": outfiles["stdout"],
        }

        # got to even out who needs plump/flat/Decimal/float/ndarray/list
        output_data["extras"]["qcvars"] = {
            k.upper(): float(v) if isinstance(v, Decimal) else v
            for k, v in qcel.util.unnp(qcvars, flat=True).items()
        }

        # copy qcvars into schema where possible
        qcvars_to_properties = {
            "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})
Esempio n. 3
0
def harvest_as_atomic_result(input_model: OptimizationInput,
                             nwout: str) -> List[AtomicResult]:
    """Parse each step in the geometry relaxation as a separate AtomicResult

    Args:
        input_model: Input specification for the relaxation
        nwout: Standard out from the NWChem simulation
    Returns:
        A list of the results at each step
    """
    # Parse the files
    out_psivars, out_mols, out_grads, version, error = harvest_output(nwout)

    # Make atomic results
    results = []
    for qcvars, nwgrad, out_mol in zip(out_psivars, out_grads, out_mols):
        if nwgrad is not None:
            qcvars[
                f"{input_model.input_specification.model.method.upper()[4:]} TOTAL GRADIENT"] = nwgrad
            qcvars["CURRENT GRADIENT"] = nwgrad

        # Get the formatted properties
        build_out(qcvars)
        atprop = build_atomicproperties(qcvars)

        # Format them inout an output
        output_data = {
            "schema_version":
            1,
            "molecule":
            out_mol,
            "driver":
            "gradient",
            "extras":
            input_model.extras.copy(),
            "model":
            input_model.input_specification.model,
            "keywords":
            input_model.input_specification.keywords,
            "properties":
            atprop,
            "provenance":
            Provenance(creator="NWChem", version=version,
                       routine="nwchem_opt"),
            "return_result":
            nwgrad,
            "success":
            True,
        }

        # got to even out who needs plump/flat/Decimal/float/ndarray/list
        # Decimal --> str preserves precision
        output_data["extras"]["qcvars"] = {
            k.upper(): str(v) if isinstance(v, Decimal) else v
            for k, v in unnp(qcvars, flat=True).items()
        }

        results.append(AtomicResult(**output_data))
    return results
Esempio n. 4
0
    def parse_output(self, outfiles: Dict[str, str],
                     input_model: 'ResultInput') -> 'Result':

        #        print('PARSE')
        #        pp.pprint(outfiles)

        # gamessmol, if it exists, is dinky, just a clue to geometry of gamess results
        qcvars, gamessgrad, gamessmol = harvest(
            input_model.molecule, outfiles["stdout"])  #**gamessfiles)

        if gamessgrad is not None:
            qcvars['CURRENT GRADIENT'] = gamessgrad

        qcvars = unnp(qcvars, flat=True)

        output_data = {
            'schema_name': 'qcschema_output',
            'molecule': gamessmol,
            'schema_version': 1,
            'extras': {},
            'properties': {
                'nuclear_repulsion_energy':
                gamessmol.nuclear_repulsion_energy(),
            },
            'return_result': qcvars[f'CURRENT {input_model.driver.upper()}'],
            'stdout': outfiles["stdout"],
        }

        #        # Absorb results into psi4 data structures
        #        for key in qcvars.keys():
        #            core.set_variable(key.upper(), float(qcvars[key]))

        #        if qcdbmolecule is None and gamessmol is not None:
        #            molecule = geometry(gamessmol.create_psi4_string_from_molecule(), name='blank_molecule_psi4_yo')
        #            molecule.update_geometry()
        #            # This case arises when no Molecule going into calc (cfour {} block) but want
        #            #   to know the orientation at which grad, properties, etc. are returned (c4mol).
        #            #   c4mol is dinky, w/o chg, mult, dummies and retains name
        #            #   blank_molecule_psi4_yo so as to not interfere with future cfour {} blocks

        # got to even out who needs plump/flat/Decimal/float/ndarray/list
        output_data['extras']['qcvars'] = {
            k.upper(): float(v) if isinstance(v, Decimal) else v
            for k, v in qcel.util.unnp(qcvars, flat=True).items()
        }

        #        # Quit if gamess threw error
        #        if core.get_variable('GAMESS ERROR CODE'):
        #            raise ValidationError("""gamess exited abnormally.""")
        #
        #        P4GAMESS_INFO.clear()
        #        P4GAMESS_INFO.update(internal_p4gamess_info)
        #
        #        optstash.restore()

        output_data['success'] = True

        return Result(**{**input_model.dict(), **output_data})
Esempio n. 5
0
    def parse_output(
        self, outfiles: Dict[str, str], input_model: AtomicInput
    ) -> AtomicResult:  # lgtm: [py/similar-function]

        stdout = outfiles.pop("stdout")
        stderr = outfiles.pop("stderr")

        # c4mol, if it exists, is dinky, just a clue to geometry of cfour results
        qcvars, c4hess, c4grad, c4mol, version, errorTMP = harvest(input_model.molecule, stdout, **outfiles)

        if c4grad is not None:
            qcvars["CURRENT GRADIENT"] = c4grad

        if c4hess is not None:
            qcvars["CURRENT HESSIAN"] = c4hess

        if input_model.driver.upper() == "PROPERTIES":
            retres = qcvars[f"CURRENT ENERGY"]
        else:
            retres = qcvars[f"CURRENT {input_model.driver.upper()}"]

        if isinstance(retres, Decimal):
            retres = float(retres)
        elif isinstance(retres, np.ndarray):
            retres = retres.ravel().tolist()

        build_out(qcvars)
        atprop = build_atomicproperties(qcvars)

        output_data = {
            "schema_version": 1,
            "extras": {"outfiles": outfiles, **input_model.extras},
            "properties": atprop,
            "provenance": Provenance(creator="CFOUR", version=self.get_version(), routine="xcfour"),
            "return_result": retres,
            "stderr": stderr,
            "stdout": stdout,
            "success": True,
        }

        # got to even out who needs plump/flat/Decimal/float/ndarray/list
        # Decimal --> str preserves precision
        output_data["extras"]["qcvars"] = {
            k.upper(): str(v) if isinstance(v, Decimal) else v for k, v in unnp(qcvars, flat=True).items()
        }

        return AtomicResult(**{**input_model.dict(), **output_data})
Esempio n. 6
0
    def parse_output(self, outfiles: Dict[str, str], input_model: AtomicInput) -> AtomicResult:

        # Get the stdout from the calculation (required)
        stdout = outfiles.pop("stdout")
        stderr = outfiles.pop("stderr")

        # gamessmol, if it exists, is dinky, just a clue to geometry of gamess results
        qcvars, gamessgrad, gamessmol = harvest(input_model.molecule, stdout, **outfiles)

        if gamessgrad is not None:
            qcvars["CURRENT GRADIENT"] = gamessgrad

        if input_model.driver.upper() == "PROPERTIES":
            retres = qcvars[f"CURRENT ENERGY"]
        else:
            retres = qcvars[f"CURRENT {input_model.driver.upper()}"]

        build_out(qcvars)
        atprop = build_atomicproperties(qcvars)

        output_data = {
            "schema_version": 1,
            "molecule": gamessmol,
            "extras": {"outfiles": outfiles, **input_model.extras},
            "properties": atprop,
            "provenance": Provenance(creator="GAMESS", version=self.get_version(), routine="rungms"),
            "return_result": retres,
            "stderr": stderr,
            "stdout": stdout,
            "success": True,
        }

        # got to even out who needs plump/flat/Decimal/float/ndarray/list
        output_data["extras"]["qcvars"] = {
            k.upper(): str(v) if isinstance(v, Decimal) else v for k, v in unnp(qcvars, flat=True).items()
        }

        return AtomicResult(**{**input_model.dict(), **output_data})
Esempio n. 7
0
    def parse_output(
        self, outfiles: Dict[str, str], input_model: "AtomicInput"
    ) -> AtomicResult:  # lgtm: [py/similar-function]

        # Get the stdout from the calculation (required)
        stdout = outfiles.pop("stdout")
        stderr = outfiles.pop("stderr")

        # Read the NWChem stdout file and, if needed, the hess or grad files
        qcvars, nwhess, nwgrad, nwmol, version, errorTMP = harvest(
            input_model.molecule, stdout, **outfiles)

        if nwgrad is not None:
            qcvars["CURRENT GRADIENT"] = nwgrad
        if nwhess is not None:
            qcvars["CURRENT HESSIAN"] = nwhess

        # Normalize the output as a float or list of floats
        if input_model.driver.upper() == "PROPERTIES":
            retres = qcvars[f"CURRENT ENERGY"]
        else:
            retres = qcvars[f"CURRENT {input_model.driver.upper()}"]
        if isinstance(retres, Decimal):
            retres = float(retres)
        elif isinstance(retres, np.ndarray):
            retres = retres.tolist()

        # Get the formatted properties
        build_out(qcvars)
        atprop = build_atomicproperties(qcvars)

        # Format them inout an output
        output_data = {
            "schema_version":
            1,
            "extras": {
                "outfiles": outfiles,
                **input_model.extras
            },
            "properties":
            atprop,
            "provenance":
            Provenance(creator="NWChem",
                       version=self.get_version(),
                       routine="nwchem"),
            "return_result":
            retres,
            "stderr":
            stderr,
            "stdout":
            stdout,
            "success":
            True,
        }

        # got to even out who needs plump/flat/Decimal/float/ndarray/list
        # Decimal --> str preserves precision
        output_data["extras"]["qcvars"] = {
            k.upper(): str(v) if isinstance(v, Decimal) else v
            for k, v in unnp(qcvars, flat=True).items()
        }

        return AtomicResult(**{**input_model.dict(), **output_data})