PSCF v1.3
pscfpp.output.Thermo Class Reference

Parser and container for PSCF thermo file blocks. More...

Public Member Functions

 __init__ (self, filename=None)
 Constructor.
 read (self, file)
 Read the passed-in open-file.
 skipEmptyLine (self, file)
 Skip empty lines in the file.
 write (self, filename)
 Write the contents of this object in thermo file format to a file.
 __str__ (self)
 Return a string representation of this object in thermo file format.

Detailed Description

Parser and container for PSCF thermo file blocks.

This module provides tools to parse the PSCF "thermo" file format and store the contents of a such a file block in accessible form. This file reports properties that are outputs of a SCFT calculation, such as Helmholtz free energy and macroscopic pressure (or grand canonical free energy density), as well as some quantities that can be either inputs or outputs depending on the mode of operation (e.g., chemical potentials and volume fractions). A thermo file block can appear either as the entire contents of a file (which can be created by the PSCF command WRITE_THERMO) or as a section of a larger data (i.e., as part of the log file that is written to standard output at the end of an SCFT or a section of the type of "state" file created by a Sweep operation). Users can access and modify values of properties stored in a Thermo object after it has been used to parse a thermo file block using the Python dot syntax for object attributes.

Construction and Parsing:

Users may parse a thermo file block file by creating a Thermo object, passing either the name of the thermo file or an open file object as an argument. This constructor parses the file and returns a Thermo object that contains its contents.

For example: To read and parse a thermo file with name 'thermo', one could enter:

from pscfpp.output import *
t = Thermo('thermo')
Module of parsers for PSCF output file formats.
Definition output.py:1

Writing out:

A multi-line string representation of a Thermo object in thermo file format (i.e., the format of the original input file), can be obtained using the str special method, or written to a file using the write method.

Example: If t is a Thermo object, then

t.write('thermoOut')

writes the contents of to file named 'thermoOut'.

Accessing properties:

After creating a Thermo object, users can retrieve the values of any property by name, using a dot notation for properties stored within the Thermo object. There are four different types of properties that are stored within a Thermo object. These are listed below, along with a summary of what is returned when they are accessed, and an example Python expression that would access this type of property in a typical Thermo object:

Single variable: if a property is represented by a single value, such as Helmholtz free energy, it can be accessed using dot notation for a Python attribute. For example, if t is a Thermo object, then the expressions

t.fHelmholtz
t.pressure

return the Helmholtz free energy per monomer in thermal units (property fHelmholtz) and the non-dimensionalized pressure (pressure times monomer reference volume in thermal units).

Arrays of Species objects: the Thermo class has two data attributes named Polymers and Solvents, each of which is a list of instances of class Species. Each Species object represents one polymer or solvent species, and has two data attributes: phi (volume fraction) and mu (chemical potential). A specific Species from the list Polymer or Solvent is accessed by square indexing, which returns the Species object. Dot notation for attributes of a Species can then be used to access the value of phi or mu for a specific polymer or solvent.

Example: If t is a Thermo object, then

t.Polymers[0].phi
t.Solvents[1].mu

return the volume fraction of polymer 0 (the first polymer) and the chemical potential of solvent 1 (the second solvent).

LatticeParameters and stresses: The attribute cellParams is created only by calculations for a periodic system, and is a list of values for each lattice parameter of the unit cell. The interpretation of the order and meaning of the lattice parameters depends on the lattice system, which is given in the input parameter file. Specific parameters can be accessed by square bracket indexing, and are float values.

Example: The expressions

t.cellParams
t.cellParams[0]

return the list of lattice parameters and the first lattice parameter, respectively.

Two additional attributes, stress and environmentStress, are optional elements of the thermo file that are written by the PSCF command WRITE_STRESS. These arrays contain one value of stress for each lattice parameter, and are therefore stored in the same form as cellParams. Note that environmentStress is only included in the output from PSCF if the calculation contained an Environment object and used a flexible unit cell.

Homogeneous information: In r1d, the COMPARE_HOMOGENEOUS command or the homogeneousMode parameter in a Sweep object will result in the output of additional data comparing the result to a corresponding homogeneous state. This contains two to seven parameters with labels "f (homo)", "p (homo)", "delta f", "delta p", "F (ex)", "Phi (ex)", and "V(tot)/v". If the parser encounters this block, the data will be read into an attribute called homogeneous, which is a dictionary. The key of the dictionary is the parameter name string (e.g., "f (homo)"), and the value is the number that follows.

