How to use the qcfractal.interface.models.rest_models.rest_model function in qcfractal

To help you get started, we’ve selected a few qcfractal 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 / QCFractal / qcfractal / queue / handlers.py View on Github external
def get(self):
        """Gets services from the service queue.
        """

        body_model, response_model = rest_model("service_queue", "get")
        body = self.parse_bodymodel(body_model)

        ret = self.storage.get_services(**body.data.dict(), projection=body.meta.projection)
        response = response_model(**ret)

        self.logger.info("GET: ServiceQueue - {} pulls.\n".format(len(response.data)))
        self.write(response.json())
github MolSSI / QCFractal / qcfractal / web_handlers.py View on Github external
def post(self):
        self.authenticate("write")

        body_model, response_model = rest_model("keyword", "post")
        body = self.parse_bodymodel(body_model)

        ret = self.storage.add_keywords(body.data)
        response = response_model(**ret)

        self.logger.info("POST: Keywords - {} inserted.".format(response.meta.n_inserted))
        self.write(response)
github MolSSI / QCFractal / qcfractal / queue / handlers.py View on Github external
def post(self):
        """Posts complete tasks to the Servers queue
        """

        body_model, response_model = rest_model("queue_manager", "post")
        body = self.parse_bodymodel(body_model)

        name = self._get_name_from_metadata(body.meta)
        self.logger.info("QueueManager: Received completed task packet from {}.".format(name))
        success, error = self.insert_complete_tasks(self.storage, body.data, self.logger)

        completed = success + error

        response = response_model(**{
            "meta": {
                "n_inserted": completed,
                "duplicates": [],
                "validation_errors": [],
                "success": True,
                "errors": [],
                "error_description": ""
github MolSSI / QCFractal / qcfractal / queue / handlers.py View on Github external
def get(self):
        """Posts new services to the service queue.
        """

        body_model, response_model = rest_model("task_queue", "get")
        body = self.parse_bodymodel(body_model)

        tasks = self.storage.get_queue(**body.data.dict(), projection=body.meta.projection)
        response = response_model(**tasks)

        self.logger.info("GET: TaskQueue - {} pulls.".format(len(response.data)))
        self.write(response.json())
github MolSSI / QCFractal / qcfractal / queue / handlers.py View on Github external
def get(self):
        """Pulls new tasks from the Servers queue
        """

        body_model, response_model = rest_model("queue_manager", "get")
        body = self.parse_bodymodel(body_model)

        # Figure out metadata and kwargs
        name = self._get_name_from_metadata(body.meta)

        # Grab new tasks and write out
        new_tasks = self.storage.queue_get_next(
            name, body.meta.programs, body.meta.procedures, limit=body.data.limit, tag=body.meta.tag)
        response = response_model(**{
            "meta": {
                "n_found": len(new_tasks),
                "success": True,
                "errors": [],
                "error_description": "",
                "missing": []
            },
github MolSSI / QCFractal / qcfractal / queue / handlers.py View on Github external
def put(self):
        """Posts new services to the service queue.
        """

        body_model, response_model = rest_model("service_queue", "put")
        body = self.parse_bodymodel(body_model)

        if (body.data.id is None) and (body.data.procedure_id is None):
            raise tornado.web.HTTPError(status_code=400, reason="Id or ProcedureId must be specified.")

        if body.meta.operation == "restart":
            updates = self.storage.update_service_status("running", **body.data.dict())
            data = {"n_updated": updates}
        else:
            raise tornado.web.HTTPError(status_code=400, reason=f"Operation '{operation}' is not valid.")

        response = response_model(data=data, meta={"errors": [], "success": True, "error_description": False})

        self.logger.info(f"PUT: TaskQueue - Operation: {body.meta.operation} - {updates}.")
        self.write(response)
github MolSSI / QCFractal / qcfractal / web_handlers.py View on Github external
def get(self, query_type='get'):

        body_model, response_model = rest_model(f"optimization/{query_type}", 'get')
        body = self.parse_bodymodel(body_model)

        try:
            if query_type == 'get':
                ret = self.storage.get_procedures(**{**body.data.dict(), **body.meta.dict()})
            else:  # all other queries, like 'best_opt_results'
                ret = self.storage.custom_query('optimization', query_type, **{**body.data.dict(), **body.meta.dict()})
        except KeyError as e:
            raise tornado.web.HTTPError(status_code=401, reason=str(e))

        response = response_model(**ret)

        self.logger.info("GET: Optimization ({}) - {} pulls.".format(query_type, len(response.data)))
        self.write(response)
github MolSSI / QCFractal / qcfractal / web_handlers.py View on Github external
Request:
            "data" - A list of key requests

        Returns:
            "meta" - Metadata associated with the query
                - "errors" - A list of errors in (index, error_id) format.
                - "n_found" - The number of molecule found.
                - "success" - If the query was successful or not.
                - "error_description" - A string based description of the error or False
                - "missing" - A list of keys that were not found.
            "data" - A dictionary of {key : value} dictionary of the results

        """

        body_model, response_model = rest_model("kvstore", "get")
        body = self.parse_bodymodel(body_model)

        ret = self.storage.get_kvstore(body.data.id)
        ret = response_model(**ret)

        self.logger.info("GET: KVStore - {} pulls.".format(len(ret.data)))
        self.write(ret)
github MolSSI / QCFractal / qcfractal / queue / handlers.py View on Github external
def post(self):
        """Posts new services to the service queue.
        """

        body_model, response_model = rest_model("service_queue", "post")
        body = self.parse_bodymodel(body_model)

        new_services = []
        for service_input in body.data:
            # Get molecules with ids
            if isinstance(service_input.initial_molecule, list):
                molecules = self.storage.get_add_molecules_mixed(service_input.initial_molecule)["data"]
                if len(molecules) != len(service_input.initial_molecule):
                    raise KeyError("We should catch this error.")
            else:
                molecules = self.storage.get_add_molecules_mixed([service_input.initial_molecule])["data"][0]

            # Update the input and build a service object
            service_input = service_input.copy(update={"initial_molecule": molecules})
            new_services.append(
                initialize_service(
github MolSSI / QCFractal / qcfractal / queue / handlers.py View on Github external
def get(self):
        """Gets services from the service queue.
        """

        body_model, response_model = rest_model("service_queue", "get")
        body = self.parse_bodymodel(body_model)

        ret = self.storage.get_services(**{**body.data.dict(), **body.meta.dict()})
        response = response_model(**ret)

        self.logger.info("GET: ServiceQueue - {} pulls.\n".format(len(response.data)))
        self.write(response)