def create_jobs(settings, fde_settings, i, mols): """ Create all the jobs associated to the dimer/monomers""" mol1, mol2 = mols name1 = 'frag1_frame_{}'.format(i) name2 = 'frag2_frame_{}'.format(i) name3 = 'frame_{}'.format(i) # Prepare isolated fragments temp_overlay = templates.singlepoint.overlay iso_frag1 = adf(temp_overlay(settings), mol1, job_name='iso_' + name1) iso_frag2 = adf(temp_overlay(settings), mol2, job_name='iso_' + name2) # Prepare embedded fragments emb_frag1 = embed_job(fde_settings, iso_frag1, iso_frag2, 'emb_' + name1, switch=False) emb_frag2 = embed_job(fde_settings, iso_frag2, iso_frag1, 'emb_' + name2, switch=True) # Prepare excitation calculations exc_frag1 = excitations_job(fde_settings, iso_frag1, iso_frag2, emb_frag1, emb_frag2, 'exc_' + name1, switch=False) exc_frag2 = excitations_job(fde_settings, iso_frag1, iso_frag2, emb_frag2, emb_frag1, 'exc_' + name2, switch=True) # Run all dependencies and final subsystem calculation name = 'subexc_' + name3 subexc = subexc_job(fde_settings, iso_frag1, iso_frag2, exc_frag1, exc_frag2, name, switch=False) return [ iso_frag1, iso_frag2, emb_frag1, emb_frag2, exc_frag1, exc_frag2, subexc ]
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 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 calc_reactant(name): smiles = {'C': '[CH]#', 'N': '[N]#'}[name[0]] + "[N+]" +\ {'C': '[CH2-]', 'N': '[NH-]', 'O': '[O-]'}[name[2]] mol = rdkitTools.smiles2plams(smiles) mol.properties.smiles = smiles reactant = adf(templates.geometry.overlay(settings), dftb(templates.geometry.overlay(settings), mol, job_name=name + "_reactant_DFTB").molecule, job_name=name + "_reactant") return reactant
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 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)
# returns a set of results object containing the output of # each point in the scan lt = PES_scan([dftb, adf], settings, cnc, scan) # Gets the object presenting the molecule # with the maximum energy calculated from the scan apprTS = select_max(lt, "energy") appr_hess = dftb(templates.freq.overlay(settings), apprTS.molecule) t = Settings() t.specific.adf.geometry.inithess = appr_hess.archive.path # Run the TS optimization with ADF, using initial hessian from DFTB freq calculation workflow = adf(templates.ts.overlay(settings).overlay(t), appr_hess.molecule) with XenonKeeper() as Xe: xenon_config = XenonConfig(jobs_scheme='slurm', location=None) job_config = RemoteJobConfig( registry=registry, prefix='/home/jhidding/venv', # the working_dir should exist and contain a file called worker.sh working_dir='/home/jhidding/qm-test', init=init, finish=finish, time_out=1) ts = run_xenon(Xe, 4, xenon_config, job_config, workflow)
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)
for a1 in ('C', 'N'): for a3 in ('C', 'N', 'O'): name = a1 + 'N' + a3 reaction_names.add(name) print(name) # generate all jobs job_list = [] for name in reaction_names: reactant = calc_reactant(name) product, adf_freq = calc_productAndTS(name) job_list.append(gather(reactant, product, adf_freq)) # Need also the energy of ethene acetylene = rdkitTools.smiles2plams('C#C') E_acetylene_job = adf(templates.geometry.overlay(settings), acetylene, job_name="acetylene").energy # Actual execution of the jobs E_acetylene, results = run(gather(E_acetylene_job, gather(*job_list)), n_processes=1) def bond_distance(r1, r2): return sqrt(sum((x - y) ** 2 for x, y in zip(r1, r2))) # extract table from results table = {} for reactant, product, TS in results: # Retrieve the molecular coordinates mol = TS.molecule
constraint2 = "dist 3 4" # scan input scan = { 'constraint': [constraint1, constraint2], 'surface': { 'nsteps': 6, 'start': [2.3, 2.3], '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, cnc, scan) # 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(adf(templates.ts.overlay(settings), apprTS.molecule), n_processes=2) # Retrieve the molecular coordinates mol = ts.molecule r1 = mol.atoms[0].coords r2 = mol.atoms[4].coords print("TS Bond distance:", bond_distance(r1, r2)) print("TS Energy:", ts.energy)
settings.specific.dftb.dftb.scc job_list = [] for s1 in ('C', 'N', 'O'): n1 = rdkitTools.modify_atom(cnc_ts, 0, s1) for s2 in ('N', 'O', 'S'): n2 = rdkitTools.modify_atom(n1, 1, s2) for s3 in ('C', 'N', 'O'): n3 = rdkitTools.modify_atom(n2, 2, s3) name = s1 + '-' + s2 + '-' + s3 n3.properties.name = name dftb_freq = dftb(templates.freq.overlay(settings), n3, job_name=name + "_dftb_freq") t = Settings() t.specific.adf.geometry.inithess = dftb_freq.archive.path job_list.append(adf(templates.ts.overlay(settings).overlay(t), n3, job_name=name + "_ts")) wf = gather(*job_list) # Actual execution of the jobs results = run(wf, n_processes=1) def bond_distance(r1, r2): return sqrt(sum((x - y) ** 2 for x, y in zip(r1, r2))) # extract table from results print("System Bond1 Bond2") for TS in results: # Retrieve the molecular coordinates
if key == "fragment2_EXTRA": for option in inputKeys["fragment2_EXTRA"]: exec(option) for key, val in list(inputKeys.items()): if key == "complex_EXTRA": for option in inputKeys["complex_EXTRA"]: exec(option) job_list = [] for key, val in list(inputKeys.items()): if key == "r1path": ircFrags = GetFragmentList(val["r1path"], [inputKeys["r1fragment"]])[0] r1_mol = ircFrags["frag1"] r1 = adf(templates.geometry.overlay(settings_R1), r1_mol, job_name="r1") job_list.append(gather(r1)) for key, val in list(inputKeys.items()): if key == "r2path": ircFrags = GetFragmentList(val["r2path"], [inputKeys["r2fragment"]])[0] r2_mol = ircFrags["frag1"] r2 = adf(templates.geometry.overlay(settings_R2), r2_mol, job_name="r2") job_list.append(gather(r2)) for key, val in list(inputKeys.items()): if key == "rcpath": ircFrags = GetFragmentList(val["rcpath"], [inputKeys["rcfragment"]])[0] rc_mol = ircFrags["frag1"] rc = adf(templates.geometry.overlay(settings_RC),
# User define Settings settings = Settings() settings.functional = "pbe" settings.basis = "TZ2P" settings.specific.dftb.dftb.scc job_list = [] # Loop over all reactions for name, reactant1, reactant2, product in reactions: # Prepare reactant1 job r1mol = rdkitTools.smiles2plams(reactant1) r1job = adf( templates.geometry.overlay(settings), dftb(templates.geometry.overlay(settings), r1mol, job_name=name + "_r1_DFTB").molecule, job_name=name + "_r1") # Prepare reactant2 job r2mol = rdkitTools.smiles2plams(reactant2) r2job = adf( templates.geometry.overlay(settings), dftb(templates.geometry.overlay(settings), r2mol, job_name=name + "_r2_DFTB").molecule, job_name=name + "_r2") # Prepare product job pmol = rdkitTools.smiles2plams(product) pmol.properties.name = name pjob = adf(
for a3 in ('C', 'N', 'O'): name = a1 + 'N' + a3 reaction_names.add(name) print(name) # generate all jobs job_list = [] for name in reaction_names: reactant = calc_reactant(name) product, adf_freq = calc_productAndTS(name) job_list.append(gather(reactant, product, adf_freq)) # Need also the energy of ethene ethene = rdkitTools.smiles2rdkit('C=C') E_ethene_job = adf(templates.geometry.overlay(settings), ethene, job_name="ethene").energy # finalize and draw workflow wf = gather(E_ethene_job, gather(*job_list)) draw_workflow("wf.svg", wf._workflow) # Actual execution of the jobs E_ethene, results = run(wf, n_processes=2) def bond_distance(r1, r2): return sqrt(sum((x - y)**2 for x, y in zip(r1, r2))) # extract table from results
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)
'nsteps': 6, 'start': [2.3, 2.3], '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, cnc, scan) # Gets the object presenting the molecule # with the maximum energy calculated from the scan apprTS = select_max(lt, "energy") appr_hess = dftb(templates.freq.overlay(settings), apprTS.molecule) t = Settings() t.specific.adf.geometry.inithess = appr_hess.archive.path # Run the TS optimization with ADF, using initial hessian from DFTB freq calculation ts = run(adf(templates.ts.overlay(settings).overlay(t), appr_hess.molecule), n_processes=1) # Retrieve the molecular coordinates mol = ts.molecule r1 = mol.atoms[0].coords r2 = mol.atoms[4].coords print("TS Bond distance:", bond_distance(r1, r2)) print("TS Energy:", ts.energy)
'nsteps': 6, 'start': [2.3, 2.3], '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, cnc, scan) # 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 workflow = adf(templates.ts.overlay(settings), apprTS.molecule) from noodles.run.xenon import (XenonKeeper, XenonConfig, RemoteJobConfig, run_xenon) with XenonKeeper() as Xe: xenon_config = XenonConfig(jobs_scheme='slurm', location=None) job_config = RemoteJobConfig( registry=registry, prefix='/home/jhidding/venv', # the working_dir should exist and contain a file called worker.sh working_dir='/home/jhidding/qm-test', init=init, finish=finish,