4 # Created by Toshi Nagata.
5 # Copyright 2014 Toshi Nagata. All rights reserved.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation version 2 of the License.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
18 def cmd_show_unit_cell
19 self.show_unitcell = !self.show_unitcell
22 def cmd_show_hydrogens
23 self.show_hydrogens = !self.show_hydrogens
26 def cmd_show_dummy_atoms
27 self.show_dummy_atoms = !self.show_dummy_atoms
31 self.show_expanded = !self.show_expanded
34 def cmd_show_ellipsoids
35 self.show_ellipsoids = !self.show_ellipsoids
38 def cmd_show_rotation_center
39 self.show_rotation_center = !self.show_rotation_center
43 n = self.show_graphite
44 flag = self.show_graphite?
45 hash = Dialog.run("Show Graphite") {
47 item(:checkbox, :title=>"Show graphite", :tag=>"show_graphite", :value=>(flag ? 1 : 0),
48 :action=>lambda { |it| set_attr("graphite", :enabled=>(it[:value] == 1)) } ),
49 item(:text, :title=>"Number of graphite rings for each direction:"),
50 item(:textfield, :width=>120, :tag=>"graphite", :value=>n.to_s, :enabled=>flag))
53 self.show_graphite(hash["graphite"])
54 self.show_graphite(hash["show_graphite"] == 1 ? true : false)
59 self.line_mode = !self.line_mode
62 def cmd_ball_and_stick_mode
65 res = mol.atom_resolution
66 brad = mol.bond_radius
67 bres = mol.bond_resolution
68 if mol.line_mode == true || mol.atom_radius >= 0.5
74 hash = Dialog.run("Ball and Stick") {
76 item(:text, :title=>"Atom Radius (0..0.5, default 0.2)"),
77 item(:textfield, :width=>100, :tag=>"atom_radius", :value=>rad.to_s),
78 item(:text, :title=>"Atom Resolution (default 12)"),
79 item(:textfield, :width=>100, :tag=>"atom_resolution", :value=>res.to_s),
80 item(:text, :title=>"Bond Radius (default 0.1)"),
81 item(:textfield, :width=>100, :tag=>"bond_radius", :value=>brad.to_s),
82 item(:text, :title=>"Atom Resolution (default 8)"),
83 item(:textfield, :width=>100, :tag=>"bond_resolution", :value=>bres.to_s))
86 f = hash["atom_radius"].to_f
87 self.atom_radius = f if f > 0.0 && f < 0.5
88 n = hash["atom_resolution"].to_i
89 self.atom_resolution = n if n >= 6 && n < 100
90 f = hash["bond_radius"].to_f
91 self.bond_radius = f if f > 0.0
92 n = hash["bond_resolution"].to_i
93 self.bond_resolution = n if n >= 4 && n < 100
94 self.line_mode = false
98 def cmd_space_filling_mode
100 rad = mol.atom_radius
101 res = mol.atom_resolution
102 if mol.line_mode == true || mol.atom_radius < 0.5
106 hash = Dialog.run("Space Filling") {
108 item(:text, :title=>"Atom Radius (0.5..2.0, default 1.0)"),
109 item(:textfield, :width=>100, :tag=>"atom_radius", :value=>rad.to_s),
110 item(:text, :title=>"Atom Resolution (default 18)"),
111 item(:textfield, :width=>100, :tag=>"atom_resolution", :value=>res.to_s))
113 if hash[:status] == 0
114 f = hash["atom_radius"].to_f
115 self.atom_radius = f if f >= 0.5 && f <= 2.0
116 n = hash["atom_resolution"].to_i
117 self.atom_resolution = n if n >= 6 && n < 100
118 self.line_mode = false
124 register_menu("View\t-", nil)
125 register_menu("View\t^Show Unit Cell", :cmd_show_unit_cell,
126 lambda { |m| [m != nil, m.show_unitcell] } )
127 register_menu("View\t^Show Hydrogen Atoms", :cmd_show_hydrogens,
128 lambda { |m| [m != nil, m.show_hydrogens] } )
129 register_menu("View\t^Show Dummy Atoms", :cmd_show_dummy_atoms,
130 lambda { |m| [m != nil, m.show_dummy_atoms] } )
131 register_menu("View\t^Show Expanded Atoms", :cmd_show_expanded,
132 lambda { |m| [m != nil, m.show_expanded] } )
133 register_menu("View\t^Show Ellipsoids", :cmd_show_ellipsoids,
134 lambda { |m| [m != nil, m.show_ellipsoids] } )
135 register_menu("View\t^Show Rotation Center", :cmd_show_rotation_center,
136 lambda { |m| [m != nil, m.show_rotation_center] } )
137 register_menu("View\t-", nil)
138 register_menu("View\t^Show Graphite...", :cmd_show_graphite,
139 lambda { |m| [m != nil, m.show_graphite?] } )
140 register_menu("View\t-", nil)
141 register_menu("View\tAppearance\t^Line", :cmd_line_mode,
142 lambda { |m| [m != nil, m.line_mode] } )
143 register_menu("View\tAppearance\t^Ball and Stick", :cmd_ball_and_stick_mode,
144 lambda { |m| [m != nil, !m.line_mode && m.atom_radius < 0.5] } )
145 register_menu("View\tAppearance\t^Space Filling", :cmd_space_filling_mode,
146 lambda { |m| [m != nil, !m.line_mode && m.atom_radius >= 0.5] } )