From fbb4ec93dba2e0bf7a3fb0e883a409def1502cfc Mon Sep 17 00:00:00 2001 From: Nicolass67 Date: Thu, 14 Nov 2024 09:53:35 +0000 Subject: [PATCH] Fix conditional header generation for NMR JCAMP export --- chem_spectra/lib/composer/ni.py | 48 +++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/chem_spectra/lib/composer/ni.py b/chem_spectra/lib/composer/ni.py index adb592c..bd6d56d 100644 --- a/chem_spectra/lib/composer/ni.py +++ b/chem_spectra/lib/composer/ni.py @@ -58,26 +58,34 @@ def __get_nucleus(self): return nucleus def __header_nmr(self): - return [ - '##.OBSERVE FREQUENCY={}\n'.format( - extrac_dic(self.core, '.OBSERVEFREQUENCY') - ), - '##.OBSERVE NUCLEUS={}\n'.format( - self.__get_nucleus() - ), - '##SPECTROMETER/DATA SYSTEM={}\n'.format( - extrac_dic(self.core, 'SPECTROMETER/DATASYSTEM') - ), - '##.SHIFT REFERENCE={}\n'.format( - extrac_dic(self.core, '.SHIFTREFERENCE') - ), - '##.SOLVENT NAME={}\n'.format( - extrac_dic(self.core, '.SOLVENTNAME') - ), - '##.PULSE SEQUENCE={}\n'.format( - extrac_dic(self.core, '.PULSESEQUENCE') - ), - ] + header_lines = [] + + # Append each line only if the extracted value is not empty + observe_frequency = extrac_dic(self.core, '.OBSERVEFREQUENCY') + if observe_frequency: + header_lines.append('##.OBSERVE FREQUENCY={}\n'.format(observe_frequency)) + + observe_nucleus = self.__get_nucleus() + if observe_nucleus: + header_lines.append('##.OBSERVE NUCLEUS={}\n'.format(observe_nucleus)) + + spectrometer_data_system = extrac_dic(self.core, 'SPECTROMETER/DATASYSTEM') + if spectrometer_data_system: + header_lines.append('##SPECTROMETER/DATA SYSTEM={}\n'.format(spectrometer_data_system)) + + shift_reference = extrac_dic(self.core, '.SHIFTREFERENCE') + if shift_reference: + header_lines.append('##.SHIFT REFERENCE={}\n'.format(shift_reference)) + + solvent_name = extrac_dic(self.core, '.SOLVENTNAME') + if solvent_name: + header_lines.append('##.SOLVENT NAME={}\n'.format(solvent_name)) + + pulse_sequence = extrac_dic(self.core, '.PULSESEQUENCE') + if pulse_sequence: + header_lines.append('##.PULSE SEQUENCE={}\n'.format(pulse_sequence)) + + return header_lines def __header_params(self): return [