Class: AimsProject::CalculationWindow

Inherits:
Wx::Panel
  • Object
show all
Includes:
Wx
Defined in:
lib/aims_project/calculation_window.rb

Constant Summary collapse

CALC_TABLE_COLS =
4

Instance Method Summary collapse

Constructor Details

#initialize(app, parent) ⇒ CalculationWindow

Returns a new instance of CalculationWindow.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/aims_project/calculation_window.rb', line 9

def initialize(app, parent)
  
  super(parent)
  @app = app
  
  # Initialize the selection
  @selection = {}
  
  # The inspector window
  @inspector_window = @app.inspector.add_inspector_window
  
  # Initialize the options for the crystal viewer
  @options = CrystalViewerOptions.new(@inspector_window)
  
  # Top level is a splitter
  topSplitterWindow = SplitterWindow.new(self)
  sizer = VBoxSizer.new
  sizer.add_item(topSplitterWindow, :proportion => 1, :flag => EXPAND)
  
  set_sizer(sizer)
  
  # The top is a list control
  @calcTable = Grid.new(topSplitterWindow, -1)
  init_table

  # Populate the calculations list
  @calcs = @app.project.calculations.sort{|a,b| a.name <=> b.name}
  @calcs.each_with_index{|calc, i|
    add_calc_at_row(calc, i)
  }
  @calcTable.auto_size

  # The bottom is a vertical splitter
  calcWindowSplitter = SplitterWindow.new(topSplitterWindow)
  
  # with a tree and a viewer
  @calcTree = CalculationTree.new(self, calcWindowSplitter)
  @calcViewer = CrystalViewer.new(self, calcWindowSplitter, @options)
  calcWindowSplitter.split_vertically(@calcTree, @calcViewer)


  # Split the top and bottom
  topSplitterWindow.split_horizontally(@calcTable, calcWindowSplitter, 100)

  # Setup the events
  evt_grid_cmd_range_select(@calcTable) {|evt|
    if evt.selecting
      row = evt.get_top_row
      puts "CalculationWindow.show_calculation #{@calcs[row].calculation_directory}"
      show_calculation(@calcs[row])        
    end
  }
  
  evt_thread_callback {|evt|
    @calcTree.show_calculation(@calculation)
    if @calculation.final_geometry
      show_geometry(@calculation.final_geometry)
    else
      show_geometry(@calculation.input_geometry)
    end
  }
  
end

Instance Method Details

#add_calc_at_row(calc, row) ⇒ Object

Insert a calculation in the table at the specified row



83
84
85
86
87
88
# File 'lib/aims_project/calculation_window.rb', line 83

def add_calc_at_row(calc, row)
  @calcTable.set_cell_value(row, 0, calc.geometry)
  @calcTable.set_cell_value(row, 1, calc.calc_subdir.to_s)
  @calcTable.set_cell_value(row, 2, calc.control)
  @calcTable.set_cell_value(row, 3, calc.status)
end

#geometryObject

get the currently displayed geometry



123
124
125
# File 'lib/aims_project/calculation_window.rb', line 123

def geometry
  @calcViewer.unit_cell
end

#imageObject

Get an Image



118
119
120
# File 'lib/aims_project/calculation_window.rb', line 118

def image
  @calcViewer.image
end

#init_tableObject



73
74
75
76
77
78
79
80
# File 'lib/aims_project/calculation_window.rb', line 73

def init_table
  @calcTable.create_grid(@app.project.calculations.size, CALC_TABLE_COLS, Grid::GridSelectRows)
  @calcTable.set_col_label_value(0, "Geometry")
  @calcTable.set_col_label_value(1, "Subdirectory")
  @calcTable.set_col_label_value(2, "Control")
  @calcTable.set_col_label_value(3, "Status")
  
end

#nudge_selected_atoms(x, y, z) ⇒ Object



136
137
138
# File 'lib/aims_project/calculation_window.rb', line 136

def nudge_selected_atoms(x,y,z)
  @app.error_dialog("Sorry, 'nudge' doesn't work on calculation outputs.")
end

#select_atom(atom) ⇒ Object



132
133
134
# File 'lib/aims_project/calculation_window.rb', line 132

def select_atom(atom)
  @app.set_status(atom.format_geometry_in)
end

#show_calculation(calc) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/aims_project/calculation_window.rb', line 94

def show_calculation(calc)
 begin
   @calculation = calc
   @err = nil
   t = Thread.new(self) { |evtHandler|
     begin
       @app.set_status("Loading #{@calculation.name}")
       @calculation.load_output
       evt = ThreadCallbackEvent.new
       evtHandler.add_pending_event(evt)
       @app.set_status("")
     rescue $! => e
       @app.set_status(e.message)
     end
   }
   t.priority = t.priority + 100
 rescue $! => e
   puts e.message
   puts e.backtrace
   @app.error_dialog(e)
 end
end

#show_geometry(geometry) ⇒ Object

Display the given geometry



128
129
130
# File 'lib/aims_project/calculation_window.rb', line 128

def show_geometry(geometry)
  @calcViewer.unit_cell = GeometryFile.new(geometry)
end

#show_inspectorObject



90
91
92
# File 'lib/aims_project/calculation_window.rb', line 90

def show_inspector
  @app.inspector.show_inspector_window(@inspector_window)
end