def main(): M = Molecule(opts.coords) if len(M.molecules) != 1: raise RuntimeError( 'Input coordinates must be a single contiguous molecule') if opts.phi1 == None: raise RuntimeError( 'phi1 (the first quartet of atoms) must be provided') xyzout = [] commout = [] xyzcsh = [] commcsh = [] if opts.phi2 != None: # Two dimensional scan for inc1 in range(0, 360, opts.scan): for inc2 in range(0, 360, opts.scan): xyzrot, clash = get_rotated_xyz(M, [opts.phi1, opts.phi2], [inc1, inc2]) print(inc1, inc2, "Clash" if clash else "Ok") comm = "Dihedrals %s, %s set to %i, %i" % (str( opts.phi1), str(opts.phi2), inc1, inc2) if clash: xyzcsh.append(xyzrot.copy()) commcsh.append(comm) else: xyzout.append(xyzrot.copy()) commout.append(comm) else: # One dimensional scan for inc1 in range(0, 360, opts.scan): xyzrot, clash = get_rotated_xyz(M, [opts.phi1], [inc1]) print(inc1, "Clash" if clash else "Ok") comm = "Dihedral %s set to %i" % (str(opts.phi1), inc1) if clash: xyzcsh.append(xyzrot.copy()) commcsh.append(comm) else: xyzout.append(xyzrot.copy()) commout.append(comm) if len(xyzout) > 0: M.xyzs = xyzout M.comms = commout M.write( os.path.splitext(opts.coords)[0] + "_out" + os.path.splitext(opts.coords)[1]) if len(xyzcsh) > 0: M.xyzs = xyzcsh M.comms = commcsh M.write( os.path.splitext(opts.coords)[0] + "_clash" + os.path.splitext(opts.coords)[1])
def write_fb_target_abinitio(self, records): """ Write a list of {'energy': xxx, 'molecule': xxx, 'name': xxx} records into a new target folder """ # prepare folder for writing target_name = 'abinitio_bond_angles' target_folder = os.path.join(self.out_folder, target_name) os.mkdir(target_folder) os.chdir(target_folder) # load data into a fb Molecule out_m = Molecule() out_m.elem = self.m.elem.copy() out_m.xyzs = [] out_m.qm_energies = [] out_m.comms = [] for record in records: qcmol = record['molecule'] energy = record['energy'] name = record.get('name', 'created by FBTargetBuilder') m = self.qc_molecule_to_fb_molecule(qcmol) assert m.elem == out_m.elem, 'Elements list of resulting qcmol is not consistent with self.m' # append geometry out_m.xyzs.append(m.xyzs[0]) # append energy out_m.qm_energies.append(energy) # append name out_m.comms.append(name) # write output print( f"Writing {len(records)} frames into targets/abinitio_bond_angles/traj.xyz" ) out_m.write('traj.xyz') print( f"Writing {len(records)} frames into targets/abinitio_bond_angles/qdata.txt" ) out_m.write('qdata.txt')
def main(): M = Molecule(opts.coords) if len(M.molecules) != 1: raise RuntimeError('Input coordinates must be a single contiguous molecule') if opts.phi1 == None: raise RuntimeError('phi1 (the first quartet of atoms) must be provided') xyzout = [] commout = [] xyzcsh = [] commcsh = [] if opts.phi2 != None: # Two dimensional scan for inc1 in range(0, 360, opts.scan): for inc2 in range(0, 360, opts.scan): xyzrot, clash = get_rotated_xyz(M, [opts.phi1, opts.phi2], [inc1, inc2]) print(inc1, inc2, "Clash" if clash else "Ok") comm = "Dihedrals %s, %s set to %i, %i" % (str(opts.phi1), str(opts.phi2), inc1, inc2) if clash: xyzcsh.append(xyzrot.copy()) commcsh.append(comm) else: xyzout.append(xyzrot.copy()) commout.append(comm) else: # One dimensional scan for inc1 in range(0, 360, opts.scan): xyzrot, clash = get_rotated_xyz(M, [opts.phi1], [inc1]) print(inc1, "Clash" if clash else "Ok") comm = "Dihedral %s set to %i" % (str(opts.phi1), inc1) if clash: xyzcsh.append(xyzrot.copy()) commcsh.append(comm) else: xyzout.append(xyzrot.copy()) commout.append(comm) if len(xyzout) > 0: M.xyzs = xyzout M.comms = commout M.write(os.path.splitext(opts.coords)[0]+"_out"+os.path.splitext(opts.coords)[1]) if len(xyzcsh) > 0: M.xyzs = xyzcsh M.comms = commcsh M.write(os.path.splitext(opts.coords)[0]+"_clash"+os.path.splitext(opts.coords)[1])
from forcebalance.readfrq import read_frq_gen # Frequency output file. fout = sys.argv[1] # Mode number, starting from 1. modenum = int(sys.argv[2]) if modenum == 0: raise RuntimeError("Start mode number from one, please") frqs, modes, intens, elem, xyz = read_frq_gen(fout) M = Molecule() M.elem = elem[:] M.xyzs = [] xmode = modes[modenum - 1] xmode /= (np.linalg.norm(xmode)/np.sqrt(M.na)) xmode *= 0.3 # Reasonable vibrational amplitude spac = np.linspace(0, 1, 101) disp = np.concatenate((spac, spac[::-1][1:], -1*spac[1:], -1*spac[::-1][1:-1])) for i in disp: M.xyzs.append(xyz+i*xmode.reshape(-1,3)) M.comms = ['Vibrational Mode %i Frequency %.3f Displacement %.3f' % (modenum, frqs[modenum-1], disp[i]*(np.linalg.norm(xmode)/np.sqrt(M.na))) for i in range(len(M))] M.write(os.path.splitext(fout)[0]+'.mode%03i.xyz' % modenum)
import os, sys, re import numpy as np from forcebalance.molecule import Molecule from forcebalance.readfrq import read_frq_psi # Psi4 output file. psiout = sys.argv[1] # Mode number, starting from 1. modenum = int(sys.argv[2]) frqs, modes, elem, xyz = read_frq_psi(psiout) M = Molecule() M.elem = elem[:] M.xyzs = [] xmode = modes[modenum - 1] xmode /= (np.linalg.norm(xmode)/np.sqrt(M.na)) xmode *= 0.3 # Reasonable vibrational amplitude spac = np.linspace(0, 1, 101) disp = np.concatenate((spac, spac[::-1][1:], -1*spac[1:], -1*spac[::-1][1:-1])) for i in disp: M.xyzs.append(xyz+i*xmode) M.comms = ['Vibrational Mode %i Frequency %.3f Displacement %.3f' % (modenum, frqs[modenum-1], disp[i]*(np.linalg.norm(xmode)/np.sqrt(M.na))) for i in range(len(M))] M.write(os.path.splitext(psiout)[0]+'.mode%03i.xyz' % modenum)