Helpers (chemistry_files.helpers
)
Based on possible_file_extensions()
and attempt_identification()
of WithIdentificationMixin , the helpers
submodule helps to open any chemistry files.
- exception qcip_tools.chemistry_files.helpers.ProbablyNotAChemistryFile
Raised when the type of the file is not recognized
- qcip_tools.chemistry_files.helpers.create_open_chemistry_file_action(must_be=None)
Create a custom argparse action.
from qcip_tools.chemistry_files import helpers, gaussian parser = argparse.ArgumentParser() parser.add_argument('-a', action=helpers.create_open_chemistry_file_action()) parser.add_argument('-b', action=helpers.create_open_chemistry_file_action(must_be=[gaussian.Input]))
String (or list) is parsed, and identifier can be added with
IDENTIFIER:/path/to/file
. Valid identifier are the values offile_type
in the differentChemistryFile
objects (a list can be found in the table on the beginning of this section).- Parameters:
must_be (list) – restrict the list of possibilities
- Return type:
argparse.Action
- qcip_tools.chemistry_files.helpers.identifiable_chemistry_file_objects(identifier_must_be=None)
Yield all objects with the
WithIdentificationMixin
.- Parameters:
identifier_must_be (list of str) – check if
file_type
is of the same type as the obj
- qcip_tools.chemistry_files.helpers.open_chemistry_file(f, must_be=None, trust_extension=False)
Try to recognise a file in the different possibility, and return the (normally) correct class.
Note
Despite the fact that it uses the file extension to pre-sort the possibilities, the performances are bad.
Note
Use the trick from https://stackoverflow.com/a/31123030 to serve a binary file if needed.
- Parameters:
f (file) – file
must_be (list) – restrict the list of possibilities
trust_extension (bool) – do not run a second pass on every other possibility if the content does not match extension
- Return type: