def minimize_seeds(nprocs=4): seeds = [] seed_names = [] route_low = "! OPT B97-D3 def2-TZVP ECP{def2-TZVP} Grid7" extra_section_low = "" route_high = "! OPT PW6B95 def2-TZVP ECP{def2-TZVP} Grid7" extra_section_high = "" for seed in os.listdir("seed"): seeds.append(files.read_cml("seed/%s" % seed, allow_errors=True, test_charges=False)[0]) seed_names.append(seed.split(".cml")[0]) jobs = [] for i,seed in enumerate(seeds): charge = sum([a.type.charge for a in seed]) jobs.append( orca.job("seed_%d_low" % i, route_low, atoms=seed, extra_section=extra_section_low, charge=charge, grad=False, queue=QUEUE_TO_RUN_ON, procs=nprocs, sandbox=False) ) for j in jobs: j.wait() for i,seed in enumerate(seeds): charge = sum([a.type.charge for a in seed]) jobs.append( orca.job("seed_%d_high" % i, route_high, atoms=[], extra_section=extra_section_high, charge=charge, grad=False, queue=QUEUE_TO_RUN_ON, procs=nprocs, previous="seed_%d_low" % i, sandbox=False) ) for j in jobs: j.wait() for i,seed in enumerate(seeds): new_pos = orca.read("seed_%d_high" % i) if not new_pos.converged: print("Failed to optimize %s" % seed_names[i]) continue new_pos = new_pos.atoms cml_file = files.read_cml("seed/%s" % seed_names[i], allow_errors=True, test_charges=False, return_molecules=True) j=0 for mol in cml_file: for k,a in enumerate(mol.atoms): b = new_pos[j] a.x, a.y, a.z = b.x, b.y, b.z j += 1 files.write_cml(cml_file, name="seed/%s_opt" % seed_names[i])
def run_low_level(training_sets_folder="training_set", procs=1, queue=None, extra_parameters={}): if not os.path.exists(training_sets_folder): raise Exception("No training set folder to run.") frange = [int(a.split('.cml')[0]) for a in os.listdir(training_sets_folder) if a.endswith(".cml")] frange.sort() if len(frange) == 0: raise Exception("No viable files in training sets folder.") route = "! B97-D3 def2-TZVP GCP(DFT/TZ) ECP{def2-TZVP} Grid7" extra_section = "" running_jobs = [] for i in frange: atoms = files.read_cml("%s/%d.cml" % (training_sets_folder, i), allow_errors=True, test_charges=False, return_molecules=False, extra_parameters=extra_parameters)[0] charge = sum([a.type.charge for a in atoms]) running_jobs.append(orca.job("ts_%d" % i, route, atoms=atoms, extra_section=extra_section, charge=charge, grad=True, queue=queue, procs=procs, sandbox=False)) return running_jobs
def orca_start_job(spline_NEB, i, state, charge, procs, queue, initial_guess, extra_section, mem, priority): """ A method for submitting a single point calculation using Orca for spline_NEB calculations. **Parameters** spline_NEB: :class:`spline_NEB` A spline_NEB container holding the main spline_NEB simulation i: *int* The index corresponding to which image on the frame is to be simulated. state: *list,* :class:`structures.Atom` A list of atoms describing the image on the frame associated with index *i*. charge: *int* Charge of the system. procs: *int* The number of processors to use during calculations. queue: *str* Which queue to submit the simulation to (this is queueing system dependent). initial_guess: *str* The name of a previous simulation for which we can read in a hessian. extra_section: *str* Extra settings for this DFT method. mem: *int* How many MegaBytes (MB) of memory you have available per core. **Returns** orca_job: :class:`jobs.Job` A job container holding the orca simulation. """ if spline_NEB.step > 0: previous = '%s-%d-%d' % (spline_NEB.name, spline_NEB.step - 1, i) else: if initial_guess: if hasattr(initial_guess, '__iter__'): previous = initial_guess[i] else: previous = initial_guess else: previous = None return orca.job('%s-%d-%d' % (spline_NEB.name, spline_NEB.step, i), spline_NEB.theory, state, charge=charge, extra_section=extra_section, grad=True, procs=procs, queue=queue, previous=previous, mem=mem, priority=spline_NEB.priority)
def run_high_level(training_sets_folder="training_set", procs=1, queue=None, extra_parameters={}): if not os.path.exists(training_sets_folder): raise Exception("No training set folder to run.") frange = [ int(a.split('.cml')[0]) for a in os.listdir(training_sets_folder) if a.endswith(".cml") ] frange.sort() if len(frange) == 0: raise Exception("No viable files in training sets folder.") route = "! PW6B95 def2-TZVP GCP(DFT/TZ) ECP{def2-TZVP} Grid7" extra_section = "" running_jobs = [] previous_failed = [] for i in frange: atoms = files.read_cml("%s/%d.cml" % (training_sets_folder, i), allow_errors=True, test_charges=False, return_molecules=False, extra_parameters=extra_parameters)[0] charge = sum([a.type.charge for a in atoms]) prev_converged = orca.read("ts_%d" % i).converged if prev_converged: running_jobs.append( orca.job("ts_%d_high" % i, route, atoms=[], extra_section=extra_section, charge=charge, grad=True, queue=queue, procs=procs, previous="ts_%d" % i, sandbox=False)) else: previous_failed.append(i) return running_jobs, previous_failed
def run_high_level(): if not os.path.exists("training_sets"): raise Exception("No training set folder to run.") frange = [int(a.split('.cml')[0]) for a in os.listdir("training_sets") if a.endswith(".cml")] frange.sort() if len(frange) == 0: raise Exception("No viable files in training sets folder.") route = "! PW6B95 def2-TZVP GCP(DFT/TZ) ECP{def2-TZVP} Grid7" extra_section = "" running_jobs = [] previous_failed = [] for i in frange: atoms = files.read_cml("training_sets/%d.cml" % i, allow_errors=True, test_charges=False, return_molecules=False)[0] charge = sum([a.type.charge for a in atoms]) prev_converged = orca.read("ts_%d" % i).converged if prev_converged: running_jobs.append( orca.job("ts_%d_high" % i, route, atoms=[], extra_section=extra_section, charge=charge, grad=True, queue=QUEUE_TO_RUN_ON, procs=QUEUE_PROCS, previous="ts_%d" % i, sandbox=False) ) else: previous_failed.append(i) return running_jobs, previous_failed
def minimize_seeds(procs=4, queue=None, extra_parameters={}): """ A function to optimize the geometry of the supplied seeds in the seed directory. Each optimized structure is then added to the seed directory under the name "previous_name_opt.cml". **Parameters** procs: *int, optional* How many processors to use for this. queue: *str, optional* What queue to run the simulation on. """ seeds = [] seed_names = [] route_low = "! OPT B97-D3 def2-TZVP ECP{def2-TZVP} Grid7" extra_section_low = "" route_high = "! OPT PW6B95 def2-TZVP ECP{def2-TZVP} Grid7" extra_section_high = "" for seed in os.listdir("seed"): seeds.append( files.read_cml("seed/%s" % seed, allow_errors=True, test_charges=False, extra_parameters=extra_parameters)[0]) seed_names.append(seed.split(".cml")[0]) jobs = [] for i, seed in enumerate(seeds): charge = sum([a.type.charge for a in seed]) jobs.append( orca.job("seed_%d_low" % i, route_low, atoms=seed, extra_section=extra_section_low, charge=charge, grad=False, queue=queue, procs=procs, sandbox=False)) for j in jobs: j.wait() for i, seed in enumerate(seeds): charge = sum([a.type.charge for a in seed]) jobs.append( orca.job("seed_%d_high" % i, route_high, atoms=[], extra_section=extra_section_high, charge=charge, grad=False, queue=queue, procs=procs, previous="seed_%d_low" % i, sandbox=False)) for j in jobs: j.wait() for i, seed in enumerate(seeds): new_pos = orca.read("seed_%d_high" % i) if not new_pos.converged: print("Failed to optimize %s" % seed_names[i]) continue new_pos = new_pos.atoms cml_file = files.read_cml("seed/%s" % seed_names[i], allow_errors=True, test_charges=False, return_molecules=True, extra_parameters=extra_parameters) j = 0 for mol in cml_file: for k, a in enumerate(mol.atoms): b = new_pos[j] a.x, a.y, a.z = b.x, b.y, b.z j += 1 files.write_cml(cml_file, name="seed/%s_opt" % seed_names[i])
def orca_start_job(NEB, i, state, charge, multiplicity, procs, queue, initial_guess, extra_section, mem, priority, extra_keywords={}): """ A method for submitting a single point calculation using Orca for NEB calculations. **Parameters** NEB: :class:`NEB` An NEB container holding the main NEB simulation i: *int* The index corresponding to which image on the frame is to be simulated. state: *list,* :class:`structures.Atom` A list of atoms describing the image on the frame associated with index *i*. charge: *int* Charge of the system. multiplicity: *int* Multiplicity of the system. procs: *int* The number of processors to use during calculations. queue: *str* Which queue to submit the simulation to (this is queueing system dependent). initial_guess: *str* The name of a previous simulation for which we can read in a hessian. extra_section: *str* Extra settings for this DFT method. mem: *int* How many MegaBytes (MB) of memory you have available per core. priority: *int* Whether to submit to NBS with a given priority extra_keywords: *dict, optional* Specify extra keywords beyond the defaults. **Returns** orca_job: :class:`jobs.Job` A job container holding the orca simulation. """ orca4 = True if "orca4" in extra_keywords: orca4 = extra_keywords["orca4"] NEB.calls_to_force += 1 if NEB.step > 0: previous = '%s-%d-%d' % (NEB.name, NEB.step - 1, i) else: if initial_guess: if hasattr(initial_guess, '__iter__'): previous = initial_guess[i] else: previous = initial_guess else: previous = None return orca.job('%s-%d-%d' % (NEB.name, NEB.step, i), NEB.theory, state, charge=charge, multiplicity=multiplicity, extra_section=extra_section, grad=True, procs=procs, queue=queue, previous=previous, mem=mem, priority=NEB.priority, orca4=orca4)
def generate_lead_halide_cation(halide, cation, ion="Pb", run_opt=True): cml_path = fpl_constants.cml_dir # Check if system exists fname = reduce_to_name(ion, halide, cation) if not cml_path.endswith("/"): cml_path += "/" if os.path.exists(cml_path + fname + ".cml"): print("Found system in cml folder, returning system") system = structures.Molecule( files.read_cml(cml_path + fname + ".cml", test_charges=False, allow_errors=True)[0]) return system def vdw(y): return PERIODIC_TABLE[units.elem_s2i(y)]['vdw_r'] # Get the PbX3 system PbX3 = generate_lead_halide(halide, ion=ion) # Get the cation from the cml file atoms, bonds, _, _ = files.read_cml(cml_path + cation + ".cml", test_charges=False, allow_errors=True) system = structures.Molecule(atoms) # Align along X axis system.atoms = geometry.align_centroid(system.atoms)[0] # Rotate to Z axis # NOTE! In case of FA, we want flat so only translate to origin instead # NOTE! We have exactly 3 cations we observe: Cs, MA, FA. If 2 N, then FA elems = [a.element for a in system.atoms] if elems.count("N") == 2: system.translate(system.get_center_of_mass()) else: R = geometry.rotation_matrix([0, 1, 0], 90, units="deg") system.rotate(R) # If N and C in system, ensure N is below C (closer to Pb) if "N" in elems and "C" in elems: N_index = [i for i, a in enumerate(system.atoms) if a.element == "N"][0] C_index = [i for i, a in enumerate(system.atoms) if a.element == "C"][0] if system.atoms[N_index].z > system.atoms[C_index].z: # Flip if needed R = geometry.rotation_matrix([0, 1, 0], 180, units="deg") system.rotate(R) # Offset system so lowest point is at 0 in the z dir z_offset = min([a.z for a in system.atoms]) * -1 system.translate([0, 0, z_offset]) # Add to the PbX3 system with an offset of vdw(Pb) system.translate([0, 0, vdw(ion)]) system.atoms += PbX3.atoms # Run a geometry optimization of this system if run_opt: PbXY = orca.job(fname, fpl_constants.default_routes[0], atoms=system.atoms, extra_section=fpl_constants.extra_section, queue="batch", procs=2) PbXY.wait() new_pos = orca.read(fname).atoms for a, b in zip(system.atoms, new_pos): a.x, a.y, a.z = [b.x, b.y, b.z] # Set OPLS types for a in system.atoms: if a.element in [ion, "Cl", "Br", "I"]: a.type = fpl_constants.atom_types[a.element] a.type_index = a.type["index"] # Write cml file so we don't re-generate, and return system files.write_cml(system, bonds=bonds, name=cml_path + fname + ".cml") return system
def minimize_seeds(procs=4, queue=None, extra_parameters={}): """ A function to optimize the geometry of the supplied seeds in the seed directory. Each optimized structure is then added to the seed directory under the name "previous_name_opt.cml". **Parameters** procs: *int, optional* How many processors to use for this. queue: *str, optional* What queue to run the simulation on. """ seeds = [] seed_names = [] route_low = "! OPT B97-D3 def2-TZVP ECP{def2-TZVP} Grid7" extra_section_low = "" route_high = "! OPT PW6B95 def2-TZVP ECP{def2-TZVP} Grid7" extra_section_high = "" for seed in os.listdir("seed"): seeds.append(files.read_cml("seed/%s" % seed, allow_errors=True, test_charges=False, extra_parameters=extra_parameters)[0]) seed_names.append(seed.split(".cml")[0]) jobs = [] for i, seed in enumerate(seeds): charge = sum([a.type.charge for a in seed]) jobs.append(orca.job("seed_%d_low" % i, route_low, atoms=seed, extra_section=extra_section_low, charge=charge, grad=False, queue=queue, procs=procs, sandbox=False)) for j in jobs: j.wait() for i, seed in enumerate(seeds): charge = sum([a.type.charge for a in seed]) jobs.append(orca.job("seed_%d_high" % i, route_high, atoms=[], extra_section=extra_section_high, charge=charge, grad=False, queue=queue, procs=procs, previous="seed_%d_low" % i, sandbox=False)) for j in jobs: j.wait() for i, seed in enumerate(seeds): new_pos = orca.read("seed_%d_high" % i) if not new_pos.converged: print("Failed to optimize %s" % seed_names[i]) continue new_pos = new_pos.atoms cml_file = files.read_cml("seed/%s" % seed_names[i], allow_errors=True, test_charges=False, return_molecules=True, extra_parameters=extra_parameters) j = 0 for mol in cml_file: for k, a in enumerate(mol.atoms): b = new_pos[j] a.x, a.y, a.z = b.x, b.y, b.z j += 1 files.write_cml(cml_file, name="seed/%s_opt" % seed_names[i])