Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$mol rewrite #18

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/app.view.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace $.$$ {

contain: 'none', //otherwise in fullscreen 'fixed' positions plot relative to parent not to the viewport

'@': {
mol_drop_status: {
drag: {
'[mol_drop_status]': {
drag: {
Menu: {
background: {
color: $mol_theme.hover,
},
Expand Down
23 changes: 12 additions & 11 deletions comparison/comparison.view.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ namespace $.$$ {
export class $mpds_cifplayer_comparison extends $.$mpds_cifplayer_comparison {

@ $mol_mem_key
cif_pages( id: any ): readonly any[] {
cif_pages( id: string ): readonly any[] {
return this.comparison_on() ? super.cif_pages( id ) : [ this.Player_page( id ) ]
}

@ $mol_mem
cif_spreads(): Record<string, any> {
return Object.fromEntries( this.cif_paths().map( path => [ path, this.Cif_spread( path ) ] ) )
}

@ $mol_mem_key
cif_title( id: any ): string {
cif_title( id: string ): string {
return id.split( '/' ).slice( -2 ).join( '/' )
}

Expand All @@ -27,44 +28,44 @@ namespace $.$$ {
}

@ $mol_mem_key
nasty_cif_reference( id: any ): string {
const num = parseInt( id.split( '/' ).at(-1) )
nasty_cif_reference( id: string ): string {
const num = parseInt( id.split( '/' ).at(-1)! )
return this.nasty_cif_csv()[ num ][ ' reference' ]
}

@ $mol_mem_key
nasty_cif_problem( id: any ): string {
const num = parseInt( id.split( '/' ).at(-1) )
nasty_cif_problem( id: string ): string {
const num = parseInt( id.split( '/' ).at(-1)! )
return this.nasty_cif_csv()[ num ][ ' problem' ]
}

@ $mol_mem_key
nasty_cif_section( id: any ): readonly any[] {
nasty_cif_section( id: string ): readonly any[] {
const cif_type = id.split( '/' ).at(-2)
if ( cif_type != 'bad' ) return []
return super.nasty_cif_section( id )
}

@ $mol_mem_key
cif_value( id: any, next?: string ): string {
cif_value( id: string, next?: string ): string {
if ( next !== undefined ) return next as never
const path = id
const str = $mol_fetch.text( gh_pages_fix_url( path ) )
return str
}

@ $mol_mem_key
matinfio_obj( id: any ): Record<string, any> {
matinfio_obj( id: string ): Record<string, any> {
return new $mpds_cifplayer_matinfio( this.cif_value( id ) ).player() as any
}

@ $mol_mem_key
crystcif_obj( id: any ): Record<string, any> {
crystcif_obj( id: string ): Record<string, any> {
return $mpds_cifplayer_lib_cif.all().crystcif.parseCifStructures( this.cif_value( id ) ) as any
}

@ $mol_mem_key
cif_loader3_obj( id: any ): Record<string, any> {
cif_loader3_obj( id: string ): Record<string, any> {
const loader = $mpds_cifplayer_lib_cif.loader()
return loader.parse( this.cif_value( id ) )
}
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions lib/cif/cif.meta.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require \/mpds/cifplayer/lib/cif/_cif.js
2 changes: 1 addition & 1 deletion lib/cif/cif.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace $ {

@ $mol_mem
static all() {
return require( '../mpds/cifplayer/lib/cif/cif.js' ) as typeof import( './_cif' )
return require( '../mpds/cifplayer/lib/cif/_cif.js' ) as typeof import( './_cif' )
}

@ $mol_mem
Expand Down
2 changes: 1 addition & 1 deletion lib/three/view/view.view.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace $.$$ {

export class $mpds_cifplayer_lib_three_view extends $.$mpds_cifplayer_lib_three_view {

@ $mol_mem
start_render_loop() {
const render_loop = ()=> {
this.rerender()
Expand All @@ -14,7 +15,6 @@ namespace $.$$ {
}

/** Get an existing object or create a new */
@ $mol_mem_key
object< T extends InstanceType< THREE["Object3D"] > >( name: string, make: ()=> T ): T {
const old = this.scene()?.getObjectByName( name )
if( old ) return old as T
Expand Down
73 changes: 39 additions & 34 deletions matinfio/cif/cif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ namespace $ {

const math = $mpds_cifplayer_lib_math

const startswith = ( str: string, prefix: string ) => {
return str.indexOf( prefix ) === 0
if( !String.prototype.startsWith ) {
Object.defineProperty( String.prototype, 'startsWith', {
value: function( search: string, rawPos: number ) {
var pos = rawPos > 0 ? rawPos|0 : 0;
return this.substring( pos, pos + search.length ) === search;
}
});
stan-donarise marked this conversation as resolved.
Show resolved Hide resolved
}

export function $mpds_cifplayer_matinfio_cif_to_obj( this: $, str: string ): $mpds_cifplayer_matinfio_internal_obj {
Expand All @@ -26,7 +31,7 @@ namespace $ {
let line_data: any[] = []
let symmetry_seq = []
const cell_props = [ 'a', 'b', 'c', 'alpha', 'beta', 'gamma' ]
const loop_vals = [
const loop_vals = [
'_atom_site_label',
'_atom_site_type_symbol',
'_atom_site_fract_x',
Expand All @@ -36,11 +41,11 @@ namespace $ {
"_atom_site_Cartn_y",
"_atom_site_Cartn_z",
]
const atom_props = [
'label',
'symbol',
'x',
'y',
const atom_props = [
'label',
'symbol',
'x',
'y',
'z',
'x',
'y',
Expand All @@ -55,7 +60,7 @@ namespace $ {
}

for( let i = 0; i < lines.length; i++ ) {
if( startswith( lines[ i ], '#' ) ) continue
if( lines[ i ].startsWith('#') ) continue
cur_line = lines[ i ].trim()
if( !cur_line ) {
loop_active = false, atprop_seq = [], symops_active = false
Expand All @@ -64,14 +69,14 @@ namespace $ {
fingerprt = cur_line.toLowerCase()
new_structure = false

if( startswith( fingerprt, 'data_' ) ) {
new_structure = true,
loop_active = false,
atprop_seq = [],
symops_active = false,
data_info = cur_line.substr( 5 )
if( fingerprt.startsWith( 'data_' ) ) {
new_structure = true
loop_active = false
atprop_seq = []
symops_active = false
data_info = cur_line.substr( 5 )

} else if( startswith( fingerprt, '_cell_' ) ) {
} else if( fingerprt.startsWith( '_cell_' ) ) {
loop_active = false
line_data = cur_line.split( " " )
const cell_data = line_data[ 0 ].split( "_" )
Expand All @@ -87,36 +92,36 @@ namespace $ {
}
continue

} else if( startswith( fingerprt, '_symmetry_space_group_name_h-m' ) || startswith( fingerprt, '_space_group.patterson_name_h-m' ) ) {
} else if( fingerprt.startsWith( '_symmetry_space_group_name_h-m' ) || fingerprt.startsWith( '_space_group.patterson_name_h-m' ) ) {
loop_active = false
cur_structure.sg_name = lines[ i ].trim().substr( 31 ).replace( /"/g, '' ).replace( /'/g, '' )
continue

} else if( startswith( fingerprt, '_space_group.it_number' ) || startswith( fingerprt, '_space_group_it_number' ) || startswith( fingerprt, '_symmetry_int_tables_number' ) ) {
} else if( fingerprt.startsWith( '_space_group.it_number' ) || fingerprt.startsWith( '_space_group_it_number' ) || fingerprt.startsWith( '_symmetry_int_tables_number' ) ) {
loop_active = false
line_data = cur_line.split( " " )
cur_structure.ng_name = line_data[ line_data.length - 1 ].trim()
continue

} else if( startswith( fingerprt, '_cif_error' ) ) { // custom tag
} else if( fingerprt.startsWith( '_cif_error' ) ) { // custom tag
const error_message = cur_line.substr( 12, cur_line.length - 13 )
return this.$mol_fail( new $mol_data_error( error_message ) )

} else if( startswith( fingerprt, '_pauling_file_entry' ) ) { // custom tag
} else if( fingerprt.startsWith( '_pauling_file_entry' ) ) { // custom tag
cur_structure.mpds_data = true
continue

} else if( startswith( fingerprt, 'loop_' ) ) {
} else if( fingerprt.startsWith( 'loop_' ) ) {
loop_active = true
atprop_seq = []
symops_active = false
continue
}

if( loop_active ) {
if( startswith( cur_line, '_symmetry_equiv' ) || startswith( cur_line, '_space_group' ) ) {
if( cur_line.startsWith( '_symmetry_equiv' ) || cur_line.startsWith( '_space_group' ) ) {
symops_active = true
} else if( startswith( cur_line, '_' ) ) {
} else if( cur_line.startsWith( '_' ) ) {
atprop_seq.push( cur_line )
if( cur_line == '_atom_site_Cartn_x' ) cur_structure.cartesian = true
} else {
Expand Down Expand Up @@ -147,9 +152,9 @@ namespace $ {
atom.overlays.label = atom.label
if( !atom.symbol ) atom.symbol = atom.label.replace( /[0-9]/g, '' )
}
if( !( $mpds_cifplayer_matinfio_chemical_elements.JmolColors as any )[ atom.symbol ]
&& atom.symbol
&& atom.symbol.length > 1
if( !( $mpds_cifplayer_matinfio_chemical_elements.JmolColors as any )[ atom.symbol ]
&& atom.symbol
&& atom.symbol.length > 1
) {
atom.symbol = atom.symbol.substr( 0, atom.symbol.length - 1 )
}
Expand Down Expand Up @@ -178,8 +183,8 @@ namespace $ {
if( symops.length > 1 ) cur_structure.symops = symops
structures.push( cur_structure )

if( !structures.length ) return this.$mol_fail( new $mol_data_error('Error: unexpected CIF format') )
if( !structures.length ) return this.$mol_fail( new $mol_data_error( 'Error: unexpected CIF format' ) )

return structures[ structures.length - 1 ] // TODO switch between frames
}

Expand All @@ -188,9 +193,9 @@ namespace $ {
/** Convert internal repr into CIF */
export function $mpds_cifplayer_matinfio_cif_from_obj( this: $, crystal: any ) {

var cif_str = "data_matinfio\n",
cell_abc,
cell_mat
let cif_str = "data_matinfio\n"
let cell_abc
let cell_mat

if( Object.keys( crystal.cell ).length == 6 ) {
cell_abc = crystal.cell
Expand Down Expand Up @@ -222,14 +227,14 @@ namespace $ {
if( crystal.cartesian ) {

//var t_cell_mat = math.transpose(cell_mat);
var t_cell_mat = cell_mat
const t_cell_mat = cell_mat
//console.log(t_cell_mat);

crystal.atoms.forEach( function( atom: any, i: number ) {
//console.log([atom.x, atom.y, atom.z]);
// TODO better test lusolve against usolve, lsolve etc.
var solved = math.lusolve( t_cell_mat, [ atom.x, atom.y, atom.z ] ),
fracs = math.transpose( solved )[ 0 ]
let solved = math.lusolve( t_cell_mat, [ atom.x, atom.y, atom.z ] )
let fracs = math.transpose( solved )[ 0 ]

//console.log(fracs);
cif_str += " " + atom.symbol + ( i + 1 ) + " " + atom.symbol + " "
Expand Down