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
f8d085a0
Commit
f8d085a0
authored
5 years ago
by
Sebastian Bittrich
Browse files
Options
Downloads
Patches
Plain Diff
white-/blacklist filtering
parent
d7f7770b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mol-io/writer/_spec/cif.spec.ts
+116
-53
116 additions, 53 deletions
src/mol-io/writer/_spec/cif.spec.ts
with
116 additions
and
53 deletions
src/mol-io/writer/_spec/cif.spec.ts
+
116
−
53
View file @
f8d085a0
...
...
@@ -2,17 +2,20 @@ import * as Data from '../../reader/cif/data-model'
import
{
CifWriter
}
from
'
../cif
'
;
import
decodeMsgPack
from
'
../../common/msgpack/decode
'
import
{
EncodedFile
,
EncodedCategory
}
from
'
../../common/binary-cif
'
;
import
Field
from
'
../../reader/cif/binary/field
'
import
Field
from
'
../../reader/cif/binary/field
'
;
import
*
as
C
from
'
../cif/encoder
'
;
const
cartn_x
=
Data
.
CifField
.
ofNumbers
([
1.001
,
1.002
,
1.003
,
1.004
,
1.005
,
1.006
,
1.007
,
1.008
,
1.009
]);
const
cartn_y
=
Data
.
CifField
.
ofNumbers
([
-
3.0
,
-
2.666
,
-
2.3333
,
-
2.0
,
-
1.666
,
-
1.333
,
-
1.0
,
-
0.666
,
-
0.333
]);
const
cartn_z
=
Data
.
CifField
.
ofNumbers
([
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
].
map
(
i
=>
Math
.
sqrt
(
i
)));
const
label_seq_id
=
Data
.
CifField
.
ofNumbers
([
1
,
2
,
3
,
6
,
11
,
23
,
47
,
106
,
235
]);
const
atom_site
=
Data
.
CifCategory
.
ofFields
(
'
atom_site
'
,
{
'
Cartn_x
'
:
cartn_x
,
'
Cartn_y
'
:
cartn_y
,
'
Cartn_z
'
:
cartn_z
,
'
label_seq_id
'
:
label_seq_id
});
const
field1
=
Data
.
CifField
.
ofNumbers
([
1
,
2
,
3
,
6
,
11
,
23
,
47
,
106
,
235
]);
const
field2
=
Data
.
CifField
.
ofNumbers
([
-
1
,
-
2
,
-
3
,
-
6
,
-
11
,
-
23
,
-
47
,
-
106
,
-
235
]);
const
other_fields
=
Data
.
CifCategory
.
ofFields
(
'
other_fields
'
,
{
'
field1
'
:
field1
,
'
field2
'
:
field2
});
const
encoder
=
CifWriter
.
createEncoder
({
const
encoding_aware_
encoder
=
CifWriter
.
createEncoder
({
binary
:
true
,
encoderName
:
'
mol*
'
,
binaryAutoClassifyEncoding
:
true
,
binaryEncodingPovider
:
CifWriter
.
createEncodingProviderFromJsonConfig
([
{
...
...
@@ -35,6 +38,115 @@ const encoder = CifWriter.createEncoder({
])
});
describe
(
'
encoding-config
'
,
()
=>
{
const
decoded
=
process
(
encoding_aware_encoder
);
const
decoded_atom_site
=
decoded
.
blocks
[
0
].
categories
[
'
atom_site
'
];
const
decoded_cartn_x
=
decoded_atom_site
.
getField
(
'
Cartn_x
'
)
!
;
const
decoded_cartn_y
=
decoded_atom_site
.
getField
(
'
Cartn_y
'
)
!
;
const
decoded_cartn_z
=
decoded_atom_site
.
getField
(
'
Cartn_z
'
)
!
;
const
decoded_label_seq_id
=
decoded_atom_site
.
getField
(
'
label_seq_id
'
)
!
;
const
delta
=
0.001
;
function
assert
(
e
:
ArrayLike
<
number
>
,
a
:
ArrayLike
<
number
>
)
{
expect
(
e
.
length
).
toBe
(
a
.
length
);
for
(
let
i
=
0
;
i
<
e
.
length
;
i
++
)
{
expect
(
Math
.
abs
(
e
[
i
]
-
a
[
i
])).
toBeLessThan
(
delta
);
}
}
function
join
(
field
:
Data
.
CifField
)
{
return
field
.
binaryEncoding
!
.
map
(
e
=>
e
.
kind
).
join
();
}
it
(
'
strategy
'
,
()
=>
{
expect
(
join
(
decoded_cartn_x
)).
toBe
(
'
FixedPoint,Delta,IntegerPacking,ByteArray
'
);
expect
(
join
(
decoded_cartn_y
)).
toBe
(
'
FixedPoint,RunLength,IntegerPacking,ByteArray
'
);
expect
(
join
(
decoded_cartn_z
)).
toBe
(
'
FixedPoint,Delta,IntegerPacking,ByteArray
'
);
expect
(
join
(
decoded_label_seq_id
)).
toBe
(
'
Delta,RunLength,IntegerPacking,ByteArray
'
);
});
it
(
'
precision
'
,
()
=>
{
assert
(
decoded_cartn_x
.
toFloatArray
(),
cartn_x
.
toFloatArray
());
assert
(
decoded_cartn_y
.
toFloatArray
(),
cartn_y
.
toFloatArray
().
map
(
d
=>
Math
.
round
(
d
)));
assert
(
decoded_cartn_z
.
toFloatArray
(),
cartn_z
.
toFloatArray
().
map
(
d
=>
Math
.
round
(
d
*
10
)
/
10
));
assert
(
decoded_label_seq_id
.
toIntArray
(),
label_seq_id
.
toIntArray
());
});
});
const
filter_aware_encoder1
=
CifWriter
.
createEncoder
({
binary
:
true
,
binaryAutoClassifyEncoding
:
true
});
filter_aware_encoder1
.
setFilter
(
C
.
Category
.
whitelistBlacklistFilter
([
'
atom_site
'
],
// allow only category atom_site
[],
// blacklist no categories
[
'
atom_site.Cartn_x
'
,
'
atom_site.Cartn_y
'
],
// for atom_site: allow only Cartn_x and Cartn_y
[]));
// blacklist no fields
const
filter_aware_encoder2
=
CifWriter
.
createEncoder
({
binary
:
true
});
filter_aware_encoder2
.
setFilter
(
C
.
Category
.
whitelistBlacklistFilter
([],
[
'
atom_site
'
],
// ignore atom_site category
[],
[
'
other_fields.field2
'
]));
// exclude field2
describe
(
'
filtering-config
'
,
()
=>
{
const
decoded1
=
process
(
filter_aware_encoder1
);
const
atom_site1
=
decoded1
.
blocks
[
0
].
categories
[
'
atom_site
'
];
const
cartn_x1
=
atom_site1
.
getField
(
'
Cartn_x
'
);
const
cartn_y1
=
atom_site1
.
getField
(
'
Cartn_y
'
);
const
cartn_z1
=
atom_site1
.
getField
(
'
Cartn_z
'
);
const
label_seq_id1
=
atom_site1
.
getField
(
'
label_seq_id
'
);
const
fields1
=
decoded1
.
blocks
[
0
].
categories
[
'
other_fields
'
];
it
(
'
whitelist-filtering
'
,
()
=>
{
expect
(
atom_site1
).
toBeDefined
();
expect
(
cartn_x1
).
toBeDefined
();
expect
(
cartn_y1
).
toBeDefined
();
expect
(
cartn_z1
).
toBeUndefined
();
expect
(
label_seq_id1
).
toBeUndefined
();
expect
(
fields1
).
toBeUndefined
();
});
const
decoded2
=
process
(
filter_aware_encoder2
);
const
atom_site2
=
decoded2
.
blocks
[
0
].
categories
[
'
atom_site
'
];
const
fields2
=
decoded2
.
blocks
[
0
].
categories
[
'
other_fields
'
];
const
field12
=
fields2
.
getField
(
'
field1
'
);
const
field22
=
fields2
.
getField
(
'
field2
'
);
it
(
'
blacklist-filtering
'
,
()
=>
{
expect
(
atom_site2
).
toBeUndefined
();
expect
(
fields2
).
toBeDefined
();
expect
(
field12
).
toBeDefined
();
expect
(
field22
).
toBeUndefined
();
});
});
function
process
(
encoder
:
C
.
Encoder
)
{
encoder
.
startDataBlock
(
'
test
'
);
for
(
const
cat
of
[
atom_site
,
other_fields
])
{
const
fields
:
CifWriter
.
Field
[]
=
[];
for
(
const
f
of
cat
.
fieldNames
)
{
fields
.
push
(
wrap
(
f
,
cat
.
getField
(
f
)
!
))
}
encoder
.
writeCategory
(
getCategoryInstanceProvider
(
cat
,
fields
));
}
const
encoded
=
encoder
.
getData
()
as
Uint8Array
;
const
unpacked
=
decodeMsgPack
(
encoded
)
as
EncodedFile
;
return
Data
.
CifFile
(
unpacked
.
dataBlocks
.
map
(
block
=>
{
const
cats
=
Object
.
create
(
null
);
for
(
const
cat
of
block
.
categories
)
cats
[
cat
.
name
.
substr
(
1
)]
=
Category
(
cat
);
return
Data
.
CifBlock
(
block
.
categories
.
map
(
c
=>
c
.
name
.
substr
(
1
)),
cats
,
block
.
header
);
}));
}
function
getCategoryInstanceProvider
(
cat
:
Data
.
CifCategory
,
fields
:
CifWriter
.
Field
[]):
CifWriter
.
Category
{
return
{
name
:
cat
.
name
,
...
...
@@ -69,53 +181,4 @@ function Category(data: EncodedCategory): Data.CifCategory {
return
cache
[
name
];
}
}
}
describe
(
'
config
'
,
()
=>
{
encoder
.
startDataBlock
(
'
test
'
);
const
fields
:
CifWriter
.
Field
[]
=
[];
for
(
const
f
of
atom_site
.
fieldNames
)
{
fields
.
push
(
wrap
(
f
,
atom_site
.
getField
(
f
)
!
))
}
encoder
.
writeCategory
(
getCategoryInstanceProvider
(
atom_site
,
fields
));
const
encoded
=
encoder
.
getData
()
as
Uint8Array
;
const
unpacked
=
decodeMsgPack
(
encoded
)
as
EncodedFile
;
const
decoded
=
Data
.
CifFile
(
unpacked
.
dataBlocks
.
map
(
block
=>
{
const
cats
=
Object
.
create
(
null
);
for
(
const
cat
of
block
.
categories
)
cats
[
cat
.
name
.
substr
(
1
)]
=
Category
(
cat
);
return
Data
.
CifBlock
(
block
.
categories
.
map
(
c
=>
c
.
name
.
substr
(
1
)),
cats
,
block
.
header
);
}));
const
decoded_atom_site
=
decoded
.
blocks
[
0
].
categories
[
'
atom_site
'
];
const
decoded_cartn_x
=
decoded_atom_site
.
getField
(
'
Cartn_x
'
)
!
;
const
decoded_cartn_y
=
decoded_atom_site
.
getField
(
'
Cartn_y
'
)
!
;
const
decoded_cartn_z
=
decoded_atom_site
.
getField
(
'
Cartn_z
'
)
!
;
const
decoded_label_seq_id
=
decoded_atom_site
.
getField
(
'
label_seq_id
'
)
!
;
const
delta
=
0.001
;
function
assert
(
e
:
ArrayLike
<
number
>
,
a
:
ArrayLike
<
number
>
)
{
expect
(
e
.
length
).
toBe
(
a
.
length
);
for
(
let
i
=
0
;
i
<
e
.
length
;
i
++
)
{
expect
(
Math
.
abs
(
e
[
i
]
-
a
[
i
])).
toBeLessThan
(
delta
);
}
}
function
join
(
field
:
Data
.
CifField
)
{
return
field
.
binaryEncoding
!
.
map
(
e
=>
e
.
kind
).
join
();
}
it
(
'
strategy
'
,
()
=>
{
expect
(
join
(
decoded_cartn_x
)).
toBe
(
'
FixedPoint,Delta,IntegerPacking,ByteArray
'
);
expect
(
join
(
decoded_cartn_y
)).
toBe
(
'
FixedPoint,RunLength,IntegerPacking,ByteArray
'
);
expect
(
join
(
decoded_cartn_z
)).
toBe
(
'
FixedPoint,Delta,IntegerPacking,ByteArray
'
);
expect
(
join
(
decoded_label_seq_id
)).
toBe
(
'
Delta,RunLength,IntegerPacking,ByteArray
'
);
});
it
(
'
precision
'
,
()
=>
{
assert
(
decoded_cartn_x
.
toFloatArray
(),
cartn_x
.
toFloatArray
());
assert
(
decoded_cartn_y
.
toFloatArray
(),
cartn_y
.
toFloatArray
().
map
(
d
=>
Math
.
round
(
d
)));
assert
(
decoded_cartn_z
.
toFloatArray
(),
cartn_z
.
toFloatArray
().
map
(
d
=>
Math
.
round
(
d
*
10
)
/
10
));
assert
(
decoded_label_seq_id
.
toIntArray
(),
label_seq_id
.
toIntArray
());
});
})
\ No newline at end of file
}
\ No newline at end of file
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