• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pycalphad.Database类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pycalphad.Database的典型用法代码示例。如果您正苦于以下问题:Python Database类的具体用法?Python Database怎么用?Python Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Database类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_incompatible_db_ignores_with_kwarg_ignore

def test_incompatible_db_ignores_with_kwarg_ignore():
    "Symbol names too long for Thermo-Calc are ignored the database written as given."
    test_dbf = Database.from_string(INVALID_TDB_STR, fmt='tdb')
    with warnings.catch_warnings(record=True) as w:
        invalid_dbf = test_dbf.to_string(fmt='tdb', if_incompatible='ignore')
        not_expected_string_fragment = 'Ignoring that the following function names are beyond the 8 character TDB limit'
        assert all([not_expected_string_fragment not in str(warning.message) for warning in w])
    assert test_dbf == Database.from_string(invalid_dbf, fmt='tdb')
开发者ID:jeffwdoak,项目名称:pycalphad,代码行数:8,代码来源:test_database.py


示例2: test_to_file_overwrites_with_if_exists_argument

def test_to_file_overwrites_with_if_exists_argument():
    "Database.to_file should overwrite if 'overwrite' is passed to if_exists"
    fname = 'testwritedb.tdb'
    test_dbf = Database(ALNIPT_TDB)
    test_dbf.to_file(fname)  # establish the initial file
    inital_modification_time = os.path.getmtime(fname)
    test_dbf.to_file(fname, if_exists='overwrite')  # test if_exists behavior
    overwrite_modification_time = os.path.getmtime(fname)
    assert overwrite_modification_time > inital_modification_time
开发者ID:jeffwdoak,项目名称:pycalphad,代码行数:9,代码来源:test_database.py


示例3: test_incompatible_db_warns_by_default

def test_incompatible_db_warns_by_default():
    "Symbol names too long for Thermo-Calc warn and write the database as given by default."
    test_dbf = Database.from_string(INVALID_TDB_STR, fmt='tdb')
    with warnings.catch_warnings(record=True) as w:
        invalid_dbf = test_dbf.to_string(fmt='tdb')
        assert len(w) >= 1
        expected_string_fragment = 'Ignoring that the following function names are beyond the 8 character TDB limit'
        assert any([expected_string_fragment in str(warning.message) for warning in w])
    assert test_dbf == Database.from_string(invalid_dbf, fmt='tdb')
开发者ID:jeffwdoak,项目名称:pycalphad,代码行数:9,代码来源:test_database.py


示例4: test_incompatible_db_mangles_names_with_kwarg_fix

def test_incompatible_db_mangles_names_with_kwarg_fix():
    "Symbol names too long for Thermo-Calc are mangled and replaced in symbol names, symbol expressions, and parameter expressions."
    test_dbf = Database.from_string(INVALID_TDB_STR, fmt='tdb')
    test_dbf_copy = deepcopy(test_dbf)
    mangled_dbf = Database.from_string(test_dbf.to_string(fmt='tdb', if_incompatible='fix'), fmt='tdb')
    # check that the long function name was hashed correctly
    a_very_long_function_name_hash_symbol = 'F' + str(hashlib.md5('A_VERY_LONG_FUNCTION_NAME'.encode('UTF-8')).hexdigest()).upper()[:7]
    assert a_very_long_function_name_hash_symbol in mangled_dbf.symbols.keys()
    assert 'COMPAT' in mangled_dbf.symbols.keys() # test that compatible keys are not removed
    assert test_dbf_copy == test_dbf # make sure test_dbf has not mutated
    assert test_dbf != mangled_dbf # also make sure test_dbf has not mutated
开发者ID:jeffwdoak,项目名称:pycalphad,代码行数:11,代码来源:test_database.py


示例5: test_tdb_species_are_parsed_correctly

