-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
General API for preparing IOData object before dumping #191
Comments
Merged
This was referenced Apr 1, 2021
Another example of required conversion is discussed in #252: many formats do not support restricted orbitals with "unrestricted occupation numbers". In this case, the orbitals need to be converted to unrestricted form to be able to write a file. |
This was referenced Jun 15, 2024
This was referenced Jun 23, 2024
This was referenced Jun 24, 2024
This was referenced Jun 27, 2024
This was referenced Jul 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Motivation
At the moment, it is mostly assumed that an
IOData
instance contains all the right attributes in the right form before it is passed on to adump_one
call. Some file formats (WNF, WFX and potentially also FCHK) modify theIOData
object to become compatible with the format. Typical modifications include:This is problematic for several reasons:
dump_one
functions long and complicated.See also:
Proposal
Add an optional
prepare_dump
function to the fileformat modules. If present, it takes andIOData
instance as argument, and returns a potentially modified one. The givenIOData
instance is not modified. An optionallow_changes=False
should be added, to allow disabling any conversion. If this flag is set toFalse
and the file cannot be written without conversion, an exception is raised. If this flag is set toTrue
, a warning is emitted when a conversion is applied.The
dump_one
anddump_many
in the file formats functions call the newprepare_dump
function before dumping.Add a
allow_changes=False
option to thedump_one
anddump_many
functions in the file formats modules. This is passed on to theprepare_dump
function. The dump functions return the potentially modifiedIOData
instance(s).Add a
allow_changes=False
option to thedump_one
anddump_many
functions in the moduleiodata.api
. This is passed on to the dump functions of the selected file format. Also these dump functions return the potentially modifiedIOData
instance(s).Factor out some of the reusable utility functions to modify the
IOData
object, e.g. manipulations of basis set and corresponding changes to MO coefficients.Add an option to the script
iodata-convert
to enable or disable modifications before dumping.Add basic sanity check to
dump_one
anddump_many
that required attributes are notNone
before creating a file. Such missing attributes will raise an error, and may result in overwriting the output with an empty file, which is never useful and may ocassionally lead to data loss. This type of pre-flight check could be added toprepare_dump
, but it is better to write one general implementation for all file formats, so it is always checked.TODO list
dump_one
anddump_many
. Indump_one
, this can be done before even creating the file. Indump_many
this check is possible on the first frame before creating a file, not for later ones. See Check required attributes before dumping to a file #337prepare_dump
API and use it for validity checks: JSON, FCHK, WFX, WFN, Molden, Molekel. This does not add any actual conversion yet. (These will be implemented in later pull requests.) See Add light version of prepare_dump API #344FileFormatError
intoLoadError
andDumpError
and update formats modules to use these consistently. The current use of exceptions in the formats module is not consistent. Idem forFileFormatWarning
. See Clean up exceptions and split FileFormatError in LoadError and DumpError #345lit.error
by raisingLoadError
directly and extendLoadError
with the logic inlit.error
. Update contributor guide accordingly. See Replace lit.error by raise LoadError #348lit.warn
by directwarnings.warn()
using an improved LoadWarning class that contains the logic now implemented inlit.warn()
. Also extendDumpWarning
with file or filename argument, likeLoadWarning
. Do not uselit.warn
ExplainLoadWarning
in the contributor guide. See Further improve error and warning infrastructure #349DumpError
with file or filename argument, likeLoadError
.Directly subclass exceptions fromException
instead ofValueError
. (The latter improves testing when usingpytest.raises
.) See Further improve error and warning infrastructure #349occs_aminusb
: WFN, WFX, Molden, Molekel. Complete prepare_dump API and apply to occs_aminusb + cleanups #352warnings.catch_warnings()
in unit tests by more specific warnings. See Remove useless catch_warnings #353iodata.api
mandatory keywords, by inserting*,
in the argument list. See Require optional arguments of iodata.api functions to be specified with keywords #355iodata
iniodata.api
todata
for consistency with the rest of the code. See Do not use iodata as variable name #356Shell
attributes into arrays (now lists) with converter functions, in analogy toIOData
attributes. Convert Shell attributes to arrays #371convert_*
functions frombasis
andorbitals
toconvert
module, which becomes the lower-level analog of theprepare
module. It does similar things, but without the context of dumping data to files. Move convert functions to new convert module #372iodata.basis
#256. See Add prepare_segmented function #373prepare_dump
for WFN and WFX. This would also fix Decontraction of basis sets #258.prepare_dump
for WFN and WFX. This would also fix Conversion to Cartesian basis sets #259.--allow-changes
option to command-line interface. See Add command-line option--allow-changes
toiodata-convert
#374dump_one
prepare_dump
function, and how to raise errors and warningsgetting_started.rst
and run them as unit tests #210. See Split the getting started docs #351--allow-changes
option.allow_changes
keyword argument.The text was updated successfully, but these errors were encountered: