How to use the qcfractal.storage_sockets.storage_utils.get_metadata_template 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 / storage_sockets / mongoengine_socket.py View on Github external
Parameters
        ----------
        collection : str, optional
        name : str, optional
        return_json : bool
        with_ids : bool
        limit : int
        skip : int

        Returns
        -------
        A dict with keys: 'data' and 'meta'
            The data is a list of the collections found
        """

        meta = get_metadata_template()
        if name:
            name = name.lower()
        if collection:
            collection = collection.lower()
        query, errors = format_query(lname=name, collection=collection)

        data = []
        try:
            if projection:
                data = CollectionORM.objects(**query).only(*projection).limit(self.get_limit(limit)).skip(skip)
            else:
                data = CollectionORM.objects(**query).exclude("lname").limit(self.get_limit(limit)).skip(skip)

            meta["n_found"] = data.count()
            meta["success"] = True
        except Exception as err:
github MolSSI / QCFractal / qcfractal / storage_sockets / mongoengine_socket.py View on Github external
the self._max_limit will be returned instead
            (This is to avoid overloading the server)
        skip : int, default is 0
            skip the first 'skip' results. Used to paginate
        return_json : bool, default is True
            Return the results as a list of json instead of objects
        with_ids : bool, default is True
            Include the ids in the returned objects/dicts

        Returns
        -------
        Dict with keys: data, meta
            Data is the objects found
        """

        meta = get_metadata_template()

        # Ignore status if Id or task_id is present
        if id is not None or task_id is not None:
            status = None

        query, error = format_query(
            id=id,
            program=program,
            method=method,
            basis=basis,
            molecule=molecule,
            driver=driver,
            keywords=keywords,
            status=status)

        q_limit = self.get_limit(limit)
github MolSSI / QCFractal / qcfractal / storage_sockets / mongoengine_socket.py View on Github external
the self._max_limit will be returned instead
            (This is to avoid overloading the server)
        skip : int, default is 0
            skip the first 'skip' results. Used to paginate
        return_json : bool, default is True
            Return the results as a list of json instead of objects
        with_ids : bool, default is True
            Include the ids in the returned objects/dicts

        Returns
        -------
        Dict with keys: data, meta
            Data is the objects found
        """

        meta = get_metadata_template()

        if id is not None or task_id is not None:
            status = None

        query, error = format_query(
            id=id, procedure=procedure, program=program, hash_index=hash_index, task_id=task_id, status=status)

        q_limit = self.get_limit(limit)

        data = []
        try:
            if projection:
                data = ProcedureORM.objects(**query).only(*projection).limit(q_limit).skip(skip)
            else:
                data = ProcedureORM.objects(**query).limit(q_limit).skip(skip)
github MolSSI / QCFractal / qcfractal / storage_sockets / mongoengine_socket.py View on Github external
return_json : bool, optional
            Return the results as a json object
            Default is True
        with_ids : bool, optional
            Include the DB ids in the returned object (names 'id')
            Default is True


        Returns
        -------
            A dict with keys: 'data' and 'meta'
            (see get_metadata_template())
            The 'data' part is an object of the result or None if not found
        """

        meta = get_metadata_template()
        query, errors = format_query(id=id, hash_index=hash_index)

        data = []
        try:
            data = KeywordsORM.objects(**query).limit(self.get_limit(limit)).skip(skip)

            meta["n_found"] = data.count()
            meta["success"] = True
        except Exception as err:  # TODO: remove
            meta['error_description'] = str(err)

        if return_json:
            rdata = [KeywordSet(**d.to_json_obj(with_ids)) for d in data]
        else:
            rdata = data
github MolSSI / QCFractal / qcfractal / storage_sockets / mongoengine_socket.py View on Github external
def get_molecules(self, id=None, molecule_hash=None, molecular_formula=None, limit: int=None, skip: int=0):

        ret = {"meta": get_metadata_template(), "data": []}

        query, errors = format_query(id=id, molecule_hash=molecule_hash, molecular_formula=molecular_formula)

        # Don't include the hash or the molecular_formula in the returned result
        # Make the query
        data = MoleculeORM.objects(**query).exclude("molecule_hash", "molecular_formula")\
                                        .limit(self.get_limit(limit))\
                                        .skip(skip)\

        ret["meta"]["success"] = True
        ret["meta"]["n_found"] = data.count()  # all data count, can be > len(data)
        ret["meta"]["errors"].extend(errors)

        # Data validated going in
        data = [Molecule(**d.to_json_obj(), validate=False) for d in data]
        ret["data"] = data
