def parse_qchem_matrix(data): ret_val = [[]] def parse_line(cols, m): row = int(m.group(1)) - 1 data = [float(f) for f in m.group(2).strip().split()] while len(ret_val) < row + 1: ret_val.append([]) while len(ret_val[row]) < cols[-1] + 1: ret_val[row].append(None) if len(cols) != len(data): raise OutputParsingError("ragged matrix in output:\n{}".format(indented(data))) for d, col in zip(data, cols): ret_val[row][col] = d def parse_group_of_lines(m): columns = [int(s.strip()) - 1 for s in m.group(1).split()] re.sub(r"(\d)((?:\s+-?\d+\.\d+)+)", partial(parse_line, columns), m.group(2)) re.sub(r"((?:\d+[ \t]*)+\n)[ \t]+((?:\d+(?:\s+-?\d+\.\d+)+\s+)+)", parse_group_of_lines, data) if None in flattened(ret_val): raise OutputParsingError("output matrix missing value:\n{}".format(indented(data))) return Matrix(ret_val)
return decorate_it #--------------------------------------------------------------------------------# # construct suites # get the list of tests grendel_suite_all = unittest.defaultTestLoader.discover( os.path.dirname(__file__)) profile_suite = unittest.TestSuite() profile_subsuites = defaultdict(lambda: unittest.TestSuite()) standard_suite = unittest.TestSuite() long_only_suite = unittest.TestSuite() subsuites = defaultdict(lambda: unittest.TestSuite()) # Now iterate over all of the tests for test in flattened(grendel_suite_all): test_func = getattr(test, test.id().split('.')[-1], None) if test_func is not None: #----------------------------------------# profile_subsuite = getattr(test_func, '__profile__', None) if profile_subsuite is not None: profile_suite.addTest(test) if isinstance(profile_subsuite, tuple): for subsuite in profile_subsuite: profile_subsuites[subsuite].addTest(test) #----------------------------------------# long_test_attr = getattr(test_func, '__is_long_test__', None) if long_test_attr: long_only_suite.addTest(test) if hide_skipped_tests: # Change the __name__ attribute so that it doesn't get discovered
f.__subsuites__ = [] for arg in args: f.__subsuites__.append(arg) return f return decorate_it #--------------------------------------------------------------------------------# # construct suites # get the list of tests grendel_suite_all = unittest.defaultTestLoader.discover(os.path.dirname(__file__)) profile_suite = unittest.TestSuite() profile_subsuites = defaultdict(lambda: unittest.TestSuite()) standard_suite = unittest.TestSuite() long_only_suite = unittest.TestSuite() subsuites = defaultdict(lambda: unittest.TestSuite()) # Now iterate over all of the tests for test in flattened(grendel_suite_all): test_func = getattr(test, test.id().split('.')[-1], None) if test_func is not None: #----------------------------------------# profile_subsuite = getattr(test_func, '__profile__', None) if profile_subsuite is not None: profile_suite.addTest(test) if isinstance(profile_subsuite, tuple): for subsuite in profile_subsuite: profile_subsuites[subsuite].addTest(test) #----------------------------------------# long_test_attr = getattr(test_func, '__is_long_test__', None) if long_test_attr: long_only_suite.addTest(test) if hide_skipped_tests: # Change the __name__ attribute so that it doesn't get discovered
def variables(self): return [f for f in flattened( [[self.molecule.cartesian_representation[3*i + d] for d in [0,1,2]] for i in self.atom_indices] )]