Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
6d842b96
Commit
6d842b96
authored
7 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
first attempt at cif dictionary parsing
parent
f03e0b67
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/reader/cif/data-model.ts
+14
-2
14 additions, 2 deletions
src/reader/cif/data-model.ts
src/reader/cif/text/parser.ts
+29
-31
29 additions, 31 deletions
src/reader/cif/text/parser.ts
src/script.ts
+35
-5
35 additions, 5 deletions
src/script.ts
with
78 additions
and
38 deletions
src/reader/cif/data-model.ts
+
14
−
2
View file @
6d842b96
...
@@ -17,16 +17,28 @@ export function File(blocks: ArrayLike<Block>, name?: string): File {
...
@@ -17,16 +17,28 @@ export function File(blocks: ArrayLike<Block>, name?: string): File {
export
interface
Block
{
export
interface
Block
{
readonly
header
:
string
,
readonly
header
:
string
,
readonly
categories
:
{
readonly
[
name
:
string
]:
Category
}
readonly
categories
:
Categories
readonly
saveFrames
:
SafeFrame
[]
}
}
export
function
Block
(
categories
:
{
readonly
[
name
:
string
]:
Categor
y
}
,
header
:
string
):
Block
{
export
function
Block
(
categories
:
Categor
ies
,
header
:
string
,
saveFrames
:
SafeFrame
[]
=
[]
):
Block
{
if
(
Object
.
keys
(
categories
).
some
(
k
=>
k
[
0
]
!==
'
_
'
))
{
if
(
Object
.
keys
(
categories
).
some
(
k
=>
k
[
0
]
!==
'
_
'
))
{
throw
new
Error
(
`Category names must start with '_'.`
);
throw
new
Error
(
`Category names must start with '_'.`
);
}
}
return
{
header
,
categories
,
saveFrames
};
}
export
interface
SafeFrame
{
readonly
header
:
string
,
readonly
categories
:
Categories
}
export
function
SafeFrame
(
categories
:
Categories
,
header
:
string
):
SafeFrame
{
return
{
header
,
categories
};
return
{
header
,
categories
};
}
}
export
type
Categories
=
{
readonly
[
name
:
string
]:
Category
}
export
interface
Category
{
export
interface
Category
{
readonly
rowCount
:
number
,
readonly
rowCount
:
number
,
getField
(
name
:
string
):
Field
|
undefined
getField
(
name
:
string
):
Field
|
undefined
...
...
This diff is collapsed.
Click to expand it.
src/reader/cif/text/parser.ts
+
29
−
31
View file @
6d842b96
...
@@ -551,9 +551,12 @@ async function parseInternal(data: string, ctx: Computation.Context) {
...
@@ -551,9 +551,12 @@ async function parseInternal(data: string, ctx: Computation.Context) {
let
blockHeader
:
string
=
''
;
let
blockHeader
:
string
=
''
;
let
blockCategories
=
Object
.
create
(
null
);
let
blockCategories
=
Object
.
create
(
null
);
//saveFrame = new DataBlock(data, "empty"),
let
inSaveFrame
=
false
//inSaveFrame = false,
//blockSaveFrames: any;
// the next three initial values are never used in valid files
let
saveFrames
:
Data
.
SafeFrame
[]
=
[];
let
saveCategories
=
Object
.
create
(
null
);
let
saveFrame
:
Data
.
SafeFrame
=
Data
.
SafeFrame
(
saveCategories
,
''
);
ctx
.
update
({
message
:
'
Parsing...
'
,
current
:
0
,
max
:
data
.
length
});
ctx
.
update
({
message
:
'
Parsing...
'
,
current
:
0
,
max
:
data
.
length
});
...
@@ -563,63 +566,58 @@ async function parseInternal(data: string, ctx: Computation.Context) {
...
@@ -563,63 +566,58 @@ async function parseInternal(data: string, ctx: Computation.Context) {
// Data block
// Data block
if
(
token
===
CifTokenType
.
Data
)
{
if
(
token
===
CifTokenType
.
Data
)
{
//
if (inSaveFrame) {
if
(
inSaveFrame
)
{
//
return error(tokenizer.
currentL
ineNumber, "Unexpected data block inside a save frame.");
return
error
(
tokenizer
.
l
ineNumber
,
"
Unexpected data block inside a save frame.
"
);
//
}
}
if
(
Object
.
keys
(
blockCategories
).
length
>
0
)
{
if
(
Object
.
keys
(
blockCategories
).
length
>
0
)
{
dataBlocks
.
push
(
Data
.
Block
(
blockCategories
,
blockHeader
));
dataBlocks
.
push
(
Data
.
Block
(
blockCategories
,
blockHeader
,
saveFrames
));
}
}
blockHeader
=
data
.
substring
(
tokenizer
.
tokenStart
+
5
,
tokenizer
.
tokenEnd
);
blockHeader
=
data
.
substring
(
tokenizer
.
tokenStart
+
5
,
tokenizer
.
tokenEnd
);
blockCategories
=
Object
.
create
(
null
);
blockCategories
=
Object
.
create
(
null
);
saveFrames
=
[]
moveNext
(
tokenizer
);
moveNext
(
tokenizer
);
}
// Save frame
/* // Save frame
}
else
if
(
token
===
CifTokenType
.
Save
)
{
}
else
if
(
token
===
CifTokenType
.
Save
)
{
id = data.substring(tokenizer.currentTokenStart + 5, tokenizer.currentTokenEnd);
const
saveHeader
=
data
.
substring
(
tokenizer
.
tokenStart
+
5
,
tokenizer
.
tokenEnd
);
if
(
saveHeader
.
length
===
0
)
{
if (id.length === 0) {
if
(
Object
.
keys
(
saveCategories
).
length
>
0
)
{
if (saveFrame.categories.length > 0) {
saveFrames
[
saveFrames
.
length
]
=
saveFrame
blockSaveFrames = blockCategories.additionalData["saveFrames"];
if (!blockSaveFrames) {
blockSaveFrames = [];
blockCategories.additionalData["saveFrames"] = blockSaveFrames;
}
blockSaveFrames[blockSaveFrames.length] = saveFrame;
}
}
inSaveFrame
=
false
;
inSaveFrame
=
false
;
}
else
{
}
else
{
if
(
inSaveFrame
)
{
if
(
inSaveFrame
)
{
return error(tokenizer.
currentL
ineNumber, "Save frames cannot be nested.");
return
error
(
tokenizer
.
l
ineNumber
,
"
Save frames cannot be nested.
"
);
}
}
inSaveFrame
=
true
;
inSaveFrame
=
true
;
saveFrame = new DataBlock(data, id);
saveCategories
=
Object
.
create
(
null
);
saveFrame
=
Data
.
SafeFrame
(
saveCategories
,
saveHeader
);
}
}
moveNext
(
tokenizer
);
moveNext
(
tokenizer
);
// Loop
// Loop
}
*/
else
if
(
token
===
CifTokenType
.
Loop
)
{
}
else
if
(
token
===
CifTokenType
.
Loop
)
{
const
cat
=
await
handleLoop
(
tokenizer
,
/*
inSaveFrame ? save
Frame : */
blockCategories
);
const
cat
=
await
handleLoop
(
tokenizer
,
inSaveFrame
?
save
Categories
:
blockCategories
);
if
(
cat
.
hasError
)
{
if
(
cat
.
hasError
)
{
return
error
(
cat
.
errorLine
,
cat
.
errorMessage
);
return
error
(
cat
.
errorLine
,
cat
.
errorMessage
);
}
}
// Single row
// Single row
}
else
if
(
token
===
CifTokenType
.
ColumnName
)
{
}
else
if
(
token
===
CifTokenType
.
ColumnName
)
{
const
cat
=
handleSingle
(
tokenizer
,
/*
inSaveFrame ? save
Frame :*/
blockCategories
);
const
cat
=
handleSingle
(
tokenizer
,
inSaveFrame
?
save
Categories
:
blockCategories
);
if
(
cat
.
hasError
)
{
if
(
cat
.
hasError
)
{
return
error
(
cat
.
errorLine
,
cat
.
errorMessage
);
return
error
(
cat
.
errorLine
,
cat
.
errorMessage
);
}
}
// Out of options
// Out of options
}
else
{
}
else
{
return
error
(
tokenizer
.
lineNumber
,
'
Unexpected token. Expected data_, loop_, or data name.
'
);
return
error
(
tokenizer
.
lineNumber
,
'
Unexpected token. Expected data_, loop_, or data name.
'
);
}
}
}
}
// Check if the latest save frame was closed.
// Check if the latest save frame was closed.
//
if (inSaveFrame) {
if
(
inSaveFrame
)
{
//
return error(tokenizer.
currentL
ineNumber, "Unfinished save frame (`" + saveFrame.header + "`).");
return
error
(
tokenizer
.
l
ineNumber
,
"
Unfinished save frame (`
"
+
saveFrame
.
header
+
"
`).
"
);
//
}
}
if
(
Object
.
keys
(
blockCategories
).
length
>
0
)
{
if
(
Object
.
keys
(
blockCategories
).
length
>
0
)
{
dataBlocks
.
push
(
Data
.
Block
(
blockCategories
,
blockHeader
));
dataBlocks
.
push
(
Data
.
Block
(
blockCategories
,
blockHeader
,
saveFrames
));
}
}
return
result
(
Data
.
File
(
dataBlocks
));
return
result
(
Data
.
File
(
dataBlocks
));
...
...
This diff is collapsed.
Click to expand it.
src/script.ts
+
35
−
5
View file @
6d842b96
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @author David Sehnal <david.sehnal@gmail.com>
* @author David Sehnal <david.sehnal@gmail.com>
*/
*/
//
import * as util from 'util'
import
*
as
util
from
'
util
'
import
*
as
fs
from
'
fs
'
import
*
as
fs
from
'
fs
'
import
Gro
from
'
./reader/gro/parser
'
import
Gro
from
'
./reader/gro/parser
'
...
@@ -74,7 +74,7 @@ async function runGro(input: string) {
...
@@ -74,7 +74,7 @@ async function runGro(input: string) {
console
.
log
(
residueNumber
.
length
,
residueNumber
[
0
],
residueNumber
[
residueNumber
.
length
-
1
])
console
.
log
(
residueNumber
.
length
,
residueNumber
[
0
],
residueNumber
[
residueNumber
.
length
-
1
])
}
}
function
_gro
()
{
export
function
_gro
()
{
fs
.
readFile
(
`./examples/
${
file
}
`
,
'
utf8
'
,
function
(
err
,
input
)
{
fs
.
readFile
(
`./examples/
${
file
}
`
,
'
utf8
'
,
function
(
err
,
input
)
{
if
(
err
)
{
if
(
err
)
{
return
console
.
log
(
err
);
return
console
.
log
(
err
);
...
@@ -83,7 +83,7 @@ function _gro() {
...
@@ -83,7 +83,7 @@ function _gro() {
});
});
}
}
_gro
()
//
_gro()
async
function
runCIF
(
input
:
string
|
Uint8Array
)
{
async
function
runCIF
(
input
:
string
|
Uint8Array
)
{
console
.
time
(
'
parseCIF
'
);
console
.
time
(
'
parseCIF
'
);
...
@@ -110,7 +110,7 @@ async function runCIF(input: string | Uint8Array) {
...
@@ -110,7 +110,7 @@ async function runCIF(input: string | Uint8Array) {
export
function
_cif
()
{
export
function
_cif
()
{
let
path
=
`./examples/1cbs_updated.cif`
;
let
path
=
`./examples/1cbs_updated.cif`
;
path
=
'
c:
/test/
quick/
3j3q.cif
'
;
path
=
'
..
/test/3j3q.cif
'
// lets have a relative path for big test files
fs
.
readFile
(
path
,
'
utf8
'
,
function
(
err
,
input
)
{
fs
.
readFile
(
path
,
'
utf8
'
,
function
(
err
,
input
)
{
if
(
err
)
{
if
(
err
)
{
return
console
.
log
(
err
);
return
console
.
log
(
err
);
...
@@ -134,7 +134,37 @@ export function _cif() {
...
@@ -134,7 +134,37 @@ export function _cif() {
});
});
}
}
_cif
();
// _cif();
async
function
runDic
(
input
:
string
|
Uint8Array
)
{
console
.
time
(
'
parseDic
'
);
const
comp
=
typeof
input
===
'
string
'
?
CIF
.
parseText
(
input
)
:
CIF
.
parseBinary
(
input
);
const
ctx
=
Computation
.
observable
({
updateRateMs
:
250
,
observer
:
p
=>
showProgress
(
'
DIC
'
,
p
)
});
const
parsed
=
await
comp
(
ctx
);
console
.
timeEnd
(
'
parseDic
'
);
if
(
parsed
.
isError
)
{
console
.
log
(
parsed
);
return
;
}
const
data
=
parsed
.
result
.
blocks
[
0
];
console
.
log
(
util
.
inspect
(
data
.
saveFrames
,
{
showHidden
:
false
,
depth
:
3
}))
}
export
function
_dic
()
{
let
path
=
'
../test/mmcif_pdbx_v50.dic
'
fs
.
readFile
(
path
,
'
utf8
'
,
function
(
err
,
input
)
{
if
(
err
)
{
return
console
.
log
(
err
);
}
console
.
log
(
'
------------------
'
);
console
.
log
(
'
Text DIC:
'
);
runDic
(
input
);
});
}
_dic
();
import
Computation
from
'
./utils/computation
'
import
Computation
from
'
./utils/computation
'
const
comp
=
Computation
.
create
(
async
ctx
=>
{
const
comp
=
Computation
.
create
(
async
ctx
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment