copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ #!/usr/bin/env python import os import sys from Harmonics import * file = sys.argv[1] Kcos = [] Ksin = [] harmonic = Harmonics(5, Kcos, Ksin) harmonic.fitPotential(file) for i in range(5): print harmonic.Kcos[i], harmonic.Ksin[i] for i in range(5): print harmonic.Kcos[i], " ", "%3.1f" % (float(i + 1)) for i in range(5): print harmonic.Ksin[i], " ", "%3.1f" % (float(i + 1))
def __init__(self, file, isTS): self.Freq = [] self.Harmonics = [] self.hindFreq = [] self.bonds = [] self.Etype = '' self.TS = isTS self.E0 = [] self.variableInertia = False #read dummy line "MOL #" line = readGeomFc.readMeaningfulLine(file) #self.linearity = line.split()[0].upper #read linearity line = readGeomFc.readMeaningfulLine(file) if line.split()[0].upper() == 'NONLINEAR': self.linearity = 'Nonlinear' elif line.split()[0].upper() == 'LINEAR': self.linearity = 'Linear' elif line.split()[0].upper() == 'ATOM': self.linearity = 'Atom' else: print 'Linearity keyword not recognized ' + line exit() #linearity = line.split()[0].upper # read geometry line = readGeomFc.readMeaningfulLine(file) tokens = line.split() if tokens[0].upper() != 'GEOM': print 'Geom keyword not found in the input file' + line exit() if len(tokens) == 1: #geometry is given following the GEOM keyword line = readGeomFc.readMeaningfulLine(file) numAtoms = int(line.split()[0]) self.geom = matrix(array(zeros((numAtoms, 3), dtype=float))) self.Mass = matrix(array(zeros((numAtoms, 1), dtype=float))) for i in range(numAtoms): line = readGeomFc.readMeaningfulLine(file) tokens = line.split() self.geom[i, 0] = double(tokens[3]) self.geom[i, 1] = double(tokens[4]) self.geom[i, 2] = double(tokens[5]) atomicNum = int(tokens[1]) if (atomicNum == 6): self.Mass[i] = 12.0 if (atomicNum == 8): self.Mass[i] = 15.99491 if (atomicNum == 1): self.Mass[i] = 1.00783 if (atomicNum == 7): self.Mass[i] = 14.0031 if (atomicNum == 17): self.Mass[i] = 34.96885 if (atomicNum == 16): self.Mass[i] = 31.97207 if (atomicNum == 9): self.Mass[i] = 18.99840 #read geometry from the file elif tokens[1].upper() == 'FILE': print "reading Geometry from the file: ", tokens[2] geomFile = open(tokens[2], 'r') (self.geom, self.Mass) = readGeomFc.readGeom(geomFile) #print self.geom elif tokens[1].upper() == 'MM4FILE': #mm4 option added by gmagoon print "reading MM4 Geometry from the file: ", tokens[2] geomFile = open(tokens[2], 'r') (self.geom, self.Mass) = readGeomFc.readMM4Geom(geomFile) #print self.geom else: print 'Either give geometry or give keyword File followed by the file containing geometry data' exit() self.calculateMomInertia() # read force constant or frequency data line = readGeomFc.readMeaningfulLine(file) tokens = line.split() if tokens[0].upper() == 'FORCEC' and tokens[1].upper() == 'FILE': #MRH added following line on 2/Dec/2009 if self.linearity != 'Atom': fcfile = open(tokens[2], 'r') self.Fc = readGeomFc.readFc(fcfile) for i in range(0, 3 * self.Mass.size): for j in range(i, 3 * self.Mass.size): self.Fc[i, j] = self.Fc[j, i] elif tokens[0].upper() == 'FORCEC' and tokens[1].upper( ) == 'MM4FILE': #MM4 case if self.linearity != 'Atom': fcfile = open(tokens[2], 'r') self.Fc = readGeomFc.readMM4Fc(fcfile) for i in range(0, 3 * self.Mass.size): for j in range(i, 3 * self.Mass.size): self.Fc[i, j] = self.Fc[j, i] elif tokens[0].upper() == "FREQ": line = readGeomFc.readMeaningfulLine(file) numFreq = int(line.split()[0]) i = 0 while (i < numFreq): line = readGeomFc.readMeaningfulLine(file) tokens = line.split() i = i + len(tokens) for j in tokens: self.Freq.append(float(j)) if self.TS: self.imagFreq = self.Freq.pop(0) if len(self.Freq) > numFreq: print 'More frequencies than ', numFreq, ' are specified' else: print 'Frequency information cannot be read, check input file again' exit() #read energy line = readGeomFc.readMeaningfulLine(file) tokens = line.split() if (tokens[0].upper() != 'ENERGY'): print 'Energy information not given' exit() if tokens[1].upper() == 'FILE': print 'Reading energy from file: ', tokens[2] energyFile = open(tokens[2], 'r') if (tokens[3].upper() == 'CBS-QB3'): self.Etype = 'cbsqb3' elif (tokens[3].upper() == 'CBS-QB3_ULTRAFINE'): self.Etype = 'cbsqb3uf' print 'Warning: "Regular" (non-ultrafine) CBS-QB3 values will be used for P, N as a first approximation' elif (tokens[3].upper() == 'G3'): self.Etype = 'g3' elif (tokens[3].upper() == 'KLIP_1'): self.Etype = 'klip_1' elif (tokens[3].upper() == 'KLIP_2'): self.Etype = 'klip_2' elif (tokens[3].upper() == 'KLIP_2_CC'): self.Etype = 'klip_2_cc' self.Energy = readGeomFc.readEnergy(energyFile, self.Etype) print self.Energy, self.Etype elif (len(tokens) == 3): self.Energy = float(tokens[1]) if (tokens[2].upper() == 'CBS-QB3'): self.Etype = 'cbsqb3' elif (tokens[2].upper() == 'CBS-QB3_ULTRAFINE'): self.Etype = 'cbsqb3uf' print 'Warning: "Regular" (non-ultrafine) CBS-QB3 values will be used for P, N as a first approximation' elif (tokens[2].upper() == 'G3'): self.Etype = 'g3' elif (tokens[2].upper() == 'Klip_1'): self.Etype = 'klip_1' elif (tokens[2].upper() == 'Klip_2'): self.Etype = 'klip_2' elif (tokens[2].upper() == 'KLIP_2_CC'): self.Etype = 'klip_2_cc' elif (tokens[2].upper() == 'MM4'): self.Etype = 'mm4' print self.Etype.upper(), ' Energy: ', self.Energy else: print 'Cannot read the Energy' exit() #read external symmetry line = readGeomFc.readMeaningfulLine(file) if (line.split()[0].upper() != 'EXTSYM'): print 'Extsym keyword required' exit() self.extSymm = float(line.split()[1]) #read electronic degeneracy line = readGeomFc.readMeaningfulLine(file) if (line.split()[0].upper() != 'NELEC'): print 'Nelec keyword required' exit() self.nelec = int(line.split()[1]) #read rotor information line = readGeomFc.readMeaningfulLine(file) if (line.split()[0].upper() != 'ROTORS'): print 'Rotors keyword required' exit() self.numRotors = int(line.split()[1]) if self.numRotors == 0: #Line added by MRH o 2/Dec/2009 #If no rotors exist and molecule is not a single atom, still need to: # (1) Check if frequencies are already computed # (2) Read in the BAC information if self.linearity != 'Atom': self.rotors = [] if (len(self.Freq) == 0): #calculate frequencies from force constant self.getFreqFromFc() line = readGeomFc.readMeaningfulLine(file) tokens = line.split() for bond in tokens: self.bonds.append(float(bond)) return # If the molecule is a single atom, no rotors exist, no frequencies need # calculating, and no BAC information needs to be read else: return rotorFile = line.split()[2] inertiaFile = open(rotorFile, 'r') #print self.Mass (self.rotors) = readGeomFc.readGeneralInertia(inertiaFile, self.Mass) if len(self.rotors) - 1 != self.numRotors: print "The number of rotors specified in file, ", rotorFile, ' is different than, ', self.numRotors if (len(self.Freq) == 0): #calculate frequencies from force constant #Added by MRH on 2/Dec/2009 if self.linearity != 'Atom': self.getFreqFromFc() else: if self.linearity != 'Atom': self.getFreqFromFreq() #read potential information for rotors line = readGeomFc.readMeaningfulLine(file) tokens = line.split() if tokens[0].upper() != 'POTENTIAL': print 'No information for potential given' exit() if tokens[1].upper() == 'SEPARABLE': if tokens[2].upper() == 'FILES': line = readGeomFc.readMeaningfulLine(file) tokens = line.split() if len(tokens) != self.numRotors: print 'give a separate potential file for each rotor' for files in tokens: Kcos = [] Ksin = [] harmonic = Harmonics(5, Kcos, Ksin) harmonic.fitPotential(files) self.Harmonics.append(harmonic) elif tokens[2].upper().startswith('MM4FILES'): if tokens[2].upper( ) == 'MM4FILES_INERTIA': #whether to consider variable inertia or not self.variableInertia = True line = readGeomFc.readMeaningfulLine(file) tokens = line.split() if len(tokens) != self.numRotors: print 'give a separate potential file for each rotor' line = readGeomFc.readMeaningfulLine( file ) #the next line contains V0 (kcal/mol) followed by the rotor dihedrals (degrees) for the minimum energy conformation rotinfo = line.split() V0 = float(rotinfo[0]) K = geomUtility.calculateD32( self.geom, self.Mass, self.rotors ) #get the rotor moments of inertia for the minimum energy conformation, which will be used during the Fourier fit i = 0 for files in tokens: i = i + 1 dihedralMinimum = float(rotinfo[i]) Kcos = [] Ksin = [] harmonic = Harmonics(5, Kcos, Ksin) harmonic.fitMM4Potential(files, V0, dihedralMinimum, self.variableInertia, self.rotors[i], float(K[i - 1])) self.Harmonics.append(harmonic) elif tokens[2].upper() == 'HARMONIC': for i in range(self.numRotors): line = readGeomFc.readMeaningfulLine(file) numFit = int(line.split()[0]) Ksin = [] Kcos = [] for i in range(numFit): line = readGeomFc.readMeaningfulLine(file) tokens = line.split() Kcos.append(tokens[0]) Ksin.append(tokens[0]) harmonic = Harmonics(numFit, Kcos, Ksin) self.Harmonics.append(harmonic) elif tokens[1].upper() == 'NONSEPARABLE': line = readGeomFc.readMeaningfulLine(file) self.potentialFile = line.split()[0] # read the energy base #line = readGeomFc.readMeaningfulLine(file) #tokens = line.split() #if (tokens[0].upper() != 'ENERGYBASE'): # print 'Keyword EnergyBase required' # exit() #self.ebase=float(tokens[1]) # read the bonds line = readGeomFc.readMeaningfulLine(file) tokens = line.split() for bond in tokens: self.bonds.append(float(bond)) #read the random seed number '''line = readGeomFc.readMeaningfulLine(file)