github MolSSI / QCFractal / qcfractal / storage_sockets / sqlalchemy_socket.py View on Github external
def get_server_stats_log(self, before=None, after=None, limit=None, skip=0):

        meta = get_metadata_template()
        query = []

        if before:
            query.append(ServerStatsLogORM.timestamp <= before)

        if after:
            query.append(ServerStatsLogORM.timestamp >= after)

        with self.session_scope() as session:
            pose = session.query(ServerStatsLogORM).filter(*query).order_by(desc("timestamp"))
            meta["n_found"] = get_count_fast(pose)

            data = pose.limit(self.get_limit(limit)).offset(skip).all()
            data = [d.to_dict() for d in data]

        meta["success"] = True
github MolSSI / QCFractal / qcfractal / storage_sockets / mongoengine_socket.py View on Github external
def get_managers(self, name: str=None, status: str=None, modified_before=None):

        query, error = format_query(name=name, status=status)
        if modified_before:
            query["modified_on__lt"] = modified_before

        data = QueueManagerORM.objects(**query)

        meta = get_metadata_template()
        meta["success"] = True
        meta["n_found"] = data.count()

        data = [x.to_json_obj(with_id=False) for x in data]

        return {"data": data, "meta": meta}
github MolSSI / QCFractal / qcfractal / storage_sockets / sqlalchemy_socket.py View on Github external
id : List[str], optional
            A list of ids to query
        include : Dict[str, bool], optional
            Description
        limit : int, optional
            Maximum number of results to return.
        skip : int, optional
            skip the `skip` results

        Returns
        -------
        TYPE
            Description
        """

        meta = get_metadata_template()

        query = format_query(WavefunctionStoreORM, id=id)
        rdata, meta["n_found"] = self.get_query_projection(
            WavefunctionStoreORM, query, limit=limit, skip=skip, include=include, exclude=exclude
        )

        meta["success"] = True

        return {"data": rdata, "meta": meta}
github MolSSI / QCFractal / qcfractal / storage_sockets / sqlalchemy_socket.py View on Github external
def get_add_keywords_mixed(self, data):
        """
        Get or add the given options (if they don't exit).
        KeywordsORM are given in a mixed format, either as a dict of mol data
        or as existing mol id

        TODO: to be split into get by_id and get_by_data
        """

        meta = get_metadata_template()

        ids = []
        for idx, kw in enumerate(data):
            if isinstance(kw, (int, str)):
                ids.append(kw)

            elif isinstance(kw, KeywordSet):
                new_id = self.add_keywords([kw])["data"][0]
                ids.append(new_id)
            else:
                meta["errors"].append((idx, "Data type not understood"))
                ids.append(None)

        missing = []
        ret = []
        for idx, id in enumerate(ids):
github MolSSI / QCFractal / qcfractal / storage_sockets / sqlalchemy_socket.py View on Github external
return_json : bool, optional
            Return the results as a json object
            Default is True
        with_ids : bool, optional
            Include the DB ids in the returned object (names 'id')
            Default is True


        Returns
        -------
            A dict with keys: 'data' and 'meta'
            (see get_metadata_template())
            The 'data' part is an object of the result or None if not found
        """

        meta = get_metadata_template()
        query = format_query(KeywordsORM, id=id, hash_index=hash_index)

        rdata, meta["n_found"] = self.get_query_projection(
            KeywordsORM, query, limit=limit, skip=skip, exclude=[None if with_ids else "id"]
        )

        meta["success"] = True

        # meta['error_description'] = str(err)

        if not return_json:
            data = [KeywordSet(**d) for d in rdata]
        else:
            data = rdata

        return {"data": data, "meta": meta}