def main(): res = VibTools.SNFResults(outname='Ala10/snf.out', restartname='Ala10/restart', coordfile='Ala10/coord') res.read() plots = [] # numbers of the amide I modes ml = range(241, 250) modes = res.modes.get_subset(ml) lv = VibTools.LocVib(modes, 'PM') lv.localize() lv.sort_by_residue() lv.adjust_signs() # vibrational coupling constants cmat = lv.get_couplingmat() print print "Vibrational coupling matrix [in cm-1]" print_mat(cmat) # intensity coupling constants lma = VibTools.LocModeAnalysis(res, 'ROA', lv.locmodes) intcmat = lma.get_intensity_coupling_matrix() print print "Intensity coupling matrix for ROA backscattering" print_mat(1000.0 * intcmat)
def localize_subsets(modes, subsets): # method that takes normal modes and list of lists (beginin and end) # of subsets and make one set of modes localized in subsets # first get number of modes in total total = 0 modes_mw = np.zeros((0, 3 * modes.natoms)) freqs = np.zeros((0, )) for subset in subsets: n = subset[1] - subset[0] total += n print 'Modes localized: %i, modes in total: %i' % (total, modes.nmodes) if total > modes.nmodes: raise Exception( 'Number of modes in the subsets is larger than the total number of modes' ) else: cmat = np.zeros((total, total)) actpos = 0 #actual position in the cmat matrix for subset in subsets: tmp = localize_subset(modes, range(subset[0], subset[1])) modes_mw = np.concatenate((modes_mw, tmp[0]), axis=0) freqs = np.concatenate((freqs, tmp[1]), axis=0) cmat[actpos:actpos + tmp[2].shape[0], actpos:actpos + tmp[2].shape[0]] = tmp[2] actpos = actpos + tmp[2].shape[0] localmodes = VibTools.VibModes(total, modes.mol) localmodes.set_modes_mw(modes_mw) localmodes.set_freqs(freqs) return localmodes, cmat
def main(): res = VibTools.SNFResults(outname='Ala10/snf.out', restartname='Ala10/restart', coordfile='Ala10/coord') res.read() # numbers of amide I normal modes (found with composition.py) ml = range(241, 250) modes = res.modes.get_subset(ml) backint = res.get_backscattering_int(modes=modes) lv = VibTools.LocVib(modes, 'PM') lv.localize() lv.sort_by_residue() lv.adjust_signs() print print "Composition of localized modes: " lv.locmodes.print_attype2_composition() lv.locmodes.print_residue_composition() # write localized modes to g98-style file lv.locmodes.write_g98out(filename="locmodes-amide1.out") backint_loc = res.get_backscattering_int(modes=lv.locmodes) print print "ROA backscattering intensities of normal modes and localized modes" print print " normal modes | localized modes " print " freq int | freq int" n = 0 for i, f, bi, f_loc, bi_loc in zip(ml, modes.freqs, backint * 1e3, lv.locmodes.freqs, backint_loc * 1e3): n = n + 1 print r"%i %6.1f %8.2f | %2i %6.1f %8.2f" % (i, f, bi, n, f_loc, bi_loc) print print "Total ROA Int : ", backint.sum() * 1e3
def get_molecule(self, modes, points): """ Same as L{get_grid_structure} but returns VibTools molecule object. """ import VibTools mol = VibTools.VibToolsMolecule() (atoms, coords) = self.get_grid_structure(modes, points) mol.add_atoms(atoms, coords) return mol
def localize_subset(modes, subset): # method that takes normal modes # and a range of modes, returns them # localized + the cmat tmpmodes = modes.get_subset(subset) tmploc = VibTools.LocVib(tmpmodes, 'PM') tmploc.localize() tmploc.sort_by_residue() tmploc.adjust_signs() tmpcmat = tmploc.get_couplingmat(hessian=True) return tmploc.locmodes.modes_mw, tmploc.locmodes.freqs, tmpcmat
def main(): res = VibTools.SNFResults(outname='Ala10/snf.out', restartname='Ala10/restart', coordfile='Ala10/coord') res.read() # change here to range of modes which are possibly of interest ml = range(140, 251) modes = res.modes.get_subset(ml) irint = res.get_ir_intensity(modes) ri = res.get_raman_int(modes) bi = res.get_backscattering_int(modes) labels = [ "%i %6.1f %10.4f %10.4f %10.4f " % (i, f, ir, r, b) for i, f, ir, r, b in zip(ml, modes.freqs, irint, ri, bi) ] modes.print_attype2_composition(labels)
import VibTools import Vibrations as vib import numpy as np import os res = VibTools.SNFResults(outname='snf_h2o/snf.out', restartname='snf_h2o/restart', coordfile='snf_h2o/coord') res.read() # use the normal modes in the following (no localization) modes = res.modes # Define the grid ngrid = 16 amp = 14 grid = vib.Grid(res.mol, modes) grid.generate_grids(ngrid, amp) # Read in anharmonic 1-mode potentials v1 = vib.Potential(grid, order=1) v1.read_np(os.path.join('potentials', 'V1_g16.npy')) # Read in anharmonic 1-mode dipole moments dm1 = vib.Dipole(grid) dm1.read_np(os.path.join('potentials', 'Dm1_g16.npy'))
cmat[actpos:actpos + tmp[2].shape[0], actpos:actpos + tmp[2].shape[0]] = tmp[2] actpos = actpos + tmp[2].shape[0] localmodes = VibTools.VibModes(total, modes.mol) localmodes.set_modes_mw(modes_mw) localmodes.set_freqs(freqs) return localmodes, cmat # The vibrations script begins here # Read in normal modes from SNF results # using VibTools (LocVib package) res = VibTools.SNFResults() res.read() # Now localize modes in separate subsets subsets = [[0, 4], [4, 8], [8, 12]] localmodes, cmat = localize_subsets(res.modes, subsets) # Define the grid ngrid = 16 amp = 14 grid = vib.Grid(res.mol, localmodes) grid.generate_grids(ngrid, amp)
def _read_snf_output(self, readagain=False): """ Read in the I{SNF} results from the output file. The read values are stored in attributes. This speeds up further retrievals of results. @param readagain: If this is set C{True}, the data will be re-read from the I{SNF} output file even if this has allready been done before. @bug: The used C{VibTools} routine doesn't work for linear molecules. You'll get weired errors in that case. @requires: C{VibTools} @raises PyAdfError: For diatomic molecules. """ # First we see if the `VibTools' are available. If that import failes, # we re-raise a more descriptive exception. try: import VibTools except ImportError: raise PyAdfError("""I couldn't import the `VibTools' module. Please make sure it can be found along your `$PYTONPATH'. I need that module to read in the I{SNF} results.""") # Next see, if we need to (re-)read the data or if we have it allready # handy. Re-reading will be a costy thing since we'll have to extract a # total of three files from our tarball to temporary files, read them # and delete them afterwards. Lots of OS level IO. if (self.vibs is None) or readagain: # We rely on the `VibTools' module by Christoph Jacob to read the # `SNF' output. That module has a bug (see below) but we hope that # it will be fixed soon. Since the `VibTools.SNFResults' object # needs reading access to the `snf.out', `restart' and `coord' file # on instanziation, we get us temporary copies of those and pass # the initializator the filenames. We'll delete these files once # everything is done. For the sake of easier handling, we make us a # dictionary that mappes the original file names (e.g. `coord') to # the names of the temporary copies (e.g. `/tmp/tmpBGr7Hh'). # (Using the `__del__' method for this cleanup and keeping the # files as a class attribute is not a safe solution since Python's # way to invoke garbage collection is REALLY unreliable.) needed_files = ['snf.out', 'restart', 'coord'] temp_copies = {} try: for needed_file in needed_files: temp_copies[needed_file] = self.get_temp_result_filename( needed_file) vibs = VibTools.SNFResults(outname=temp_copies['snf.out'], restartname=temp_copies['restart'], coordfile=temp_copies['coord']) vibs.read() self.vibs = vibs finally: for key, value in temp_copies.iteritems(): try: os.remove(value) except OSError: pass # okay, that tempfile doesn't bother us that much
def __init__(self, dirname): f = open(dirname + '/grid_params') lines = f.readlines() f.close() whichmodes = None localized = None if os.path.isfile(dirname + '/whichmodes'): whichmodes = [] f = open(dirname + '/whichmodes') lines2 = f.readlines() f.close for l in lines2: for el in l.split(): whichmodes.append(int(el)) grid_params = lines[0].split() self.ngrid = int(grid_params[0]) self.amp = int(grid_params[1]) res = VibTools.SNFResults(outname=dirname + '/snf.out', restartname=dirname + '/restart', coordfile=dirname + '/coord') res.read() self.freqs = res.modes.freqs self.ints = res.get_ir_intensity() modes = res.modes if whichmodes is not None: self.freqs = res.modes.freqs[whichmodes] self.ints = res.get_ir_intensity( modes=res.modes.get_subset(whichmodes)) modes = res.modes.get_subset(whichmodes) self.grid = vib.Grid(res.mol, modes) self.grid.generate_grids(self.ngrid, self.amp) self.v1 = vib.Potential(self.grid, 1) self.v1.read_np(dirname + '/v1.npy') self.v1_harm = vib.Potential(self.grid, 1) self.v1_harm.generate_harmonic() self.dm1_harm = vib.Dipole(self.grid, 1) self.dm1_harm.generate_harmonic(res) self.v2 = vib.Potential(self.grid, 2) self.v2.read_np(dirname + '/v2.npy') self.dm1 = vib.Dipole(self.grid, 1) self.dm1.read_np(dirname + '/dm1.npy') self.dm2 = vib.Dipole(self.grid, 2) self.dm2.read_np(dirname + '/dm2.npy') self.diagonal_eigv = np.load(dirname + '/diagonal_eigv.npy') self.vscf_singles_energies = np.load(dirname + '/vscf_singles.npy') self.vci1 = np.load(dirname + '/vci1.npy') self.vci2 = np.load(dirname + '/vci2.npy') self.vci3 = np.load(dirname + '/vci3.npy') self.vci4 = np.load(dirname + '/vci4.npy') self.vci1_int = np.load(dirname + '/vci1_int.npy')