diff --git a/src/tcutility/results/__init__.py b/src/tcutility/results/__init__.py index ea1a6694..d369308a 100644 --- a/src/tcutility/results/__init__.py +++ b/src/tcutility/results/__init__.py @@ -105,16 +105,13 @@ def read(calc_dir: Union[str, pl.Path]) -> Result: elif ret.engine == "orca": try: ret.orca = orca.get_calc_settings(ret) - except: + except: # noqa ret.orca = None - print('Error reading:', calc_dir) - raise + try: ret.properties = orca.get_properties(ret) - except: + except: # noqa ret.properties = None - print('Error reading:', calc_dir) - raise # unload cached KFReaders associated with this calc_dir to_delete = [key for key in cache._cache if key.startswith(os.path.abspath(calc_dir))] diff --git a/src/tcutility/results/orca.py b/src/tcutility/results/orca.py index cac4b324..3d0db65d 100644 --- a/src/tcutility/results/orca.py +++ b/src/tcutility/results/orca.py @@ -9,7 +9,7 @@ def get_calc_files(calc_dir: str) -> Result: - """Function that returns files relevant to AMS calculations stored in ``calc_dir``. + """Function that returns files relevant to ORCA calculations stored in ``calc_dir``. Args: calc_dir: path pointing to the desired calculation @@ -22,18 +22,22 @@ def get_calc_files(calc_dir: str) -> Result: for root, _, files_ in os.walk(calc_dir): files.extend([j(root, file) for file in files_]) - # parse the filenames + # we now go through all the files and check their nature ret = Result() ret.root = os.path.abspath(calc_dir) for file in files: - try: - with open(file) as f: - lines = f.readlines() - + with open(file, errors='ignore') as f: + lines = f.readlines() + # detect the output file if any(["* O R C A *" in line for line in lines]): ret.out = os.path.abspath(file) - except: # noqa - pass + continue + + # detect the input file + # there should be lines starting with ! and also the system line, starting with * xyz, * xyzfile, * gzmtfile or * int + if any([line.startswith('!') for line in lines]) and any([(len(line.split()) > 2 and line.split()[0] == '*' and line.split()[1] in ['xyz', 'xyzfile', 'gzmtfile', 'int']) for line in lines]): + ret.inp = os.path.abspath(file) + continue return ret @@ -81,22 +85,29 @@ def get_input(info: Result) -> Result: - **task (str)** - the task that was performed by the calculation, e.g. "SinglePoint", "TransitionStateSearch". """ ret = Result() - with open(info.files.out) as out: - start_reading = False - lines = [] - for line in out.readlines(): - line = line.strip() - if start_reading: - lines.append(line) - if "INPUT FILE" in line: - start_reading = True - continue + # we read the input file first + if 'inp' in info.files: + with open(info.files.inp) as inp: + lines = inp.readlines() + # if we don't have it we read the output file, which contains the input as a block + else: + with open(info.files.out) as out: + start_reading = False + lines = [] + for line in out.readlines(): + line = line.strip() + if start_reading: + lines.append(line) - if "****END OF INPUT****" in line: - break + if "INPUT FILE" in line: + start_reading = True + continue + + if "****END OF INPUT****" in line: + break - lines = [line.split(">")[1] for line in lines[2:-1] if line.split(">")[1].strip()] + lines = [line.split(">")[1] for line in lines[2:-1] if line.split(">")[1].strip()] ret.main = [] curr_section = None