-
Notifications
You must be signed in to change notification settings - Fork 0
MassRead
Read multiple types of data from multiple log files and store them into numpy npz files after being trimmed according to how such type of data is normally printed out in Gaussian log files.
-
Initialization: MassRead(n_log=-1, log_list=0, ext=".log", init_fh=None, input_dir="", output_dir="", data_type=None)
- Parameters:
- data_type: python list
optional, default=None. A list containing the data type names to be read from the log files. If not passed in, i.e. set to None, the default data type list will be used. The default data type list is: ["Cartesian Coordinates #VarRow", "Mass Weighted Velocity #VarRow", "Time", "Total Energy", "Kinetic Energy", "Potential Energy", "Total Angular Momentum", "Angular Momemtum Components", "Mulliken Charges #VarRow", "Dipole Moment"] Only the data type name that subclasses FileRead and ArrayTrim recognise should be passed in, which can be tedious to do. Therefore, if the data type needed to be read is among the already supported ones, the next object attribute, MassRead.data_name_short could be more convenient to use: any data type shorthand in this dictionary will be translated into its actual data type name. In the case of reading and trimming unsupported data type, these two processes have to be initialized manually by assign the corresponding object to attributes MassRead.read_operator and MassRead.trim_operator. - n_log: integer
optional, default=-1, which is a flag signifying nothing passed in. This is the number of log files to read. - log_list: python list of strings, python File object
optional, default=0, which is a flag signifying nothing passed in. This is either a list of log file names to read or the file handle of the text file containing such list. If the previous argument, n_log, was passed in, the initialization will generate a list of log file names in the following manner: [0.log, 1.log, 2.log, 3.log, ...]; otherwise, the actual list passed in here or the one read from the file handle passed in here will be used. * init_fh: tuple, string, python File object
optional, default=None. This parameter is what the initialization attempts to initialize the FileRead and ArrayTrim objects with. If passed in a tuple of integers, (init_n_atom, init_max_pts)=init_fh; if passed in the raw string or file handle of a log file, the n_atom and max_pts parameters needed to initialize the FileRead and ArrayTrim objects will be read from such log file.- input_dir: string
optional, default="". Input directory from where the log file would be read. If nothing passed in, the current directory from where the script is running in will be taken. - output_dir: string
optional, default="". Output directory to where the results will be saved. If nothing passed in, the current directory from where the script is running in will be taken. - ext: string
optional, default=".log". File extension of the log files. No need to change unless somehow the file extension of the Gaussian log files are not ".log".
- input_dir: string
- data_type: python list
- Parameters:
-
MassRead.data_name_short =
{ "ef": "Electric Field", "ef_alt": "Electric Field Alt", "xyz": "Cartesian Coordinates #VarRow", "MWVxyz": "Mass Weighted Velocity #VarRow", "time": "Time", "Etot": "Total Energy", "Ekin": "Kinetic Energy", "Epot": "Potential Energy", "Jtot": "Total Angular Momentum", "Jtot_xyz": "Angular Momemtum Components", "MlkC": "Mulliken Charges #VarRow", "dipole": "Dipole Moment" }In the case that the data type needed to be read is among the already supported ones, any data type shorthand in this dictionary will be translated into its actual data type name in the MassRead.read() method.
-
MassRead.read_operator = None
This should be assigned to a FileRead object. In the case of reading unsupported data type, do the following:fh = open(log_file_name, "r") mr = MassRead(n_log=100) mr.read_operator = FileRead(file_str=fh) mr.read_operator.pattern_dict[custom_type_name] = custom_type_pattern fh.close() -
MassRead.trim_operator = None
This should be assigned to a ArrayTrim object. In the case of trimming unsupported data type, do the following:fh = open(log_file_name, "r") mr = MassRead(n_log=100) mr.trim_operator = ArrayTrim(file_str=fh) mr.trim_operator.trim_par_dict[custom_type_name] = custom_type_pattern fh.close() -
MassRead.data_read = list()
The results from MassRead.read() is stored in this attribute. -
MassRead.read(n_log=-1, log_list=None)
Read the data types in MassRead.data_type_list from log files with names in log_list.-
Parameters:
- n_log: integer
optional, default=-1, which is a flag signifying nothing passed in. This is the number of log files to read. - log_list: python list of strings, python File object
optional, default=0, which is a flag signifying nothing passed in. This is either a list of log file names to read or the file handle of the text file containing such list. If the previous argument, n_log, was passed in, the initialization will generate a list of log file names in the following manner: [0.log, 1.log, 2.log, 3.log, ...]; otherwise, the actual list passed in here or the one read from the file handle passed in here will be used.
These two parameters are used identically as in initialization and are used to read files differently as set up during initialization if needed.
- n_log: integer
-
Returns: a list of lists of numpy arrays. The dimension is this 2-D list is [data_type, log_files]
-
-
MassRead.save(list_of_data=None, list_of_names=None)
Save the data from list_of_data as numpy npz package files with the names in list_of_names.- Parameters:
- list_of_data: a list of lists of numpy arrays.
optional, default=None, which signifies using MassRead.data_read instead. The dimension of this 2-D list is [data_type, log_files]. - list_of_names: a list of names of the data types
optional, default=None, which signifies using MassRead.data_type_list instead. The MassRead.data_name_short will be used reversely to translate actual data type names into shorhands when saving into numpy npz files.
- list_of_data: a list of lists of numpy arrays.
- Parameters:
-
Example:
Suppose there are 100 log files named numerically, starting from "0.log". The following script will read and save all supported data types:mr = MassRead(n_log=100, input_dir=INPUT_DIRECTORY, output_dir=OUTPUT_DIRECTORY) mr.read() mr.save()