Molecular Modeling Software
リビジョン | 00005e8cde17a696a8d2dc1704974d3de3a12bd9 (tree) |
---|---|
日時 | 2022-01-27 21:53:32 |
作者 | Toshi Nagata <alchemist.2005@nift...> |
コミッター | Toshi Nagata |
Concatenate frames command is implemented.
@@ -121,6 +121,108 @@ class Molecule | ||
121 | 121 | end |
122 | 122 | end |
123 | 123 | |
124 | + def cmd_concat_frames | |
125 | + n = nframes | |
126 | + return if n == 0 | |
127 | + if Molecule.list.length == 1 | |
128 | + message_box("No other molecule.", "", :ok) | |
129 | + return | |
130 | + end | |
131 | + ls = (0...Molecule.list.length).select { |i| | |
132 | + m = Molecule[i] | |
133 | + if m == self || m.natoms != self.natoms | |
134 | + false | |
135 | + else | |
136 | + if nil != (0...m.natoms).find { |n| m.atoms[n].atomic_number != self.atoms[n].atomic_number } | |
137 | + false | |
138 | + else | |
139 | + true | |
140 | + end | |
141 | + end | |
142 | + } | |
143 | + if ls.length == 0 | |
144 | + message_box("No molecule has the same atomic sequence as the present one.", "", :ok) | |
145 | + return | |
146 | + end | |
147 | + labels = [] | |
148 | + label_hash = Hash.new # Check if documents with the same name are present | |
149 | + ls.each_with_index { |i, idx| # i is an index to Molecule, idx is an index to ls | |
150 | + m = Molecule[i] | |
151 | + label = m.name | |
152 | + idx_h = label_hash[label] # If non-nil, then duplicate name | |
153 | + label_hash[label] = idx | |
154 | + if idx_h | |
155 | + if labels[idx_h] == label | |
156 | + labels[idx_h] = label + " (" + Molecule[ls[idx_h]].dir + ")" | |
157 | + end | |
158 | + label = label + " (" + Molecule[i].dir + ")" | |
159 | + end | |
160 | + labels.push(label) | |
161 | + } | |
162 | + nf = Molecule[ls[0]].nframes | |
163 | + hash = Dialog.run("Concatenate Frames") { | |
164 | + layout(2, | |
165 | + item(:text, :title=>"From Molecule:"), | |
166 | + item(:popup, :subitems=>labels, :tag=>"mol", :width=>240, | |
167 | + :action=>lambda { |it| | |
168 | + nf = Molecule[ls[it[:value]]].nframes | |
169 | + set_attr("start_title", :title=>"Start (0-#{nf})") | |
170 | + set_attr("end_title", :title=>"End (0-#{nf})") | |
171 | + }), | |
172 | + item(:radio, :title=>"All Frames", :tag=>"all_frames", :value=>1, | |
173 | + :action=>lambda { |it| | |
174 | + flag = (it[:value] == 0) | |
175 | + set_attr("start_frame", :enabled=>flag) | |
176 | + set_attr("end_frame", :enabled=>flag) | |
177 | + }), -1, | |
178 | + item(:radio, :title=>"Select Frames", :tag=>"select_frames", | |
179 | + :action=>lambda { |it| | |
180 | + flag = (it[:value] != 0) | |
181 | + set_attr("start_frame", :enabled=>flag) | |
182 | + set_attr("end_frame", :enabled=>flag) | |
183 | + }), -1, | |
184 | + item(:text, :title=>"Start (0-#{nf})", :tag=>"start_title"), | |
185 | + item(:textfield, :value=>"0", :tag=>"start_frame", :enabled=>false), | |
186 | + item(:text, :title=>"End (0-#{nf})", :tag=>"end_title"), | |
187 | + item(:textfield, :value=>"0", :tag=>"end_frame", :enabled=>false)) | |
188 | + radio_group("all_frames", "select_frames") | |
189 | + } | |
190 | + if hash[:status] == 0 | |
191 | + idx_h = Integer(hash["mol"]) | |
192 | + m = Molecule[ls[idx_h]] | |
193 | + f = m.frame # Save the current frame number | |
194 | + nf = m.nframes | |
195 | + if hash["all_frame"] != 0 | |
196 | + f1 = 0 | |
197 | + f2 = nf - 1 | |
198 | + else | |
199 | + f1 = Integer(hash["start_frame"]) | |
200 | + f2 = Integer(hash["end_frame"]) | |
201 | + f1 = 0 if f1 < 0 | |
202 | + f1 = nf - 1 if f1 > nf - 1 | |
203 | + f2 = 0 if f2 < 0 | |
204 | + f2 = nf - 1 if f2 > nf - 1 | |
205 | + end | |
206 | + if f1 <= f2 | |
207 | + a = (f1..f2).to_a | |
208 | + else | |
209 | + a = (f2..f1).to_a.reverse | |
210 | + end | |
211 | + prop = m.property_names | |
212 | + na = m.natoms | |
213 | + a.each { |n| | |
214 | + self.create_frame() | |
215 | + m.select_frame(n) | |
216 | + na.times { |i| | |
217 | + self.atoms[i].r = m.atoms[i].r | |
218 | + } | |
219 | + prop.each { |pr| | |
220 | + self.set_property(pr, m.get_property(pr)) | |
221 | + } | |
222 | + } | |
223 | + end | |
224 | + end | |
225 | + | |
124 | 226 | def cmd_extra_properties |
125 | 227 | mol = self |
126 | 228 | get_count = lambda { |it| mol.nframes } |
@@ -591,6 +693,7 @@ register_menu("Sort by residue", :cmd_sort_by_residue, :non_empty) | ||
591 | 693 | register_menu("", "") |
592 | 694 | register_menu("Delete Frames...", :cmd_delete_frames, lambda { |m| m && m.nframes > 1 } ) |
593 | 695 | register_menu("Reverse Frames...", :cmd_reverse_frames, lambda { |m| m && m.nframes > 1 } ) |
696 | +register_menu("Concatenate Frames...", :cmd_concat_frames, lambda { |m| m && m.nframes > 1 } ) | |
594 | 697 | register_menu("", "") |
595 | 698 | register_menu("Show Energy Window...", :cmd_show_energy, lambda { |m| m && m.property_names.include?("energy") } ) |
596 | 699 | register_menu("Show MO Surface...", :cmd_create_surface, lambda { |m| m && m.get_mo_info(:type) != nil } ) |