From 8e4d8f62ce64a4c723b80c03f3b5524f3d5c7569 Mon Sep 17 00:00:00 2001 From: yokochi47 Date: Thu, 5 Dec 2024 10:11:28 +0900 Subject: [PATCH] Add SPARKY peak reader and parserlistener with code refactoring --- wwpdb/utils/nmr/mr/ParserListenerUtil.py | 21 +- wwpdb/utils/nmr/pk/BasePKParserListener.py | 317 +++++++ wwpdb/utils/nmr/pk/NmrPipePKParserListener.py | 356 +------- wwpdb/utils/nmr/pk/NmrViewPKParserListener.py | 357 +------- wwpdb/utils/nmr/pk/SparkyPKLexer.py | 306 +++---- wwpdb/utils/nmr/pk/SparkyPKParser.py | 86 +- wwpdb/utils/nmr/pk/SparkyPKParserListener.py | 838 +++++++++++++++++- wwpdb/utils/nmr/pk/SparkyPKReader.py | 216 +++++ wwpdb/utils/nmr/pk/XeasyPKLexer.py | 280 +++--- wwpdb/utils/nmr/pk/XeasyPKParser.py | 254 ++++-- wwpdb/utils/nmr/pk/XeasyPKParserListener.py | 440 ++------- .../antlr-grammars-v4.10/SparkyPKLexer.g4 | 14 +- .../antlr-grammars-v4.10/XeasyPKLexer.g4 | 2 +- .../antlr-grammars-v4.10/XeasyPKParser.g4 | 9 +- 14 files changed, 1978 insertions(+), 1518 deletions(-) create mode 100644 wwpdb/utils/nmr/pk/SparkyPKReader.py diff --git a/wwpdb/utils/nmr/mr/ParserListenerUtil.py b/wwpdb/utils/nmr/mr/ParserListenerUtil.py index 48555aae..e656e0b4 100644 --- a/wwpdb/utils/nmr/mr/ParserListenerUtil.py +++ b/wwpdb/utils/nmr/mr/ParserListenerUtil.py @@ -10006,26 +10006,33 @@ def extractPeakAssignment(numOfDim: int, string: str, segIdSet: Set[str], compId resIdLike[idx] = True resIdSpan[idx] = resIdTest.span() + minIndex = len(term) + for compId in compIdSet: if compId in term: resNameLike[idx] = True index = term.index(compId) - resNameSpan[idx] = (index, index + len(compId)) - break + if index < minIndex: + resNameSpan[idx] = (index, index + len(compId)) + minIndex = index + if not resNameLike[idx]: for compId in altCompIdSet: if compId in term: resNameLike[idx] = True index = term.index(compId) - resNameSpan[idx] = (index, index + len(compId)) - break + if index < minIndex: + resNameSpan[idx] = (index, index + len(compId)) + minIndex = index + if not resNameLike[idx] and aaOnly: for compId in oneLetterCodeSet: if compId in term: resNameLike[idx] = True index = term.index(compId) - resNameSpan[idx] = (index, index + len(compId)) - break + if index < minIndex: + resNameSpan[idx] = (index, index + len(compId)) + minIndex = index for elem in PEAK_HALF_SPIN_NUCLEUS: if len(elem) == 1: @@ -10247,4 +10254,4 @@ def extractPeakAssignment(numOfDim: int, string: str, segIdSet: Set[str], compId dimId += 1 ret.append({'dim_id': dimId, 'chain_id': segId, 'seq_id': resId, 'comp_id': resName, 'atom_id': atomName}) - return ret if len(ret) == numOfDim else None + return ret if len(ret) == numOfDim else None # ignore multiple assignments for a peak diff --git a/wwpdb/utils/nmr/pk/BasePKParserListener.py b/wwpdb/utils/nmr/pk/BasePKParserListener.py index 45b9ba49..637de37f 100644 --- a/wwpdb/utils/nmr/pk/BasePKParserListener.py +++ b/wwpdb/utils/nmr/pk/BasePKParserListener.py @@ -44,6 +44,7 @@ from wwpdb.utils.nmr.NEFTranslator.NEFTranslator import NEFTranslator from wwpdb.utils.nmr.AlignUtil import (LARGE_ASYM_ID, monDict3, + emptyValue, protonBeginCode, pseProBeginCode, aminoProtonCode, @@ -53,13 +54,22 @@ isReservedLigCode, updatePolySeqRst, revertPolySeqRst, + sortPolySeqRst, + syncCompIdOfPolySeqRst, + alignPolymerSequence, + assignPolymerSequence, + trimSequenceAlignment, updatePolySeqRstAmbig, retrieveAtomIdentFromMRMap, retrieveAtomIdFromMRMap, retrieveRemappedSeqId, retrieveRemappedSeqIdAndCompId, + splitPolySeqRstForMultimers, + splitPolySeqRstForExactNoes, retrieveRemappedChainId, + splitPolySeqRstForNonPoly, retrieveRemappedNonPoly, + splitPolySeqRstForBranched, retrieveOriginalSeqIdFromMRMap) except ImportError: from nmr.io.CifReader import (CifReader, SYMBOLS_ELEMENT) @@ -90,6 +100,7 @@ from nmr.NEFTranslator.NEFTranslator import NEFTranslator from nmr.AlignUtil import (LARGE_ASYM_ID, monDict3, + emptyValue, protonBeginCode, pseProBeginCode, aminoProtonCode, @@ -99,13 +110,22 @@ isReservedLigCode, updatePolySeqRst, revertPolySeqRst, + sortPolySeqRst, + syncCompIdOfPolySeqRst, + alignPolymerSequence, + assignPolymerSequence, + trimSequenceAlignment, updatePolySeqRstAmbig, retrieveAtomIdentFromMRMap, retrieveAtomIdFromMRMap, retrieveRemappedSeqId, retrieveRemappedSeqIdAndCompId, + splitPolySeqRstForMultimers, + splitPolySeqRstForExactNoes, retrieveRemappedChainId, + splitPolySeqRstForNonPoly, retrieveRemappedNonPoly, + splitPolySeqRstForBranched, retrieveOriginalSeqIdFromMRMap) @@ -374,6 +394,303 @@ def setListIdCounter(self, listIdCounter: dict): def setEntryId(self, entryId: str): self.entryId = entryId + def exit(self): + + try: + + if self.hasPolySeq and self.polySeqRst is not None: + sortPolySeqRst(self.polySeqRst, + None if self.reasons is None else self.reasons.get('non_poly_remap')) + + self.seqAlign, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRst, + resolvedMultimer=self.reasons is not None) + self.chainAssign, message = assignPolymerSequence(self.pA, self.ccU, self.file_type, self.polySeq, self.polySeqRst, self.seqAlign) + + if len(message) > 0: + self.f.extend(message) + + if self.chainAssign is not None: + + if len(self.polySeq) == len(self.polySeqRst): + + chain_mapping = {} + + for ca in self.chainAssign: + ref_chain_id = ca['ref_chain_id'] + test_chain_id = ca['test_chain_id'] + + if ref_chain_id != test_chain_id: + chain_mapping[test_chain_id] = ref_chain_id + + if len(chain_mapping) == len(self.polySeq): + + for ps in self.polySeqRst: + if ps['chain_id'] in chain_mapping: + ps['chain_id'] = chain_mapping[ps['chain_id']] + + self.seqAlign, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRst, + resolvedMultimer=self.reasons is not None) + self.chainAssign, _ = assignPolymerSequence(self.pA, self.ccU, self.file_type, self.polySeq, self.polySeqRst, self.seqAlign) + + trimSequenceAlignment(self.seqAlign, self.chainAssign) + + if self.reasons is None and any(f for f in self.f + if '[Atom not found]' in f or '[Sequence mismatch]' in f): + + seqIdRemap = [] + + cyclicPolymer = {} + + for ca in self.chainAssign: + ref_chain_id = ca['ref_chain_id'] + test_chain_id = ca['test_chain_id'] + + sa = next(sa for sa in self.seqAlign + if sa['ref_chain_id'] == ref_chain_id + and sa['test_chain_id'] == test_chain_id) + + poly_seq_model = next(ps for ps in self.polySeq + if ps['auth_chain_id'] == ref_chain_id) + poly_seq_rst = next(ps for ps in self.polySeqRst + if ps['chain_id'] == test_chain_id) + + seq_id_mapping = {} + offset = None + for ref_seq_id, mid_code, test_seq_id in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id']): + if test_seq_id is None: + continue + if mid_code == '|': + try: + seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id + in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) + if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) + if offset is None: + offset = seq_id_mapping[test_seq_id] - test_seq_id + except StopIteration: + pass + elif mid_code == ' ' and test_seq_id in poly_seq_rst['seq_id']: + idx = poly_seq_rst['seq_id'].index(test_seq_id) + if poly_seq_rst['comp_id'][idx] == '.' and poly_seq_rst['auth_comp_id'][idx] not in emptyValue: + seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id + in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) + if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) + + if offset is not None and all(v - k == offset for k, v in seq_id_mapping.items()): + test_seq_id_list = list(seq_id_mapping.keys()) + min_test_seq_id = min(test_seq_id_list) + max_test_seq_id = max(test_seq_id_list) + for test_seq_id in range(min_test_seq_id + 1, max_test_seq_id): + if test_seq_id not in seq_id_mapping: + seq_id_mapping[test_seq_id] = test_seq_id + offset + + if ref_chain_id not in cyclicPolymer: + cyclicPolymer[ref_chain_id] =\ + isCyclicPolymer(self.cR, self.polySeq, ref_chain_id, + self.representativeModelId, self.representativeAltId, self.modelNumName) + + if cyclicPolymer[ref_chain_id]: + + poly_seq_model = next(ps for ps in self.polySeq + if ps['auth_chain_id'] == ref_chain_id) + + offset = None + for seq_id, comp_id in zip(poly_seq_rst['seq_id'], poly_seq_rst['comp_id']): + if seq_id is not None and seq_id not in seq_id_mapping: + _seq_id = next((_seq_id for _seq_id, _comp_id in zip(poly_seq_model['seq_id'], poly_seq_model['comp_id']) + if _seq_id not in seq_id_mapping.values() and _comp_id == comp_id), None) + if _seq_id is not None: + offset = seq_id - _seq_id + break + + if offset is not None: + for seq_id in poly_seq_rst['seq_id']: + if seq_id is not None and seq_id not in seq_id_mapping: + seq_id_mapping[seq_id] = seq_id - offset + + if any(k for k, v in seq_id_mapping.items() if k != v)\ + and not any(k for k, v in seq_id_mapping.items() + if v in poly_seq_model['seq_id'] + and k == poly_seq_model['auth_seq_id'][poly_seq_model['seq_id'].index(v)]): + seqIdRemap.append({'chain_id': test_chain_id, 'seq_id_dict': seq_id_mapping}) + + if len(seqIdRemap) > 0: + if 'seq_id_remap' not in self.reasonsForReParsing: + self.reasonsForReParsing['seq_id_remap'] = seqIdRemap + + if any(ps for ps in self.polySeq if 'identical_chain_id' in ps): + polySeqRst, chainIdMapping = splitPolySeqRstForMultimers(self.pA, self.polySeq, self.polySeqRst, self.chainAssign) + + if polySeqRst is not None and (not self.hasNonPoly or len(self.polySeq) // len(self.nonPoly) in (1, 2)): + self.polySeqRst = polySeqRst + if 'chain_id_remap' not in self.reasonsForReParsing: + self.reasonsForReParsing['chain_id_remap'] = chainIdMapping + + if len(self.polySeq) == 1 and len(self.polySeqRst) == 1: + polySeqRst, chainIdMapping, _ =\ + splitPolySeqRstForExactNoes(self.pA, self.polySeq, self.polySeqRst, self.chainAssign) + + if polySeqRst is not None: + self.polySeqRst = polySeqRst + if 'chain_id_clone' not in self.reasonsForReParsing: + self.reasonsForReParsing['chain_id_clone'] = chainIdMapping + + if self.hasNonPoly: + polySeqRst, nonPolyMapping = splitPolySeqRstForNonPoly(self.ccU, self.nonPoly, self.polySeqRst, + self.seqAlign, self.chainAssign) + + if polySeqRst is not None: + self.polySeqRst = polySeqRst + if 'non_poly_remap' not in self.reasonsForReParsing: + self.reasonsForReParsing['non_poly_remap'] = nonPolyMapping + + if self.hasBranched: + polySeqRst, branchedMapping = splitPolySeqRstForBranched(self.pA, self.polySeq, self.branched, self.polySeqRst, + self.chainAssign) + + if polySeqRst is not None: + self.polySeqRst = polySeqRst + if 'branched_remap' not in self.reasonsForReParsing: + self.reasonsForReParsing['branched_remap'] = branchedMapping + + if len(self.polySeqRstFailed) > 0: + sortPolySeqRst(self.polySeqRstFailed) + if not any(f for f in self.f if '[Sequence mismatch]' in f): # 2n6y + syncCompIdOfPolySeqRst(self.polySeqRstFailed, self.compIdMap) # 2mx9 + + seqAlignFailed, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRstFailed) + chainAssignFailed, _ = assignPolymerSequence(self.pA, self.ccU, self.file_type, + self.polySeq, self.polySeqRstFailed, seqAlignFailed) + + if chainAssignFailed is not None: + seqIdRemapFailed = [] + + uniq_ps = not any('identical_chain_id' in ps for ps in self.polySeq) + + for ca in chainAssignFailed: + if ca['conflict'] > 0: + continue + ref_chain_id = ca['ref_chain_id'] + test_chain_id = ca['test_chain_id'] + + sa = next((sa for sa in seqAlignFailed + if sa['ref_chain_id'] == ref_chain_id + and sa['test_chain_id'] == test_chain_id), None) + + if sa is None: + continue + + poly_seq_model = next(ps for ps in self.polySeq + if ps['auth_chain_id'] == ref_chain_id) + + seq_id_mapping = {} + for ref_seq_id, mid_code, test_seq_id in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id']): + if test_seq_id is None: + continue + if mid_code == '|': + try: + seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id + in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) + if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) + except StopIteration: + if uniq_ps: + seq_id_mapping[test_seq_id] = ref_seq_id + + offset = None + offsets = [v - k for k, v in seq_id_mapping.items()] + if len(offsets) > 0 and ('gap_in_auth_seq' not in poly_seq_model or not poly_seq_model['gap_in_auth_seq']): + offsets = collections.Counter(offsets).most_common() + if len(offsets) > 1: + offset = offsets[0][0] + for k, v in seq_id_mapping.items(): + if v - k != offset: + seq_id_mapping[k] = k + offset + + if uniq_ps and offset is not None and len(seq_id_mapping) > 0\ + and ('gap_in_auth_seq' not in poly_seq_model or not poly_seq_model['gap_in_auth_seq']): + for ref_seq_id, mid_code, test_seq_id, ref_code, test_code in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id'], + sa['ref_code'], sa['test_code']): + if test_seq_id is None: + continue + if mid_code == '|' and test_seq_id not in seq_id_mapping: + seq_id_mapping[test_seq_id] = test_seq_id + offset + elif ref_code != '.' and test_code == '.': + seq_id_mapping[test_seq_id] = test_seq_id + offset + + if any(k for k, v in seq_id_mapping.items() if k != v)\ + and not any(k for k, v in seq_id_mapping.items() + if v in poly_seq_model['seq_id'] + and k == poly_seq_model['auth_seq_id'][poly_seq_model['seq_id'].index(v)]): + seqIdRemapFailed.append({'chain_id': ref_chain_id, 'seq_id_dict': seq_id_mapping, + 'comp_id_set': list(set(poly_seq_model['comp_id']))}) + + if len(seqIdRemapFailed) > 0: + if 'chain_seq_id_remap' not in self.reasonsForReParsing: + seqIdRemap = self.reasonsForReParsing['seq_id_remap'] if 'seq_id_remap' in self.reasonsForReParsing else [] + if len(seqIdRemap) != len(seqIdRemapFailed)\ + or seqIdRemap[0]['chain_id'] != seqIdRemapFailed[0]['chain_id']\ + or not all(src_seq_id in seqIdRemap[0] for src_seq_id in seqIdRemapFailed[0]): + self.reasonsForReParsing['chain_seq_id_remap'] = seqIdRemapFailed + + else: + for ps in self.polySeqRstFailed: + for ca in self.chainAssign: + ref_chain_id = ca['ref_chain_id'] + test_chain_id = ca['test_chain_id'] + + if test_chain_id != ps['chain_id']: + continue + + sa = next(sa for sa in self.seqAlign + if sa['ref_chain_id'] == ref_chain_id + and sa['test_chain_id'] == test_chain_id) + + if len(sa['test_seq_id']) != len(sa['ref_seq_id']): + continue + + poly_seq_model = next(ps for ps in self.polySeq + if ps['auth_chain_id'] == ref_chain_id) + + seq_id_mapping, comp_id_mapping = {}, {} + + for seq_id, comp_id in zip(ps['seq_id'], ps['comp_id']): + if seq_id in sa['test_seq_id']: + idx = sa['test_seq_id'].index(seq_id) + auth_seq_id = sa['ref_seq_id'][idx] + seq_id_mapping[seq_id] = auth_seq_id + comp_id_mapping[seq_id] = comp_id + if any(k for k, v in seq_id_mapping.items() if k != v)\ + or ('label_seq_scheme' not in self.reasonsForReParsing + and all(v not in poly_seq_model['auth_seq_id'] for v in seq_id_mapping.values())): + seqIdRemapFailed.append({'chain_id': ref_chain_id, 'seq_id_dict': seq_id_mapping, + 'comp_id_dict': comp_id_mapping}) + + if len(seqIdRemapFailed) > 0: + if 'ext_chain_seq_id_remap' not in self.reasonsForReParsing: + seqIdRemap = self.reasonsForReParsing['seq_id_remap'] if 'seq_id_remap' in self.reasonsForReParsing else [] + if len(seqIdRemap) != len(seqIdRemapFailed)\ + or seqIdRemap[0]['chain_id'] != seqIdRemapFailed[0]['chain_id']\ + or not all(src_seq_id in seqIdRemap[0] for src_seq_id in seqIdRemapFailed[0]): + self.reasonsForReParsing['ext_chain_seq_id_remap'] = seqIdRemapFailed + + if 'local_seq_scheme' in self.reasonsForReParsing: + if 'non_poly_remap' in self.reasonsForReParsing or 'branched_remap' in self.reasonsForReParsing: + del self.reasonsForReParsing['local_seq_scheme'] + elif 'seq_id_remap' in self.reasonsForReParsing: + del self.reasonsForReParsing['local_seq_scheme'] + elif 'chain_seq_id_remap' in self.reasonsForReParsing: + del self.reasonsForReParsing['local_seq_scheme'] + elif 'ext_chain_seq_id_remap' in self.reasonsForReParsing: + del self.reasonsForReParsing['local_seq_scheme'] + + if 'local_seq_scheme' in self.reasonsForReParsing and len(self.reasonsForReParsing) == 1: + sortPolySeqRst(self.polySeqRstFailed) + if len(self.polySeqRstFailed) > 0: + self.reasonsForReParsing['extend_seq_scheme'] = self.polySeqRstFailed + del self.reasonsForReParsing['local_seq_scheme'] + + finally: + self.warningMessage = sorted(list(set(self.f)), key=self.f.index) + def validatePeak2D(self, index: int, pos_1: float, pos_2: float, pos_unc_1: Optional[float], pos_unc_2: Optional[float], lw_1: Optional[float], lw_2: Optional[float], diff --git a/wwpdb/utils/nmr/pk/NmrPipePKParserListener.py b/wwpdb/utils/nmr/pk/NmrPipePKParserListener.py index 5049ad48..71bbe399 100644 --- a/wwpdb/utils/nmr/pk/NmrPipePKParserListener.py +++ b/wwpdb/utils/nmr/pk/NmrPipePKParserListener.py @@ -22,21 +22,11 @@ REPRESENTATIVE_MODEL_ID, REPRESENTATIVE_ALT_ID, SPECTRAL_DIM_TEMPLATE, - isCyclicPolymer, getMaxEffDigits, roundString, extractPeakAssignment, getPkRow) - from wwpdb.utils.nmr.AlignUtil import (emptyValue, - sortPolySeqRst, - syncCompIdOfPolySeqRst, - alignPolymerSequence, - assignPolymerSequence, - trimSequenceAlignment, - splitPolySeqRstForMultimers, - splitPolySeqRstForExactNoes, - splitPolySeqRstForNonPoly, - splitPolySeqRstForBranched) + from wwpdb.utils.nmr.AlignUtil import emptyValue except ImportError: from nmr.pk.NmrPipePKParser import NmrPipePKParser @@ -45,21 +35,11 @@ REPRESENTATIVE_MODEL_ID, REPRESENTATIVE_ALT_ID, SPECTRAL_DIM_TEMPLATE, - isCyclicPolymer, getMaxEffDigits, roundString, extractPeakAssignment, getPkRow) - from nmr.AlignUtil import (emptyValue, - sortPolySeqRst, - syncCompIdOfPolySeqRst, - alignPolymerSequence, - assignPolymerSequence, - trimSequenceAlignment, - splitPolySeqRstForMultimers, - splitPolySeqRstForExactNoes, - splitPolySeqRstForNonPoly, - splitPolySeqRstForBranched) + from nmr.AlignUtil import emptyValue # This class defines a complete listener for a parse tree produced by NmrPipePKParser. @@ -94,303 +74,12 @@ 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 - try: - - if self.hasPolySeq and self.polySeqRst is not None: - sortPolySeqRst(self.polySeqRst, - None if self.reasons is None else self.reasons.get('non_poly_remap')) - - self.seqAlign, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRst, - resolvedMultimer=self.reasons is not None) - self.chainAssign, message = assignPolymerSequence(self.pA, self.ccU, self.file_type, self.polySeq, self.polySeqRst, self.seqAlign) - - if len(message) > 0: - self.f.extend(message) - - if self.chainAssign is not None: - - if len(self.polySeq) == len(self.polySeqRst): - - chain_mapping = {} - - for ca in self.chainAssign: - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - if ref_chain_id != test_chain_id: - chain_mapping[test_chain_id] = ref_chain_id - - if len(chain_mapping) == len(self.polySeq): - - for ps in self.polySeqRst: - if ps['chain_id'] in chain_mapping: - ps['chain_id'] = chain_mapping[ps['chain_id']] - - self.seqAlign, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRst, - resolvedMultimer=self.reasons is not None) - self.chainAssign, _ = assignPolymerSequence(self.pA, self.ccU, self.file_type, self.polySeq, self.polySeqRst, self.seqAlign) - - trimSequenceAlignment(self.seqAlign, self.chainAssign) - - if self.reasons is None and any(f for f in self.f - if '[Atom not found]' in f or '[Sequence mismatch]' in f): - - seqIdRemap = [] - - cyclicPolymer = {} - - for ca in self.chainAssign: - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - sa = next(sa for sa in self.seqAlign - if sa['ref_chain_id'] == ref_chain_id - and sa['test_chain_id'] == test_chain_id) - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - poly_seq_rst = next(ps for ps in self.polySeqRst - if ps['chain_id'] == test_chain_id) - - seq_id_mapping = {} - offset = None - for ref_seq_id, mid_code, test_seq_id in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id']): - if test_seq_id is None: - continue - if mid_code == '|': - try: - seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id - in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) - if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) - if offset is None: - offset = seq_id_mapping[test_seq_id] - test_seq_id - except StopIteration: - pass - elif mid_code == ' ' and test_seq_id in poly_seq_rst['seq_id']: - idx = poly_seq_rst['seq_id'].index(test_seq_id) - if poly_seq_rst['comp_id'][idx] == '.' and poly_seq_rst['auth_comp_id'][idx] not in emptyValue: - seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id - in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) - if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) - - if offset is not None and all(v - k == offset for k, v in seq_id_mapping.items()): - test_seq_id_list = list(seq_id_mapping.keys()) - min_test_seq_id = min(test_seq_id_list) - max_test_seq_id = max(test_seq_id_list) - for test_seq_id in range(min_test_seq_id + 1, max_test_seq_id): - if test_seq_id not in seq_id_mapping: - seq_id_mapping[test_seq_id] = test_seq_id + offset - - if ref_chain_id not in cyclicPolymer: - cyclicPolymer[ref_chain_id] =\ - isCyclicPolymer(self.cR, self.polySeq, ref_chain_id, - self.representativeModelId, self.representativeAltId, self.modelNumName) - - if cyclicPolymer[ref_chain_id]: - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - - offset = None - for seq_id, comp_id in zip(poly_seq_rst['seq_id'], poly_seq_rst['comp_id']): - if seq_id is not None and seq_id not in seq_id_mapping: - _seq_id = next((_seq_id for _seq_id, _comp_id in zip(poly_seq_model['seq_id'], poly_seq_model['comp_id']) - if _seq_id not in seq_id_mapping.values() and _comp_id == comp_id), None) - if _seq_id is not None: - offset = seq_id - _seq_id - break - - if offset is not None: - for seq_id in poly_seq_rst['seq_id']: - if seq_id is not None and seq_id not in seq_id_mapping: - seq_id_mapping[seq_id] = seq_id - offset - - if any(k for k, v in seq_id_mapping.items() if k != v)\ - and not any(k for k, v in seq_id_mapping.items() - if v in poly_seq_model['seq_id'] - and k == poly_seq_model['auth_seq_id'][poly_seq_model['seq_id'].index(v)]): - seqIdRemap.append({'chain_id': test_chain_id, 'seq_id_dict': seq_id_mapping}) - - if len(seqIdRemap) > 0: - if 'seq_id_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['seq_id_remap'] = seqIdRemap - - if any(ps for ps in self.polySeq if 'identical_chain_id' in ps): - polySeqRst, chainIdMapping = splitPolySeqRstForMultimers(self.pA, self.polySeq, self.polySeqRst, self.chainAssign) - - if polySeqRst is not None and (not self.hasNonPoly or len(self.polySeq) // len(self.nonPoly) in (1, 2)): - self.polySeqRst = polySeqRst - if 'chain_id_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['chain_id_remap'] = chainIdMapping - - if len(self.polySeq) == 1 and len(self.polySeqRst) == 1: - polySeqRst, chainIdMapping, _ =\ - splitPolySeqRstForExactNoes(self.pA, self.polySeq, self.polySeqRst, self.chainAssign) - - if polySeqRst is not None: - self.polySeqRst = polySeqRst - if 'chain_id_clone' not in self.reasonsForReParsing: - self.reasonsForReParsing['chain_id_clone'] = chainIdMapping - - if self.hasNonPoly: - polySeqRst, nonPolyMapping = splitPolySeqRstForNonPoly(self.ccU, self.nonPoly, self.polySeqRst, - self.seqAlign, self.chainAssign) - - if polySeqRst is not None: - self.polySeqRst = polySeqRst - if 'non_poly_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['non_poly_remap'] = nonPolyMapping - - if self.hasBranched: - polySeqRst, branchedMapping = splitPolySeqRstForBranched(self.pA, self.polySeq, self.branched, self.polySeqRst, - self.chainAssign) - - if polySeqRst is not None: - self.polySeqRst = polySeqRst - if 'branched_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['branched_remap'] = branchedMapping - - if len(self.polySeqRstFailed) > 0: - sortPolySeqRst(self.polySeqRstFailed) - if not any(f for f in self.f if '[Sequence mismatch]' in f): # 2n6y - syncCompIdOfPolySeqRst(self.polySeqRstFailed, self.compIdMap) # 2mx9 - - seqAlignFailed, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRstFailed) - chainAssignFailed, _ = assignPolymerSequence(self.pA, self.ccU, self.file_type, - self.polySeq, self.polySeqRstFailed, seqAlignFailed) - - if chainAssignFailed is not None: - seqIdRemapFailed = [] - - uniq_ps = not any('identical_chain_id' in ps for ps in self.polySeq) - - for ca in chainAssignFailed: - if ca['conflict'] > 0: - continue - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - sa = next((sa for sa in seqAlignFailed - if sa['ref_chain_id'] == ref_chain_id - and sa['test_chain_id'] == test_chain_id), None) - - if sa is None: - continue - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - - seq_id_mapping = {} - for ref_seq_id, mid_code, test_seq_id in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id']): - if test_seq_id is None: - continue - if mid_code == '|': - try: - seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id - in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) - if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) - except StopIteration: - if uniq_ps: - seq_id_mapping[test_seq_id] = ref_seq_id - - offset = None - offsets = [v - k for k, v in seq_id_mapping.items()] - if len(offsets) > 0 and ('gap_in_auth_seq' not in poly_seq_model or not poly_seq_model['gap_in_auth_seq']): - offsets = collections.Counter(offsets).most_common() - if len(offsets) > 1: - offset = offsets[0][0] - for k, v in seq_id_mapping.items(): - if v - k != offset: - seq_id_mapping[k] = k + offset - - if uniq_ps and offset is not None and len(seq_id_mapping) > 0\ - and ('gap_in_auth_seq' not in poly_seq_model or not poly_seq_model['gap_in_auth_seq']): - for ref_seq_id, mid_code, test_seq_id, ref_code, test_code in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id'], - sa['ref_code'], sa['test_code']): - if test_seq_id is None: - continue - if mid_code == '|' and test_seq_id not in seq_id_mapping: - seq_id_mapping[test_seq_id] = test_seq_id + offset - elif ref_code != '.' and test_code == '.': - seq_id_mapping[test_seq_id] = test_seq_id + offset - - if any(k for k, v in seq_id_mapping.items() if k != v)\ - and not any(k for k, v in seq_id_mapping.items() - if v in poly_seq_model['seq_id'] - and k == poly_seq_model['auth_seq_id'][poly_seq_model['seq_id'].index(v)]): - seqIdRemapFailed.append({'chain_id': ref_chain_id, 'seq_id_dict': seq_id_mapping, - 'comp_id_set': list(set(poly_seq_model['comp_id']))}) - - if len(seqIdRemapFailed) > 0: - if 'chain_seq_id_remap' not in self.reasonsForReParsing: - seqIdRemap = self.reasonsForReParsing['seq_id_remap'] if 'seq_id_remap' in self.reasonsForReParsing else [] - if len(seqIdRemap) != len(seqIdRemapFailed)\ - or seqIdRemap[0]['chain_id'] != seqIdRemapFailed[0]['chain_id']\ - or not all(src_seq_id in seqIdRemap[0] for src_seq_id in seqIdRemapFailed[0]): - self.reasonsForReParsing['chain_seq_id_remap'] = seqIdRemapFailed - - else: - for ps in self.polySeqRstFailed: - for ca in self.chainAssign: - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - if test_chain_id != ps['chain_id']: - continue - - sa = next(sa for sa in self.seqAlign - if sa['ref_chain_id'] == ref_chain_id - and sa['test_chain_id'] == test_chain_id) - - if len(sa['test_seq_id']) != len(sa['ref_seq_id']): - continue - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - - seq_id_mapping, comp_id_mapping = {}, {} - - for seq_id, comp_id in zip(ps['seq_id'], ps['comp_id']): - if seq_id in sa['test_seq_id']: - idx = sa['test_seq_id'].index(seq_id) - auth_seq_id = sa['ref_seq_id'][idx] - seq_id_mapping[seq_id] = auth_seq_id - comp_id_mapping[seq_id] = comp_id - if any(k for k, v in seq_id_mapping.items() if k != v)\ - or ('label_seq_scheme' not in self.reasonsForReParsing - and all(v not in poly_seq_model['auth_seq_id'] for v in seq_id_mapping.values())): - seqIdRemapFailed.append({'chain_id': ref_chain_id, 'seq_id_dict': seq_id_mapping, - 'comp_id_dict': comp_id_mapping}) - - if len(seqIdRemapFailed) > 0: - if 'ext_chain_seq_id_remap' not in self.reasonsForReParsing: - seqIdRemap = self.reasonsForReParsing['seq_id_remap'] if 'seq_id_remap' in self.reasonsForReParsing else [] - if len(seqIdRemap) != len(seqIdRemapFailed)\ - or seqIdRemap[0]['chain_id'] != seqIdRemapFailed[0]['chain_id']\ - or not all(src_seq_id in seqIdRemap[0] for src_seq_id in seqIdRemapFailed[0]): - self.reasonsForReParsing['ext_chain_seq_id_remap'] = seqIdRemapFailed - - if 'local_seq_scheme' in self.reasonsForReParsing: - if 'non_poly_remap' in self.reasonsForReParsing or 'branched_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - elif 'seq_id_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - elif 'chain_seq_id_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - elif 'ext_chain_seq_id_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - - if 'local_seq_scheme' in self.reasonsForReParsing and len(self.reasonsForReParsing) == 1: - sortPolySeqRst(self.polySeqRstFailed) - if len(self.polySeqRstFailed) > 0: - self.reasonsForReParsing['extend_seq_scheme'] = self.polySeqRstFailed - del self.reasonsForReParsing['local_seq_scheme'] - - 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(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: @@ -410,26 +99,25 @@ def exitNmrpipe_pk(self, ctx: NmrPipePKParser.Nmrpipe_pkContext): # pylint: dis elif 30 < center < 50 and atom_type == 'C': __v['spectral_region'] = 'C_ali' - del __v['freq_hint'] + 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 __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 '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' + 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}') + if self.debug: + print(f'num_of_dim: {d}, list_id: {_id}') + for __d, __v in _v.items(): + print(f'{__d} {__v}') - finally: - self.warningMessage = sorted(list(set(self.f)), key=self.f.index) + self.exit() # Enter a parse tree produced by NmrPipePKParser#data_label. def enterData_label(self, ctx: NmrPipePKParser.Data_labelContext): # pylint: disable=unused-argument diff --git a/wwpdb/utils/nmr/pk/NmrViewPKParserListener.py b/wwpdb/utils/nmr/pk/NmrViewPKParserListener.py index f17d2edd..b22d999d 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 collections import numpy as np from antlr4 import ParseTreeListener @@ -21,19 +20,9 @@ REPRESENTATIVE_MODEL_ID, REPRESENTATIVE_ALT_ID, SPECTRAL_DIM_TEMPLATE, - isCyclicPolymer, extractPeakAssignment, getPkRow) - from wwpdb.utils.nmr.AlignUtil import (emptyValue, - sortPolySeqRst, - syncCompIdOfPolySeqRst, - alignPolymerSequence, - assignPolymerSequence, - trimSequenceAlignment, - splitPolySeqRstForMultimers, - splitPolySeqRstForExactNoes, - splitPolySeqRstForNonPoly, - splitPolySeqRstForBranched) + from wwpdb.utils.nmr.AlignUtil import emptyValue except ImportError: from nmr.pk.NmrViewPKParser import NmrViewPKParser @@ -42,19 +31,9 @@ REPRESENTATIVE_MODEL_ID, REPRESENTATIVE_ALT_ID, SPECTRAL_DIM_TEMPLATE, - isCyclicPolymer, extractPeakAssignment, getPkRow) - from nmr.AlignUtil import (emptyValue, - sortPolySeqRst, - syncCompIdOfPolySeqRst, - alignPolymerSequence, - assignPolymerSequence, - trimSequenceAlignment, - splitPolySeqRstForMultimers, - splitPolySeqRstForExactNoes, - splitPolySeqRstForNonPoly, - splitPolySeqRstForBranched) + from nmr.AlignUtil import emptyValue # This class defines a complete listener for a parse tree produced by NmrViewPKParser. @@ -93,303 +72,12 @@ 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 - try: - - if self.hasPolySeq and self.polySeqRst is not None: - sortPolySeqRst(self.polySeqRst, - None if self.reasons is None else self.reasons.get('non_poly_remap')) - - self.seqAlign, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRst, - resolvedMultimer=self.reasons is not None) - self.chainAssign, message = assignPolymerSequence(self.pA, self.ccU, self.file_type, self.polySeq, self.polySeqRst, self.seqAlign) - - if len(message) > 0: - self.f.extend(message) - - if self.chainAssign is not None: - - if len(self.polySeq) == len(self.polySeqRst): - - chain_mapping = {} - - for ca in self.chainAssign: - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - if ref_chain_id != test_chain_id: - chain_mapping[test_chain_id] = ref_chain_id - - if len(chain_mapping) == len(self.polySeq): - - for ps in self.polySeqRst: - if ps['chain_id'] in chain_mapping: - ps['chain_id'] = chain_mapping[ps['chain_id']] - - self.seqAlign, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRst, - resolvedMultimer=self.reasons is not None) - self.chainAssign, _ = assignPolymerSequence(self.pA, self.ccU, self.file_type, self.polySeq, self.polySeqRst, self.seqAlign) - - trimSequenceAlignment(self.seqAlign, self.chainAssign) - - if self.reasons is None and any(f for f in self.f - if '[Atom not found]' in f or '[Sequence mismatch]' in f): - - seqIdRemap = [] - - cyclicPolymer = {} - - for ca in self.chainAssign: - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - sa = next(sa for sa in self.seqAlign - if sa['ref_chain_id'] == ref_chain_id - and sa['test_chain_id'] == test_chain_id) - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - poly_seq_rst = next(ps for ps in self.polySeqRst - if ps['chain_id'] == test_chain_id) - - seq_id_mapping = {} - offset = None - for ref_seq_id, mid_code, test_seq_id in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id']): - if test_seq_id is None: - continue - if mid_code == '|': - try: - seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id - in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) - if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) - if offset is None: - offset = seq_id_mapping[test_seq_id] - test_seq_id - except StopIteration: - pass - elif mid_code == ' ' and test_seq_id in poly_seq_rst['seq_id']: - idx = poly_seq_rst['seq_id'].index(test_seq_id) - if poly_seq_rst['comp_id'][idx] == '.' and poly_seq_rst['auth_comp_id'][idx] not in emptyValue: - seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id - in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) - if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) - - if offset is not None and all(v - k == offset for k, v in seq_id_mapping.items()): - test_seq_id_list = list(seq_id_mapping.keys()) - min_test_seq_id = min(test_seq_id_list) - max_test_seq_id = max(test_seq_id_list) - for test_seq_id in range(min_test_seq_id + 1, max_test_seq_id): - if test_seq_id not in seq_id_mapping: - seq_id_mapping[test_seq_id] = test_seq_id + offset - - if ref_chain_id not in cyclicPolymer: - cyclicPolymer[ref_chain_id] =\ - isCyclicPolymer(self.cR, self.polySeq, ref_chain_id, - self.representativeModelId, self.representativeAltId, self.modelNumName) - - if cyclicPolymer[ref_chain_id]: - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - - offset = None - for seq_id, comp_id in zip(poly_seq_rst['seq_id'], poly_seq_rst['comp_id']): - if seq_id is not None and seq_id not in seq_id_mapping: - _seq_id = next((_seq_id for _seq_id, _comp_id in zip(poly_seq_model['seq_id'], poly_seq_model['comp_id']) - if _seq_id not in seq_id_mapping.values() and _comp_id == comp_id), None) - if _seq_id is not None: - offset = seq_id - _seq_id - break - - if offset is not None: - for seq_id in poly_seq_rst['seq_id']: - if seq_id is not None and seq_id not in seq_id_mapping: - seq_id_mapping[seq_id] = seq_id - offset - - if any(k for k, v in seq_id_mapping.items() if k != v)\ - and not any(k for k, v in seq_id_mapping.items() - if v in poly_seq_model['seq_id'] - and k == poly_seq_model['auth_seq_id'][poly_seq_model['seq_id'].index(v)]): - seqIdRemap.append({'chain_id': test_chain_id, 'seq_id_dict': seq_id_mapping}) - - if len(seqIdRemap) > 0: - if 'seq_id_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['seq_id_remap'] = seqIdRemap - - if any(ps for ps in self.polySeq if 'identical_chain_id' in ps): - polySeqRst, chainIdMapping = splitPolySeqRstForMultimers(self.pA, self.polySeq, self.polySeqRst, self.chainAssign) - - if polySeqRst is not None and (not self.hasNonPoly or len(self.polySeq) // len(self.nonPoly) in (1, 2)): - self.polySeqRst = polySeqRst - if 'chain_id_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['chain_id_remap'] = chainIdMapping - - if len(self.polySeq) == 1 and len(self.polySeqRst) == 1: - polySeqRst, chainIdMapping, _ =\ - splitPolySeqRstForExactNoes(self.pA, self.polySeq, self.polySeqRst, self.chainAssign) - - if polySeqRst is not None: - self.polySeqRst = polySeqRst - if 'chain_id_clone' not in self.reasonsForReParsing: - self.reasonsForReParsing['chain_id_clone'] = chainIdMapping - - if self.hasNonPoly: - polySeqRst, nonPolyMapping = splitPolySeqRstForNonPoly(self.ccU, self.nonPoly, self.polySeqRst, - self.seqAlign, self.chainAssign) - - if polySeqRst is not None: - self.polySeqRst = polySeqRst - if 'non_poly_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['non_poly_remap'] = nonPolyMapping - - if self.hasBranched: - polySeqRst, branchedMapping = splitPolySeqRstForBranched(self.pA, self.polySeq, self.branched, self.polySeqRst, - self.chainAssign) - - if polySeqRst is not None: - self.polySeqRst = polySeqRst - if 'branched_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['branched_remap'] = branchedMapping - - if len(self.polySeqRstFailed) > 0: - sortPolySeqRst(self.polySeqRstFailed) - if not any(f for f in self.f if '[Sequence mismatch]' in f): # 2n6y - syncCompIdOfPolySeqRst(self.polySeqRstFailed, self.compIdMap) # 2mx9 - - seqAlignFailed, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRstFailed) - chainAssignFailed, _ = assignPolymerSequence(self.pA, self.ccU, self.file_type, - self.polySeq, self.polySeqRstFailed, seqAlignFailed) - - if chainAssignFailed is not None: - seqIdRemapFailed = [] - - uniq_ps = not any('identical_chain_id' in ps for ps in self.polySeq) - - for ca in chainAssignFailed: - if ca['conflict'] > 0: - continue - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - sa = next((sa for sa in seqAlignFailed - if sa['ref_chain_id'] == ref_chain_id - and sa['test_chain_id'] == test_chain_id), None) - - if sa is None: - continue - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - - seq_id_mapping = {} - for ref_seq_id, mid_code, test_seq_id in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id']): - if test_seq_id is None: - continue - if mid_code == '|': - try: - seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id - in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) - if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) - except StopIteration: - if uniq_ps: - seq_id_mapping[test_seq_id] = ref_seq_id - - offset = None - offsets = [v - k for k, v in seq_id_mapping.items()] - if len(offsets) > 0 and ('gap_in_auth_seq' not in poly_seq_model or not poly_seq_model['gap_in_auth_seq']): - offsets = collections.Counter(offsets).most_common() - if len(offsets) > 1: - offset = offsets[0][0] - for k, v in seq_id_mapping.items(): - if v - k != offset: - seq_id_mapping[k] = k + offset - - if uniq_ps and offset is not None and len(seq_id_mapping) > 0\ - and ('gap_in_auth_seq' not in poly_seq_model or not poly_seq_model['gap_in_auth_seq']): - for ref_seq_id, mid_code, test_seq_id, ref_code, test_code in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id'], - sa['ref_code'], sa['test_code']): - if test_seq_id is None: - continue - if mid_code == '|' and test_seq_id not in seq_id_mapping: - seq_id_mapping[test_seq_id] = test_seq_id + offset - elif ref_code != '.' and test_code == '.': - seq_id_mapping[test_seq_id] = test_seq_id + offset - - if any(k for k, v in seq_id_mapping.items() if k != v)\ - and not any(k for k, v in seq_id_mapping.items() - if v in poly_seq_model['seq_id'] - and k == poly_seq_model['auth_seq_id'][poly_seq_model['seq_id'].index(v)]): - seqIdRemapFailed.append({'chain_id': ref_chain_id, 'seq_id_dict': seq_id_mapping, - 'comp_id_set': list(set(poly_seq_model['comp_id']))}) - - if len(seqIdRemapFailed) > 0: - if 'chain_seq_id_remap' not in self.reasonsForReParsing: - seqIdRemap = self.reasonsForReParsing['seq_id_remap'] if 'seq_id_remap' in self.reasonsForReParsing else [] - if len(seqIdRemap) != len(seqIdRemapFailed)\ - or seqIdRemap[0]['chain_id'] != seqIdRemapFailed[0]['chain_id']\ - or not all(src_seq_id in seqIdRemap[0] for src_seq_id in seqIdRemapFailed[0]): - self.reasonsForReParsing['chain_seq_id_remap'] = seqIdRemapFailed - - else: - for ps in self.polySeqRstFailed: - for ca in self.chainAssign: - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - if test_chain_id != ps['chain_id']: - continue - - sa = next(sa for sa in self.seqAlign - if sa['ref_chain_id'] == ref_chain_id - and sa['test_chain_id'] == test_chain_id) - - if len(sa['test_seq_id']) != len(sa['ref_seq_id']): - continue - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - - seq_id_mapping, comp_id_mapping = {}, {} - - for seq_id, comp_id in zip(ps['seq_id'], ps['comp_id']): - if seq_id in sa['test_seq_id']: - idx = sa['test_seq_id'].index(seq_id) - auth_seq_id = sa['ref_seq_id'][idx] - seq_id_mapping[seq_id] = auth_seq_id - comp_id_mapping[seq_id] = comp_id - if any(k for k, v in seq_id_mapping.items() if k != v)\ - or ('label_seq_scheme' not in self.reasonsForReParsing - and all(v not in poly_seq_model['auth_seq_id'] for v in seq_id_mapping.values())): - seqIdRemapFailed.append({'chain_id': ref_chain_id, 'seq_id_dict': seq_id_mapping, - 'comp_id_dict': comp_id_mapping}) - - if len(seqIdRemapFailed) > 0: - if 'ext_chain_seq_id_remap' not in self.reasonsForReParsing: - seqIdRemap = self.reasonsForReParsing['seq_id_remap'] if 'seq_id_remap' in self.reasonsForReParsing else [] - if len(seqIdRemap) != len(seqIdRemapFailed)\ - or seqIdRemap[0]['chain_id'] != seqIdRemapFailed[0]['chain_id']\ - or not all(src_seq_id in seqIdRemap[0] for src_seq_id in seqIdRemapFailed[0]): - self.reasonsForReParsing['ext_chain_seq_id_remap'] = seqIdRemapFailed - - if 'local_seq_scheme' in self.reasonsForReParsing: - if 'non_poly_remap' in self.reasonsForReParsing or 'branched_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - elif 'seq_id_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - elif 'chain_seq_id_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - elif 'ext_chain_seq_id_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - - if 'local_seq_scheme' in self.reasonsForReParsing and len(self.reasonsForReParsing) == 1: - sortPolySeqRst(self.polySeqRstFailed) - if len(self.polySeqRstFailed) > 0: - self.reasonsForReParsing['extend_seq_scheme'] = self.polySeqRstFailed - del self.reasonsForReParsing['local_seq_scheme'] - - 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(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: @@ -409,25 +97,24 @@ def exitNmrview_pk(self, ctx: NmrViewPKParser.Nmrview_pkContext): # pylint: dis 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' + 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'] + 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' + 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}') + if self.debug: + print(f'num_of_dim: {d}, list_id: {_id}') + for __d, __v in _v.items(): + print(f'{__d} {__v}') - finally: - self.warningMessage = sorted(list(set(self.f)), key=self.f.index) + self.exit() # Enter a parse tree produced by NmrViewPKParser#data_label. def enterData_label(self, ctx: NmrViewPKParser.Data_labelContext): # pylint: disable=unused-argument diff --git a/wwpdb/utils/nmr/pk/SparkyPKLexer.py b/wwpdb/utils/nmr/pk/SparkyPKLexer.py index 43b60e42..7549cbab 100644 --- a/wwpdb/utils/nmr/pk/SparkyPKLexer.py +++ b/wwpdb/utils/nmr/pk/SparkyPKLexer.py @@ -10,7 +10,7 @@ def serializedATN(): return [ - 4,0,26,392,6,-1,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5, + 4,0,25,400,6,-1,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5, 7,5,2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12, 2,13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19, 7,19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25, @@ -26,138 +26,141 @@ def serializedATN(): 9,170,9,9,1,9,5,9,173,8,9,10,9,12,9,176,9,9,1,9,1,9,1,10,4,10,181, 8,10,11,10,12,10,182,1,10,5,10,186,8,10,10,10,12,10,189,9,10,1,10, 5,10,192,8,10,10,10,12,10,195,9,10,1,10,5,10,198,8,10,10,10,12,10, - 201,9,10,1,10,1,10,1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12, - 1,12,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,13,1,14,1,14,1,15,1,15, - 1,16,1,16,3,16,229,8,16,1,17,1,17,3,17,233,8,17,1,18,1,18,3,18,237, - 8,18,1,19,1,19,5,19,241,8,19,10,19,12,19,244,9,19,1,20,4,20,247, - 8,20,11,20,12,20,248,1,20,1,20,1,21,4,21,254,8,21,11,21,12,21,255, - 1,22,1,22,1,22,5,22,261,8,22,10,22,12,22,264,9,22,1,22,1,22,1,23, - 1,23,1,23,4,23,271,8,23,11,23,12,23,272,1,23,1,23,4,23,277,8,23, - 11,23,12,23,278,1,23,1,23,4,23,283,8,23,11,23,12,23,284,1,23,1,23, - 1,23,1,23,1,23,1,23,3,23,293,8,23,1,23,5,23,296,8,23,10,23,12,23, - 299,9,23,1,23,1,23,1,23,1,23,1,24,1,24,1,24,4,24,308,8,24,11,24, - 12,24,309,1,24,1,24,4,24,314,8,24,11,24,12,24,315,1,24,1,24,4,24, - 320,8,24,11,24,12,24,321,1,24,1,24,1,24,1,24,1,24,1,24,3,24,330, - 8,24,1,24,5,24,333,8,24,10,24,12,24,336,9,24,1,24,1,24,1,24,1,24, - 1,25,1,25,1,25,1,26,1,26,1,26,1,27,1,27,1,27,1,28,1,28,1,28,1,29, - 1,29,1,29,1,29,1,29,3,29,359,8,29,1,29,1,29,1,29,1,29,1,29,1,29, - 1,29,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,31,1,31,1,31,1,31,1,32, - 4,32,380,8,32,11,32,12,32,381,1,32,1,32,1,33,4,33,387,8,33,11,33, - 12,33,388,1,33,1,33,1,262,0,34,2,1,4,2,6,3,8,4,10,5,12,0,14,0,16, - 0,18,6,20,7,22,8,24,9,26,10,28,11,30,12,32,0,34,0,36,0,38,0,40,0, - 42,13,44,14,46,15,48,16,50,17,52,18,54,19,56,20,58,21,60,22,62,23, - 64,24,66,25,68,26,2,0,1,9,2,0,43,43,45,45,2,0,69,69,101,101,1,0, - 48,57,2,0,10,10,13,13,2,0,65,90,97,122,5,0,35,35,42,43,45,46,63, - 63,95,95,2,0,34,34,39,39,2,0,9,9,32,32,5,0,33,33,35,35,38,38,59, - 59,92,92,430,0,2,1,0,0,0,0,4,1,0,0,0,0,6,1,0,0,0,0,8,1,0,0,0,0,10, - 1,0,0,0,0,18,1,0,0,0,0,20,1,0,0,0,0,22,1,0,0,0,0,24,1,0,0,0,0,26, - 1,0,0,0,0,28,1,0,0,0,0,30,1,0,0,0,0,42,1,0,0,0,0,44,1,0,0,0,0,46, - 1,0,0,0,0,48,1,0,0,0,0,50,1,0,0,0,1,52,1,0,0,0,1,54,1,0,0,0,1,56, - 1,0,0,0,1,58,1,0,0,0,1,60,1,0,0,0,1,62,1,0,0,0,1,64,1,0,0,0,1,66, - 1,0,0,0,1,68,1,0,0,0,2,70,1,0,0,0,4,83,1,0,0,0,6,89,1,0,0,0,8,94, - 1,0,0,0,10,101,1,0,0,0,12,120,1,0,0,0,14,122,1,0,0,0,16,125,1,0, - 0,0,18,130,1,0,0,0,20,155,1,0,0,0,22,180,1,0,0,0,24,204,1,0,0,0, - 26,208,1,0,0,0,28,214,1,0,0,0,30,222,1,0,0,0,32,224,1,0,0,0,34,228, - 1,0,0,0,36,232,1,0,0,0,38,236,1,0,0,0,40,238,1,0,0,0,42,246,1,0, - 0,0,44,253,1,0,0,0,46,257,1,0,0,0,48,292,1,0,0,0,50,329,1,0,0,0, - 52,341,1,0,0,0,54,344,1,0,0,0,56,347,1,0,0,0,58,350,1,0,0,0,60,358, - 1,0,0,0,62,367,1,0,0,0,64,374,1,0,0,0,66,379,1,0,0,0,68,386,1,0, - 0,0,70,71,5,65,0,0,71,72,5,115,0,0,72,73,5,115,0,0,73,74,5,105,0, - 0,74,75,5,103,0,0,75,76,5,110,0,0,76,77,5,109,0,0,77,78,5,101,0, - 0,78,79,5,110,0,0,79,80,5,116,0,0,80,81,1,0,0,0,81,82,6,0,0,0,82, - 3,1,0,0,0,83,84,5,119,0,0,84,85,5,49,0,0,85,86,1,0,0,0,86,87,6,1, - 0,0,87,5,1,0,0,0,88,90,7,0,0,0,89,88,1,0,0,0,89,90,1,0,0,0,90,91, - 1,0,0,0,91,92,3,16,7,0,92,7,1,0,0,0,93,95,7,0,0,0,94,93,1,0,0,0, - 94,95,1,0,0,0,95,98,1,0,0,0,96,99,3,16,7,0,97,99,3,12,5,0,98,96, - 1,0,0,0,98,97,1,0,0,0,99,9,1,0,0,0,100,102,7,0,0,0,101,100,1,0,0, - 0,101,102,1,0,0,0,102,105,1,0,0,0,103,106,3,16,7,0,104,106,3,12, - 5,0,105,103,1,0,0,0,105,104,1,0,0,0,106,112,1,0,0,0,107,109,7,1, - 0,0,108,110,7,0,0,0,109,108,1,0,0,0,109,110,1,0,0,0,110,111,1,0, - 0,0,111,113,3,16,7,0,112,107,1,0,0,0,112,113,1,0,0,0,113,11,1,0, - 0,0,114,115,3,16,7,0,115,116,5,46,0,0,116,117,3,16,7,0,117,121,1, - 0,0,0,118,119,5,46,0,0,119,121,3,16,7,0,120,114,1,0,0,0,120,118, - 1,0,0,0,121,13,1,0,0,0,122,123,7,2,0,0,123,15,1,0,0,0,124,126,3, - 14,6,0,125,124,1,0,0,0,126,127,1,0,0,0,127,125,1,0,0,0,127,128,1, - 0,0,0,128,17,1,0,0,0,129,131,5,35,0,0,130,129,1,0,0,0,131,132,1, - 0,0,0,132,130,1,0,0,0,132,133,1,0,0,0,133,137,1,0,0,0,134,136,8, - 3,0,0,135,134,1,0,0,0,136,139,1,0,0,0,137,135,1,0,0,0,137,138,1, - 0,0,0,138,143,1,0,0,0,139,137,1,0,0,0,140,142,5,35,0,0,141,140,1, - 0,0,0,142,145,1,0,0,0,143,141,1,0,0,0,143,144,1,0,0,0,144,149,1, - 0,0,0,145,143,1,0,0,0,146,148,8,3,0,0,147,146,1,0,0,0,148,151,1, - 0,0,0,149,147,1,0,0,0,149,150,1,0,0,0,150,152,1,0,0,0,151,149,1, - 0,0,0,152,153,6,8,1,0,153,19,1,0,0,0,154,156,5,33,0,0,155,154,1, - 0,0,0,156,157,1,0,0,0,157,155,1,0,0,0,157,158,1,0,0,0,158,162,1, - 0,0,0,159,161,8,3,0,0,160,159,1,0,0,0,161,164,1,0,0,0,162,160,1, - 0,0,0,162,163,1,0,0,0,163,168,1,0,0,0,164,162,1,0,0,0,165,167,5, - 33,0,0,166,165,1,0,0,0,167,170,1,0,0,0,168,166,1,0,0,0,168,169,1, - 0,0,0,169,174,1,0,0,0,170,168,1,0,0,0,171,173,8,3,0,0,172,171,1, - 0,0,0,173,176,1,0,0,0,174,172,1,0,0,0,174,175,1,0,0,0,175,177,1, - 0,0,0,176,174,1,0,0,0,177,178,6,9,1,0,178,21,1,0,0,0,179,181,5,59, - 0,0,180,179,1,0,0,0,181,182,1,0,0,0,182,180,1,0,0,0,182,183,1,0, - 0,0,183,187,1,0,0,0,184,186,8,3,0,0,185,184,1,0,0,0,186,189,1,0, - 0,0,187,185,1,0,0,0,187,188,1,0,0,0,188,193,1,0,0,0,189,187,1,0, - 0,0,190,192,5,59,0,0,191,190,1,0,0,0,192,195,1,0,0,0,193,191,1,0, - 0,0,193,194,1,0,0,0,194,199,1,0,0,0,195,193,1,0,0,0,196,198,8,3, - 0,0,197,196,1,0,0,0,198,201,1,0,0,0,199,197,1,0,0,0,199,200,1,0, - 0,0,200,202,1,0,0,0,201,199,1,0,0,0,202,203,6,10,1,0,203,23,1,0, - 0,0,204,205,3,40,19,0,205,206,5,45,0,0,206,207,3,40,19,0,207,25, - 1,0,0,0,208,209,3,40,19,0,209,210,5,45,0,0,210,211,3,40,19,0,211, - 212,5,45,0,0,212,213,3,40,19,0,213,27,1,0,0,0,214,215,3,40,19,0, - 215,216,5,45,0,0,216,217,3,40,19,0,217,218,5,45,0,0,218,219,3,40, - 19,0,219,220,5,45,0,0,220,221,3,40,19,0,221,29,1,0,0,0,222,223,3, - 40,19,0,223,31,1,0,0,0,224,225,7,4,0,0,225,33,1,0,0,0,226,229,3, - 32,15,0,227,229,3,14,6,0,228,226,1,0,0,0,228,227,1,0,0,0,229,35, - 1,0,0,0,230,233,3,34,16,0,231,233,7,5,0,0,232,230,1,0,0,0,232,231, - 1,0,0,0,233,37,1,0,0,0,234,237,3,36,17,0,235,237,7,6,0,0,236,234, - 1,0,0,0,236,235,1,0,0,0,237,39,1,0,0,0,238,242,3,36,17,0,239,241, - 3,38,18,0,240,239,1,0,0,0,241,244,1,0,0,0,242,240,1,0,0,0,242,243, - 1,0,0,0,243,41,1,0,0,0,244,242,1,0,0,0,245,247,7,7,0,0,246,245,1, - 0,0,0,247,248,1,0,0,0,248,246,1,0,0,0,248,249,1,0,0,0,249,250,1, - 0,0,0,250,251,6,20,2,0,251,43,1,0,0,0,252,254,7,3,0,0,253,252,1, - 0,0,0,254,255,1,0,0,0,255,253,1,0,0,0,255,256,1,0,0,0,256,45,1,0, - 0,0,257,262,5,123,0,0,258,261,3,8,3,0,259,261,3,40,19,0,260,258, - 1,0,0,0,260,259,1,0,0,0,261,264,1,0,0,0,262,263,1,0,0,0,262,260, - 1,0,0,0,263,265,1,0,0,0,264,262,1,0,0,0,265,266,5,125,0,0,266,47, - 1,0,0,0,267,293,7,8,0,0,268,270,5,47,0,0,269,271,5,47,0,0,270,269, - 1,0,0,0,271,272,1,0,0,0,272,270,1,0,0,0,272,273,1,0,0,0,273,293, - 1,0,0,0,274,276,5,42,0,0,275,277,5,42,0,0,276,275,1,0,0,0,277,278, - 1,0,0,0,278,276,1,0,0,0,278,279,1,0,0,0,279,293,1,0,0,0,280,282, - 5,61,0,0,281,283,5,61,0,0,282,281,1,0,0,0,283,284,1,0,0,0,284,282, - 1,0,0,0,284,285,1,0,0,0,285,293,1,0,0,0,286,287,5,82,0,0,287,288, - 5,69,0,0,288,289,5,77,0,0,289,290,5,65,0,0,290,291,5,82,0,0,291, - 293,5,75,0,0,292,267,1,0,0,0,292,268,1,0,0,0,292,274,1,0,0,0,292, - 280,1,0,0,0,292,286,1,0,0,0,293,297,1,0,0,0,294,296,5,32,0,0,295, - 294,1,0,0,0,296,299,1,0,0,0,297,295,1,0,0,0,297,298,1,0,0,0,298, - 300,1,0,0,0,299,297,1,0,0,0,300,301,3,44,21,0,301,302,1,0,0,0,302, - 303,6,23,1,0,303,49,1,0,0,0,304,330,7,8,0,0,305,307,5,47,0,0,306, - 308,5,47,0,0,307,306,1,0,0,0,308,309,1,0,0,0,309,307,1,0,0,0,309, - 310,1,0,0,0,310,330,1,0,0,0,311,313,5,42,0,0,312,314,5,42,0,0,313, - 312,1,0,0,0,314,315,1,0,0,0,315,313,1,0,0,0,315,316,1,0,0,0,316, - 330,1,0,0,0,317,319,5,61,0,0,318,320,5,61,0,0,319,318,1,0,0,0,320, - 321,1,0,0,0,321,319,1,0,0,0,321,322,1,0,0,0,322,330,1,0,0,0,323, - 324,5,82,0,0,324,325,5,69,0,0,325,326,5,77,0,0,326,327,5,65,0,0, - 327,328,5,82,0,0,328,330,5,75,0,0,329,304,1,0,0,0,329,305,1,0,0, - 0,329,311,1,0,0,0,329,317,1,0,0,0,329,323,1,0,0,0,330,334,1,0,0, - 0,331,333,8,3,0,0,332,331,1,0,0,0,333,336,1,0,0,0,334,332,1,0,0, - 0,334,335,1,0,0,0,335,337,1,0,0,0,336,334,1,0,0,0,337,338,3,44,21, - 0,338,339,1,0,0,0,339,340,6,24,1,0,340,51,1,0,0,0,341,342,5,119, - 0,0,342,343,5,49,0,0,343,53,1,0,0,0,344,345,5,119,0,0,345,346,5, - 50,0,0,346,55,1,0,0,0,347,348,5,119,0,0,348,349,5,51,0,0,349,57, - 1,0,0,0,350,351,5,119,0,0,351,352,5,52,0,0,352,59,1,0,0,0,353,354, - 5,68,0,0,354,355,5,97,0,0,355,356,5,116,0,0,356,357,5,97,0,0,357, - 359,5,32,0,0,358,353,1,0,0,0,358,359,1,0,0,0,359,360,1,0,0,0,360, - 361,5,72,0,0,361,362,5,101,0,0,362,363,5,105,0,0,363,364,5,103,0, - 0,364,365,5,104,0,0,365,366,5,116,0,0,366,61,1,0,0,0,367,368,5,86, - 0,0,368,369,5,111,0,0,369,370,5,108,0,0,370,371,5,117,0,0,371,372, - 5,109,0,0,372,373,5,101,0,0,373,63,1,0,0,0,374,375,5,83,0,0,375, - 376,5,47,0,0,376,377,5,78,0,0,377,65,1,0,0,0,378,380,7,7,0,0,379, - 378,1,0,0,0,380,381,1,0,0,0,381,379,1,0,0,0,381,382,1,0,0,0,382, - 383,1,0,0,0,383,384,6,32,2,0,384,67,1,0,0,0,385,387,7,3,0,0,386, - 385,1,0,0,0,387,388,1,0,0,0,388,386,1,0,0,0,388,389,1,0,0,0,389, - 390,1,0,0,0,390,391,6,33,3,0,391,69,1,0,0,0,44,0,1,89,94,98,101, + 201,9,10,1,10,1,10,1,11,1,11,1,11,5,11,208,8,11,10,11,12,11,211, + 9,11,1,12,1,12,1,12,1,12,1,13,1,13,1,13,1,13,1,13,1,13,1,14,1,14, + 1,14,1,14,1,14,1,14,1,14,1,14,1,15,1,15,1,16,1,16,3,16,235,8,16, + 1,17,1,17,3,17,239,8,17,1,18,1,18,3,18,243,8,18,1,19,1,19,5,19,247, + 8,19,10,19,12,19,250,9,19,1,20,4,20,253,8,20,11,20,12,20,254,1,20, + 1,20,1,21,4,21,260,8,21,11,21,12,21,261,1,22,1,22,1,22,5,22,267, + 8,22,10,22,12,22,270,9,22,1,22,1,22,1,22,1,22,1,23,1,23,1,23,4,23, + 279,8,23,11,23,12,23,280,1,23,1,23,4,23,285,8,23,11,23,12,23,286, + 1,23,1,23,4,23,291,8,23,11,23,12,23,292,1,23,1,23,1,23,1,23,1,23, + 1,23,3,23,301,8,23,1,23,5,23,304,8,23,10,23,12,23,307,9,23,1,23, + 1,23,1,23,1,23,1,24,1,24,1,24,4,24,316,8,24,11,24,12,24,317,1,24, + 1,24,4,24,322,8,24,11,24,12,24,323,1,24,1,24,4,24,328,8,24,11,24, + 12,24,329,1,24,1,24,1,24,1,24,1,24,1,24,3,24,338,8,24,1,24,5,24, + 341,8,24,10,24,12,24,344,9,24,1,24,1,24,1,24,1,24,1,25,1,25,1,25, + 1,26,1,26,1,26,1,27,1,27,1,27,1,28,1,28,1,28,1,29,1,29,1,29,1,29, + 1,29,3,29,367,8,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,30,1,30, + 1,30,1,30,1,30,1,30,1,30,1,31,1,31,1,31,1,31,1,32,4,32,388,8,32, + 11,32,12,32,389,1,32,1,32,1,33,4,33,395,8,33,11,33,12,33,396,1,33, + 1,33,1,268,0,34,2,1,4,2,6,3,8,4,10,5,12,0,14,0,16,0,18,6,20,7,22, + 8,24,0,26,9,28,10,30,11,32,0,34,0,36,0,38,0,40,0,42,12,44,13,46, + 14,48,15,50,16,52,17,54,18,56,19,58,20,60,21,62,22,64,23,66,24,68, + 25,2,0,1,10,2,0,43,43,45,45,2,0,69,69,101,101,1,0,48,57,2,0,10,10, + 13,13,4,0,38,38,44,44,46,47,59,59,2,0,65,90,97,122,4,0,35,35,42, + 43,63,63,95,95,2,0,34,34,39,39,2,0,9,9,32,32,5,0,33,33,35,35,38, + 38,59,59,92,92,438,0,2,1,0,0,0,0,4,1,0,0,0,0,6,1,0,0,0,0,8,1,0,0, + 0,0,10,1,0,0,0,0,18,1,0,0,0,0,20,1,0,0,0,0,22,1,0,0,0,0,26,1,0,0, + 0,0,28,1,0,0,0,0,30,1,0,0,0,0,42,1,0,0,0,0,44,1,0,0,0,0,46,1,0,0, + 0,0,48,1,0,0,0,0,50,1,0,0,0,1,52,1,0,0,0,1,54,1,0,0,0,1,56,1,0,0, + 0,1,58,1,0,0,0,1,60,1,0,0,0,1,62,1,0,0,0,1,64,1,0,0,0,1,66,1,0,0, + 0,1,68,1,0,0,0,2,70,1,0,0,0,4,83,1,0,0,0,6,89,1,0,0,0,8,94,1,0,0, + 0,10,101,1,0,0,0,12,120,1,0,0,0,14,122,1,0,0,0,16,125,1,0,0,0,18, + 130,1,0,0,0,20,155,1,0,0,0,22,180,1,0,0,0,24,204,1,0,0,0,26,212, + 1,0,0,0,28,216,1,0,0,0,30,222,1,0,0,0,32,230,1,0,0,0,34,234,1,0, + 0,0,36,238,1,0,0,0,38,242,1,0,0,0,40,244,1,0,0,0,42,252,1,0,0,0, + 44,259,1,0,0,0,46,263,1,0,0,0,48,300,1,0,0,0,50,337,1,0,0,0,52,349, + 1,0,0,0,54,352,1,0,0,0,56,355,1,0,0,0,58,358,1,0,0,0,60,366,1,0, + 0,0,62,375,1,0,0,0,64,382,1,0,0,0,66,387,1,0,0,0,68,394,1,0,0,0, + 70,71,5,65,0,0,71,72,5,115,0,0,72,73,5,115,0,0,73,74,5,105,0,0,74, + 75,5,103,0,0,75,76,5,110,0,0,76,77,5,109,0,0,77,78,5,101,0,0,78, + 79,5,110,0,0,79,80,5,116,0,0,80,81,1,0,0,0,81,82,6,0,0,0,82,3,1, + 0,0,0,83,84,5,119,0,0,84,85,5,49,0,0,85,86,1,0,0,0,86,87,6,1,0,0, + 87,5,1,0,0,0,88,90,7,0,0,0,89,88,1,0,0,0,89,90,1,0,0,0,90,91,1,0, + 0,0,91,92,3,16,7,0,92,7,1,0,0,0,93,95,7,0,0,0,94,93,1,0,0,0,94,95, + 1,0,0,0,95,98,1,0,0,0,96,99,3,16,7,0,97,99,3,12,5,0,98,96,1,0,0, + 0,98,97,1,0,0,0,99,9,1,0,0,0,100,102,7,0,0,0,101,100,1,0,0,0,101, + 102,1,0,0,0,102,105,1,0,0,0,103,106,3,16,7,0,104,106,3,12,5,0,105, + 103,1,0,0,0,105,104,1,0,0,0,106,112,1,0,0,0,107,109,7,1,0,0,108, + 110,7,0,0,0,109,108,1,0,0,0,109,110,1,0,0,0,110,111,1,0,0,0,111, + 113,3,16,7,0,112,107,1,0,0,0,112,113,1,0,0,0,113,11,1,0,0,0,114, + 115,3,16,7,0,115,116,5,46,0,0,116,117,3,16,7,0,117,121,1,0,0,0,118, + 119,5,46,0,0,119,121,3,16,7,0,120,114,1,0,0,0,120,118,1,0,0,0,121, + 13,1,0,0,0,122,123,7,2,0,0,123,15,1,0,0,0,124,126,3,14,6,0,125,124, + 1,0,0,0,126,127,1,0,0,0,127,125,1,0,0,0,127,128,1,0,0,0,128,17,1, + 0,0,0,129,131,5,35,0,0,130,129,1,0,0,0,131,132,1,0,0,0,132,130,1, + 0,0,0,132,133,1,0,0,0,133,137,1,0,0,0,134,136,8,3,0,0,135,134,1, + 0,0,0,136,139,1,0,0,0,137,135,1,0,0,0,137,138,1,0,0,0,138,143,1, + 0,0,0,139,137,1,0,0,0,140,142,5,35,0,0,141,140,1,0,0,0,142,145,1, + 0,0,0,143,141,1,0,0,0,143,144,1,0,0,0,144,149,1,0,0,0,145,143,1, + 0,0,0,146,148,8,3,0,0,147,146,1,0,0,0,148,151,1,0,0,0,149,147,1, + 0,0,0,149,150,1,0,0,0,150,152,1,0,0,0,151,149,1,0,0,0,152,153,6, + 8,1,0,153,19,1,0,0,0,154,156,5,33,0,0,155,154,1,0,0,0,156,157,1, + 0,0,0,157,155,1,0,0,0,157,158,1,0,0,0,158,162,1,0,0,0,159,161,8, + 3,0,0,160,159,1,0,0,0,161,164,1,0,0,0,162,160,1,0,0,0,162,163,1, + 0,0,0,163,168,1,0,0,0,164,162,1,0,0,0,165,167,5,33,0,0,166,165,1, + 0,0,0,167,170,1,0,0,0,168,166,1,0,0,0,168,169,1,0,0,0,169,174,1, + 0,0,0,170,168,1,0,0,0,171,173,8,3,0,0,172,171,1,0,0,0,173,176,1, + 0,0,0,174,172,1,0,0,0,174,175,1,0,0,0,175,177,1,0,0,0,176,174,1, + 0,0,0,177,178,6,9,1,0,178,21,1,0,0,0,179,181,5,59,0,0,180,179,1, + 0,0,0,181,182,1,0,0,0,182,180,1,0,0,0,182,183,1,0,0,0,183,187,1, + 0,0,0,184,186,8,3,0,0,185,184,1,0,0,0,186,189,1,0,0,0,187,185,1, + 0,0,0,187,188,1,0,0,0,188,193,1,0,0,0,189,187,1,0,0,0,190,192,5, + 59,0,0,191,190,1,0,0,0,192,195,1,0,0,0,193,191,1,0,0,0,193,194,1, + 0,0,0,194,199,1,0,0,0,195,193,1,0,0,0,196,198,8,3,0,0,197,196,1, + 0,0,0,198,201,1,0,0,0,199,197,1,0,0,0,199,200,1,0,0,0,200,202,1, + 0,0,0,201,199,1,0,0,0,202,203,6,10,1,0,203,23,1,0,0,0,204,209,3, + 40,19,0,205,206,7,4,0,0,206,208,3,40,19,0,207,205,1,0,0,0,208,211, + 1,0,0,0,209,207,1,0,0,0,209,210,1,0,0,0,210,25,1,0,0,0,211,209,1, + 0,0,0,212,213,3,24,11,0,213,214,5,45,0,0,214,215,3,24,11,0,215,27, + 1,0,0,0,216,217,3,24,11,0,217,218,5,45,0,0,218,219,3,24,11,0,219, + 220,5,45,0,0,220,221,3,24,11,0,221,29,1,0,0,0,222,223,3,24,11,0, + 223,224,5,45,0,0,224,225,3,24,11,0,225,226,5,45,0,0,226,227,3,24, + 11,0,227,228,5,45,0,0,228,229,3,24,11,0,229,31,1,0,0,0,230,231,7, + 5,0,0,231,33,1,0,0,0,232,235,3,32,15,0,233,235,3,14,6,0,234,232, + 1,0,0,0,234,233,1,0,0,0,235,35,1,0,0,0,236,239,3,34,16,0,237,239, + 7,6,0,0,238,236,1,0,0,0,238,237,1,0,0,0,239,37,1,0,0,0,240,243,3, + 36,17,0,241,243,7,7,0,0,242,240,1,0,0,0,242,241,1,0,0,0,243,39,1, + 0,0,0,244,248,3,36,17,0,245,247,3,38,18,0,246,245,1,0,0,0,247,250, + 1,0,0,0,248,246,1,0,0,0,248,249,1,0,0,0,249,41,1,0,0,0,250,248,1, + 0,0,0,251,253,7,8,0,0,252,251,1,0,0,0,253,254,1,0,0,0,254,252,1, + 0,0,0,254,255,1,0,0,0,255,256,1,0,0,0,256,257,6,20,2,0,257,43,1, + 0,0,0,258,260,7,3,0,0,259,258,1,0,0,0,260,261,1,0,0,0,261,259,1, + 0,0,0,261,262,1,0,0,0,262,45,1,0,0,0,263,268,5,123,0,0,264,267,3, + 46,22,0,265,267,9,0,0,0,266,264,1,0,0,0,266,265,1,0,0,0,267,270, + 1,0,0,0,268,269,1,0,0,0,268,266,1,0,0,0,269,271,1,0,0,0,270,268, + 1,0,0,0,271,272,5,125,0,0,272,273,1,0,0,0,273,274,6,22,1,0,274,47, + 1,0,0,0,275,301,7,9,0,0,276,278,5,47,0,0,277,279,5,47,0,0,278,277, + 1,0,0,0,279,280,1,0,0,0,280,278,1,0,0,0,280,281,1,0,0,0,281,301, + 1,0,0,0,282,284,5,42,0,0,283,285,5,42,0,0,284,283,1,0,0,0,285,286, + 1,0,0,0,286,284,1,0,0,0,286,287,1,0,0,0,287,301,1,0,0,0,288,290, + 5,61,0,0,289,291,5,61,0,0,290,289,1,0,0,0,291,292,1,0,0,0,292,290, + 1,0,0,0,292,293,1,0,0,0,293,301,1,0,0,0,294,295,5,82,0,0,295,296, + 5,69,0,0,296,297,5,77,0,0,297,298,5,65,0,0,298,299,5,82,0,0,299, + 301,5,75,0,0,300,275,1,0,0,0,300,276,1,0,0,0,300,282,1,0,0,0,300, + 288,1,0,0,0,300,294,1,0,0,0,301,305,1,0,0,0,302,304,5,32,0,0,303, + 302,1,0,0,0,304,307,1,0,0,0,305,303,1,0,0,0,305,306,1,0,0,0,306, + 308,1,0,0,0,307,305,1,0,0,0,308,309,3,44,21,0,309,310,1,0,0,0,310, + 311,6,23,1,0,311,49,1,0,0,0,312,338,7,9,0,0,313,315,5,47,0,0,314, + 316,5,47,0,0,315,314,1,0,0,0,316,317,1,0,0,0,317,315,1,0,0,0,317, + 318,1,0,0,0,318,338,1,0,0,0,319,321,5,42,0,0,320,322,5,42,0,0,321, + 320,1,0,0,0,322,323,1,0,0,0,323,321,1,0,0,0,323,324,1,0,0,0,324, + 338,1,0,0,0,325,327,5,61,0,0,326,328,5,61,0,0,327,326,1,0,0,0,328, + 329,1,0,0,0,329,327,1,0,0,0,329,330,1,0,0,0,330,338,1,0,0,0,331, + 332,5,82,0,0,332,333,5,69,0,0,333,334,5,77,0,0,334,335,5,65,0,0, + 335,336,5,82,0,0,336,338,5,75,0,0,337,312,1,0,0,0,337,313,1,0,0, + 0,337,319,1,0,0,0,337,325,1,0,0,0,337,331,1,0,0,0,338,342,1,0,0, + 0,339,341,8,3,0,0,340,339,1,0,0,0,341,344,1,0,0,0,342,340,1,0,0, + 0,342,343,1,0,0,0,343,345,1,0,0,0,344,342,1,0,0,0,345,346,3,44,21, + 0,346,347,1,0,0,0,347,348,6,24,1,0,348,51,1,0,0,0,349,350,5,119, + 0,0,350,351,5,49,0,0,351,53,1,0,0,0,352,353,5,119,0,0,353,354,5, + 50,0,0,354,55,1,0,0,0,355,356,5,119,0,0,356,357,5,51,0,0,357,57, + 1,0,0,0,358,359,5,119,0,0,359,360,5,52,0,0,360,59,1,0,0,0,361,362, + 5,68,0,0,362,363,5,97,0,0,363,364,5,116,0,0,364,365,5,97,0,0,365, + 367,5,32,0,0,366,361,1,0,0,0,366,367,1,0,0,0,367,368,1,0,0,0,368, + 369,5,72,0,0,369,370,5,101,0,0,370,371,5,105,0,0,371,372,5,103,0, + 0,372,373,5,104,0,0,373,374,5,116,0,0,374,61,1,0,0,0,375,376,5,86, + 0,0,376,377,5,111,0,0,377,378,5,108,0,0,378,379,5,117,0,0,379,380, + 5,109,0,0,380,381,5,101,0,0,381,63,1,0,0,0,382,383,5,83,0,0,383, + 384,5,47,0,0,384,385,5,78,0,0,385,65,1,0,0,0,386,388,7,8,0,0,387, + 386,1,0,0,0,388,389,1,0,0,0,389,387,1,0,0,0,389,390,1,0,0,0,390, + 391,1,0,0,0,391,392,6,32,2,0,392,67,1,0,0,0,393,395,7,3,0,0,394, + 393,1,0,0,0,395,396,1,0,0,0,396,394,1,0,0,0,396,397,1,0,0,0,397, + 398,1,0,0,0,398,399,6,33,3,0,399,69,1,0,0,0,45,0,1,89,94,98,101, 105,109,112,120,127,132,137,143,149,157,162,168,174,182,187,193, - 199,228,232,236,242,248,255,260,262,272,278,284,292,297,309,315, - 321,329,334,358,381,388,4,5,1,0,0,1,0,6,0,0,4,0,0 + 199,209,234,238,242,248,254,261,266,268,280,286,292,300,305,317, + 323,329,337,342,366,389,396,4,5,1,0,0,1,0,6,0,0,4,0,0 ] class SparkyPKLexer(Lexer): @@ -179,21 +182,20 @@ class SparkyPKLexer(Lexer): Assignment_2d_ex = 9 Assignment_3d_ex = 10 Assignment_4d_ex = 11 - Simple_name = 12 - SPACE = 13 - RETURN = 14 - ENCLOSE_COMMENT = 15 - SECTION_COMMENT = 16 - LINE_COMMENT = 17 - W1_LA = 18 - W2_LA = 19 - W3_LA = 20 - W4_LA = 21 - Height_LA = 22 - Volume_LA = 23 - S_N_LA = 24 - SPACE_LA = 25 - RETURN_LA = 26 + SPACE = 12 + RETURN = 13 + ENCLOSE_COMMENT = 14 + SECTION_COMMENT = 15 + LINE_COMMENT = 16 + W1_LA = 17 + W2_LA = 18 + W3_LA = 19 + W4_LA = 20 + Height_LA = 21 + Volume_LA = 22 + S_N_LA = 23 + SPACE_LA = 24 + RETURN_LA = 25 channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ] @@ -205,14 +207,14 @@ class SparkyPKLexer(Lexer): symbolicNames = [ "", "Assignment", "W1", "Integer", "Float", "Real", "SHARP_COMMENT", "EXCLM_COMMENT", "SMCLN_COMMENT", "Assignment_2d_ex", "Assignment_3d_ex", - "Assignment_4d_ex", "Simple_name", "SPACE", "RETURN", "ENCLOSE_COMMENT", - "SECTION_COMMENT", "LINE_COMMENT", "W1_LA", "W2_LA", "W3_LA", - "W4_LA", "Height_LA", "Volume_LA", "S_N_LA", "SPACE_LA", "RETURN_LA" ] + "Assignment_4d_ex", "SPACE", "RETURN", "ENCLOSE_COMMENT", "SECTION_COMMENT", + "LINE_COMMENT", "W1_LA", "W2_LA", "W3_LA", "W4_LA", "Height_LA", + "Volume_LA", "S_N_LA", "SPACE_LA", "RETURN_LA" ] ruleNames = [ "Assignment", "W1", "Integer", "Float", "Real", "DEC_DOT_DEC", "DEC_DIGIT", "DECIMAL", "SHARP_COMMENT", "EXCLM_COMMENT", - "SMCLN_COMMENT", "Assignment_2d_ex", "Assignment_3d_ex", - "Assignment_4d_ex", "Simple_name", "ALPHA", "ALPHA_NUM", + "SMCLN_COMMENT", "ASS_EACH_AXIS", "Assignment_2d_ex", + "Assignment_3d_ex", "Assignment_4d_ex", "ALPHA", "ALPHA_NUM", "START_CHAR", "NAME_CHAR", "SIMPLE_NAME", "SPACE", "RETURN", "ENCLOSE_COMMENT", "SECTION_COMMENT", "LINE_COMMENT", "W1_LA", "W2_LA", "W3_LA", "W4_LA", "Height_LA", "Volume_LA", diff --git a/wwpdb/utils/nmr/pk/SparkyPKParser.py b/wwpdb/utils/nmr/pk/SparkyPKParser.py index 60db2f46..51f29a7b 100644 --- a/wwpdb/utils/nmr/pk/SparkyPKParser.py +++ b/wwpdb/utils/nmr/pk/SparkyPKParser.py @@ -10,7 +10,7 @@ def serializedATN(): return [ - 4,1,26,123,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 4,1,25,123,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, 6,2,7,7,7,1,0,1,0,5,0,19,8,0,10,0,12,0,22,9,0,1,0,1,0,1,1,1,1,1, 1,1,1,3,1,30,8,1,1,1,3,1,33,8,1,1,1,1,1,3,1,37,8,1,1,1,3,1,40,8, 1,1,1,1,1,4,1,44,8,1,11,1,12,1,45,1,1,4,1,49,8,1,11,1,12,1,50,1, @@ -24,32 +24,32 @@ def serializedATN(): 10,101,1,0,0,0,12,114,1,0,0,0,14,120,1,0,0,0,16,19,3,2,1,0,17,19, 3,4,2,0,18,16,1,0,0,0,18,17,1,0,0,0,19,22,1,0,0,0,20,18,1,0,0,0, 20,21,1,0,0,0,21,23,1,0,0,0,22,20,1,0,0,0,23,24,5,0,0,1,24,1,1,0, - 0,0,25,26,5,1,0,0,26,27,5,18,0,0,27,29,5,19,0,0,28,30,5,20,0,0,29, - 28,1,0,0,0,29,30,1,0,0,0,30,32,1,0,0,0,31,33,5,21,0,0,32,31,1,0, - 0,0,32,33,1,0,0,0,33,34,1,0,0,0,34,36,5,22,0,0,35,37,5,23,0,0,36, - 35,1,0,0,0,36,37,1,0,0,0,37,39,1,0,0,0,38,40,5,24,0,0,39,38,1,0, - 0,0,39,40,1,0,0,0,40,41,1,0,0,0,41,57,5,26,0,0,42,44,3,6,3,0,43, + 0,0,25,26,5,1,0,0,26,27,5,17,0,0,27,29,5,18,0,0,28,30,5,19,0,0,29, + 28,1,0,0,0,29,30,1,0,0,0,30,32,1,0,0,0,31,33,5,20,0,0,32,31,1,0, + 0,0,32,33,1,0,0,0,33,34,1,0,0,0,34,36,5,21,0,0,35,37,5,22,0,0,36, + 35,1,0,0,0,36,37,1,0,0,0,37,39,1,0,0,0,38,40,5,23,0,0,39,38,1,0, + 0,0,39,40,1,0,0,0,40,41,1,0,0,0,41,57,5,25,0,0,42,44,3,6,3,0,43, 42,1,0,0,0,44,45,1,0,0,0,45,43,1,0,0,0,45,46,1,0,0,0,46,58,1,0,0, 0,47,49,3,8,4,0,48,47,1,0,0,0,49,50,1,0,0,0,50,48,1,0,0,0,50,51, 1,0,0,0,51,58,1,0,0,0,52,54,3,10,5,0,53,52,1,0,0,0,54,55,1,0,0,0, 55,53,1,0,0,0,55,56,1,0,0,0,56,58,1,0,0,0,57,43,1,0,0,0,57,48,1, - 0,0,0,57,53,1,0,0,0,58,3,1,0,0,0,59,60,5,2,0,0,60,62,5,19,0,0,61, - 63,5,20,0,0,62,61,1,0,0,0,62,63,1,0,0,0,63,65,1,0,0,0,64,66,5,21, - 0,0,65,64,1,0,0,0,65,66,1,0,0,0,66,67,1,0,0,0,67,69,5,22,0,0,68, - 70,5,23,0,0,69,68,1,0,0,0,69,70,1,0,0,0,70,72,1,0,0,0,71,73,5,24, - 0,0,72,71,1,0,0,0,72,73,1,0,0,0,73,74,1,0,0,0,74,76,5,26,0,0,75, + 0,0,0,57,53,1,0,0,0,58,3,1,0,0,0,59,60,5,2,0,0,60,62,5,18,0,0,61, + 63,5,19,0,0,62,61,1,0,0,0,62,63,1,0,0,0,63,65,1,0,0,0,64,66,5,20, + 0,0,65,64,1,0,0,0,65,66,1,0,0,0,66,67,1,0,0,0,67,69,5,21,0,0,68, + 70,5,22,0,0,69,68,1,0,0,0,69,70,1,0,0,0,70,72,1,0,0,0,71,73,5,23, + 0,0,72,71,1,0,0,0,72,73,1,0,0,0,73,74,1,0,0,0,74,76,5,25,0,0,75, 77,3,12,6,0,76,75,1,0,0,0,77,78,1,0,0,0,78,76,1,0,0,0,78,79,1,0, 0,0,79,5,1,0,0,0,80,81,5,9,0,0,81,82,5,4,0,0,82,84,5,4,0,0,83,85, 3,14,7,0,84,83,1,0,0,0,85,86,1,0,0,0,86,84,1,0,0,0,86,87,1,0,0,0, - 87,88,1,0,0,0,88,89,5,14,0,0,89,7,1,0,0,0,90,91,5,10,0,0,91,92,5, + 87,88,1,0,0,0,88,89,5,13,0,0,89,7,1,0,0,0,90,91,5,10,0,0,91,92,5, 4,0,0,92,93,5,4,0,0,93,95,5,4,0,0,94,96,3,14,7,0,95,94,1,0,0,0,96, - 97,1,0,0,0,97,95,1,0,0,0,97,98,1,0,0,0,98,99,1,0,0,0,99,100,5,14, + 97,1,0,0,0,97,95,1,0,0,0,97,98,1,0,0,0,98,99,1,0,0,0,99,100,5,13, 0,0,100,9,1,0,0,0,101,102,5,11,0,0,102,103,5,4,0,0,103,104,5,4,0, 0,104,105,5,4,0,0,105,107,5,4,0,0,106,108,3,14,7,0,107,106,1,0,0, 0,108,109,1,0,0,0,109,107,1,0,0,0,109,110,1,0,0,0,110,111,1,0,0, - 0,111,112,5,14,0,0,112,11,1,0,0,0,113,115,3,14,7,0,114,113,1,0,0, + 0,111,112,5,13,0,0,112,11,1,0,0,0,113,115,3,14,7,0,114,113,1,0,0, 0,115,116,1,0,0,0,116,114,1,0,0,0,116,117,1,0,0,0,117,118,1,0,0, - 0,118,119,5,14,0,0,119,13,1,0,0,0,120,121,7,0,0,0,121,15,1,0,0,0, + 0,118,119,5,13,0,0,119,13,1,0,0,0,120,121,7,0,0,0,121,15,1,0,0,0, 19,18,20,29,32,36,39,45,50,55,57,62,65,69,72,78,86,97,109,116 ] @@ -67,16 +67,15 @@ class SparkyPKParser ( Parser ): "", "", "", "", "", "", "", "", "", "", "", "", - "", "", "", "'w2'", "'w3'", - "'w4'", "", "'Volume'", "'S/N'" ] + "", "", "'w2'", "'w3'", "'w4'", "", + "'Volume'", "'S/N'" ] symbolicNames = [ "", "Assignment", "W1", "Integer", "Float", "Real", "SHARP_COMMENT", "EXCLM_COMMENT", "SMCLN_COMMENT", "Assignment_2d_ex", "Assignment_3d_ex", "Assignment_4d_ex", - "Simple_name", "SPACE", "RETURN", "ENCLOSE_COMMENT", - "SECTION_COMMENT", "LINE_COMMENT", "W1_LA", "W2_LA", - "W3_LA", "W4_LA", "Height_LA", "Volume_LA", "S_N_LA", - "SPACE_LA", "RETURN_LA" ] + "SPACE", "RETURN", "ENCLOSE_COMMENT", "SECTION_COMMENT", + "LINE_COMMENT", "W1_LA", "W2_LA", "W3_LA", "W4_LA", + "Height_LA", "Volume_LA", "S_N_LA", "SPACE_LA", "RETURN_LA" ] RULE_sparky_pk = 0 RULE_data_label = 1 @@ -102,21 +101,20 @@ class SparkyPKParser ( Parser ): Assignment_2d_ex=9 Assignment_3d_ex=10 Assignment_4d_ex=11 - Simple_name=12 - SPACE=13 - RETURN=14 - ENCLOSE_COMMENT=15 - SECTION_COMMENT=16 - LINE_COMMENT=17 - W1_LA=18 - W2_LA=19 - W3_LA=20 - W4_LA=21 - Height_LA=22 - Volume_LA=23 - S_N_LA=24 - SPACE_LA=25 - RETURN_LA=26 + SPACE=12 + RETURN=13 + ENCLOSE_COMMENT=14 + SECTION_COMMENT=15 + LINE_COMMENT=16 + W1_LA=17 + W2_LA=18 + W3_LA=19 + W4_LA=20 + Height_LA=21 + Volume_LA=22 + S_N_LA=23 + SPACE_LA=24 + RETURN_LA=25 def __init__(self, input:TokenStream, output:TextIO = sys.stdout): super().__init__(input, output) @@ -290,7 +288,7 @@ def data_label(self): self.state = 29 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==20: + if _la==19: self.state = 28 self.match(SparkyPKParser.W3_LA) @@ -298,7 +296,7 @@ def data_label(self): self.state = 32 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==21: + if _la==20: self.state = 31 self.match(SparkyPKParser.W4_LA) @@ -308,7 +306,7 @@ def data_label(self): self.state = 36 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==23: + if _la==22: self.state = 35 self.match(SparkyPKParser.Volume_LA) @@ -316,7 +314,7 @@ def data_label(self): self.state = 39 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==24: + if _la==23: self.state = 38 self.match(SparkyPKParser.S_N_LA) @@ -446,7 +444,7 @@ def data_label_wo_assign(self): self.state = 62 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==20: + if _la==19: self.state = 61 self.match(SparkyPKParser.W3_LA) @@ -454,7 +452,7 @@ def data_label_wo_assign(self): self.state = 65 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==21: + if _la==20: self.state = 64 self.match(SparkyPKParser.W4_LA) @@ -464,7 +462,7 @@ def data_label_wo_assign(self): self.state = 69 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==23: + if _la==22: self.state = 68 self.match(SparkyPKParser.Volume_LA) @@ -472,7 +470,7 @@ def data_label_wo_assign(self): self.state = 72 self._errHandler.sync(self) _la = self._input.LA(1) - if _la==24: + if _la==23: self.state = 71 self.match(SparkyPKParser.S_N_LA) diff --git a/wwpdb/utils/nmr/pk/SparkyPKParserListener.py b/wwpdb/utils/nmr/pk/SparkyPKParserListener.py index 31e2584b..8f556374 100644 --- a/wwpdb/utils/nmr/pk/SparkyPKParserListener.py +++ b/wwpdb/utils/nmr/pk/SparkyPKParserListener.py @@ -1,84 +1,844 @@ -# Generated from SparkyPKParser.g4 by ANTLR 4.13.0 -from antlr4 import * -if "." in __name__: - from .SparkyPKParser import SparkyPKParser -else: - from SparkyPKParser import SparkyPKParser +## +# File: SparkyPKParserListener.py +# Date: 04-Dec-2024 +# +# Updates: +""" ParserLister class for SPARKY PK files. + @author: Masashi Yokochi +""" +import sys +import copy +import numpy as np + +from antlr4 import ParseTreeListener + +try: + from wwpdb.utils.nmr.pk.SparkyPKParser import SparkyPKParser + from wwpdb.utils.nmr.pk.BasePKParserListener import BasePKParserListener + from wwpdb.utils.nmr.mr.ParserListenerUtil import (REPRESENTATIVE_MODEL_ID, + REPRESENTATIVE_ALT_ID, + SPECTRAL_DIM_TEMPLATE, + extractPeakAssignment, + getPkRow) + +except ImportError: + from nmr.pk.SparkyPKParser import SparkyPKParser + from nmr.pk.BasePKParserListener import BasePKParserListener + from nmr.mr.ParserListenerUtil import (REPRESENTATIVE_MODEL_ID, + REPRESENTATIVE_ALT_ID, + SPECTRAL_DIM_TEMPLATE, + extractPeakAssignment, + getPkRow) + # This class defines a complete listener for a parse tree produced by SparkyPKParser. -class SparkyPKParserListener(ParseTreeListener): +class SparkyPKParserListener(ParseTreeListener, BasePKParserListener): + + __has_volume = False + + def __init__(self, verbose=True, log=sys.stdout, + representativeModelId=REPRESENTATIVE_MODEL_ID, + representativeAltId=REPRESENTATIVE_ALT_ID, + mrAtomNameMapping=None, + cR=None, caC=None, ccU=None, csStat=None, nefT=None, + reasons=None): + super().__init__(verbose, log, representativeModelId, representativeAltId, + mrAtomNameMapping, cR, caC, ccU, csStat, nefT, reasons) + + self.file_type = 'nm-pea-spa' + self.software_name = 'SPARKY' # Enter a parse tree produced by SparkyPKParser#sparky_pk. - def enterSparky_pk(self, ctx:SparkyPKParser.Sparky_pkContext): - pass + def enterSparky_pk(self, ctx: SparkyPKParser.Sparky_pkContext): # pylint: disable=unused-argument + self.num_of_dim = -1 + self.spectral_dim = {} + self.listIdInternal = {} + self.chainNumberDict = {} + self.extResKey = [] + self.polySeqRst = [] + self.polySeqRstFailed = [] + self.polySeqRstFailedAmbig = [] + self.compIdMap = {} + self.f = [] # Exit a parse tree produced by SparkyPKParser#sparky_pk. - def exitSparky_pk(self, ctx:SparkyPKParser.Sparky_pkContext): - pass + 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 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 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. - def enterData_label(self, ctx:SparkyPKParser.Data_labelContext): - pass + def enterData_label(self, ctx: SparkyPKParser.Data_labelContext): + if ctx.W1_LA(): + self.num_of_dim = max(self.num_of_dim, 1) + if ctx.W2_LA(): + self.num_of_dim = max(self.num_of_dim, 2) + if ctx.W3_LA(): + self.num_of_dim = max(self.num_of_dim, 3) + if ctx.W4_LA(): + self.num_of_dim = max(self.num_of_dim, 4) + + self.__has_volume = False + + if ctx.Volume_LA(): + self.__has_volume = True + + self.fillCurrentSpectralDim() # Exit a parse tree produced by SparkyPKParser#data_label. - def exitData_label(self, ctx:SparkyPKParser.Data_labelContext): + def exitData_label(self, ctx: SparkyPKParser.Data_labelContext): # pylint: disable=unused-argument pass - # Enter a parse tree produced by SparkyPKParser#data_label_wo_assign. - def enterData_label_wo_assign(self, ctx:SparkyPKParser.Data_label_wo_assignContext): - pass + def enterData_label_wo_assign(self, ctx: SparkyPKParser.Data_label_wo_assignContext): + if ctx.W1_LA(): + self.num_of_dim = max(self.num_of_dim, 1) + if ctx.W2_LA(): + self.num_of_dim = max(self.num_of_dim, 2) + if ctx.W3_LA(): + self.num_of_dim = max(self.num_of_dim, 3) + if ctx.W4_LA(): + self.num_of_dim = max(self.num_of_dim, 4) + + self.__has_volume = False + + if ctx.Volume_LA(): + self.__has_volume = True + + self.fillCurrentSpectralDim() # Exit a parse tree produced by SparkyPKParser#data_label_wo_assign. - def exitData_label_wo_assign(self, ctx:SparkyPKParser.Data_label_wo_assignContext): + def exitData_label_wo_assign(self, ctx: SparkyPKParser.Data_label_wo_assignContext): # pylint: disable=unused-argument pass - # Enter a parse tree produced by SparkyPKParser#peak_2d. - def enterPeak_2d(self, ctx:SparkyPKParser.Peak_2dContext): - pass + def enterPeak_2d(self, ctx: SparkyPKParser.Peak_2dContext): # pylint: disable=unused-argument + self.peaks2D += 1 + + self.atomSelectionSet.clear() # Exit a parse tree produced by SparkyPKParser#peak_2d. - def exitPeak_2d(self, ctx:SparkyPKParser.Peak_2dContext): - pass + def exitPeak_2d(self, ctx: SparkyPKParser.Peak_2dContext): + + try: + + if len(self.numberSelection) == 0: + self.peaks2D -= 1 + return + + index = self.peaks2D + + ass = str(ctx.Assignment_2d_ex()) + if ass.startswith('?'): + ass = None + + x_ppm = float(str(ctx.Float(0))) + y_ppm = float(str(ctx.Float(1))) + + height = self.originalNumberSelection[0] + if self.__has_volume: + volume = self.originalNumberSelection[1] + + if not self.hasPolySeq and not self.hasNonPolySeq: + return + + if x_ppm is None or y_ppm is None: + self.peaks2D -= 1 + return + + dstFunc = self.validatePeak2D(index, x_ppm, y_ppm, None, None, None, None, + None, None, None, None, height, None, volume if self.__has_volume else None, None) + + if dstFunc is None: + self.peaks2D -= 1 + return + + cur_spectral_dim = self.spectral_dim[self.num_of_dim][self.cur_list_id] + cur_spectral_dim[1]['freq_hint'].append(x_ppm) + cur_spectral_dim[2]['freq_hint'].append(y_ppm) + + has_assignments = False + + if ass is not None: + assignments =\ + extractPeakAssignment(self.num_of_dim, ass, self.authAsymIdSet, self.compIdSet, self.altCompIdSet, + self.polyPeptide, self.polyDeoxyribonucleotide, self.polyRibonucleotide, self.nefT) + + if assignments is not None: + + self.retrieveLocalSeqScheme() + + hasChainId = all(a['chain_id'] is not None for a in assignments) + hasCompId = all(a['comp_id'] is not None for a in assignments) + + a1 = assignments[0] + a2 = assignments[1] + + if hasChainId and hasCompId: + chainAssign1, asis1 = self.assignCoordPolymerSequenceWithChainId(a1['chain_id'], a1['seq_id'], a1['comp_id'], a1['atom_id'], index) + chainAssign2, asis2 = self.assignCoordPolymerSequenceWithChainId(a2['chain_id'], a2['seq_id'], a2['comp_id'], a2['atom_id'], index) + + elif hasChainId: + chainAssign1 = self.assignCoordPolymerSequenceWithChainIdWithoutCompId(a1['chain_id'], a1['seq_id'], a1['atom_id'], index) + chainAssign2 = self.assignCoordPolymerSequenceWithChainIdWithoutCompId(a2['chain_id'], a2['seq_id'], a2['atom_id'], index) + asis1 = asis2 = False + + elif hasCompId: + chainAssign1, asis1 = self.assignCoordPolymerSequence(a1['chain_id'], a1['seq_id'], a1['comp_id'], a1['atom_id'], index) + chainAssign2, asis2 = self.assignCoordPolymerSequence(a2['chain_id'], a2['seq_id'], a2['comp_id'], a2['atom_id'], index) + + else: + chainAssign1 = self.assignCoordPolymerSequenceWithoutCompId(a1['seq_id'], a1['atom_id'], index) + chainAssign2 = self.assignCoordPolymerSequenceWithoutCompId(a2['seq_id'], a2['atom_id'], index) + asis1 = asis2 = False + + if len(chainAssign1) > 0 and len(chainAssign2) > 0: + self.selectCoordAtoms(chainAssign1, a1['seq_id'], a1['comp_id'], a1['atom_id'], index) + self.selectCoordAtoms(chainAssign2, a2['seq_id'], a2['comp_id'], a2['atom_id'], index) + + if len(self.atomSelectionSet) == self.num_of_dim: + has_assignments = True + + if self.createSfDict__: + sf = self.getSf() + + if self.debug: + print(f"subtype={self.cur_subtype} id={self.peaks2D} (index={index}) " + f"{ass} -> {self.atomSelectionSet[0] if has_assignments else None} {self.atomSelectionSet[1] if has_assignments else None} {dstFunc}") + + if self.createSfDict__ and sf is not None: + sf['index_id'] += 1 + ambig_code1 = ambig_code2 = None + if has_assignments: + atom1 = self.atomSelectionSet[0][0] + atom2 = self.atomSelectionSet[1][0] + if len(self.atomSelectionSet[0]) > 1: + ambig_code1 = self.csStat.getMaxAmbigCodeWoSetId(atom1['comp_id'], atom1['atom_id']) + if ambig_code1 == 0: + ambig_code1 = None + if len(self.atomSelectionSet[1]) > 1: + ambig_code2 = self.csStat.getMaxAmbigCodeWoSetId(atom2['comp_id'], atom2['atom_id']) + if ambig_code2 == 0: + ambig_code2 = None + else: + atom1 = atom2 = None + + row = getPkRow(self.cur_subtype, sf['id'], sf['index_id'], + sf['list_id'], self.entryId, dstFunc, + self.authToStarSeq, self.authToOrigSeq, self.offsetHolder, + atom1, atom2, asis1=asis1, asis2=asis2, + ambig_code1=ambig_code1, ambig_code2=ambig_code2, details=ass) + sf['loop'].add_data(row) + + finally: + self.numberSelection.clear() + self.originalNumberSelection.clear() # Enter a parse tree produced by SparkyPKParser#peak_3d. - def enterPeak_3d(self, ctx:SparkyPKParser.Peak_3dContext): - pass + def enterPeak_3d(self, ctx: SparkyPKParser.Peak_3dContext): # pylint: disable=unused-argument + self.peaks3D += 1 + + self.atomSelectionSet.clear() # Exit a parse tree produced by SparkyPKParser#peak_3d. - def exitPeak_3d(self, ctx:SparkyPKParser.Peak_3dContext): - pass + def exitPeak_3d(self, ctx: SparkyPKParser.Peak_3dContext): + + try: + + if len(self.numberSelection) == 0: + self.peaks3D -= 1 + return + + index = self.peaks3D + + ass = str(ctx.Assignment_3d_ex()) + if ass.startswith('?'): + ass = None + + x_ppm = float(str(ctx.Float(0))) + y_ppm = float(str(ctx.Float(1))) + z_ppm = float(str(ctx.Float(2))) + + height = self.originalNumberSelection[0] + if self.__has_volume: + volume = self.originalNumberSelection[1] + + if not self.hasPolySeq and not self.hasNonPolySeq: + return + + if x_ppm is None or y_ppm is None or z_ppm is None: + self.peaks3D -= 1 + return + + dstFunc = self.validatePeak3D(index, x_ppm, y_ppm, z_ppm, None, None, None, None, None, None, + None, None, None, None, None, None, height, None, volume if self.__has_volume else None, None) + + if dstFunc is None: + self.peaks3D -= 1 + return + + cur_spectral_dim = self.spectral_dim[self.num_of_dim][self.cur_list_id] + + cur_spectral_dim[1]['freq_hint'].append(x_ppm) + cur_spectral_dim[2]['freq_hint'].append(y_ppm) + cur_spectral_dim[3]['freq_hint'].append(z_ppm) + + has_assignments = False + + if ass is not None: + assignments =\ + extractPeakAssignment(self.num_of_dim, ass, self.authAsymIdSet, self.compIdSet, self.altCompIdSet, + self.polyPeptide, self.polyDeoxyribonucleotide, self.polyRibonucleotide, self.nefT) + print(f'{ass=} {assignments=}') + + if assignments is not None: + + self.retrieveLocalSeqScheme() + + hasChainId = all(a['chain_id'] is not None for a in assignments) + hasCompId = all(a['comp_id'] is not None for a in assignments) + + a1 = assignments[0] + a2 = assignments[1] + a3 = assignments[2] + + if hasChainId and hasCompId: + chainAssign1, asis1 = self.assignCoordPolymerSequenceWithChainId(a1['chain_id'], a1['seq_id'], a1['comp_id'], a1['atom_id'], index) + chainAssign2, asis2 = self.assignCoordPolymerSequenceWithChainId(a2['chain_id'], a2['seq_id'], a2['comp_id'], a2['atom_id'], index) + chainAssign3, asis3 = self.assignCoordPolymerSequenceWithChainId(a3['chain_id'], a3['seq_id'], a3['comp_id'], a3['atom_id'], index) + + elif hasChainId: + chainAssign1 = self.assignCoordPolymerSequenceWithChainIdWithoutCompId(a1['chain_id'], a1['seq_id'], a1['atom_id'], index) + chainAssign2 = self.assignCoordPolymerSequenceWithChainIdWithoutCompId(a2['chain_id'], a2['seq_id'], a2['atom_id'], index) + chainAssign3 = self.assignCoordPolymerSequenceWithChainIdWithoutCompId(a3['chain_id'], a3['seq_id'], a3['atom_id'], index) + asis1 = asis2 = asis3 = False + + elif hasCompId: + chainAssign1, asis1 = self.assignCoordPolymerSequence(a1['chain_id'], a1['seq_id'], a1['comp_id'], a1['atom_id'], index) + chainAssign2, asis2 = self.assignCoordPolymerSequence(a2['chain_id'], a2['seq_id'], a2['comp_id'], a2['atom_id'], index) + chainAssign3, asis3 = self.assignCoordPolymerSequence(a3['chain_id'], a3['seq_id'], a3['comp_id'], a3['atom_id'], index) + + else: + chainAssign1 = self.assignCoordPolymerSequenceWithoutCompId(a1['seq_id'], a1['atom_id'], index) + chainAssign2 = self.assignCoordPolymerSequenceWithoutCompId(a2['seq_id'], a2['atom_id'], index) + chainAssign3 = self.assignCoordPolymerSequenceWithoutCompId(a3['seq_id'], a3['atom_id'], index) + asis1 = asis2 = asis3 = False + + if len(chainAssign1) > 0 and len(chainAssign2) > 0 and len(chainAssign3) > 0: + self.selectCoordAtoms(chainAssign1, a1['seq_id'], a1['comp_id'], a1['atom_id'], index) + self.selectCoordAtoms(chainAssign2, a2['seq_id'], a2['comp_id'], a2['atom_id'], index) + self.selectCoordAtoms(chainAssign3, a3['seq_id'], a3['comp_id'], a3['atom_id'], index) + if len(self.atomSelectionSet) == self.num_of_dim: + has_assignments = True + + if self.createSfDict__: + sf = self.getSf() + + if self.debug: + print(f"subtype={self.cur_subtype} id={self.peaks3D} (index={index}) " + f"{ass} -> {self.atomSelectionSet[0] if has_assignments else None} {self.atomSelectionSet[1] if has_assignments else None} " + f"{self.atomSelectionSet[2] if has_assignments else None} {dstFunc}") + + if self.createSfDict__ and sf is not None: + sf['index_id'] += 1 + ambig_code1 = ambig_code2 = ambig_code3 = None + if has_assignments: + atom1 = self.atomSelectionSet[0][0] + atom2 = self.atomSelectionSet[1][0] + atom3 = self.atomSelectionSet[2][0] + if len(self.atomSelectionSet[0]) > 1: + ambig_code1 = self.csStat.getMaxAmbigCodeWoSetId(atom1['comp_id'], atom1['atom_id']) + if ambig_code1 == 0: + ambig_code1 = None + if len(self.atomSelectionSet[1]) > 1: + ambig_code2 = self.csStat.getMaxAmbigCodeWoSetId(atom2['comp_id'], atom2['atom_id']) + if ambig_code2 == 0: + ambig_code2 = None + if len(self.atomSelectionSet[2]) > 1: + ambig_code3 = self.csStat.getMaxAmbigCodeWoSetId(atom3['comp_id'], atom3['atom_id']) + if ambig_code3 == 0: + ambig_code3 = None + else: + atom1 = atom2 = atom3 = None + + row = getPkRow(self.cur_subtype, sf['id'], sf['index_id'], + sf['list_id'], self.entryId, dstFunc, + self.authToStarSeq, self.authToOrigSeq, self.offsetHolder, + atom1, atom2, atom3, asis1=asis1, asis2=asis2, asis3=asis3, + ambig_code1=ambig_code1, ambig_code2=ambig_code2, + ambig_code3=ambig_code3, details=ass) + sf['loop'].add_data(row) + + finally: + self.numberSelection.clear() + self.originalNumberSelection.clear() # Enter a parse tree produced by SparkyPKParser#peak_4d. - def enterPeak_4d(self, ctx:SparkyPKParser.Peak_4dContext): - pass + def enterPeak_4d(self, ctx: SparkyPKParser.Peak_4dContext): # pylint: disable=unused-argument + self.peaks4D += 1 + + self.atomSelectionSet.clear() # Exit a parse tree produced by SparkyPKParser#peak_4d. - def exitPeak_4d(self, ctx:SparkyPKParser.Peak_4dContext): - pass + def exitPeak_4d(self, ctx: SparkyPKParser.Peak_4dContext): + + try: + + if len(self.numberSelection) == 0: + self.peaks4D -= 1 + return + + index = self.peaks4D + + ass = str(ctx.Assignment_4d_ex()) + if ass.startswith('?'): + ass = None + + x_ppm = float(str(ctx.Float(0))) + y_ppm = float(str(ctx.Float(1))) + z_ppm = float(str(ctx.Float(2))) + a_ppm = float(str(ctx.Float(3))) + + height = self.originalNumberSelection[0] + if self.__has_volume: + volume = self.originalNumberSelection[1] + + if not self.hasPolySeq and not self.hasNonPolySeq: + return + + if x_ppm is None or y_ppm is None or z_ppm is None or a_ppm is None: + self.peaks4D -= 1 + return + + dstFunc = self.validatePeak4D(index, x_ppm, y_ppm, z_ppm, a_ppm, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, height, None, volume if self.__has_volume else None, None) + + if dstFunc is None: + self.peaks4D -= 1 + return + + cur_spectral_dim = self.spectral_dim[self.num_of_dim][self.cur_list_id] + + cur_spectral_dim[1]['freq_hint'].append(x_ppm) + cur_spectral_dim[2]['freq_hint'].append(y_ppm) + cur_spectral_dim[3]['freq_hint'].append(z_ppm) + cur_spectral_dim[4]['freq_hint'].append(a_ppm) + + has_assignments = False + + if ass is not None: + assignments =\ + extractPeakAssignment(self.num_of_dim, ass, self.authAsymIdSet, self.compIdSet, self.altCompIdSet, + self.polyPeptide, self.polyDeoxyribonucleotide, self.polyRibonucleotide, self.nefT) + if assignments is not None: + + self.retrieveLocalSeqScheme() + + hasChainId = all(a['chain_id'] is not None for a in assignments) + hasCompId = all(a['comp_id'] is not None for a in assignments) + + a1 = assignments[0] + a2 = assignments[1] + a3 = assignments[2] + a4 = assignments[3] + + if hasChainId and hasCompId: + chainAssign1, asis1 = self.assignCoordPolymerSequenceWithChainId(a1['chain_id'], a1['seq_id'], a1['comp_id'], a1['atom_id'], index) + chainAssign2, asis2 = self.assignCoordPolymerSequenceWithChainId(a2['chain_id'], a2['seq_id'], a2['comp_id'], a2['atom_id'], index) + chainAssign3, asis3 = self.assignCoordPolymerSequenceWithChainId(a3['chain_id'], a3['seq_id'], a3['comp_id'], a3['atom_id'], index) + chainAssign4, asis4 = self.assignCoordPolymerSequenceWithChainId(a4['chain_id'], a4['seq_id'], a4['comp_id'], a4['atom_id'], index) + + elif hasChainId: + chainAssign1 = self.assignCoordPolymerSequenceWithChainIdWithoutCompId(a1['chain_id'], a1['seq_id'], a1['atom_id'], index) + chainAssign2 = self.assignCoordPolymerSequenceWithChainIdWithoutCompId(a2['chain_id'], a2['seq_id'], a2['atom_id'], index) + chainAssign3 = self.assignCoordPolymerSequenceWithChainIdWithoutCompId(a3['chain_id'], a3['seq_id'], a3['atom_id'], index) + chainAssign4 = self.assignCoordPolymerSequenceWithChainIdWithoutCompId(a4['chain_id'], a4['seq_id'], a4['atom_id'], index) + asis1 = asis2 = asis3 = asis4 = False + + elif hasCompId: + chainAssign1, asis1 = self.assignCoordPolymerSequence(a1['chain_id'], a1['seq_id'], a1['comp_id'], a1['atom_id'], index) + chainAssign2, asis2 = self.assignCoordPolymerSequence(a2['chain_id'], a2['seq_id'], a2['comp_id'], a2['atom_id'], index) + chainAssign3, asis3 = self.assignCoordPolymerSequence(a3['chain_id'], a3['seq_id'], a3['comp_id'], a3['atom_id'], index) + chainAssign4, asis4 = self.assignCoordPolymerSequence(a4['chain_id'], a4['seq_id'], a4['comp_id'], a4['atom_id'], index) + + else: + chainAssign1 = self.assignCoordPolymerSequenceWithoutCompId(a1['seq_id'], a1['atom_id'], index) + chainAssign2 = self.assignCoordPolymerSequenceWithoutCompId(a2['seq_id'], a2['atom_id'], index) + chainAssign3 = self.assignCoordPolymerSequenceWithoutCompId(a3['seq_id'], a3['atom_id'], index) + chainAssign4 = self.assignCoordPolymerSequenceWithoutCompId(a4['seq_id'], a4['atom_id'], index) + asis1 = asis2 = asis3 = asis4 = False + + if len(chainAssign1) > 0 and len(chainAssign2) > 0 and len(chainAssign3) > 0 and len(chainAssign4) > 0: + self.selectCoordAtoms(chainAssign1, a1['seq_id'], a1['comp_id'], a1['atom_id'], index) + self.selectCoordAtoms(chainAssign2, a2['seq_id'], a2['comp_id'], a2['atom_id'], index) + self.selectCoordAtoms(chainAssign3, a3['seq_id'], a3['comp_id'], a3['atom_id'], index) + self.selectCoordAtoms(chainAssign4, a4['seq_id'], a4['comp_id'], a4['atom_id'], index) + + if len(self.atomSelectionSet) == self.num_of_dim: + has_assignments = True + + if self.createSfDict__: + sf = self.getSf() + + if self.debug: + print(f"subtype={self.cur_subtype} id={self.peaks4D} (index={index}) " + f"{ass} -> {self.atomSelectionSet[0] if has_assignments else None} {self.atomSelectionSet[1] if has_assignments else None} " + f"{self.atomSelectionSet[2] if has_assignments else None} {self.atomSelectionSet[3] if has_assignments else None} {dstFunc}") + + if self.createSfDict__ and sf is not None: + sf['index_id'] += 1 + ambig_code1 = ambig_code2 = ambig_code3 = ambig_code4 = None + if has_assignments: + atom1 = self.atomSelectionSet[0][0] + atom2 = self.atomSelectionSet[1][0] + atom3 = self.atomSelectionSet[2][0] + atom4 = self.atomSelectionSet[3][0] + if len(self.atomSelectionSet[0]) > 1: + ambig_code1 = self.csStat.getMaxAmbigCodeWoSetId(atom1['comp_id'], atom1['atom_id']) + if ambig_code1 == 0: + ambig_code1 = None + if len(self.atomSelectionSet[1]) > 1: + ambig_code2 = self.csStat.getMaxAmbigCodeWoSetId(atom2['comp_id'], atom2['atom_id']) + if ambig_code2 == 0: + ambig_code2 = None + if len(self.atomSelectionSet[2]) > 1: + ambig_code3 = self.csStat.getMaxAmbigCodeWoSetId(atom3['comp_id'], atom3['atom_id']) + if ambig_code3 == 0: + ambig_code3 = None + if len(self.atomSelectionSet[3]) > 1: + ambig_code4 = self.csStat.getMaxAmbigCodeWoSetId(atom4['comp_id'], atom4['atom_id']) + if ambig_code4 == 0: + ambig_code4 = None + else: + atom1 = atom2 = atom3 = atom4 = None + + row = getPkRow(self.cur_subtype, sf['id'], sf['index_id'], + sf['list_id'], self.entryId, dstFunc, + self.authToStarSeq, self.authToOrigSeq, self.offsetHolder, + atom1, atom2, atom3, atom4, asis1=asis1, asis2=asis2, asis3=asis3, asis4=asis4, + ambig_code1=ambig_code1, ambig_code2=ambig_code2, + ambig_code3=ambig_code3, ambig_code4=ambig_code4, details=ass) + sf['loop'].add_data(row) + + finally: + self.numberSelection.clear() + self.originalNumberSelection.clear() # Enter a parse tree produced by SparkyPKParser#peak_wo_assign. - def enterPeak_wo_assign(self, ctx:SparkyPKParser.Peak_wo_assignContext): - pass + def enterPeak_wo_assign(self, ctx: SparkyPKParser.Peak_wo_assignContext): # pylint: disable=unused-argument + if self.num_of_dim == 2: + self.peaks2D += 1 + elif self.num_of_dim == 3: + self.peaks3D += 1 + elif self.num_of_dim == 4: + self.peaks4D += 1 + + self.atomSelectionSet.clear() # Exit a parse tree produced by SparkyPKParser#peak_wo_assign. - def exitPeak_wo_assign(self, ctx:SparkyPKParser.Peak_wo_assignContext): - pass + def exitPeak_wo_assign(self, ctx: SparkyPKParser.Peak_wo_assignContext): # pylint: disable=unused-argument + + try: + + if len(self.numberSelection) == 0: + if self.num_of_dim == 2: + self.peaks2D -= 1 + elif self.num_of_dim == 3: + self.peaks3D -= 1 + elif self.num_of_dim == 4: + self.peaks4D -= 1 + return + + if self.num_of_dim == 2: + + try: + index = self.peaks2D + x_ppm = self.numberSelection[0] + y_ppm = self.numberSelection[1] + height = self.originalNumberSelection[2] + if self.__has_volume: + volume = self.originalNumberSelection[3] + + if not self.hasPolySeq and not self.hasNonPolySeq: + return + + if x_ppm is None or y_ppm is None: + self.peaks2D -= 1 + return + + dstFunc = self.validatePeak2D(index, x_ppm, y_ppm, None, None, None, None, + None, None, None, None, height, None, volume if self.__has_volume else None, None) + + if dstFunc is None: + self.peaks2D -= 1 + return + + cur_spectral_dim = self.spectral_dim[self.num_of_dim][self.cur_list_id] + + cur_spectral_dim[1]['freq_hint'].append(x_ppm) + cur_spectral_dim[2]['freq_hint'].append(y_ppm) + + if self.createSfDict__: + sf = self.getSf() + + if self.debug: + print(f"subtype={self.cur_subtype} id={self.peaks2D} (index={index}) {dstFunc}") + + if self.createSfDict__ and sf is not None: + sf['index_id'] += 1 + + row = getPkRow(self.cur_subtype, sf['id'], sf['index_id'], + sf['list_id'], self.entryId, dstFunc, + self.authToStarSeq, self.authToOrigSeq, self.offsetHolder) + sf['loop'].add_data(row) + + except IndexError: + self.peaks2D -= 1 + return + + elif self.num_of_dim == 3: + + try: + + index = self.peaks3D + x_ppm = self.numberSelection[0] + y_ppm = self.numberSelection[1] + z_ppm = self.numberSelection[2] + height = self.originalNumberSelection[3] + if self.__has_volume: + volume = self.originalNumberSelection[4] + + if not self.hasPolySeq and not self.hasNonPolySeq: + return + + if x_ppm is None or y_ppm is None or z_ppm is None: + self.peaks3D -= 1 + return + + dstFunc = self.validatePeak3D(index, x_ppm, y_ppm, z_ppm, None, None, None, None, None, None, + None, None, None, None, None, None, height, None, volume if self.__has_volume else None, None) + + if dstFunc is None: + self.peaks3D -= 1 + return + + cur_spectral_dim = self.spectral_dim[self.num_of_dim][self.cur_list_id] + + cur_spectral_dim[1]['freq_hint'].append(x_ppm) + cur_spectral_dim[2]['freq_hint'].append(y_ppm) + cur_spectral_dim[3]['freq_hint'].append(z_ppm) + + if self.createSfDict__: + sf = self.getSf() + + if self.debug: + print(f"subtype={self.cur_subtype} id={self.peaks3D} (index={index}) {dstFunc}") + + if self.createSfDict__ and sf is not None: + sf['index_id'] += 1 + + row = getPkRow(self.cur_subtype, sf['id'], sf['index_id'], + sf['list_id'], self.entryId, dstFunc, + self.authToStarSeq, self.authToOrigSeq, self.offsetHolder) + sf['loop'].add_data(row) + + except IndexError: + self.peaks3D -= 1 + return + + elif self.num_of_dim == 4: + + try: + + index = self.peaks4D + x_ppm = self.numberSelection[0] + y_ppm = self.numberSelection[1] + z_ppm = self.numberSelection[2] + a_ppm = self.numberSelection[3] + height = self.originalNumberSelection[4] + if self.__has_volume: + volume = self.originalNumberSelection[5] + + if not self.hasPolySeq and not self.hasNonPolySeq: + return + + if x_ppm is None or y_ppm is None or z_ppm is None or a_ppm is None: + self.peaks4D -= 1 + return + + dstFunc = self.validatePeak4D(index, x_ppm, y_ppm, z_ppm, a_ppm, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, height, None, volume if self.__has_volume else None, None) + + if dstFunc is None: + self.peaks4D -= 1 + return + + cur_spectral_dim = self.spectral_dim[self.num_of_dim][self.cur_list_id] + + cur_spectral_dim[1]['freq_hint'].append(x_ppm) + cur_spectral_dim[2]['freq_hint'].append(y_ppm) + cur_spectral_dim[3]['freq_hint'].append(z_ppm) + cur_spectral_dim[4]['freq_hint'].append(a_ppm) + + if self.createSfDict__: + sf = self.getSf() + + if self.debug: + print(f"subtype={self.cur_subtype} id={self.peaks4D} (index={index}) {dstFunc}") + + if self.createSfDict__ and sf is not None: + sf['index_id'] += 1 + + row = getPkRow(self.cur_subtype, sf['id'], sf['index_id'], + sf['list_id'], self.entryId, dstFunc, + self.authToStarSeq, self.authToOrigSeq, self.offsetHolder) + sf['loop'].add_data(row) + + except IndexError: + self.peaks4D -= 1 + return + + finally: + self.numberSelection.clear() + self.originalNumberSelection.clear() # Enter a parse tree produced by SparkyPKParser#number. - def enterNumber(self, ctx:SparkyPKParser.NumberContext): - pass + def enterNumber(self, ctx: SparkyPKParser.NumberContext): + if ctx.Float(): + value = str(ctx.Float()) + self.numberSelection.append(float(value)) + self.originalNumberSelection.append(value) + + elif ctx.Real(): + value = str(ctx.Real()) + self.numberSelection.append(float(value)) + self.originalNumberSelection.append(value) + + else: + value = str(ctx.Integer()) + self.numberSelection.append(int(value)) + self.originalNumberSelection.append(value) # Exit a parse tree produced by SparkyPKParser#number. - def exitNumber(self, ctx:SparkyPKParser.NumberContext): + def exitNumber(self, ctx: SparkyPKParser.NumberContext): # pylint: disable=unused-argument pass + def fillCurrentSpectralDim(self): + self.cur_subtype = f'peak{self.num_of_dim}d' + if self.num_of_dim not in self.listIdInternal: + self.listIdInternal[self.num_of_dim] = 0 + self.listIdInternal[self.num_of_dim] += 1 + self.cur_list_id = self.listIdInternal[self.num_of_dim] + if self.num_of_dim not in self.spectral_dim: + self.spectral_dim[self.num_of_dim] = {} + if self.cur_list_id not in self.spectral_dim[self.num_of_dim]: + self.spectral_dim[self.num_of_dim][self.cur_list_id] = {} + for _dim_id in range(1, self.num_of_dim + 1): + self.spectral_dim[self.num_of_dim][self.cur_list_id][_dim_id] =\ + copy.copy(SPECTRAL_DIM_TEMPLATE + 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'] = [] + if self.num_of_dim == 2: + self.peaks2D = 0 + if self.num_of_dim == 3: + self.peaks3D = 0 + if self.num_of_dim == 4: + self.peaks4D = 0 -del SparkyPKParser \ No newline at end of file +# del SparkyPKParser diff --git a/wwpdb/utils/nmr/pk/SparkyPKReader.py b/wwpdb/utils/nmr/pk/SparkyPKReader.py new file mode 100644 index 00000000..85af99de --- /dev/null +++ b/wwpdb/utils/nmr/pk/SparkyPKReader.py @@ -0,0 +1,216 @@ +## +# SparkyPKReader.py +# +# Update: +## +""" A collection of classes for parsing SPARKY PK files. +""" +import sys +import os + +from antlr4 import InputStream, CommonTokenStream, ParseTreeWalker + +try: + from wwpdb.utils.nmr.mr.LexerErrorListener import LexerErrorListener + from wwpdb.utils.nmr.mr.ParserErrorListener import ParserErrorListener + from wwpdb.utils.nmr.pk.SparkyPKLexer import SparkyPKLexer + from wwpdb.utils.nmr.pk.SparkyPKParser import SparkyPKParser + from wwpdb.utils.nmr.pk.SparkyPKParserListener import SparkyPKParserListener + from wwpdb.utils.nmr.mr.ParserListenerUtil import (coordAssemblyChecker, + MAX_ERROR_REPORT, + REPRESENTATIVE_MODEL_ID, + REPRESENTATIVE_ALT_ID) + from wwpdb.utils.nmr.io.CifReader import CifReader + from wwpdb.utils.nmr.ChemCompUtil import ChemCompUtil + from wwpdb.utils.nmr.BMRBChemShiftStat import BMRBChemShiftStat + from wwpdb.utils.nmr.NEFTranslator.NEFTranslator import NEFTranslator +except ImportError: + from nmr.mr.LexerErrorListener import LexerErrorListener + from nmr.mr.ParserErrorListener import ParserErrorListener + from nmr.pk.SparkyPKLexer import SparkyPKLexer + from nmr.pk.SparkyPKParser import SparkyPKParser + from nmr.pk.SparkyPKParserListener import SparkyPKParserListener + from nmr.mr.ParserListenerUtil import (coordAssemblyChecker, + MAX_ERROR_REPORT, + REPRESENTATIVE_MODEL_ID, + REPRESENTATIVE_ALT_ID) + from nmr.io.CifReader import CifReader + from nmr.ChemCompUtil import ChemCompUtil + from nmr.BMRBChemShiftStat import BMRBChemShiftStat + from nmr.NEFTranslator.NEFTranslator import NEFTranslator + + +class SparkyPKReader: + """ Accessor methods for parsing SPARKY PK files. + """ + + def __init__(self, verbose=True, log=sys.stdout, + representativeModelId=REPRESENTATIVE_MODEL_ID, + representativeAltId=REPRESENTATIVE_ALT_ID, + mrAtomNameMapping=None, + cR=None, caC=None, ccU=None, csStat=None, nefT=None, + reasons=None): + self.__verbose = verbose + self.__lfh = log + self.__debug = False + + self.__maxLexerErrorReport = MAX_ERROR_REPORT + self.__maxParserErrorReport = MAX_ERROR_REPORT + + self.__representativeModelId = representativeModelId + self.__representativeAltId = representativeAltId + self.__mrAtomNameMapping = mrAtomNameMapping + + # CCD accessing utility + self.__ccU = ChemCompUtil(verbose, log) if ccU is None else ccU + + if cR is not None and caC is None: + caC = coordAssemblyChecker(verbose, log, representativeModelId, representativeAltId, + cR, self.__ccU, None, None, fullCheck=False) + + self.__cR = cR + self.__caC = caC + + # BMRB chemical shift statistics + self.__csStat = BMRBChemShiftStat(verbose, log, self.__ccU) if csStat is None else csStat + + # NEFTranslator + self.__nefT = NEFTranslator(verbose, log, self.__ccU, self.__csStat) if nefT is None else nefT + if nefT is None: + self.__nefT.set_remediation_mode(True) + + # reasons for re-parsing request from the previous trial + self.__reasons = reasons + + def setDebugMode(self, debug): + self.__debug = debug + + def setLexerMaxErrorReport(self, maxErrReport): + self.__maxLexerErrorReport = maxErrReport + + def setParserMaxErrorReport(self, maxErrReport): + self.__maxParserErrorReport = maxErrReport + + def parse(self, pkFilePath, cifFilePath=None, isFilePath=True, + createSfDict=False, originalFileName=None, listIdCounter=None, entryId=None): + """ Parse SPARKY PK file. + @return: SparkyPKParserListener for success or None otherwise, ParserErrorListener, LexerErrorListener. + """ + + ifh = None + + try: + + if isFilePath: + pkString = None + + if not os.access(pkFilePath, os.R_OK): + if self.__verbose: + self.__lfh.write(f"SparkyPKReader.parse() {pkFilePath} is not accessible.\n") + return None, None, None + + ifh = open(pkFilePath, 'r') # pylint: disable=consider-using-with + input = InputStream(ifh.read()) + + else: + pkFilePath, pkString = None, pkFilePath + + if pkString is None or len(pkString) == 0: + if self.__verbose: + self.__lfh.write("SparkyPKReader.parse() Empty string.\n") + return None, None, None + + input = InputStream(pkString) + + if cifFilePath is not None: + if not os.access(cifFilePath, os.R_OK): + if self.__verbose: + self.__lfh.write(f"SparkyPKReader.parse() {cifFilePath} is not accessible.\n") + return None, None, None + + if self.__cR is None: + self.__cR = CifReader(self.__verbose, self.__lfh) + if not self.__cR.parse(cifFilePath): + return None, None, None + + lexer = SparkyPKLexer(input) + lexer.removeErrorListeners() + + lexer_error_listener = LexerErrorListener(pkFilePath, maxErrorReport=self.__maxLexerErrorReport) + lexer.addErrorListener(lexer_error_listener) + + messageList = lexer_error_listener.getMessageList() + + if messageList is not None and self.__verbose: + for description in messageList: + self.__lfh.write(f"[Syntax error] line {description['line_number']}:{description['column_position']} {description['message']}\n") + if 'input' in description: + self.__lfh.write(f"{description['input']}\n") + self.__lfh.write(f"{description['marker']}\n") + + stream = CommonTokenStream(lexer) + parser = SparkyPKParser(stream) + # try with simpler/faster SLL prediction mode + # parser._interp.predictionMode = PredictionMode.SLL # pylint: disable=protected-access + parser.removeErrorListeners() + parser_error_listener = ParserErrorListener(pkFilePath, maxErrorReport=self.__maxParserErrorReport) + parser.addErrorListener(parser_error_listener) + tree = parser.sparky_pk() + + walker = ParseTreeWalker() + listener = SparkyPKParserListener(self.__verbose, self.__lfh, + self.__representativeModelId, + self.__representativeAltId, + self.__mrAtomNameMapping, + self.__cR, self.__caC, + self.__ccU, self.__csStat, self.__nefT, + self.__reasons) + listener.setDebugMode(self.__debug) + listener.createSfDict(createSfDict) + if createSfDict: + if originalFileName is not None: + listener.setOriginaFileName(originalFileName) + if listIdCounter is not None: + listener.setListIdCounter(listIdCounter) + if entryId is not None: + listener.setEntryId(entryId) + walker.walk(listener, tree) + + messageList = parser_error_listener.getMessageList() + + if messageList is not None and self.__verbose: + for description in messageList: + self.__lfh.write(f"[Syntax error] line {description['line_number']}:{description['column_position']} {description['message']}\n") + if 'input' in description: + self.__lfh.write(f"{description['input']}\n") + self.__lfh.write(f"{description['marker']}\n") + + if self.__verbose: + if listener.warningMessage is not None and len(listener.warningMessage) > 0: + print('\n'.join(listener.warningMessage)) + if isFilePath: + print(listener.getContentSubtype()) + + return listener, parser_error_listener, lexer_error_listener + + except IOError as e: + if self.__verbose: + self.__lfh.write(f"+SparkyPKReader.parse() ++ Error - {str(e)}\n") + return None, None, None + # pylint: disable=unreachable + """ debug code + except Exception as e: + if self.__verbose and isFilePath: + self.__lfh.write(f"+SparkyPKReader.parse() ++ Error - {pkFilePath!r} - {str(e)}\n") + return None, None, None + """ + finally: + if isFilePath and ifh is not None: + ifh.close() + + +if __name__ == "__main__": + reader = SparkyPKReader(True) + reader.setDebugMode(True) + reader.parse('../../tests-nmr/mock-data-remediation/2js7/2js7-trimmed-div_ext.mr', + '../../tests-nmr/mock-data-remediation/2js7/2js7.cif') diff --git a/wwpdb/utils/nmr/pk/XeasyPKLexer.py b/wwpdb/utils/nmr/pk/XeasyPKLexer.py index e14950aa..acad04a1 100644 --- a/wwpdb/utils/nmr/pk/XeasyPKLexer.py +++ b/wwpdb/utils/nmr/pk/XeasyPKLexer.py @@ -56,148 +56,148 @@ def serializedATN(): 9,2,11,3,13,4,15,5,17,6,19,7,21,8,23,9,25,0,27,0,29,0,31,10,33,11, 35,12,37,0,39,0,41,0,43,0,45,0,47,13,49,14,51,15,53,16,55,17,57, 18,59,19,61,20,63,21,65,22,67,23,69,24,71,25,73,26,75,27,77,28,79, - 29,81,30,83,31,85,32,87,33,89,34,91,35,93,36,7,0,1,2,3,4,5,6,11, + 29,81,30,83,31,85,32,87,33,89,34,91,35,93,36,7,0,1,2,3,4,5,6,10, 2,0,9,10,13,13,2,0,43,43,45,45,2,0,69,69,101,101,1,0,48,57,2,0,10, 10,13,13,2,0,65,90,97,122,5,0,35,35,42,43,45,46,63,63,95,95,2,0, - 34,34,39,39,3,0,9,10,13,13,32,32,4,0,33,33,38,38,59,59,92,92,2,0, - 9,9,32,32,541,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0, - 0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0, - 0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,47,1,0,0,0,0,49,1,0,0,0, - 0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,1,57,1,0,0,0,1,59,1,0,0,0, - 1,61,1,0,0,0,2,63,1,0,0,0,2,65,1,0,0,0,2,67,1,0,0,0,3,69,1,0,0,0, - 3,71,1,0,0,0,3,73,1,0,0,0,3,75,1,0,0,0,4,77,1,0,0,0,4,79,1,0,0,0, - 4,81,1,0,0,0,5,83,1,0,0,0,5,85,1,0,0,0,5,87,1,0,0,0,6,89,1,0,0,0, - 6,91,1,0,0,0,6,93,1,0,0,0,7,95,1,0,0,0,9,125,1,0,0,0,11,135,1,0, - 0,0,13,144,1,0,0,0,15,159,1,0,0,0,17,171,1,0,0,0,19,185,1,0,0,0, - 21,190,1,0,0,0,23,197,1,0,0,0,25,216,1,0,0,0,27,218,1,0,0,0,29,221, - 1,0,0,0,31,226,1,0,0,0,33,251,1,0,0,0,35,275,1,0,0,0,37,277,1,0, - 0,0,39,281,1,0,0,0,41,285,1,0,0,0,43,289,1,0,0,0,45,291,1,0,0,0, - 47,299,1,0,0,0,49,306,1,0,0,0,51,310,1,0,0,0,53,347,1,0,0,0,55,384, - 1,0,0,0,57,397,1,0,0,0,59,402,1,0,0,0,61,409,1,0,0,0,63,415,1,0, - 0,0,65,418,1,0,0,0,67,425,1,0,0,0,69,432,1,0,0,0,71,436,1,0,0,0, - 73,439,1,0,0,0,75,446,1,0,0,0,77,452,1,0,0,0,79,455,1,0,0,0,81,462, - 1,0,0,0,83,468,1,0,0,0,85,471,1,0,0,0,87,478,1,0,0,0,89,484,1,0, - 0,0,91,487,1,0,0,0,93,494,1,0,0,0,95,99,5,35,0,0,96,98,8,0,0,0,97, - 96,1,0,0,0,98,101,1,0,0,0,99,97,1,0,0,0,99,100,1,0,0,0,100,102,1, - 0,0,0,101,99,1,0,0,0,102,103,5,78,0,0,103,104,5,117,0,0,104,105, - 5,109,0,0,105,106,5,98,0,0,106,107,5,101,0,0,107,108,5,114,0,0,108, - 109,5,32,0,0,109,110,5,111,0,0,110,111,5,102,0,0,111,112,5,32,0, - 0,112,113,5,100,0,0,113,114,5,105,0,0,114,115,5,109,0,0,115,116, - 5,101,0,0,116,117,5,110,0,0,117,118,5,115,0,0,118,119,5,105,0,0, - 119,120,5,111,0,0,120,121,5,110,0,0,121,122,5,115,0,0,122,123,1, - 0,0,0,123,124,6,0,0,0,124,8,1,0,0,0,125,126,5,35,0,0,126,127,5,70, - 0,0,127,128,5,79,0,0,128,129,5,82,0,0,129,130,5,77,0,0,130,131,5, - 65,0,0,131,132,5,84,0,0,132,133,1,0,0,0,133,134,6,1,1,0,134,10,1, - 0,0,0,135,136,5,35,0,0,136,137,5,73,0,0,137,138,5,78,0,0,138,139, - 5,65,0,0,139,140,5,77,0,0,140,141,5,69,0,0,141,142,1,0,0,0,142,143, - 6,2,2,0,143,12,1,0,0,0,144,145,5,35,0,0,145,146,5,67,0,0,146,147, - 5,89,0,0,147,148,5,65,0,0,148,149,5,78,0,0,149,150,5,65,0,0,150, - 151,5,70,0,0,151,152,5,79,0,0,152,153,5,82,0,0,153,154,5,77,0,0, - 154,155,5,65,0,0,155,156,5,84,0,0,156,157,1,0,0,0,157,158,6,3,3, - 0,158,14,1,0,0,0,159,160,5,35,0,0,160,161,5,83,0,0,161,162,5,80, - 0,0,162,163,5,69,0,0,163,164,5,67,0,0,164,165,5,84,0,0,165,166,5, - 82,0,0,166,167,5,85,0,0,167,168,5,77,0,0,168,169,1,0,0,0,169,170, - 6,4,4,0,170,16,1,0,0,0,171,172,5,35,0,0,172,173,5,84,0,0,173,174, - 5,79,0,0,174,175,5,76,0,0,175,176,5,69,0,0,176,177,5,82,0,0,177, - 178,5,65,0,0,178,179,5,78,0,0,179,180,5,67,0,0,180,181,5,69,0,0, - 181,182,1,0,0,0,182,183,6,5,5,0,183,18,1,0,0,0,184,186,7,1,0,0,185, - 184,1,0,0,0,185,186,1,0,0,0,186,187,1,0,0,0,187,188,3,29,11,0,188, - 20,1,0,0,0,189,191,7,1,0,0,190,189,1,0,0,0,190,191,1,0,0,0,191,194, - 1,0,0,0,192,195,3,29,11,0,193,195,3,25,9,0,194,192,1,0,0,0,194,193, - 1,0,0,0,195,22,1,0,0,0,196,198,7,1,0,0,197,196,1,0,0,0,197,198,1, - 0,0,0,198,201,1,0,0,0,199,202,3,29,11,0,200,202,3,25,9,0,201,199, - 1,0,0,0,201,200,1,0,0,0,202,208,1,0,0,0,203,205,7,2,0,0,204,206, - 7,1,0,0,205,204,1,0,0,0,205,206,1,0,0,0,206,207,1,0,0,0,207,209, - 3,29,11,0,208,203,1,0,0,0,208,209,1,0,0,0,209,24,1,0,0,0,210,211, - 3,29,11,0,211,212,5,46,0,0,212,213,3,29,11,0,213,217,1,0,0,0,214, - 215,5,46,0,0,215,217,3,29,11,0,216,210,1,0,0,0,216,214,1,0,0,0,217, - 26,1,0,0,0,218,219,7,3,0,0,219,28,1,0,0,0,220,222,3,27,10,0,221, - 220,1,0,0,0,222,223,1,0,0,0,223,221,1,0,0,0,223,224,1,0,0,0,224, - 30,1,0,0,0,225,227,5,33,0,0,226,225,1,0,0,0,227,228,1,0,0,0,228, - 226,1,0,0,0,228,229,1,0,0,0,229,233,1,0,0,0,230,232,8,4,0,0,231, - 230,1,0,0,0,232,235,1,0,0,0,233,231,1,0,0,0,233,234,1,0,0,0,234, - 239,1,0,0,0,235,233,1,0,0,0,236,238,5,33,0,0,237,236,1,0,0,0,238, - 241,1,0,0,0,239,237,1,0,0,0,239,240,1,0,0,0,240,245,1,0,0,0,241, - 239,1,0,0,0,242,244,8,4,0,0,243,242,1,0,0,0,244,247,1,0,0,0,245, - 243,1,0,0,0,245,246,1,0,0,0,246,248,1,0,0,0,247,245,1,0,0,0,248, - 249,6,12,6,0,249,32,1,0,0,0,250,252,5,59,0,0,251,250,1,0,0,0,252, - 253,1,0,0,0,253,251,1,0,0,0,253,254,1,0,0,0,254,258,1,0,0,0,255, - 257,8,4,0,0,256,255,1,0,0,0,257,260,1,0,0,0,258,256,1,0,0,0,258, - 259,1,0,0,0,259,264,1,0,0,0,260,258,1,0,0,0,261,263,5,59,0,0,262, - 261,1,0,0,0,263,266,1,0,0,0,264,262,1,0,0,0,264,265,1,0,0,0,265, - 270,1,0,0,0,266,264,1,0,0,0,267,269,8,4,0,0,268,267,1,0,0,0,269, - 272,1,0,0,0,270,268,1,0,0,0,270,271,1,0,0,0,271,273,1,0,0,0,272, - 270,1,0,0,0,273,274,6,13,6,0,274,34,1,0,0,0,275,276,3,45,19,0,276, - 36,1,0,0,0,277,278,7,5,0,0,278,38,1,0,0,0,279,282,3,37,15,0,280, - 282,3,27,10,0,281,279,1,0,0,0,281,280,1,0,0,0,282,40,1,0,0,0,283, - 286,3,39,16,0,284,286,7,6,0,0,285,283,1,0,0,0,285,284,1,0,0,0,286, - 42,1,0,0,0,287,290,3,41,17,0,288,290,7,7,0,0,289,287,1,0,0,0,289, - 288,1,0,0,0,290,44,1,0,0,0,291,295,3,41,17,0,292,294,3,43,18,0,293, - 292,1,0,0,0,294,297,1,0,0,0,295,293,1,0,0,0,295,296,1,0,0,0,296, - 46,1,0,0,0,297,295,1,0,0,0,298,300,7,8,0,0,299,298,1,0,0,0,300,301, - 1,0,0,0,301,299,1,0,0,0,301,302,1,0,0,0,302,303,1,0,0,0,303,304, - 6,20,7,0,304,48,1,0,0,0,305,307,7,4,0,0,306,305,1,0,0,0,307,308, - 1,0,0,0,308,306,1,0,0,0,308,309,1,0,0,0,309,50,1,0,0,0,310,315,5, - 123,0,0,311,314,3,51,22,0,312,314,9,0,0,0,313,311,1,0,0,0,313,312, - 1,0,0,0,314,317,1,0,0,0,315,316,1,0,0,0,315,313,1,0,0,0,316,318, - 1,0,0,0,317,315,1,0,0,0,318,319,5,125,0,0,319,320,1,0,0,0,320,321, - 6,22,6,0,321,52,1,0,0,0,322,348,7,9,0,0,323,325,5,47,0,0,324,326, - 5,47,0,0,325,324,1,0,0,0,326,327,1,0,0,0,327,325,1,0,0,0,327,328, - 1,0,0,0,328,348,1,0,0,0,329,331,5,42,0,0,330,332,5,42,0,0,331,330, - 1,0,0,0,332,333,1,0,0,0,333,331,1,0,0,0,333,334,1,0,0,0,334,348, - 1,0,0,0,335,337,5,61,0,0,336,338,5,61,0,0,337,336,1,0,0,0,338,339, - 1,0,0,0,339,337,1,0,0,0,339,340,1,0,0,0,340,348,1,0,0,0,341,342, - 5,82,0,0,342,343,5,69,0,0,343,344,5,77,0,0,344,345,5,65,0,0,345, - 346,5,82,0,0,346,348,5,75,0,0,347,322,1,0,0,0,347,323,1,0,0,0,347, - 329,1,0,0,0,347,335,1,0,0,0,347,341,1,0,0,0,348,352,1,0,0,0,349, - 351,5,32,0,0,350,349,1,0,0,0,351,354,1,0,0,0,352,350,1,0,0,0,352, - 353,1,0,0,0,353,355,1,0,0,0,354,352,1,0,0,0,355,356,3,49,21,0,356, - 357,1,0,0,0,357,358,6,23,6,0,358,54,1,0,0,0,359,385,7,9,0,0,360, - 362,5,47,0,0,361,363,5,47,0,0,362,361,1,0,0,0,363,364,1,0,0,0,364, - 362,1,0,0,0,364,365,1,0,0,0,365,385,1,0,0,0,366,368,5,42,0,0,367, - 369,5,42,0,0,368,367,1,0,0,0,369,370,1,0,0,0,370,368,1,0,0,0,370, - 371,1,0,0,0,371,385,1,0,0,0,372,374,5,61,0,0,373,375,5,61,0,0,374, - 373,1,0,0,0,375,376,1,0,0,0,376,374,1,0,0,0,376,377,1,0,0,0,377, - 385,1,0,0,0,378,379,5,82,0,0,379,380,5,69,0,0,380,381,5,77,0,0,381, - 382,5,65,0,0,382,383,5,82,0,0,383,385,5,75,0,0,384,359,1,0,0,0,384, - 360,1,0,0,0,384,366,1,0,0,0,384,372,1,0,0,0,384,378,1,0,0,0,385, - 389,1,0,0,0,386,388,8,4,0,0,387,386,1,0,0,0,388,391,1,0,0,0,389, - 387,1,0,0,0,389,390,1,0,0,0,390,392,1,0,0,0,391,389,1,0,0,0,392, - 393,3,49,21,0,393,394,1,0,0,0,394,395,6,24,6,0,395,56,1,0,0,0,396, - 398,7,1,0,0,397,396,1,0,0,0,397,398,1,0,0,0,398,399,1,0,0,0,399, - 400,3,29,11,0,400,58,1,0,0,0,401,403,7,10,0,0,402,401,1,0,0,0,403, - 404,1,0,0,0,404,402,1,0,0,0,404,405,1,0,0,0,405,406,1,0,0,0,406, - 407,6,26,7,0,407,60,1,0,0,0,408,410,7,4,0,0,409,408,1,0,0,0,410, - 411,1,0,0,0,411,409,1,0,0,0,411,412,1,0,0,0,412,413,1,0,0,0,413, - 414,6,27,8,0,414,62,1,0,0,0,415,416,3,45,19,0,416,64,1,0,0,0,417, - 419,7,10,0,0,418,417,1,0,0,0,419,420,1,0,0,0,420,418,1,0,0,0,420, - 421,1,0,0,0,421,422,1,0,0,0,422,423,6,29,7,0,423,66,1,0,0,0,424, - 426,7,4,0,0,425,424,1,0,0,0,426,427,1,0,0,0,427,425,1,0,0,0,427, - 428,1,0,0,0,428,429,1,0,0,0,429,430,6,30,8,0,430,68,1,0,0,0,431, - 433,7,1,0,0,432,431,1,0,0,0,432,433,1,0,0,0,433,434,1,0,0,0,434, - 435,3,29,11,0,435,70,1,0,0,0,436,437,3,45,19,0,437,72,1,0,0,0,438, - 440,7,10,0,0,439,438,1,0,0,0,440,441,1,0,0,0,441,439,1,0,0,0,441, - 442,1,0,0,0,442,443,1,0,0,0,443,444,6,33,7,0,444,74,1,0,0,0,445, - 447,7,4,0,0,446,445,1,0,0,0,447,448,1,0,0,0,448,446,1,0,0,0,448, - 449,1,0,0,0,449,450,1,0,0,0,450,451,6,34,8,0,451,76,1,0,0,0,452, - 453,3,45,19,0,453,78,1,0,0,0,454,456,7,10,0,0,455,454,1,0,0,0,456, - 457,1,0,0,0,457,455,1,0,0,0,457,458,1,0,0,0,458,459,1,0,0,0,459, - 460,6,36,7,0,460,80,1,0,0,0,461,463,7,4,0,0,462,461,1,0,0,0,463, - 464,1,0,0,0,464,462,1,0,0,0,464,465,1,0,0,0,465,466,1,0,0,0,466, - 467,6,37,8,0,467,82,1,0,0,0,468,469,3,45,19,0,469,84,1,0,0,0,470, - 472,7,10,0,0,471,470,1,0,0,0,472,473,1,0,0,0,473,471,1,0,0,0,473, - 474,1,0,0,0,474,475,1,0,0,0,475,476,6,39,7,0,476,86,1,0,0,0,477, - 479,7,4,0,0,478,477,1,0,0,0,479,480,1,0,0,0,480,478,1,0,0,0,480, - 481,1,0,0,0,481,482,1,0,0,0,482,483,6,40,8,0,483,88,1,0,0,0,484, - 485,3,21,7,0,485,90,1,0,0,0,486,488,7,10,0,0,487,486,1,0,0,0,488, - 489,1,0,0,0,489,487,1,0,0,0,489,490,1,0,0,0,490,491,1,0,0,0,491, - 492,6,42,7,0,492,92,1,0,0,0,493,495,7,4,0,0,494,493,1,0,0,0,495, - 496,1,0,0,0,496,494,1,0,0,0,496,497,1,0,0,0,497,498,1,0,0,0,498, - 499,6,43,8,0,499,94,1,0,0,0,57,0,1,2,3,4,5,6,99,185,190,194,197, - 201,205,208,216,223,228,233,239,245,253,258,264,270,281,285,289, - 295,301,308,313,315,327,333,339,347,352,364,370,376,384,389,397, - 404,411,420,427,432,441,448,457,464,473,480,489,496,9,5,1,0,5,2, - 0,5,3,0,5,4,0,5,5,0,5,6,0,0,1,0,6,0,0,4,0,0 + 34,34,39,39,2,0,9,9,32,32,4,0,33,33,38,38,59,59,92,92,541,0,7,1, + 0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1, + 0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,31,1,0,0,0,0,33,1, + 0,0,0,0,35,1,0,0,0,0,47,1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1, + 0,0,0,0,55,1,0,0,0,1,57,1,0,0,0,1,59,1,0,0,0,1,61,1,0,0,0,2,63,1, + 0,0,0,2,65,1,0,0,0,2,67,1,0,0,0,3,69,1,0,0,0,3,71,1,0,0,0,3,73,1, + 0,0,0,3,75,1,0,0,0,4,77,1,0,0,0,4,79,1,0,0,0,4,81,1,0,0,0,5,83,1, + 0,0,0,5,85,1,0,0,0,5,87,1,0,0,0,6,89,1,0,0,0,6,91,1,0,0,0,6,93,1, + 0,0,0,7,95,1,0,0,0,9,125,1,0,0,0,11,135,1,0,0,0,13,144,1,0,0,0,15, + 159,1,0,0,0,17,171,1,0,0,0,19,185,1,0,0,0,21,190,1,0,0,0,23,197, + 1,0,0,0,25,216,1,0,0,0,27,218,1,0,0,0,29,221,1,0,0,0,31,226,1,0, + 0,0,33,251,1,0,0,0,35,275,1,0,0,0,37,277,1,0,0,0,39,281,1,0,0,0, + 41,285,1,0,0,0,43,289,1,0,0,0,45,291,1,0,0,0,47,299,1,0,0,0,49,306, + 1,0,0,0,51,310,1,0,0,0,53,347,1,0,0,0,55,384,1,0,0,0,57,397,1,0, + 0,0,59,402,1,0,0,0,61,409,1,0,0,0,63,415,1,0,0,0,65,418,1,0,0,0, + 67,425,1,0,0,0,69,432,1,0,0,0,71,436,1,0,0,0,73,439,1,0,0,0,75,446, + 1,0,0,0,77,452,1,0,0,0,79,455,1,0,0,0,81,462,1,0,0,0,83,468,1,0, + 0,0,85,471,1,0,0,0,87,478,1,0,0,0,89,484,1,0,0,0,91,487,1,0,0,0, + 93,494,1,0,0,0,95,99,5,35,0,0,96,98,8,0,0,0,97,96,1,0,0,0,98,101, + 1,0,0,0,99,97,1,0,0,0,99,100,1,0,0,0,100,102,1,0,0,0,101,99,1,0, + 0,0,102,103,5,78,0,0,103,104,5,117,0,0,104,105,5,109,0,0,105,106, + 5,98,0,0,106,107,5,101,0,0,107,108,5,114,0,0,108,109,5,32,0,0,109, + 110,5,111,0,0,110,111,5,102,0,0,111,112,5,32,0,0,112,113,5,100,0, + 0,113,114,5,105,0,0,114,115,5,109,0,0,115,116,5,101,0,0,116,117, + 5,110,0,0,117,118,5,115,0,0,118,119,5,105,0,0,119,120,5,111,0,0, + 120,121,5,110,0,0,121,122,5,115,0,0,122,123,1,0,0,0,123,124,6,0, + 0,0,124,8,1,0,0,0,125,126,5,35,0,0,126,127,5,70,0,0,127,128,5,79, + 0,0,128,129,5,82,0,0,129,130,5,77,0,0,130,131,5,65,0,0,131,132,5, + 84,0,0,132,133,1,0,0,0,133,134,6,1,1,0,134,10,1,0,0,0,135,136,5, + 35,0,0,136,137,5,73,0,0,137,138,5,78,0,0,138,139,5,65,0,0,139,140, + 5,77,0,0,140,141,5,69,0,0,141,142,1,0,0,0,142,143,6,2,2,0,143,12, + 1,0,0,0,144,145,5,35,0,0,145,146,5,67,0,0,146,147,5,89,0,0,147,148, + 5,65,0,0,148,149,5,78,0,0,149,150,5,65,0,0,150,151,5,70,0,0,151, + 152,5,79,0,0,152,153,5,82,0,0,153,154,5,77,0,0,154,155,5,65,0,0, + 155,156,5,84,0,0,156,157,1,0,0,0,157,158,6,3,3,0,158,14,1,0,0,0, + 159,160,5,35,0,0,160,161,5,83,0,0,161,162,5,80,0,0,162,163,5,69, + 0,0,163,164,5,67,0,0,164,165,5,84,0,0,165,166,5,82,0,0,166,167,5, + 85,0,0,167,168,5,77,0,0,168,169,1,0,0,0,169,170,6,4,4,0,170,16,1, + 0,0,0,171,172,5,35,0,0,172,173,5,84,0,0,173,174,5,79,0,0,174,175, + 5,76,0,0,175,176,5,69,0,0,176,177,5,82,0,0,177,178,5,65,0,0,178, + 179,5,78,0,0,179,180,5,67,0,0,180,181,5,69,0,0,181,182,1,0,0,0,182, + 183,6,5,5,0,183,18,1,0,0,0,184,186,7,1,0,0,185,184,1,0,0,0,185,186, + 1,0,0,0,186,187,1,0,0,0,187,188,3,29,11,0,188,20,1,0,0,0,189,191, + 7,1,0,0,190,189,1,0,0,0,190,191,1,0,0,0,191,194,1,0,0,0,192,195, + 3,29,11,0,193,195,3,25,9,0,194,192,1,0,0,0,194,193,1,0,0,0,195,22, + 1,0,0,0,196,198,7,1,0,0,197,196,1,0,0,0,197,198,1,0,0,0,198,201, + 1,0,0,0,199,202,3,29,11,0,200,202,3,25,9,0,201,199,1,0,0,0,201,200, + 1,0,0,0,202,208,1,0,0,0,203,205,7,2,0,0,204,206,7,1,0,0,205,204, + 1,0,0,0,205,206,1,0,0,0,206,207,1,0,0,0,207,209,3,29,11,0,208,203, + 1,0,0,0,208,209,1,0,0,0,209,24,1,0,0,0,210,211,3,29,11,0,211,212, + 5,46,0,0,212,213,3,29,11,0,213,217,1,0,0,0,214,215,5,46,0,0,215, + 217,3,29,11,0,216,210,1,0,0,0,216,214,1,0,0,0,217,26,1,0,0,0,218, + 219,7,3,0,0,219,28,1,0,0,0,220,222,3,27,10,0,221,220,1,0,0,0,222, + 223,1,0,0,0,223,221,1,0,0,0,223,224,1,0,0,0,224,30,1,0,0,0,225,227, + 5,33,0,0,226,225,1,0,0,0,227,228,1,0,0,0,228,226,1,0,0,0,228,229, + 1,0,0,0,229,233,1,0,0,0,230,232,8,4,0,0,231,230,1,0,0,0,232,235, + 1,0,0,0,233,231,1,0,0,0,233,234,1,0,0,0,234,239,1,0,0,0,235,233, + 1,0,0,0,236,238,5,33,0,0,237,236,1,0,0,0,238,241,1,0,0,0,239,237, + 1,0,0,0,239,240,1,0,0,0,240,245,1,0,0,0,241,239,1,0,0,0,242,244, + 8,4,0,0,243,242,1,0,0,0,244,247,1,0,0,0,245,243,1,0,0,0,245,246, + 1,0,0,0,246,248,1,0,0,0,247,245,1,0,0,0,248,249,6,12,6,0,249,32, + 1,0,0,0,250,252,5,59,0,0,251,250,1,0,0,0,252,253,1,0,0,0,253,251, + 1,0,0,0,253,254,1,0,0,0,254,258,1,0,0,0,255,257,8,4,0,0,256,255, + 1,0,0,0,257,260,1,0,0,0,258,256,1,0,0,0,258,259,1,0,0,0,259,264, + 1,0,0,0,260,258,1,0,0,0,261,263,5,59,0,0,262,261,1,0,0,0,263,266, + 1,0,0,0,264,262,1,0,0,0,264,265,1,0,0,0,265,270,1,0,0,0,266,264, + 1,0,0,0,267,269,8,4,0,0,268,267,1,0,0,0,269,272,1,0,0,0,270,268, + 1,0,0,0,270,271,1,0,0,0,271,273,1,0,0,0,272,270,1,0,0,0,273,274, + 6,13,6,0,274,34,1,0,0,0,275,276,3,45,19,0,276,36,1,0,0,0,277,278, + 7,5,0,0,278,38,1,0,0,0,279,282,3,37,15,0,280,282,3,27,10,0,281,279, + 1,0,0,0,281,280,1,0,0,0,282,40,1,0,0,0,283,286,3,39,16,0,284,286, + 7,6,0,0,285,283,1,0,0,0,285,284,1,0,0,0,286,42,1,0,0,0,287,290,3, + 41,17,0,288,290,7,7,0,0,289,287,1,0,0,0,289,288,1,0,0,0,290,44,1, + 0,0,0,291,295,3,41,17,0,292,294,3,43,18,0,293,292,1,0,0,0,294,297, + 1,0,0,0,295,293,1,0,0,0,295,296,1,0,0,0,296,46,1,0,0,0,297,295,1, + 0,0,0,298,300,7,8,0,0,299,298,1,0,0,0,300,301,1,0,0,0,301,299,1, + 0,0,0,301,302,1,0,0,0,302,303,1,0,0,0,303,304,6,20,7,0,304,48,1, + 0,0,0,305,307,7,4,0,0,306,305,1,0,0,0,307,308,1,0,0,0,308,306,1, + 0,0,0,308,309,1,0,0,0,309,50,1,0,0,0,310,315,5,123,0,0,311,314,3, + 51,22,0,312,314,9,0,0,0,313,311,1,0,0,0,313,312,1,0,0,0,314,317, + 1,0,0,0,315,316,1,0,0,0,315,313,1,0,0,0,316,318,1,0,0,0,317,315, + 1,0,0,0,318,319,5,125,0,0,319,320,1,0,0,0,320,321,6,22,6,0,321,52, + 1,0,0,0,322,348,7,9,0,0,323,325,5,47,0,0,324,326,5,47,0,0,325,324, + 1,0,0,0,326,327,1,0,0,0,327,325,1,0,0,0,327,328,1,0,0,0,328,348, + 1,0,0,0,329,331,5,42,0,0,330,332,5,42,0,0,331,330,1,0,0,0,332,333, + 1,0,0,0,333,331,1,0,0,0,333,334,1,0,0,0,334,348,1,0,0,0,335,337, + 5,61,0,0,336,338,5,61,0,0,337,336,1,0,0,0,338,339,1,0,0,0,339,337, + 1,0,0,0,339,340,1,0,0,0,340,348,1,0,0,0,341,342,5,82,0,0,342,343, + 5,69,0,0,343,344,5,77,0,0,344,345,5,65,0,0,345,346,5,82,0,0,346, + 348,5,75,0,0,347,322,1,0,0,0,347,323,1,0,0,0,347,329,1,0,0,0,347, + 335,1,0,0,0,347,341,1,0,0,0,348,352,1,0,0,0,349,351,5,32,0,0,350, + 349,1,0,0,0,351,354,1,0,0,0,352,350,1,0,0,0,352,353,1,0,0,0,353, + 355,1,0,0,0,354,352,1,0,0,0,355,356,3,49,21,0,356,357,1,0,0,0,357, + 358,6,23,6,0,358,54,1,0,0,0,359,385,7,9,0,0,360,362,5,47,0,0,361, + 363,5,47,0,0,362,361,1,0,0,0,363,364,1,0,0,0,364,362,1,0,0,0,364, + 365,1,0,0,0,365,385,1,0,0,0,366,368,5,42,0,0,367,369,5,42,0,0,368, + 367,1,0,0,0,369,370,1,0,0,0,370,368,1,0,0,0,370,371,1,0,0,0,371, + 385,1,0,0,0,372,374,5,61,0,0,373,375,5,61,0,0,374,373,1,0,0,0,375, + 376,1,0,0,0,376,374,1,0,0,0,376,377,1,0,0,0,377,385,1,0,0,0,378, + 379,5,82,0,0,379,380,5,69,0,0,380,381,5,77,0,0,381,382,5,65,0,0, + 382,383,5,82,0,0,383,385,5,75,0,0,384,359,1,0,0,0,384,360,1,0,0, + 0,384,366,1,0,0,0,384,372,1,0,0,0,384,378,1,0,0,0,385,389,1,0,0, + 0,386,388,8,4,0,0,387,386,1,0,0,0,388,391,1,0,0,0,389,387,1,0,0, + 0,389,390,1,0,0,0,390,392,1,0,0,0,391,389,1,0,0,0,392,393,3,49,21, + 0,393,394,1,0,0,0,394,395,6,24,6,0,395,56,1,0,0,0,396,398,7,1,0, + 0,397,396,1,0,0,0,397,398,1,0,0,0,398,399,1,0,0,0,399,400,3,29,11, + 0,400,58,1,0,0,0,401,403,7,8,0,0,402,401,1,0,0,0,403,404,1,0,0,0, + 404,402,1,0,0,0,404,405,1,0,0,0,405,406,1,0,0,0,406,407,6,26,7,0, + 407,60,1,0,0,0,408,410,7,4,0,0,409,408,1,0,0,0,410,411,1,0,0,0,411, + 409,1,0,0,0,411,412,1,0,0,0,412,413,1,0,0,0,413,414,6,27,8,0,414, + 62,1,0,0,0,415,416,3,45,19,0,416,64,1,0,0,0,417,419,7,8,0,0,418, + 417,1,0,0,0,419,420,1,0,0,0,420,418,1,0,0,0,420,421,1,0,0,0,421, + 422,1,0,0,0,422,423,6,29,7,0,423,66,1,0,0,0,424,426,7,4,0,0,425, + 424,1,0,0,0,426,427,1,0,0,0,427,425,1,0,0,0,427,428,1,0,0,0,428, + 429,1,0,0,0,429,430,6,30,8,0,430,68,1,0,0,0,431,433,7,1,0,0,432, + 431,1,0,0,0,432,433,1,0,0,0,433,434,1,0,0,0,434,435,3,29,11,0,435, + 70,1,0,0,0,436,437,3,45,19,0,437,72,1,0,0,0,438,440,7,8,0,0,439, + 438,1,0,0,0,440,441,1,0,0,0,441,439,1,0,0,0,441,442,1,0,0,0,442, + 443,1,0,0,0,443,444,6,33,7,0,444,74,1,0,0,0,445,447,7,4,0,0,446, + 445,1,0,0,0,447,448,1,0,0,0,448,446,1,0,0,0,448,449,1,0,0,0,449, + 450,1,0,0,0,450,451,6,34,8,0,451,76,1,0,0,0,452,453,3,45,19,0,453, + 78,1,0,0,0,454,456,7,8,0,0,455,454,1,0,0,0,456,457,1,0,0,0,457,455, + 1,0,0,0,457,458,1,0,0,0,458,459,1,0,0,0,459,460,6,36,7,0,460,80, + 1,0,0,0,461,463,7,4,0,0,462,461,1,0,0,0,463,464,1,0,0,0,464,462, + 1,0,0,0,464,465,1,0,0,0,465,466,1,0,0,0,466,467,6,37,8,0,467,82, + 1,0,0,0,468,469,3,45,19,0,469,84,1,0,0,0,470,472,7,8,0,0,471,470, + 1,0,0,0,472,473,1,0,0,0,473,471,1,0,0,0,473,474,1,0,0,0,474,475, + 1,0,0,0,475,476,6,39,7,0,476,86,1,0,0,0,477,479,7,4,0,0,478,477, + 1,0,0,0,479,480,1,0,0,0,480,478,1,0,0,0,480,481,1,0,0,0,481,482, + 1,0,0,0,482,483,6,40,8,0,483,88,1,0,0,0,484,485,3,21,7,0,485,90, + 1,0,0,0,486,488,7,8,0,0,487,486,1,0,0,0,488,489,1,0,0,0,489,487, + 1,0,0,0,489,490,1,0,0,0,490,491,1,0,0,0,491,492,6,42,7,0,492,92, + 1,0,0,0,493,495,7,4,0,0,494,493,1,0,0,0,495,496,1,0,0,0,496,494, + 1,0,0,0,496,497,1,0,0,0,497,498,1,0,0,0,498,499,6,43,8,0,499,94, + 1,0,0,0,57,0,1,2,3,4,5,6,99,185,190,194,197,201,205,208,216,223, + 228,233,239,245,253,258,264,270,281,285,289,295,301,308,313,315, + 327,333,339,347,352,364,370,376,384,389,397,404,411,420,427,432, + 441,448,457,464,473,480,489,496,9,5,1,0,5,2,0,5,3,0,5,4,0,5,5,0, + 5,6,0,0,1,0,6,0,0,4,0,0 ] class XeasyPKLexer(Lexer): diff --git a/wwpdb/utils/nmr/pk/XeasyPKParser.py b/wwpdb/utils/nmr/pk/XeasyPKParser.py index 29cf3155..5b8dedf8 100644 --- a/wwpdb/utils/nmr/pk/XeasyPKParser.py +++ b/wwpdb/utils/nmr/pk/XeasyPKParser.py @@ -10,53 +10,64 @@ def serializedATN(): return [ - 4,1,36,146,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 4,1,36,176,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13, 2,14,7,14,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,5,0,40,8,0,10,0,12, 0,43,9,0,1,0,1,0,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,3,1,3,1,3,1,3, 1,3,1,4,1,4,1,4,1,4,1,5,1,5,4,5,66,8,5,11,5,12,5,67,1,5,1,5,1,6, 1,6,4,6,74,8,6,11,6,12,6,75,1,6,1,6,1,7,4,7,81,8,7,11,7,12,7,82, - 1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,9,4,9,98,8,9,11, - 9,12,9,99,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10, - 1,10,1,10,1,10,1,11,4,11,117,8,11,11,11,12,11,118,1,12,1,12,1,12, + 1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8, + 5,8,101,8,8,10,8,12,8,104,9,8,1,9,4,9,107,8,9,11,9,12,9,108,1,10, + 1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10, + 1,10,1,10,1,10,1,10,1,10,5,10,130,8,10,10,10,12,10,133,9,10,1,11, + 4,11,136,8,11,11,11,12,11,137,1,12,1,12,1,12,1,12,1,12,1,12,1,12, 1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12, - 1,13,1,13,1,14,1,14,1,14,3,14,142,8,14,3,14,144,8,14,1,14,0,0,15, - 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,0,1,2,0,7,9,12,12,146,0, - 41,1,0,0,0,2,46,1,0,0,0,4,50,1,0,0,0,6,54,1,0,0,0,8,59,1,0,0,0,10, - 63,1,0,0,0,12,71,1,0,0,0,14,80,1,0,0,0,16,84,1,0,0,0,18,97,1,0,0, - 0,20,101,1,0,0,0,22,116,1,0,0,0,24,120,1,0,0,0,26,136,1,0,0,0,28, - 143,1,0,0,0,30,40,3,2,1,0,31,40,3,4,2,0,32,40,3,6,3,0,33,40,3,8, - 4,0,34,40,3,10,5,0,35,40,3,12,6,0,36,40,3,14,7,0,37,40,3,18,9,0, - 38,40,3,22,11,0,39,30,1,0,0,0,39,31,1,0,0,0,39,32,1,0,0,0,39,33, - 1,0,0,0,39,34,1,0,0,0,39,35,1,0,0,0,39,36,1,0,0,0,39,37,1,0,0,0, - 39,38,1,0,0,0,40,43,1,0,0,0,41,39,1,0,0,0,41,42,1,0,0,0,42,44,1, - 0,0,0,43,41,1,0,0,0,44,45,5,0,0,1,45,1,1,0,0,0,46,47,5,1,0,0,47, - 48,5,18,0,0,48,49,5,20,0,0,49,3,1,0,0,0,50,51,5,2,0,0,51,52,5,21, - 0,0,52,53,5,23,0,0,53,5,1,0,0,0,54,55,5,3,0,0,55,56,5,24,0,0,56, - 57,5,25,0,0,57,58,5,27,0,0,58,7,1,0,0,0,59,60,5,4,0,0,60,61,5,28, - 0,0,61,62,5,30,0,0,62,9,1,0,0,0,63,65,5,5,0,0,64,66,5,31,0,0,65, - 64,1,0,0,0,66,67,1,0,0,0,67,65,1,0,0,0,67,68,1,0,0,0,68,69,1,0,0, - 0,69,70,5,33,0,0,70,11,1,0,0,0,71,73,5,6,0,0,72,74,5,34,0,0,73,72, - 1,0,0,0,74,75,1,0,0,0,75,73,1,0,0,0,75,76,1,0,0,0,76,77,1,0,0,0, - 77,78,5,36,0,0,78,13,1,0,0,0,79,81,3,16,8,0,80,79,1,0,0,0,81,82, - 1,0,0,0,82,80,1,0,0,0,82,83,1,0,0,0,83,15,1,0,0,0,84,85,5,7,0,0, - 85,86,5,8,0,0,86,87,5,8,0,0,87,88,5,7,0,0,88,89,5,12,0,0,89,90,3, - 26,13,0,90,91,3,26,13,0,91,92,5,12,0,0,92,93,5,7,0,0,93,94,3,28, - 14,0,94,95,3,28,14,0,95,17,1,0,0,0,96,98,3,20,10,0,97,96,1,0,0,0, - 98,99,1,0,0,0,99,97,1,0,0,0,99,100,1,0,0,0,100,19,1,0,0,0,101,102, - 5,7,0,0,102,103,5,8,0,0,103,104,5,8,0,0,104,105,5,8,0,0,105,106, - 5,7,0,0,106,107,5,12,0,0,107,108,3,26,13,0,108,109,3,26,13,0,109, - 110,5,12,0,0,110,111,5,7,0,0,111,112,3,28,14,0,112,113,3,28,14,0, - 113,114,3,28,14,0,114,21,1,0,0,0,115,117,3,24,12,0,116,115,1,0,0, - 0,117,118,1,0,0,0,118,116,1,0,0,0,118,119,1,0,0,0,119,23,1,0,0,0, - 120,121,5,7,0,0,121,122,5,8,0,0,122,123,5,8,0,0,123,124,5,8,0,0, - 124,125,5,8,0,0,125,126,5,7,0,0,126,127,5,12,0,0,127,128,3,26,13, - 0,128,129,3,26,13,0,129,130,5,12,0,0,130,131,5,7,0,0,131,132,3,28, - 14,0,132,133,3,28,14,0,133,134,3,28,14,0,134,135,3,28,14,0,135,25, - 1,0,0,0,136,137,7,0,0,0,137,27,1,0,0,0,138,144,5,7,0,0,139,141,5, - 12,0,0,140,142,5,7,0,0,141,140,1,0,0,0,141,142,1,0,0,0,142,144,1, - 0,0,0,143,138,1,0,0,0,143,139,1,0,0,0,144,29,1,0,0,0,9,39,41,67, - 75,82,99,118,141,143 + 1,12,1,12,5,12,162,8,12,10,12,12,12,165,9,12,1,13,1,13,1,14,1,14, + 1,14,3,14,172,8,14,3,14,174,8,14,1,14,0,0,15,0,2,4,6,8,10,12,14, + 16,18,20,22,24,26,28,0,1,2,0,7,9,12,12,179,0,41,1,0,0,0,2,46,1,0, + 0,0,4,50,1,0,0,0,6,54,1,0,0,0,8,59,1,0,0,0,10,63,1,0,0,0,12,71,1, + 0,0,0,14,80,1,0,0,0,16,84,1,0,0,0,18,106,1,0,0,0,20,110,1,0,0,0, + 22,135,1,0,0,0,24,139,1,0,0,0,26,166,1,0,0,0,28,173,1,0,0,0,30,40, + 3,2,1,0,31,40,3,4,2,0,32,40,3,6,3,0,33,40,3,8,4,0,34,40,3,10,5,0, + 35,40,3,12,6,0,36,40,3,14,7,0,37,40,3,18,9,0,38,40,3,22,11,0,39, + 30,1,0,0,0,39,31,1,0,0,0,39,32,1,0,0,0,39,33,1,0,0,0,39,34,1,0,0, + 0,39,35,1,0,0,0,39,36,1,0,0,0,39,37,1,0,0,0,39,38,1,0,0,0,40,43, + 1,0,0,0,41,39,1,0,0,0,41,42,1,0,0,0,42,44,1,0,0,0,43,41,1,0,0,0, + 44,45,5,0,0,1,45,1,1,0,0,0,46,47,5,1,0,0,47,48,5,18,0,0,48,49,5, + 20,0,0,49,3,1,0,0,0,50,51,5,2,0,0,51,52,5,21,0,0,52,53,5,23,0,0, + 53,5,1,0,0,0,54,55,5,3,0,0,55,56,5,24,0,0,56,57,5,25,0,0,57,58,5, + 27,0,0,58,7,1,0,0,0,59,60,5,4,0,0,60,61,5,28,0,0,61,62,5,30,0,0, + 62,9,1,0,0,0,63,65,5,5,0,0,64,66,5,31,0,0,65,64,1,0,0,0,66,67,1, + 0,0,0,67,65,1,0,0,0,67,68,1,0,0,0,68,69,1,0,0,0,69,70,5,33,0,0,70, + 11,1,0,0,0,71,73,5,6,0,0,72,74,5,34,0,0,73,72,1,0,0,0,74,75,1,0, + 0,0,75,73,1,0,0,0,75,76,1,0,0,0,76,77,1,0,0,0,77,78,5,36,0,0,78, + 13,1,0,0,0,79,81,3,16,8,0,80,79,1,0,0,0,81,82,1,0,0,0,82,80,1,0, + 0,0,82,83,1,0,0,0,83,15,1,0,0,0,84,85,5,7,0,0,85,86,5,8,0,0,86,87, + 5,8,0,0,87,88,5,7,0,0,88,89,5,12,0,0,89,90,3,26,13,0,90,91,3,26, + 13,0,91,92,5,12,0,0,92,93,5,7,0,0,93,94,3,28,14,0,94,95,3,28,14, + 0,95,102,5,14,0,0,96,97,3,28,14,0,97,98,3,28,14,0,98,99,5,14,0,0, + 99,101,1,0,0,0,100,96,1,0,0,0,101,104,1,0,0,0,102,100,1,0,0,0,102, + 103,1,0,0,0,103,17,1,0,0,0,104,102,1,0,0,0,105,107,3,20,10,0,106, + 105,1,0,0,0,107,108,1,0,0,0,108,106,1,0,0,0,108,109,1,0,0,0,109, + 19,1,0,0,0,110,111,5,7,0,0,111,112,5,8,0,0,112,113,5,8,0,0,113,114, + 5,8,0,0,114,115,5,7,0,0,115,116,5,12,0,0,116,117,3,26,13,0,117,118, + 3,26,13,0,118,119,5,12,0,0,119,120,5,7,0,0,120,121,3,28,14,0,121, + 122,3,28,14,0,122,123,3,28,14,0,123,131,5,14,0,0,124,125,3,28,14, + 0,125,126,3,28,14,0,126,127,3,28,14,0,127,128,5,14,0,0,128,130,1, + 0,0,0,129,124,1,0,0,0,130,133,1,0,0,0,131,129,1,0,0,0,131,132,1, + 0,0,0,132,21,1,0,0,0,133,131,1,0,0,0,134,136,3,24,12,0,135,134,1, + 0,0,0,136,137,1,0,0,0,137,135,1,0,0,0,137,138,1,0,0,0,138,23,1,0, + 0,0,139,140,5,7,0,0,140,141,5,8,0,0,141,142,5,8,0,0,142,143,5,8, + 0,0,143,144,5,8,0,0,144,145,5,7,0,0,145,146,5,12,0,0,146,147,3,26, + 13,0,147,148,3,26,13,0,148,149,5,12,0,0,149,150,5,7,0,0,150,151, + 3,28,14,0,151,152,3,28,14,0,152,153,3,28,14,0,153,154,3,28,14,0, + 154,163,5,14,0,0,155,156,3,28,14,0,156,157,3,28,14,0,157,158,3,28, + 14,0,158,159,3,28,14,0,159,160,5,14,0,0,160,162,1,0,0,0,161,155, + 1,0,0,0,162,165,1,0,0,0,163,161,1,0,0,0,163,164,1,0,0,0,164,25,1, + 0,0,0,165,163,1,0,0,0,166,167,7,0,0,0,167,27,1,0,0,0,168,174,5,7, + 0,0,169,171,5,12,0,0,170,172,5,7,0,0,171,170,1,0,0,0,171,172,1,0, + 0,0,172,174,1,0,0,0,173,168,1,0,0,0,173,169,1,0,0,0,174,29,1,0,0, + 0,12,39,41,67,75,82,102,108,131,137,163,171,173 ] class XeasyPKParser ( Parser ): @@ -746,6 +757,12 @@ def assign(self, i:int=None): return self.getTypedRuleContext(XeasyPKParser.AssignContext,i) + def RETURN(self, i:int=None): + if i is None: + return self.getTokens(XeasyPKParser.RETURN) + else: + return self.getToken(XeasyPKParser.RETURN, i) + def getRuleIndex(self): return XeasyPKParser.RULE_peak_2d @@ -788,6 +805,23 @@ def peak_2d(self): self.assign() self.state = 94 self.assign() + self.state = 95 + self.match(XeasyPKParser.RETURN) + self.state = 102 + self._errHandler.sync(self) + _alt = self._interp.adaptivePredict(self._input,5,self._ctx) + while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: + if _alt==1: + self.state = 96 + self.assign() + self.state = 97 + self.assign() + self.state = 98 + self.match(XeasyPKParser.RETURN) + self.state = 104 + self._errHandler.sync(self) + _alt = self._interp.adaptivePredict(self._input,5,self._ctx) + except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -831,19 +865,19 @@ def peak_list_3d(self): self.enterRule(localctx, 18, self.RULE_peak_list_3d) try: self.enterOuterAlt(localctx, 1) - self.state = 97 + self.state = 106 self._errHandler.sync(self) _alt = 1 while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: if _alt == 1: - self.state = 96 + self.state = 105 self.peak_3d() else: raise NoViableAltException(self) - self.state = 99 + self.state = 108 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,5,self._ctx) + _alt = self._interp.adaptivePredict(self._input,6,self._ctx) except RecognitionException as re: localctx.exception = re @@ -893,6 +927,12 @@ def assign(self, i:int=None): return self.getTypedRuleContext(XeasyPKParser.AssignContext,i) + def RETURN(self, i:int=None): + if i is None: + return self.getTokens(XeasyPKParser.RETURN) + else: + return self.getToken(XeasyPKParser.RETURN, i) + def getRuleIndex(self): return XeasyPKParser.RULE_peak_3d @@ -913,32 +953,51 @@ def peak_3d(self): self.enterRule(localctx, 20, self.RULE_peak_3d) try: self.enterOuterAlt(localctx, 1) - self.state = 101 + self.state = 110 self.match(XeasyPKParser.Integer) - self.state = 102 + self.state = 111 self.match(XeasyPKParser.Float) - self.state = 103 + self.state = 112 self.match(XeasyPKParser.Float) - self.state = 104 + self.state = 113 self.match(XeasyPKParser.Float) - self.state = 105 + self.state = 114 self.match(XeasyPKParser.Integer) - self.state = 106 + self.state = 115 self.match(XeasyPKParser.Simple_name) - self.state = 107 + self.state = 116 self.number() - self.state = 108 + self.state = 117 self.number() - self.state = 109 + self.state = 118 self.match(XeasyPKParser.Simple_name) - self.state = 110 + self.state = 119 self.match(XeasyPKParser.Integer) - self.state = 111 + self.state = 120 self.assign() - self.state = 112 + self.state = 121 self.assign() - self.state = 113 + self.state = 122 self.assign() + self.state = 123 + self.match(XeasyPKParser.RETURN) + self.state = 131 + self._errHandler.sync(self) + _alt = self._interp.adaptivePredict(self._input,7,self._ctx) + while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: + if _alt==1: + self.state = 124 + self.assign() + self.state = 125 + self.assign() + self.state = 126 + self.assign() + self.state = 127 + self.match(XeasyPKParser.RETURN) + self.state = 133 + self._errHandler.sync(self) + _alt = self._interp.adaptivePredict(self._input,7,self._ctx) + except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -982,19 +1041,19 @@ def peak_list_4d(self): self.enterRule(localctx, 22, self.RULE_peak_list_4d) try: self.enterOuterAlt(localctx, 1) - self.state = 116 + self.state = 135 self._errHandler.sync(self) _alt = 1 while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: if _alt == 1: - self.state = 115 + self.state = 134 self.peak_4d() else: raise NoViableAltException(self) - self.state = 118 + self.state = 137 self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input,6,self._ctx) + _alt = self._interp.adaptivePredict(self._input,8,self._ctx) except RecognitionException as re: localctx.exception = re @@ -1044,6 +1103,12 @@ def assign(self, i:int=None): return self.getTypedRuleContext(XeasyPKParser.AssignContext,i) + def RETURN(self, i:int=None): + if i is None: + return self.getTokens(XeasyPKParser.RETURN) + else: + return self.getToken(XeasyPKParser.RETURN, i) + def getRuleIndex(self): return XeasyPKParser.RULE_peak_4d @@ -1064,36 +1129,57 @@ def peak_4d(self): self.enterRule(localctx, 24, self.RULE_peak_4d) try: self.enterOuterAlt(localctx, 1) - self.state = 120 + self.state = 139 self.match(XeasyPKParser.Integer) - self.state = 121 + self.state = 140 self.match(XeasyPKParser.Float) - self.state = 122 + self.state = 141 self.match(XeasyPKParser.Float) - self.state = 123 + self.state = 142 self.match(XeasyPKParser.Float) - self.state = 124 + self.state = 143 self.match(XeasyPKParser.Float) - self.state = 125 + self.state = 144 self.match(XeasyPKParser.Integer) - self.state = 126 + self.state = 145 self.match(XeasyPKParser.Simple_name) - self.state = 127 + self.state = 146 self.number() - self.state = 128 + self.state = 147 self.number() - self.state = 129 + self.state = 148 self.match(XeasyPKParser.Simple_name) - self.state = 130 + self.state = 149 self.match(XeasyPKParser.Integer) - self.state = 131 + self.state = 150 self.assign() - self.state = 132 + self.state = 151 self.assign() - self.state = 133 + self.state = 152 self.assign() - self.state = 134 + self.state = 153 self.assign() + self.state = 154 + self.match(XeasyPKParser.RETURN) + self.state = 163 + self._errHandler.sync(self) + _alt = self._interp.adaptivePredict(self._input,9,self._ctx) + while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: + if _alt==1: + self.state = 155 + self.assign() + self.state = 156 + self.assign() + self.state = 157 + self.assign() + self.state = 158 + self.assign() + self.state = 159 + self.match(XeasyPKParser.RETURN) + self.state = 165 + self._errHandler.sync(self) + _alt = self._interp.adaptivePredict(self._input,9,self._ctx) + except RecognitionException as re: localctx.exception = re self._errHandler.reportError(self, re) @@ -1143,7 +1229,7 @@ def number(self): self._la = 0 # Token type try: self.enterOuterAlt(localctx, 1) - self.state = 136 + self.state = 166 _la = self._input.LA(1) if not((((_la) & ~0x3f) == 0 and ((1 << _la) & 4992) != 0)): self._errHandler.recoverInline(self) @@ -1191,23 +1277,23 @@ def assign(self): localctx = XeasyPKParser.AssignContext(self, self._ctx, self.state) self.enterRule(localctx, 28, self.RULE_assign) try: - self.state = 143 + self.state = 173 self._errHandler.sync(self) token = self._input.LA(1) if token in [7]: self.enterOuterAlt(localctx, 1) - self.state = 138 + self.state = 168 self.match(XeasyPKParser.Integer) pass elif token in [12]: self.enterOuterAlt(localctx, 2) - self.state = 139 + self.state = 169 self.match(XeasyPKParser.Simple_name) - self.state = 141 + self.state = 171 self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input,7,self._ctx) + la_ = self._interp.adaptivePredict(self._input,10,self._ctx) if la_ == 1: - self.state = 140 + self.state = 170 self.match(XeasyPKParser.Integer) diff --git a/wwpdb/utils/nmr/pk/XeasyPKParserListener.py b/wwpdb/utils/nmr/pk/XeasyPKParserListener.py index 6f644cc7..2eb697ec 100644 --- a/wwpdb/utils/nmr/pk/XeasyPKParserListener.py +++ b/wwpdb/utils/nmr/pk/XeasyPKParserListener.py @@ -9,7 +9,6 @@ import sys import re import copy -import collections import numpy as np from antlr4 import ParseTreeListener @@ -21,19 +20,9 @@ REPRESENTATIVE_MODEL_ID, REPRESENTATIVE_ALT_ID, SPECTRAL_DIM_TEMPLATE, - isCyclicPolymer, extractPeakAssignment, getPkRow) - from wwpdb.utils.nmr.AlignUtil import (emptyValue, - sortPolySeqRst, - syncCompIdOfPolySeqRst, - alignPolymerSequence, - assignPolymerSequence, - trimSequenceAlignment, - splitPolySeqRstForMultimers, - splitPolySeqRstForExactNoes, - splitPolySeqRstForNonPoly, - splitPolySeqRstForBranched) + from wwpdb.utils.nmr.AlignUtil import emptyValue except ImportError: from nmr.pk.XeasyPKParser import XeasyPKParser @@ -42,19 +31,9 @@ REPRESENTATIVE_MODEL_ID, REPRESENTATIVE_ALT_ID, SPECTRAL_DIM_TEMPLATE, - isCyclicPolymer, extractPeakAssignment, getPkRow) - from nmr.AlignUtil import (emptyValue, - sortPolySeqRst, - syncCompIdOfPolySeqRst, - alignPolymerSequence, - assignPolymerSequence, - trimSequenceAlignment, - splitPolySeqRstForMultimers, - splitPolySeqRstForExactNoes, - splitPolySeqRstForNonPoly, - splitPolySeqRstForBranched) + from nmr.AlignUtil import emptyValue # This class defines a complete listener for a parse tree produced by XeasyPKParser. @@ -91,305 +70,15 @@ 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 - try: - - if self.hasPolySeq and self.polySeqRst is not None: - sortPolySeqRst(self.polySeqRst, - None if self.reasons is None else self.reasons.get('non_poly_remap')) - - self.seqAlign, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRst, - resolvedMultimer=self.reasons is not None) - self.chainAssign, message = assignPolymerSequence(self.pA, self.ccU, self.file_type, self.polySeq, self.polySeqRst, self.seqAlign) - - if len(message) > 0: - self.f.extend(message) - - if self.chainAssign is not None: - - if len(self.polySeq) == len(self.polySeqRst): - - chain_mapping = {} - - for ca in self.chainAssign: - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - if ref_chain_id != test_chain_id: - chain_mapping[test_chain_id] = ref_chain_id - - if len(chain_mapping) == len(self.polySeq): - - for ps in self.polySeqRst: - if ps['chain_id'] in chain_mapping: - ps['chain_id'] = chain_mapping[ps['chain_id']] - - self.seqAlign, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRst, - resolvedMultimer=self.reasons is not None) - self.chainAssign, _ = assignPolymerSequence(self.pA, self.ccU, self.file_type, self.polySeq, self.polySeqRst, self.seqAlign) - - trimSequenceAlignment(self.seqAlign, self.chainAssign) - - if self.reasons is None and any(f for f in self.f - if '[Atom not found]' in f or '[Sequence mismatch]' in f): - - seqIdRemap = [] - - cyclicPolymer = {} - - for ca in self.chainAssign: - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - sa = next(sa for sa in self.seqAlign - if sa['ref_chain_id'] == ref_chain_id - and sa['test_chain_id'] == test_chain_id) - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - poly_seq_rst = next(ps for ps in self.polySeqRst - if ps['chain_id'] == test_chain_id) - - seq_id_mapping = {} - offset = None - for ref_seq_id, mid_code, test_seq_id in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id']): - if test_seq_id is None: - continue - if mid_code == '|': - try: - seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id - in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) - if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) - if offset is None: - offset = seq_id_mapping[test_seq_id] - test_seq_id - except StopIteration: - pass - elif mid_code == ' ' and test_seq_id in poly_seq_rst['seq_id']: - idx = poly_seq_rst['seq_id'].index(test_seq_id) - if poly_seq_rst['comp_id'][idx] == '.' and poly_seq_rst['auth_comp_id'][idx] not in emptyValue: - seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id - in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) - if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) - - if offset is not None and all(v - k == offset for k, v in seq_id_mapping.items()): - test_seq_id_list = list(seq_id_mapping.keys()) - min_test_seq_id = min(test_seq_id_list) - max_test_seq_id = max(test_seq_id_list) - for test_seq_id in range(min_test_seq_id + 1, max_test_seq_id): - if test_seq_id not in seq_id_mapping: - seq_id_mapping[test_seq_id] = test_seq_id + offset - - if ref_chain_id not in cyclicPolymer: - cyclicPolymer[ref_chain_id] =\ - isCyclicPolymer(self.cR, self.polySeq, ref_chain_id, - self.representativeModelId, self.representativeAltId, self.modelNumName) - - if cyclicPolymer[ref_chain_id]: - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - - offset = None - for seq_id, comp_id in zip(poly_seq_rst['seq_id'], poly_seq_rst['comp_id']): - if seq_id is not None and seq_id not in seq_id_mapping: - _seq_id = next((_seq_id for _seq_id, _comp_id in zip(poly_seq_model['seq_id'], poly_seq_model['comp_id']) - if _seq_id not in seq_id_mapping.values() and _comp_id == comp_id), None) - if _seq_id is not None: - offset = seq_id - _seq_id - break - - if offset is not None: - for seq_id in poly_seq_rst['seq_id']: - if seq_id is not None and seq_id not in seq_id_mapping: - seq_id_mapping[seq_id] = seq_id - offset - - if any(k for k, v in seq_id_mapping.items() if k != v)\ - and not any(k for k, v in seq_id_mapping.items() - if v in poly_seq_model['seq_id'] - and k == poly_seq_model['auth_seq_id'][poly_seq_model['seq_id'].index(v)]): - seqIdRemap.append({'chain_id': test_chain_id, 'seq_id_dict': seq_id_mapping}) - - if len(seqIdRemap) > 0: - if 'seq_id_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['seq_id_remap'] = seqIdRemap - - if any(ps for ps in self.polySeq if 'identical_chain_id' in ps): - polySeqRst, chainIdMapping = splitPolySeqRstForMultimers(self.pA, self.polySeq, self.polySeqRst, self.chainAssign) - - if polySeqRst is not None and (not self.hasNonPoly or len(self.polySeq) // len(self.nonPoly) in (1, 2)): - self.polySeqRst = polySeqRst - if 'chain_id_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['chain_id_remap'] = chainIdMapping - - if len(self.polySeq) == 1 and len(self.polySeqRst) == 1: - polySeqRst, chainIdMapping, _ =\ - splitPolySeqRstForExactNoes(self.pA, self.polySeq, self.polySeqRst, self.chainAssign) - - if polySeqRst is not None: - self.polySeqRst = polySeqRst - if 'chain_id_clone' not in self.reasonsForReParsing: - self.reasonsForReParsing['chain_id_clone'] = chainIdMapping - - if self.hasNonPoly: - polySeqRst, nonPolyMapping = splitPolySeqRstForNonPoly(self.ccU, self.nonPoly, self.polySeqRst, - self.seqAlign, self.chainAssign) - - if polySeqRst is not None: - self.polySeqRst = polySeqRst - if 'non_poly_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['non_poly_remap'] = nonPolyMapping - - if self.hasBranched: - polySeqRst, branchedMapping = splitPolySeqRstForBranched(self.pA, self.polySeq, self.branched, self.polySeqRst, - self.chainAssign) - - if polySeqRst is not None: - self.polySeqRst = polySeqRst - if 'branched_remap' not in self.reasonsForReParsing: - self.reasonsForReParsing['branched_remap'] = branchedMapping - - if len(self.polySeqRstFailed) > 0: - sortPolySeqRst(self.polySeqRstFailed) - if not any(f for f in self.f if '[Sequence mismatch]' in f): # 2n6y - syncCompIdOfPolySeqRst(self.polySeqRstFailed, self.compIdMap) # 2mx9 - - seqAlignFailed, _ = alignPolymerSequence(self.pA, self.polySeq, self.polySeqRstFailed) - chainAssignFailed, _ = assignPolymerSequence(self.pA, self.ccU, self.file_type, - self.polySeq, self.polySeqRstFailed, seqAlignFailed) - - if chainAssignFailed is not None: - seqIdRemapFailed = [] - - uniq_ps = not any('identical_chain_id' in ps for ps in self.polySeq) - - for ca in chainAssignFailed: - if ca['conflict'] > 0: - continue - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - sa = next((sa for sa in seqAlignFailed - if sa['ref_chain_id'] == ref_chain_id - and sa['test_chain_id'] == test_chain_id), None) - - if sa is None: - continue - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - - seq_id_mapping = {} - for ref_seq_id, mid_code, test_seq_id in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id']): - if test_seq_id is None: - continue - if mid_code == '|': - try: - seq_id_mapping[test_seq_id] = next(auth_seq_id for auth_seq_id, seq_id - in zip(poly_seq_model['auth_seq_id'], poly_seq_model['seq_id']) - if seq_id == ref_seq_id and isinstance(auth_seq_id, int)) - except StopIteration: - if uniq_ps: - seq_id_mapping[test_seq_id] = ref_seq_id - - offset = None - offsets = [v - k for k, v in seq_id_mapping.items()] - if len(offsets) > 0 and ('gap_in_auth_seq' not in poly_seq_model or not poly_seq_model['gap_in_auth_seq']): - offsets = collections.Counter(offsets).most_common() - if len(offsets) > 1: - offset = offsets[0][0] - for k, v in seq_id_mapping.items(): - if v - k != offset: - seq_id_mapping[k] = k + offset - - if uniq_ps and offset is not None and len(seq_id_mapping) > 0\ - and ('gap_in_auth_seq' not in poly_seq_model or not poly_seq_model['gap_in_auth_seq']): - for ref_seq_id, mid_code, test_seq_id, ref_code, test_code in zip(sa['ref_seq_id'], sa['mid_code'], sa['test_seq_id'], - sa['ref_code'], sa['test_code']): - if test_seq_id is None: - continue - if mid_code == '|' and test_seq_id not in seq_id_mapping: - seq_id_mapping[test_seq_id] = test_seq_id + offset - elif ref_code != '.' and test_code == '.': - seq_id_mapping[test_seq_id] = test_seq_id + offset - - if any(k for k, v in seq_id_mapping.items() if k != v)\ - and not any(k for k, v in seq_id_mapping.items() - if v in poly_seq_model['seq_id'] - and k == poly_seq_model['auth_seq_id'][poly_seq_model['seq_id'].index(v)]): - seqIdRemapFailed.append({'chain_id': ref_chain_id, 'seq_id_dict': seq_id_mapping, - 'comp_id_set': list(set(poly_seq_model['comp_id']))}) - - if len(seqIdRemapFailed) > 0: - if 'chain_seq_id_remap' not in self.reasonsForReParsing: - seqIdRemap = self.reasonsForReParsing['seq_id_remap'] if 'seq_id_remap' in self.reasonsForReParsing else [] - if len(seqIdRemap) != len(seqIdRemapFailed)\ - or seqIdRemap[0]['chain_id'] != seqIdRemapFailed[0]['chain_id']\ - or not all(src_seq_id in seqIdRemap[0] for src_seq_id in seqIdRemapFailed[0]): - self.reasonsForReParsing['chain_seq_id_remap'] = seqIdRemapFailed - - else: - for ps in self.polySeqRstFailed: - for ca in self.chainAssign: - ref_chain_id = ca['ref_chain_id'] - test_chain_id = ca['test_chain_id'] - - if test_chain_id != ps['chain_id']: - continue - - sa = next(sa for sa in self.seqAlign - if sa['ref_chain_id'] == ref_chain_id - and sa['test_chain_id'] == test_chain_id) - - if len(sa['test_seq_id']) != len(sa['ref_seq_id']): - continue - - poly_seq_model = next(ps for ps in self.polySeq - if ps['auth_chain_id'] == ref_chain_id) - - seq_id_mapping, comp_id_mapping = {}, {} - - for seq_id, comp_id in zip(ps['seq_id'], ps['comp_id']): - if seq_id in sa['test_seq_id']: - idx = sa['test_seq_id'].index(seq_id) - auth_seq_id = sa['ref_seq_id'][idx] - seq_id_mapping[seq_id] = auth_seq_id - comp_id_mapping[seq_id] = comp_id - if any(k for k, v in seq_id_mapping.items() if k != v)\ - or ('label_seq_scheme' not in self.reasonsForReParsing - and all(v not in poly_seq_model['auth_seq_id'] for v in seq_id_mapping.values())): - seqIdRemapFailed.append({'chain_id': ref_chain_id, 'seq_id_dict': seq_id_mapping, - 'comp_id_dict': comp_id_mapping}) - - if len(seqIdRemapFailed) > 0: - if 'ext_chain_seq_id_remap' not in self.reasonsForReParsing: - seqIdRemap = self.reasonsForReParsing['seq_id_remap'] if 'seq_id_remap' in self.reasonsForReParsing else [] - if len(seqIdRemap) != len(seqIdRemapFailed)\ - or seqIdRemap[0]['chain_id'] != seqIdRemapFailed[0]['chain_id']\ - or not all(src_seq_id in seqIdRemap[0] for src_seq_id in seqIdRemapFailed[0]): - self.reasonsForReParsing['ext_chain_seq_id_remap'] = seqIdRemapFailed - - if 'local_seq_scheme' in self.reasonsForReParsing: - if 'non_poly_remap' in self.reasonsForReParsing or 'branched_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - elif 'seq_id_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - elif 'chain_seq_id_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - elif 'ext_chain_seq_id_remap' in self.reasonsForReParsing: - del self.reasonsForReParsing['local_seq_scheme'] - - if 'local_seq_scheme' in self.reasonsForReParsing and len(self.reasonsForReParsing) == 1: - sortPolySeqRst(self.polySeqRstFailed) - if len(self.polySeqRstFailed) > 0: - self.reasonsForReParsing['extend_seq_scheme'] = self.polySeqRstFailed - del self.reasonsForReParsing['local_seq_scheme'] - - 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(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' @@ -420,59 +109,58 @@ def exitXeasy_pk(self, ctx: XeasyPKParser.Xeasy_pkContext): # pylint: disable=u __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: - 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 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}') + 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 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}') - finally: - self.warningMessage = sorted(list(set(self.f)), key=self.f.index) + self.exit() # Enter a parse tree produced by XeasyPKParser#dimension. def enterDimension(self, ctx: XeasyPKParser.DimensionContext): @@ -611,6 +299,8 @@ def exitPeak_2d(self, ctx: XeasyPKParser.Peak_2dContext): x_ass = self.assignmentSelection[0] y_ass = self.assignmentSelection[1] + if len(self.assignmentSelection) > self.num_of_dim: # ignore multiple assignments for a peak + x_ass = y_ass = None if not self.hasPolySeq and not self.hasNonPolySeq: return @@ -771,6 +461,8 @@ def exitPeak_3d(self, ctx: XeasyPKParser.Peak_3dContext): x_ass = self.assignmentSelection[0] y_ass = self.assignmentSelection[1] z_ass = self.assignmentSelection[2] + if len(self.assignmentSelection) > self.num_of_dim: # ignore multiple assignments for a peak + x_ass = y_ass = z_ass = None if not self.hasPolySeq and not self.hasNonPolySeq: return @@ -949,6 +641,8 @@ def exitPeak_4d(self, ctx: XeasyPKParser.Peak_4dContext): y_ass = self.assignmentSelection[1] z_ass = self.assignmentSelection[2] a_ass = self.assignmentSelection[3] + if len(self.assignmentSelection) > self.num_of_dim: # ignore multiple assignments for a peak + x_ass = y_ass = z_ass = a_ass = None if not self.hasPolySeq and not self.hasNonPolySeq: return diff --git a/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/SparkyPKLexer.g4 b/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/SparkyPKLexer.g4 index 1341df44..135cd773 100644 --- a/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/SparkyPKLexer.g4 +++ b/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/SparkyPKLexer.g4 @@ -30,18 +30,20 @@ SHARP_COMMENT: '#'+ ~[\r\n]* '#'* ~[\r\n]* -> channel(HIDDEN); EXCLM_COMMENT: '!'+ ~[\r\n]* '!'* ~[\r\n]* -> channel(HIDDEN); SMCLN_COMMENT: ';'+ ~[\r\n]* ';'* ~[\r\n]* -> channel(HIDDEN); -Assignment_2d_ex: SIMPLE_NAME '-' SIMPLE_NAME; -Assignment_3d_ex: SIMPLE_NAME '-' SIMPLE_NAME '-' SIMPLE_NAME; -Assignment_4d_ex: SIMPLE_NAME '-' SIMPLE_NAME '-' SIMPLE_NAME '-' SIMPLE_NAME; +fragment ASS_EACH_AXIS: SIMPLE_NAME ([;&/,.] SIMPLE_NAME)*; -Simple_name: SIMPLE_NAME; +Assignment_2d_ex: ASS_EACH_AXIS '-' ASS_EACH_AXIS; +Assignment_3d_ex: ASS_EACH_AXIS '-' ASS_EACH_AXIS '-' ASS_EACH_AXIS; +Assignment_4d_ex: ASS_EACH_AXIS '-' ASS_EACH_AXIS '-' ASS_EACH_AXIS '-' ASS_EACH_AXIS; + +//Simple_name: SIMPLE_NAME; //Residue_number: Integer; //Residue_name: SIMPLE_NAME; //Atom_name: ALPHA_NUM ATM_NAME_CHAR*; fragment ALPHA: [A-Za-z]; fragment ALPHA_NUM: ALPHA | DEC_DIGIT; -fragment START_CHAR: ALPHA_NUM | '_' | '-' | '+' | '.' | '*' | '#' | '?'; +fragment START_CHAR: ALPHA_NUM | '_' | '+' | '*' | '#' | '?'; fragment NAME_CHAR: START_CHAR | '\'' | '"'; //fragment ATM_NAME_CHAR: ALPHA_NUM | '\''; fragment SIMPLE_NAME: START_CHAR NAME_CHAR*; @@ -49,7 +51,7 @@ fragment SIMPLE_NAME: START_CHAR NAME_CHAR*; SPACE: [ \t]+ -> skip; RETURN: [\r\n]+; -ENCLOSE_COMMENT: '{' (Float | SIMPLE_NAME)*? '}'; +ENCLOSE_COMMENT: '{' (ENCLOSE_COMMENT | .)*? '}' -> channel(HIDDEN); SECTION_COMMENT: ('#' | '!' | ';' | '\\' | '&' | '/' '/'+ | '*' '*'+ | '=' '='+ | 'REMARK') ' '* RETURN -> channel(HIDDEN); LINE_COMMENT: ('#' | '!' | ';' | '\\' | '&' | '/' '/'+ | '*' '*'+ | '=' '='+ | 'REMARK') ~[\r\n]* RETURN -> channel(HIDDEN); diff --git a/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/XeasyPKLexer.g4 b/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/XeasyPKLexer.g4 index df9a43fe..85250547 100644 --- a/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/XeasyPKLexer.g4 +++ b/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/XeasyPKLexer.g4 @@ -50,7 +50,7 @@ fragment NAME_CHAR: START_CHAR | '\'' | '"'; //fragment ATM_NAME_CHAR: ALPHA_NUM | '\''; fragment SIMPLE_NAME: START_CHAR NAME_CHAR*; -SPACE: [ \t\r\n]+ -> skip; +SPACE: [ \t]+ -> skip; RETURN: [\r\n]+; ENCLOSE_COMMENT: '{' (ENCLOSE_COMMENT | .)*? '}' -> channel(HIDDEN); diff --git a/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/XeasyPKParser.g4 b/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/XeasyPKParser.g4 index c6ee2f17..5e3600f4 100644 --- a/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/XeasyPKParser.g4 +++ b/wwpdb/utils/tests-nmr/antlr-grammars-v4.10/XeasyPKParser.g4 @@ -59,7 +59,8 @@ peak_2d: Integer Simple_name number number Simple_name Integer - assign assign; + assign assign RETURN + (assign assign RETURN)*; peak_list_3d: peak_3d+; @@ -70,7 +71,8 @@ peak_3d: Integer Simple_name number number Simple_name Integer - assign assign assign; + assign assign assign RETURN + (assign assign assign RETURN)*; peak_list_4d: peak_4d+; @@ -81,7 +83,8 @@ peak_4d: Integer Simple_name number number Simple_name Integer - assign assign assign assign; + assign assign assign assign RETURN + (assign assign assign assign RETURN)*; /* number expression in peak list */ number: Float | Real | Integer | Simple_name;