@@ -7,20 +7,39 @@ node ccd.js components.cif > components.json
7
7
8
8
const { CIF } = require ( 'molstar/lib/commonjs/mol-io/reader/cif' ) ;
9
9
const fs = require ( 'fs' ) ;
10
+ const JSONStream = require ( 'JSONStream' ) ;
10
11
11
- function isValidComponent ( block ) {
12
+ function isLinkingMonomer ( block ) {
12
13
const { chem_comp } = block . categories ;
13
14
const type = chem_comp . getField ( 'type' ) ?. str ( 0 ) . toLowerCase ( ) ?? '' ;
14
15
15
- return type . endsWith ( 'linking' )
16
- && ( type . includes ( 'dna' ) || type . includes ( 'rna' ) || type . includes ( 'peptide' ) ) ;
16
+ return type . endsWith ( 'linking' ) && type . includes ( 'peptide' ) ;
17
+ }
18
+
19
+ function isNotLinkingMonomer ( block ) {
20
+ return ! isLinkingMonomer ( block ) ;
17
21
}
18
22
19
23
function formatComponent ( block ) {
20
24
const { chem_comp, chem_comp_atom, chem_comp_bond } = block . categories ;
21
25
22
26
// Atoms info
23
27
const atoms = [ ] ;
28
+ const bonds = [ ] ;
29
+ let atomCount = chem_comp_atom ?. rowCount ?? 0 ;
30
+ if ( atomCount === 0 ) {
31
+ console . info ( "No atoms found for" , chem_comp . getField ( 'id' ) ?. str ( 0 ) ) ;
32
+ return {
33
+ name : chem_comp . getField ( 'id' ) ?. str ( 0 ) ,
34
+ one_letter_code : chem_comp . getField ( 'one_letter_code' ) ?. str ( 0 ) ,
35
+ full_name : chem_comp . getField ( 'name' ) ?. str ( 0 ) ,
36
+ synonyms : chem_comp . getField ( 'pdbx_synonyms' ) ?. str ( 0 ) ,
37
+ type : chem_comp . getField ( 'type' ) ?. str ( 0 ) ,
38
+ formal_charge : chem_comp . getField ( 'pdbx_formal_charge' ) ?. int ( 0 ) ,
39
+ atoms,
40
+ bonds,
41
+ }
42
+ }
24
43
for ( let i = 0 ; i < chem_comp_atom . rowCount ; i ++ ) {
25
44
atoms . push ( {
26
45
name : chem_comp_atom . getField ( 'atom_id' ) . str ( i ) ,
@@ -33,9 +52,8 @@ function formatComponent(block) {
33
52
}
34
53
35
54
// Bonds info
36
- const bonds = [ ] ;
37
55
if ( chem_comp_bond ) {
38
- for ( let i = 0 ; i < chem_comp_bond . rowCount ; i ++ ) {
56
+ for ( let i = 0 ; i < chem_comp_bond ? .rowCount ?? 0 ; i ++ ) {
39
57
let bond = {
40
58
name_a : chem_comp_bond . getField ( 'atom_id_1' ) . str ( i ) ,
41
59
name_b : chem_comp_bond . getField ( 'atom_id_2' ) . str ( i ) ,
@@ -51,6 +69,7 @@ function formatComponent(block) {
51
69
name : chem_comp . getField ( 'id' ) ?. str ( 0 ) ,
52
70
one_letter_code : chem_comp . getField ( 'one_letter_code' ) ?. str ( 0 ) ,
53
71
full_name : chem_comp . getField ( 'name' ) ?. str ( 0 ) ,
72
+ synonyms : chem_comp . getField ( 'pdbx_synonyms' ) ?. str ( 0 ) ,
54
73
type : chem_comp . getField ( 'type' ) ?. str ( 0 ) ,
55
74
formal_charge : chem_comp . getField ( 'pdbx_formal_charge' ) ?. int ( 0 ) ,
56
75
atoms,
@@ -67,10 +86,21 @@ async function run() {
67
86
}
68
87
69
88
const components = parsed . result . blocks
70
- . filter ( isValidComponent )
89
+ . filter ( isLinkingMonomer )
71
90
. map ( formatComponent ) ;
72
91
73
- console . log ( JSON . stringify ( components , null , 2 ) ) ;
92
+ var transformStream = JSONStream . stringify ( ) ;
93
+ var outputStream = fs . createWriteStream ( 'processed-components.json' ) ;
94
+ transformStream . pipe ( outputStream ) ;
95
+ components . forEach ( transformStream . write ) ;
96
+ transformStream . end ( ) ;
97
+
98
+ outputStream . on (
99
+ "finish" ,
100
+ function handleFinish ( ) {
101
+ console . log ( "Done" ) ;
102
+ }
103
+ ) ;
74
104
}
75
105
76
- run ( ) ;
106
+ run ( ) ;
0 commit comments