def train_inter(): intra_h2o_gap = gt.gap.SolventIntraGAP(name='water_intra_gap', system=system) intra_methane_gap = gt.gap.SoluteIntraGAP( name='intra_znh2o6', system=system, molecule=gt.Molecule('znh2o6.xyz')) inter_gap = gt.InterGAP(name='inter', system=system, default_params=False) inter_gap.params.soap['O'] = gt.GTConfig.gap_default_soap_params inter_gap.params.soap['O']['cutoff'] = 4.0 inter_gap.params.soap['O']['other'] = ['Zn', 'H', 'O'] gt.active.train(system, method_name='gpaw', validate=False, max_time_active_fs=5000, active_e_thresh=0.1 + 0.04 * 20, gap=gt.gap.SSGAP(solute_intra=intra_methane_gap, solvent_intra=intra_h2o_gap, inter=inter_gap), max_energy_threshold=5, n_configs_iter=20) return None
validate=False, gap=gt.gap.SSGAP( solute_intra=intra_methane_gap, solvent_intra=intra_h2o_gap, inter=inter_gap)) return None if __name__ == '__main__': h2o = gt.System(box_size=[10, 10, 10]) h2o.add_solvent('h2o', n=1) train_h2o() methane = gt.System(box_size=[10, 10, 10]) methane.add_molecules(gt.Molecule('methane.xyz')) train_methane() system = gt.System(box_size=[10, 10, 10]) system.add_molecules(gt.Molecule('methane.xyz')) system.add_solvent('h2o', n=10) intra_h2o_gap = gt.gap.SolventIntraGAP(name='intra_h2o', system=system) intra_methane_gap = gt.gap.SoluteIntraGAP( name='intra_methane', system=system, molecule=gt.Molecule('methane.xyz')) inter_gap = gt.InterGAP(name='inter', system=system) train_inter() traj = gt.md.run_gapmd(configuration=system.random(min_dist_threshold=2.0),
import gaptrain as gt gt.GTConfig.n_cores = 4 if __name__ == '__main__': system = gt.System(box_size=[12.42, 12.42, 12.42]) system.add_molecules(gt.Molecule('znh2o6.xyz', charge=2)) system.add_solvent('h2o', n=58) intra_h2o_gap = gt.gap.SolventIntraGAP(name='water_intra_gap', system=system) intra_znh2o6_gap = gt.gap.SoluteIntraGAP( name='intra_znh2o6', system=system, molecule=gt.Molecule('znh2o6.xyz')) inter_gap = gt.InterGAP(name='inter', system=system, default_params=False) # Run 30 ps of dynamics from an equilibrated point traj = gt.md.run_gapmd(configuration=gt.Data('eqm_final_frame.xyz')[0], gap=gt.gap.SSGAP(solute_intra=intra_znh2o6_gap, solvent_intra=intra_h2o_gap, inter=inter_gap), temp=300, dt=0.5, interval=5, ps=30, n_cores=4) traj.save(filename=f'zn_h2o_traj')
rxn = ade.Reaction('C=CC=C.C=C>>C1=CCCCC1', name='DA') rxn.locate_transition_state() rxn.ts.print_xyz_file(filename='ts.xyz') return None # First find the transition state and save ts.xyz find_ts() # Set the keywords to use for an ORCA energy and gradient calculation as low- # level PBE with a double zeta basis set gt.GTConfig.orca_keywords = GradientKeywords(['PBE', 'def2-SVP', 'EnGrad']) # Initialise a cubic box 10x10x10 Å containing a single methane molecule da_ts = gt.System(box_size=[10, 10, 10]) da_ts.add_molecules(gt.Molecule('ts.xyz')) # and train the GAP using a 0.1 eV threshold (~2 kcal mol-1), here the initial # configuration from which dynamics is propagated from needs to be fixed to # the TS (i.e. the first configuration) for good sampling around the TS data, gap = gt.active.train(da_ts, method_name='orca', temp=500, active_e_thresh=0.1, max_time_active_fs=200, fix_init_config=True) # 'uplift' the configurations obtained at PBE/DZ to MP2/TZ gt.GTConfig.orca_keywords = GradientKeywords( ['RI-MP2', 'def2-TZVP', 'TightSCF', 'AutoAux', 'NoFrozenCore', 'EnGrad']) data.parallel_orca()
inter_gap.params.soap['O']['other'] = ['Zn', 'H', 'O'] gt.active.train(system, method_name='gpaw', validate=False, max_time_active_fs=5000, active_e_thresh=0.1 + 0.04 * 20, gap=gt.gap.SSGAP(solute_intra=intra_methane_gap, solvent_intra=intra_h2o_gap, inter=inter_gap), max_energy_threshold=5, n_configs_iter=20) return None if __name__ == '__main__': if not os.path.exists('water_intra_gap.xml'): exit('Intramolecular GAP for water did not exist. Please generate it ' 'with e.g. train_water_h2o.py') znh2o6 = gt.System(box_size=[10, 10, 10]) znh2o6.add_molecules(gt.Molecule('znh2o6.xyz', charge=2)) train_intra_zn() # Generate a [Zn(H2O)6](aq) system system = gt.System(box_size=[10, 10, 10]) system.add_molecules(gt.Molecule('znh2o6.xyz', charge=2)) system.add_solvent('h2o', n=20) train_inter()
"""Train a GAP for a gas phase methane molecule with a PBE/def2-SVP ground truth and compare the accuracy along a trajectory""" import gaptrain as gt from autode.wrappers.keywords import GradientKeywords gt.GTConfig.n_cores = 8 # Set the keywords to use for an ORCA energy and gradient calculation gt.GTConfig.orca_keywords = GradientKeywords(['PBE', 'def2-SVP', 'EnGrad']) # Initialise a cubic box 10x10x10 Å containing a single methane molecule methane = gt.System(box_size=[10, 10, 10]) methane.add_molecules(gt.Molecule('methane.xyz')) # Train a GAP at 1000 K data, gap = gt.active.train(methane, method_name='orca', temp=1000) # Run 1 ps molecular dynamics using the GAP at 300 K using a 0.5 fs time-step. # The initial configuration is methane located at a random position in the box traj = gt.md.run_gapmd( configuration=methane.random(), gap=gap, temp=500, # Kelvin dt=0.5, # fs interval=1, # frames fs=50, n_cores=4) # save the trajectory with no energies traj.save(filename='traj.xyz') # create sets of data from the trajectory containing predicted & true energies
import gaptrain as gt from autode.wrappers.keywords import GradientKeywords gt.GTConfig.n_cores = 8 if __name__ == '__main__': gt.GTConfig.orca_keywords = GradientKeywords( ['PBE', 'ma-def2-SVP', 'EnGrad']) # large box to ensure no self-interaction sn2_ts = gt.System(box_size=[20, 20, 20]) sn2_ts.add_molecules(gt.Molecule('ts.xyz', charge=-1)) gap = gt.GAP(name='sn2_gap', system=sn2_ts, default_params=False) gap.params.soap['C'] = gt.GTConfig.gap_default_soap_params gap.params.soap['C']['other'] = ['H', 'Cl'] gap.params.soap['C']['cutoff'] = 6.0 data, gap = gt.active.train(sn2_ts, method_name='orca', temp=500, active_e_thresh=0.1, max_time_active_fs=500, fix_init_config=True) # 'uplift' the configurations obtained at PBE/DZ to MP2/TZ gt.GTConfig.orca_keywords = GradientKeywords( ['DLPNO-CCSD(T)', 'ma-def2-TZVPP', 'NumGrad', 'AutoAux', 'EnGrad']) data.parallel_orca() gap.train(data)
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
import gaptrain as gt from autode.wrappers.keywords import GradientKeywords gt.GTConfig.n_cores = 10 gt.GTConfig.orca_keywords = GradientKeywords(['B3LYP', 'def2-SVP', 'EnGrad']) # For non-periodic systems there's no need to define a box, but a System # requires one ts = gt.System(box_size=[10, 10, 10]) ts.add_molecules(gt.Molecule('ts1_prime.xyz')) gap = gt.GAP(name='da_gap', system=ts, default_params={}) gap.params.soap['C'] = gt.GTConfig.gap_default_soap_params gap.params.soap['C']['cutoff'] = 3.0 gap.params.soap['C']['other'] = ['H', 'C'] data, gap = gt.active.train( system=ts, method_name='orca', gap=gap, max_time_active_fs=200, temp=500, active_e_thresh=3 * 0.043, # 3 kcal mol-1 max_energy_threshold=5, max_active_iters=50, n_init_configs=10, fix_init_config=True)
from gaptrain.cur import rows import gaptrain as gt import numpy as np import os here = os.path.abspath(os.path.dirname(__file__)) h2o = gt.Molecule(os.path.join(here, 'data', 'h2o.xyz')) def test_cur(): # Check several times that the CUR matrix is the correct size for # different random input for _ in range(100): matrix = np.random.random(size=(10, 2)) cur_rows_mat = rows(matrix) n_rows, n_cols = cur_rows_mat.shape assert 0 < n_rows < 10 assert n_cols == 2 def test_cur_soap_matrix(): """Test CUR decomposition on a matrix of SOAP vectors to select the most different configurations""" h2o_dimer = gt.System(box_size=[10, 10, 10]) h2o_dimer.add_molecules(h2o, n=2)
"""Train a GAP for a gas phase benzene molecule with a DFTB ground truth""" import gaptrain as gt gt.GTConfig.n_cores = 4 # Initialise a cubic box 10x10x10 Å containing a single benzene molecule benzene = gt.System(box_size=[10, 10, 10]) benzene.add_molecules(gt.Molecule('benzene.xyz')) # Train a GAP at 1000 K using DFTB as the ground truth method data, gap = gt.active.train(benzene, method_name='dftb', validate=False, temp=1000) # Run 1 ps molecular dynamics using the GAP at 300 K using a 0.5 fs time-step. # The initial configuration is methane located at a random position in the box traj = gt.md.run_gapmd(configuration=benzene.random(), gap=gap, temp=300, # Kelvin dt=0.5, # fs interval=5, # frames ps=1, n_cores=4) # and save the trajectory for visualisation in Avogadro, VMD, PyMol etc. traj.save(filename='traj.xyz')
import gaptrain as gt import os here = os.path.abspath(os.path.dirname(__file__)) h2o = gt.Molecule(os.path.join(here, 'data', 'h2o.xyz')) methane = gt.Molecule(os.path.join(here, 'data', 'methane.xyz')) def test_gap(): water_dimer = gt.System(box_size=[3.0, 3.0, 3.0]) water_dimer.add_molecules(h2o, n=2) gap = gt.GAP(name='test', system=water_dimer) assert hasattr(gap, 'name') assert hasattr(gap, 'params') assert gap.training_data is None assert hasattr(gap.params, 'general') assert hasattr(gap.params, 'pairwise') assert hasattr(gap.params, 'soap') # By default should only add a SOAP to non-hydrogen elements assert 'O' in gap.params.soap.keys() assert len(list(gap.params.soap)) == 1 def test_gap_train(): system = gt.System(box_size=[10, 10, 10])