The code in question is just 2 lines used to import the "COST507 database for light alloys" (downloaded from the opencalphad homepage http://www.opencalphad.com/).

from pycalphad import Database
db = Database('COST507.tdb')

This is the error it returns:

Failed while parsing:  ELEMENT Y HCP_A3 8.89059+01 5.9664E+03 4.4434E+01 
Tokens: None

ParseException                            Traceback (most recent call last)
<ipython-input-6-84bd58f009b2> in <module>
      1 from pycalphad import Database
----> 2 db = Database('COST507.tdb')

~\Anaconda3\envs\pycalphad_env\lib\site-packages\pycalphad\io\database.py in __new__(cls, *args)
    127             elif fname.find('\n') == -1:
    128                 # Single-line string; it's probably a filename
--> 129                 return cls.from_file(fname, fmt=fmt)
    130             else:
    131                 # Newlines found: probably a full database string

~\Anaconda3\envs\pycalphad_env\lib\site-packages\pycalphad\io\database.py in from_file(fname, fmt)
    221         try:
    222             dbf = Database()
--> 223             format_registry[fmt.lower()].read(dbf, fd)
    224         finally:
    225             # Close file descriptors created in this routine

~\Anaconda3\envs\pycalphad_env\lib\site-packages\pycalphad\io\tdb.py in read_tdb(dbf, fd)
    911         tokens = None
    912         try:
--> 913             tokens = _tdb_grammar().parseString(command)
    914             _TDB_PROCESSOR[tokens[0]](dbf, *tokens[1:])
    915         except ParseException:

~\Anaconda3\envs\pycalphad_env\lib\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

~\Anaconda3\envs\pycalphad_env\lib\site-packages\pyparsing.py in parseImpl(self, instring, loc, doActions)
   3782                 return loc + 1, "\n"
   3783             else:
-> 3784                 raise ParseException(instring, loc, self.errmsg, self)
   3785         elif loc == len(instring):
   3786             return loc + 1, []

ParseException: Expected {{"ELEMENT" W:(ABCD...) [Suppress:(W:(ABCD...))] [Suppress:({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:(YNyn) | <SP><TAB><CR><LF>})}}...}} | {"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]+)?)')}...) 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:(YNyn) | <SP><TAB><CR><LF>})}}...}}}, found '+'  (at char 25), (line:1, col:26)
  • 2
    $\begingroup$ From the error line, it looks the first coordinate is missing the E to indicate it is scientific notation. $\endgroup$
    – Tyberius
    May 29 at 21:03

Thanks to Tyberius for pointing out one issue in the database in their comment.

The pycalphad database parser is strict, but also tries to prevent ambiguities or mistakes.

I made the following corrections:

  • Changed ELEMENT Y HCP_A3 8.89059+01 5.9664E+03 4.4434E+01 ! to ELEMENT Y HCP_A3 8.89059E+01 5.9664E+03 4.4434E+01 (adding E to the exponent of the mass)
  • Changed the parameter PARAMETER L(B4M3,B:HF,TI;0) 298.15 !.0E-4; 6000.00 N ! to PARAMETER L(B4M3,B:HF,TI;0) 298.15 1.0E-4; 6000.00 N ! (assuming that !.0E-4 should be 1.0E-4).
  • Commented out the following type definition because it is not yet supported by pycalphad (it will not affect correctness) TYPE_DEF R IF(AL AND FE) THEN TDB RESTORE_PH AL5FE4 !
  • Fixed several incorrectly formatted reference keys, REF: 0 and REF: 3, (spaces are not allowed in reference keys)

You can find a corrected version that works with pycalphad here. I'm not sure if there's a better way to share this relatively large file in a more permanent and StackExchange-approved way.

  • $\begingroup$ +1 I was considering to inform you that another CALPHAD question was asked but you didn't need that after all :) Have you subscribed to the CALPHAD mailing list here: mattermodeling.meta.stackexchange.com/a/60/5 ? $\endgroup$ May 30 at 2:09
  • 1
    $\begingroup$ For completeness, you can add the correction from my comment to the answer. Its probably better to have all the info collected in the answer in case the comment is ever removed. $\endgroup$
    – Tyberius
    May 30 at 13:19
  • 1
    $\begingroup$ @ NikeDattani: I had it in my "Watched" tags, but didn't know about the email feature, thanks! @Tyberius: good suggestion - updated. $\endgroup$ May 30 at 16:47
  • $\begingroup$ Thanks for going above and beyond on this one! $\endgroup$
    – sgp45
    May 30 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.