Example: The expressions

t.homogeneous
t.homogeneous["f (homo)"]

return the dictionary of homogeneous data and the "f (homo)" value, respectively.

Following this data, a list of species is provided, with their homogeneous mu, phi, and deltaV values. These values are stored in the attribute named homogeneousSpecies, which is a list with one entry per species. Each entry is a dictionary where the key is the name of the parameter from the parameter file, and the value is its numerical value.

Example: The expressions

t.homogeneousSpecies
t.homogeneousSpecies[1]
t.homogeneousSpecies[1]["mu"]

return the list of species data, the dictionary of data for species 1, and the mu value for species 1, respectively.

Modifying properties:

The numerical values of properties stored in a Thermo object are stored as Python attributes of Thermo or Species, which can be modified as well as accessed for reading.

Example: The expressions

t.fHelmholtz *= 2
t.fHelmholtz = 0.8

reset the value of fHelmholtz.

Example: The expressions

t.Polymers[0].phi += 0.3
t.Solvents[1].mu = 0.2

modify values of phi and mu for specific species.

Example: The expressions

t.LatticeParameters = [0.2, 0.2]
t.LatticeParameters[0] = 0.2

modify lattice parameters, either by replacing the list in the first case, or by modifying a single element in the second.

Definition at line 179 of file output.py.

Constructor & Destructor Documentation

◆ __init__()

pscfpp.output.Thermo.__init__ ( self,
filename = None )

Constructor.

If the filename parameter is the name of a thermo file, the file is parsed and its contents are stored in attributes of the resulting Thermo object. If filename is absent or None, then an empty object is created.

Parameters
filenamea filename string, defult to be None.

Definition at line 191 of file output.py.

References cellParams, environmentStress, fExt, fHelmholtz, fIdeal, fInter, homogeneous, homogeneousSpecies, polymers, pressure, Pscf::Rpc::BasisFieldState< D >.read(), Pscf::Rpg::BasisFieldState< D >.read(), pscfpp.command.Script.read(), pscfpp.field.Field.read(), read(), Util::Label.read(), Util::ParamComposite.read(), solvents, stress, and tableLabel.

Member Function Documentation

◆ read()

pscfpp.output.Thermo.read ( self,
file )

Read the passed-in open-file.

This function reads a thermo block from a file that is open for reading and stores the property values in this Thermo object.

Parameters
filean open-file object.

Definition at line 218 of file output.py.

References cellParams, environmentStress, fExt, fHelmholtz, fIdeal, fInter, homogeneous, homogeneousSpecies, polymers, pressure, skipEmptyLine(), solvents, stress, and tableLabel.

Referenced by __init__(), pscfpp.param.Array.__init__(), pscfpp.param.Composite.__init__(), and pscfpp.param.Matrix.__init__().

◆ skipEmptyLine()

pscfpp.output.Thermo.skipEmptyLine ( self,
file )

Skip empty lines in the file.

This function skips empty lines read from the file. It is a helper function used by the read() function.

Parameters
filea file object, open for reading

Definition at line 340 of file output.py.

Referenced by read().

◆ write()

pscfpp.output.Thermo.write ( self,
filename )

Write the contents of this object in thermo file format to a file.

This function writes out the thermo file string to the specified file with the name of the passed-in parameter, filename.

Parameters
filenamea filename string.

Definition at line 355 of file output.py.

References pscfpp.command.Script.__str__(), pscfpp.field.Field.__str__(), pscfpp.file.Directory.__str__(), pscfpp.file.File.__str__(), pscfpp.make.MakeMaker.__str__(), and __str__().

◆ __str__()

pscfpp.output.Thermo.__str__ ( self)

Return a string representation of this object in thermo file format.

Definition at line 362 of file output.py.

References cellParams, environmentStress, fExt, fIdeal, fInter, homogeneous, homogeneousSpecies, polymers, solvents, stress, and tableLabel.

Referenced by pscfpp.output.State.write(), and write().


The documentation for this class was generated from the following file: