def _verify_inputs(self): user_qin = QCInput.from_file(os.path.join(os.getcwd(), "mol.qin")) # Check mol.qin ref_qin = QCInput.from_file(os.path.join(self["ref_dir"], "mol.qin")) np.testing.assert_equal(ref_qin.molecule.species, user_qin.molecule.species) np.testing.assert_allclose( ref_qin.molecule.cart_coords, user_qin.molecule.cart_coords, atol=0.0001) for key in ref_qin.rem: if user_qin.rem.get(key) != ref_qin.rem.get(key): raise ValueError("Rem key {} is inconsistent!".format(key)) if ref_qin.opt is not None: for key in ref_qin.opt: if user_qin.opt.get(key) != ref_qin.opt.get(key): raise ValueError("Opt key {} is inconsistent!".format(key)) if ref_qin.pcm is not None: for key in ref_qin.pcm: if user_qin.pcm.get(key) != ref_qin.pcm.get(key): raise ValueError("PCM key {} is inconsistent!".format(key)) if ref_qin.solvent is not None: for key in ref_qin.solvent: if user_qin.solvent.get(key) != ref_qin.solvent.get(key): raise ValueError( "Solvent key {} is inconsistent!".format(key)) logger.info("RunQChemFake: verified input successfully")
def _check_equivalent_inputs(self, input1, input2): self.assertEqual( QCInput.from_file(input1).molecule, QCInput.from_file(input2).molecule) self.assertEqual( QCInput.from_file(input1).rem, QCInput.from_file(input2).rem)
def test_write_input(self): mol = self.co_mol rem = {"job_type": "opt", "basis": "6-311++G*", "max_scf_cycles": 200, "method": "wB97X-V", "geom_opt_max_cycles": 200} qc_input = QCInput(mol, rem) ft = WriteInput({"qc_input": qc_input}) ft.run_task({}) test_dict = QCInput.from_file("mol.qin").as_dict() for k, v in self.co_opt_ref_in.as_dict().items(): self.assertEqual(v, test_dict[k])
def setUpClass(cls): co_species = ["C", "O"] co_coords = [[0.0, 0.0, 0.0], [1.3, 0.0, 0.0]] cls.co_mol = Molecule(co_species, co_coords) cls.co_opt_ref_in = QCInput.from_file( os.path.join(module_dir, "..", "..", "test_files", "co_qc.in")) cls.opt_mol_ref_in = QCInput.from_file( os.path.join(module_dir, "..", "..", "test_files", "to_opt.qin")) cls.opt_mol = cls.opt_mol_ref_in.molecule cls.opt_mol_pcm_ref_in = QCInput.from_file( os.path.join(module_dir, "..", "..", "test_files", "to_opt_pcm.qin"))
def test_full_init(self): test_molecule = QCInput.from_file( os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule test_DictSet = QChemDictSet( molecule=test_molecule, job_type='opt', basis_set='6-31g*', scf_algorithm='diis', dft_rung=1, pcm_dielectric=10.0, max_scf_cycles=35) self.assertEqual( test_DictSet.rem, { 'job_type': 'opt', 'gen_scfman': 'true', 'basis': '6-31g*', 'max_scf_cycles': 35, 'exchange': 'b3lyp', 'geom_opt_max_cycles': 200, 'scf_algorithm': 'diis', 'solvent_method': 'pcm' }) self.assertEqual( test_DictSet.pcm, { 'heavypoints': '194', 'hpoints': '194', 'radii': 'uff', 'theory': 'cpcm', 'vdwscale': '1.1' }) self.assertEqual(test_DictSet.solvent, {'dielectric': 10.0}) self.assertEqual(test_DictSet.molecule, test_molecule)
def test_read_only_rem(self): str_rem = """Trying to break you! $rem job_type opt method wB97M-V basis def2-QZVPPD max_scf_cycles 300 gen_scfman = true $end $pcm heavypoints 194 hpoints 194 radii uff theory cpcm vdwscale 1.1 $end $solvent dielectric 10.0 $end """ rem_test = QCInput.read_rem(str_rem) rem_actual = { "job_type": "opt", "method": "wB97M-V", "basis": "def2-QZVPPD", "max_scf_cycles": "300", "gen_scfman": "true" } self.assertDictEqual(rem_actual, rem_test)
def test_opt_template(self): opt_params = OrderedDict({ "CONSTRAINT": ["tors 2 3 4 5 25.0", "bend 2 1 4 110.0"], "FIXED": ["x y 2 4 5"], "DUMMY": ["M 2 3 4 5"], "CONNECT": ["4 3 2 3 5 6"] }) opt_test = QCInput.opt_template(opt_params) opt_actual = """$opt CONSTRAINT tors 2 3 4 5 25.0 bend 2 1 4 110.0 ENDCONSTRAINT FIXED x y 2 4 5 ENDFIXED DUMMY M 2 3 4 5 ENDDUMMY CONNECT 4 3 2 3 5 6 ENDCONNECT $end""" self.assertEqual(opt_actual, opt_test)
def test__str__(self): species = ["C", "O"] coords = [[-9.5782000000, 0.6241500000, 0.0000000000], [-7.5827400000, 0.5127000000, -0.0000000000]] molecule = Molecule(species=species, coords=coords) rem = OrderedDict({ "jobtype": "opt", "method": "wB97M-V", "basis": "def2-QZVPPD", "max_scf_cycles": "300", "gen_scfman": "true" }) str_test = QCInput(molecule=molecule, rem=rem).__str__() str_actual = """$molecule 0 1 C -9.5782000000 0.6241500000 0.0000000000 O -7.5827400000 0.5127000000 -0.0000000000 $end $rem jobtype = opt method = wB97M-V basis = def2-QZVPPD max_scf_cycles = 300 gen_scfman = true $end """ self.assertEqual(str_actual, str_test)
def test_read_opt(self): str_opt = """$opt CONSTRAINT tors 2 3 4 5 25.0 bend 2 1 4 110.0 ENDCONSTRAINT FIXED x y 2 4 5 ENDFIXED DUMMY M 2 3 4 5 ENDDUMMY CONNECT 4 3 2 3 5 6 ENDCONNECT $end""" opt_test = QCInput.read_opt(str_opt) opt_actual = { "CONSTRAINT": ["tors 2 3 4 5 25.0", "bend 2 1 4 110.0"], "FIXED": ["x y 2 4 5"], "DUMMY": ["M 2 3 4 5"], "CONNECT": ["4 3 2 3 5 6"] } self.assertDictEqual(opt_actual, opt_test)
def process_qchem_multirun(dir_name, input_files, output_files): """ Process a QChem run which is known to include multiple calculations in a single input/output pair. """ if len(input_files) != 1: raise ValueError( "ERROR: The drone can only process a directory containing a single input/output pair when each include multiple calculations." ) else: for key in input_files: to_return = [] qchem_input_file = os.path.join(dir_name, input_files.get(key)) qchem_output_file = os.path.join(dir_name, output_files.get(key)) multi_out = QCOutput.multiple_outputs_from_file( QCOutput, qchem_output_file, keep_sub_files=False) multi_in = QCInput.from_multi_jobs_file(qchem_input_file) for ii, out in enumerate(multi_out): d = out.data d["input"] = {} d["input"]["molecule"] = multi_in[ii].molecule d["input"]["rem"] = multi_in[ii].rem d["input"]["opt"] = multi_in[ii].opt d["input"]["pcm"] = multi_in[ii].pcm d["input"]["solvent"] = multi_in[ii].solvent d["task"] = {"type": key, "name": "calc" + str(ii)} to_return.append(d) return to_return
def test_read_only_rem(self): str_rem = """Trying to break you! $rem job_type opt method wb97m-v basis def2-qzvppd max_scf_cycles 300 gen_scfman = true $end $pcm heavypoints 194 hpoints 194 radii uff theory cpcm vdwscale 1.1 $end $solvent dielectric 10.0 $end """ rem_test = QCInput.read_rem(str_rem) rem_actual = { "job_type": "opt", "method": "wb97m-v", "basis": "def2-qzvppd", "max_scf_cycles": "300", "gen_scfman": "true" } self.assertDictEqual(rem_actual, rem_test)
def test_double_FF_opt(self): # location of test files test_double_FF_files = os.path.join(module_dir, "..", "..", "test_files", "double_FF_wf") # define starting molecule and workflow object initial_qcin = QCInput.from_file( os.path.join(test_double_FF_files, "block", "launcher_first", "mol.qin.opt_0")) initial_mol = initial_qcin.molecule real_wf = get_wf_double_FF_opt( molecule=initial_mol, pcm_dielectric=10.0, max_cores=32, qchem_input_params={ "basis_set": "6-311++g**", "overwrite_inputs": { "rem": { "sym_ignore": "true" } } }) # use powerup to replace run with fake run ref_dirs = { "first_FF_no_pcm": os.path.join(test_double_FF_files, "block", "launcher_first"), "second_FF_with_pcm": os.path.join(test_double_FF_files, "block", "launcher_second") } fake_wf = use_fake_qchem(real_wf, ref_dirs) self.lp.add_wf(fake_wf) rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) wf_test = self.lp.get_wf_by_fw_id(1) self.assertTrue( all([s == "COMPLETED" for s in wf_test.fw_states.values()])) first_FF = self.get_task_collection().find_one({ "task_label": "first_FF_no_pcm" }) self.assertEqual(first_FF["calcs_reversed"][0]["input"]["solvent"], None) self.assertEqual(first_FF["num_frequencies_flattened"], 1) first_FF_final_mol = Molecule.from_dict( first_FF["output"]["optimized_molecule"]) second_FF = self.get_task_collection().find_one({ "task_label": "second_FF_with_pcm" }) self.assertEqual(second_FF["calcs_reversed"][0]["input"]["solvent"], {"dielectric": "10.0"}) self.assertEqual(second_FF["num_frequencies_flattened"], 1) second_FF_initial_mol = Molecule.from_dict( second_FF["input"]["initial_molecule"]) self.assertEqual(first_FF_final_mol, second_FF_initial_mol)
def setUpClass(cls): co_species = ['C', 'O'] co_coords = [[0.0, 0.0, 0.0], [1.3, 0.0, 0.0]] cls.co_mol = Molecule(co_species, co_coords) cls.co_opt_ref_in = QCInput.from_file( os.path.join(module_dir, "..", "..", "test_files", "co_qc.in"))
def test_read_opt(self): str_opt = """$opt CONSTRAINT tors 2 3 4 5 25.0 bend 2 1 4 110.0 ENDCONSTRAINT FIXED x y 2 4 5 ENDFIXED DUMMY M 2 3 4 5 ENDDUMMY CONNECT 4 3 2 3 5 6 ENDCONNECT $end""" opt_test = QCInput.read_opt(str_opt) opt_actual = OrderedDict({ "CONSTRAINT": ["tors 2 3 4 5 25.0", "bend 2 1 4 110.0"], "FIXED": ["x y 2 4 5"], "DUMMY": ["M 2 3 4 5"], "CONNECT": ["4 3 2 3 5 6"] }) self.assertDictEqual(opt_actual, opt_test)
def test_parse_pass_rotate_write(self): input_file = "pt_gs_wb97mv_tz_initial.in" output_file = "pt_gs_wb97mv_tz_initial_1_job.out" calc_dir = os.path.join(module_dir, "..", "..", "test_files") p_task = QChemToDb(calc_dir=calc_dir, input_file=input_file, output_file=output_file, db_file=">>db_file<<") fw1 = Firework([p_task]) atom_indexes = [6, 8, 9, 10] angle = 90.0 rot_task = RotateTorsion(atom_indexes=atom_indexes, angle=angle) w_task = WriteInputFromIOSet(qchem_input_set="OptSet", write_to_dir=module_dir) fw2 = Firework([rot_task, w_task], parents=fw1) wf = Workflow([fw1, fw2]) self.lp.add_wf(wf) rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) test_mol = QCInput.from_file(os.path.join(module_dir, "mol.qin")).molecule act_mol = Molecule.from_file( os.path.join(module_dir, "..", "..", "test_files", "pt_rotated_90.0.xyz")) np.testing.assert_equal(act_mol.species, test_mol.species) np.testing.assert_allclose(act_mol.cart_coords, test_mol.cart_coords, atol=0.0001)
def test_pcm_init(self): test_molecule = QCInput.from_file( os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule test_SPSet = SinglePointSet( molecule=test_molecule, pcm_dielectric=10.0) self.assertEqual( test_SPSet.rem, { 'job_type': 'sp', 'gen_scfman': 'true', 'basis': '6-311++g*', 'max_scf_cycles': 200, 'method': 'wb97xd', 'scf_algorithm': 'diis', 'solvent_method': 'pcm' }) self.assertEqual( test_SPSet.pcm, { 'heavypoints': '194', 'hpoints': '194', 'radii': 'uff', 'theory': 'cpcm', 'vdwscale': '1.1' }) self.assertEqual(test_SPSet.solvent, {'dielectric': 10.0}) self.assertEqual(test_SPSet.molecule, test_molecule)
def test_pcm_init(self): test_molecule = QCInput.from_file( os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule test_SPSet = SinglePointSet(molecule=test_molecule, pcm_dielectric=10.0) self.assertEqual( test_SPSet.rem, { 'job_type': 'sp', 'gen_scfman': 'true', 'basis': '6-311++g*', 'max_scf_cycles': 200, 'method': 'wb97xd', 'scf_algorithm': 'diis', 'solvent_method': 'pcm' }) self.assertEqual( test_SPSet.pcm, { 'heavypoints': '194', 'hpoints': '194', 'radii': 'uff', 'theory': 'cpcm', 'vdwscale': '1.1' }) self.assertEqual(test_SPSet.solvent, {'dielectric': 10.0}) self.assertEqual(test_SPSet.molecule, test_molecule)
def test_full_init(self): test_molecule = QCInput.from_file( os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule test_DictSet = QChemDictSet(molecule=test_molecule, job_type='opt', basis_set='6-31g*', scf_algorithm='diis', dft_rung=1, pcm_dielectric=10.0, max_scf_cycles=35) self.assertEqual( test_DictSet.rem, { 'job_type': 'opt', 'gen_scfman': 'true', 'basis': '6-31g*', 'max_scf_cycles': 35, 'exchange': 'b3lyp', 'geom_opt_max_cycles': 200, 'scf_algorithm': 'diis', 'solvent_method': 'pcm' }) self.assertEqual( test_DictSet.pcm, { 'heavypoints': '194', 'hpoints': '194', 'radii': 'uff', 'theory': 'cpcm', 'vdwscale': '1.1' }) self.assertEqual(test_DictSet.solvent, {'dielectric': 10.0}) self.assertEqual(test_DictSet.molecule, test_molecule)
def test_pcm_template(self): pcm_params = {"theory": "cpcm"} pcm_test = QCInput.pcm_template(pcm_params) pcm_actual = """$pcm theory cpcm $end""" self.assertEqual(pcm_actual, pcm_test)
def test_solvent_template(self): solvent_params = {"dielectric": "5.0"} solvent_test = QCInput.solvent_template(solvent_params) solvent_actual = """$solvent dielectric 5.0 $end""" self.assertEqual(solvent_actual, solvent_test)
def test_pcm_template(self): pcm_params = {"theory": "cpcm"} pcm_test = QCInput.pcm_template(pcm_params) pcm_actual = """$pcm theory = cpcm $end""" self.assertEqual(pcm_actual, pcm_test)
def test_write_input_from_io_set_diff_mol(self): ft = WriteInputFromIOSet( molecule=self.opt_mol, qchem_input_set="OptSet") ft.run_task({}) test_dict = QCInput.from_file("mol.qin").as_dict() for k, v in self.opt_mol_ref_in.as_dict().items(): self.assertEqual(v, test_dict[k])
def test_parse_pass_write(self): input_file = "test.qin.opt_1" output_file = "test.qout.opt_1" calc_dir = os.path.join(module_dir, "..", "..", "test_files", "FF_working") p_task = QChemToDb(calc_dir=calc_dir, input_file=input_file, output_file=output_file, db_file=">>db_file<<") fw1 = Firework([p_task]) w_task = WriteInputFromIOSet(qchem_input_set="OptSet", write_to_dir=module_dir) fw2 = Firework([w_task], parents=fw1) wf = Workflow([fw1, fw2]) self.lp.add_wf(wf) rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) test_mol = QCInput.from_file(os.path.join(module_dir, "mol.qin")).molecule np.testing.assert_equal(self.act_mol.species, test_mol.species) np.testing.assert_equal(self.act_mol.cart_coords, test_mol.cart_coords)
def test_solvent_template(self): solvent_params = {"dielectric": "5.0"} solvent_test = QCInput.solvent_template(solvent_params) solvent_actual = """$solvent dielectric = 5.0 $end""" self.assertEqual(solvent_actual, solvent_test)
def test_write_input(self): mol = self.co_mol rem = { "job_type": "opt", "basis": "6-311++G*", "max_scf_cycles": 200, "method": "wB97xd", "geom_opt_max_cycles": 200, "gen_scfman": True, "scf_algorithm": "diis" } qc_input = QCInput(mol, rem) ft = WriteInput(qc_input=qc_input) ft.run_task({}) test_dict = QCInput.from_file("mol.qin").as_dict() for k, v in self.co_opt_ref_in.as_dict().items(): self.assertEqual(v, test_dict[k])
def test_from_multi_jobs_file(self): job_list_test = QCInput.from_multi_jobs_file( os.path.join(test_dir, "pt_n2_wb97mv_0.0.in")) species = [ "S", "C", "H", "C", "H", "C", "H", "C", "C", "C", "H", "C", "H", "C", "H", "S" ] coords = [[-0.00250959, -0.05817469, -0.02921636], [1.70755408, -0.03033788, -0.01382912], [2.24317221, -0.05215019, 0.92026728], [2.21976393, 0.01718014, -1.27293235], [3.27786220, 0.04082146, -1.48539646], [1.20867399, 0.04478540, -2.27007793], [1.40292257, 0.10591684, -3.33110912], [-0.05341046, 0.01577217, -1.74839343], [-1.32843436, 0.03545064, -2.45531187], [-1.55195156, 0.08743920, -3.80184635], [-0.75245172, 0.10267657, -4.52817967], [-2.93293778, 0.08408786, -4.13352169], [-3.31125108, 0.11340328, -5.14405819], [-3.73173288, 0.02741365, -3.03412864], [-4.80776535, 0.00535688, -2.99564645], [-2.81590978, -0.00516172, -1.58990580]] molecule_1_actual = Molecule(species, coords) rem_1_actual = { "job_type": "opt", "method": "wb97m-v", "basis": "def2-tzvppd", "gen_scfman": "true", "geom_opt_max_cycles": "75", "max_scf_cycles": "300", "scf_algorithm": "diis", "scf_guess": "sad", "sym_ignore": "true", "symmetry": "false", "thresh": "14" } opt_1_actual = {"CONSTRAINT": ["tors 6 8 9 10 0.0"]} self.assertEqual(molecule_1_actual, job_list_test[0].molecule) self.assertEqual(rem_1_actual, job_list_test[0].rem) self.assertEqual(opt_1_actual, job_list_test[0].opt) molecule_2_actual = "read" rem_2_actual = { "job_type": "sp", "method": "wb97m-v", "basis": "def2-tzvppd", "gen_scfman": "true", "geom_opt_max_cycles": "75", "max_scf_cycles": "300", "scf_algorithm": "diis", "scf_guess": "read", "sym_ignore": "true", "symmetry": "false", "thresh": "14" } self.assertEqual(molecule_2_actual, job_list_test[1].molecule) self.assertEqual(rem_2_actual, job_list_test[1].rem)
def test_read_bad_solvent(self): str_solvent = """Once again, I'm trying to break you! $solvent dielectric = 5.0 $end""" solvent_test = QCInput.read_solvent(str_solvent) solvent_actual = {} self.assertDictEqual(solvent_actual, solvent_test)
def test_from_multi_jobs_file(self): job_list_test = QCInput.from_multi_jobs_file( os.path.join(test_dir, "pt_n2_wb97mv_0.0.in")) species = ["S", "C", "H", "C", "H", "C", "H", "C", "C", "C", "H", "C", "H", "C", "H", "S"] coords = [[-0.00250959, -0.05817469, -0.02921636], [1.70755408, -0.03033788, -0.01382912], [2.24317221, -0.05215019, 0.92026728], [2.21976393, 0.01718014, -1.27293235], [3.27786220, 0.04082146, -1.48539646], [1.20867399, 0.04478540, -2.27007793], [1.40292257, 0.10591684, -3.33110912], [-0.05341046, 0.01577217, -1.74839343], [-1.32843436, 0.03545064, -2.45531187], [-1.55195156, 0.08743920, -3.80184635], [-0.75245172, 0.10267657, -4.52817967], [-2.93293778, 0.08408786, -4.13352169], [-3.31125108, 0.11340328, -5.14405819], [-3.73173288, 0.02741365, -3.03412864], [-4.80776535, 0.00535688, -2.99564645], [-2.81590978, -0.00516172, -1.58990580]] molecule_1_actual = Molecule(species, coords) rem_1_actual = { "job_type": "opt", "method": "wb97m-v", "basis": "def2-tzvppd", "gen_scfman": "true", "geom_opt_max_cycles": "75", "max_scf_cycles": "300", "scf_algorithm": "diis", "scf_guess": "sad", "sym_ignore": "true", "symmetry": "false", "thresh": "14" } opt_1_actual = {"CONSTRAINT": ["tors 6 8 9 10 0.0"]} self.assertEqual(molecule_1_actual, job_list_test[0].molecule) self.assertEqual(rem_1_actual, job_list_test[0].rem) self.assertEqual(opt_1_actual, job_list_test[0].opt) molecule_2_actual = "read" rem_2_actual = { "job_type": "sp", "method": "wb97m-v", "basis": "def2-tzvppd", "gen_scfman": "true", "geom_opt_max_cycles": "75", "max_scf_cycles": "300", "scf_algorithm": "diis", "scf_guess": "read", "sym_ignore": "true", "symmetry": "false", "thresh": "14" } self.assertEqual(molecule_2_actual, job_list_test[1].molecule) self.assertEqual(rem_2_actual, job_list_test[1].rem)
def test_write_input_from_io_set_write_dir(self): ft = WriteInputFromIOSet( molecule=self.co_mol, qchem_input_set="OptSet", write_to_dir=module_dir) ft.run_task({}) test_dict = QCInput.from_file(os.path.join(module_dir, "mol.qin")).as_dict() for k, v in self.co_opt_ref_in.as_dict().items(): self.assertEqual(v, test_dict[k])
def test_read_bad_pcm(self): str_pcm = """I'm once again trying to break you! $pcm theory = cpcm radii = uff vdwscale = 1.1 $end""" pcm_test = QCInput.read_pcm(str_pcm) pcm_actual = {} self.assertDictEqual(pcm_actual, pcm_test)
def test_read_pcm(self): str_pcm = """I'm once again trying to break you! $pcm theory cpcm radii uff vdwscale 1.1 $end""" pcm_test = QCInput.read_pcm(str_pcm) pcm_actual = {"theory": "cpcm", "radii": "uff", "vdwscale": "1.1"} self.assertDictEqual(pcm_actual, pcm_test)
def test_read_molecule(self): str_molecule = """$molecule 0 1 C -9.5782000000 0.6241500000 0.0000000000 O -7.5827400000 0.5127000000 -0.0000000000 $end""" molecule_test = QCInput.read_molecule(str_molecule) species = ["C", "O"] coords = [[-9.5782000000, 0.6241500000, 0.0000000000], [-7.5827400000, 0.5127000000, -0.0000000000]] molecule_actual = Molecule(species, coords) self.assertEqual(molecule_actual, molecule_test)
def test_molecule_template(self): species = ["C", "O"] coords = [[-9.5782000000, 0.6241500000, 0.0000000000], [-7.5827400000, 0.5127000000, -0.0000000000]] mol = Molecule(species=species, coords=coords) molecule_test = QCInput.molecule_template(mol) molecule_actual = """$molecule 0 1 C -9.5782000000 0.6241500000 0.0000000000 O -7.5827400000 0.5127000000 -0.0000000000 $end""" self.assertEqual(molecule_actual, molecule_test)
def test_init(self): test_molecule = QCInput.from_file( os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule test_FreqSet = FreqSet(molecule=test_molecule) self.assertEqual( test_FreqSet.rem, { 'job_type': 'freq', 'basis': '6-311++G*', 'max_scf_cycles': 200, 'method': 'wB97X-V' }) self.assertEqual(test_FreqSet.pcm, {}) self.assertEqual(test_FreqSet.solvent, {}) self.assertEqual(test_FreqSet.molecule, test_molecule)
def test_rem_template(self): rem_params = { "job_type": "opt", "method": "wb97m-v", "basis": "def2-qzvppd", "max_scf_cycles": 300, "gen_scfman": "true" } rem_test = QCInput.rem_template(rem_params).split("\n") rem_actual_list = ["$rem", " job_type = opt", " method = wb97m-v", " basis = def2-qzvppd", " max_scf_cycles = 300", " gen_scfman = true", "$end"] for i_rem in rem_actual_list: self.assertIn(i_rem, rem_test)
def test_read_pcm(self): str_pcm = """I'm once again trying to break you! $pcm theory cpcm radii uff vdwscale 1.1 $end""" pcm_test = QCInput.read_pcm(str_pcm) pcm_actual = { "theory": "cpcm", "radii": "uff", "vdwscale": "1.1" } self.assertDictEqual(pcm_actual, pcm_test)
def run_task(self, fw_spec): input_file = os.path.join(self.get("write_to_dir", ""), self.get("input_file", "mol.qin")) # these if statements might need to be reordered at some point if "molecule" in self: molecule = self["molecule"] elif fw_spec.get("prev_calc_molecule"): molecule = fw_spec.get("prev_calc_molecule") else: raise KeyError( "No molecule present, add as an optional param or check fw_spec" ) # in the current structure there needs to be a statement for every optional QChem section # the code below defaults the section to None if the variable is not passed opt = self.get("opt", None) pcm = self.get("pcm", None) solvent = self.get("solvent", None) qcin = QCInput(molecule=molecule, rem=self["rem"], opt=opt, pcm=pcm, solvent=solvent) qcin.write_file(input_file)
def process_qchemrun(dir_name, taskname, input_file, output_file): """ Process a QChem calculation, aka an input/output pair. """ qchem_input_file = os.path.join(dir_name, input_file) qchem_output_file = os.path.join(dir_name, output_file) d = QCOutput(qchem_output_file).data temp_input = QCInput.from_file(qchem_input_file) d["input"] = {} d["input"]["molecule"] = temp_input.molecule d["input"]["rem"] = temp_input.rem d["input"]["opt"] = temp_input.opt d["input"]["pcm"] = temp_input.pcm d["input"]["solvent"] = temp_input.solvent d["task"] = {"type": taskname, "name": taskname} return d
def test_opt_template(self): opt_params = { "CONSTRAINT": ["tors 2 3 4 5 25.0", "bend 2 1 4 110.0"], "FIXED": ["x y 2 4 5"], "DUMMY": ["M 2 3 4 5"], "CONNECT": ["4 3 2 3 5 6"] } opt_test = QCInput.opt_template(opt_params).split("\n") opt_actual_list = ["$opt", "CONSTRAINT", " tors 2 3 4 5 25.0", " bend 2 1 4 110.0", "ENDCONSTRAINT", "FIXED", " x y 2 4 5", "ENDFIXED", "DUMMY", " M 2 3 4 5", "ENDDUMMY", "CONNECT", " 4 3 2 3 5 6", "ENDCONNECT", "$end"] for i_opt in opt_actual_list: self.assertIn(i_opt, opt_test)
def test_init(self): test_molecule = QCInput.from_file( os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule test_FreqSet = FreqSet(molecule=test_molecule) self.assertEqual( test_FreqSet.rem, { 'job_type': 'freq', 'gen_scfman': 'true', 'basis': '6-311++g*', 'max_scf_cycles': 200, 'method': 'wb97xd', 'scf_algorithm': 'diis' }) self.assertEqual(test_FreqSet.pcm, {}) self.assertEqual(test_FreqSet.solvent, {}) self.assertEqual(test_FreqSet.molecule, test_molecule)
def test_find_sections(self): str_single_job_input = """$molecule 0 1 S -0.00250959 -0.05817469 -0.02921636 C 1.70755408 -0.03033788 -0.01382912 H 2.24317221 -0.05215019 0.92026728 C 2.21976393 0.01718014 -1.27293235 H 3.27786220 0.04082146 -1.48539646 C 1.20867399 0.04478540 -2.27007793 H 1.40292257 0.10591684 -3.33110912 C -0.05341046 0.01577217 -1.74839343 C -1.32843436 0.03545064 -2.45531187 C -1.55195156 0.08743920 -3.80184635 H -0.75245172 0.10267657 -4.52817967 C -2.93293778 0.08408786 -4.13352169 H -3.31125108 0.11340328 -5.14405819 C -3.73173288 0.02741365 -3.03412864 H -4.80776535 0.00535688 -2.99564645 S -2.81590978 -0.00516172 -1.58990580 $end $rem job_type = opt method = wb97m-v basis = def2-tzvppd gen_scfman = true geom_opt_max_cycles = 75 max_scf_cycles = 300 scf_algorithm = diis scf_guess = sad sym_ignore = true symmetry = false thresh = 14 $end $opt CONSTRAINT tors 6 8 9 10 0.0 ENDCONSTRAINT $end """ sections_test = QCInput.find_sections(str_single_job_input) section_actual = ["molecule", "rem", "opt"] self.assertEqual(section_actual, sections_test)
def test_overwrite_input_addition(self): test_molecule = QCInput.from_file( os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule overwrite_inputs = {"rem": {'thresh': 14}} test_OptSet = OptSet( molecule=test_molecule, overwrite_inputs=overwrite_inputs) act_rem = { 'job_type': 'opt', 'gen_scfman': 'true', 'basis': '6-311++g*', 'max_scf_cycles': 200, 'method': 'wb97xd', 'scf_algorithm': 'diis', 'geom_opt_max_cycles': 200, 'thresh': 14 } self.assertDictEqual(act_rem, test_OptSet.rem)
def test_read_rem(self): str_rem = """Trying to break you! $rem job_type opt method wb97m-v basis def2-qzvppd max_scf_cycles 300 gen_scfman = true $end""" rem_test = QCInput.read_rem(str_rem) rem_actual = { "job_type": "opt", "method": "wb97m-v", "basis": "def2-qzvppd", "max_scf_cycles": "300", "gen_scfman": "true" } self.assertDictEqual(rem_actual, rem_test)
def test_init(self): test_molecule = QCInput.from_file( os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule test_DictSet = QChemDictSet( molecule=test_molecule, job_type='opt', basis_set='6-31G*', scf_algorithm='diis') self.assertEqual( test_DictSet.rem, { 'job_type': 'opt', 'gen_scfman': 'true', 'basis': '6-31g*', 'max_scf_cycles': 200, 'method': 'wb97xd', 'scf_algorithm': 'diis', 'geom_opt_max_cycles': 200 }) self.assertEqual(test_DictSet.pcm, {}) self.assertEqual(test_DictSet.solvent, {}) self.assertEqual(test_DictSet.molecule, test_molecule)
def test_multi_job_string(self): species = ["S", "C", "H", "C", "H", "C", "H", "C", "C", "C", "H", "C", "H", "C", "H", "S"] coords = [[-0.00250959, -0.05817469, -0.02921636], [1.70755408, -0.03033788, -0.01382912], [2.24317221, -0.05215019, 0.92026728], [2.21976393, 0.01718014, -1.27293235], [3.27786220, 0.04082146, -1.48539646], [1.20867399, 0.04478540, -2.27007793], [1.40292257, 0.10591684, -3.33110912], [-0.05341046, 0.01577217, -1.74839343], [-1.32843436, 0.03545064, -2.45531187], [-1.55195156, 0.08743920, -3.80184635], [-0.75245172, 0.10267657, -4.52817967], [-2.93293778, 0.08408786, -4.13352169], [-3.31125108, 0.11340328, -5.14405819], [-3.73173288, 0.02741365, -3.03412864], [-4.80776535, 0.00535688, -2.99564645], [-2.81590978, -0.00516172, -1.58990580]] molecule_1 = Molecule(species, coords) rem_1 = { "jobtype": "opt", "method": "wb97m-v", "basis": "def2-tzvppd", "gen_scfman": "true", "geom_opt_max_cycles": "75", "max_scf_cycles": "300", "scf_algorithm": "diis", "scf_guess": "sad", "sym_ignore": "true", "symmetry": "false", "thresh": "14" } opt_1 = {"CONSTRAINT": ["tors 6 8 9 10 0.0"]} job_1 = QCInput(molecule=molecule_1, rem=rem_1, opt=opt_1) molecule_2 = "read" rem_2 = { "jobtype": "sp", "method": "wb97m-v", "basis": "def2-tzvppd", "gen_scfman": "true", "geom_opt_max_cycles": "75", "max_scf_cycles": "300", "scf_algorithm": "diis", "scf_guess": "read", "sym_ignore": "true", "symmetry": "false", "thresh": "14" } job_2 = QCInput(molecule=molecule_2, rem=rem_2) job_list = [job_1, job_2] multi_job_str_test = QCInput.multi_job_string( job_list=job_list).split("\n") multi_job_str_actual_list = ["$molecule", " 0 1", " S -0.0025095900 -0.0581746900 -0.0292163600", " C 1.7075540800 -0.0303378800 -0.0138291200", " H 2.2431722100 -0.0521501900 0.9202672800", " C 2.2197639300 0.0171801400 -1.2729323500", " H 3.2778622000 0.0408214600 -1.4853964600", " C 1.2086739900 0.0447854000 -2.2700779300", " H 1.4029225700 0.1059168400 -3.3311091200", " C -0.0534104600 0.0157721700 -1.7483934300", " C -1.3284343600 0.0354506400 -2.4553118700", " C -1.5519515600 0.0874392000 -3.8018463500", " H -0.7524517200 0.1026765700 -4.5281796700", " C -2.9329377800 0.0840878600 -4.1335216900", " H -3.3112510800 0.1134032800 -5.1440581900", " C -3.7317328800 0.0274136500 -3.0341286400", " H -4.8077653500 0.0053568800 -2.9956464500", " S -2.8159097800 -0.0051617200 -1.5899058000", "$end", "$rem", " job_type = opt", " method = wb97m-v", " basis = def2-tzvppd", " gen_scfman = true", " geom_opt_max_cycles = 75", " max_scf_cycles = 300", " scf_algorithm = diis", " scf_guess = sad", " sym_ignore = true", " symmetry = false", " thresh = 14", "$end", "$opt", "CONSTRAINT", " tors 6 8 9 10 0.0", "ENDCONSTRAINT", "$end", "@@@", "$molecule", " read", "$end", "$rem", " job_type = opt", " method = wb97m-v", " basis = def2-tzvppd", " gen_scfman = true", " geom_opt_max_cycles = 75", " max_scf_cycles = 300", " scf_algorithm = diis", " scf_guess = sad", " sym_ignore = true", " symmetry = false", " thresh = 14", "$end"] for i_str in multi_job_str_actual_list: self.assertIn(i_str, multi_job_str_test)
def test_from_string(self): string = """$molecule 0 1 S -0.00250959 -0.05817469 -0.02921636 C 1.70755408 -0.03033788 -0.01382912 H 2.24317221 -0.05215019 0.92026728 C 2.21976393 0.01718014 -1.27293235 H 3.27786220 0.04082146 -1.48539646 C 1.20867399 0.04478540 -2.27007793 H 1.40292257 0.10591684 -3.33110912 C -0.05341046 0.01577217 -1.74839343 C -1.32843436 0.03545064 -2.45531187 C -1.55195156 0.08743920 -3.80184635 H -0.75245172 0.10267657 -4.52817967 C -2.93293778 0.08408786 -4.13352169 H -3.31125108 0.11340328 -5.14405819 C -3.73173288 0.02741365 -3.03412864 H -4.80776535 0.00535688 -2.99564645 S -2.81590978 -0.00516172 -1.58990580 $end $rem jobtype = opt method = wb97m-v basis = def2-tzvppd gen_scfman = true geom_opt_max_cycles = 75 max_scf_cycles = 300 scf_algorithm = diis scf_guess = sad sym_ignore = true symmetry = false thresh = 14 $end $opt CONSTRAINT tors 6 8 9 10 0.0 ENDCONSTRAINT $end """ qcinput_test = QCInput.from_string(string) species = ["S", "C", "H", "C", "H", "C", "H", "C", "C", "C", "H", "C", "H", "C", "H", "S"] coords = [[-0.00250959, -0.05817469, -0.02921636], [1.70755408, -0.03033788, -0.01382912], [2.24317221, -0.05215019, 0.92026728], [2.21976393, 0.01718014, -1.27293235], [3.27786220, 0.04082146, -1.48539646], [1.20867399, 0.04478540, -2.27007793], [1.40292257, 0.10591684, -3.33110912], [-0.05341046, 0.01577217, -1.74839343], [-1.32843436, 0.03545064, -2.45531187], [-1.55195156, 0.08743920, -3.80184635], [-0.75245172, 0.10267657, -4.52817967], [-2.93293778, 0.08408786, -4.13352169], [-3.31125108, 0.11340328, -5.14405819], [-3.73173288, 0.02741365, -3.03412864], [-4.80776535, 0.00535688, -2.99564645], [-2.81590978, -0.00516172, -1.58990580]] molecule_actual = Molecule(species, coords) self.assertEqual(molecule_actual, qcinput_test.molecule) rem_actual = { "job_type": "opt", "method": "wb97m-v", "basis": "def2-tzvppd", "gen_scfman": "true", "geom_opt_max_cycles": "75", "max_scf_cycles": "300", "scf_algorithm": "diis", "scf_guess": "sad", "sym_ignore": "true", "symmetry": "false", "thresh": "14" } self.assertDictEqual(rem_actual, qcinput_test.rem) opt_actual = {"CONSTRAINT": ["tors 6 8 9 10 0.0"]} self.assertDictEqual(opt_actual, qcinput_test.opt)