Exemplo n.º 1
0
 def run_mopac(self, mol):
     cur_dir = os.getcwd()
     all_errors = set()
     energy = 0.0
     with tempfile.TemporaryDirectory() as scratch_dir:
         order_text = ["st", "nd", "th"]
         title = "Salt Alignment {}{} Calculation".format(
             self.run_number,
             order_text[self.run_number - 1 if self.run_number < 3 else 2])
         self.run_number += 1
         mop = MopTask(mol, self.total_charge, "opt", title, "PM7",
                       {"CYCLES": 2000})
         mop.write_file("mol.mop")
         job = MopacJob(backup=False)
         handler = MopacErrorHandler()
         c = Custodian(handlers=[handler], jobs=[job], max_errors=50)
         custodian_out = c.run()
         mopout = MopOutput("mol.out")
         final_pmg_mol = mopout.data["molecules"][-1]
         final_ob_mol = BabelMolAdaptor(final_pmg_mol)._obmol
         energy = Energy(mopout.data["energies"][-1][-1], "eV").to("Ha")
         if energy < self.global_best_energy:
             self.global_best_energy = energy
             shutil.copy("mol.out", os.path.join(cur_dir, "best_mol.out"))
         for run in custodian_out:
             for correction in run['corrections']:
                 all_errors.update(correction['errors'])
         if len(all_errors) > 0:
             out_error_logs_file = os.path.join(cur_dir,
                                                "out_error_logs.txt")
             bak_cmd = "cat {} >> {}".format("mol.out", out_error_logs_file)
             os.system(bak_cmd)
     return energy, final_ob_mol
Exemplo n.º 2
0
 def check(self):
     self.outdata = MopOutput(self.output_file).data
     self.mopinp = MopTask.from_file(self.input_file)
     self.errors = None
     if self.outdata["has_error"]:
         self.errors = self.outdata["errors"]
         return True
     return False
Exemplo n.º 3
0
    def test_parse_structures(self):
        moo = MopOutput(os.path.join(test_dir, "ch3cl_ef.out"))
        ans_mol1 = """Molecule Summary (H9 C4 N1 O3)
Reduced Formula: H9C4NO3
Charge = 0, Spin Mult = 1
Sites (17)
1 C    -1.500500     1.510500    -0.753900
2 C    -2.618000     0.880700     0.073000
3 C    -3.572900     1.988900     0.611400
4 H    -4.132700     2.465100    -0.227600
5 O    -2.857300     3.085300     1.127500
6 H    -2.369800     2.782000     1.884000
7 C    -4.534800     1.408600     1.645800
8 H    -5.165800     0.626600     1.204800
9 H    -5.200800     2.185700     2.043700
10 H    -4.003400     0.963000     2.498200
11 N    -3.390800    -0.115500    -0.704200
12 O    -1.498900     1.782200    -1.940900
13 O    -0.358100     1.767200    -0.079200
14 H    -2.169800     0.329600     0.939000
15 H    -2.775300    -0.817100    -1.055900
16 H    -3.863300     0.327900    -1.464000
17 H     0.271500     2.195900    -0.650900"""
        self.assertEqual(ans_mol1, str(moo.data["molecules"][0]))
        ans_mol2 = """Molecule Summary (H9 C4 N1 O3)
Reduced Formula: H9C4NO3
Charge = 0, Spin Mult = 1
Sites (17)
1 C    -1.517682     1.490044    -0.707280
2 C    -2.693150     0.817317    -0.013378
3 C    -3.626038     1.922600     0.582224
4 H    -4.351657     2.287764    -0.183361
5 O    -2.880302     3.079022     0.858364
6 H    -2.121236     2.897494     1.451907
7 C    -4.328070     1.419830     1.836240
8 H    -4.915870     0.516629     1.620984
9 H    -5.016872     2.181694     2.224643
10 H    -3.625366     1.180514     2.640740
11 N    -3.473778    -0.006085    -0.940194
12 O    -1.354202     1.649287    -1.885729
13 O    -0.581079     1.866540     0.201170
14 H    -2.306531     0.161269     0.812776
15 H    -2.960140    -0.811422    -1.264447
16 H    -3.793316     0.519019    -1.743723
17 H     0.183750     2.356539    -0.192487"""
        self.assertEqual(ans_mol2, str(moo.data["molecules"][1]))
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser(
        description="Convert a MOPAC output file to an XYZ file")
    parser.add_argument("-i",
                        "--moo",
                        dest="moo_file",
                        type=str,
                        required=True,
                        help="the MOPAC output file")
    parser.add_argument("-o",
                        "--xyz",
                        dest="xyz_file",
                        type=str,
                        required=True,
                        help="The XYZ file to write to")
    options = parser.parse_args()
    moo = MopOutput(options.moo_file)
    moo.data["molecules"][-1].to("xyz", options.xyz_file)
Exemplo n.º 5
0
 def test_not_accurate_enough(self):
     moo = MopOutput(os.path.join(test_dir, "not_accurate_enough.out"))
     self.assertTrue(moo.data["has_error"])
     self.assertEqual(moo.data["errors"], ['Not Accurate Enough'])
Exemplo n.º 6
0
 def test_scf_failed(self):
     moo = MopOutput(os.path.join(test_dir, "quino_salt_scf_failed.out"))
     self.assertTrue(moo.data["has_error"])
     self.assertTrue(moo.data["errors"], ['Bad SCF convergence'])
Exemplo n.º 7
0
 def test_geom_opt_failed(self):
     moo = MopOutput(os.path.join(test_dir, "quino_salt_geom_failed.out"))
     self.assertTrue(moo.data["has_error"])
     self.assertTrue(moo.data["errors"], ['Geometry optimization failed'])
Exemplo n.º 8
0
 def test_energies(self):
     moo = MopOutput(os.path.join(test_dir, "ch3cl_ef.out"))
     self.assertAlmostEqual(moo.data["energies"][0][1], -6.34798632251, 3)
     self.assertAlmostEqual(moo.data["energies"][1][1], -1685.76391, 3)
Exemplo n.º 9
0
 def test_successful_message(self):
     moo = MopOutput(os.path.join(test_dir, "ch3cl_ef.out"))
     self.assertFalse(moo.data["has_error"])
     self.assertEqual(moo.data["jobtype"], "OPT")
     self.assertTrue(moo.data["gracefully_terminated"])