def singlepoint(molecule, method, keywords, n_cores=None): """ Run a single point energy evaluation on a molecule :param molecule: (object) :param method: (autode.ElectronicStructureMethod) :param keywords: (list(str)) Keywords to use for the electronic structure calculation e.g. ['Opt', 'PBE', 'def2-SVP'] :param n_cores: (int) Number of cores to use :return: """ logger.info('Running single point calculation') n_cores = Config.n_cores if n_cores is None else int(n_cores) try: from autode.calculation import Calculation from autode.wrappers.XTB import xtb from autode.wrappers.ORCA import orca from autode.wrappers.keywords import SinglePointKeywords except ModuleNotFoundError: logger.error('autode not found. Calculations not available') raise RequiresAutodE if keywords is None: if method == orca: keywords = SinglePointKeywords( ['SP', 'M062X', 'def2-TZVP', 'RIJCOSX', 'def2/J', 'SlowConv']) logger.warning('No keywords were set for the single point but an ' 'ORCA calculation was requested. ' f'Using {str(keywords)}') elif method == xtb: keywords = xtb.keywords.sp else: logger.critical('No keywords were set for the single-point ' 'calculation') raise Exception else: # If the keywords are specified as a list convert them to a set of # OptKeywords, required for autodE if type(keywords) is list: keywords = SinglePointKeywords(keywords) sp = Calculation(name=molecule.name + '_sp', molecule=molecule, method=method, keywords=keywords, n_cores=n_cores) sp.run() molecule.energy = sp.get_energy() return None
def test_input_gen(): xtb = XTB() calc = Calculation(name='tmp', molecule=test_mol, method=xtb, keywords=xtb.keywords.sp) Config.keep_input_files = True calc.generate_input() assert os.path.exists('tmp_xtb.xyz') calc.clean_up() # Clean-up should do nothing if keep_input_files = True assert os.path.exists('tmp_xtb.xyz') # but should be able to be forced calc.clean_up(force=True) assert not os.path.exists('tmp_xtb.xyz') # Test the keywords parsing unsupported_func = Functional('PBE', orca='PBE') calc_kwds = Calculation(name='tmp', molecule=test_mol, method=xtb, keywords=SinglePointKeywords([unsupported_func])) with pytest.raises(ex.UnsuppportedCalculationInput): calc_kwds.generate_input()
def test_keywords(): Config.keyword_prefixes = True keywords = Keywords(keyword_list=None) assert keywords.keyword_list == [] assert isinstance(GradientKeywords(None), Keywords) assert isinstance(OptKeywords(None), Keywords) assert isinstance(SinglePointKeywords(None), Keywords) keywords = Keywords(keyword_list=['test']) # Should not add a keyword that's already there keywords.append('test') assert len(keywords.keyword_list) == 1 assert hasattr(keywords, 'copy') # Should have reasonable names assert 'opt' in str(OptKeywords(None)).lower() assert 'hess' in str(HessianKeywords(None)).lower() assert 'grad' in str(GradientKeywords(None)).lower() assert 'sp' in str(SinglePointKeywords(None)).lower() Config.keyword_prefixes = False
def test_keywords(): keywords = Keywords(keyword_list=None) assert keywords.keyword_list == [] assert isinstance(GradientKeywords(None), Keywords) assert isinstance(OptKeywords(None), Keywords) assert isinstance(SinglePointKeywords(None), Keywords) keywords = Keywords(keyword_list=['test']) # Should not readd a keyword that's already there keywords.append('test') assert len(keywords.keyword_list) == 1 assert hasattr(keywords, 'copy')
def test_sp_hmethod_ranking(): Config.hmethod_sp_conformers = True butane = Molecule(smiles='CCCC') xtb = XTB() cwd = os.getcwd() # Need to set hmethod.low_sp with pytest.raises(AssertionError): butane.find_lowest_energy_conformer(lmethod=xtb, hmethod=orca) # work_in function will change directories and not change back when an # exception is raised, so ensure we're working in the same dir as before os.chdir(cwd) orca.keywords.low_sp = SinglePointKeywords(['PBE', 'D3BJ', 'def2-SVP']) butane.find_lowest_energy_conformer(lmethod=xtb, hmethod=orca) assert butane.energy is not None Config.hmethod_sp_conformers = False
def test_keyword_setting(): orca = ORCA() orca.keywords.sp.functional = 'B3LYP' # Setter should generate a Functional from the keyword string assert isinstance(orca.keywords.sp.functional, Functional) calc = Calculation(name='tmp', molecule=test_mol.copy(), method=orca, keywords=orca.keywords.sp) calc.generate_input() assert calc.input.exists() # B3LYP should now be in the in input inp_lines = open(calc.input.filename, 'r').readlines() assert any('B3LYP' in line for line in inp_lines) # With a keyword without ORCA defined then raise an exception with pytest.raises(UnsuppportedCalculationInput): orca.keywords.sp.functional = Functional(name='B3LYP', g09='B3LYP') calc = Calculation(name='tmp', molecule=test_mol.copy(), method=orca, keywords=orca.keywords.sp) calc.generate_input() # Without a default wavefunction method defined in the single point method # we can't set keywords.wf with pytest.raises(ValueError): orca.keywords.sp.wf_method = 'HF' # but if we have a WF method in the keywords we should be able to set it orca.keywords.sp = SinglePointKeywords( [WFMethod('MP2'), BasisSet('def2-TZVP')]) orca.keywords.sp.wf_method = 'HF' assert orca.keywords.sp.wf_method == 'HF'
import pytest import os import numpy as np here = os.path.dirname(os.path.abspath(__file__)) test_mol = Molecule(name='methane', smiles='C') method = G09() method.available = True opt_keywords = OptKeywords(['PBE1PBE/Def2SVP', 'Opt']) optts_keywords = OptKeywords([ 'PBE1PBE/Def2SVP', 'Freq', 'Opt=(TS, CalcFC, NoEigenTest, ' 'MaxCycles=100, MaxStep=10, NoTrustUpdate)' ]) sp_keywords = SinglePointKeywords(['PBE1PBE/Def2SVP']) def test_gauss_opt_calc(): os.chdir(os.path.join(here, 'data')) methylchloride = Molecule(name='CH3Cl', smiles='[H]C([H])(Cl)[H]', solvent_name='water') calc = Calculation(name='opt', molecule=methylchloride, method=method, keywords=opt_keywords) calc.run()
from autode.exceptions import NoInputError from autode.exceptions import SolventUnavailable from autode.exceptions import UnsuppportedCalculationInput from autode.wrappers.keywords import SinglePointKeywords, OptKeywords from autode.solvent.solvents import Solvent from . import testutils import numpy as np import pytest import os here = os.path.dirname(os.path.abspath(__file__)) test_mol = Molecule(name='methane', smiles='C') method = ORCA() method.available = True sp_keywords = SinglePointKeywords(['PBE', 'def2-SVP']) opt_keywords = OptKeywords(['Opt', 'PBE', 'def2-SVP']) @testutils.work_in_zipped_dir(os.path.join(here, 'data', 'orca.zip')) def test_orca_opt_calculation(): methylchloride = Molecule(name='CH3Cl', smiles='[H]C([H])(Cl)[H]', solvent_name='water') calc = Calculation(name='opt', molecule=methylchloride, method=method, keywords=opt_keywords) calc.run()
from autode.species.molecule import Molecule from autode.exceptions import AtomsNotFound from autode.exceptions import NoInputError from autode.exceptions import UnsuppportedCalculationInput from autode.wrappers.keywords import SinglePointKeywords, OptKeywords from . import testutils import pytest import numpy as np import os here = os.path.dirname(os.path.abspath(__file__)) test_mol = Molecule(name='methane', smiles='C') method = PSI4() method.available = True sp_keywords = SinglePointKeywords(['PBE0-D3BJ', 'def2-TZVP']) opt_keywords = OptKeywords(['PBE0-D3BJ', 'def2-SVP']) @testutils.work_in_zipped_dir(os.path.join(here, 'data', 'psi4.zip')) def test_psi4_opt_calculation(): methylchloride = Molecule(name='CH3Cl', smiles='[H]C([H])(Cl)[H]', solvent_name='water') calc = Calculation(name='opt', molecule=methylchloride, method=method, keywords=opt_keywords) calc.run()