Skip to content

Commit ac922f8

Browse files
committed
matinfio: revert CIF detection and rewrite console warnings into fatal errors
1 parent 30ba0f5 commit ac922f8

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

matinfio/cif/cif.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ namespace $ {
5151
}
5252

5353
for( let i = 0; i < lines.length; i++ ) {
54+
5455
if( lines[ i ].startsWith('#') ) continue
5556
cur_line = lines[ i ].trim()
5657
if( !cur_line ) {
@@ -83,8 +84,8 @@ namespace $ {
8384
}
8485
continue
8586

86-
} else if(
87-
fingerprt.startsWith( '_symmetry_space_group_name_h-m' )
87+
} else if(
88+
fingerprt.startsWith( '_symmetry_space_group_name_h-m' )
8889
|| fingerprt.startsWith( '_space_group.patterson_name_h-m' )
8990
|| fingerprt.startsWith( '_space_group_name_h-m_alt' )
9091
) {
@@ -179,6 +180,8 @@ namespace $ {
179180
}
180181
}
181182

183+
if (!cur_structure.atoms.length) return this.$mol_fail( new $mol_data_error( 'Error: no atomic positions available' ) )
184+
182185
cur_structure.info = data_info
183186
if( symops.length > 1 ) cur_structure.symops = symops
184187
structures.push( cur_structure )

matinfio/matinfio.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace $ {
8888

8989
if( typeof data === 'object' ) return 'OPTIMADE'
9090

91-
if( data.indexOf( "_atom_site" ) > 0 && data.indexOf( "loop_" ) > 0 )
91+
if( data.indexOf( "_cell_angle_gamma " ) > 0 && data.indexOf( "loop_" ) > 0 )
9292
return 'CIF'
9393

9494
else if( data.indexOf( '"immutable_id"' ) > 0 && data.indexOf( '"cartesian_site_positions"' ) > 0 && data.indexOf( '"lattice_vectors"' ) > 0 )

matinfio/optimade/optimade.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ namespace $ {
22

33
export function $optimade_cifplayer_matinfio_optimade_str_to_obj( this: $, str: string ) {
44
const payload = JSON.parse( str )
5-
5+
66
return this.$optimade_cifplayer_matinfio_optimade_to_obj( payload )
77
}
88

99
export function $optimade_cifplayer_matinfio_optimade_to_obj( this: $, payload: Record< string, any > ) {
10+
1011
const atoms: any[] = []
1112
const src = payload?.data?.[ 0 ] ?? payload
1213

13-
if( !src ) {
14-
this.$optimade_cifplayer_matinfio_log.error( "Error: unexpected OPTIMADE format" )
15-
return false
14+
if( !src || !src.attributes ) {
15+
return this.$mol_fail( new $mol_data_error('Error: unexpected OPTIMADE format') )
1616
}
1717

1818
var n_atoms = src.attributes.cartesian_site_positions.length
1919
if( !n_atoms ) {
20-
this.$optimade_cifplayer_matinfio_log.error( "Error: no atomic positions found" )
21-
return false
20+
return this.$mol_fail( new $mol_data_error('Error: no atomic positions found') )
2221
}
2322

2423
if( src.attributes.species && src.attributes.species[ n_atoms - 1 ] && src.attributes.species[ n_atoms - 1 ].chemical_symbols ) {
@@ -41,8 +40,7 @@ namespace $ {
4140
} )
4241
} )
4342
} else {
44-
this.$optimade_cifplayer_matinfio_log.error( "Error: no atomic data found" )
45-
return false
43+
return this.$mol_fail( new $mol_data_error('Error: no atomic data found') )
4644
}
4745

4846
return {
@@ -52,5 +50,5 @@ namespace $ {
5250
'cartesian': true
5351
}
5452
}
55-
53+
5654
}

matinfio/poscar/poscar.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ namespace $ {
8585
break
8686
else if( line_data.length == 3 ) elems.length ? line_data.push( elems[ atidx ] ) : line_data.push( 'Xx' )
8787
else if( line_data.length < 3 ) {
88-
this.$optimade_cifplayer_matinfio_log.error( "Error: unknown atom definition" )
89-
return false
88+
return this.$mol_fail( new $mol_data_error( "Error: unknown atom definition" ) )
9089
}
9190

9291
for( let j = 0; j < 4; j++ ) {
@@ -95,8 +94,7 @@ namespace $ {
9594
}
9695
//console.log(atom);
9796
if( !atom.symbol ) {
98-
this.$optimade_cifplayer_matinfio_log.error( "Error: unknown data lines order" )
99-
return false
97+
return this.$mol_fail( new $mol_data_error( "Error: unknown file lines order" ) )
10098
}
10199
atom.symbol = atom.symbol.replace( /\W+/, '' ).replace( /\d+/, '' )
102100
if( !atom.symbol.length ) atom.symbol = 'Xx'
@@ -115,8 +113,7 @@ namespace $ {
115113
'cartesian': cartesian
116114
}
117115
else {
118-
this.$optimade_cifplayer_matinfio_log.error( "Error: unexpected POSCAR format" )
119-
return false
116+
return this.$mol_fail( new $mol_data_error( "Error: unexpected POSCAR format" ) )
120117
}
121118
}
122119
}

0 commit comments

Comments
 (0)