コード例 #1
0
ファイル: test_jobs.py プロジェクト: yimingchen-eng/custodian
 def test_OptFF(self):
     myjob = QCJob.opt_with_frequency_flattener(
         qchem_command="qchem -slurm",
         max_cores=32,
         input_file="mol.qin",
         output_file="mol.qout")
     expected_next = QCJob(qchem_command="qchem -slurm",
                           max_cores=32,
                           multimode="openmp",
                           input_file="mol.qin",
                           output_file="mol.qout",
                           suffix=".opt_0",
                           backup=True).as_dict()
     self.assertEqual(next(myjob).as_dict(), expected_next)
     expected_next = QCJob(qchem_command="qchem -slurm",
                           max_cores=32,
                           multimode="openmp",
                           input_file="mol.qin",
                           output_file="mol.qout",
                           suffix=".freq_0",
                           backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(), expected_next)
     self.assertEqual(
         QCInput.from_file(
             os.path.join(
                 test_dir,
                 "disconnected_but_converged/mol.qin.freq_0")).as_dict(),
         QCInput.from_file(os.path.join(scr_dir, "mol.qin")).as_dict())
     self.assertRaises(StopIteration, myjob.__next__)
コード例 #2
0
 def test_not_defaults(self):
     with patch("custodian.qchem.jobs.os.putenv") as putenv_patch:
         myjob = QCJob(qchem_command="qchem -slurm", multimode="mpi", input_file="different.qin", output_file="not_default.qout", max_cores=12, scratch_dir="/not/default/scratch/", backup=False)
         self.assertEqual(myjob.current_command, ["qchem", "-slurm", "-np", "12", "different.qin", "not_default.qout"])
         myjob.setup()
         self.assertEqual(putenv_patch.call_args_list[0][0][0], "QCSCRATCH")
         self.assertEqual(putenv_patch.call_args_list[0][0][1], "/not/default/scratch/")
コード例 #3
0
 def test_not_defaults(self):
     with patch("custodian.qchem.jobs.os.putenv") as putenv_patch:
         myjob = QCJob(qchem_command="qchem -slurm", multimode="mpi", input_file="different.qin", output_file="not_default.qout", max_cores=12, scratch_dir="/not/default/scratch/", backup=False)
         self.assertEqual(myjob.current_command, ["qchem", "-slurm", "-np", "12", "different.qin", "not_default.qout"])
         myjob.setup()
         self.assertEqual(putenv_patch.call_args_list[0][0][0], "QCSCRATCH")
         self.assertEqual(putenv_patch.call_args_list[0][0][1], "/not/default/scratch/")
コード例 #4
0
 def test_OptFF(self):
     myjob = QCJob.opt_with_frequency_flattener(
         qchem_command="qchem -slurm",
         max_cores=32,
         input_file="mol.qin",
         output_file="mol.qout",
         linked=True,
         transition_state=True,
         freq_before_opt=True,
     )
     expected_next = QCJob(
         qchem_command="qchem -slurm",
         max_cores=32,
         multimode="openmp",
         input_file="mol.qin",
         output_file="mol.qout",
         suffix=".freq_pre",
         save_scratch=True,
         backup=True,
     ).as_dict()
     self.assertEqual(next(myjob).as_dict(), expected_next)
     expected_next = QCJob(
         qchem_command="qchem -slurm",
         max_cores=32,
         multimode="openmp",
         input_file="mol.qin",
         output_file="mol.qout",
         suffix=".ts_0",
         save_scratch=True,
         backup=False,
     ).as_dict()
     self.assertEqual(next(myjob).as_dict(), expected_next)
     self.assertEqual(
         QCInput.from_file(os.path.join(test_dir, "fftsopt_freqfirst/mol.qin.ts_0")).as_dict(),
         QCInput.from_file(os.path.join(scr_dir, "mol.qin")).as_dict(),
     )
     shutil.copyfile(
         os.path.join(scr_dir, "mol.qin"),
         os.path.join(scr_dir, "mol.qin.ts_0"),
     )
     expected_next = QCJob(
         qchem_command="qchem -slurm",
         max_cores=32,
         multimode="openmp",
         input_file="mol.qin",
         output_file="mol.qout",
         suffix=".freq_0",
         save_scratch=True,
         backup=False,
     ).as_dict()
     self.assertEqual(next(myjob).as_dict(), expected_next)
     self.assertEqual(
         QCInput.from_file(os.path.join(test_dir, "fftsopt_freqfirst/mol.qin.freq_0")).as_dict(),
         QCInput.from_file(os.path.join(scr_dir, "mol.qin")).as_dict(),
     )
     shutil.copyfile(
         os.path.join(scr_dir, "mol.qin"),
         os.path.join(scr_dir, "mol.qin.freq_0"),
     )
     self.assertRaises(StopIteration, myjob.__next__)
