pycalphad.io package

Submodules

pycalphad.io.database module

The database module provides support for reading and writing data types associated with structured thermodynamic/kinetic data.

class pycalphad.io.database.Database[source]

Bases: object

Structured thermodynamic and/or kinetic data.

elements : list
List of elements in database.
species : list
List of species in database.
phases : dict
Phase objects indexed by their system-local name.
symbols : dict
SymPy objects indexed by their name (FUNCTIONs in Thermo-Calc).
references : dict
Reference objects indexed by their system-local identifier.
>>> mydb = Database(open('crfeni_mie.tdb'))
>>> mydb = Database('crfeni_mie.tdb')
>>> f = StringIO(u'$a complete TDB file as a string
‘)
>>> mydb = Database(f)
add_parameter(param_type, phase_name, constituent_array, param_order, param, ref=None, diffusing_species=None)[source]

Add a parameter.

Parameters:
  • param_type (str) – Type name of the parameter, e.g., G, L, BMAGN.
  • phase_name (str) – Name of the phase.
  • constituent_array (list) – Configuration of the sublattices (elements and/or species).
  • param_order (int) – Polynomial order of the parameter.
  • param (object) – Abstract representation of the parameter, e.g., in SymPy format.
  • ref (str, optional) – Reference for the parameter.
  • diffusing_species (str, optional) – (If kinetic parameter) Diffusing species for this parameter.

Examples

None yet.

add_phase(phase_name, model_hints, sublattices)[source]

Add a phase.

Parameters:
  • phase_name (string) – System-local name of the phase.
  • model_hints (list) – Structured “hints” for a Model trying to read this phase. Hints for major constituents and typedefs (Thermo-Calc) go here.
  • sublattices (list) – Site ratios of sublattices.

Examples

None yet.

add_phase_constituents(phase_name, constituents)[source]

Add a phase.

Parameters:
  • phase_name (string) – System-local name of the phase.
  • constituents (list) – Possible phase constituents (elements and/or species).

Examples

None yet.

add_structure_entry(local_name, global_name)[source]

Define a relation between the system-local name of a phase and a “global” identifier. This is used to link crystallographically similar phases known by different colloquial names.

Parameters:
  • local_name (string) – System-local name of the phase.
  • global_name (object) – Abstract representation of symbol, e.g., in SymPy format.

Examples

None yet.

static from_file(fname, fmt=None)[source]

Create a Database from a file.

Parameters:
  • fname (str or file-like) – File name/descriptor to read.
  • fmt (str, optional) – File format. If not specified, an attempt at auto-detection is made.
Returns:

dbf – Database from file.

Return type:

Database

Examples

None yet.

classmethod from_string(data, **kwargs)[source]

Returns Database from a string in the specified format. This function is a wrapper for calling from_file with StringIO.

Parameters:
  • data (str) – Raw database string in the specified format.
  • kwargs (optional) – See keyword arguments for from_file.
Returns:

dbf

Return type:

Database

static register_format(fmt, read=None, write=None)[source]

Add support for reading and/or writing the specified format.

Parameters:
  • fmt (str) – Format.
  • read (callable, optional) – Read function with arguments (Database, file_descriptor)
  • write (callable, optional) – Write function with arguments (Database, file_descriptor)

Examples

None yet.

search(query)[source]

Search for parameters matching the specified query.

Parameters:query (object) – Structured database query in TinyDB format.

Examples

>>>> from tinydb import where >>>> db = Database() >>>> eid = db.add_parameter(…) #TODO >>>> db.search(where(‘eid’) == eid)

to_file(fname, fmt=None, if_exists='raise', **write_kwargs)[source]

Write the Database to a file.

Parameters:
  • fname (str or file-like) – File name/descriptor to write.
  • fmt (str, optional) – File format. If not specified, an attempt at auto-detection is made.
  • if_exists (string, optional ['raise', 'rename', 'overwrite']) – Strategy if ‘fname’ already exists. The ‘raise’ option (default) will raise a FileExistsError. The ‘rename’ option will append the date/time to the filename. The ‘overwrite’ option will overwrite the file. This argument is ignored if ‘fname’ is file-like.
  • write_kwargs (optional) – Keyword arguments to pass to write function.