def test_tdb_species_are_parsed_correctly():
    """The TDB speciescommand should be properly parsed."""
    tdb_species_str = """
ELEMENT /-   ELECTRON_GAS              0.0000E+00  0.0000E+00  0.0000E+00!
ELEMENT VA   VACUUM                    0.0000E+00  0.0000E+00  0.0000E+00!
ELEMENT AL   FCC_A1                    2.6982E+01  4.5773E+03  2.8321E+01!
ELEMENT O    1/2_MOLE_O2(G)            1.5999E+01  4.3410E+03  1.0252E+02!

SPECIES AL+3                        AL1/+3!
SPECIES O-2                         O1/-2!
SPECIES O1                          O!
SPECIES O2                          O2!
SPECIES O3                          O3!
SPECIES AL1O1                       AL1O1!
SPECIES AL1O2                       AL1O2!
SPECIES AL2                         AL2!
SPECIES AL2O                        AL2O1!
SPECIES AL2O1                       AL2O1!
SPECIES AL2O2                       AL2O2!
SPECIES AL2O3                       AL2O3!
SPECIES ALO                         AL1O1!
SPECIES ALO2                        AL1O2!
SPECIES ALO3/2                      AL1O1.5!
    """
    test_dbf = Database.from_string(tdb_species_str, fmt='tdb')
    assert len(test_dbf.species) == 19
    species_dict = {sp.name: sp for sp in test_dbf.species}
    assert species_dict['AL'].charge == 0
    assert species_dict['O2'].constituents['O'] == 2
    assert species_dict['O1'].constituents['O'] == 1
    assert species_dict['AL1O2'].constituents['AL'] == 1
    assert species_dict['AL1O2'].constituents['O'] == 2
    assert species_dict['ALO3/2'].constituents['O'] == 1.5
开发者ID:jeffwdoak,项目名称:pycalphad,代码行数:33,代码来源:test_database.py


示例6: test_binary_magnetic_reimported

def test_binary_magnetic_reimported():
    "Export and re-import a TDB before the calculation."
    dbf_imported = Database.from_string(DBF.to_string(fmt='tdb'), fmt='tdb')
    check_energy(Model(dbf_imported, ['CR', 'NI'], 'L12_FCC'),
                {v.T: 500, v.SiteFraction('L12_FCC', 0, 'CR'): 0.33,
                v.SiteFraction('L12_FCC', 0, 'NI'): 0.67,
                v.SiteFraction('L12_FCC', 1, 'CR'): 0.33,
                v.SiteFraction('L12_FCC', 1, 'NI'): 0.67},
                -1.68840e4, mode='sympy')
开发者ID:pycalphad,项目名称:pycalphad,代码行数:9,代码来源:test_energy.py


示例7: test_database_parameter_with_species_that_is_not_a_stoichiometric_formula

def test_database_parameter_with_species_that_is_not_a_stoichiometric_formula():
    """Species names used in parameters do not have to be stoichiometric formulas"""

    # names are taken from the Thermo-Calc documentation set, Database Manager Guide, SPECIES

    tdb_string = """
     ELEMENT /-   ELECTRON_GAS              0.0000E+00  0.0000E+00  0.0000E+00!
     ELEMENT VA   VACUUM                    0.0000E+00  0.0000E+00  0.0000E+00!
     ELEMENT O    1/2_MOLE_O2(G)            0.0000E+00  0.0000E+00  0.0000E+00!
     ELEMENT SI   HCP_A3                    0.0000E+00  0.0000E+00  0.0000E+00!
     ELEMENT NA   HCP_A3                    0.0000E+00  0.0000E+00  0.0000E+00!
     ELEMENT SB   RHOMBOHEDRAL_A7           0.0000E+00  0.0000E+00  0.0000E+00!
     ELEMENT H    1/2_MOLE_H2(G)            0.0000E+00  0.0000E+00  0.0000E+00!

     SPECIES SILICA                      SI1O2 !  $ tests for arbitrary names
     SPECIES NASB_6OH                    NA1SB1O6H6 !  $ tests for underscores
     SPECIES SB-3                        SB/-3 !  $ tests for charge
     SPECIES ALCL2OH.3WATER                        AL1O1H1CL2H6O3 !  $ tests for charge


     PHASE LIQUID:L %  1  1.0  !

     CONSTITUENT LIQUID:L : O, SI, NA, SB, H, SILICA, NASB_6OH, SB-3, ALCL2OH.3WATER  :  !
     PARAMETER G(LIQUID,SILICA;0)      298.15  10;      3000 N !
     PARAMETER G(LIQUID,NASB_6OH;0)    298.15  100;      3000 N !
     PARAMETER G(LIQUID,ALCL2OH.3WATER;0)    298.15  1000;      3000 N !
     PARAMETER G(LIQUID,SB-3;0)        298.15  10000;      3000 N !

     """

    dbf = Database.from_string(tdb_string, fmt='tdb')

    species_dict = {sp.name: sp for sp in dbf.species}
    species_names = list(species_dict.keys())

    # check that the species are found
    assert 'SILICA' in species_names
    assert 'NASB_6OH' in species_names
    assert 'ALCL2OH.3WATER' in species_names
    assert 'SB-3' in species_names

    import tinydb
    silica = dbf._parameters.search(tinydb.where('constituent_array') == ((species_dict['SILICA'],),))
    assert len(silica) == 1
    assert silica[0]['parameter'].args[0][0] == 10

    nasb_6oh = dbf._parameters.search(tinydb.where('constituent_array') == ((species_dict['NASB_6OH'],),))
    assert len(nasb_6oh) == 1
    assert nasb_6oh[0]['parameter'].args[0][0] == 100

    alcl2oh_3water = dbf._parameters.search(tinydb.where('constituent_array') == ((species_dict['ALCL2OH.3WATER'],),))
    assert len(alcl2oh_3water) == 1
    assert alcl2oh_3water[0]['parameter'].args[0][0] == 1000

    sbminus3 = dbf._parameters.search(tinydb.where('constituent_array') == ((species_dict['SB-3'],),))
    assert len(sbminus3) == 1
    assert sbminus3[0]['parameter'].args[0][0] == 10000
