4 # Created by Toshi Nagata on 2013/11/01.
5 # Copyright 2013 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 # Execute mopac6 (inferior copy of rungms script)
19 # inpname is the input file
20 # mol (optional) is the molecule from which the MOPAC input was built.
21 def Molecule.execute_mopac(inpname, mol = nil)
24 mopexe = "#{ResourcePath}/mopac/mopac606"
26 inpbase = File.basename(inpname)
27 inpdir = File.dirname(inpname)
28 inpbody = inpbase.sub(/\.\w*$/, "")
30 # Prepare the scratch directory in the home directory
31 scrdir = document_home.sub(/\/My Documents/, "") + "/mopac"
33 while File.exist?(scrdir) && !File.directory?(scrdir)
37 scrdir = scrdir.sub(".#{n}", ".#{n + 1}")
41 if !File.exist?(scrdir)
44 scrdir = scrdir + "/" + inpbody + "." + $$.to_s + ".0"
46 while File.exist?(scrdir)
47 scrdir = scrdir.sub(".#{n}", ".#{n + 1}")
52 # Copy the input file to the scratch directory
54 filecopy(inpname, scrdir + "/FOR005")
55 term_callback = proc { |m, n|
57 filecopy("#{scrdir}/FOR006", "#{cwd}/#{inpdir}/#{inpbody}.out");
59 Dir.foreach(scrdir) { |fn|
60 next if fn == "." || fn == ".."
61 File.delete("#{scrdir}/#{fn}")
71 pid = mol.call_subprocess_async(mopexe, term_callback, timer_callback, "NUL", "NUL")
73 pid = call_subprocess(mopexe, "Running MOPAC", nil, "NUL", "NUL")
74 term_callback.call(nil, pid)
78 error_message_box("MOPAC failed to run.")
86 Molecule.execute_mopac("test01.inp", nil)