コード例 #5
0
 def test_save_scratch(self):
     with patch("custodian.qchem.jobs.shutil.copy") as copy_patch:
         myjob = QCJob(qchem_command="qchem -slurm", max_cores=32, scratch_dir=os.getcwd(), save_scratch=True, save_name="freq_scratch")
         self.assertEqual(myjob.current_command, ' qchem -slurm -nt 32 mol.qin mol.qout freq_scratch')
         myjob.setup()
         self.assertEqual(copy_patch.call_args_list[0][0][0], "mol.qin")
         self.assertEqual(copy_patch.call_args_list[0][0][1], "mol.qin.orig")
         self.assertEqual(os.environ["QCSCRATCH"],os.getcwd())
         self.assertEqual(os.environ["QCTHREADS"],"32")
         self.assertEqual(os.environ["OMP_NUM_THREADS"],"32")
コード例 #6
0
 def test_defaults(self):
     with patch("custodian.qchem.jobs.shutil.copy") as copy_patch:
         myjob = QCJob(qchem_command="qchem", max_cores=32)
         self.assertEqual(myjob.current_command, "qchem -nt 32 mol.qin mol.qout scratch")
         myjob.setup()
         self.assertEqual(copy_patch.call_args_list[0][0][0], "mol.qin")
         self.assertEqual(copy_patch.call_args_list[0][0][1], "mol.qin.orig")
         self.assertEqual(os.environ["QCSCRATCH"], os.getcwd())
         self.assertEqual(os.environ["QCTHREADS"], "32")
         self.assertEqual(os.environ["OMP_NUM_THREADS"], "32")
コード例 #7
0
 def test_OptFF(self):
     myjob = QCJob.opt_with_frequency_flattener(qchem_command="qchem -slurm", input_file="mol.qin", output_file="mol.qout")
     expected_next = QCJob(
                     qchem_command="qchem -slurm",
                     multimode="openmp",
                     input_file="mol.qin",
                     output_file="mol.qout",
                     suffix=".opt_0",
                     backup=True).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertRaises(StopIteration,myjob.__next__)
コード例 #8
0
 def test_not_defaults(self):
     myjob = QCJob(
         qchem_command="qchem -slurm",
         multimode="mpi",
         input_file="different.qin",
         output_file="not_default.qout",
         max_cores=12,
         calc_loc="/not/default/",
         backup=False,
     )
     self.assertEqual(myjob.current_command, "qchem -slurm -np 12 different.qin not_default.qout scratch")
     myjob.setup()
     self.assertEqual(os.environ["QCSCRATCH"], os.getcwd())
     self.assertEqual(os.environ["QCLOCALSCR"], "/not/default/")
コード例 #9
0
 def test_defaults(self):
     with patch("custodian.qchem.jobs.os.putenv") as putenv_patch:
         with patch("custodian.qchem.jobs.shutil.copy") as copy_patch:
             myjob = QCJob(qchem_command="qchem")
             self.assertEqual(myjob.current_command, ["qchem", "-nt", "32", "mol.qin", "mol.qout"])
             myjob.setup()
             self.assertEqual(copy_patch.call_args_list[0][0][0], "mol.qin")
             self.assertEqual(copy_patch.call_args_list[0][0][1], "mol.qin.orig")
             self.assertEqual(putenv_patch.call_args_list[0][0][0], "QCSCRATCH")
             self.assertEqual(putenv_patch.call_args_list[0][0][1], "/dev/shm/qcscratch/")
             self.assertEqual(putenv_patch.call_args_list[1][0][0], "QCTHREADS")
             self.assertEqual(putenv_patch.call_args_list[1][0][1], "32")
             self.assertEqual(putenv_patch.call_args_list[2][0][0], "OMP_NUM_THREADS")
             self.assertEqual(putenv_patch.call_args_list[2][0][1], "32")
コード例 #10
0
 def test_defaults(self):
     with patch("custodian.qchem.jobs.os.putenv") as putenv_patch:
         with patch("custodian.qchem.jobs.shutil.copy") as copy_patch:
             myjob = QCJob(qchem_command="qchem", max_cores=32)
             self.assertEqual(myjob.current_command, ["qchem", "-nt", "32", "mol.qin", "mol.qout"])
             myjob.setup()
             self.assertEqual(copy_patch.call_args_list[0][0][0], "mol.qin")
             self.assertEqual(copy_patch.call_args_list[0][0][1], "mol.qin.orig")
             self.assertEqual(putenv_patch.call_args_list[0][0][0], "QCSCRATCH")
             self.assertEqual(putenv_patch.call_args_list[0][0][1], "/dev/shm/qcscratch/")
             self.assertEqual(putenv_patch.call_args_list[1][0][0], "QCTHREADS")
             self.assertEqual(putenv_patch.call_args_list[1][0][1], "32")
             self.assertEqual(putenv_patch.call_args_list[2][0][0], "OMP_NUM_THREADS")
             self.assertEqual(putenv_patch.call_args_list[2][0][1], "32")
