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 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_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_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_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_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_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_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_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_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_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 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 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_write_custom_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" } ft = WriteCustomInput(molecule=mol, rem=rem) 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_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_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_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_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', 'basis': '6-31G*', 'max_scf_cycles': 200, 'method': 'wB97X-V', 'geom_opt_max_cycles': 200 }) self.assertEqual(test_DictSet.pcm, {}) self.assertEqual(test_DictSet.solvent, {}) self.assertEqual(test_DictSet.molecule, test_molecule)
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 __init__(self, input_file="mol.qin", output_file="mol.qout", scf_max_cycles=200, geom_max_cycles=200): """ Initializes the error handler from a set of input and output files. Args: input_file (str): Name of the QChem input file. output_file (str): Name of the QChem output file. scf_max_cycles (int): The max iterations to set to fix SCF failure. geom_max_cycles (int): The max iterations to set to fix geometry optimization failure. """ self.input_file = input_file self.output_file = output_file self.scf_max_cycles = scf_max_cycles self.geom_max_cycles = geom_max_cycles self.qcinp = QCInput.from_file(self.input_file) self.outdata = None self.errors = []
def test_pcm_init(self): test_molecule = QCInput.from_file( os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule test_FreqSet = FreqSet(molecule=test_molecule, pcm_dielectric=10.0) self.assertEqual( test_FreqSet.rem, { 'job_type': 'freq', 'basis': '6-311++G*', 'max_scf_cycles': 200, 'method': 'wB97X-V', 'solvent_method': 'pcm' }) self.assertEqual( test_FreqSet.pcm, { 'heavypoints': '194', 'hpoints': '194', 'radii': 'uff', 'theory': 'cpcm', 'vdwscale': '1.1' }) self.assertEqual(test_FreqSet.solvent, {'dielectric': 10.0}) self.assertEqual(test_FreqSet.molecule, test_molecule)
def __init__(self, input_file="mol.qin", output_file="mol.qout", rca_gdm_thresh=1.0E-3, scf_max_cycles=200): """ Initializes the error handler from a set of input and output files. Args: input_file (str): Name of the QChem input file. output_file (str): Name of the QChem output file. rca_gdm_thresh (float): The threshold for the prior scf algorithm. If last deltaE is larger than the threshold try RCA_DIIS first, else, try DIIS_GDM first. scf_max_cycles (int): The max iterations to set to fix SCF failure. """ self.input_file = input_file self.output_file = output_file self.scf_max_cycles = scf_max_cycles self.geom_max_cycles = geom_max_cycles self.qcinp = QCInput.from_file(self.input_file) self.outdata = None self.errors = None self.qchem_job = qchem_job
def test_write_input_from_io_set(self): ft = WriteInputFromIOSet({"molecule": self.co_mol, "qchem_input_set": "OptSet"}) 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_torsion_potential(self): # location of test files test_tor_files = os.path.join(module_dir, "..", "..", "test_files", "torsion_wf") # define starting molecule and torsion potential workflow object initial_qcin = QCInput.from_file( os.path.join(test_tor_files, "initial_opt", "mol.qin")) initial_mol = initial_qcin.molecule atom_indexes = [6, 8, 9, 10] angles = [0.0, 90.0, 180.0] rem = [] # add the first rem section rem.append({ "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 }) # the second rem section rem.append({ "jobtype": "opt", "method": "wb97m-v", "basis": "def2-tzvppd", "geom_opt_max_cycles": 75, "max_scf_cycles": 300, "scf_algorithm": "diis", "scf_guess": "sad", "sym_ignore": "true", "symmetry": "false", "thresh": 14 }) real_wf = get_wf_torsion_potential(molecule=initial_mol, atom_indexes=atom_indexes, angles=angles, rem=rem, db_file=">>db_file<<") # use powerup to replace run with fake run # def ref_dirs ref_dirs = { "initial_opt": os.path.join(test_tor_files, "initial_opt"), "opt_0": os.path.join(test_tor_files, "opt_0"), "opt_90": os.path.join(test_tor_files, "opt_90"), "opt_180": os.path.join(test_tor_files, "opt_180") } 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()])) # Checking of the inputs happens in fake_run_qchem so there is no point to retest the inputs # Check the output info that gets inserted in the DB init_opt = self.get_task_collection().find_one( {"task_label": "initial_opt"}) init_opt_final_mol = Molecule.from_dict( init_opt["output"]["optimized_molecule"]) init_opt_final_e = init_opt["output"]["final_energy"] # parse output file act_init_opt_out = QCOutput( os.path.join(test_tor_files, "initial_opt", "mol.qout")) act_init_opt_mol = act_init_opt_out.data[ "molecule_from_optimized_geometry"] act_init_opt_final_e = act_init_opt_out.data["final_energy"] np.testing.assert_equal(act_init_opt_mol.species, init_opt_final_mol.species) np.testing.assert_allclose(act_init_opt_mol.cart_coords, init_opt_final_mol.cart_coords, atol=0.0001) np.testing.assert_equal(act_init_opt_final_e, init_opt_final_e) # Optimization of 0 torsion opt_0 = self.get_task_collection().find_one({"task_label": "opt_0"}) opt_0_final_mol = Molecule.from_dict( opt_0["output"]["optimized_molecule"]) opt_0_final_e = opt_0["output"]["final_energy"] # parse output file act_opt_0_out = QCOutput( os.path.join(test_tor_files, "opt_0", "mol.qout")) act_opt_0_mol = act_opt_0_out.data["molecule_from_optimized_geometry"] act_opt_0_final_e = act_opt_0_out.data["final_energy"] np.testing.assert_equal(act_opt_0_mol.species, opt_0_final_mol.species) np.testing.assert_allclose(act_opt_0_mol.cart_coords, opt_0_final_mol.cart_coords, atol=0.0001) np.testing.assert_equal(act_opt_0_final_e, opt_0_final_e) # Optimization of 90 torsion opt_90 = self.get_task_collection().find_one({"task_label": "opt_90"}) opt_90_final_mol = Molecule.from_dict( opt_90["output"]["optimized_molecule"]) opt_90_final_e = opt_90["output"]["final_energy"] # parse output file act_opt_90_out = QCOutput( os.path.join(test_tor_files, "opt_90", "mol.qout")) act_opt_90_mol = act_opt_90_out.data[ "molecule_from_optimized_geometry"] act_opt_90_final_e = act_opt_90_out.data["final_energy"] np.testing.assert_equal(act_opt_90_mol.species, opt_90_final_mol.species) np.testing.assert_allclose(act_opt_90_mol.cart_coords, opt_90_final_mol.cart_coords, atol=0.0001) np.testing.assert_equal(act_opt_90_final_e, opt_90_final_e) # Optimization of 180 torsion opt_180 = self.get_task_collection().find_one( {"task_label": "opt_180"}) opt_180_final_mol = Molecule.from_dict( opt_180["output"]["optimized_molecule"]) opt_180_final_e = opt_180["output"]["final_energy"] # parse output file act_opt_180_out = QCOutput( os.path.join(test_tor_files, "opt_180", "mol.qout")) act_opt_180_mol = act_opt_180_out.data[ "molecule_from_optimized_geometry"] act_opt_180_final_e = act_opt_180_out.data["final_energy"] np.testing.assert_equal(act_opt_180_mol.species, opt_180_final_mol.species) np.testing.assert_allclose(act_opt_180_mol.cart_coords, opt_180_final_mol.cart_coords, atol=0.0001) np.testing.assert_equal(act_opt_180_final_e, opt_180_final_e)