• R/O
  • HTTP
  • SSH
  • HTTPS

Molby: コミット

Molecular Modeling Software


コミットメタ情報

リビジョン49adab98c657ae4b09c86bd45c7f26bab4b172ac (tree)
日時2014-04-25 14:18:32
作者toshinagata1964 <toshinagata1964@a2be...>
コミッターtoshinagata1964

ログメッセージ

Setting the 'Scratch' directory is sorted out.

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@533 a2be9bc6-48de-4e38-9406-05402d4bc13c

変更サマリ

差分

--- a/Scripts/commands.rb
+++ b/Scripts/commands.rb
@@ -107,6 +107,27 @@ class Molecule
107107
108108 end
109109
110+module Kernel
111+ def ask_scratch_dir
112+ sdir = get_global_settings("global.scratch_dir")
113+ while 1
114+ p = Dialog.open_panel("Please select scratch directory", sdir, nil, true)
115+ if p
116+ if p =~ / /
117+ error_message_box("Please avoid path containing a white space.\n" + p.sub(/ /, "<!> <!>"))
118+ sdir = p
119+ next
120+ else
121+ set_global_settings("global.scratch_dir", p)
122+ return p
123+ end
124+ else
125+ return nil
126+ end
127+ end
128+ end
129+end
130+
110131 register_menu("Assign residue...", :cmd_assign_residue, :non_empty)
111132 register_menu("Offset residue...", :cmd_offset_residue, :non_empty)
112133 register_menu("Sort by residue", :cmd_sort_by_residue, :non_empty)
--- a/Scripts/crystal.rb
+++ b/Scripts/crystal.rb
@@ -1415,7 +1415,12 @@ end
14151415
14161416 def cmd_show_ortep
14171417 mol = self
1418- tmp = create_temp_dir("ortep", mol.name)
1418+ begin
1419+ tmp = create_temp_dir("ortep", mol.name)
1420+ rescue
1421+ error_message_box($!.to_s)
1422+ return
1423+ end
14191424 tepexe = "#{ResourcePath}/ortep3/ortep3"
14201425 if $platform == "win"
14211426 tepexe += ".exe"
@@ -1685,7 +1690,7 @@ def cmd_show_ortep
16851690 }
16861691 # Close handler (called when the close box is pressed or the document is closed)
16871692 @on_close = lambda { |*d|
1688- cleanup_temp_dir(tmp)
1693+ erase_old_logs(tmp)
16891694 tmp = nil
16901695 true
16911696 }
--- a/Scripts/gamess.rb
+++ b/Scripts/gamess.rb
@@ -158,23 +158,28 @@ class Molecule
158158 ncpus = 1
159159 end
160160
161- # Prepare the scratch directory in the home directory
162- # (Not in the document home to avoid space-containing path in Windows)
163- scrdir = $home_directory + "/Test Dir/Molby/gamess" # "Test Dir" for debug
161+ # Prepare the scratch directory
164162 begin
165- mkdir_recursive(scrdir)
163+ scrdir = create_temp_dir("gamess", inpbody)
166164 rescue
167- error_message_box("Cannot create directory #{scrdir}: " + $!.to_s)
165+ error_message_box($!.to_s)
168166 return
169167 end
168+# scrdir = $home_directory + "/Molby/gamess"
169+# begin
170+# mkdir_recursive(scrdir)
171+# rescue
172+# error_message_box("Cannot create directory #{scrdir}: " + $!.to_s)
173+# return
174+# end
170175
171- scrdir = scrdir + "/" + inpbody + "." + $$.to_s + ".0"
172- n = 0
173- while File.exist?(scrdir)
174- scrdir = scrdir.sub(".#{n}", ".#{n + 1}")
175- n += 1
176- end
177- Dir.mkdir(scrdir)
176+# scrdir = scrdir + "/" + inpbody + "." + $$.to_s + ".0"
177+# n = 0
178+# while File.exist?(scrdir)
179+# scrdir = scrdir.sub(".#{n}", ".#{n + 1}")
180+# n += 1
181+# end
182+# Dir.mkdir(scrdir)
178183
179184 if $platform == "win"
180185 sep = "\\"
@@ -196,7 +201,7 @@ class Molecule
196201 end
197202 uname = backquote("cmd.exe /c ver").to_s.gsub("\n", "")
198203 else
199- freebytes = `df -k #{scrdir}`
204+ freebytes = `df -k "#{scrdir}"`
200205 uname = `uname`.chomp
201206 end
202207
@@ -217,6 +222,7 @@ class Molecule
217222 scrbody = scrprefix
218223 end
219224 filecopy(inpname, scrprefix + ".F05")
225+ File.open("#{scrdir}/.in_use", "w") { |fp| }
220226
221227 # Prepare environmental variables
222228 auxdir = "#{gmsdir}#{sep}auxdata"
@@ -413,6 +419,9 @@ class Molecule
413419 icon = :error
414420 end
415421 msg += "\n(In directory #{inpdir})"
422+
423+ File.delete("#{scrdir}/.in_use")
424+
416425 ext_to_keep = [".dat", ".rst", ".trj", ".efp", ".gamma", ".log"]
417426 ext_to_keep.each { |ex|
418427 if File.exists?("#{scrprefix}#{ex}")
@@ -424,7 +433,13 @@ class Molecule
424433 File.delete("#{scrdir}#{sep}#{file}")
425434 end
426435 }
427- erase_old_logs(scrdir, "latest", 5)
436+
437+ begin
438+ erase_old_logs(scrdir, "latest", 5)
439+ rescue
440+ error_message_box($!.to_s)
441+ return
442+ end
428443 if mol != nil
429444 message_box(msg, hmsg, :ok, icon)
430445 end
@@ -493,13 +508,13 @@ class Molecule
493508 if $platform == "win"
494509 if gmsvers == "11"
495510 hosts = "localhost " * ncpus
496- cmdline = "cmd.exe /c \"#{gmsdir}/ddikick.exe #{gmsdir}/gamess.#{gmsvers}.exe #{inpbody} -ddi #{ncpus} #{ncpus} #{hosts} -scr \\\"#{scrdir}\\\" < NUL >>\\\"#{logname}\\\""
511+ cmdline = "cmd.exe /c \"#{gmsdir}/ddikick.exe #{gmsdir}/gamess.#{gmsvers}.exe #{inpbody} -ddi #{ncpus} #{ncpus} #{hosts} -scr #{scrdir} < NUL >>#{logname}"
497512 else
498- cmdline = "cmd.exe /c \"mpiexec -configfile \\\"#{procfil}\\\" >>\\\"#{logname}\\\""
513+ cmdline = "cmd.exe /c \"mpiexec -configfile #{procfil} >>#{logname}"
499514 end
500515 else
501516 hosts = "localhost " * ncpus
502- cmdline = "/bin/sh -c '\"#{gmsdir}/ddikick.x\" \"#{gmsdir}/gamess.#{gmsvers}.x\" #{inpbody} -ddi #{ncpus} #{ncpus} #{hosts} -scr \"#{scrdir}\" < /dev/null >>\"#{logname}\"'"
517+ cmdline = "/bin/sh -c '#{gmsdir}/ddikick.x #{gmsdir}/gamess.#{gmsvers}.x #{inpbody} -ddi #{ncpus} #{ncpus} #{hosts} -scr #{scrdir} < /dev/null >>#{logname}'"
503518 end
504519
505520 if mol
--- a/Scripts/md.rb
+++ b/Scripts/md.rb
@@ -235,10 +235,7 @@ class Molecule
235235 end
236236
237237 def ambertools_dialog(tool, msg = nil, block = nil)
238- log_dir = get_global_settings("antechamber.log_dir")
239- if !log_dir
240- log_dir = $home_directory + "/Molby/antechamber"
241- end
238+ log_dir = get_global_settings("global.scratch_dir") || ""
242239 if $platform == "win"
243240 suffix = ".exe"
244241 else
@@ -292,10 +289,10 @@ class Molecule
292289 -1,
293290 item(:line),
294291 -1,
295- item(:text, :title=>"Log directory:"),
292+ item(:text, :title=>"Scratch directory (default = home):"),
296293 [ item(:button, :title=>"Choose...",
297294 :action=>lambda { |it|
298- dir = Dialog.open_panel(nil, nil, nil, true)
295+ dir = ask_scratch_dir
299296 if dir
300297 set_value("log_dir", dir)
301298 end
@@ -326,6 +323,10 @@ class Molecule
326323 }
327324 hash.each_pair { |key, value|
328325 next if key == :status
326+ if key == "log_dir"
327+ set_global_settings("global.scratch_dir", value)
328+ next
329+ end
329330 v = [["log_none", "none"], ["log_error_only", "error_only"], ["log_keep_latest", "latest"], ["log_all", "all"]].assoc(key)
330331 if v
331332 next if value != 1
@@ -339,60 +340,72 @@ class Molecule
339340 return 1 - hash[:status] # 1: OK, 0: Cancel, -1: Skip
340341 end
341342
342- def create_ante_log_dir(name, key)
343- log_dir = get_global_settings("antechamber.log_dir")
344- msg = ""
345- begin
346- if !FileTest.directory?(log_dir)
347- mkdir_recursive(log_dir) rescue ((msg = "Cannot create directory #{log_dir}") && raise)
348- end
349- n = 1
350- while FileTest.exist?(dname = log_dir + "/#{name}_#{key}.#{n}")
351- n += 1
352- end
353- Dir.mkdir(dname) rescue ((msg = "Cannot create directory #{dname}") && raise)
354- return dname
355- rescue
356- error_message_box(msg + ": " + $!.to_s)
357- return
358- end
359- end
343+# def create_ante_log_dir(name, key)
344+# log_dir = get_global_settings("global.scratch_dir")
345+# if log_dir == nil || log_dir == ""
346+# log_dir = ask_scratch_dir
347+# if log_dir == nil
348+# error_message_box("Scratch directory is not set.")
349+# return nil
350+# end
351+# end
352+# log_dir = log_dir + "/Molby/antechamber"
353+# msg = ""
354+# begin
355+# if !FileTest.directory?(log_dir)
356+# mkdir_recursive(log_dir) rescue ((msg = "Cannot create directory #{log_dir}") && raise)
357+# end
358+# n = 1
359+# while FileTest.exist?(dname = log_dir + "/#{name}_#{key}.#{n}")
360+# n += 1
361+# end
362+# Dir.mkdir(dname) rescue ((msg = "Cannot create directory #{dname}") && raise)
363+# return dname
364+# rescue
365+# error_message_box(msg + ": " + $!.to_s)
366+# return
367+# end
368+# end
360369
361- def clean_ante_log_dir(nkeep)
362- def rm_recursive(f)
363- if FileTest.directory?(f)
364- Dir.entries(f).each { |file|
365- next if file == "." || file == ".."
366- rm_recursive(f + "/" + file)
367- }
368- Dir.rmdir(f)
369- else
370- File.delete(f)
371- end
372- end
373- log_dir = get_global_settings("antechamber.log_dir")
374- cwd = Dir.pwd
375- count = 0
376- begin
377- Dir.chdir(log_dir)
378- # Get subdirectories and sort by last modified time
379- dirs = Dir.entries(log_dir).reject! { |x|
380- !FileTest.directory?(x) || x == "." || x == ".."
381- }.sort_by { |x|
382- File.mtime(x)
383- }
384- dirs[0..-(nkeep + 1)].each { |d|
385- rm_recursive(d)
386- count += 1
387- }
388- rescue
389- error_message_box $!.to_s
390- Dir.chdir(cwd)
391- return
392- end
393- Dir.chdir(cwd)
394- return count
395- end
370+# def clean_ante_log_dir(nkeep)
371+# def rm_recursive(f)
372+# if FileTest.directory?(f)
373+# Dir.entries(f).each { |file|
374+# next if file == "." || file == ".."
375+# rm_recursive(f + "/" + file)
376+# }
377+# Dir.rmdir(f)
378+# else
379+# File.delete(f)
380+# end
381+# end
382+# log_dir = get_global_settings("global.scratch_dir")
383+# if log_dir == nil || log_dir == ""
384+# return
385+# end
386+# log_dir = log_dir + "/Molby/antechamber"
387+# cwd = Dir.pwd
388+# count = 0
389+# begin
390+# Dir.chdir(log_dir)
391+# # Get subdirectories and sort by last modified time
392+# dirs = Dir.entries(log_dir).reject! { |x|
393+# !FileTest.directory?(x) || x == "." || x == ".."
394+# }.sort_by { |x|
395+# File.mtime(x)
396+# }
397+# dirs[0..-(nkeep + 1)].each { |d|
398+# rm_recursive(d)
399+# count += 1
400+# }
401+# rescue
402+# error_message_box $!.to_s
403+# Dir.chdir(cwd)
404+# return
405+# end
406+# Dir.chdir(cwd)
407+# return count
408+# end
396409
397410 def invoke_antechamber(ask_options = true, msg = nil)
398411 # Find the ambertool directory
@@ -407,25 +420,13 @@ class Molecule
407420 guess_atom_types = get_global_settings("antechamber.guess_atom_types").to_i
408421 optimize_structure = get_global_settings("antechamber.optimize_structure").to_i
409422 use_residue = get_global_settings("antechamber.use_residue").to_i
423+
410424 # Create log directory
411425 name = (self.name || "unknown").sub(/\.\w*$/, "").sub(/\*/, "") # Remove the extension and "*"
412- log_dir = get_global_settings("antechamber.log_dir")
413- if log_dir == nil
414- log_dir = document_home + "/Molby/antechamber"
415- end
416- if !File.directory?(log_dir)
417- mkdir_recursive(log_dir)
418- end
419- tdir = nil
420- 1000.times { |i|
421- tdir = sprintf("%s/%s.%04d", log_dir, name, i)
422- if !File.exists?(tdir) && (Dir.mkdir(tdir) == 0)
423- break
424- end
425- tdir = nil
426- }
427- if tdir == nil
428- error_message_box("Cannot create log directory in #{log_dir}.")
426+ begin
427+ tdir = create_temp_dir("antechamber", name)
428+ rescue
429+ error_message_box($!.to_s)
429430 return -1
430431 end
431432 cwd = Dir.pwd
@@ -1261,8 +1262,13 @@ class Molecule
12611262 ante_dir = Molby::ResourcePath + "/amber11/bin"
12621263
12631264 # Create the temporary directory
1264- dname = create_ante_log_dir((self.path ? File.basename(self.path, ".*") : self.name), "rs")
1265- return unless dname
1265+ name = (self.name || "unknown").sub(/\.\w*$/, "").sub(/\*/, "") # Remove the extension and "*"
1266+ begin
1267+ dname = create_temp_dir("resp", name)
1268+ rescue
1269+ error_message_box($!.to_s)
1270+ return -1
1271+ end
12661272 cwd = Dir.pwd
12671273 Dir.chdir(dname)
12681274
@@ -1381,6 +1387,11 @@ class Molecule
13811387 end
13821388 }
13831389 Dir.chdir(cwd)
1390+
1391+ log_level = get_global_settings("antechamber.log_level")
1392+ log_keep_number = get_global_settings("antechamber.log_keep_number")
1393+ erase_old_logs(dname, log_level, log_keep_number)
1394+
13841395 return true
13851396 end
13861397
@@ -1427,9 +1438,6 @@ class Molecule
14271438 [item(:button, :title=>"Run RESP...", :tag=>"resp",
14281439 :action=>lambda { |it|
14291440 if mol.cmd_run_resp
1430- if get_global_settings("antechamber.log_level") == "latest"
1431- mol.clean_ante_log_dir(Integer(get_global_settings("antechamber.log_keep_number")))
1432- end
14331441 end_modal(0)
14341442 end
14351443 }),
--- a/Scripts/startup.rb
+++ b/Scripts/startup.rb
@@ -35,6 +35,24 @@ case RUBY_PLATFORM
3535 $home_directory = ENV['HOME']
3636 end
3737
38+sdir = get_global_settings("global.scratch_dir")
39+if sdir == nil || sdir == ""
40+ sdir = $home_directory
41+ if $platform == "win" && sdir =~ / /
42+ # Try 8.3 name
43+ tdir = ENV['TEMP']
44+ if tdir != nil
45+ sdir = tdir.gsub(/\\/, "/")
46+ end
47+ if sdir =~ /\/AppData\/Local\/Temp$/
48+ sdir = Regexp.last_match.pre_match
49+ end
50+ end
51+ if sdir !~ / /
52+ set_global_settings("global.scratch_dir", sdir)
53+ end
54+end
55+
3856 $backtrace = nil
3957
4058 def backtrace
@@ -103,18 +121,29 @@ module Kernel
103121 end
104122 end
105123 def create_temp_dir(tag, name = nil)
106- # Create a temporary directory like HomeDirectory/Molby/tag/name.xxxxxx
107- name ||= "temp"
108- base = $home_directory + "/Molby/" + tag
109- mkdir_recursive(base)
110- 10000.times { |n|
111- p = sprintf("%s/%s.%05d", base, name, n)
112- if !FileTest.exist?(p)
113- Dir.mkdir(p)
114- return p
124+ # Create a temporary directory like %scratch%/Molby/tag/name.xxxxxx
125+ base = get_global_settings("global.scratch_dir")
126+ if base == nil || base == ""
127+ base = ask_scratch_dir
128+ if base == nil
129+ raise "Scratch directory is not set."
115130 end
116- }
117- raise "Cannot create temporary directory in #{base}"
131+ end
132+ msg = nil
133+ name ||= "temp"
134+ base = base + "/Molby/" + tag
135+ begin
136+ mkdir_recursive(base) rescue ((msg = "Cannot create directory #{base}") && raise)
137+ 10000.times { |n|
138+ p = sprintf("%s/%s.%05d", base, name, n)
139+ if !FileTest.exist?(p)
140+ Dir.mkdir(p) rescue ((msg = "Cannot create directory #{p}") && raise)
141+ return p
142+ end
143+ }
144+ rescue
145+ raise "Cannot create temporary directory in #{base}"
146+ end
118147 end
119148 def rm_recursive(path)
120149 if FileTest.directory?(path)
@@ -127,39 +156,44 @@ module Kernel
127156 File.unlink(path)
128157 end
129158 end
130- def cleanup_temp_dir(path, option = nil)
159+# def cleanup_temp_dir(path, option = nil)
131160 # Clean-up temporary directories
132161 # If option is nil, then the directory at path is removed
133162 # If option is a number, then the directories that are in the same parent directory as path
134163 # are removed except for the newest ones
135- if path.index($home_directory + "/Molby/") != 0
136- raise "Bad cleanup_temp_dir call: the path does not begin with $HOME/Molby/ (#{path})"
137- end
138- if !FileTest.directory?(path)
139- raise "Bad cleanup_temp_dir call: the path is not a directory (#{path})"
140- end
141- option = option.to_i
142- if option <= 0
143- rm_recursive(path)
144- else
145- base = File.dirname(path)
146- ent = Dir.entries.sort_by { |en| File.mtime("#{base}/#{en}").to_i * (-1) } - [".", ".."]
147- if $platform == "mac"
148- ent -= [".DS_Store"]
149- end
150- ent[0, option] = [] # Remove newest #{option} entries
151- # Mark this directory to be ready to remove (see below)
152- open("#{path}/.done", "w") { |fp| }
153- # Remove the older directories
154- ent.each { |en|
155- # Check the existence of ".done" file (otherwise, we may accidentarily remove a directory
156- # that is still in use in other threads)
157- if File.exist?("#{base}/#{en}/.done")
158- rm_recursive("#{base}/#{en}")
159- end
160- }
161- end
162- end
164+# base = get_global_settings("global.scratch_dir")
165+# if base == nil || base == ""
166+# raise "Scratch directory is not set."
167+# end
168+# base = base + "/Molby/"
169+# if path.index(base) != 0
170+# raise "Bad cleanup_temp_dir call: the path is not a part of the scratch directory (#{path})"
171+# end
172+# if !FileTest.directory?(path)
173+# raise "Bad cleanup_temp_dir call: the path is not a directory (#{path})"
174+# end
175+# option = option.to_i
176+# if option <= 0
177+# rm_recursive(path)
178+# else
179+# base = File.dirname(path)
180+# ent = Dir.entries.sort_by { |en| File.mtime("#{base}/#{en}").to_i * (-1) } - [".", ".."]
181+# if $platform == "mac"
182+# ent -= [".DS_Store"]
183+# end
184+# ent[0, option] = [] # Remove newest #{option} entries
185+# # Mark this directory to be ready to remove (see below)
186+# open("#{path}/.done", "w") { |fp| }
187+# # Remove the older directories
188+# ent.each { |en|
189+# # Check the existence of ".done" file (otherwise, we may accidentarily remove a directory
190+# # that is still in use in other threads)
191+# if File.exist?("#{base}/#{en}/.done")
192+# rm_recursive("#{base}/#{en}")
193+# end
194+# }
195+# end
196+# end
163197
164198 def remove_dir(dir)
165199 entries = Dir.entries(dir)
@@ -175,8 +209,17 @@ module Kernel
175209 Dir.unlink(dir)
176210 end
177211
178- def erase_old_logs(tdir, level, keep_number)
212+ def erase_old_logs(tdir, level = nil, keep_number = 0)
179213 log_dir = File.dirname(tdir)
214+ base = get_global_settings("global.scratch_dir")
215+ if base == nil || base == ""
216+ raise "Scratch directory is not set."
217+ end
218+ base = base.gsub(/\\/, "/") + "/Molby/"
219+ tdir = tdir.gsub(/\\/, "/")
220+ if tdir.index(base) != 0
221+ raise "Bad erase_old_logs call: the path is not a part of the scratch directory (#{tdir}, #{base})"
222+ end
180223 if level == nil || level == "none"
181224 remove_dir(tdir)
182225 elsif level == "latest"
@@ -185,11 +228,18 @@ module Kernel
185228 else
186229 keep_number = keep_number.to_i
187230 end
188- entries = Dir.entries(log_dir).select { |en| en != "." && en != ".." && File.directory?("#{log_dir}/#{en}") }
189- # Sort by modification date
190- entries = entries.sort_by { |en| File.mtime("#{log_dir}/#{en}").to_i }
191- (0...entries.count - keep_number).each { |i|
192- remove_dir("#{log_dir}/#{entries[i]}")
231+ entries = Dir.entries(log_dir).sort_by { |en| File.mtime("#{log_dir}/#{en}").to_i * (-1) } - [".", ".."]
232+ if $platform == "mac"
233+ entries -= [".DS_Store"]
234+ end
235+ entries[0, keep_number] = [] # Remove newest #{keep_number} entries
236+ # Remove the older directories
237+ entries.each { |en|
238+ # Check the existence of ".in_use" file (otherwise, we may accidentarily remove a directory
239+ # that is still in use in other threads)
240+ if !File.exist?("#{log_dir}/#{en}/.in_use")
241+ rm_recursive("#{log_dir}/#{en}")
242+ end
193243 }
194244 end
195245 end
旧リポジトリブラウザで表示