Trouble reading TDB files from various sources

180 views
Skip to first unread message

Sashank Shivakumar

unread,
Jun 19, 2021, 4:21:14 PM6/19/21
to pycalphad
I'm having some trouble reading TDB files from various sources (ex. PANDAT and TDB DB). For example, I just downloaded this https://doi.org/10.1016/j.calphad.2014.07.003 TDb file for CuZn: When importing into pycalphad using dbf = databases('File_name.tdb') I get the following error:

Failed while parsing: PARAMETER VA(LIQUID,CU;0) 2.981E+02 +9.7463E-05*T -2.6458E-01*T**(-1); 6.00E+03 N Tokens: None

--------------------------------------------------------------------------- ParseException Traceback (most recent call last) <ipython-input-25-cad73db0074c> in <module> ----> 1 dbc = Database('Cu_Zn.tdb') ~/opt/anaconda3/lib/python3.8/site-packages/pycalphad/io/database.py in __new__(cls, *args) 117 elif fname.find('\n') == -1: 118 # Single-line string; it's probably a filename --> 119 return cls.from_file(fname, fmt=fmt) 120 else: 121 # Newlines found: probably a full database string ~/opt/anaconda3/lib/python3.8/site-packages/pycalphad/io/database.py in from_file(fname, fmt) 211 try: 212 dbf = Database() --> 213 format_registry[fmt.lower()].read(dbf, fd) 214 finally: 215 # Close file descriptors created in this routine ~/opt/anaconda3/lib/python3.8/site-packages/pycalphad/io/tdb.py in read_tdb(dbf, fd) 959 tokens = None 960 try: --> 961 tokens = grammar.parseString(command) 962 _TDB_PROCESSOR[tokens[0]](dbf, *tokens[1:]) 963 except: ~/opt/anaconda3/lib/python3.8/site-packages/pyparsing.py in parseString(self, instring, parseAll) 1953 if getattr(exc, '__traceback__', None) is not None: 1954 exc.__traceback__ = self._trim_traceback(exc.__traceback__) -> 1955 raise exc 1956 else: 1957 return tokens ~/opt/anaconda3/lib/python3.8/site-packages/pycalphad/io/tdb.py in parseImpl(self, instring, loc, doActions) 186 except ValueError: 187 pass --> 188 raise ParseException(instring, loc, self.errmsg, self) 189 190 def _tdb_grammar(): #pylint: disable=R0914 

ParseException: Expected {{"ELEMENT" W:(ABCD...) W:(ABCD...) Re:('[-+]?([0-9]+\\.(?!([0-9]|[eE])))|([0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)') Re:('[-+]?([0-9]+\\.(?!([0-9]|[eE])))|([0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)') Re:('[-+]?([0-9]+\\.(?!([0-9]|[eE])))|([0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)') LineEnd} | {"SPECIES" W:(ABCD...) [Suppress:("%")] Group:({{W:(ABCD...) [Re:('[-+]?([0-9]+\\.(?!([0-9]|[eE])))|([0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)')]}}...) [{Suppress:("/") W:(+-01...)}] LineEnd} | {"TYPE_DEFINITION" Suppress:(<SP><TAB><CR><LF>) !W:( !) SkipTo:(LineEnd)} | {"FUNCTION" W:(ABCD...) {{Re:('[-+]?([0-9]+\\.(?!([0-9]|[eE])))|([0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)') | [","]...} {{SkipTo:(";") Suppress:(";") [Suppress:(",")]... [Re:('[-+]?([0-9]+\\.(?!([0-9]|[eE])))|([0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)')] Suppress:([W:(Yy)])}}... Suppress:([W:(Nn)])} [Suppress:(W:(ABCD...))] LineEnd} | {"ASSESSED_SYSTEMS" SkipTo:(LineEnd)} | {"DEFINE_SYSTEM_DEFAULT" SkipTo:(LineEnd)} | {"DEFAULT_COMMAND" SkipTo:(LineEnd)} | {"DATABASE_INFO" SkipTo:(LineEnd)} | {"VERSION_DATE" SkipTo:(LineEnd)} | {"REFERENCE_FILE" SkipTo:(LineEnd)} | {"ADD_REFERENCES" SkipTo:(LineEnd)} | {"LIST_OF_REFERENCES" SkipTo:(LineEnd)} | {"TEMPERATURE_LIMITS" SkipTo:(LineEnd)} | {"PHASE" W:(ABCD...) Suppress:(<SP><TAB><CR><LF>) !W:( !) Suppress:(<SP><TAB><CR><LF>) Suppress:(W:(0123...)) Group:({Re:('[-+]?([0-9]+\\.(?!([0-9]|[eE])))|([0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)')}...) Suppress:(SkipTo:(LineEnd))} | {"CONSTITUENT" W:(ABCD...) Suppress:(<SP><TAB><CR><LF>) Suppress:(":") Group:(Group:({{[Suppress:(",")] {W:(ABCD...) [Suppress:("%")]}}}...) [: Group:({{[Suppress:(",")] {W:(ABCD...) [Suppress:("%")]}}}...)]...) Suppress:(":") LineEnd} | {"PARAMETER" {"BMAGN" | "DF" | "DQ" | "G" | "GD" | "L" | "MF" | "MQ" | "NT" | "TC" | "THETA" | "V0" | "VS"} Suppress:("(") W:(ABCD...) [{Suppress:("&") W:(ABCD...)}] Suppress:(",") Group:(Group:({{[Suppress:(",")] {W:(ABCD...) [Suppress:("%")]}}}...) [: Group:({{[Suppress:(",")] {W:(ABCD...) [Suppress:("%")]}}}...)]...) [{Suppress:(";") W:(0123...)}] Suppress:(")") {{Re:('[-+]?([0-9]+\\.(?!([0-9]|[eE])))|([0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)') | [","]...} {{SkipTo:(";") Suppress:(";") [Suppress:(",")]... [Re:('[-+]?([0-9]+\\.(?!([0-9]|[eE])))|([0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)')] Suppress:([W:(Yy)])}}... Suppress:([W:(Nn)])} [Suppress:(W:(ABCD...))] LineEnd}}, found '(' (at char 13), (line:1, col:14)

