def test_point_charge_calc(): os.chdir(os.path.join(here, 'data')) # Methane single point using a point charge with a unit positive charge # located at (10, 10, 10) calc = Calculation( name='methane_point_charge', molecule=test_mol, method=method, keywords=sp_keywords, point_charges=[PointCharge(charge=1.0, x=10.0, y=10.0, z=10.0)]) calc.run() # Assert that the input file is in the expected configuration for line in open('methane_point_charge_g09.com', 'r'): if 'PBE' in line: assert 'Charge' in line if len(line.split()) == 4: if not line.split()[0].isdigit(): continue x, y, z, charge = line.split() assert float(x) == 10.0 assert float(y) == 10.0 assert float(z) == 10.0 assert float(charge) == 1.0 assert -40.428 < calc.get_energy() < -40.427 # Gaussian needs x-matrix and nosymm in the input line to run optimisations # with point charges.. for opt_keyword in ['Opt', 'Opt=Tight', 'Opt=(Tight)']: calc = Calculation( name='methane_point_charge_o', molecule=test_mol, method=method, keywords=OptKeywords(['PBE1PBE/Def2SVP', opt_keyword]), point_charges=[PointCharge(charge=1.0, x=3.0, y=3.0, z=3.0)]) calc.generate_input() for line in open('methane_point_charge_o_g09.com', 'r').readlines(): if 'PBE' in line: assert 'charge' in line.lower() assert 'z-matrix' in line.lower() and 'nosymm' in line.lower() break os.remove('methane_point_charge_g09.com') os.remove('methane_point_charge_o_g09.com') os.chdir(os.path.join(here))
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_opt_hf_constraints(): keywords = OptKeywords([ 'driver\n gmax 0.002\n grms 0.0005\n' ' xmax 0.01\n xrms 0.007\n eprec 0.00003\nend', 'basis\n * library Def2-SVP\nend', 'task scf optimize' ]) h2o = Molecule(name='water', smiles='O') calc = Calculation(name='opt_water', molecule=h2o, method=method, keywords=keywords, cartesian_constraints=[0], distance_constraints={(0, 1): 0.95}) calc.run() h2o.atoms = calc.get_final_atoms() assert 0.94 < h2o.distance(0, 1) < 0.96
def test_opt_hf_constraints(): os.chdir(os.path.join(here, 'data')) keywords = OptKeywords([ 'driver\n gmax 0.002\n grms 0.0005\n' ' xmax 0.01\n xrms 0.007\n eprec 0.00003\nend', 'basis\n * library Def2-SVP\nend', 'task scf optimize' ]) h2o = Molecule(name='water', smiles='O') calc = Calculation(name='opt_water', molecule=h2o, method=method, keywords=keywords, cartesian_constraints=[0], distance_constraints={(0, 1): 0.95}) calc.run() h2o.set_atoms(atoms=calc.get_final_atoms()) assert 0.94 < h2o.get_distance(0, 1) < 0.96 os.remove('opt_water_nwchem.nw') os.chdir(here)
from autode.species.molecule import Molecule from autode.wrappers.keywords import OptKeywords, SinglePointKeywords from autode.exceptions import AtomsNotFound from autode.exceptions import NoInputError from autode.exceptions import NoNormalModesFound from autode.point_charges import PointCharge 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')
def optimise(molecule, method, keywords, n_cores=None, cartesian_constraints=None): """ Optimise a molecule :param molecule: (object) :param method: (autode.ElectronicStructureMethod) :param keywords: (list(str)) Keywords to use for the electronic structure c alculation e.g. ['Opt', 'PBE', 'def2-SVP'] :param n_cores: (int) Number of cores to use :param cartesian_constraints: (list(int)) List of atom ids to constrain :return: """ logger.info('Running an optimisation 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 OptKeywords except ModuleNotFoundError: logger.error('autode not found. Calculations not available') raise RequiresAutodE if keywords is None: if method == orca: keywords = OptKeywords(['LooseOpt', 'PBE', 'D3BJ', 'def2-SVP']) logger.warning(f'No keywords were set for the optimisation but an' f' ORCA calculation was requested. ' f'Using {str(keywords)}') elif method == xtb: keywords = xtb.keywords.opt else: logger.critical('No keywords were set for the optimisation ' '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 = OptKeywords(keywords) opt = Calculation(name=molecule.name + '_opt', molecule=molecule, method=method, keywords=keywords, n_cores=n_cores, cartesian_constraints=cartesian_constraints) opt.run() molecule.energy = opt.get_energy() molecule.set_atoms(atoms=opt.get_final_atoms()) return None
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()
import gaptrain as gt import autode as ade from autode.wrappers.keywords import GradientKeywords, OptKeywords gt.GTConfig.n_cores = 8 gt.GTConfig.orca_keywords = GradientKeywords( ['PBE', 'def2-SVP', 'D3BJ', 'EnGrad']) # Generate an optimised cyclobutene molecule mol = ade.Molecule(smiles='C1C=CC1', name='cyclobutene') mol.optimise(method=ade.methods.ORCA(), keywords=OptKeywords(['PBE', 'def2-SVP', 'D3BJ', 'Looseopt'])) mol.print_xyz_file() # Create a gap-train system and train system = gt.System(box_size=[10, 10, 10]) system.add_molecules(gt.Molecule('cyclobutene.xyz')) data, gap = gt.active.train( system, method_name='orca', temp=500, max_time_active_fs=200, validate=False, bbond_energy={(0, 3): 4}, # Atoms indexed from 0.. max_active_iters=15) # ..and the energy in eV
from autode.species.molecule import Molecule from autode.wrappers.keywords import OptKeywords from autode.atoms import Atom from autode.config import Config from . import testutils import numpy as np import os here = os.path.dirname(os.path.abspath(__file__)) test_mol = Molecule(name='methane', smiles='C') method = NWChem() Config.keyword_prefixes = False opt_keywords = OptKeywords([ 'driver\n gmax 0.002\n grms 0.0005\n' ' xmax 0.01\n xrms 0.007\n eprec 0.00003\nend', 'basis\n * library Def2-SVP\nend', 'dft\n xc xpbe96 cpbe96\nend', 'task dft optimize' ]) @testutils.work_in_zipped_dir(os.path.join(here, 'data', 'nwchem.zip')) def test_opt_calc(): calc = Calculation(name='opt', molecule=test_mol, method=method, keywords=opt_keywords) calc.run() assert os.path.exists('opt_nwchem.nw') assert os.path.exists('opt_nwchem.out')
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()