iodata.prepare module¶
Preparation of IOData instances before they are dumped.
The prepare_* functions below can be used as building blocks in prepare_dump functions.
When the allow_changes argument is set to True,
they can return a new IOData instance with some modified attributes.
Otherwise, they can raise an error if a conversion is needed.
When no conversion is needed, no errors or warnings are raised,
and the same IOData object is returned.
- prepare_segmented(data, keep_sp, allow_changes, filename, fmt)[source]¶
If needed, convert generalized contractions to segmented ones.
- Parameters:
data (
IOData) – The IOData instance with the orbital basis set.keep_sp (
bool) – Set to True if SP-shells should not be segmented.allow_changes (
bool) – Whether conversion of the IOData object to a compatible form is allowed or not.filename (
str) – The file to be written to, only used for error messages.fmt (
str) – The file format whose dump function is calling this function, only used for error messages.
- Returns:
data – The given data object if no conversion took place, or a shallow copy with some new attributes.
- Raises:
ValueError – If the given data object has no orbital basis set.
PrepareDumpError – If
allow_changes == Falseand a conversion is required.PrepareDumpWarning – If
allow_changes == Trueand a conversion is required.
- prepare_single_line_title(data, allow_changes, filename, fmt)[source]¶
Put the title on a single line, for file formats that can only store one line.
A title can have several lines, e.g. when it is loaded from a PDB file. Writing such a title as it is would break the structure of the file.
- Parameters:
data (
IOData) – The IOData instance with the title.allow_changes (
bool) – Whether conversion of the IOData object to a compatible form is allowed or not.filename (
str) – The file to be written to, only used for error messages.fmt (
str) – The file format whose dump function is calling this function, only used for error messages.
- Returns:
data – The given data object if the title is empty or already fits on one line, or a shallow copy with the lines of the title joined by single spaces.
- Raises:
PrepareDumpError – If
allow_changes == Falseand the title has more than one line.PrepareDumpWarning – If
allow_changes == Trueand the title has more than one line.
- prepare_unrestricted_aminusb(data, allow_changes, filename, fmt)[source]¶
If molecular orbitals have aminusb set, they are converted to unrestricted.
- Parameters:
data (
IOData) – The IOData instance with the molecular orbitals.allow_changes (
bool) – Whether conversion of the IOData object to a compatible form is allowed or not.filename (
str) – The file to be written to, only used for error messages.fmt (
str) – The file format whose dump function is calling this function, only used for error messages.
- Returns:
data – The given data object if no conversion took place, or a shallow copy with some new attributes.
- Raises:
ValueError – If the given data object has no molecular orbitals, or if the orbitals are generalized.
PrepareDumpError – If
allow_changes == Falseand a conversion is required.PrepareDumpWarning – If
allow_changes == Trueand a conversion is required.