pythmpg.spreadsheet

User-level interface for generating Magnetic Point Group (MPG) spreadsheets.

This module defines the Spreadsheet class, which is designed to be invoked at the user level, i.e., called from outside the pythmpg package.

Notes

External functions called from this module are defined in module mpg_tools, which in turn makes use of other lower-level modules in this package.

Example

Here is a minimal example of a calling script: >>> from pythmpg import Spreadsheet # Import this module >>> my_sheet = Spreadsheet() # Instantiate spreadsheet >>> my_sheet.header_report() # Print header info (optional) >>> my_sheet.build_csv() # Analyze tensors >>> my_sheet.write_csv(‘my_sheet.csv’) # Write the .csv file

class pythmpg.spreadsheet.Spreadsheet[source]

Bases: object

Generate and output data for a Magnetic Point Group (MPG) spreadsheet.

The spreadsheet is organized into named sections of column headers. Default sections cover group identification (groups), symmetry indicators (symm), and scalar and vector property columns (scalar, vector). Sections can be added, removed, or replaced before calling build_csv().

defaults

Class-level dictionary of default header sections, each mapping a section name to a list of column-header tuples.

Type:

dict

section_dict

Instance copy of defaults, modified by add(), delete(), and modify().

Type:

dict

spreadsheet_data

Populated by build_csv(); contains header rows followed by one data row per MPG.

Type:

list of list

add(section, section_entry)[source]

Add a new section to the spreadsheet headers.

Parameters:
  • section (str) – Key for the new section to add to section_dict.

  • section_entry (list of tuple) – List of column-header tuples defining the new section.

Raises:

ValueError – If section is already a key in section_dict; use modify() to update an existing section.

build_csv()[source]

Populate spreadsheet_data with header and MPG data rows.

Constructs the full spreadsheet contents by first building four header rows from section_dict, then calling external helpers to obtain per-MPG symmetry information and independent-tensor counts for each Jahn symbol. Results are stored in self.spreadsheet_data as a list of rows ready for writing with write_csv().

Notes

This method imports mpg_dict from pythmpg.mpg_dicts and get_mpg_info, get_num_indep from pythmpg.mpg_tools. Both function calls use their defaults, which implies all MPGs.

delete(section)[source]

Remove a section from the spreadsheet headers.

Parameters:

section (str) – Key of the section to remove from section_dict.

Raises:

ValueError – If section is not a key in section_dict.

header_report()[source]

Print a formatted report of the current spreadsheet headers.

Iterates over all sections in section_dict and prints each column-header tuple, along with any associated annotation stored in the third element of the tuple.

jahn_report()[source]

Print the details of the parsing of Jahn symbols.

Iterates over all sections in section_dict, pulls the Jahn symbol names, parses each one, and prints explanatory information.

modify(section, section_entry)[source]

Replace an existing section of the spreadsheet headers.

Parameters:
  • section (str) – Key of the section to update in section_dict.

  • section_entry (list of tuple) – New list of column-header tuples for the section.

Raises:

ValueError – If section is not a key in section_dict; use add() to introduce a new section.

write_csv(filename, kind='bool')[source]

Write spreadsheet_data to a CSV file.

Parameters:
  • filename (str) – Path of the output CSV file.

  • kind ({'bool', 'num'}, optional) – Output format. 'bool' (default) replaces all non-zero, non-blank data cells with '1'; 'num' writes the raw numerical values.

Raises:

ValueError – If kind is not 'bool' or 'num'.