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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
df27c595
Commit
df27c595
authored
7 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
use schema created from dic to read mmcif data
parent
b90480cb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/reader/cif/schema/utils.ts
+22
-23
22 additions, 23 deletions
src/reader/cif/schema/utils.ts
src/script.ts
+18
-4
18 additions, 4 deletions
src/script.ts
with
40 additions
and
27 deletions
src/reader/cif/schema/utils.ts
+
22
−
23
View file @
df27c595
// import dic from './dic'
import
{
Field
/*
, Category
*/
}
from
'
../schema
'
import
{
Field
,
Block
,
Category
}
from
'
../schema
'
import
*
as
Data
from
'
../data-model
'
const
pooledStr
=
Field
.
pooledStr
()
...
...
@@ -87,28 +87,28 @@ function getField ( category: string, field: string, d: Data.SafeFrame, ctx: Saf
}
}
function
getEnums
(
d
:
Data
.
SafeFrame
,
ctx
:
SafeFrameData
):
string
[]
|
undefined
{
const
value
=
getField
(
'
_item_enumeration
'
,
'
value
'
,
d
,
ctx
)
if
(
value
)
{
const
enums
:
string
[]
=
[]
for
(
let
i
=
0
;
i
<
value
.
rowCount
;
++
i
)
{
enums
.
push
(
value
.
str
(
i
))
// console.log(value.str(i))
}
return
enums
}
else
{
// console.log(`item_enumeration.value not found for '${d.header}'`)
}
}
//
function getEnums (d: Data.SafeFrame, ctx: SafeFrameData): string[]|undefined {
//
const value = getField('_item_enumeration', 'value', d, ctx)
//
if (value) {
//
const enums: string[] = []
//
for (let i = 0; i < value.rowCount; ++i) {
//
enums.push(value.str(i))
//
// console.log(value.str(i))
//
}
//
return enums
//
} else {
//
// console.log(`item_enumeration.value not found for '${d.header}'`)
//
}
//
}
function
getCode
(
d
:
Data
.
SafeFrame
,
ctx
:
SafeFrameData
):
string
|
undefined
{
const
code
=
getField
(
'
_item_type
'
,
'
code
'
,
d
,
ctx
)
if
(
code
)
{
let
c
=
code
.
str
(
0
)
if
(
c
===
'
ucode
'
)
{
const
enums
=
getEnums
(
d
,
ctx
)
if
(
enums
)
c
+=
`:
${
enums
.
join
(
'
|
'
)}
`
}
//
if (c === 'ucode') {
//
const enums = getEnums(d, ctx)
//
if (enums) c += `: ${enums.join('|')}`
//
}
return
c
}
else
{
console
.
log
(
`item_type.code not found for '
${
d
.
header
}
'`
)
...
...
@@ -116,8 +116,7 @@ function getCode (d: Data.SafeFrame, ctx: SafeFrameData): string|undefined {
}
export
function
getSchema
(
dic
:
Data
.
Block
)
{
// todo Block needs to be specialized with safe frames as well
// const schema: { [category: string]: Category.Schema } = {}
const
schema
:
{
[
category
:
string
]:
{
[
k
:
string
]:
string
}
}
=
{}
const
schema
:
Block
.
Schema
=
{}
// { [category: string]: Category.Schema } = {}
const
categories
:
SafeFrameCategories
=
{}
const
links
:
SafeFrameLinks
=
{}
...
...
@@ -143,7 +142,7 @@ export function getSchema (dic: Data.Block) { // todo Block needs to be special
Object
.
keys
(
categories
).
forEach
(
fullName
=>
{
const
d
=
categories
[
fullName
]
const
categoryName
=
d
.
header
.
substring
(
0
,
d
.
header
.
indexOf
(
'
.
'
))
const
categoryName
=
d
.
header
.
substring
(
1
,
d
.
header
.
indexOf
(
'
.
'
))
const
itemName
=
d
.
header
.
substring
(
d
.
header
.
indexOf
(
'
.
'
)
+
1
)
let
fields
if
(
categoryName
in
schema
)
{
...
...
@@ -155,11 +154,11 @@ export function getSchema (dic: Data.Block) { // todo Block needs to be special
const
code
=
getCode
(
d
,
{
categories
,
links
})
if
(
code
)
{
fields
[
itemName
]
=
code
//
getFieldType(code)
fields
[
itemName
]
=
getFieldType
(
code
)
}
else
{
console
.
log
(
`could not determine code for '
${
d
.
header
}
'`
)
}
})
return
schema
return
schema
as
Block
.
Instance
<
any
>
}
This diff is collapsed.
Click to expand it.
src/script.ts
+
18
−
4
View file @
df27c595
...
...
@@ -14,6 +14,7 @@ const readFileAsync = util.promisify(fs.readFile);
import
Gro
from
'
./reader/gro/parser
'
import
CIF
from
'
./reader/cif/index
'
import
{
apply
as
applySchema
}
from
'
./reader/cif/schema
'
import
{
getSchema
}
from
'
./reader/cif/schema/utils
'
const
file
=
'
1crn.gro
'
...
...
@@ -107,11 +108,22 @@ async function runCIF(input: string | Uint8Array) {
console
.
log
(
mmcif
.
atom_site
.
Cartn_x
.
value
(
0
));
console
.
log
(
mmcif
.
entity
.
type
.
toArray
());
console
.
log
(
mmcif
.
pdbx_struct_oper_list
.
matrix
.
value
(
0
));
const
schema
=
await
_dic
()
if
(
schema
)
{
const
mmcif2
=
applySchema
(
schema
,
data
)
// console.log(util.inspect(mmcif2.atom_site, {showHidden: false, depth: 3}))
console
.
log
(
mmcif2
.
atom_site
.
Cartn_x
.
value
(
0
));
console
.
log
(
mmcif2
.
entity
.
type
.
toArray
());
// console.log(mmcif2.pdbx_struct_oper_list.matrix.value(0)); // TODO
}
else
{
console
.
log
(
'
error getting mmcif schema from dic
'
)
}
}
export
async
function
_cif
()
{
let
path
=
`./examples/1cbs_updated.cif`
;
path
=
'
../test/3j3q.cif
'
// lets have a relative path for big test files
//
path = '../test/3j3q.cif' // lets have a relative path for big test files
const
input
=
await
readFileAsync
(
path
,
'
utf8
'
)
console
.
log
(
'
------------------
'
);
console
.
log
(
'
Text CIF:
'
);
...
...
@@ -127,7 +139,7 @@ export async function _cif() {
runCIF
(
input2
);
}
//
_cif();
_cif
();
async
function
runDic
(
input
:
string
|
Uint8Array
)
{
console
.
time
(
'
parseDic
'
);
...
...
@@ -144,6 +156,8 @@ async function runDic(input: string | Uint8Array) {
const
schema
=
getSchema
(
parsed
.
result
.
blocks
[
0
])
console
.
log
(
util
.
inspect
(
schema
,
{
showHidden
:
false
,
depth
:
3
}))
// console.log(util.inspect(Object.keys(schema).length, {showHidden: false, depth: 1}))
return
schema
}
export
async
function
_dic
()
{
...
...
@@ -151,10 +165,10 @@ export async function _dic() {
const
input
=
await
readFileAsync
(
path
,
'
utf8
'
)
console
.
log
(
'
------------------
'
);
console
.
log
(
'
Text DIC:
'
);
runDic
(
input
);
return
runDic
(
input
);
}
_dic
();
//
_dic();
import
Computation
from
'
./utils/computation
'
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