def test_orca_optts_calculation(): methane = SolvatedMolecule(name='methane', smiles='C') methane.qm_solvent_atoms = [] calc = Calculation(name='test_ts_reopt_optts', molecule=methane, method=method, bond_ids_to_add=[(0, 1)], keywords=opt_keywords, other_input_block='%geom\n' 'Calc_Hess true\n' 'Recalc_Hess 40\n' 'Trust 0.2\n' 'MaxIter 100\nend') calc.run() assert os.path.exists('test_ts_reopt_optts_orca.inp') assert calc.get_normal_mode_displacements(mode_number=6) is not None assert calc.terminated_normally() assert calc.optimisation_converged() assert calc.optimisation_nearly_converged() is False assert len(calc.get_imaginary_freqs()) == 1 # Gradients should be an n_atom x 3 array gradients = calc.get_gradients() assert len(gradients) == 5 assert len(gradients[0]) == 3 assert -599.437 < calc.get_enthalpy() < -599.436 assert -599.469 < calc.get_free_energy() < -599.468
def test_gauss_optts_calc(): os.chdir(os.path.join(here, 'data')) calc = Calculation(name='test_ts_reopt_optts', molecule=test_mol, method=method, keywords=optts_keywords, bond_ids_to_add=[(0, 1)]) calc.run() print(calc.input.added_internals) assert os.path.exists('test_ts_reopt_optts_g09.com') bond_added = False for line in open('test_ts_reopt_optts_g09.com', 'r'): if 'B' in line and len(line.split()) == 3: bond_added = True assert line.split()[0] == 'B' assert line.split()[1] == '1' assert line.split()[2] == '2' assert bond_added assert calc.get_normal_mode_displacements(mode_number=6) is not None assert calc.terminated_normally() assert calc.optimisation_converged() assert calc.optimisation_nearly_converged() is False assert len(calc.get_imaginary_freqs()) == 1 assert -40.324 < calc.get_free_energy() < -40.322 assert -40.301 < calc.get_enthalpy() < -40.299 os.remove('test_ts_reopt_optts_g09.com') os.chdir(here)
def test_calc_class(): xtb = XTB() calc = Calculation(name='-tmp', molecule=test_mol, method=xtb, keywords=xtb.keywords.sp) # Should prepend a dash to appease some EST methods assert not calc.name.startswith('-') assert calc.molecule is not None assert calc.method.name == 'xtb' assert calc.get_energy() is None assert calc.get_enthalpy() is None assert calc.get_free_energy() is None assert not calc.optimisation_converged() assert not calc.optimisation_nearly_converged() with pytest.raises(ex.AtomsNotFound): _ = calc.get_final_atoms() with pytest.raises(ex.CouldNotGetProperty): _ = calc.get_gradients() with pytest.raises(ex.CouldNotGetProperty): _ = calc.get_atomic_charges() # Calculation that has not been run shouldn't have an opt converged assert not calc.optimisation_converged() assert not calc.optimisation_nearly_converged() # With a filename that doesn't exist a NoOutput exception should be raised calc.output.filename = '/a/path/that/does/not/exist/tmp' with pytest.raises(ex.NoCalculationOutput): calc.output.set_lines() # With no output should not be able to get properties calc.output.filename = 'tmp' calc.output.file_lines = [] with pytest.raises(ex.CouldNotGetProperty): _ = calc.get_atomic_charges() # or final atoms with pytest.raises(ex.AtomsNotFound): _ = calc.get_final_atoms() # Should default to a single core assert calc.n_cores == 1 calc_str = str(calc) new_calc = Calculation(name='tmp2', molecule=test_mol, method=xtb, keywords=xtb.keywords.sp) new_calc_str = str(new_calc) # Calculation strings need to be unique assert new_calc_str != calc_str new_calc = Calculation(name='tmp2', molecule=test_mol, method=xtb, keywords=xtb.keywords.sp, temp=5000) assert str(new_calc) != new_calc_str mol_no_atoms = Molecule() with pytest.raises(ex.NoInputError): _ = Calculation(name='tmp2', molecule=mol_no_atoms, method=xtb, keywords=xtb.keywords.sp)