def main(in_xyz, in_log, target, output, bonding, thresh, kind): if (in_xyz): mol = rf.mol_from_file(in_xyz) else: mol = rf.mol_from_gauss(in_log) charges = rf.read_g_char(in_log, kind)[0] cluster = rf.mol_from_file(target) mol.set_bonding(bonding=bonding, thresh=thresh) cluster.set_bonding(bonding=bonding, thresh=thresh) for atom, char in zip(mol, charges): atom.q = char assign_charges(mol, cluster) # warning if some atoms have not been assigned or if some original charges # were 0 bad_atoms = [] for atom in cluster: if abs(atom.q) <= 0.000: bad_atoms.append(atom) if len(bad_atoms) > 0: print("WARNING: " + str(len(bad_atoms)) + " atoms have null charge!") print(bad_atoms) out_file = open(output, "w") out_file.write(str(len(cluster)) + "\n\n") for atom in cluster: out_file.write(str(atom) + "\n") out_file.close()
def read_out_mol(self, pop="EPS"): """Read the output log file and return Mol""" gauss_path = os.path.join(self.here, self.calc_name) os.chdir(gauss_path) out_mol = rf.mol_from_gauss(self.calc_name + ".log") os.chdir(self.here) return out_mol
def populate_cell(in_mol, program, pop_file, method): """ Assign charge to the atoms from a unit cell Don't import this. If you want to assign charges go straign to assign_charges.py and use those utilities. Parameters ---------- in_mol : Mol object Make sure these atoms form a unit cell. program : str Make it "gaussian" or "cp2k" pop_file : str The corresponding file to read charges from method : str Acceptable strings are "esp", "mulliken" and "hirshfeld" """ output_file = open(here + "/prep.out", "a") if program.lower() == "cp2k": charges = rf.read_cp2k(pop_file, method)[0] output_file.write("Read " + str(len(in_mol)) + " charges in cp2k_file\n") # in case there are more charges than atoms charges = charges[:len(in_mol)] # correct charges if they are not perfectly neutral if sum(charges) != 0.0: output_file.write("Charge correction: " + str(sum(charges)) + "\n") charges[-1] -= sum(charges) if program.lower() == "gaussian": mol_char = rf.mol_from_gauss(pop_file, pop=method) mol_char.bonding = in_mol.bonding mol_char.thresh = in_mol.thresh charges = [i.q for i in mol_char] # correct charges if they are not perfectly neutral if sum(charges) != 0.0: output_file.write("Charge correction: " + str(sum(charges)) + "\n") mol_char[-1].q -= sum(charges) # assign charges to the rest of the cell in_mol.populate(mol_char) output_file.close() return
def make_region_2(self): """ Get region 2 Mols with different charges Returns ------- shell_high : Mol object Region 2 molecules with high level of theory charges shell_low : Mole object Region 2 molecules with low level of theory charges """ if self.inputs["target_shell"]: shell_high = rf.mol_from_file(self.inputs["target_shell"]) self.write_out("Outer region read in with " + str(len(shell_high)) + " atoms.\n") high_level_pop_mol = rf.mol_from_gauss( self.inputs["high_pop_file"], pop=self.inputs["high_pop_method"]) shell_high.populate(high_level_pop_mol) else: shell_high = self.cell.make_cluster(self.inputs["clust_rad"], central_mol=self.region_1, mode=self.inputs["clust_mode"]) for atom_i in self.region_1: for atom_j in shell_high: if atom_i.very_close(atom_j): shell_high.remove(atom_j) break self.write_out("Outer region generated with " + str(len(shell_high)) + " atoms.\n") low_level_pop_mol = rf.mol_from_gauss( self.inputs["low_pop_file"], pop=self.inputs["low_pop_method"]) shell_low = shell_high.copy() shell_low.populate(low_level_pop_mol) return shell_low, shell_high
def pery_solo(): """Return a Mol object of a charged perylene""" out_mol = rf.mol_from_gauss("perylene_pop.log") return out_mol
def benz_solo(): """Return a Mol object of a charged benzene""" out_mol = rf.mol_from_gauss("benzene_pop.log") return out_mol