From e940d741f530b78a72a8b447c8d7c67e509f5cb6 Mon Sep 17 00:00:00 2001 From: James Jia <32031865+wenzhaojia2000@users.noreply.github.com> Date: Mon, 9 Oct 2023 08:20:37 +0100 Subject: [PATCH] Replace 'state_name' dict with lambda function in ddpesgeo Should save a bit of memory --- .../analyse/analysis_gui/analysis/direct_dynamics.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/analyse/analysis_gui/analysis/direct_dynamics.py b/source/analyse/analysis_gui/analysis/direct_dynamics.py index d027284..bc264da 100644 --- a/source/analyse/analysis_gui/analysis/direct_dynamics.py +++ b/source/analyse/analysis_gui/analysis/direct_dynamics.py @@ -285,11 +285,11 @@ def _ddpesgeoV4(self, con:sqlite3.Connection, cur:sqlite3.Cursor): if self.ddpesgeo_type.currentIndex() == 0: table = 'pes' - # dictionary mapping states to column names - state_name = {s: f'eng_{s}_{s}' for s in range(1, nroot+1)} + # lambda mapping states to column names + state_name = lambda s: f'eng_{s}_{s}' else: table = 'apes' - state_name = {s: f'eng_{s}' for s in range(1, nroot+1)} + state_name = lambda s: f'eng_{s}' if self.ddpesgeo_task[0].isChecked(): # task is find energies between interval @@ -300,7 +300,7 @@ def _ddpesgeoV4(self, con:sqlite3.Connection, cur:sqlite3.Cursor): # retrieve matching id + energies for s in range(1, nroot+1): query = (f'SELECT * FROM {table} LEFT JOIN geo USING(id) ' - f'WHERE {state_name[s]} BETWEEN {emin} AND {emax};') + f'WHERE {state_name(s)} BETWEEN {emin} AND {emax};') res = cur.execute(query).fetchall() # add id, energies, geo. split geo into geo_length subarrays # so there are 3 columns @@ -322,7 +322,7 @@ def _ddpesgeoV4(self, con:sqlite3.Connection, cur:sqlite3.Cursor): continue else: query = (f'SELECT * FROM {table} LEFT JOIN geo USING(id)' - f'WHERE ABS({state_name[s2]} - {state_name[s1]}) <= {tol};') + f'WHERE ABS({state_name(s2)} - {state_name(s1)}) <= {tol};') res = cur.execute(query).fetchall() # add id, energies, geo. split geo into geo_length subarrays # so there are 3 columns @@ -348,7 +348,7 @@ def _ddpesgeoV4(self, con:sqlite3.Connection, cur:sqlite3.Cursor): # format col_names and energies into a table # if relevant state, make energy header and value bold for i, name in enumerate(col_names): - if name in [state_name[state] for state in states]: + if name in [state_name(state) for state in states]: header.append(f'{name:>15}') values.append('' + '{: .8e}'.format(energies[i]) + '') else: