Пример #1
0
    def filter(self, fes):
        request = self.request

        filters = request.GET.get("filter", False)

        if not filters:
            meta_data = {
                "warnings": [
                    "_oqmd_NoFilterWarning: No filters were provided in the query. Returning all structures"
                ],
            }
            return fes, meta_data

        # shortcut to get all stable phases
        filters = filters.replace("stability=0", "stability<=0")

        filters = filters.replace("&", " AND ")
        filters = filters.replace("|", " OR ")
        filters = filters.replace("~", " NOT ")

        q, meta_info = query_to_Q(filters)
        if not q:
            return ([], meta_info)
        fes = fes.filter(q)

        return (fes, meta_info)
Пример #2
0
    def composition_filter(self, entries):
        """
        Valid url parameter inputs:
            1. ?composition=Fe2O3
            2. ?composition=Fe-O
            3. ?composition={Fe,Ni}O
            4. ?composition={3d}2O3
            5. ?composition=include_(Fe,Mn)-O : (Fe OR Mn) AND O
            6. ?composition=include_Cl,O-H : Cl OR O AND H 
            6. ?composition=include_H-{3d} : 3d elements AND H
        """
        request = self.request

        comp = request.GET.get("composition", False)
        if not comp:
            return entries

        if not "include_" in comp:
            if "{" and "}" in comp:
                c_dict_lst = parse_formula_regex(comp)
                f_lst = []
                for cd in c_dict_lst:
                    f = " ".join(
                        ["%s%g" % (k, cd[k]) for k in sorted(cd.keys())])
                    f_lst.append(f)
                entries = entries.filter(composition__formula__in=f_lst)
            else:
                c_lst = comp.strip().split("-")
                cs = Composition.get_list(c_lst)
                if len(cs) == 1:
                    c = cs[0]
                else:
                    c = cs
                entries = entries.filter(composition=c)

        else:
            comp_in = comp.replace("include_", "")
            # t = Token(comp_in)
            # q = t.evaluate()
            q = query_to_Q(comp_in)
            entries = entries.filter(q)

        # comp_ex = request.GET.get('composition_exclude', False)
        # if comp_ex:
        #    cex_lst = Composition.get(comp_ex).comp.keys()
        #    while cex_lst:
        #        tmp_ex = cex_lst.pop()
        #        entries = entries.exclude(composition__element_set=tmp_ex)

        return entries
Пример #3
0
    def filter(self, fes):
        """
        Valid attributes:
            element, generic, prototype, spacegroup,
            volume, natoms, ntypes, stability,
            delta_e, band_gap

        Requirments:
            1. Space padding is required between expression.
            2. For each epression, space is not allowed.
            3. Operators include: 'AND', 'OR'
            4. '(' and ')' can be used to change precedence
            5. For numerical attributes, we can have '>' or '<' conditions.
            Valid examples:
                'element=Mn AND band_gap>1'
                '( element=O OR element=S ) AND natoms<3'
            Invalid examples:
                'element = Fe'
                '( element=Fe And element=O)'

        Additionally, instead of multiple 'element' expressions, we can use
        'element_set' expression to combine elements in the filter.

        Format of element_set expression:
            ',': AND operator
            '-': OR operator
            '(', ')': to change precedence
            Examples:
                element_set=Al;O,H
                element_set=(Mn;Fe),O
        """
        request = self.request

        filters = request.GET.get("filter", False)

        if not filters:
            return fes

        # shortcut to get all stable phases
        filters = filters.replace("stability=0", "stability<=0")

        # replace'&' ,'|' and '~'  to 'AND', 'OR' and 'NOT', respectively
        filters = filters.replace("&", " AND ")
        filters = filters.replace("|", " OR ")
        filters = filters.replace("~", " NOT ")
        q, meta_info = query_to_Q(filters)
        if not q:
            return []
        fes = fes.filter(q)
        return fes
Пример #4
0
    def filter(self, fes):
        request = self.request

        filters = request.GET.get('filter', False)

        if not filters:
            return fes

        filters = filters.replace('&', ' AND ')
        filters = filters.replace('|', ' OR ')
        filters = filters.replace('~', ' NOT ')
        q = query_to_Q(filters)
        fes = fes.filter(q)

        return fes
Пример #5
0
    def filter(self, fes):
        request = self.request

        filters = request.GET.get('filter', False)

        if not filters:
            return fes

        # shortcut to get all stable phases
        filters = filters.replace('stability=0', 'stability<=0')

        filters = filters.replace('&', ' AND ')
        filters = filters.replace('|', ' OR ')
        filters = filters.replace('~', ' NOT ')
        q = query_to_Q(filters)
        fes = fes.filter(q)

        return fes
Пример #6
0
    def filter(self, fes):
        request = self.request

        filters = request.GET.get("filter", False)

        if not filters:
            return fes

        # shortcut to get all stable phases
        filters = filters.replace("stability=0", "stability<=0")

        filters = filters.replace("&", " AND ")
        filters = filters.replace("|", " OR ")
        filters = filters.replace("~", " NOT ")
        q = query_to_Q(filters)
        if not q:
            return []
        fes = fes.filter(q)

        return fes