开发者ID:jeffwdoak,项目名称:pycalphad,代码行数:57,代码来源:test_database.py


示例8: test_tdb_content_after_line_end_is_neglected

def test_tdb_content_after_line_end_is_neglected():
    """Any characters after the line ending '!' are neglected as in commercial software."""
    tdb_line_ending_str = """$ Characters after line endings should be discarded.
    PARAMETER G(PH,A;0) 298.15 +42; 6000 N ! SHOULD_NOT_RAISE_ERROR
    $ G(PH,C;0) should not parse
    PARAMETER G(PH,B;0) 298.15 +9001; 6000 N ! PARAMETER G(PH,C;0) 298.15 +2; 600 N !
    PARAMETER G(PH,D;0) 298.15 -42; 6000 N !
    """
    test_dbf = Database.from_string(tdb_line_ending_str, fmt='tdb')
    assert len(test_dbf._parameters) == 3
开发者ID:jeffwdoak,项目名称:pycalphad,代码行数:10,代码来源:test_database.py


示例9: test_writing_tdb_with_species_gives_same_result

def test_writing_tdb_with_species_gives_same_result():
    """Species defined in the tdb should be written back to the TDB correctly"""
    tdb_species_str = """
ELEMENT /-   ELECTRON_GAS              0.0000E+00  0.0000E+00  0.0000E+00!
ELEMENT VA   VACUUM                    0.0000E+00  0.0000E+00  0.0000E+00!
ELEMENT AL   FCC_A1                    2.6982E+01  4.5773E+03  2.8321E+01!
ELEMENT O    1/2_MOLE_O2(G)            1.5999E+01  4.3410E+03  1.0252E+02!

SPECIES AL+3                        AL1/+3!
SPECIES O-2                         O1/-2!
SPECIES O2                          O2!
SPECIES AL2                         AL2!
    """
    test_dbf = Database.from_string(tdb_species_str, fmt='tdb')
    written_tdb_str = test_dbf.to_string(fmt='tdb')
    test_dbf_reread = Database.from_string(written_tdb_str, fmt='tdb')
    assert len(test_dbf_reread.species) == 8
    species_dict = {sp.name: sp for sp in test_dbf_reread.species}
    assert species_dict['AL'].charge == 0
    assert species_dict['AL+3'].charge == 3
    assert species_dict['O-2'].charge == -2
开发者ID:jeffwdoak,项目名称:pycalphad,代码行数:21,代码来源:test_database.py


示例10: run_test

def run_test():
    dbf = Database()
    dbf.elements = frozenset(['A'])
    dbf.add_phase('TEST', {}, [1])
    dbf.add_phase_constituents('TEST', [['A']])
    # add THETA parameters here
    dbf.add_parameter('THETA', 'TEST', [['A']], 0, 334.)
    conds = {v.T: np.arange(1.,800.,1), v.P: 101325}
    res = calculate(dbf, ['A'], 'TEST', T=conds[v.T], P=conds[v.P],
                    model=EinsteinModel, output='testprop')
    #res_TE = calculate(dbf, ['A'], 'TEST', T=conds[v.T], P=conds[v.P],
    #                model=EinsteinModel, output='einstein_temperature')
    import matplotlib.pyplot as plt
    plt.scatter(res['T'], res['testprop'])
    plt.xlabel('Temperature (K)')
    plt.ylabel('Molar Heat Capacity (J/mol-K)')
    plt.savefig('einstein.png')
    print(dbf.to_string(fmt='tdb'))
开发者ID:richardotis,项目名称:pycalphad-sandbox,代码行数:18,代码来源:sedimodel.py


示例11: test_symbol_names_are_propagated_through_symbols_and_parameters

def test_symbol_names_are_propagated_through_symbols_and_parameters():
    """A map of old symbol names to new symbol names should propagate through symbol and parameter SymPy expressions"""
    tdb_propagate_str = """$ Mangled function names should propagate through other symbols and parameters
    ELEMENT A PH 0 0 0 !
    FUNCTION FN1  298.15 -42; 6000 N !
    FUNCTION FN2 298.15 FN1#; 6000 N !
    PARAMETER G(PH,A;0) 298.15 FN1# + FN2#; 6000 N !
    """
    test_dbf = Database.from_string(tdb_propagate_str, fmt='tdb')
    rename_map = {'FN1': 'RENAMED_FN1', 'FN2': 'RENAMED_FN2'}
    _apply_new_symbol_names(test_dbf, rename_map)
    assert 'RENAMED_FN1' in test_dbf.symbols
    assert 'FN1' not in test_dbf.symbols # check that the old key was removed
    assert test_dbf.symbols['RENAMED_FN2'] == Piecewise((Symbol('RENAMED_FN1'), And(v.T < 6000.0, v.T >= 298.15)), (0, True))
    assert test_dbf._parameters.all()[0]['parameter'] == Piecewise((Symbol('RENAMED_FN1')+Symbol('RENAMED_FN2'), And(v.T < 6000.0, v.T >= 298.15)), (0, True))
开发者ID:jeffwdoak,项目名称:pycalphad,代码行数:15,代码来源:test_database.py


示例12: run_test

def run_test():
    dbf = Database()
    dbf.elements = frozenset(["A"])
    dbf.add_phase("TEST", {}, [1])
    dbf.add_phase_constituents("TEST", [["A"]])
    # add THETA parameters here
    dbf.add_parameter("THETA", "TEST", [["A"]], 0, 334.0)
    conds = {v.T: np.arange(1.0, 800.0, 1), v.P: 101325}
    res = calculate(dbf, ["A"], "TEST", T=conds[v.T], P=conds[v.P], model=EinsteinModel, output="testprop")
    # res_TE = calculate(dbf, ['A'], 'TEST', T=conds[v.T], P=conds[v.P],
    #                model=EinsteinModel, output='einstein_temperature')
    import matplotlib.pyplot as plt

    plt.scatter(res["T"], res["testprop"])
    plt.xlabel("Temperature (K)")
    plt.ylabel("Molar Heat Capacity (J/mol-K)")
    plt.savefig("einstein.png")
开发者ID:tkphd,项目名称:pycalphad,代码行数:17,代码来源:sedimodel.py


示例13: test_species_are_parsed_in_tdb_phases_and_parameters

def test_species_are_parsed_in_tdb_phases_and_parameters():
    """Species defined in the tdb phases and parameters should be parsed."""
    tdb_str = """
ELEMENT /-   ELECTRON_GAS              0.0000E+00  0.0000E+00  0.0000E+00!
ELEMENT VA   VACUUM                    0.0000E+00  0.0000E+00  0.0000E+00!
ELEMENT AL   FCC_A1                    2.6982E+01  4.5773E+03  2.8321E+01!
ELEMENT O    1/2_MOLE_O2(G)            1.5999E+01  4.3410E+03  1.0252E+02!

SPECIES AL+3                        AL1/+3!
SPECIES O-2                         O1/-2!
SPECIES O2                          O2!
SPECIES AL2                         AL2!


 PHASE TEST_PH % 1 1 !
 CONSTITUENT TEST_PH :AL,AL2,O-2: !
 PARA G(TEST_PH,AL;0) 298.15          +10; 6000 N !
 PARA G(TEST_PH,AL2;0) 298.15          +100; 6000 N !
 PARA G(TEST_PH,O-2;0) 298.15          +1000; 6000 N !

 PHASE T2SL % 2 1 1 !
  CONSTITUENT T2SL :AL+3:O-2: !
  PARA L(T2SL,AL+3:O-2;0) 298.15 +2; 6000 N !
    """
    from tinydb import where
    test_dbf = Database.from_string(tdb_str, fmt='tdb')
    written_tdb_str = test_dbf.to_string(fmt='tdb')
    test_dbf_reread = Database.from_string(written_tdb_str, fmt='tdb')
    assert set(test_dbf_reread.phases.keys()) == {'TEST_PH', 'T2SL'}
    assert test_dbf_reread.phases['TEST_PH'].constituents[0] == {Species('AL'), Species('AL2'), Species('O-2')}
    assert len(test_dbf_reread._parameters.search(where('constituent_array') == ((Species('AL'),),))) == 1
    assert len(test_dbf_reread._parameters.search(where('constituent_array') == ((Species('AL2'),),))) == 1
    assert len(test_dbf_reread._parameters.search(where('constituent_array') == ((Species('O-2'),),))) == 1

    assert test_dbf_reread.phases['T2SL'].constituents == ({Species('AL+3')}, {Species('O-2')})
    assert len(test_dbf_reread._parameters.search(where('constituent_array') == ((Species('AL+3'),),(Species('O-2'),)))) == 1
