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)
# MOPAC executable
mopexe = "#{ResourcePath}/mopac/mopac606"
+ inpname = File.expand_path(inpname)
inpbase = File.basename(inpname)
inpdir = File.dirname(inpname)
inpbody = inpbase.sub(/\.\w*$/, "")
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
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
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)
}
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");
else event.Enable(false);
return;
case myMenuID_CreateGamessInput:
+ case myMenuID_CreateMOPACInput:
if (mol != NULL && mol->natoms > 0)
event.Enable(true);
else event.Enable(false);