def main(): """ Reads a structure from a Gaussian Log file and other parameters from a Gaussian Com file and creates a new Gaussian Com. """ args = get_args() gaulog = GaussianLog(args.log) gaucom = GaussianCom(args.template_com) atoms_log_coords = gaulog.read_geometry(args.opt_step, args.scan_step) for no, atom in enumerate(gaucom.atoms_list): atom.SetVector(atoms_log_coords[no].GetVector()) gaucom.write_to_file(args.new_com)
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:d:') except getopt.GetoptError as err: sys.stderr.write(str(err) + '\n') if len(args) < 1: usage() print('Missing:') print(' gaussian_input.com') sys.exit(2) elif len(args) > 1: usage() print('Hey! Too many args:') print(' %s' % (', '.join(args))) gaussian_com_filename = args[0] new_folder_name = 'residel' freeze_angs = 15 for o, a in opts: if o == '-f': freeze_angs = float(a) if o == '-d': new_folder_name = a if not os.path.exists("./{}".format(new_folder_name)): os.makedirs(new_folder_name) # input gaussian_file = GaussianCom(gaussian_com_filename) resID_dict = build_resID_dict(gaussian_file.atoms_list) # get xyz tuples highlayer_xyz = [] all_xyz = [] non_wat_xyz = [] for i,atom in enumerate(gaussian_file.atoms_list): if atom.oniom.layer == 'H': highlayer_xyz.append((atom.GetX(), atom.GetY(), atom.GetZ())) if not atom.resinfo.resname == 'WAT' or atom.oniom.layer == 'H': non_wat_xyz.append((atom.GetX(), atom.GetY(), atom.GetZ())) all_xyz.append((atom.GetX(), atom.GetY(), atom.GetZ())) if not len(highlayer_xyz): print('WELL WELL...') print(' no highlayer defined, freezing nothing') else: # indexes to freeze CUTOFF = freeze_angs + 1.0 freeze_idx = [False for _ in all_xyz] for (i,xyz) in enumerate(all_xyz): atom = gaussian_file.atoms_list[i] tofreeze = min_dist( [xyz] , highlayer_xyz, CUTOFF) <= freeze_angs freeze_idx[i] = tofreeze if atom.resinfo.resname == 'WAT' or atom.oniom.layer == 'H': freeze_idx[i] = False # byres freeze_idx = byres(resID_dict, freeze_idx) # residue selection res_2_go = list(set(get_resID(gaussian_file.atoms_list[i]) for i in np.where(freeze_idx)[0])) atoms_list = gaussian_file.atoms_list residues_list = Molecule("protein", atoms_list).make_residues_list() input_list = [] for no, residue in enumerate(residues_list): if get_resID(residue[0]) not in res_2_go: continue residue_number_name = "{0.resinfo.resnum}_{0.resinfo.resname}".format(residue[0]) print(residue_number_name) incomplete_residues_list = Molecule("protein", atoms_list).make_residues_list() incomplete_residues_list.remove(residue) new_atoms_list = [] for res in incomplete_residues_list: new_atoms_list.extend(res) gaussian_file.atoms_list = new_atoms_list gaussian_file.redo_connectivity_list() no_electrons = 0 # correct link atom number and count total number of electrons for i, atom in enumerate(new_atoms_list): no_electrons += atom.GetAtomicNum() if atom.oniom.link_bound_to: if int(atom.oniom.link_bound_to) > atoms_list.index(residue[0]): atom.oniom.link_bound_to = str(int(atom.oniom.link_bound_to) - len(residue)) #correct charge and multiplicity new_protein = Molecule("new_protein", new_atoms_list) charge = sum([res.get_charge() for res in incomplete_residues_list]) no_electrons -= round(charge) multiplicity = int(gaussian_file.multiplicity_line.split()[1]) if (no_electrons%2==0 and multiplicity-1%2!=0) or (no_electrons%2==1 and multiplicity-1%2!=1): print("Number of electrons and multiplicity are not compatible. Charge increased arbitrarily by one") charge += 1 gaussian_file.multiplicity_line = "{0} {1}\n".format(int(round(charge))," ".join(gaussian_file.multiplicity_line.split()[1:])) gaussian_name = "{0}_{1}.com".format(gaussian_com_filename[:-4],residue_number_name) gaussian_file.write_to_file("{0}/{1}".format(new_folder_name, gaussian_name)) input_list.append(gaussian_name) script_file_name = "{0}/{1}".format(new_folder_name,"run.sh") with open(script_file_name, 'w') as run_script: for job in input_list: out_name = job[:-4]+".log" run_script.write("g09 {0} {1}\n".format(job,out_name))
def main(): gaussian_com_filename = sys.argv[1] new_folder_name = os.path.splitext(sys.argv[1])[0] freeze_angs = 15 if not os.path.exists("./{}".format(new_folder_name)): os.makedirs(new_folder_name) # input gaussian_file = GaussianCom(gaussian_com_filename) resID_dict = build_resID_dict(gaussian_file.atoms_list) # get xyz tuples highlayer_xyz = [] all_xyz = [] non_wat_xyz = [] #all MM and non waters for i,atom in enumerate(gaussian_file.atoms_list): if atom.oniom.layer == 'H': highlayer_xyz.append((atom.GetX(), atom.GetY(), atom.GetZ())) if not atom.resinfo.resname == 'WAT' or atom.oniom.layer == 'H': non_wat_xyz.append((atom.GetX(), atom.GetY(), atom.GetZ())) all_xyz.append((atom.GetX(), atom.GetY(), atom.GetZ())) if not len(highlayer_xyz): print('WELL WELL...') print(' no highlayer defined, freezing nothing') else: # indexes to freeze [list of atoms to "freeze"] CUTOFF = freeze_angs + 1.0 freeze_idx = [False for _ in all_xyz] for (i,xyz) in enumerate(all_xyz): atom = gaussian_file.atoms_list[i] tofreeze = min_dist( [xyz] , highlayer_xyz, CUTOFF) <= freeze_angs freeze_idx[i] = tofreeze if atom.resinfo.resname == 'WAT' or atom.oniom.layer == 'H': freeze_idx[i] = False # byres - returns the same freeze_idx list, but if at least one atom is true, then changes all to True freeze_idx = byres(resID_dict, freeze_idx) # residue selection [list of tuples (resn, resid)] res_2_go = list(set(get_resID(gaussian_file.atoms_list[i]) for i in np.where(freeze_idx)[0])) old_atoms_list = gaussian_file.atoms_list residues_list = Molecule("protein", old_atoms_list).make_residues_list() # do the magic for no, residue in enumerate(residues_list): if get_resID(residue[0]) not in res_2_go: continue #NOTA: a lista de residues (residue[0]) parece uma [lista de residues[lista atoms]] devo conseguir descompactar isto resname = residue[0].resinfo.resname resid = residue[0].resinfo.resnum residue_number_name = "{0}_{1}".format(resname,resid) original_charges = zerate_res_charge(old_atoms_list, (resname, resid)) #print(residue_number_name) gaussian_name = "{0}_{1}.com".format( gaussian_com_filename[:-4], residue_number_name ) gaussian_file.write_to_file("{0}/{1}".format( new_folder_name, gaussian_name) ) reset_res_charge(old_atoms_list, (resname, resid), original_charges)