コード例 #11
0
ファイル: test_run_calc.py プロジェクト: shimanek/atomate
 def test_RunQChemCustodian_using_fw_spec_defaults(self):
     with patch("atomate.qchem.firetasks.run_calc.Custodian"
                ) as custodian_patch:
         firetask = RunQChemCustodian(qchem_cmd=">>qchem_cmd<<",
                                      scratch_dir=">>scratch_dir<<",
                                      input_file=os.path.join(
                                          module_dir, "..", "..",
                                          "test_files", "co_qc.in"))
         firetask.run_task(
             fw_spec={
                 "_fw_env": {
                     "qchem_cmd": "qchem -slurm",
                     "scratch_dir": "/this/is/a/test"
                 }
             })
         custodian_patch.assert_called_once()
         self.assertEqual(
             custodian_patch.call_args[0][0][0].as_dict(),
             QChemErrorHandler(input_file=os.path.join(
                 module_dir, "..", "..", "test_files", "co_qc.in"),
                               output_file="mol.qout").as_dict())
         self.assertEqual(
             custodian_patch.call_args[0][1][0].as_dict(),
             QCJob(qchem_command="qchem -slurm",
                   multimode="openmp",
                   input_file=os.path.join(module_dir, "..", "..",
                                           "test_files", "co_qc.in"),
                   output_file="mol.qout",
                   scratch_dir="/this/is/a/test").as_dict())
         self.assertEqual(custodian_patch.call_args[1], {
             "max_errors": 5,
             "gzipped_output": True
         })
コード例 #12
0
 def test_RunQChemCustodian_basic_defaults(self):
     with patch("atomate.qchem.firetasks.run_calc.Custodian"
                ) as custodian_patch:
         firetask = RunQChemCustodian(
             qchem_cmd="qchem",
             input_file=os.path.join(module_dir, "..", "..", "test_files",
                                     "co_qc.in"),
             max_cores=32)
         firetask.run_task(fw_spec={})
         custodian_patch.assert_called_once()
         self.assertEqual(custodian_patch.call_args[0][0][0].as_dict(),
                          QChemErrorHandler(
                              input_file=os.path.join(
                                  module_dir, "..", "..", "test_files",
                                  "co_qc.in"),
                              output_file="mol.qout").as_dict())
         self.assertEqual(custodian_patch.call_args[0][1][0].as_dict(),
                          QCJob(
                              qchem_command="qchem",
                              max_cores=32,
                              multimode="openmp",
                              input_file=os.path.join(
                                  module_dir, "..", "..", "test_files",
                                  "co_qc.in"),
                              output_file="mol.qout").as_dict())
         self.assertEqual(custodian_patch.call_args[1], {
             "max_errors": 5,
             "gzipped_output": True
         })
コード例 #13
0
 def test_OptFF(self):
     myjob = QCJob.opt_with_frequency_flattener(qchem_command="qchem -slurm", max_cores=32, input_file="mol.qin", output_file="mol.qout")
     expected_next = QCJob(
                     qchem_command="qchem -slurm",
                     max_cores=32,
                     multimode="openmp",
                     input_file="mol.qin",
                     output_file="mol.qout",
                     suffix=".opt_0",
                     backup=True).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertRaises(StopIteration,myjob.__next__)
コード例 #14
0
 def test_RunQChemCustodian_using_fw_spec_not_defaults(self):
     with patch("atomate.qchem.firetasks.run_calc.Custodian"
                ) as custodian_patch:
         firetask = RunQChemCustodian(
             qchem_cmd=">>qchem_cmd<<",
             calc_loc=">>calc_loc<<",
             multimode=">>multimode<<",
             input_file=os.path.join(module_dir, "..", "..", "test_files",
                                     "co_qc.in"),
             output_file="this_is_a_test.qout",
             max_cores=4,
             qclog_file="this_is_a_test.qclog",
             suffix="bad_idea",
             save_scratch=True,
             max_errors=137,
             gzipped_output=False,
             handler_group="no_handler",
         )
         firetask.run_task(
             fw_spec={
                 "_fw_env": {
                     "qchem_cmd": "qchem -slurm",
                     "calc_loc": "/this/is/a/test",
                     "max_cores": 32,
                     "multimode": "mpi",
                 }
             })
         custodian_patch.assert_called_once()
         self.assertEqual(custodian_patch.call_args[0][0], [])
         self.assertEqual(
             custodian_patch.call_args[0][1][0].as_dict(),
             QCJob(
                 qchem_command="qchem -slurm",
                 calc_loc="/this/is/a/test",
                 multimode="mpi",
                 input_file=os.path.join(module_dir, "..", "..",
                                         "test_files", "co_qc.in"),
                 output_file="this_is_a_test.qout",
                 max_cores=4,
                 qclog_file="this_is_a_test.qclog",
                 suffix="bad_idea",
                 save_scratch=True,
             ).as_dict(),
         )
         self.assertEqual(
             custodian_patch.call_args[1],
             {
                 "max_errors": 137,
                 "gzipped_output": False
             },
         )
