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?