Skip to content

Commit

Permalink
Merge pull request #23 from stan-donarise/fixes-1
Browse files Browse the repository at this point in the history
fixed support for optimade, poscar and some cifs; error styles
  • Loading branch information
blokhin authored Mar 22, 2024
2 parents c856d74 + 8d96fb2 commit b970ad3
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 20 deletions.
7 changes: 2 additions & 5 deletions matinfio/cell/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ namespace $ {
}

/** 3x3 matrix to crystalline cell parameters */
export function $mpds_cifplayer_matinfio_cell_params_from_matrix( matrix: number[] ) {
const norms: number[] = []
export function $mpds_cifplayer_matinfio_cell_params_from_matrix( matrix: number[][] ) {
const norms: number[] = matrix.map( vec => math.norm( vec ) )
const angles = []
matrix.forEach( function( vec ) {
norms.push( math.norm( vec ) )
} )
let j = -1
let k = -2
for( let i = 0; i < 3; i++ ) {
Expand Down
9 changes: 7 additions & 2 deletions matinfio/cif/cif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ namespace $ {
}
continue

} else if( fingerprt.startsWith( '_symmetry_space_group_name_h-m' ) || fingerprt.startsWith( '_space_group.patterson_name_h-m' ) ) {
} else if(
fingerprt.startsWith( '_symmetry_space_group_name_h-m' )
|| fingerprt.startsWith( '_space_group.patterson_name_h-m' )
|| fingerprt.startsWith( '_space_group_name_h-m_alt' )
) {
loop_active = false
cur_structure.sg_name = lines[ i ].trim().substr( 31 ).replace( /"/g, '' ).replace( /'/g, '' )
const match = cur_line.match( /"(.*)"|'(.*)'/ )
cur_structure.sg_name = match?.[1] || match?.[2]
continue

} else if( fingerprt.startsWith( '_space_group.it_number' ) || fingerprt.startsWith( '_space_group_it_number' ) || fingerprt.startsWith( '_symmetry_int_tables_number' ) ) {
Expand Down
10 changes: 10 additions & 0 deletions matinfio/player/player.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ namespace $ {

} else {
cell_matrix = crystal.cell_matrix // for POSCAR and OPTIMADE

const params = $mpds_cifplayer_matinfio_cell_params_from_matrix( cell_matrix! )
descr = {
'a': params[0],
'b': params[1],
'c': params[2],
'alpha': params[3],
'beta': params[4],
'gamma': params[5],
}
}

if( !crystal.atoms.length ) this.$mpds_cifplayer_matinfio_log.warning( "Note: no atomic coordinates supplied" )
Expand Down
8 changes: 4 additions & 4 deletions matinfio/spacegroup/spacegroup.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace $ {
super()
}

@ $mol_mem_key
static by_name_and_num( name: string, num: number ) {
const spacegroup = $mpds_cifplayer_matinfio_spacegroup.by_num( num )
?? $mpds_cifplayer_matinfio_spacegroup.by_name( name )
static by_name_or_num( name: string, num: number ) {
const spacegroup = num
? $mpds_cifplayer_matinfio_spacegroup.by_num( num )
: name ? $mpds_cifplayer_matinfio_spacegroup.by_name( name ) : null
return spacegroup ? spacegroup : $mpds_cifplayer_matinfio_spacegroup.unknown()
}

Expand Down
15 changes: 15 additions & 0 deletions player/player.view.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ namespace $.$$ {
height: '2rem',
},

Message: {
position: 'absolute',
zIndex: 1,
top: '6rem',
left: 0,
right: 0,
},

Message_card: {
background: {
color: $mol_theme.back,
},
margin: 'auto',
},

} )

}
7 changes: 6 additions & 1 deletion player/player.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ $mpds_cifplayer_player $mol_view
sub <= overlays_sub /
<= Switch_overlay $mol_switch
value? <=> overlay? \S
options <= available_overlays *
options <= available_overlays *string
\
\display none
S \elements
^ message_visible / <= Message $mol_view
sub /
<= Message_card $mol_card
theme \$mol_theme_special
title <= message \
colors_light *
a \#990000
b \#009900
Expand Down
37 changes: 29 additions & 8 deletions player/player.view.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace $.$$ {

export class $mpds_cifplayer_player extends $.$mpds_cifplayer_player {

@ $mol_mem
render(): void {
super.render()
this.structure_3d_data() //for bubbling errors into view
}

@ $mol_mem
available_overlays() {
try {
this.structure_3d_data()
} catch (error) {
return {}
}

return {
...super.available_overlays(),
...this.structure_3d_data().overlayed
Expand Down Expand Up @@ -91,6 +91,22 @@ namespace $.$$ {
this.camera().position.add( this.camera_distance().multiplyScalar( this.zoom_scale_step() ) )
}

@ $mol_mem
message_visible() {
return this.message() ? super.message_visible() : []
}

@ $mol_mem
message(): string {
try {
this.structure_3d_data()
return ''

} catch ( error: any ) {
return error.message || error
}
}

@ $mol_mem
structure_3d_data() {
return new $mpds_cifplayer_matinfio( this.data() ).player()
Expand Down Expand Up @@ -153,7 +169,7 @@ namespace $.$$ {
spacegroup() {
const { sg_name, ng_name } = this.structure_3d_data()

return $mpds_cifplayer_matinfio_spacegroup.by_name_and_num( sg_name, ng_name )
return $mpds_cifplayer_matinfio_spacegroup.by_name_or_num( sg_name, ng_name )
}

@ $mol_mem
Expand Down Expand Up @@ -444,7 +460,12 @@ namespace $.$$ {

@ $mol_mem
left_panel(): readonly any[] {
console.log('this.structure_3d_data()', this.structure_3d_data())
try {
this.structure_3d_data()
} catch (error) {
return []
}

return this.structure_3d_data().cell_matrix ? super.left_panel() : []
}

Expand Down

0 comments on commit b970ad3

Please sign in to comment.