示例#1
0
def test_ordering():
    """Tests a live query with ordering."""
    from aflow import search, K

    result = (search(batch_size=20).select(
        K.agl_thermal_conductivity_300K).filter(K.Egap > 6).orderby(
            K.agl_thermal_conductivity_300K, True))
    assert len(result[80].aurl) > 0

    orderby_exclude_result = (search(batch_size=20).select(
        K.agl_thermal_conductivity_300K).filter(K.Egap > 6).orderby(
            K.auid).exclude(K.auid))

    assert orderby_exclude_result.matchbook().startswith("$auid")
示例#2
0
def test_ordering():
    """Tests a live query with ordering.
    """
    import aflow
    import aflow.keywords as kw
    result = aflow.search(batch_size=20
        ).select(kw.agl_thermal_conductivity_300K
        ).filter(kw.Egap > 6).orderby(kw.agl_thermal_conductivity_300K, True)
    assert len(result[80].aurl) > 0

    orderby_exclude_result = aflow.search(batch_size=20
        ).select(kw.agl_thermal_conductivity_300K
        ).filter(kw.Egap > 6).orderby(kw.auid).exclude(kw.auid)

    assert orderby_exclude_result.matchbook().startswith('$auid')
示例#3
0
def test_empty_query_result():
    import aflow
    import aflow.keywords as kw
    # Check for auids that end with "aflow", which none do
    result = aflow.search(catalog='icsd', batch_size=20
                          ).filter(kw.auid < "aflow")
    assert result.N == 0
示例#4
0
def paper():
    """Returns a search query that mimics the one shown in the paper
    for electrically-insulating heat sinks.
    """
    from aflow import search, K

    result = (search(batch_size=20).select(
        K.agl_thermal_conductivity_300K).filter(K.Egap >= 6).orderby(
            K.agl_thermal_conductivity_300K, True))

    # Let's pre-fill the responses from the saved JSON files so that the tests
    # run faster *and* so that the results are predictable.
    import json

    result._N = 912

    n = -1
    with open(curdir / "data0.json") as f:
        response = json.loads(f.read())
        result.responses[n] = response
    n = -2
    with open(curdir / "data1.json") as f:
        response = json.loads(f.read())
        result.responses[n] = response

    return result[0:40]
示例#5
0
def test_ordering():
    """Tests a live query with ordering.
    """
    import aflow
    import aflow.keywords as kw
    result = aflow.search(batch_size=20).select(
        kw.agl_thermal_conductivity_300K).filter(kw.Egap > 6).orderby(
            kw.agl_thermal_conductivity_300K, True)
    assert len(result[80].aurl) > 0
示例#6
0
    def _build_query(self):
        """Constructs the :class:`aflow.control.Query` object for requesting
        data from the server.
        """
        result = aflow.search(self.catalog, self.batch_size)
        for f in self.filters:
            result = result.filter(f)
        result = result.select(*self.select).exclude(*self.exclude)
        if self.orderby:
            result = result.orderby(self.orderby, self.reverse)

        if self.nconfigs:
            return result[0:self.nconfigs]
        else:
            return result
示例#7
0
def test_Si():
    """Tests a query for silicon prototypes from ICSD.
    """
    import aflow
    from aflow import K
    Si = aflow.search(catalog="icsd").filter(K.species == 'Si').select(
        K.positions_cartesian).exclude(K.Egap)

    #We purposefully request across a paging boundary to make sure
    #there is continuity.
    for i, entry in enumerate(Si[90:110]):
        assert "ICSD" in entry.aurl

    #Now, get a single item in a set that we haven't queried yet.
    assert "ICSD" in Si[220].aurl

    #Make sure that the finalization actually works.
    N = len(Si.filters)
    assert Si.filter(K.Egap > 3) is Si
    assert len(Si.filters) == N
示例#8
0
def paper():
    """Returns a search query that mimics the one shown in the paper
    for electrically-insulating heat sinks.
    """
    import aflow
    import aflow.keywords as kw
    result = aflow.search(batch_size=20).select(
        kw.agl_thermal_conductivity_300K).filter(kw.Egap > 6).orderby(
            kw.agl_thermal_conductivity_300K, True)

    #Let's pre-fill the responses from the saved JSON files so that the tests
    #run faster *and* so that the results are predictable.
    import json
    result._N = 912

    n = -1
    with open("tests/files/aflow/data.json") as f:
        response = json.loads(f.read())
        result.responses[n] = response

    return result[0:20]
示例#9
0
# http://aflowlib.org/

from aflow import K, search

result = search().filter((K.species == "Al") & (K.species == "O")).select(
    K.compound, K.Egap)

print('Number of results found:', len(result), '\n')

print("%-20s %-20s" % ('Compound', 'Band Gap (eV)'), '\n')

for entry in result:
    print("%-20s %-20s" % (entry.compound, entry.Egap))
def get_initial_aflow_results(nspecies=2, enthalpy_formation_atom=-0.1):
    result = search(batch_size=10000).filter((K.nspecies == nspecies) & (
        K.enthalpy_formation_atom < enthalpy_formation_atom)).select(
            K.species, K.stoich, K.compound, K.auid)
    return list(tqdm.tqdm(result))
示例#11
0
def test_empty_query_result():
    from aflow import search, K

    # Check for auids that end with "aflow", which none do
    result = search(catalog="ICSD", batch_size=20).filter(K.auid < "aflow")
    assert result.N == 0