When I try to run a pandat binary .tdb file I get the following:
Undefined phase LIQUID Failed while parsing: Constituent Liquid : Au, Bi : Tokens: ['CONSTITUENT', 'Liquid', [['Au', 'Bi']]]

--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-26-60cfe43c8609> in <module> ----> 1 dbc = Database('AuBi.tdb') ~/opt/anaconda3/lib/python3.8/site-packages/pycalphad/io/database.py in __new__(cls, *args) 117 elif fname.find('\n') == -1: 118 # Single-line string; it's probably a filename --> 119 return cls.from_file(fname, fmt=fmt) 120 else: 121 # Newlines found: probably a full database string ~/opt/anaconda3/lib/python3.8/site-packages/pycalphad/io/database.py in from_file(fname, fmt) 211 try: 212 dbf = Database() --> 213 format_registry[fmt.lower()].read(dbf, fd) 214 finally: 215 # Close file descriptors created in this routine ~/opt/anaconda3/lib/python3.8/site-packages/pycalphad/io/tdb.py in read_tdb(dbf, fd) 960 try: 961 tokens = grammar.parseString(command) --> 962 _TDB_PROCESSOR[tokens[0]](dbf, *tokens[1:]) 963 except: 964 print("Failed while parsing: " + command) ~/opt/anaconda3/lib/python3.8/site-packages/pycalphad/io/tdb.py in <lambda>(db, name, c) 411 'PHASE': _process_phase, 412 'CONSTITUENT': \ --> 413 lambda db, name, c: db.add_phase_constituents( 414 name.split(':')[0].upper(), c), 415 'PARAMETER': _process_parameter ~/opt/anaconda3/lib/python3.8/site-packages/pycalphad/io/database.py in add_phase_constituents(self, phase_name, constituents) 451 # Need to convert constituents from ParseResults 452 # Otherwise equality testing will be broken --> 453 self.phases[phase_name].constituents = tuple([frozenset([species_dict[s.upper()] for s in xs]) for xs in constituents]) 454 except KeyError: 455 print("Undefined phase "+phase_name) ~/opt/anaconda3/lib/python3.8/site-packages/pycalphad/io/database.py in <listcomp>(.0) 451 # Need to convert constituents from ParseResults 452 # Otherwise equality testing will be broken --> 453 self.phases[phase_name].constituents = tuple([frozenset([species_dict[s.upper()] for s in xs]) for xs in constituents]) 454 except KeyError: 455 print("Undefined phase "+phase_name) ~/opt/anaconda3/lib/python3.8/site-packages/pycalphad/io/database.py in <listcomp>(.0) 451 # Need to convert constituents from ParseResults 452 # Otherwise equality testing will be broken --> 453 self.phases[phase_name].constituents = tuple([frozenset([species_dict[s.upper()] for s in xs]) for xs in constituents]) 454 except KeyError: 455 print("Undefined phase "+phase_name)

KeyError: 'AU'


I am new to pyCALPHAD and to python in general, is there anything I'm doing wrong? how do I fix these import issues?



Brandon Bocklund

unread,
Jun 21, 2021, 1:31:01 PM6/21/21
to pycalphad
Hi Sashank,

For the Cu-Zn database you linked, the parsing failed because the VA parameter was not supported by the parser. I opened a pull request to add support for this parameter. Once the pull request is merged, the development version will be able to parse all three databases in that file's supplementary information. Note that the molar volume models are not yet implemented in pycalphad's Model, but they should be able to be implemented in a custom model in a similar way as the viscosity was modeled in this example.

For the PANDAT database you are using, I'm not certain, but I think the issue may be that some of the parsed tokens are not converted to uppercase correctly in all places. That looks like a bug and I opened an issue for that here. You can try to convert it to uppercase in the code that you are running to see if that fixes it:

Instead of:

    dbf = Database('AuBi.tdb')

try:

    with open('AuBi.tdb') as fp:
        dbf = Database(fp.read().upper())

If that doesn't work,  are able to share the database, I can take a look at it further.

Cheers,
Brandon
Reply all
Reply to author
Forward
0 new messages