def test_opt_orca(): """ Test Orca input generation and run functions. """ h2o = Molecule('test/test_files/h2o.xyz', 'xyz', charge=0, multiplicity=1) h2o_geometry = dftb(templates.geometry, h2o) s = Settings() # generic keyword "basis" must be present in the generic dictionary s.basis = "sto_dzp" # "specific" allows the user to apply specific keywords for a # package that are not in a generic dictionary # s.specific.adf.basis.core = "large" r = templates.singlepoint.overlay(s) h2o_singlepoint = orca(r, h2o_geometry.molecule) dipole = h2o_singlepoint.dipole final_result = run(dipole, n_processes=1) expected_dipole = [0.82409, 0.1933, -0.08316] diff = sqrt(sum((x - y)**2 for x, y in zip(final_result, expected_dipole))) print("Expected dipole computed with Orca 3.0.3 is:", expected_dipole) print("Actual dipole is:", final_result) assert diff < 1e-2
def main(): # Current Work Directory cwd = os.getcwd() # ========== Fill in the following variables # Varaible to define the Path ehere the Cp2K jobs will be computed scratch = "/path/to/scratch" project_name = 'My_awesome_project' # name use to create folders # Path to the basis set used by Cp2k basisCP2K = "/Path/to/CP2K/BASIS_MOLOPT" potCP2K = "/Path/to/CP2K/GTH_POTENTIALS" path_to_trajectory = 'Path/to/trajectory/in/XYZ' # Number of MO used to compute the coupling nHOMO = None couplings_range = None # Basis basis = "DZVP-MOLOPT-SR-GTH" # Algorithm to compute the NAC algorithm = 'levine' # Integation step used for the dynamics (femtoseconds) dt = 1 # ============== End of User definitions =================================== cp2k_args = Settings() cp2k_args.basis = basis # Results folder results_dir = join(cwd, 'total_results') if not os.path.exists(results_dir): os.mkdir(results_dir) # Merge all the HDF5 files file_hdf5 = merge_hdf5(scratch, project_name, cwd, results_dir) # compute missing couplings script_name = "merge_data.py" write_python_script(scratch, 'total_results', path_to_trajectory, project_name, basisCP2K, potCP2K, cp2k_args, Settings(), 0, script_name, file_hdf5, nHOMO, couplings_range, algorithm, dt) # Script using SLURM write_slurm_script(scratch, results_dir, script_name)
def calc_productAndTS(name): smiles = 'C1' + name[0] + "=" + name[1:] + 'C=1' mol = rdkitTools.smiles2plams(smiles) mol.properties.smiles = smiles product = adf(templates.geometry.overlay(settings), dftb(templates.geometry.overlay(settings), mol, job_name=name + "_product_DFTB").molecule, job_name=name + "_product") constraint1 = "dist 1 2" constraint2 = "dist 4 5" sv1 = startvalue[name[0]] sv2 = startvalue[name[2]] # scan input if name[0] == name[2]: # symmetric molecule scan = {'constraint': [constraint1, constraint2], 'surface': {'nsteps': 4, 'start': [sv1, sv2], 'stepsize': [0.1, 0.1]}} else: scan = {'constraint': constraint1, 'surface': {'nsteps': 4, 'start': sv1, 'stepsize': 0.1}, 'scan': {'constraint': constraint2, 'surface': {'nsteps': 4, 'start': sv2, 'stepsize': 0.1} } } # PES = gathered (promised) result objects for each point in the scan PES = PES_scan([dftb, adf], settings, product.molecule, scan, job_name=name + "_PES") # get the object presenting the molecule with the maximum energy calculated from the scan apprTS = select_max(PES, 'energy') DFTB_freq = dftb(templates.freq.overlay(settings), apprTS.molecule, job_name=name + "_DFTBfreq") t = Settings() t.inithess = DFTB_freq.hessian # Run the TS optimization, using the default TS template TS = adf(templates.ts.overlay(settings).overlay(t), DFTB_freq.molecule, job_name=name + "_TS") adf_freq = adf(templates.freq.overlay(settings), TS.molecule, job_name=name + "_freq") return product, adf_freq
def test_opt_gamess(): """ Test Optimization in Gamess using methanol in water. """ methanol = Molecule('test/test_files/ion_methanol.xyz') methanol.properties['symmetry'] = 'Cs' s = Settings() s.specific.gamess.contrl.nzvar = 12 s.specific.gamess.system.timlim = 2 s.specific.gamess.system.mwords = 2 s.specific.gamess.pcm.solvnt = 'water' s.specific.gamess.basis.gbasis = 'sto' s.specific.gamess.basis.ngauss = 3 s.specific.gamess.guess.guess = 'huckel' s.specific.gamess.stapt.optol = '1d-5' s.specific.gamess.zmat["izmat(1)"] = "1,1,2, 1,2,3, 1,3,4, 1,3,5, 1,3,6, \n"\ "2,1,2,3, 2,2,3,4, 2,2,3,5, 2,2,3,6, \n"\ "3,1,2,3,4, 3,1,2,3,5, 3,1,2,3,6" inp = templates.geometry.overlay(s) methanol_geometry = gamess(inp, methanol, work_dir='/tmp') mol_opt = run(methanol_geometry.molecule) coords = concat([a.coords for a in mol_opt.atoms]) expected_coords = [-0.9956983464, 0.9204754677, -0.0002616586, -0.72585581, -0.0802380791, 2.18166e-05, 0.741292161, 0.0371204735, -1.69738e-05, 1.1448441964, 0.5632291664, -0.9026112278, 1.1448447102, 0.562978981, 0.9027182521, 1.1454516521, -0.9993402516, 1.04943e-05] assert abs(sum(zipWith(operator.sub)(coords)(expected_coords))) < 1e-7
def main(pdb_path, splitAt, work_dir): monomers = create_monomers(pdb_path, splitAt, work_dir) settings = Settings() settings.basis = "DZP" # settings.functional = "CAMY-B3LYP" settings.specific.adf.basis.core = "None" settings.specific.adf.symmetry = "Nosym" settings.specific.adf.xc.hybrid = "CAMY-B3LYP" settings.specific.adf.xc.xcfun = "" fde_settings = Settings() # fde_settings.functional = "camy-b3lyp" fde_settings.specific.adf.xc.hybrid = "CAMY-B3LYP" fde_settings.specific.adf.xc.xcfun = "" fde_settings.basis = "DZP" fde_settings.specific.adf.symmetry = "Nosym" fde_settings.specific.adf.fde.PW91k = "" fde_settings.specific.adf.fde.fullgrid = "" fde_settings.specific.adf.allow = "Partialsuperfrags" fde_settings.specific.adf.fde.GGAPOTXFD = "Becke" fde_settings.specific.adf.fde.GGAPOTCFD = "LYP" # Read input from molfiles jobs = chain(*list( map(lambda xs: create_jobs(settings, fde_settings, *xs), enumerate(monomers)))) run(gather(*jobs), n_processes=2)
def test_linear_ts(): """ compute a first approximation to the TS. """ # Read the Molecule from file cnc = Molecule('test/test_files/C-N-C.mol', 'mol') # User define Settings settings = Settings() settings.functional = "pbe" settings.basis = "SZ" settings.specific.dftb.dftb.scc constraint1 = Distance(0, 4) constraint2 = Distance(2, 3) # scan input pes = PES(cnc, constraints=[constraint1, constraint2], offset=[2.3, 2.3], get_current_values=False, nsteps=2, stepsize=[0.1, 0.1]) # returns a set of results object containing the output of # each point in the scan lt = pes.scan([dftb, adf], settings) # Gets the object presenting the molecule # with the maximum energy calculated from the scan apprTS = select_max(lt, "energy") # Run the TS optimization, using the default TS template ts = run(apprTS) expected_energy = -3.219708290363864 assert abs(ts.energy - expected_energy) < 0.02
def adf_fragmentsjob(settings, mol, *frozen_frags): mol_tot = Molecule() frag_settings = Settings() for i, frag in enumerate(frozen_frags): frag_id = "frag" + str(i + 1) for m in frag.mol_list: for a in m: a.fragment = frag_id mol_tot += m path = frag.result.kf.path + " type=FDE" frag_settings.specific.adf.fragments[frag_id] = path frag_settings.specific.adf.fde.PW91k = "" mol_tot += mol return adf(settings.overlay(frag_settings), mol_tot, job_name="fde")
def subexc_job(settings, iso_frag1, iso_frag2, emb_frag, frozen_frag, jobname, switch): subexc_settings = Settings() m_tot = add_fragments(iso_frag1, iso_frag2, switch) s_frag = subexc_settings.specific.adf.fragments s_frag['frag1'] = emb_frag.kf.path + ' subfrag=active' s_frag['frag2'] = frozen_frag.kf.path + ' subfrag=active type=FDE' subexc_settings.specific.adf.excitations.onlysing = "" subexc_settings.specific.adf.excitations.lowest = "5" subexc_settings.specific.adf.subexci.cthres = "10000.00" subexc_settings.specific.adf.subexci.sfthres = "0.00010000" subexc_settings.specific.adf.subexci.couplblock = "" subexc_settings.specific.adf.subexci.cicoupl = "" subexc_settings.specific.adf.subexci.tda = "" return adf(settings.overlay(subexc_settings), m_tot, job_name=jobname)
def test_overlay_cp2k_singlepoint(): """ Test if the merging with the CP2K templates produces the same Settings that writing it by hand. """ s = Settings() dft = s.specific.cp2k.force_eval.dft force = s.specific.cp2k.force_eval dft.scf.scf_guess = 'atomic' dft.scf.ot.minimizer = 'diis' dft.scf.ot.n_diis = 7 dft.scf.ot.preconditioner = 'full_single_inverse' dft.scf.added_mos = 0 dft.scf.eps_scf = 5e-06 r = templates.singlepoint.overlay(s) dft.basis_set_file_name = '' dft.mgrid.cutoff = 400 dft.mgrid.ngrids = 4 dft.potential_file_name = '' dft['print']['mo']['add_last'] = 'numeric' dft['print']['mo']['each']['qs_scf'] = 0 dft['print']['mo']['eigenvalues'] = '' dft['print']['mo']['eigenvectors'] = '' dft['print']['mo']['filename'] = './mo.data' dft['print']['mo']['ndigits'] = 36 dft['print']['mo']['occupation_numbers'] = '' dft.scf.max_scf = 200 dft.scf.scf_guess = 'atomic' dft.xc.xc_functional = 'pbe' dft.qs.method = 'gpw' force.subsys.cell.periodic = 'xyz' force.subsys.topology.coordinate = 'xyz' force.subsys.topology.coord_file_name = '' g = s['specific']['cp2k']['global'] g.print_level = 'low' g.project = "qmworks-cp2k" g.run_type = "energy_force" print(s.specific.cp2k.force_eval) print(r.specific.cp2k.force_eval) assert s.specific.cp2k == r.specific.cp2k
def excitations_job(settings, iso1, iso2, emb_frag, frozen_frag, jobname, switch): exc_settings = Settings() if not switch: m_tot = add_fragments(iso1, iso2, switch) else: m_tot = add_fragments(iso2, iso1, switch) s_frag = exc_settings.specific.adf.fragments if not switch: s_frag['frag1'] = emb_frag.kf.path + ' subfrag=active' s_frag['frag2'] = frozen_frag.kf.path + ' subfrag=active type=FDE' else: s_frag['frag2'] = emb_frag.kf.path + ' subfrag=active' s_frag['frag1'] = frozen_frag.kf.path + ' subfrag=active type=FDE' exc_settings.specific.adf.excitations.onlysing = "" exc_settings.specific.adf.excitations.lowest = "5" return adf(settings.overlay(exc_settings), m_tot, job_name=jobname)
def embed_job(settings, emb_frag, frozen_frag, jobname, switch): """ Define different jobs """ frag_settings = Settings() m_tot = add_fragments(emb_frag, frozen_frag, switch) if not switch: frag_settings.specific.adf.fragments[ 'frag1'] = emb_frag.kf.path + ' subfrag=active' frag_settings.specific.adf.fragments[ 'frag2'] = frozen_frag.kf.path + ' subfrag=active type=FDE' else: frag_settings.specific.adf.fragments[ 'frag2'] = emb_frag.kf.path + ' subfrag=active' frag_settings.specific.adf.fragments[ 'frag1'] = frozen_frag.kf.path + ' subfrag=active type=FDE' return adf(settings.overlay(frag_settings), m_tot, job_name=jobname)
def calc_productAndTS(name): smiles = 'C1' + name[0] + "=" + name[1:] + 'C1' mol = rdkitTools.smiles2plams(smiles) mol.properties.smiles = smiles product = adf(templates.geometry.overlay(settings), dftb(templates.geometry.overlay(settings), mol, job_name=name + "_product_DFTB").molecule, job_name=name + "_product") constraint1 = Distance(1, 0) constraint2 = Distance(4, 3) # scan input pes = PES(product.molecule, constraints=[constraint1, constraint2], offset=[2.0, 2.0], get_current_values=False, nsteps=5, stepsize=[0.1, 0.1]) # PES = gathered (promised) result objects for each point in the scan pesscan = pes.scan([dftb, adf], settings, job_name=name + "_PES") # get the object presenting the molecule with the maximum energy # calculated from the scan apprTS = select_max(pesscan, 'energy') DFTB_freq = dftb(templates.freq.overlay(settings), apprTS.molecule, job_name=name + "_DFTBfreq") t = Settings() t.specific.adf.geometry.inithess = DFTB_freq.kf.path # Run the TS optimization, using the default TS template TS = adf(templates.ts.overlay(settings).overlay(t), DFTB_freq.molecule, job_name=name + "_TS") adf_freq = adf(templates.freq.overlay(settings), TS.molecule, job_name=name + "_freq") return product, adf_freq
def test_overlay_adf_freq(): """ Test if the overlay function produces the same Settings that a user would write by hand. """ s = Settings() s.specific.adf.xc.gga = "bp86" s.specific.adf.beckegrid.quality = "good" s.specific.adf.scf.iterations = "99" s.specific.adf.scf.converge = "0.0000001" s.specific.adf.analyticalfreq r = templates.freq.overlay(s) s.specific.adf.basis.type = "DZP" s.specific.adf.basis.core = "None" print(s.specific.adf) print(r.specific.adf) assert s.specific.adf == r.specific.adf
def test_methanol_opt_orca(): """ Run a methanol optimization and retrieve the optimized geom. """ methanol = Molecule('test/test_files/methanol.xyz') s = Settings() s.specific.orca.main = "RKS B3LYP SVP Opt TightSCF SmallPrint" opt = orca(s, methanol) mol_opt = run(opt.molecule) expected_coords = [ -1.311116, -0.051535, -0.000062, 0.097548, 0.033890, -0.000077, -1.683393, -1.092152, -0.000066, -1.734877, 0.448868, 0.891460, -1.734894, 0.448881, -0.891567, 0.460481, -0.857621, -0.000038 ] coords = concat([a.coords for a in mol_opt.atoms]) assert abs(sum(zipWith(operator.sub)(coords)(expected_coords))) < 1e-7
def test_ADFGeometry_Constraint(): """ Test "freeze" and "selected_atoms" keywords for constrained geometry optimizations. """ an = plams.Molecule('test/test_files/an.xyz', 'xyz') # optimize only H atoms s = Settings() s.freeze = [1, 2, 3] result1 = adf(templates.geometry.overlay(s), an) geom1 = result1.molecule # optimize only H atoms s = Settings() s.selected_atoms = ['H'] result2 = adf(templates.geometry.overlay(s), an) geom2 = result2.molecule r = run(gather(geom1, geom2), n_processes=1) assert str(r[0]) == str(r[1])
from noodles import gather # User Defined imports from math import sqrt from qmworks.packages.SCM import dftb from qmworks.components import PES_scan, select_max import plams # ========== ============= plams.init() hartree2kcal = 627.5095 startvalue = {'C': 2.1, 'N': 1.9, 'O': 1.8} settings = Settings() settings.specific.dftb.dftb.scc.mixing = 0.15 settings.specific.dftb.dftb.scc.iterations = 200 settings.specific.dftb.geometry.iterations = 200 settings.specific.dftb.geometry.converge = "rad=0.002" def calc_reactant(name): smiles = {'C': '[CH2]=', 'N': '[NH]=', 'O': 'O='}[name[0]] +\ {'N': '[NH+]', 'O': '[O+]', 'S': '[S+]'}[name[1]] +\ {'C': '[CH2-]', 'N': '[NH-]', 'O': '[O-]'}[name[2]] mol = rdkitTools.smiles2plams(smiles) mol.properties.smiles = smiles return dftb(templates.geometry.overlay(settings), mol, job_name=name + "_reactant")
# ========== ============= def bond_distance(r1, r2): return sqrt(sum((x - y)**2 for x, y in zip(r1, r2))) # ========== ============= plams.init() # Read the Molecule from file cnc = Molecule('C-N-C.mol', 'mol') # User define Settings settings = Settings() settings.functional = "pbe" settings.basis = "TZ2P" settings.specific.dftb.dftb.scc constraint1 = "dist 1 5" constraint2 = "dist 3 4" # scan input scan = { 'constraint': [constraint1, constraint2], 'surface': { 'nsteps': 6, 'start': [2.3, 2.3], 'stepsize': [0.1, 0.1] }
HH = plams.Molecule("H_Mes2PCBH2_TS3series1.xyz") HH.guess_bonds() newmol = rdkitTools.apply_template(HH, template) # Change the 2 hydrogens to dummy atoms temp = rdkitTools.modify_atom(newmol, 47, '*') temp = rdkitTools.modify_atom(temp, 48, '*') # Put coordinates of dummy atoms to 0.0, this will force generating new # coordinates for the new atoms temp.atoms[47].move_to((0.0, 0.0, 0.0)) temp.atoms[48].move_to((0.0, 0.0, 0.0)) # Replace dummy atoms by new groups, generate coordinates only for new atoms job_list = [] for mod, smirks in list_of_modifications.items(): print(mod) temp2 = rdkitTools.apply_smirks(temp, smirks)[0] temp2 = rdkitTools.apply_smirks(temp2, smirks)[0] freeze = rdkitTools.gen_coords(temp2) # rdkitTools.write_molblock(temp2) # generate job s = Settings() s.freeze = [a + 1 for a in freeze] partial_geometry = adf(templates.geometry.overlay(s), temp2, job_name="partial_opt_" + mod) job_list.append( adf(templates.ts, partial_geometry.molecule, job_name="ts_" + mod)) results = run(gather(*job_list), n_processes=1)
return adf(settings.overlay(frag_settings), mol_tot, job_name = "fde") # ---------------------------------------------------------------- plams.init() # Read the Molecule from file m_h2o_1 = Molecule('FDE-H2O-1.xyz') m_h2o_2 = Molecule('FDE-H2O-2.xyz') m_mol = Molecule('FDE-mol.xyz') m_tot = m_mol + m_h2o_1 + m_h2o_2 print(m_tot) settings = Settings() settings.basis = 'SZ' settings.specific.adf.nosymfit = '' # Prepare first water molecule r_h2o_1 = adf(templates.singlepoint.overlay(settings), m_h2o_1, job_name="h2o_1") # Prepare second water molecule r_h2o_2 = adf(templates.singlepoint.overlay(settings), m_h2o_2, job_name="h2o_2") frozen_frags = [Fragment(r_h2o_1, [m_h2o_1]), Fragment(r_h2o_2, [m_h2o_2])] fde_res = run(fragmentsjob(settings, m_mol, *frozen_frags)) print(fde_res.dipole)
"settings_Frag2.specific.fragment2." + adfkey + '="' + keyval.strip("\n") + '"' for adfkey, keyval in adfinputLine ] elif key == "complex_EXTRA": f = open(val[0][0]) adfinputLine = [(line.split("=", 1)) for line in f.readlines()] inputKeys[key] = [ "settings_Fa.specific.complex." + adfkey + '="' + keyval.strip("\n") + '"' for adfkey, keyval in adfinputLine ] else: inputKeys[key] = [term for term in val] settings = Settings() settings_R1 = Settings() settings_R2 = Settings() settings_RC = Settings() settings_TS = Settings() settings_P = Settings() settings_IRC = Settings() settings_Frag1 = Settings() settings_Frag2 = Settings() settings_Fa = Settings() for key, val in list(inputKeys.items()): if key == "adfinputfile": for option in inputKeys["adfinputfile"]: exec(option) for key, val in list(inputKeys.items()):
def fun_ethylene(scratch_path): """ Test Ethylene singlw """ project_name = 'ethylene' # create Settings for the Cp2K Jobs s = Settings() s.basis = "DZVP-MOLOPT-SR-GTH" s.potential = "GTH-PBE" s.cell_parameters = [12.74] * 3 dft = s.specific.cp2k.force_eval.dft dft.scf.added_mos = 20 dft.scf.eps_scf = 1e-4 dft['print']['ao_matrices']['overlap'] = '' dft['print']['ao_matrices']['filename'] = join(scratch_path, 'overlap.out') # Copy the basis and potential to a tmp file shutil.copy('test/test_files/BASIS_MOLOPT', scratch_path) shutil.copy('test/test_files/GTH_POTENTIALS', scratch_path) # Cp2k configuration files basiscp2k = join(scratch_path, 'BASIS_MOLOPT') potcp2k = join(scratch_path, 'GTH_POTENTIALS') cp2k_config = {"basis": basiscp2k, "potential": potcp2k} # HDF5 path path_hdf5 = join(scratch_path, 'ethylene.hdf5') # all_geometries type :: [String] path_xyz = 'test/test_files/ethylene.xyz' geometries = split_file_geometries(path_xyz) # Input/Output Files file_xyz = join(scratch_path, 'coordinates.xyz') file_inp = join(scratch_path, 'ethylene.inp') file_out = join(scratch_path, 'ethylene.out') file_MO = join(scratch_path, 'mo_coeffs.out') files = JobFiles(file_xyz, file_inp, file_out, file_MO) schedule_job = schedule(prepare_job_cp2k) promise = schedule_job(geometries[0], files, s, scratch_path, project_name=project_name, hdf5_file=path_hdf5, wfn_restart_job=None, store_in_hdf5=True, nHOMOS=25, nLUMOS=25, package_config=cp2k_config) cp2k_result = run(promise) path_properties = cp2k_result.orbitals with h5py.File(path_hdf5) as f5: assert (all(p in f5 for p in path_properties))
def cp2k_input(range_orbitals, cell_parameters, cell_angles, added_mos, basis="DZVP-MOLOPT-SR-GTH", potential="GTH-PBE"): """ # create ``Settings`` for the Cp2K Jobs. """ # Main Cp2k Jobs cp2k_args = Settings() cp2k_args.basis = fun_format(basis) cp2k_args.potential = fun_format(potential) cp2k_args.cell_parameters = cell_parameters cp2k_args.cell_angles = cell_angles main_dft = cp2k_args.specific.cp2k.force_eval.dft main_dft.scf.added_mos = added_mos main_dft.scf.max_scf = 40 main_dft.scf.eps_scf = 5e-4 main_dft['print']['mo']['mo_index_range'] = '"{} {}"'.format( *range_orbitals) cp2k_args.specific.cp2k.force_eval.subsys.cell.periodic = fun_format( 'None') # Setting to calculate the wave function used as guess cp2k_OT = Settings() cp2k_OT.basis = fun_format(basis) cp2k_OT.potential = fun_format(potential) cp2k_OT.cell_parameters = cell_parameters cp2k_OT.cell_angles = cell_angles ot_dft = cp2k_OT.specific.cp2k.force_eval.dft ot_dft.scf.scf_guess = fun_format('atomic') ot_dft.scf.ot.minimizer = fun_format('DIIS') ot_dft.scf.ot.n_diis = 7 ot_dft.scf.ot.preconditioner = fun_format('FULL_SINGLE_INVERSE') ot_dft.scf.added_mos = 0 ot_dft.scf.eps_scf = 1e-06 ot_dft.scf.scf_guess = fun_format('restart') cp2k_OT.specific.cp2k.force_eval.subsys.cell.periodic = fun_format('None') return cp2k_args, cp2k_OT