diff --git a/wwpdb/utils/nmr/mr/ParserListenerUtil.py b/wwpdb/utils/nmr/mr/ParserListenerUtil.py index 60b4623d..2e64738f 100644 --- a/wwpdb/utils/nmr/mr/ParserListenerUtil.py +++ b/wwpdb/utils/nmr/mr/ParserListenerUtil.py @@ -2086,11 +2086,6 @@ 'encoded_reduced_dimension_id': None } -SPECTRAL_DIM_TRANSFER_TEMPLATE = {'spectral_dim_id_1': None, - 'spectral_dim_id_2': None, - 'indirect': None, - 'type': None} - def toRegEx(string: str) -> str: """ Return regular expression for a given string including XPLOR-NIH wildcard format. diff --git a/wwpdb/utils/nmr/pk/AriaPKParserListener.py b/wwpdb/utils/nmr/pk/AriaPKParserListener.py index a45d1662..a2b64daf 100644 --- a/wwpdb/utils/nmr/pk/AriaPKParserListener.py +++ b/wwpdb/utils/nmr/pk/AriaPKParserListener.py @@ -8,7 +8,6 @@ @see: https://aria-test.pasteur.fr/documentation/input-format/version-2.1/spectrum """ import sys -import numpy as np from antlr4 import ParseTreeListener @@ -32,6 +31,9 @@ class AriaPKParserListener(ParseTreeListener, BasePKParserListener): __cur_path = None + __spectrum_names = None + __spectrum_name = None + __index = None __proton1_ppm = None __proton1_ppm_error = None @@ -74,111 +76,13 @@ def __init__(self, verbose=True, log=sys.stdout, # Enter a parse tree produced by XMLParser#document. def enterDocument(self, ctx: XMLParser.DocumentContext): # pylint: disable=unused-argument self.__cur_path = '' + self.__spectrum_names = {} self.enter() # Exit a parse tree produced by XMLParser#document. def exitDocument(self, ctx: XMLParser.DocumentContext): # pylint: disable=unused-argument - - if len(self.spectral_dim) > 0: - for d, v in self.spectral_dim.items(): - for _id, _v in v.items(): - self.acq_dim_id = 1 - for __d, __v in _v.items(): - if 'freq_hint' in __v: - if len(__v['freq_hint']) > 0: - center = np.mean(np.array(__v['freq_hint'])) - - if __v['atom_isotope_number'] is None: - if 125 < center < 130: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C_aro' - elif 115 < center < 125: - __v['atom_type'] = 'N' - __v['atom_isotope_number'] = 15 - __v['axis_code'] = 'N_ami' - elif 170 < center < 180: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'CO' - elif 6 < center < 9: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H_ami_or_aro' - elif 4 < center < 6: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H' - elif 2 < center < 4: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H_ali' - elif 60 < center < 90: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C' - elif 30 < center < 50: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C_ali' - - isotope_number = __v['atom_isotope_number'] - - if isotope_number is not None: - __v['acquisition'] = 'yes' if __d == self.acq_dim_id\ - and (isotope_number == 1 or (isotope_number == 13 and self.exptlMethod == 'SOLID-STATE NMR')) else 'no' - - if __d == 1 and __v['acquisition'] == 'no': - self.acq_dim_id = self.num_of_dim - - __v['under_sampling_type'] = 'not observed' if __v['acquisition'] == 'yes' else 'aliased' - - if __v['spectral_region'] is None and len(__v['freq_hint']) > 0: - atom_type = __v['atom_type'] - if 125 < center < 130 and atom_type == 'C': - __v['spectral_region'] = 'C_aro' - elif 115 < center < 125 and atom_type == 'N': - __v['spectral_region'] = 'N_ami' - elif 170 < center < 180 and atom_type == 'C': - __v['spectral_region'] = 'CO' - elif 6 < center < 9 and atom_type == 'H': - __v['spectral_region'] = 'H_ami_or_aro' - elif 4 < center < 6 and atom_type == 'H': - __v['spectral_region'] = 'H_all' - elif 2 < center < 4 and atom_type == 'H': - __v['spectral_region'] = 'H_ali' - elif 60 < center < 90 and atom_type == 'C': - __v['spectral_region'] = 'C_all' - elif 30 < center < 50 and atom_type == 'C': - __v['spectral_region'] = 'C_ali' - - if len(__v['freq_hint']) > 0 and d > 2 and __d >= 2\ - and self.exptlMethod != 'SOLID-STATE NMR' and __v['atom_isotope_number'] == 13: - max_ppm = max(__v['freq_hint']) - min_ppm = min(__v['freq_hint']) - width = max_ppm - min_ppm - if center < 100.0 and width < 50.0: - __v['under_sampling_type'] = 'fold' - - del __v['freq_hint'] - - for __v in _v.values(): - if __v['axis_code'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['axis_code'] = 'H_aro' if has_a else 'H_ami' - if __v['spectral_region'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['spectral_region'] = 'H_aro' if has_a else 'H_ami' - - if self.debug: - print(f'num_of_dim: {d}, list_id: {_id}') - for __d, __v in _v.items(): - print(f'{__d} {__v}') - - self.exit() - - self.__cur_path = None + self.exit(self.__spectrum_names) # Enter a parse tree produced by XMLParser#prolog. def enterProlog(self, ctx: XMLParser.PrologContext): # pylint: disable=unused-argument @@ -202,6 +106,7 @@ def enterElement(self, ctx: XMLParser.ElementContext): if self.__cur_path == '/spectrum': self.num_of_dim = -1 + self.__spectrum_name = None elif self.__cur_path == '/spectrum/peak': self.__volume = None @@ -277,6 +182,10 @@ def exitElement(self, ctx: XMLParser.ElementContext): # pylint: disable=unused- self.num_of_dim += 1 self.__hetero2_active = True self.initSpectralDim() + if self.num_of_dim not in self.__spectrum_names: + self.__spectrum_names[self.num_of_dim] = {} + if self.cur_list_id not in self.__spectrum_names[self.num_of_dim]: + self.__spectrum_names[self.num_of_dim][self.cur_list_id] = self.__spectrum_name index = self.__index @@ -722,7 +631,12 @@ def enterAttribute(self, ctx: XMLParser.AttributeContext): name = str(ctx.Name()) string = str(ctx.STRING())[1:-1].strip() - if self.__cur_path == '/spectrum/peak': + if self.__cur_path == '/spectrum': + + if name == 'name': + self.__spectrum_name = string + + elif self.__cur_path == '/spectrum/peak': if name == 'number': self.__index = int(string) diff --git a/wwpdb/utils/nmr/pk/BasePKParserListener.py b/wwpdb/utils/nmr/pk/BasePKParserListener.py index 8614c57a..fc17a864 100644 --- a/wwpdb/utils/nmr/pk/BasePKParserListener.py +++ b/wwpdb/utils/nmr/pk/BasePKParserListener.py @@ -10,6 +10,7 @@ import re import copy import collections +import numpy from typing import List, IO, Tuple, Optional @@ -420,7 +421,9 @@ def enter(self): self.compIdMap = {} self.f = [] - def exit(self): + def exit(self, spectrum_names: Optional[dict] = None): + + self.fillSpectralDimTransfer(spectrum_names) try: @@ -733,7 +736,7 @@ def initSpectralDim(self): if len(self.cur_spectral_dim) == 0 or _dim_id not in self.cur_spectral_dim else self.cur_spectral_dim[_dim_id]) - self.spectral_dim[self.num_of_dim][self.cur_list_id][_dim_id]['freq_hint'] = [] + self.spectral_dim[self.num_of_dim][self.cur_list_id][_dim_id]['freq_hint'] = [] # list -> numpy array before exit() if self.file_type == 'nm-pea-pip': self.spectral_dim[self.num_of_dim][self.cur_list_id][_dim_id]['obs_freq_hint'] = [] if self.num_of_dim not in self.spectral_dim_transfer: @@ -757,8 +760,418 @@ def fillAtomTypeInCase(self, _dim_id: int, atom_type: str) -> bool: return True return False - def fillSpectralDimTransfer(self): - pass + def fillSpectralDimTransfer(self, spectrum_names: Optional[dict]): + if len(self.spectral_dim) > 0: + for d, v in self.spectral_dim.items(): + for _id, _v in v.items(): + self.acq_dim_id = 1 + for __d, __v in _v.items(): + if 'freq_hint' in __v: + __v['freq_hint'] = numpy.array(__v['freq_hint'], dtype=float) # list -> numpy array + if __v['freq_hint'].size > 0: + center = numpy.mean(__v['freq_hint']) + + if __v['atom_isotope_number'] is None: + if 125 < center < 130: + __v['atom_type'] = 'C' + __v['atom_isotope_number'] = 13 + __v['axis_code'] = 'C_aro' + elif 115 < center < 125: + __v['atom_type'] = 'N' + __v['atom_isotope_number'] = 15 + __v['axis_code'] = 'N_ami' + elif 170 < center < 180: + __v['atom_type'] = 'C' + __v['atom_isotope_number'] = 13 + __v['axis_code'] = 'CO' + elif 6 < center < 9: + __v['atom_type'] = 'H' + __v['atom_isotope_number'] = 1 + __v['axis_code'] = 'H_ami_or_aro' + elif 4 < center < 6: + __v['atom_type'] = 'H' + __v['atom_isotope_number'] = 1 + __v['axis_code'] = 'H' + elif 2 < center < 4: + __v['atom_type'] = 'H' + __v['atom_isotope_number'] = 1 + __v['axis_code'] = 'H_ali' + elif 60 < center < 90: + __v['atom_type'] = 'C' + __v['atom_isotope_number'] = 13 + __v['axis_code'] = 'C' + elif 30 < center < 50: + __v['atom_type'] = 'C' + __v['atom_isotope_number'] = 13 + __v['axis_code'] = 'C_ali' + + isotope_number = __v['atom_isotope_number'] + + if isotope_number is not None: + __v['acquisition'] = 'yes' if __d == self.acq_dim_id\ + and (isotope_number == 1 or (isotope_number == 13 and self.exptlMethod == 'SOLID-STATE NMR')) else 'no' + + if __d == 1 and __v['acquisition'] == 'no': + self.acq_dim_id = self.num_of_dim + + __v['under_sampling_type'] = 'not observed' if __v['acquisition'] == 'yes' else 'aliased' + + if __v['spectral_region'] is None and __v['freq_hint'].size > 0: + atom_type = __v['atom_type'] + if 125 < center < 130 and atom_type == 'C': + __v['spectral_region'] = 'C_aro' + elif 115 < center < 125 and atom_type == 'N': + __v['spectral_region'] = 'N_ami' + elif 170 < center < 180 and atom_type == 'C': + __v['spectral_region'] = 'CO' + elif 6 < center < 9 and atom_type == 'H': + __v['spectral_region'] = 'H_ami_or_aro' + elif 4 < center < 6 and atom_type == 'H': + __v['spectral_region'] = 'H_all' + elif 2 < center < 4 and atom_type == 'H': + __v['spectral_region'] = 'H_ali' + elif 60 < center < 90 and atom_type == 'C': + __v['spectral_region'] = 'C_all' + elif 30 < center < 50 and atom_type == 'C': + __v['spectral_region'] = 'C_ali' + + if __v['freq_hint'].size > 0 and d > 2 and __d >= 2\ + and self.exptlMethod != 'SOLID-STATE NMR' and __v['atom_isotope_number'] == 13: + max_ppm = __v['freq_hint'].max() + min_ppm = __v['freq_hint'].min() + width = max_ppm - min_ppm + if center < 100.0 and width < 50.0: + __v['under_sampling_type'] = 'fold' + + if __v['spectrometer_frequency'] is None and 'obs_freq_hint' in __v and len(__v['obs_freq_hint']) > 0: + __v['spectrometer_frequency'] = collections.Counter(__v['obs_freq_hint']).most_common()[0][0] + + if 'obs_freq_hint' in __v: + del __v['obs_freq_hint'] + + if __v['spectrometer_frequency'] is not None and __v['sweep_width_unit'] == 'ppm': + row = [str(__v['sweep_width']), str(__v['spectrometer_frequency'])] + max_eff_digits = getMaxEffDigits(row) + + __v['sweep_width'] = float(roundString(str(__v['sweep_width'] * __v['spectrometer_frequency']), + max_eff_digits)) + __v['sweep_width_unit'] = 'Hz' + + for __v in _v.values(): + if __v['axis_code'] == 'H_ami_or_aro': + has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) + __v['axis_code'] = 'H_aro' if has_a else 'H_ami' + if __v['spectral_region'] == 'H_ami_or_aro': + has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) + __v['spectral_region'] = 'H_aro' if has_a else 'H_ami' + + for d, v in self.spectral_dim.items(): + for _id, cur_spectral_dim in v.items(): + + if self.debug: + print(f'original file name: {self.__originalFileName}{", spectrum name: " + spectrum_names[d][_id] if spectrum_names is not None else ""}') + + file_name = self.__originalFileName.lower() + alt_file_name = spectrum_names[d][_id].lower() if spectrum_names is not None else '' + cur_spectral_dim_transfer = self.spectral_dim_transfer[d][_id] + + # onebond: 'Any transfer that connects only directly bonded atoms in this experiment' + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 in ('H_ami', 'H_ali', 'H_aro'): + cases = 0 + max_corr_eff = 0.0 + for _dim_id2, _dict2 in cur_spectral_dim.items(): + _region2 = _dict2['spectral_region'] + if (_region1 == 'H_ami' and _region2 == 'N_ami')\ + or (_region1 == 'H_ali' and _region2 == 'C_ali')\ + or (_region1 == 'H_aro' and _region2 == 'C_aro'): + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + if not any(_transfer for _transfer in cur_spectral_dim_transfer + if _transfer['type'] == 'onebond' + and (_dim_id1 in [_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']] + or _dim_id2 in [_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']])): + cases += 1 + max_corr_eff = max(max_corr_eff, numpy.corrcoef(_dict1['freq_hint'], _dict2['freq_hint'])[0][1]) + + if cases == 1: + for _dim_id2, _dict2 in cur_spectral_dim.items(): + _region2 = _dict2['spectral_region'] + if (_region1 == 'H_ami' and _region2 == 'N_ami')\ + or (_region1 == 'H_ali' and _region2 == 'C_ali')\ + or (_region1 == 'H_aro' and _region2 == 'C_aro'): + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + if not any(_transfer for _transfer in cur_spectral_dim_transfer + if _transfer['type'] == 'onebond' + and (_dim_id1 in [_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']] + or _dim_id2 in [_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']])): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'onebond', + 'indirect': 'no'} + cur_spectral_dim_transfer.append(transfer) + + elif cases > 1: + for _dim_id2, _dict2 in cur_spectral_dim.items(): + _region2 = _dict2['spectral_region'] + if (_region1 == 'H_ami' and _region2 == 'N_ami')\ + or (_region1 == 'H_ali' and _region2 == 'C_ali')\ + or (_region1 == 'H_aro' and _region2 == 'C_aro'): + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + if not any(_transfer for _transfer in cur_spectral_dim_transfer + if _transfer['type'] == 'onebond' + and (_dim_id1 in [_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']] + or _dim_id2 in [_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']])): + if numpy.corrcoef(_dict1['freq_hint'], _dict2['freq_hint'])[0][1] < max_corr_eff: + continue + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'onebond', + 'indirect': 'no'} + cur_spectral_dim_transfer.append(transfer) + + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 in ('H_ami', 'H_ali', 'H_aro'): + for _dim_id2, _dict2 in cur_spectral_dim.items(): + _region2 = _dict2['spectral_region'] + if (_region1 == 'H_ami' and _region2 == 'N_ami')\ + or (_region1 == 'H_ali' and _region2 == 'C_ali')\ + or (_region1 == 'H_aro' and _region2 == 'C_aro'): + if _dict1['acquisition'] == 'no' and _dict2['acquisition'] == 'no': + if not any(_transfer for _transfer in cur_spectral_dim_transfer + if _transfer['type'] == 'onebond' + and (_dim_id1 in [_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']] + or _dim_id2 in [_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']])): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'onebond', + 'indirect': 'no'} + cur_spectral_dim_transfer.append(transfer) + + # jcoupling: 'Transfer via direct J coupling over one or more bonds' + if 'copy' in file_name or 'copy' in alt_file_name: + if d == 2: + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _iso_num1 = _dict1['atom_isotope_number'] + if _iso_num1 == 1: + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _iso_num1 != _dict2['atom_isotope_number']: + continue + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'jcoupling', + 'indirect': 'no'} + cur_spectral_dim_transfer.append(transfer) + + elif d == 3: + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 == 'H_ami': + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _dict2['atom_isotope_number'] not in (1, 13): + continue + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'jcoupling', + 'indirect': 'yes'} + cur_spectral_dim_transfer.append(transfer) + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 == 'H_ali': + for _dim_id2, _dict2 in cur_spectral_dim.items(): + _isotope2 = _dict2['atom_isotope'] + if _dim_id1 == _dim_id2 or _isotope2 not in (1, 13): + continue + if _isotope2 == 13\ + and not any(_transfer for _transfer in cur_spectral_dim_transfer + if _transfer['type'] == 'onebond' + and {_dim_id1, _dim_id2} == {_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']}): + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'jcoupling', + 'indirect': 'yes' if _isotope2 == 1 else 'no'} + cur_spectral_dim_transfer.append(transfer) + + elif d == 4: + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 == 'H_ami': + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _dict2['atom_isotope_number'] != 1: + continue + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'jcoupling', + 'indirect': 'yes'} + cur_spectral_dim_transfer.append(transfer) + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 == 'H_ali': + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _dict2['atom_isotope_number'] != 1: + continue + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'jcoupling', + 'indirect': 'no'} + cur_spectral_dim_transfer.append(transfer) + + # jmultibond: 'Transfer via direct J coupling over multiple bonds' + + # relayed: 'Transfer via multiple successive J coupling steps (TOCSY relay)' + if 'tocsy' in file_name or 'tocsy' in alt_file_name: + if d == 2: + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _iso_num1 = _dict1['atom_isotope_number'] + if _iso_num1 == 1: + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _iso_num1 != _dict2['atom_isotope_number']: + continue + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'relayed', + 'indirect': 'no'} + cur_spectral_dim_transfer.append(transfer) + + elif d == 3: + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 == 'H_ami': + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _dict2['atom_isotope_number'] not in (1, 13): + continue + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'relayed', + 'indirect': 'yes'} + cur_spectral_dim_transfer.append(transfer) + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 == 'H_ali': + for _dim_id2, _dict2 in cur_spectral_dim.items(): + _isotope2 = _dict2['atom_isotope'] + if _dim_id1 == _dim_id2 or _isotope2 not in (1, 13): + continue + if _isotope2 == 13\ + and not any(_transfer for _transfer in cur_spectral_dim_transfer + if _transfer['type'] == 'onebond' + and {_dim_id1, _dim_id2} == {_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']}): + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'relayed', + 'indirect': 'yes' if _isotope2 == 1 else 'no'} + cur_spectral_dim_transfer.append(transfer) + + elif d == 4: + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 == 'H_ami': + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _dict2['atom_isotope_number'] != 1: + continue + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'relayed', + 'indirect': 'yes'} + cur_spectral_dim_transfer.append(transfer) + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 == 'H_ali': + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _dict2['atom_isotope_number'] != 1: + continue + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'relayed', + 'indirect': 'no'} + cur_spectral_dim_transfer.append(transfer) + + # relayed-alternate: 'Relayed transfer where peaks from an odd resp. even number of transfer steps have opposite sign' + + # through-space: 'Any transfer that does not go through the covalent bonded skeleton + if 'noe' in file_name or 'roe' in file_name or 'rfdr' in file_name\ + or 'noe' in alt_file_name or 'roe' in alt_file_name or 'rfdr' in alt_file_name: + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 in ('H_ami', 'H_ali', 'H_aro') and d > 2: + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _dict1['atom_isotope_number'] != _dict2['atom_isotope_number']: + continue + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'through-space', + 'indirect': 'yes'} + cur_spectral_dim_transfer.append(transfer) + + if self.exptlMethod == 'SOLID-STATE NMR': + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _iso_num1 = _dict1['atom_isotope_number'] + if _iso_num1 in (1, 13): + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _iso_num1 != _dict2['atom_isotope_number']: + continue + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'through-space', + 'indirect': 'yes'} + cur_spectral_dim_transfer.append(transfer) + + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _region1 = _dict1['spectral_region'] + if _region1 in ('H_ami', 'H_ali', 'H_aro') and d > 2: + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _dict1['atom_isotope_number'] != _dict2['atom_isotope_number']: + continue + if not any(_transfer for _transfer in cur_spectral_dim_transfer + if {_dim_id1, _dim_id2} == {_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']}): + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'through-space?', + 'indirect': 'yes'} + cur_spectral_dim_transfer.append(transfer) + + if self.exptlMethod == 'SOLID-STATE NMR': + for _dim_id1, _dict1 in cur_spectral_dim.items(): + _iso_num1 = _dict1['atom_isotope_number'] + if _iso_num1 in (1, 13): + for _dim_id2, _dict2 in cur_spectral_dim.items(): + if _dim_id1 == _dim_id2 or _iso_num1 != _dict2['atom_isotope_number']: + continue + if not any(_transfer for _transfer in cur_spectral_dim_transfer + if {_dim_id1, _dim_id2} == {_transfer['spectral_dim_id_1'], _transfer['spectral_dim_id_2']}): + if 'yes' in (_dict1['acquisition'], _dict2['acquisition']): + transfer = {'spectral_dim_id_1': min([_dim_id1, _dim_id2]), + 'spectral_dim_id_2': max([_dim_id1, _dim_id2]), + 'type': 'through-space?', + 'indirect': 'yes'} + cur_spectral_dim_transfer.append(transfer) + + for __v in cur_spectral_dim.values(): + if 'freq_hint' in __v: + del __v['freq_hint'] + + if self.debug: + print(f'num_of_dim: {d}, list_id: {_id}') + print('spectral_dim') + for __d, __v in cur_spectral_dim.items(): + print(f'{__d} {__v}') + print('spectral_dim_transfer') + for transfer in cur_spectral_dim_transfer: + print(transfer) def validatePeak2D(self, index: int, pos_1: float, pos_2: float, pos_unc_1: Optional[float], pos_unc_2: Optional[float], diff --git a/wwpdb/utils/nmr/pk/NmrPipePKParserListener.py b/wwpdb/utils/nmr/pk/NmrPipePKParserListener.py index 80cbca27..53214815 100644 --- a/wwpdb/utils/nmr/pk/NmrPipePKParserListener.py +++ b/wwpdb/utils/nmr/pk/NmrPipePKParserListener.py @@ -9,8 +9,6 @@ import sys import re import copy -import collections -import numpy as np import math from antlr4 import ParseTreeListener @@ -61,52 +59,6 @@ def enterNmrpipe_pk(self, ctx: NmrPipePKParser.Nmrpipe_pkContext): # pylint: di # Exit a parse tree produced by DynamoMRParser#dynamo_mr. def exitNmrpipe_pk(self, ctx: NmrPipePKParser.Nmrpipe_pkContext): # pylint: disable=unused-argument - - if len(self.spectral_dim) > 0: - for d, v in self.spectral_dim.items(): - for _id, _v in v.items(): - for __v in _v.values(): - if 'freq_hint' in __v: - if len(__v['freq_hint']) > 0: - center = np.mean(np.array(__v['freq_hint'])) - - if __v['spectral_region'] is None: - atom_type = __v['atom_type'] - if 125 < center < 130 and atom_type == 'C': - __v['spectral_region'] = 'C_aro' - elif 115 < center < 125 and atom_type == 'N': - __v['spectral_region'] = 'N_ami' - elif 170 < center < 180 and atom_type == 'C': - __v['spectral_region'] = 'CO' - elif 6 < center < 9 and atom_type == 'H': - __v['spectral_region'] = 'H_ami_or_aro' - elif 4 < center < 6 and atom_type == 'H': - __v['spectral_region'] = 'H_all' - elif 2 < center < 4 and atom_type == 'H': - __v['spectral_region'] = 'H_ali' - elif 60 < center < 90 and atom_type == 'C': - __v['spectral_region'] = 'C_all' - elif 30 < center < 50 and atom_type == 'C': - __v['spectral_region'] = 'C_ali' - - del __v['freq_hint'] - - if __v['spectrometer_frequency'] is None and 'obs_freq_hint' in __v and len(__v['obs_freq_hint']) > 0: - __v['spectrometer_frequency'] = collections.Counter(__v['obs_freq_hint']).most_common()[0][0] - - if 'obs_freq_hint' in __v: - del __v['obs_freq_hint'] - - for __v in _v.values(): - if __v['spectral_region'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['spectral_region'] = 'H_aro' if has_a else 'H_ami' - - if self.debug: - print(f'num_of_dim: {d}, list_id: {_id}') - for __d, __v in _v.items(): - print(f'{__d} {__v}') - self.exit() # Enter a parse tree produced by NmrPipePKParser#data_label. @@ -169,14 +121,30 @@ def set_spectral_dim(_dim_id): cur_spectral_dim['center_frequency_offset'] = roundString(str((first_ppm + last_ppm) / 2.0), max_eff_digits) - if truncated: + if truncated and isotope_number in (1, 13, 15): _last_point = int(pow(2.0, round_log2_last_point + 1.0)) scale = float(_last_point) / float(last_point - first_point - 1) - cur_spectral_dim['sweep_width'] = roundString(str((first_ppm - last_ppm) * scale), - max_eff_digits) + center = first_ppm - (first_ppm - last_ppm) * scale / 2 + + if isotope_number == 1: + if not 4 < center < 6: + __last_point = _last_point + _last_point / 2 + _scale = float(__last_point) / float(last_point - first_point - 1) + center = first_ppm - (first_ppm - last_ppm) * _scale / 2 + if 4 < center < 6: + scale = _scale + else: + __last_point = _last_point + _last_point + _scale = float(__last_point) / float(last_point - first_point - 1) + center = first_ppm - (first_ppm - last_ppm) * _scale / 2 + if 4 < center < 6: + scale = _scale + + cur_spectral_dim['sweep_width'] = float(roundString(str((first_ppm - last_ppm) * scale), + max_eff_digits)) else: - cur_spectral_dim['sweep_width'] = roundString(str(first_ppm - last_ppm), - max_eff_digits) + cur_spectral_dim['sweep_width'] = float(roundString(str(first_ppm - last_ppm), + max_eff_digits)) cur_spectral_dim['sweep_width_unit'] = 'ppm' diff --git a/wwpdb/utils/nmr/pk/NmrViewPKParserListener.py b/wwpdb/utils/nmr/pk/NmrViewPKParserListener.py index 26f5e3ca..515824aa 100644 --- a/wwpdb/utils/nmr/pk/NmrViewPKParserListener.py +++ b/wwpdb/utils/nmr/pk/NmrViewPKParserListener.py @@ -9,7 +9,6 @@ import sys import re import copy -import numpy as np from antlr4 import ParseTreeListener @@ -59,51 +58,6 @@ def enterNmrview_pk(self, ctx: NmrViewPKParser.Nmrview_pkContext): # pylint: di # Exit a parse tree produced by NmrViewPKParser#nmrview_pk. def exitNmrview_pk(self, ctx: NmrViewPKParser.Nmrview_pkContext): # pylint: disable=unused-argument - - if len(self.spectral_dim) > 0: - for d, v in self.spectral_dim.items(): - for _id, _v in v.items(): - for __d, __v in _v.items(): - if 'freq_hint' in __v: - if len(__v['freq_hint']) > 0: - center = np.mean(np.array(__v['freq_hint'])) - - if __v['spectral_region'] is None: - atom_type = __v['atom_type'] - if 125 < center < 130 and atom_type == 'C': - __v['spectral_region'] = 'C_aro' - elif 115 < center < 125 and atom_type == 'N': - __v['spectral_region'] = 'N_ami' - elif 170 < center < 180 and atom_type == 'C': - __v['spectral_region'] = 'CO' - elif 6 < center < 9 and atom_type == 'H': - __v['spectral_region'] = 'H_ami_or_aro' - elif 4 < center < 6 and atom_type == 'H': - __v['spectral_region'] = 'H_all' - elif 2 < center < 4 and atom_type == 'H': - __v['spectral_region'] = 'H_ali' - elif 60 < center < 90 and atom_type == 'C': - __v['spectral_region'] = 'C_all' - elif 30 < center < 50 and atom_type == 'C': - __v['spectral_region'] = 'C_ali' - - if len(__v['freq_hint']) > 0 and d > 2 and __d >= 2\ - and self.exptlMethod != 'SOLID-STATE NMR' and __v['atom_isotope_number'] == 13: - if center < 100.0 and __v['sweep_width'] / __v['spectrometer_frequency'] < 50.0: - __v['under_sampling_type'] = 'fold' - - del __v['freq_hint'] - - for __v in _v.values(): - if __v['spectral_region'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['spectral_region'] = 'H_aro' if has_a else 'H_ami' - - if self.debug: - print(f'num_of_dim: {d}, list_id: {_id}') - for __d, __v in _v.items(): - print(f'{__d} {__v}') - self.exit() # Enter a parse tree produced by NmrViewPKParser#data_label. @@ -176,13 +130,13 @@ def exitLabels(self, ctx: NmrViewPKParser.LabelsContext): # pylint: disable=unu elif self.__cur_label_type == 'sw': for _dim_id, _spectral_width in enumerate(labels, start=1): - self.cur_spectral_dim[_dim_id]['sweep_width'] = _spectral_width + self.cur_spectral_dim[_dim_id]['sweep_width'] = float(_spectral_width) self.cur_spectral_dim[_dim_id]['sweep_width_unit'] = 'Hz' elif self.__cur_label_type == 'sf': for _dim_id, _freq in enumerate(labels, start=1): - self.cur_spectral_dim[_dim_id]['spectrometer_frequency'] = _freq + self.cur_spectral_dim[_dim_id]['spectrometer_frequency'] = float(_freq) # Enter a parse tree produced by NmrViewPKParser#peak_list_2d. def enterPeak_list_2d(self, ctx: NmrViewPKParser.Peak_list_2dContext): # pylint: disable=unused-argument diff --git a/wwpdb/utils/nmr/pk/SparkyPKParserListener.py b/wwpdb/utils/nmr/pk/SparkyPKParserListener.py index dea0346a..052c120c 100644 --- a/wwpdb/utils/nmr/pk/SparkyPKParserListener.py +++ b/wwpdb/utils/nmr/pk/SparkyPKParserListener.py @@ -7,7 +7,6 @@ @author: Masashi Yokochi """ import sys -import numpy as np from antlr4 import ParseTreeListener @@ -49,103 +48,6 @@ def enterSparky_pk(self, ctx: SparkyPKParser.Sparky_pkContext): # pylint: disab # Exit a parse tree produced by SparkyPKParser#sparky_pk. def exitSparky_pk(self, ctx: SparkyPKParser.Sparky_pkContext): # pylint: disable=unused-argument - - if len(self.spectral_dim) > 0: - for d, v in self.spectral_dim.items(): - for _id, _v in v.items(): - self.acq_dim_id = 1 - for __d, __v in _v.items(): - if 'freq_hint' in __v: - if len(__v['freq_hint']) > 0: - center = np.mean(np.array(__v['freq_hint'])) - - if __v['atom_isotope_number'] is None: - if 125 < center < 130: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C_aro' - elif 115 < center < 125: - __v['atom_type'] = 'N' - __v['atom_isotope_number'] = 15 - __v['axis_code'] = 'N_ami' - elif 170 < center < 180: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'CO' - elif 6 < center < 9: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H_ami_or_aro' - elif 4 < center < 6: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H' - elif 2 < center < 4: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H_ali' - elif 60 < center < 90: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C' - elif 30 < center < 50: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C_ali' - - isotope_number = __v['atom_isotope_number'] - - if isotope_number is not None: - __v['acquisition'] = 'yes' if __d == self.acq_dim_id\ - and (isotope_number == 1 or (isotope_number == 13 and self.exptlMethod == 'SOLID-STATE NMR')) else 'no' - - if __d == 1 and __v['acquisition'] == 'no': - self.acq_dim_id = self.num_of_dim - - __v['under_sampling_type'] = 'not observed' if __v['acquisition'] == 'yes' else 'aliased' - - if __v['spectral_region'] is None and len(__v['freq_hint']) > 0: - atom_type = __v['atom_type'] - if 125 < center < 130 and atom_type == 'C': - __v['spectral_region'] = 'C_aro' - elif 115 < center < 125 and atom_type == 'N': - __v['spectral_region'] = 'N_ami' - elif 170 < center < 180 and atom_type == 'C': - __v['spectral_region'] = 'CO' - elif 6 < center < 9 and atom_type == 'H': - __v['spectral_region'] = 'H_ami_or_aro' - elif 4 < center < 6 and atom_type == 'H': - __v['spectral_region'] = 'H_all' - elif 2 < center < 4 and atom_type == 'H': - __v['spectral_region'] = 'H_ali' - elif 60 < center < 90 and atom_type == 'C': - __v['spectral_region'] = 'C_all' - elif 30 < center < 50 and atom_type == 'C': - __v['spectral_region'] = 'C_ali' - - if len(__v['freq_hint']) > 0 and d > 2 and __d >= 2\ - and self.exptlMethod != 'SOLID-STATE NMR' and __v['atom_isotope_number'] == 13: - max_ppm = max(__v['freq_hint']) - min_ppm = min(__v['freq_hint']) - width = max_ppm - min_ppm - if center < 100.0 and width < 50.0: - __v['under_sampling_type'] = 'fold' - - del __v['freq_hint'] - - for __v in _v.values(): - if __v['axis_code'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['axis_code'] = 'H_aro' if has_a else 'H_ami' - if __v['spectral_region'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['spectral_region'] = 'H_aro' if has_a else 'H_ami' - - if self.debug: - print(f'num_of_dim: {d}, list_id: {_id}') - for __d, __v in _v.items(): - print(f'{__d} {__v}') - self.exit() # Enter a parse tree produced by SparkyPKParser#data_label. diff --git a/wwpdb/utils/nmr/pk/TopSpinPKParserListener.py b/wwpdb/utils/nmr/pk/TopSpinPKParserListener.py index 42e8ae31..75c8eee1 100644 --- a/wwpdb/utils/nmr/pk/TopSpinPKParserListener.py +++ b/wwpdb/utils/nmr/pk/TopSpinPKParserListener.py @@ -7,7 +7,6 @@ @author: Masashi Yokochi """ import sys -import numpy as np from antlr4 import ParseTreeListener @@ -59,107 +58,8 @@ def enterDocument(self, ctx: XMLParser.DocumentContext): # pylint: disable=unus # Exit a parse tree produced by XMLParser#document. def exitDocument(self, ctx: XMLParser.DocumentContext): # pylint: disable=unused-argument - - if len(self.spectral_dim) > 0: - for d, v in self.spectral_dim.items(): - for _id, _v in v.items(): - self.acq_dim_id = 1 - for __d, __v in _v.items(): - if 'freq_hint' in __v: - if len(__v['freq_hint']) > 0: - center = np.mean(np.array(__v['freq_hint'])) - - if __v['atom_isotope_number'] is None: - if 125 < center < 130: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C_aro' - elif 115 < center < 125: - __v['atom_type'] = 'N' - __v['atom_isotope_number'] = 15 - __v['axis_code'] = 'N_ami' - elif 170 < center < 180: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'CO' - elif 6 < center < 9: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H_ami_or_aro' - elif 4 < center < 6: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H' - elif 2 < center < 4: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H_ali' - elif 60 < center < 90: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C' - elif 30 < center < 50: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C_ali' - - isotope_number = __v['atom_isotope_number'] - - if isotope_number is not None: - __v['acquisition'] = 'yes' if __d == self.acq_dim_id\ - and (isotope_number == 1 or (isotope_number == 13 and self.exptlMethod == 'SOLID-STATE NMR')) else 'no' - - if __d == 1 and __v['acquisition'] == 'no': - self.acq_dim_id = self.num_of_dim - - __v['under_sampling_type'] = 'not observed' if __v['acquisition'] == 'yes' else 'aliased' - - if __v['spectral_region'] is None and len(__v['freq_hint']) > 0: - atom_type = __v['atom_type'] - if 125 < center < 130 and atom_type == 'C': - __v['spectral_region'] = 'C_aro' - elif 115 < center < 125 and atom_type == 'N': - __v['spectral_region'] = 'N_ami' - elif 170 < center < 180 and atom_type == 'C': - __v['spectral_region'] = 'CO' - elif 6 < center < 9 and atom_type == 'H': - __v['spectral_region'] = 'H_ami_or_aro' - elif 4 < center < 6 and atom_type == 'H': - __v['spectral_region'] = 'H_all' - elif 2 < center < 4 and atom_type == 'H': - __v['spectral_region'] = 'H_ali' - elif 60 < center < 90 and atom_type == 'C': - __v['spectral_region'] = 'C_all' - elif 30 < center < 50 and atom_type == 'C': - __v['spectral_region'] = 'C_ali' - - if len(__v['freq_hint']) > 0 and d > 2 and __d >= 2\ - and self.exptlMethod != 'SOLID-STATE NMR' and __v['atom_isotope_number'] == 13: - max_ppm = max(__v['freq_hint']) - min_ppm = min(__v['freq_hint']) - width = max_ppm - min_ppm - if center < 100.0 and width < 50.0: - __v['under_sampling_type'] = 'fold' - - del __v['freq_hint'] - - for __v in _v.values(): - if __v['axis_code'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['axis_code'] = 'H_aro' if has_a else 'H_ami' - if __v['spectral_region'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['spectral_region'] = 'H_aro' if has_a else 'H_ami' - - if self.debug: - print(f'num_of_dim: {d}, list_id: {_id}') - for __d, __v in _v.items(): - print(f'{__d} {__v}') - self.exit() - self.__cur_path = None - # Enter a parse tree produced by XMLParser#prolog. def enterProlog(self, ctx: XMLParser.PrologContext): # pylint: disable=unused-argument pass diff --git a/wwpdb/utils/nmr/pk/XeasyPKParserListener.py b/wwpdb/utils/nmr/pk/XeasyPKParserListener.py index cc78e27d..8fb7b613 100644 --- a/wwpdb/utils/nmr/pk/XeasyPKParserListener.py +++ b/wwpdb/utils/nmr/pk/XeasyPKParserListener.py @@ -8,7 +8,6 @@ """ import sys import re -import numpy as np from antlr4 import ParseTreeListener @@ -18,7 +17,6 @@ from wwpdb.utils.nmr.mr.ParserListenerUtil import (ISOTOPE_NUMBERS_OF_NMR_OBS_NUCS, REPRESENTATIVE_MODEL_ID, REPRESENTATIVE_ALT_ID, - SPECTRAL_DIM_TEMPLATE, getPkRow) from wwpdb.utils.nmr.AlignUtil import emptyValue @@ -28,7 +26,6 @@ from nmr.mr.ParserListenerUtil import (ISOTOPE_NUMBERS_OF_NMR_OBS_NUCS, REPRESENTATIVE_MODEL_ID, REPRESENTATIVE_ALT_ID, - SPECTRAL_DIM_TEMPLATE, getPkRow) from nmr.AlignUtil import emptyValue @@ -59,103 +56,6 @@ def enterXeasy_pk(self, ctx: XeasyPKParser.Xeasy_pkContext): # pylint: disable= # Exit a parse tree produced by XeasyPKParser#xeasy_pk. def exitXeasy_pk(self, ctx: XeasyPKParser.Xeasy_pkContext): # pylint: disable=unused-argument - - if len(self.spectral_dim) > 0: - for d, v in self.spectral_dim.items(): - for _id, _v in v.items(): - self.acq_dim_id = 1 - for __d, __v in _v.items(): - if 'freq_hint' in __v: - if len(__v['freq_hint']) > 0: - center = np.mean(np.array(__v['freq_hint'])) - - if __v['atom_isotope_number'] is None: - if 125 < center < 130: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C_aro' - elif 115 < center < 125: - __v['atom_type'] = 'N' - __v['atom_isotope_number'] = 15 - __v['axis_code'] = 'N_ami' - elif 170 < center < 180: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'CO' - elif 6 < center < 9: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H_ami_or_aro' - elif 4 < center < 6: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H' - elif 2 < center < 4: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H_ali' - elif 60 < center < 90: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C' - elif 30 < center < 50: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C_ali' - - isotope_number = __v['atom_isotope_number'] - - if isotope_number is not None: - __v['acquisition'] = 'yes' if __d == self.acq_dim_id\ - and (isotope_number == 1 or (isotope_number == 13 and self.exptlMethod == 'SOLID-STATE NMR')) else 'no' - - if __d == 1 and __v['acquisition'] == 'no': - self.acq_dim_id = self.num_of_dim - - __v['under_sampling_type'] = 'not observed' if __v['acquisition'] == 'yes' else 'aliased' - - if __v['spectral_region'] is None and len(__v['freq_hint']) > 0: - atom_type = __v['atom_type'] - if 125 < center < 130 and atom_type == 'C': - __v['spectral_region'] = 'C_aro' - elif 115 < center < 125 and atom_type == 'N': - __v['spectral_region'] = 'N_ami' - elif 170 < center < 180 and atom_type == 'C': - __v['spectral_region'] = 'CO' - elif 6 < center < 9 and atom_type == 'H': - __v['spectral_region'] = 'H_ami_or_aro' - elif 4 < center < 6 and atom_type == 'H': - __v['spectral_region'] = 'H_all' - elif 2 < center < 4 and atom_type == 'H': - __v['spectral_region'] = 'H_ali' - elif 60 < center < 90 and atom_type == 'C': - __v['spectral_region'] = 'C_all' - elif 30 < center < 50 and atom_type == 'C': - __v['spectral_region'] = 'C_ali' - - if len(__v['freq_hint']) > 0 and d > 2 and __d >= 2\ - and self.exptlMethod != 'SOLID-STATE NMR' and __v['atom_isotope_number'] == 13: - max_ppm = max(__v['freq_hint']) - min_ppm = min(__v['freq_hint']) - width = max_ppm - min_ppm - if center < 100.0 and width < 50.0: - __v['under_sampling_type'] = 'fold' - - del __v['freq_hint'] - - for __v in _v.values(): - if __v['axis_code'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['axis_code'] = 'H_aro' if has_a else 'H_ami' - if __v['spectral_region'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['spectral_region'] = 'H_aro' if has_a else 'H_ami' - - if self.debug: - print(f'num_of_dim: {d}, list_id: {_id}') - for __d, __v in _v.items(): - print(f'{__d} {__v}') - self.exit() # Enter a parse tree produced by XeasyPKParser#dimension. diff --git a/wwpdb/utils/nmr/pk/XwinNmrPKParserListener.py b/wwpdb/utils/nmr/pk/XwinNmrPKParserListener.py index 6b671fbd..0fade592 100644 --- a/wwpdb/utils/nmr/pk/XwinNmrPKParserListener.py +++ b/wwpdb/utils/nmr/pk/XwinNmrPKParserListener.py @@ -7,7 +7,6 @@ @author: Masashi Yokochi """ import sys -import numpy as np from antlr4 import ParseTreeListener @@ -54,103 +53,6 @@ def enterXwinnmr_pk(self, ctx: XwinNmrPKParser.Xwinnmr_pkContext): # pylint: di # Exit a parse tree produced by XwinNmrPKParser#xwinnmr_pk. def exitXwinnmr_pk(self, ctx: XwinNmrPKParser.Xwinnmr_pkContext): # pylint: disable=unused-argument - - if len(self.spectral_dim) > 0: - for d, v in self.spectral_dim.items(): - for _id, _v in v.items(): - self.acq_dim_id = 1 - for __d, __v in _v.items(): - if 'freq_hint' in __v: - if len(__v['freq_hint']) > 0: - center = np.mean(np.array(__v['freq_hint'])) - - if __v['atom_isotope_number'] is None: - if 125 < center < 130: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C_aro' - elif 115 < center < 125: - __v['atom_type'] = 'N' - __v['atom_isotope_number'] = 15 - __v['axis_code'] = 'N_ami' - elif 170 < center < 180: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'CO' - elif 6 < center < 9: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H_ami_or_aro' - elif 4 < center < 6: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H' - elif 2 < center < 4: - __v['atom_type'] = 'H' - __v['atom_isotope_number'] = 1 - __v['axis_code'] = 'H_ali' - elif 60 < center < 90: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C' - elif 30 < center < 50: - __v['atom_type'] = 'C' - __v['atom_isotope_number'] = 13 - __v['axis_code'] = 'C_ali' - - isotope_number = __v['atom_isotope_number'] - - if isotope_number is not None: - __v['acquisition'] = 'yes' if __d == self.acq_dim_id\ - and (isotope_number == 1 or (isotope_number == 13 and self.exptlMethod == 'SOLID-STATE NMR')) else 'no' - - if __d == 1 and __v['acquisition'] == 'no': - self.acq_dim_id = self.num_of_dim - - __v['under_sampling_type'] = 'not observed' if __v['acquisition'] == 'yes' else 'aliased' - - if __v['spectral_region'] is None and len(__v['freq_hint']) > 0: - atom_type = __v['atom_type'] - if 125 < center < 130 and atom_type == 'C': - __v['spectral_region'] = 'C_aro' - elif 115 < center < 125 and atom_type == 'N': - __v['spectral_region'] = 'N_ami' - elif 170 < center < 180 and atom_type == 'C': - __v['spectral_region'] = 'CO' - elif 6 < center < 9 and atom_type == 'H': - __v['spectral_region'] = 'H_ami_or_aro' - elif 4 < center < 6 and atom_type == 'H': - __v['spectral_region'] = 'H_all' - elif 2 < center < 4 and atom_type == 'H': - __v['spectral_region'] = 'H_ali' - elif 60 < center < 90 and atom_type == 'C': - __v['spectral_region'] = 'C_all' - elif 30 < center < 50 and atom_type == 'C': - __v['spectral_region'] = 'C_ali' - - if len(__v['freq_hint']) > 0 and d > 2 and __d >= 2\ - and self.exptlMethod != 'SOLID-STATE NMR' and __v['atom_isotope_number'] == 13: - max_ppm = max(__v['freq_hint']) - min_ppm = min(__v['freq_hint']) - width = max_ppm - min_ppm - if center < 100.0 and width < 50.0: - __v['under_sampling_type'] = 'fold' - - del __v['freq_hint'] - - for __v in _v.values(): - if __v['axis_code'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['axis_code'] = 'H_aro' if has_a else 'H_ami' - if __v['spectral_region'] == 'H_ami_or_aro': - has_a = any(___v['spectral_region'] == 'C_aro' for ___v in _v.values()) - __v['spectral_region'] = 'H_aro' if has_a else 'H_ami' - - if self.debug: - print(f'num_of_dim: {d}, list_id: {_id}') - for __d, __v in _v.items(): - print(f'{__d} {__v}') - self.exit() # Enter a parse tree produced by XwinNmrPKParser#comment.