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:
objectGenerate 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 callingbuild_csv().- defaults¶
Class-level dictionary of default header sections, each mapping a section name to a list of column-header tuples.
- 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
sectionis already a key insection_dict; usemodify()to update an existing section.
- build_csv()[source]¶
Populate
spreadsheet_datawith 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 inself.spreadsheet_dataas a list of rows ready for writing withwrite_csv().Notes
This method imports
mpg_dictfrompythmpg.mpg_dictsandget_mpg_info,get_num_indepfrompythmpg.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
sectionis not a key insection_dict.
- header_report()[source]¶
Print a formatted report of the current spreadsheet headers.
Iterates over all sections in
section_dictand 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
sectionis not a key insection_dict; useadd()to introduce a new section.
- write_csv(filename, kind='bool')[source]¶
Write
spreadsheet_datato 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
kindis not'bool'or'num'.