Exemplo n.º 1
0
def test_forge_fetch_datasets_from_results():
    # Get some results
    f = Forge(index="mdf")
    # Record from OQMD
    res01 = f.search("mdf.source_name:oqmd AND mdf.resource_type:record",
                     advanced=True,
                     limit=1)
    # Record from OQMD with info
    res02 = f.search("mdf.source_name:oqmd AND mdf.resource_type:record",
                     advanced=True,
                     limit=1,
                     info=True)
    # Records from JANAF
    res03 = f.search(
        "mdf.source_name:khazana_vasp AND mdf.resource_type:record",
        advanced=True,
        limit=2)
    # Dataset for NIST XPS DB
    res04 = f.search(
        "mdf.source_name:nist_xps_db AND mdf.resource_type:dataset",
        advanced=True)

    # Get the correct dataset entries
    oqmd = f.search("mdf.source_name:oqmd AND mdf.resource_type:dataset",
                    advanced=True)[0]
    khazana_vasp = f.search(
        "mdf.source_name:khazana_vasp AND mdf.resource_type:dataset",
        advanced=True)[0]

    # Fetch single dataset
    res1 = f.fetch_datasets_from_results(res01[0])
    assert mdf_toolbox.insensitive_comparison(res1[0], oqmd)

    # Fetch dataset with results + info
    res2 = f.fetch_datasets_from_results(res02)
    assert mdf_toolbox.insensitive_comparison(res2[0], oqmd)

    # Fetch multiple datasets
    rtemp = res01 + res03
    res3 = f.fetch_datasets_from_results(rtemp)
    assert len(res3) == 2
    assert oqmd in res3
    assert khazana_vasp in res3

    # Fetch dataset from dataset
    res4 = f.fetch_datasets_from_results(res04)
    assert mdf_toolbox.insensitive_comparison(res4, res04)

    # Fetch entries from current query
    f.match_source_names("nist_xps_db")
    assert f.fetch_datasets_from_results() == res04

    # Fetch nothing
    unknown_entry = {"mdf": {"resource_type": "unknown"}}
    assert f.fetch_datasets_from_results(unknown_entry) == []
def test_tdb():
    tdb1_path = os.path.join(BASE_PATH, "tdb", "PbSSeTe_Na.TDB")
    tdb1_record = {
        'calphad': {
            'phases': [
                'LIQUID', 'FCC_A1', 'HALITE', 'HEXAGONAL_A8', 'ORTHORHOMBIC_S',
                'BCC_A2', 'NA2TE', 'NATE', 'NATE3', 'NA2SE', 'NASE', 'NASE2',
                'NA2S', 'NAS', 'NAS2'
            ]
        },
        'material': {
            'composition': 'SeVaTeNaSPb'
        }
    }
    tdb2_path = os.path.join(BASE_PATH, "tdb", "test_AuSi.TDB")
    tdb2_record = {
        'calphad': {
            'phases': [
                'LIQUID', 'BCC_A2', 'CBCC_A12', 'CUB_A13', 'DIAMOND_A4',
                'FCC_A1', 'HCP_A3', 'HCP_ZN'
            ]
        },
        'material': {
            'composition': 'SiVaAu'
        }
    }
    tdb3_path = os.path.join(BASE_PATH, "tdb", "test_PbTe.TDB")
    tdb3_record = {
        'calphad': {
            'phases': ['LIQUID', 'PBTE', 'HEXAGONAL_A8', 'RHOMBOHEDRAL_A7']
        },
        'material': {
            'composition': 'TeVaPb'
        }
    }

    assert mdf_toolbox.insensitive_comparison(extractors.extract_tdb(
        [tdb1_path]),
                                              tdb1_record,
                                              string_insensitive=True)
    assert mdf_toolbox.insensitive_comparison(extractors.extract_tdb(
        [tdb2_path]),
                                              tdb2_record,
                                              string_insensitive=True)
    assert mdf_toolbox.insensitive_comparison(extractors.extract_tdb(
        [tdb3_path]),
                                              tdb3_record,
                                              string_insensitive=True)
    assert extractors.extract_tdb([NO_DATA_FILE]) == {}
    assert extractors.extract_tdb([NA_PATH]) == {}
Exemplo n.º 3
0
def test_insensitive_comparison():
    # Correct results:
    # dbase == d1 always
    # dbase == d2 iff string_insensitive=True
    # dbase == d3 iff type_insensitive=True
    # dbase == d4 never (extra dict key)
    # dbase == d5 never (extra list item)
    # dbase == d6 never (float not equal)
    dbase = {
        "aaa": ["a", "zzz", 4, 5, "QQzz"],
        "ccc": "AAAABBBBCCCC",
        "bbb": 50.00000000000,
        "www": (1, 2, 9, 4, 5, "F")
    }
    d1 = {
        "bbb": 50.0,
        "aaa": ["a", 5, 4, "zzz", "QQzz"],
        "www": (2, 1, 9, 5, "F", 4),
        "ccc": "AAAABBBBCCCC"
    }
    d2 = {
        "aaa": ["a", "zzz", 4, 5, "zzqq"],
        "ccc": "aaaaBB BBCCC\tC\n",
        "bbb": 50.00000000000,
        "www": (1, 2, 9, 4, 5, "f")
    }
    d3 = {
        "aaa": ("a", "zzz", 4, 5, "QQzz"),
        "ccc": "AAAABBBBCCCC",
        "bbb": 50.00000000000,
        "www": [1, 2, 9, 4, 5, "F"]
    }
    d4 = {
        "aaa": ["a", "zzz", 4, 5, "QQzz"],
        "ccc": "AAAABBBBCCCC",
        "bbb": 50.00000000000,
        "www": (1, 2, 9, 4, 5, "F"),
        "zzz": "abc"
    }
    d5 = {
        "aaa": ["a", "zzz", 4, 5, "QQzz", "zzz"],
        "ccc": "AAAABBBBCCCC",
        "bbb": 50.00000000000,
        "www": (1, 2, 9, 4, 5, "F")
    }
    d6 = {
        "aaa": ["a", "zzz", 4, 5, "QQzz"],
        "ccc": "AAAABBBBCCCC",
        "bbb": 50.1,
        "www": (1, 2, 9, 4, 5, "F")
    }

    assert mdf_toolbox.insensitive_comparison(dbase, d1) is True
    assert mdf_toolbox.insensitive_comparison(dbase, d2) is False
    assert mdf_toolbox.insensitive_comparison(
        dbase, d2, string_insensitive=True) is True
    assert mdf_toolbox.insensitive_comparison(dbase, d3) is False
    assert mdf_toolbox.insensitive_comparison(dbase, d3,
                                              type_insensitive=True) is True
    assert mdf_toolbox.insensitive_comparison(dbase, d4) is False
    assert mdf_toolbox.insensitive_comparison(
        dbase, d4, string_insensitive=True, type_insensitive=True) is False
    assert mdf_toolbox.insensitive_comparison(dbase, d5) is False
    assert mdf_toolbox.insensitive_comparison(
        dbase, d5, string_insensitive=True, type_insensitive=True) is False
    assert mdf_toolbox.insensitive_comparison(dbase, d6) is False
    assert mdf_toolbox.insensitive_comparison(
        dbase, d6, string_insensitive=True, type_insensitive=True) is False