• R/O
  • HTTP
  • SSH
  • HTTPS

Molby: コミット

Molecular Modeling Software


コミットメタ情報

リビジョンdef8983f0b362c00e7f9b015eb9af814afc3521a (tree)
日時2022-09-24 23:29:07
作者Toshi Nagata <alchemist.2005@nift...>
コミッターToshi Nagata

ログメッセージ

Psi4 import is improved (nalpha and nbeta are correctly imported, etc.)

変更サマリ

差分

--- a/Scripts/commands.rb
+++ b/Scripts/commands.rb
@@ -258,41 +258,71 @@ class Molecule
258258 end
259259
260260 def cmd_show_energy
261- wave = [0.0, 0.0]
262- cur = 0
263- mol = self
264- d = open_auxiliary_window("Energy", :resizable=>true, :has_close_box=>true) {
265- graph_item = nil # Forward declaration
266- target_mol = nil
267- draw_graph = lambda { |it|
268- clear
269- f = graph_item[:frame]
270- draw_rectangle(0, 0, f[2], f[3])
271- width = f[2] - 25
272- height = f[3] - 25
273- draw_line(16, 0, 16, height + 12, width + 20, height + 12)
274- xx = yy = nil
275- min = wave.min
276- h = wave.max - min
277- h = (h == 0.0 ? 1.0 : height / h)
278- w = wave.count
279- w = (w == 0 ? 1.0 : Float(width) / w)
280- a = []
281- wave.each_with_index { |d, i|
282- a.push(i * w + 16)
283- a.push(height - (d - min) * h + 12)
284- }
285- if wave.count == 1
286- a.push(w + 16)
287- a.push(height - (wave[0] - min) * h + 12)
288- end
289- draw_line(a)
290- brush(:color=>[0.2, 0.2, 1.0])
291- y = wave[cur] || 0.0
292- xx = cur * w + 16
293- yy = height - (y - min) * h + 12
294- draw_ellipse(cur * w + 16, height - (y - min) * h + 12, 6)
295- }
261+ wave = [0.0, 0.0]
262+ cur = 0
263+ mol = self
264+ wave_min = lambda { m = 1e8; wave.each { |x| if x != 0.0 && x < m; m = x; end }; m }
265+ wave_max = lambda { m = -1e8; wave.each { |x| if x != 0.0 && x > m; m = x; end }; m }
266+ d = open_auxiliary_window("Energy", :resizable=>true, :has_close_box=>true) {
267+ graph_item = nil # Forward declaration
268+ target_mol = nil
269+ draw_graph = lambda { |it|
270+ clear
271+ f = graph_item[:frame]
272+ draw_rectangle(0, 0, f[2], f[3])
273+ width = f[2] - 25
274+ height = f[3] - 25
275+ draw_line(16, 0, 16, height + 12, width + 20, height + 12)
276+ xx = yy = nil
277+ min = wave_min.call
278+ max = wave_max.call
279+ h = max - min
280+ h = (h == 0.0 ? 1.0 : height / h)
281+ w = wave.count
282+ w = (w == 0 ? 1.0 : Float(width) / w)
283+ lines = []
284+ a = []
285+ # Skip the points that have exactly 0.0 value
286+ wave.each_with_index { |d, i|
287+ if d != 0.0
288+ a.push(i * w + 16)
289+ a.push(height - (d - min) * h + 12)
290+ end
291+ if d == 0.0 || i == wave.length - 1
292+ # End of this curve fragment
293+ if a.length == 0
294+ # Do nothing
295+ else
296+ if a.length == 2
297+ if wave.count == 1
298+ # If wave has only one point, then draw a horizontal line
299+ a.push(a[0] + 16)
300+ a.push(a[1])
301+ else
302+ # Otherwise, draw a zero-length line
303+ a.push(a[0])
304+ a.push(a[1])
305+ end
306+ end
307+ lines.push(a) # Store this line fragment
308+ a = []
309+ end
310+ end
311+ }
312+ lines.each { |a|
313+ draw_line(a)
314+ }
315+ brush(:color=>[0.2, 0.2, 1.0])
316+ y = wave[cur] || 0.0
317+ if y < min
318+ y = min
319+ elsif y > max
320+ y = max
321+ end
322+ xx = cur * w + 16
323+ yy = height - (y - min) * h + 12
324+ draw_ellipse(cur * w + 16, height - (y - min) * h + 12, 6)
325+ }
296326 @on_document_modified = lambda { |m|
297327 cur = mol.frame
298328 wave.clear
--- a/Scripts/gamess.rb
+++ b/Scripts/gamess.rb
@@ -1219,11 +1219,11 @@ class Molecule
12191219 fp.close
12201220 user_input["charge"] = user_input["CONTRL"]["ICHARG"]
12211221 user_input["mult"] = user_input["CONTRL"]["MULT"]
1222- user_input["runtype"] = ((i = ["ENERGY", "PROP", "OPTIMIZE"].find_index(user_input["CONTRL"]["RUNTYP"])) ? i.to_s : nil)
1223- user_input["scftype"] = ((i = ["RHF", "ROHF", "UHF"].find_index(user_input["CONTRL"]["SCFTYP"])) ? i.to_s : nil)
1222+ user_input["runtype"] = ["ENERGY", "PROP", "OPTIMIZE"].find_index(user_input["CONTRL"]["RUNTYP"])
1223+ user_input["scftype"] = ["RHF", "ROHF", "UHF"].find_index(user_input["CONTRL"]["SCFTYP"])
12241224 dft_type = dft_internal.find_index(user_input["CONTRL"]["DFTTYP"])
12251225 if dft_type
1226- user_input["dfttype"] = dft_type.to_s
1226+ user_input["dfttype"] = dft_type
12271227 user_input["dft"] = 1
12281228 end
12291229 bssname = nil
@@ -1544,20 +1544,20 @@ class Molecule
15441544 now = Time.now.to_s
15451545 if fname
15461546 fp = File.open(fname, "wb")
1547- mname = File.basename(fname, ".*")
15481547 else
15491548 fp = MemoryIO.new
1550- mname = self.name
1551- if mname == nil || mname == ""
1552- mname = "mol"
1553- end
15541549 end
15551550 if fp
15561551 fp.print "# Psi4 input\n"
15571552 fp.print "# Generated by Molby at #{now}\n"
15581553 fp.print "import sys\n"
15591554 fp.print "import re\n"
1560- fp.print "molecule #{mname} {\n"
1555+ fp.print "molecule mol {\n"
1556+ charge = Integer(hash["charge"])
1557+ mult = Integer(hash["mult"])
1558+ if charge != 0 || mult != 1
1559+ fp.printf " %d %d\n", charge, mult
1560+ end
15611561 atoms.each { |ap|
15621562 fp.printf "%-8s %10.6f %10.6f %10.6f\n", ap.element, ap.x, ap.y, ap.z
15631563 }
@@ -1605,8 +1605,12 @@ class Molecule
16051605 end
16061606 Dir.chdir(inpdir)
16071607 cmdline = "psi4 #{inpbase}"
1608+ hf_type = nil
1609+ nalpha = nil
1610+ nbeta = nil
16081611
16091612 term_callback = lambda { |m, n|
1613+ begin
16101614 msg = "Psi4 execution of #{inpbase}"
16111615 hmsg = "Psi4 "
16121616 if n == 0
@@ -1626,6 +1630,9 @@ class Molecule
16261630 end
16271631 if n == 0
16281632 # Try to load molden file if available
1633+ mol.clear_basis_set
1634+ mol.clear_mo_coefficients
1635+ mol.set_mo_info(:type => hf_type, :alpha => nalpha, :beta => nbeta)
16291636 molden = inpdir + "/" + inpbody +".molden"
16301637 if File.exists?(molden)
16311638 fp = Kernel.open(molden, "rt")
@@ -1640,6 +1647,11 @@ class Molecule
16401647 end
16411648 end
16421649 end
1650+ rescue => e
1651+ print("#{e.message}\n")
1652+ print("#{e.backtrace.to_s}\n")
1653+ end
1654+ true
16431655 }
16441656
16451657 timer_count = 0
@@ -1726,6 +1738,10 @@ class Molecule
17261738 hf_type = "ROHF"
17271739 end
17281740 next_index = li
1741+ elsif line =~ /^ *Nalpha *= *(\d+)/
1742+ nalpha = Integer($1)
1743+ elsif line =~ /^ *Nbeta *= *(\d+)/
1744+ nbeta = Integer($1)
17291745 end
17301746 end
17311747 if next_index > 0
--- a/Scripts/loadsave.rb
+++ b/Scripts/loadsave.rb
@@ -520,7 +520,6 @@ class Molecule
520520 n = 0
521521 nf = 0
522522 energy = nil
523- hf_type = nil
524523
525524 show_progress_panel("Loading Psi4 output file...")
526525
@@ -531,6 +530,9 @@ class Molecule
531530 ats = []
532531 first_frame = nframes
533532 trans = nil
533+ hf_type = nil
534+ nalpha = nil
535+ nbeta = nil
534536 while line = getline.call
535537 if line =~ /==> Geometry <==/
536538 # Skip until line containing "------"
@@ -595,13 +597,20 @@ class Molecule
595597 elsif line =~ /ROHF/
596598 hf_type = "ROHF"
597599 end
600+ elsif line =~ /^ *Nalpha *= *(\d+)/
601+ nalpha = Integer($1)
602+ elsif line =~ /^ *Nbeta *= *(\d+)/
603+ nbeta = Integer($1)
598604 end
599605 end
600606 hide_progress_panel
601- @hf_type = hf_type
607+ clear_basis_set
608+ clear_mo_coefficients
609+ set_mo_info(:type => hf_type, :alpha => nalpha, :beta => nbeta)
602610 return true
603611 end
604612
613+ # mol.set_mo_info should be set before calling this function
605614 def sub_load_molden(fp)
606615 getline = lambda { @lineno += 1; return fp.gets }
607616 bohr = 0.529177210903
@@ -629,8 +638,6 @@ class Molecule
629638 break
630639 end
631640 end
632- clear_basis_set
633- clear_mo_coefficients
634641 redo # The next line will be the beginning of the next block
635642 elsif line =~ /^\[GTO\]/
636643 shell = 0
@@ -725,13 +732,6 @@ class Molecule
725732 end
726733 end # end while
727734 end # end catch
728- h = Hash.new
729- h[:alpha] = Integer(occ_alpha)
730- h[:beta] = Integer(occ_beta)
731- if @hf_type
732- h[:type] = @hf_type
733- end
734- set_mo_info(h)
735735 if errmsg
736736 message_box("The MOLDEN file was found but not imported. " + errmsg, "Psi4 import info", :ok)
737737 return false
旧リポジトリブラウザで表示