コード例 #15
0
 def test_OptFF(self):
     myjob = QCJob.opt_with_frequency_flattener(qchem_command="qchem", input_file="test.qin", output_file="test.qout")
     expected_next = QCJob(
                     qchem_command="qchem",
                     multimode="openmp",
                     input_file="test.qin",
                     output_file="test.qout",
                     suffix=".opt_0",
                     backup=True).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     expected_next = QCJob(
                     qchem_command="qchem",
                     multimode="openmp",
                     input_file="test.qin",
                     output_file="test.qout",
                     suffix=".freq_0",
                     backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertEqual(QCInput.from_file(os.path.join(test_dir,"FF_working/test.qin.freq_0")).as_dict(),QCInput.from_file(os.path.join(scr_dir,"test.qin")).as_dict())
     expected_next = QCJob(
                     qchem_command="qchem",
                     multimode="openmp",
                     input_file="test.qin",
                     output_file="test.qout",
                     suffix=".opt_1",
                     backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertEqual(QCInput.from_file(os.path.join(test_dir,"FF_working/test.qin.opt_1")).as_dict(),QCInput.from_file(os.path.join(scr_dir,"test.qin")).as_dict())
     expected_next = QCJob(
                     qchem_command="qchem",
                     multimode="openmp",
                     input_file="test.qin",
                     output_file="test.qout",
                     suffix=".freq_1",
                     backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertEqual(QCInput.from_file(os.path.join(test_dir,"FF_working/test.qin.freq_1")).as_dict(),QCInput.from_file(os.path.join(scr_dir,"test.qin")).as_dict())
     self.assertRaises(StopIteration,myjob.__next__)
コード例 #16
0
def run_QChem(label,
              encode=None,
              rem=None,
              pcm=None,
              solvent=None,
              more_info=None,
              self_correct=True):
    inname = label + '.inp'
    outname = label + '.out'
    logname = label + '.log'
    command = 'qchem'
    handlers = [QChemErrorHandler(input_file=inname, output_file=outname)]
    """If no encoding provided, assume this is the first Firework in workflow and that input file is already written.
    'label' is the name of the file without the extension (e.g. .inp, .out). otherwise, take encoding, 
    form new QCInput and write input file, then run.
    """
    if encode != None:
        qcin = encode_to_QCInput(encode=encode,
                                 rem=rem,
                                 pcm=pcm,
                                 solvent=solvent)
        qcin.write_file(inname)

    if self_correct:
        jobs = [
            QCJob(input_file=inname,
                  output_file=outname,
                  qchem_command=command,
                  max_cores=multiprocessing.cpu_count(),
                  qclog_file=logname)
        ]
        c = Custodian(handlers, jobs, max_errors=10)
        c.run()
    else:
        job = QCJob(input_file=inname,
                    output_file=outname,
                    qchem_command=command,
                    max_cores=multiprocessing.cpu_count(),
                    qclog_file=logname)
        job.setup()
        p = job.run()
        p.wait()
        """
        qclog = open(logname, "w")
        current_command = ['qchem', '-nt', '20',inname]
        print(current_command)
        subprocess.run(current_command, stdout=qclog, shell=True)
        """

    try:
        output = [QCOutput(filename=outname)]
    except:
        output = QCOutput.multiple_outputs_from_file(QCOutput, filename)
    return QCOutput_to_encode(output, more_info=more_info)
コード例 #17
0
 def test_OptFF(self):
     myjob = QCJob.opt_with_frequency_flattener(qchem_command="qchem", max_cores=32, input_file="test.qin", output_file="test.qout")
     expected_next = QCJob(
                     qchem_command="qchem",
                     max_cores=32,
                     multimode="openmp",
                     input_file="test.qin",
                     output_file="test.qout",
                     suffix=".opt_0",
                     backup=True).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     expected_next = QCJob(
                     qchem_command="qchem",
                     max_cores=32,
                     multimode="openmp",
                     input_file="test.qin",
                     output_file="test.qout",
                     suffix=".freq_0",
                     backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertEqual(QCInput.from_file(os.path.join(test_dir,"FF_working/test.qin.freq_0")).as_dict(),QCInput.from_file(os.path.join(scr_dir,"test.qin")).as_dict())
     expected_next = QCJob(
                     qchem_command="qchem",
                     max_cores=32,
                     multimode="openmp",
                     input_file="test.qin",
                     output_file="test.qout",
                     suffix=".opt_1",
                     backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertEqual(QCInput.from_file(os.path.join(test_dir,"FF_working/test.qin.opt_1")).as_dict(),QCInput.from_file(os.path.join(scr_dir,"test.qin")).as_dict())
     expected_next = QCJob(
                     qchem_command="qchem",
                     max_cores=32,
                     multimode="openmp",
                     input_file="test.qin",
                     output_file="test.qout",
                     suffix=".freq_1",
                     backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertEqual(QCInput.from_file(os.path.join(test_dir,"FF_working/test.qin.freq_1")).as_dict(),QCInput.from_file(os.path.join(scr_dir,"test.qin")).as_dict())
     self.assertRaises(StopIteration,myjob.__next__)
コード例 #18
0
    def run_task(self, fw_spec):

        # initialize variables
        qchem_cmd = env_chk(self["qchem_cmd"], fw_spec)
        multimode = env_chk(self.get("multimode"), fw_spec)
        if multimode == None:
            multimode = "openmp"
        input_file = self.get("input_file", "mol.qin")
        output_file = self.get("output_file", "mol.qout")
        max_cores = env_chk(self["max_cores"], fw_spec)
        qclog_file = self.get("qclog_file", "mol.qclog")
        suffix = self.get("suffix", "")
        scratch_dir = env_chk(self.get("scratch_dir"), fw_spec)
        if scratch_dir == None:
            scratch_dir = "/dev/shm/qcscratch/"
        save_scratch = self.get("save_scratch", False)
        save_name = self.get("save_name", "saved_scratch")
        max_errors = self.get("max_errors", 5)
        max_iterations = self.get("max_iterations", 10)
        linked = self.get("linked", False)
        max_molecule_perturb_scale = self.get("max_molecule_perturb_scale",
                                              0.3)
        job_type = self.get("job_type", "normal")
        gzipped_output = self.get("gzipped_output", True)

        handler_groups = {
            "default": [
                QChemErrorHandler(input_file=input_file,
                                  output_file=output_file)
            ],
            "no_handler": []
        }

        # construct jobs
        if job_type == "normal":
            jobs = [
                QCJob(qchem_command=qchem_cmd,
                      max_cores=max_cores,
                      multimode=multimode,
                      input_file=input_file,
                      output_file=output_file,
                      qclog_file=qclog_file,
                      suffix=suffix,
                      scratch_dir=scratch_dir,
                      save_scratch=save_scratch,
                      save_name=save_name)
            ]
        elif job_type == "opt_with_frequency_flattener":
            if linked:
                jobs = QCJob.opt_with_frequency_flattener(
                    qchem_command=qchem_cmd,
                    multimode=multimode,
                    input_file=input_file,
                    output_file=output_file,
                    qclog_file=qclog_file,
                    max_iterations=max_iterations,
                    linked=linked,
                    max_cores=max_cores)
            else:
                jobs = QCJob.opt_with_frequency_flattener(
                    qchem_command=qchem_cmd,
                    multimode=multimode,
                    input_file=input_file,
                    output_file=output_file,
                    qclog_file=qclog_file,
                    max_iterations=max_iterations,
                    linked=linked,
                    max_molecule_perturb_scale=max_molecule_perturb_scale,
                    scratch_dir=scratch_dir,
                    save_scratch=save_scratch,
                    save_name=save_name,
                    max_cores=max_cores)

        else:
            raise ValueError("Unsupported job type: {}".format(job_type))

        # construct handlers
        handlers = handler_groups[self.get("handler_group", "default")]

        c = Custodian(handlers,
                      jobs,
                      max_errors=max_errors,
                      gzipped_output=gzipped_output)

        c.run()
コード例 #19
0
ファイル: test_cust.py プロジェクト: samblau/atomate
from custodian import Custodian
from custodian.qchem.jobs import QCJob
from custodian.qchem.handlers import QChemErrorHandler

my_input = "mol.qin"
my_output = "mol.qout"

myjob = QCJob(qchem_command="qchem -slurm",multimode="openmp",input_file=my_input,output_file=my_output,max_cores=12)
myhandler = QChemErrorHandler(input_file=my_input,output_file=my_output)

c = Custodian([myhandler],[myjob],max_errors_per_job=10,max_errors=10)

c.run()

コード例 #20
0
 def test_not_defaults(self):
     myjob = QCJob(qchem_command="qchem -slurm", multimode="mpi", input_file="different.qin", output_file="not_default.qout", max_cores=12, scratch_dir="/not/default/scratch/", backup=False)
     self.assertEqual(myjob.current_command, ' qchem -slurm -np 12 different.qin not_default.qout')
     myjob.setup()
     self.assertEqual(os.environ["QCSCRATCH"],"/not/default/scratch/")
コード例 #21
0
ファイル: run_calc.py プロジェクト: yiwang62/atomate
    def run_task(self, fw_spec):

        # initialize variables
        qchem_cmd = env_chk(self["qchem_cmd"], fw_spec)
        multimode = env_chk(self.get("multimode"), fw_spec)
        if multimode == None:
            multimode = "openmp"
        """
        Note that I'm considering hardcoding openmp in the future
        because there is basically no reason anyone should ever run
        QChem on multiple nodes, aka with multimode = mpi.
        """
        input_file = self.get("input_file", "mol.qin")
        output_file = self.get("output_file", "mol.qout")
        max_cores = env_chk(self["max_cores"], fw_spec)
        qclog_file = self.get("qclog_file", "mol.qclog")
        suffix = self.get("suffix", "")
        calc_loc = env_chk(self.get("calc_loc"), fw_spec)
        save_scratch = self.get("save_scratch", False)
        max_errors = self.get("max_errors", 5)
        max_iterations = self.get("max_iterations", 10)
        linked = self.get("linked", True)
        backup = self.get("backup", True)
        max_molecule_perturb_scale = self.get("max_molecule_perturb_scale",
                                              0.3)
        job_type = self.get("job_type", "normal")
        gzipped_output = self.get("gzipped_output", True)

        handler_groups = {
            "default": [
                QChemErrorHandler(input_file=input_file,
                                  output_file=output_file)
            ],
            "no_handler": []
        }

        # construct jobs
        if job_type == "normal":
            jobs = [
                QCJob(qchem_command=qchem_cmd,
                      max_cores=max_cores,
                      multimode=multimode,
                      input_file=input_file,
                      output_file=output_file,
                      qclog_file=qclog_file,
                      suffix=suffix,
                      calc_loc=calc_loc,
                      save_scratch=save_scratch,
                      backup=backup)
            ]
        elif job_type == "opt_with_frequency_flattener":
            if linked:
                jobs = QCJob.opt_with_frequency_flattener(
                    qchem_command=qchem_cmd,
                    multimode=multimode,
                    input_file=input_file,
                    output_file=output_file,
                    qclog_file=qclog_file,
                    max_iterations=max_iterations,
                    linked=linked,
                    save_final_scratch=save_scratch,
                    max_cores=max_cores,
                    calc_loc=calc_loc)
            else:
                jobs = QCJob.opt_with_frequency_flattener(
                    qchem_command=qchem_cmd,
                    multimode=multimode,
                    input_file=input_file,
                    output_file=output_file,
                    qclog_file=qclog_file,
                    max_iterations=max_iterations,
                    max_molecule_perturb_scale=max_molecule_perturb_scale,
                    linked=linked,
                    save_final_scratch=save_scratch,
                    max_cores=max_cores,
                    calc_loc=calc_loc)

        else:
            raise ValueError("Unsupported job type: {}".format(job_type))

        # construct handlers
        handlers = handler_groups[self.get("handler_group", "default")]

        c = Custodian(handlers,
                      jobs,
                      max_errors=max_errors,
                      gzipped_output=gzipped_output)

        c.run()
コード例 #22
0
 def test_OptFF(self):
     myjob = QCJob.opt_with_frequency_flattener(qchem_command="qchem -slurm", max_cores=32,input_file="mol.qin", output_file="mol.qout", linked=True)
     expected_next = QCJob(
                     qchem_command="qchem -slurm",
                     max_cores=32,
                     multimode="openmp",
                     input_file="mol.qin",
                     output_file="mol.qout",
                     suffix=".opt_0",
                     scratch_dir=os.getcwd(),
                     save_scratch=True,
                     save_name="chain_scratch",
                     backup=True).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     expected_next = QCJob(
                     qchem_command="qchem -slurm",
                     max_cores=32,
                     multimode="openmp",
                     input_file="mol.qin",
                     output_file="mol.qout",
                     suffix=".freq_0",
                     scratch_dir=os.getcwd(),
                     save_scratch=True,
                     save_name="chain_scratch",
                     backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertEqual(QCInput.from_file(os.path.join(test_dir,"small_neg_freq/mol.qin.freq_0")).as_dict(),QCInput.from_file(os.path.join(scr_dir,"mol.qin")).as_dict())
     expected_next = QCJob(
                     qchem_command="qchem -slurm",
                     max_cores=32,
                     multimode="openmp",
                     input_file="mol.qin",
                     output_file="mol.qout",
                     suffix=".opt_1",
                     scratch_dir=os.getcwd(),
                     save_scratch=True,
                     save_name="chain_scratch",
                     backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertEqual(QCInput.from_file(os.path.join(test_dir,"small_neg_freq/mol.qin.opt_1")).as_dict(),QCInput.from_file(os.path.join(scr_dir,"mol.qin")).as_dict())
     expected_next = QCJob(
                     qchem_command="qchem -slurm",
                     max_cores=32,
                     multimode="openmp",
                     input_file="mol.qin",
                     output_file="mol.qout",
                     suffix=".freq_1",
                     scratch_dir=os.getcwd(),
                     save_scratch=True,
                     save_name="chain_scratch",
                     backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertEqual(QCInput.from_file(os.path.join(test_dir,"small_neg_freq/mol.qin.freq_1")).as_dict(),QCInput.from_file(os.path.join(scr_dir,"mol.qin")).as_dict())
     expected_next = QCJob(
                     qchem_command="qchem -slurm",
                     max_cores=32,
                     multimode="openmp",
                     input_file="mol.qin",
                     output_file="mol.qout",
                     suffix=".opt_2",
                     scratch_dir=os.getcwd(),
                     save_scratch=True,
                     save_name="chain_scratch",
                     backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertEqual(QCInput.from_file(os.path.join(test_dir,"small_neg_freq/mol.qin.opt_2")).as_dict(),QCInput.from_file(os.path.join(scr_dir,"mol.qin")).as_dict())
     expected_next = QCJob(
                     qchem_command="qchem -slurm",
                     max_cores=32,
                     multimode="openmp",
                     input_file="mol.qin",
                     output_file="mol.qout",
                     suffix=".freq_2",
                     scratch_dir=os.getcwd(),
                     save_scratch=True,
                     save_name="chain_scratch",
                     backup=False).as_dict()
     self.assertEqual(next(myjob).as_dict(),expected_next)
     self.assertEqual(QCInput.from_file(os.path.join(test_dir,"small_neg_freq/mol.qin.freq_2")).as_dict(),QCInput.from_file(os.path.join(scr_dir,"mol.qin")).as_dict())
     self.assertRaises(StopIteration,myjob.__next__)
コード例 #23
0
from custodian import Custodian
from custodian.qchem.jobs import QCJob
from custodian.qchem.handlers import QChemErrorHandler

my_input = "test.qin"
my_output = "test.qout"

myjob = QCJob.opt_with_frequency_flattener(qchem_command="qchem -slurm",multimode="openmp",input_file=my_input,output_file=my_output,max_iterations=10,max_molecule_perturb_scale=0.3,max_cores=12)
myhandler = QChemErrorHandler(input_file=my_input,output_file=my_output)

c = Custodian([myhandler],myjob,max_errors_per_job=10,max_errors=10)

c.run()

コード例 #24
0
ファイル: run_calc.py プロジェクト: montoyjh/MatMethods
    def run_task(self, fw_spec):

        # initialize variables
        qchem_cmd = env_chk(self["qchem_cmd"], fw_spec)
        multimode = env_chk(self.get("multimode"), fw_spec)
        if multimode == None:
            multimode = "openmp"
        input_file = self.get("input_file", "mol.qin")
        output_file = self.get("output_file", "mol.qout")
        max_cores = env_chk(self["max_cores"], fw_spec)
        qclog_file = self.get("qclog_file", "mol.qclog")
        suffix = self.get("suffix", "")
        scratch_dir = env_chk(self.get("scratch_dir"), fw_spec)
        if scratch_dir == None:
            scratch_dir = "/dev/shm/qcscratch/"
        save_scratch = self.get("save_scratch", False)
        save_name = self.get("save_name", "default_save_name")
        max_errors = self.get("max_errors", 5)
        max_iterations = self.get("max_iterations", 10)
        max_molecule_perturb_scale = self.get("max_molecule_perturb_scale",
                                              0.3)
        job_type = self.get("job_type", "normal")
        gzipped_output = self.get("gzipped_output", True)

        handler_groups = {
            "default": [
                QChemErrorHandler(
                    input_file=input_file, output_file=output_file)
            ],
            "no_handler": []
        }

        # construct jobs
        if job_type == "normal":
            jobs = [
                QCJob(
                    qchem_command=qchem_cmd,
                    max_cores=max_cores,
                    multimode=multimode,
                    input_file=input_file,
                    output_file=output_file,
                    qclog_file=qclog_file,
                    suffix=suffix,
                    scratch_dir=scratch_dir,
                    save_scratch=save_scratch,
                    save_name=save_name)
            ]
        elif job_type == "opt_with_frequency_flattener":
            jobs = QCJob.opt_with_frequency_flattener(
                qchem_command=qchem_cmd,
                multimode=multimode,
                input_file=input_file,
                output_file=output_file,
                qclog_file=qclog_file,
                max_iterations=max_iterations,
                max_molecule_perturb_scale=max_molecule_perturb_scale,
                scratch_dir=scratch_dir,
                save_scratch=save_scratch,
                save_name=save_name,
                max_cores=max_cores)

        else:
            raise ValueError("Unsupported job type: {}".format(job_type))

        # construct handlers
        handlers = handler_groups[self.get("handler_group", "default")]

        c = Custodian(
            handlers,
            jobs,
            max_errors=max_errors,
            gzipped_output=gzipped_output)

        c.run()
コード例 #25
0
 def test_OptFF(self):
     myjob = QCJob.opt_with_frequency_flattener(
         qchem_command="qchem -slurm",
         max_cores=32,
         input_file="mol.qin",
         output_file="mol.qout",
         linked=False,
     )
     expected_next = QCJob(
         qchem_command="qchem -slurm",
         max_cores=32,
         multimode="openmp",
         input_file="mol.qin",
         output_file="mol.qout",
         suffix=".opt_0",
         backup=True,
     ).as_dict()
     self.assertEqual(next(myjob).as_dict(), expected_next)
     expected_next = QCJob(
         qchem_command="qchem -slurm",
         max_cores=32,
         multimode="openmp",
         input_file="mol.qin",
         output_file="mol.qout",
         suffix=".freq_0",
         backup=False,
     ).as_dict()
     self.assertEqual(next(myjob).as_dict(), expected_next)
     self.assertEqual(
         QCInput.from_file(os.path.join(test_dir, "5690_frag18/mol.qin.freq_0")).as_dict(),
         QCInput.from_file(os.path.join(scr_dir, "mol.qin")).as_dict(),
     )
     expected_next = QCJob(
         qchem_command="qchem -slurm",
         max_cores=32,
         multimode="openmp",
         input_file="mol.qin",
         output_file="mol.qout",
         suffix=".opt_1",
         backup=False,
     ).as_dict()
     self.assertEqual(next(myjob).as_dict(), expected_next)
     self.assertEqual(
         QCInput.from_file(os.path.join(test_dir, "5690_frag18/mol.qin.opt_1")).as_dict(),
         QCInput.from_file(os.path.join(scr_dir, "mol.qin")).as_dict(),
     )
     expected_next = QCJob(
         qchem_command="qchem -slurm",
         max_cores=32,
         multimode="openmp",
         input_file="mol.qin",
         output_file="mol.qout",
         suffix=".freq_1",
         backup=False,
     ).as_dict()
     self.assertEqual(next(myjob).as_dict(), expected_next)
     self.assertEqual(
         QCInput.from_file(os.path.join(test_dir, "5690_frag18/mol.qin.freq_1")).as_dict(),
         QCInput.from_file(os.path.join(scr_dir, "mol.qin")).as_dict(),
     )
     expected_next = QCJob(
         qchem_command="qchem -slurm",
         max_cores=32,
         multimode="openmp",
         input_file="mol.qin",
         output_file="mol.qout",
         suffix=".opt_2",
         backup=False,
     ).as_dict()
     self.assertEqual(next(myjob).as_dict(), expected_next)
     self.assertEqual(
         QCInput.from_file(os.path.join(test_dir, "5690_frag18/mol.qin.opt_2")).as_dict(),
         QCInput.from_file(os.path.join(scr_dir, "mol.qin")).as_dict(),
     )
     expected_next = QCJob(
         qchem_command="qchem -slurm",
         max_cores=32,
         multimode="openmp",
         input_file="mol.qin",
         output_file="mol.qout",
         suffix=".freq_2",
         backup=False,
     ).as_dict()
     self.assertEqual(next(myjob).as_dict(), expected_next)
     self.assertEqual(
         QCInput.from_file(os.path.join(test_dir, "5690_frag18/mol.qin.freq_2")).as_dict(),
         QCInput.from_file(os.path.join(scr_dir, "mol.qin")).as_dict(),
     )
     self.assertRaises(Exception, myjob.__next__)