コード例 #1
0
        """
        import numpy as np

        hessian = []
        hessian_found = False
        for line in fchkfile.split("\n"):
            if line.startswith("Cartesian Force Constants"):
                hessian_found = True
            elif hessian_found:
                if line.startswith("Nonadiabatic coupling") or line.startswith(
                        "Dipole Moment"):
                    hessian_found = False
                else:
                    hessian.extend([float(hess) for hess in line.split()])
        # now we can calculate the size of the hessian
        # (2 * triangle length) + 0.25 = (x+0.5)^2
        hess_size = int(np.sqrt(2 * len(hessian) + 0.25) - 0.5)
        full_hessian = np.zeros((hess_size, hess_size))
        m = 0
        for i in range(hess_size):
            for j in range(i + 1):
                full_hessian[i, j] = hessian[m]
                full_hessian[j, i] = hessian[m]
                m += 1

        return full_hessian.flatten().tolist()


# register the gaussian harness this must be done so gaussian can be used!
register_program(GaussianHarness())
コード例 #2
0
ファイル: testing.py プロジェクト: zachglick/QCEngine
def failure_engine():
    unique_name = "testing_random_name"

    class FailEngine(qcng.programs.ProgramHarness):
        iter_modes: List[str] = []
        ncalls: int = 0
        start_distance: float = 5
        equilibrium_distance: float = 4

        _defaults = {
            "name": unique_name,
            "scratch": False,
            "thread_safe": True,
            "thread_parallel": False,
            "node_parallel": False,
            "managed_memory": False,
        }

        class Config(qcng.programs.ProgramHarness.Config):
            allow_mutation: True

        @staticmethod
        def found(raise_error: bool = False) -> bool:
            return True

        def compute(self, input_data: 'ResultInput',
                    config: 'JobConfig') -> 'Result':
            self.ncalls += 1
            mode = self.iter_modes.pop(0)

            geom = input_data.molecule.geometry
            if geom.shape[0] != 2:
                raise ValueError(
                    "Failure Test must have an input size of two.")

            grad_value = np.abs(
                np.linalg.norm(geom[0] - geom[1]) - self.equilibrium_distance)
            grad = [0, 0, -grad_value, 0, 0, grad_value]

            if mode == "pass":
                return qcel.models.Result(
                    **{
                        **input_data.dict(),
                        **{
                            "properties": {
                                "return_energy": grad_value
                            },
                            "return_result": grad,
                            "success": True,
                            "extras": {
                                "ncalls": self.ncalls
                            },
                            "provenance": {
                                "creator": "failure_engine",
                                "ncores": config.ncores
                            }
                        }
                    })
            elif mode == "random_error":
                raise qcng.exceptions.RandomError("Whoops!")
            elif mode == "input_error":
                raise qcng.exceptions.InputError("Whoops!")
            else:
                raise KeyError("Testing error, should not arrive here.")

        def get_job(self):
            json_data = {
                "molecule": {
                    "symbols": ["He", "He"],
                    "geometry": [0, 0, 0, 0, 0, self.start_distance]
                },
                "driver": "gradient",
                "model": {
                    "method": "something"
                }
            }

            return json_data

    engine = FailEngine()
    qcng.register_program(engine)

    yield engine

    qcng.unregister_program(engine.name)