From: toshinagata1964 Date: Sat, 9 Nov 2013 08:56:31 +0000 (+0000) Subject: 'Create MOPAC input' is implemented X-Git-Tag: v1.0.2~226 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=6651e4867ad0fd9261aba026c384ccc1642c5121;p=molby%2FMolby.git 'Create MOPAC input' is implemented git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@412 a2be9bc6-48de-4e38-9406-05402d4bc13c --- diff --git a/Scripts/gamess.rb b/Scripts/gamess.rb index f2a2120..f118fc2 100755 --- a/Scripts/gamess.rb +++ b/Scripts/gamess.rb @@ -395,6 +395,7 @@ class Molecule File.delete("#{scrdir}#{sep}#{file}") end } + erase_old_logs(scrdir, "latest", 5) message_box(msg, hmsg, :ok, icon) } diff --git a/Scripts/mopac6.rb b/Scripts/mopac6.rb index 7f5a87e..98ef5d6 100755 --- a/Scripts/mopac6.rb +++ b/Scripts/mopac6.rb @@ -15,7 +15,7 @@ class Molecule - # Execute mopac6 (inferior copy of rungms script) + # Execute mopac6 # inpname is the input file # mol (optional) is the molecule from which the MOPAC input was built. def Molecule.execute_mopac(inpname, mol = nil) @@ -23,6 +23,7 @@ class Molecule # MOPAC executable mopexe = "#{ResourcePath}/mopac/mopac606" + inpname = File.expand_path(inpname) inpbase = File.basename(inpname) inpdir = File.dirname(inpname) inpbody = inpbase.sub(/\.\w*$/, "") @@ -53,15 +54,23 @@ class Molecule cwd = Dir.pwd filecopy(inpname, scrdir + "/FOR005") term_callback = proc { |m, n| + if File.exist?("#{scrdir}/FOR006") + filecopy("#{scrdir}/FOR006", "#{inpdir}/#{inpbody}.out") + end + msg = "MOPAC execution on #{inpbase} " + hmsg = "MOPAC " if n == 0 - filecopy("#{scrdir}/FOR006", "#{cwd}/#{inpdir}/#{inpbody}.out"); + msg += "succeeded." + hmsg += "Completed" + icon = :info + else + msg += "failed with status #{n}." + hmsg += "Failed" + icon = :error end - Dir.foreach(scrdir) { |fn| - next if fn == "." || fn == ".." - File.delete("#{scrdir}/#{fn}") - } - Dir.chdir(cwd) - Dir.rmdir(scrdir) + msg += "\n(In directory #{inpdir})" + message_box(msg, hmsg, :ok, icon) + erase_old_logs(scrdir, "latest", 5) # Keep latest 5 logs } timer_callback = nil @@ -80,7 +89,86 @@ class Molecule end end - -end + + def create_mopac + if !@mopac_settings || (com = @mopac_settings["commands"]) == nil + com = " PM3" + (@mopac_settings ||= Hash.new)["commands"] = com + end + str = com + "\n" + str += sprintf("# %-76.76s\n", self.name) + str += sprintf("# %-76.76s\n", "Generated by Molby at #{Time.now.to_s}") + # Create geometry input + geom = "" + if self.natoms <= 3 + # Z-matrix + if self.natoms >= 1 + geom += atoms[0].element + "\n" + if self.natoms >= 2 + r = calc_bond(0, 1) + geom += sprintf("%s %.6f 1\n", atoms[1].element, r) + if self.natoms >= 3 + con = atoms[2].connects + if con.include?(0) + r = calc_bond(0, 2) + a = calc_angle(2, 0, 1) + c = "1 2" + else + r = calc_bond(1, 2) + a = calc_angle(2, 1, 0) + c = "2 1" + end + geom += sprintf("%s %.6f 1 %.3f 1 %s\n", atoms[2].element, r, a, c) + end + end + end + else + # Cartesian + atoms.each { |ap| + geom += sprintf("%s %.6f 1 %.6f 1 %.6f 1\n", ap.element, ap.x, ap.y, ap.z) + } + end + return str + geom + "\n" + end + + def cmd_create_mopac_input -Molecule.execute_mopac("test01.inp", nil) + mol = self + h = Dialog.run("Create MOPAC6 Input") { + layout(1, + item(:text, :title=>"MOPAC input"), + item(:textview, :width=>480, :height=>200, :tag=>"mopac_commands"), + layout(2, + item(:text, :title=>"Action: "), + item(:radio, :title=>"Save only", :tag=>"save_only", :value=>1), + -1, + item(:radio, :title=>"Save and Run MOPAC", :tag=>"save_and_run") + ) + ) + radio_group("save_only", "save_and_run") + item_with_tag("mopac_commands")[:value] = mol.create_mopac + } + # Record the command lines for next invocation + mop = h["mopac_commands"] + com = (mop.split(/[\r\n]/))[0..0].join("\n") + (@mopac_settings ||= Hash.new)["commands"] = com + if h[:status] == 0 + basename = (self.path ? File.basename(self.path, ".*") : self.name) + fname = Dialog.save_panel("Export MOPAC input file:", self.dir, basename + ".mopin", "MOPAC input file (*.mopin)|*.mopin|All files|*.*") + return nil if !fname + open(fname, "w") { |fp| + fp.write(mop) + } + if h["save_and_run"] == 1 + Molecule.execute_mopac(fname, self) + end + end + + end + +# if lookup_menu("Create MOPAC6 Input...") < 0 +# register_menu("", "") +# register_menu("Create MOPAC6 Input...", :cmd_create_mopac) +# end + +end diff --git a/Scripts/startup.rb b/Scripts/startup.rb index 9de72e2..6802dd3 100755 --- a/Scripts/startup.rb +++ b/Scripts/startup.rb @@ -82,5 +82,6 @@ load "md.rb" load "uff.rb" load "gamess.rb" load "crystal.rb" +load "mopac6.rb" GC.start diff --git a/wxSources/MyApp.cpp b/wxSources/MyApp.cpp index 18a532c..5f02b2e 100755 --- a/wxSources/MyApp.cpp +++ b/wxSources/MyApp.cpp @@ -471,6 +471,7 @@ MyApp::CreateMenuBar(int kind, wxMenu **out_file_history_menu, wxMenu **out_edit wxMenu *qc_menu = new wxMenu; qc_menu->Append(myMenuID_CreateGamessInput, _T("Create GAMESS input...")); + qc_menu->Append(myMenuID_CreateMOPACInput, _T("Create MOPAC input...")); qc_menu->Append(myMenuID_CreateMOCube, _T("Create MO cube...")); wxMenu *script_menu = new wxMenu; diff --git a/wxSources/MyApp.h b/wxSources/MyApp.h index c0c7a99..edd1e3a 100755 --- a/wxSources/MyApp.h +++ b/wxSources/MyApp.h @@ -105,7 +105,8 @@ enum { myMenuID_ImportAmberLib = 215, myMenuID_ImportAmberFrcmod = 216, myMenuID_CreateGamessInput = 250, - myMenuID_CreateMOCube = 251, + myMenuID_CreateMOPACInput = 251, + myMenuID_CreateMOCube = 252, myMenuID_ExecuteScript = 300, myMenuID_OpenConsoleWindow = 301, myMenuID_EmptyConsoleWindow = 302, diff --git a/wxSources/MyDocument.cpp b/wxSources/MyDocument.cpp index 58a9ebe..971417a 100755 --- a/wxSources/MyDocument.cpp +++ b/wxSources/MyDocument.cpp @@ -107,6 +107,7 @@ BEGIN_EVENT_TABLE(MyDocument, wxDocument) EVT_MENU(myMenuID_CreateSanderInput, MyDocument::OnCreateSanderInput) EVT_MENU(myMenuID_ImportAmberFrcmod, MyDocument::OnImportAmberFrcmod) EVT_MENU(myMenuID_CreateGamessInput, MyDocument::OnCreateGamessInput) + EVT_MENU(myMenuID_CreateMOPACInput, MyDocument::OnCreateMOPACInput) EVT_MENU(myMenuID_CreateMOCube, MyDocument::OnCreateMOCube) EVT_MENU(myMenuID_ShowAllAtoms, MyDocument::OnShowAllAtoms) EVT_MENU(myMenuID_HideReverse, MyDocument::OnHideReverse) @@ -1427,6 +1428,12 @@ MyDocument::OnCreateGamessInput(wxCommandEvent &event) } void +MyDocument::OnCreateMOPACInput(wxCommandEvent &event) +{ + MolActionCreateAndPerform(mol, SCRIPT_ACTION(""), "cmd_create_mopac_input"); +} + +void MyDocument::OnCreateMOCube(wxCommandEvent &event) { MolActionCreateAndPerform(mol, SCRIPT_ACTION(""), "cmd_create_cube"); @@ -1536,6 +1543,7 @@ MyDocument::OnUpdateUI(wxUpdateUIEvent& event) else event.Enable(false); return; case myMenuID_CreateGamessInput: + case myMenuID_CreateMOPACInput: if (mol != NULL && mol->natoms > 0) event.Enable(true); else event.Enable(false); diff --git a/wxSources/MyDocument.h b/wxSources/MyDocument.h index 2068ffa..81de81c 100755 --- a/wxSources/MyDocument.h +++ b/wxSources/MyDocument.h @@ -142,6 +142,7 @@ public: void OnImportAmberFrcmod(wxCommandEvent &event); void OnCreateGamessInput(wxCommandEvent &event); + void OnCreateMOPACInput(wxCommandEvent &event); void OnCreateMOCube(wxCommandEvent &event); void OnInsertFrameFromMD(wxCommandEvent &event);