proc parse_mmcif_atoms {filename} { # Open and read the mmCIF file if {[catch {open $filename r} filehandle]} { puts "Error: Cannot open file $filename" return [list] } set extracting 0 set header_dict {} set atom_data {} while {[gets $filehandle line] >= 0} { # Check for start marker if {[string first "_atom_site.group_PDB" $line] != -1} { set i 0 dict set header_dict [string trim $line] $i set extracting 1 continue } # Check for end marker if {$extracting && [string first "#" $line] != -1} { break } # Collect lines while extracting if {$extracting} { if {[string first "_atom_site" $line] != -1 } { dict set header_dict [string trim $line] [incr i] } else { lappend atom_data $line } } } close $filehandle # TEST #~ # Create a temporary molecule and fill it with dummy atoms #~ set n [llength $atom_data] #~ set tmpmolid [ mol new atoms $n] #~ set atomslist [list] #~ for {set i 1} {$i<=$n} {incr i} { #~ ## list format {radius resname resid chain x y z occupancy element segname} #~ lappend atomslist [list 0 DUM 9999 X 0.00 0.00 0.00 0 DUM MOLF] #~ } #~ # Initialize the dummy atoms pool #~ set sel [atomselect $tmpmolid "all"] # Select molecule (top) set mol_id [molinfo top] set sel [atomselect $mol_id all] # Create an empty frame. animate dup $mol_id # Build coordinate and property lists set coords_x [list] set coords_y [list] set coords_z [list] set elements [list] set names [list] set resnames [list] set chains [list] set resids [list] set betas [list] set occupancies [list] set serials [list] # Populate the lists foreach atom $atom_data { lappend coords_x [lindex $atom [dict get $header_dict "_atom_site.Cartn_x"]] lappend coords_y [lindex $atom [dict get $header_dict "_atom_site.Cartn_y"]] lappend coords_z [lindex $atom [dict get $header_dict "_atom_site.Cartn_z"]] lappend elements [lindex $atom [dict get $header_dict "_atom_site.type_symbol"]] lappend names [lindex $atom [dict get $header_dict "_atom_site.label_atom_id"]] lappend resnames [lindex $atom [dict get $header_dict "_atom_site.label_comp_id"]] lappend chains [lindex $atom [dict get $header_dict "_atom_site.label_asym_id"]] lappend molecule [lindex $atom [dict get $header_dict "_atom_site.label_entity_id"]] lappend resids [lindex $atom [dict get $header_dict "_atom_site.auth_seq_id"]] lappend betas [lindex $atom [dict get $header_dict "_atom_site.B_iso_or_equiv"]] lappend occupancies [lindex $atom [dict get $header_dict "_atom_site.occupancy"]] } # Set all atomic properties at once $sel set x $coords_x $sel set y $coords_y $sel set z $coords_z $sel set element $elements $sel set name $names $sel set resname $resnames $sel set chain $chains $sel set resid $resids $sel set beta $betas $sel set occupancy $occupancies # Housekeeping: Delete selection $sel delete # Update VMD mol reanalyze $mol_id display resetview puts "Successfully created molecule $mol_id with [llength $atom_data] atoms" }