Skip to content

Commit

Permalink
fix: conditional header generation for NMR JCAMP export (#219)
Browse files Browse the repository at this point in the history
* Fix conditional header generation for NMR JCAMP export

* Add tests to ensure that empty headers are not added to nmr files + Add a test file with empty headers
  • Loading branch information
Nicolass67 authored Nov 20, 2024
1 parent 3cf1088 commit fbaa71f
Show file tree
Hide file tree
Showing 3 changed files with 17,362 additions and 20 deletions.
48 changes: 28 additions & 20 deletions chem_spectra/lib/composer/ni.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
Loading

0 comments on commit fbaa71f

Please sign in to comment.