From db16caa63cff28c0b3c15ade6aa3fc1b33092e68 Mon Sep 17 00:00:00 2001 From: Tim Snow Date: Mon, 18 Sep 2023 16:18:41 +0100 Subject: [PATCH 1/2] Update sas_gen.py Adding dictionary lookup for speed increases --- src/sas/sascalc/calculator/sas_gen.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/sas/sascalc/calculator/sas_gen.py b/src/sas/sascalc/calculator/sas_gen.py index 518b7588de..63d0a3eda2 100644 --- a/src/sas/sascalc/calculator/sas_gen.py +++ b/src/sas/sascalc/calculator/sas_gen.py @@ -1192,6 +1192,7 @@ def read(self, path): x_lines = [] y_lines = [] z_lines = [] + atom_value_dict = {} try: input_f = open(path, 'rb') buff = decode(input_f.read()) @@ -1222,14 +1223,20 @@ def read(self, path): pos_y.append(_pos_y) pos_z.append(_pos_z) try: - val = nsf.neutron_sld(atom_name)[0] - # sld in Ang^-2 unit - val *= 1.0e-6 - sld_n.append(val) - atom = formula(atom_name) - # cm to A units - vol = 1.0e+24 * atom.mass / atom.density / NA - vol_pix.append(vol) + if atom_name in atom_value_dict: + sld_n.append(atom_value_dict[atom_name][0]) + vol_pix.append(atom_value_dict[atom_name][1]) + else: + val = nsf.neutron_sld(atom_name)[0] + # sld in Ang^-2 unit + val *= 1.0e-6 + sld_n.append(val) + atom = formula(atom_name) + # # cm to A units + vol = 1.0e+24 * atom.mass / atom.density / Na + vol_pix.append(vol) + atom_value_dict[atom_name] = [val, vol] + except Exception: logging.warning("Warning: set the sld of %s to zero"% atom_name) sld_n.append(0.0) From 6029972a663b97b2ba4394c865421ebfac24aeb4 Mon Sep 17 00:00:00 2001 From: Tim Snow Date: Tue, 19 Sep 2023 08:43:57 +0100 Subject: [PATCH 2/2] Correction for Na to NA Small typo lead to continual exceptions being raised --- src/sas/sascalc/calculator/sas_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sas/sascalc/calculator/sas_gen.py b/src/sas/sascalc/calculator/sas_gen.py index 63d0a3eda2..0007a2d63a 100644 --- a/src/sas/sascalc/calculator/sas_gen.py +++ b/src/sas/sascalc/calculator/sas_gen.py @@ -1233,7 +1233,7 @@ def read(self, path): sld_n.append(val) atom = formula(atom_name) # # cm to A units - vol = 1.0e+24 * atom.mass / atom.density / Na + vol = 1.0e+24 * atom.mass / atom.density / NA vol_pix.append(vol) atom_value_dict[atom_name] = [val, vol]