开发者ID:jeffwdoak,项目名称:pycalphad,代码行数:36,代码来源:test_database.py


示例14: test_tdb_species_with_charge_are_parsed_correctly

def test_tdb_species_with_charge_are_parsed_correctly():
    """The TDB species that have a charge should be properly parsed."""
    tdb_species_str = """
ELEMENT /-   ELECTRON_GAS              0.0000E+00  0.0000E+00  0.0000E+00!
ELEMENT VA   VACUUM                    0.0000E+00  0.0000E+00  0.0000E+00!
ELEMENT AL   FCC_A1                    2.6982E+01  4.5773E+03  2.8321E+01!
ELEMENT O    1/2_MOLE_O2(G)            1.5999E+01  4.3410E+03  1.0252E+02!

SPECIES AL+3                        AL1/+3!
SPECIES O-2                         O1/-2!
SPECIES O2                          O2!
SPECIES AL2                         AL2!
    """
    test_dbf = Database.from_string(tdb_species_str, fmt='tdb')
    assert len(test_dbf.species) == 8
    species_dict = {sp.name: sp for sp in test_dbf.species}
    assert species_dict['AL'].charge == 0
    assert species_dict['AL+3'].charge == 3
    assert species_dict['O-2'].charge == -2
开发者ID:jeffwdoak,项目名称:pycalphad,代码行数:19,代码来源:test_database.py


示例15: test_unknown_format_from_file

def test_unknown_format_from_file():
    "from_string: Unknown import file format raises NotImplementedError."
    Database.from_string(ALCRNI_TDB, fmt='_fail_')
开发者ID:mahendra-r,项目名称:pycalphad,代码行数:3,代码来源:test_database.py


示例16: test_unspecified_format_from_file

def test_unspecified_format_from_file():
    "from_file: Unspecified format for file descriptor raises ValueError."
    Database.from_file(StringIO(ALCRNI_TDB))
开发者ID:mahendra-r,项目名称:pycalphad,代码行数:3,代码来源:test_database.py


示例17: test_load_from_stringio

def test_load_from_stringio():
    "Test database loading from a file-like object."
    test_tdb = Database.from_file(StringIO(ALCRNI_TDB), fmt='tdb')
    assert test_tdb == REFERENCE_DBF
开发者ID:mahendra-r,项目名称:pycalphad,代码行数:4,代码来源:test_database.py


示例18: test_unspecified_format_from_string

def test_unspecified_format_from_string():
    "from_string: Unspecified string format raises ValueError."
    Database.from_string(ALCRNI_TDB)
开发者ID:mahendra-r,项目名称:pycalphad,代码行数:3,代码来源:test_database.py


示例19: test_export_import

def test_export_import():
    "Equivalence of re-imported database to original."
    test_dbf = Database(ALNIPT_TDB)
    assert Database.from_string(test_dbf.to_string(fmt='tdb'), fmt='tdb') == test_dbf
开发者ID:mahendra-r,项目名称:pycalphad,代码行数:4,代码来源:test_database.py


示例20: test_load_from_string

def test_load_from_string():
    "Test database loading from a string."
    test_model = Model(Database.from_string(ALCRNI_TDB, fmt='tdb'), ['CR', 'NI'], 'L12_FCC')
    assert test_model == REFERENCE_MOD
开发者ID:mahendra-r,项目名称:pycalphad,代码行数:4,代码来源:test_database.py



注:本文中的pycalphad.Database类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python log.warn函数代码示例发布时间:2022-05-25
下一篇:
Python pycalphad.equilibrium函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap