Skip to content

Commit

Permalink
Add SPARKY peak reader and parserlistener with code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
yokochi47 committed Dec 5, 2024
1 parent 3eb3572 commit 8e4d8f6
Show file tree
Hide file tree
Showing 14 changed files with 1,978 additions and 1,518 deletions.
21 changes: 14 additions & 7 deletions wwpdb/utils/nmr/mr/ParserListenerUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
317 changes: 317 additions & 0 deletions wwpdb/utils/nmr/pk/BasePKParserListener.py

Large diffs are not rendered by default.

356 changes: 22 additions & 334 deletions wwpdb/utils/nmr/pk/NmrPipePKParserListener.py

Large diffs are not rendered by default.

357 changes: 22 additions & 335 deletions wwpdb/utils/nmr/pk/NmrViewPKParserListener.py

Large diffs are not rendered by default.

306 changes: 154 additions & 152 deletions wwpdb/utils/nmr/pk/SparkyPKLexer.py

Large diffs are not rendered by default.

86 changes: 42 additions & 44 deletions wwpdb/utils/nmr/pk/SparkyPKParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
]

Expand All @@ -67,16 +67,15 @@ class SparkyPKParser ( Parser ):
"<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>",
"<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>",
"<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>",
"<INVALID>", "<INVALID>", "<INVALID>", "'w2'", "'w3'",
"'w4'", "<INVALID>", "'Volume'", "'S/N'" ]
"<INVALID>", "<INVALID>", "'w2'", "'w3'", "'w4'", "<INVALID>",
"'Volume'", "'S/N'" ]

symbolicNames = [ "<INVALID>", "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
Expand All @@ -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)
Expand Down Expand Up @@ -290,15 +288,15 @@ 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)


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)

Expand All @@ -308,15 +306,15 @@ 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)


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)

Expand Down Expand Up @@ -446,15 +444,15 @@ 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)


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)

Expand All @@ -464,15 +462,15 @@ 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)


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)

Expand Down
Loading

0 comments on commit 8e4d8f6

Please sign in to comment.