4 # Created by Toshi Nagata on 2008/06/28.
5 # Copyright 2008 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_assign_residue
23 atoms = sel.inspect.sub!("IntGroup[", "").sub!("]", "")
26 item(:text, :title=>"New residue name/number\n(like \"RES.1\")\nfor atoms #{atoms}"),
27 item(:textfield, :width=>120, :tag=>"residue"))
30 residue = hash["residue"]
31 assign_residue(sel, residue)
35 def cmd_offset_residue
40 atoms = sel.inspect.sub!("IntGroup[", "").sub!("]", "")
43 item(:text, :title=>"Offset residue number:\nfor atoms #{atoms}"),
44 item(:textfield, :width=>120, :tag=>"offset"))
47 offset = hash["offset"].to_i
48 offset_residue(sel, offset)
52 def cmd_sort_by_residue
57 sorted = sel.sort_by { |i| [self.atoms[i].res_seq, i] }
60 (0...natoms).each { |i|
64 break if j >= sorted.length
69 self.renumber_atoms(ary)
72 def save_gamess_with_ecp(filename)
74 raise MolbyError, "cannot save GAMESS input; the molecule is empty"
76 fp = open(filename, "wb")
78 fp.print <<end_of_header
80 ! Generated by Molby at #{now}
81 $CONTRL COORD=UNIQUE EXETYP=RUN ICHARG=0
82 ICUT=20 INTTYP=HONDO ITOL=30
83 MAXIT=200 MOLPLT=.T. MPLEVL=0
84 MULT=1 QMTTOL=1e-08 RUNTYP=OPTIMIZE
86 SCFTYP=RHF UNITS=ANGS $END
87 $SCF CONV=1.0E-06 DIRSCF=.T. FDIFF=.T. DAMP=.T. $END
88 $STATPT NSTEP=400 OPTTOL=1.0E-06 $END
89 $SYSTEM MEMDDI=0 MWORDS=16 TIMLIM=50000 $END
90 $BASIS EXTFIL=.T. GBASIS=321LAN $END
91 $GUESS GUESS=HUCKEL $END
99 fp.printf " %-6s %4d %10.6f %10.6f %10.6f\n", ap.name, ap.atomic_number, ap.r.x, ap.r.y, ap.r.z
100 if ap.atomic_number >= 11
101 ecp[ap.element.upcase] = 1
106 efp = open($startup_dir + "/gamess_ecp.txt", "rb")
111 if line == nil || line =~ /(\w\w)-ECP /
123 print "#{line}: #{'->ignore' if ecplines == nil}\n"
133 elem = ap.element.upcase
136 ecp[elem] = "#{elem}-ECP\n"
138 fp.print "#{elem}-ECP NONE\n"
145 def cmd_create_gamess
148 item(:text, :title=>"Create GAMESS input with LANL2DZ effective core potentials"))
150 if hash[:status] == 0
151 fname = File.basename(self.path, ".*") + ".inp"
152 fname = Dialog.save_panel(nil, self.dir, fname)
154 save_gamess_with_ecp(fname)
160 grid = default_MO_grid
164 item(:text, :title=>"This molecule does not contain MO information."))
169 if mos == nil || mos.length == 0
172 item(:text, :title=>"Please select MO(s) in the MO Info table."))
178 item(:text, :title=>"Please specify cube dimensions (in bohr unit):"),
180 item(:text, :title=>"Origin"),
181 item(:textfield, :width=>100, :height=>20, :tag=>"originx", :value=>sprintf("%.6f", grid[0].x)),
182 item(:textfield, :width=>100, :height=>20, :tag=>"originy", :value=>sprintf("%.6f", grid[0].y)),
183 item(:textfield, :width=>100, :height=>20, :tag=>"originz", :value=>sprintf("%.6f", grid[0].z)),
184 item(:text, :title=>"Delta"),
185 item(:textfield, :width=>100, :height=>20, :tag=>"deltax", :value=>sprintf("%.6f", grid[1])),
186 item(:textfield, :width=>100, :height=>20, :tag=>"deltay", :value=>sprintf("%.6f", grid[2])),
187 item(:textfield, :width=>100, :height=>20, :tag=>"deltaz", :value=>sprintf("%.6f", grid[3])),
188 item(:text, :title=>"Step"),
189 item(:textfield, :width=>100, :height=>20, :tag=>"stepx", :value=>grid[4].to_s),
190 item(:textfield, :width=>100, :height=>20, :tag=>"stepy", :value=>grid[5].to_s),
191 item(:textfield, :width=>100, :height=>20, :tag=>"stepz", :value=>grid[6].to_s)))
193 if hash[:status] == 0
194 path = self.path || self.name
195 dir = self.dir || Dir.pwd
196 origin = Vector3D[hash["originx"], hash["originy"], hash["originz"]]
203 basename = File.basename(path, ".*")
205 mo_type = self.mo_type
207 fname1 = fname2 = nil
208 alpha = (mo_type != "UHF" ? "" : "alpha ")
209 a = (mo_type != "UHF" ? "" : "a")
210 fname1 = Dialog.save_panel("Cube file name for #{alpha}MO #{n}", dir, basename + "_#{n}#{a}.cube", "Gaussian cube file (*.cube)|*.cube")
211 if (mo_type == "UHF")
212 fname2 = Dialog.save_panel("Cube file name for beta MO #{n}", dir, basename + "_#{n}b.cube", "Gaussian cube file (*.cube)|*.cube")
214 filenames.push([n, fname1, fname2])
216 filenames.each { |pair|
218 alpha = (mo_type != "UHF" ? "" : "alpha ")
219 show_progress_panel("Creating cube file for #{alpha}MO #{n}...")
221 cubegen(pair[1], n, origin, dx, dy, dz, nx, ny, nz, true)
223 if pair[2] && mo_type == "UHF"
224 set_progress_message("Creating cube file for beta MO #{n}...")
225 cubegen(pair[2], n, origin, dx, dy, dz, nx, ny, nz, true, true)
232 def Dialog.list_remote_files(host, directory)
233 # list = `ssh #{host} "env COLUMNS=40 ls -C #{directory}"`
234 list = `ssh #{host} "ls #{directory}"`
237 def Molecule.cmd_load_remote(mol) # mol is not used
239 def button_action(it) # Action for OK and Cancel buttons
240 if it[:index] == 0 # OK
241 local = File.expand_path(value("local"))
242 if value("local") != ""
243 # Check whether the local file already exists
245 sfile = value("sfile")
246 cfile = value("cfile")
247 if sfile != "" && FileTest.exist?("#{local}/#{sfile}")
250 if cfile != "" && FileTest.exist?("#{local}/#{cfile}")
255 msg = "The file #{exist[0]} already exists"
257 msg = "The files " + exist.join(", ") + " already exist"
259 msg += " in directory #{local}. Overwrite?"
261 layout(1, item(:text, :title=>msg, :width=>240, :height=>60))
263 return if hash[:status] != 0 # No call of super -> dialog is not dismissed
270 if value("host") != "" && value("directory") != "" && value("sfile") != ""
271 set_attr(0, :enabled=>true)
273 set_attr(0, :enabled=>false)
277 item(:text, :title=>"Remote host"),
278 item(:textfield, :width=>280, :height=>20, :tag=>"host", :action=>:text_action),
279 item(:text, :title=>"Directory"),
280 item(:textfield, :width=>280, :height=>20, :tag=>"directory", :action=>:text_action),
281 item(:text, :title=>"Structure File"),
282 item(:textfield, :width=>280, :height=>20, :tag=>"sfile", :action=>:text_action),
283 item(:text, :title=>"Coordinate File"),
284 item(:textfield, :width=>280, :height=>20, :tag=>"cfile"),
285 item(:text, :title=>"File List"),
286 item(:textview, :width=>280, :height=>80, :tag=>"list", :editable=>false),
288 [ item(:button, :title=>"Update",
289 :action=>lambda { |it|
290 list = Dialog.list_remote_files(value("host"), value("directory"))
291 set_value("list", list)
293 ), {:align=>:right} ],
294 # item(:checkbox, :title=>"Copy files to a local directory"),
296 item(:text, :title=>"Local directory"),
297 item(:textfield, :width=>280, :height=>20, :tag=>"local"),
299 [ item(:button, :title=>"Choose...",
300 :action=>lambda { |it|
301 dir = Dialog.open_panel(nil, nil, nil, true)
303 set_value("local", dir)
306 ), {:align=>:right} ]
309 set_attr(0, :action=>:button_action)
310 set_attr(1, :action=>:button_action)
311 set_attr(0, :enabled=>false)
312 self.each_item { |it|
314 if (type = it[:type]) == :textfield || type == :textview
315 val = get_global_settings("load_remote.#{tag}")
322 hash.each_pair { |key, value|
323 next if key == :status
324 set_global_settings("load_remote.#{key}", value)
326 if hash[:status] == 0
327 sfile = hash["sfile"]
328 cfile = hash["cfile"]
330 directory = hash["directory"]
331 local = hash["local"]
333 local = `mktemp -d /tmp/MolbyRemoteLoad.XXXXXX`.chomp
335 raise "Cannot create a temporary directory"
338 local = File.expand_path(local)
339 if cfile == "" && sfile =~ /\.psf$/
340 cfile = sfile.sub(/\.psf$/, ".pdb")
345 files = "{#{sfile},#{cfile}}"
347 show_progress_panel("Fetching remote file(s)...")
348 if !system("scp '#{host}:#{directory}/#{files}' '#{local}'")
349 raise "Cannot copy remote files"
351 hide_progress_panel()
352 mol = Molecule.open("#{local}/#{sfile}")
353 if cfile != "" && FileTest.exist?("#{local}/#{cfile}")
354 mol.undo_enabled = false
355 mol.molload("#{local}/#{cfile}")
356 mol.undo_enabled = true
361 def cmd_delete_frames
366 item(:text, :title=>"Start"),
367 item(:textfield, :width=>120, :tag=>"start", :value=>"0"),
368 item(:text, :title=>"End"),
369 item(:textfield, :width=>120, :tag=>"end", :value=>(n - 1).to_s),
370 item(:text, :title=>"Keeping frames every..."),
372 item(:text, :title=>"Step"),
373 item(:textfield, :width=>120, :tag=>"step", :value=>"0"))
375 if hash[:status] == 0
376 sframe = Integer(hash["start"])
377 eframe = Integer(hash["end"])
378 step = Integer(hash["step"])
379 return if sframe > eframe
380 eframe = n - 1 if eframe >= n
381 fgroup = IntGroup[sframe..eframe]
383 while sframe <= eframe
384 fgroup.delete(sframe)
388 remove_frames(fgroup)
393 # Find molecule with unit cell defined
396 Molecule.list.each { |m|
399 solvnames.push m.name
402 if solvnames.length == 0
405 item(:text, :title=>"Please open a molecule file containing a solvent box."))
411 item(:text, :title=>"Choose solvent box:"),
412 item(:popup, :subitems=>solvnames, :tag=>"solvent"),
413 item(:text, :title=>"Box offset\n(Negative numbers for absolute sizes)"),
415 item(:text, :title=>"x"),
416 item(:textfield, :width=>"120", :tag=>"x", :value=>"10.0"),
417 item(:text, :title=>"y"),
418 item(:textfield, :width=>"120", :tag=>"y", :value=>"10.0"),
419 item(:text, :title=>"z"),
420 item(:textfield, :width=>"120", :tag=>"z", :value=>"10.0")),
421 item(:text, :title=>"Exclusion limit distance:"),
422 item(:textfield, :width=>"120", :tag=>"limit", :value=>"3.0"))
424 if hash[:status] == 0
425 solvate(solv[hash["solvent"]], [hash["x"], hash["y"], hash["z"]], hash["limit"])
429 def cmd_show_graphite
430 n = self.show_graphite
431 flag = self.show_graphite?
432 hash = Dialog.run("Show Graphite") {
434 item(:checkbox, :title=>"Show graphite", :tag=>"show_graphite", :value=>(flag ? 1 : 0),
435 :action=>lambda { |it| set_attr("graphite", :enabled=>(it[:value] == 1)) } ),
436 item(:text, :title=>"Number of graphite rings for each direction:"),
437 item(:textfield, :width=>120, :tag=>"graphite", :value=>n.to_s, :enabled=>flag))
439 if hash[:status] == 0
440 self.show_graphite(hash["graphite"])
441 self.show_graphite(hash["show_graphite"] == 1 ? true : false)
447 $test_dialog = Dialog.new("Test") { item(:text, :title=>"test"); show }
452 register_menu("Assign residue...", :cmd_assign_residue)
453 register_menu("Offset residue...", :cmd_offset_residue)
454 register_menu("Sort by residue", :cmd_sort_by_residue)
455 register_menu("", "")
456 register_menu("Load remote...", :cmd_load_remote)
457 #register_menu("Create GAMESS input...", :cmd_create_gamess)
458 #register_menu("Create Cube file...", :cmd_create_cube)
459 register_menu("", "")
460 register_menu("Delete Frames...", :cmd_delete_frames)
461 register_menu("Solvate...", :cmd_solvate)
462 #register_menu("cmd test", :cmd_test)