本文整理汇总了Python中pycalphad.Database.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python Database.from_string方法的具体用法?Python Database.from_string怎么用?Python Database.from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycalphad.Database
的用法示例。
在下文中一共展示了Database.from_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_incompatible_db_ignores_with_kwarg_ignore
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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')
示例2: test_incompatible_db_warns_by_default
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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')
示例3: test_incompatible_db_mangles_names_with_kwarg_fix
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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
示例4: test_tdb_species_are_parsed_correctly
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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
示例5: test_database_parameter_with_species_that_is_not_a_stoichiometric_formula
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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
示例6: test_binary_magnetic_reimported
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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')
示例7: test_tdb_content_after_line_end_is_neglected
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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
示例8: test_writing_tdb_with_species_gives_same_result
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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
示例9: test_symbol_names_are_propagated_through_symbols_and_parameters
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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))
示例10: test_species_are_parsed_in_tdb_phases_and_parameters
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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
示例11: test_tdb_species_with_charge_are_parsed_correctly
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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
示例12: test_unknown_format_from_file
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
def test_unknown_format_from_file():
"from_string: Unknown import file format raises NotImplementedError."
Database.from_string(ALCRNI_TDB, fmt='_fail_')
示例13: test_unspecified_format_from_string
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
def test_unspecified_format_from_string():
"from_string: Unspecified string format raises ValueError."
Database.from_string(ALCRNI_TDB)
示例14: test_export_import
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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
示例15: test_load_from_string
# 需要导入模块: from pycalphad import Database [as 别名]
# 或者: from pycalphad.Database import from_string [as 别名]
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