Examples

None yet.

to_string(**kwargs)[source]

Returns Database as a string. This function is a wrapper for calling to_file with StringIO.

Parameters:kwargs (optional) – See keyword arguments for to_file.
Returns:result
Return type:str
exception pycalphad.io.database.DatabaseExportError[source]

Bases: Exception

Raised when a database cannot be written.

class pycalphad.io.database.DatabaseFormat(read, write)

Bases: tuple

read

Alias for field number 0

write

Alias for field number 1

class pycalphad.io.database.Phase[source]

Bases: object

Phase in the database.

name

System-local name of the phase.

Type:string
constituents

Possible sublattice constituents (elements and/or species).

Type:tuple of frozenset
sublattices

Site ratios of sublattices.

Type:list
model_hints

Structured “hints” for a Model trying to read this phase. Hints for major constituents and typedefs (Thermo-Calc) go here.

Type:dict

pycalphad.io.grammar module

“Common pyparsing grammar patterns.

pycalphad.io.tdb module

The tdb module provides support for reading and writing databases in Thermo-Calc TDB format.

class pycalphad.io.tdb.TCCommand(matchString, identChars=None)[source]

Bases: pyparsing.CaselessKeyword

Parser element for dealing with Thermo-Calc command abbreviations.

parseImpl(instring, loc, doActions=True)[source]
class pycalphad.io.tdb.TCPrinter(settings=None)[source]

Bases: sympy.printing.str.StrPrinter

Prints Thermo-Calc style function expressions.

blacklisted(expr)[source]
pycalphad.io.tdb.read_tdb(dbf, fd)[source]

Parse a TDB file into a pycalphad Database object.

Parameters:
  • dbf (Database) – A pycalphad Database.
  • fd (file-like) – File descriptor.
pycalphad.io.tdb.reflow_text(text, linewidth=80)[source]

Add line breaks to ensure text doesn’t exceed a certain line width.

Parameters:
  • text (str) –
  • linewidth (int, optional) –
Returns:

reflowed_text

Return type:

str

pycalphad.io.tdb.to_interval(relational)[source]
pycalphad.io.tdb.write_tdb(dbf, fd, groupby='subsystem', if_incompatible='warn')[source]

Write a TDB file from a pycalphad Database object.

The goal is to produce TDBs that conform to the most restrictive subset of database specifications. Some of these can be adjusted for automatically, such as the Thermo-Calc line length limit of 78. Others require changing the database in non-trivial ways, such as the maximum length of function names (8). The default is to warn the user when attempting to write an incompatible database and the user must choose whether to warn and write the file anyway or to fix the incompatibility.

Currently the supported compatibility fixes are: - Line length <= 78 characters (Thermo-Calc) - Function names <= 8 characters (Thermo-Calc)

The current unsupported fixes include: - Keyword length <= 2000 characters (Thermo-Calc) - Element names <= 2 characters (Thermo-Calc) - Phase names <= 24 characters (Thermo-Calc)

Other TDB compatibility issues required by Thermo-Calc or other software should be reported to the issue tracker.

Parameters:
  • dbf (Database) – A pycalphad Database.
  • fd (file-like) – File descriptor.
  • groupby (['subsystem', 'phase'], optional) – Desired grouping of parameters in the file.
  • if_incompatible (string, optional ['raise', 'warn', 'fix']) – Strategy if the database does not conform to the most restrictive database specification. The ‘warn’ option (default) will write out the incompatible database with a warning. The ‘raise’ option will raise a DatabaseExportError. The ‘ignore’ option will write out the incompatible database silently. The ‘fix’ option will rectify the incompatibilities e.g. through name mangling.

pycalphad.io.tdb_keywords module

This module defines valid Thermo-Calc TDB keywords and handles abbreviations. Note that not all of these keywords are fully supported yet.

pycalphad.io.tdb_keywords.expand_keyword(possible, candidate)[source]

Expand an abbreviated keyword based on the provided list.

Parameters:
  • possible (list of str) – Possible keywords for ‘candidate’ to be matched against.
  • candidate (str) – Abbreviated keyword to expand.
Returns:

Return type:

list of str of matching expanded keywords

Examples

None yet.

Module contents