def process_cmd_line(argv): prefix = "" gauss_fn = sys.argv[1] pdb_fn = sys.argv[2] import cclib from cclib.parser import Gaussian #from cclib.method import CSPA #MPA myfile = Gaussian(gauss_fn) data = myfile.parse() opt_coords = data.atomcoords[-1] # last coords from the optimization charges = get_mulliken_charges(fn)[-1] #analysis = CSPA(myfile)#MPA(myfile) #if analysis.calculate(): # charges = analysis.fragcharges # last coords from the optimization # print(charges) paramslines = [] try: with open(sys.argv[3]) as f: paramslines = f.readlines() except: with open( ROSETTA + "/main/database/chemical/residue_type_sets/fa_standard/residue_types/{}.params" .format(params)) as f: paramslines = f.readlines() pdb = [] with open(pdb_fn) as f: pdb = f.readlines() return opt_coords, charges, pdb, paramslines
def gau_get(in_file): gout = Gaussian(in_file) gout.logger.setLevel(logging.ERROR) gdata = gout.parse() gatoms = Atoms(numbers = gdata.atomnos, positions = gdata.atomcoords[-1]) return gatoms
def test_converged_structures(): """Tests that non converged coordinates in Gaussian log files are discarded""" structure = get_fun('MPR.psf') scan = qmdb.parse_gauss(get_fun('MPR.scan1.pos.log'), structure) log = Gaussian(get_fun('MPR.scan1.pos.log')) data = log.parse() assert_array_equal(data.atomcoords.shape, scan.xyz.shape) converted = convertor(data.scfenergies, "eV", "kJmol-1") - \ min(convertor(data.scfenergies[:len(data.atomcoords)], "eV", "kJmol-1")) assert_array_equal(converted[:47], scan.qm_energy)
def test_converged_structures(): """Tests that non converged coordinates in Gaussian log files are discarded""" structure = get_fn('MPR.psf') scan = qmdb.parse_gauss(get_fn('MPR.scan1.pos.log'), structure) log = Gaussian(get_fn('MPR.scan1.pos.log')) data = log.parse() assert_array_equal(data.atomcoords.shape, scan.xyz.shape) converted = convertor(data.scfenergies, "eV", "kJmol-1") - \ min(convertor(data.scfenergies[:len(data.atomcoords)], "eV", "kJmol-1")) assert_array_equal(converted[:47], scan.qm_energy)
def test_read_logfile(): """Tests the logfile parser""" structure = get_fun('PRL.psf') logfiles = [get_fun('PRL.scan2.neg.log'), get_fun('PRL.scan2.pos.log')] scan = qmdb.parse_gauss(logfiles, structure) scan1 = Gaussian(logfiles[0]) scan2 = Gaussian(logfiles[1]) data1 = scan1.parse() data2 = scan2.parse() assert_almost_equal(scan.xyz[:40]*10, data1.atomcoords, decimal=6) assert_almost_equal(scan.xyz[40:]*10, data2.atomcoords, decimal=6)
def gaussian_modes(path_or_parser): """ Read the modes Create a prody.modes instance Parameters ---------- path_or_parser : str or cclib.Gaussian gaussian frequencies output path or already parsed cclib.Gaussian instance Returns ------- modes : ProDy modes ANM or RTB """ if isinstance(path_or_parser, basestring): parsed = Gaussian(path_or_parser).parse() else: parsed = path_or_parser shape = parsed.vibdisps.shape modes_vectors = parsed.vibdisps.reshape(shape[0], shape[1] * shape[2]).T modes_frequencies = np.abs(parsed.vibfreqs) modes = prody.NMA() modes.setEigens(vectors=modes_vectors, values=modes_frequencies) return modes
def testnoparseGaussian_Gaussian09_coeffs_zip(filename): """This is a test for a Gaussian file with more than 999 basis functions. The log file is too big, so we are just including a section. Before parsing, we set some attributes of the parser so that it all goes smoothly. """ d = Gaussian(filename) d.logger.setLevel(logging.ERROR) d.nmo = 5 d.nbasis = 1128 logfile = d.parse() assert logfile.data.mocoeffs[0].shape == (5, 1128) assert logfile.data.aonames[-1] == "Ga71_19D-2" assert logfile.data.aonames[0] == "Mn1_1S"
def testnoparseGaussian_Gaussian09_coeffs_log(filename): """This is a test for a Gaussian file with more than 999 basis functions. The log file is too big, so we are just including a section. Before parsing, we set some attributes of the parser so that it all goes smoothly. """ parser = Gaussian(os.path.join(__filedir__, filename)) parser.logger.setLevel(logging.ERROR) parser.nmo = 5 parser.nbasis = 1128 data = parser.parse() assert data.mocoeffs[0].shape == (5, 1128) assert data.aonames[-1] == "Ga71_19D-2" assert data.aonames[0] == "Mn1_1S"
def from_gaussian(cls, gaussian_path, task=None): """ initializes from a gaussian output file """ gaussian_parser = Gaussian(gaussian_path).parse() modes = gaussian_modes(gaussian_parser) chimera_molecule = convert_gaussian_molecule_to_chimera( gaussian_parser) chimera.openModels.add([chimera_molecule]) return cls(chimera_molecule, modes)
def __init__(self, filename): """ Constructor. filename -- filename to get info from, either Gaussian (out, g03) or netCDF file (nc) """ self.file = filename if os.path.exists(filename): ext = filename.split('.')[-1] self.complex = filename.split('.')[-2] #print ext if ext == 'nc': self.type = 'nc' # read directly from nc to avoid calculation #self.data = netCDF(filename,'r') self.data = Jacapo.read_atoms(filename) elif ext == 'out' or ext == 'g03' or ext == 'log': gout = Gaussian(filename) gout.logger.setLevel(logging.ERROR) self.type = 'gau' self.data = gout.parse() else: raise Exception, 'File is not of identifiable format'
def test_read_logfile(): """Tests the logfile parser""" structure = get_fn('PRL.psf') logfiles = [get_fn('PRL.scan2.neg.log'), get_fn('PRL.scan2.pos.log')] scan = qmdb.parse_gauss(logfiles, structure) scan1 = Gaussian(logfiles[0]) scan2 = Gaussian(logfiles[1]) data1 = scan1.parse() data2 = scan2.parse() assert_almost_equal(scan.xyz[:40] * 10, data1.atomcoords, decimal=6) assert_almost_equal(scan.xyz[40:] * 10, data2.atomcoords, decimal=6)
def convert_gaussian_molecule_to_chimera(path_or_parser): if isinstance(path_or_parser, basestring): parsed = Gaussian(path_or_parser).parse() else: parsed = path_or_parser elements = parsed.atomnos coords = parsed.atomcoords[-1] m = chimera.Molecule() r = m.newResidue("UNK", " ", 1, " ") for i, (element, xyz) in enumerate(zip(elements, coords)): element = chimera.Element(element) a = m.newAtom('{}{}'.format(element, i), element) r.addAtom(a) a.setCoord(chimera.Point(*xyz)) a.serialNumber = i chimera.connectMolecule(m) return m
def gaussian_modes(path): """ Read the modes Create a prody.modes instance Parameters ---------- path : str gaussian frequencies output path Returns ------- modes : ProDy modes ANM or RTB """ gaussian_parser = Gaussian(path).parse() shape = gaussian_parser.vibdisps.shape modes_vectors = gaussian_parser.vibdisps.reshape(shape[0], shape[1] * shape[2]).T modes_frequencies = numpy.abs(gaussian_parser.vibfreqs) modes = prody.NMA() modes.setEigens(vectors=modes_vectors, values=modes_frequencies) return modes
def read_scan_logfile(logfiles, structure): """ parses Guassian09 torsion-scan log file parameters ---------- logfiles: str of list of str Name of Guassian 09 torsion scan log file structure: charmm psf file returns ------- TorsionScanSet """ topology = md.load_psf(structure) structure = CharmmPsfFile(structure) positions = np.ndarray((0, topology.n_atoms, 3)) qm_energies = np.ndarray(0) torsions = np.ndarray((0, 4), dtype=int) directions = np.ndarray(0, dtype=int) steps = np.ndarray((0, 3), dtype=int) if type(logfiles) != list: logfiles = [logfiles] for file in logfiles: print("loading %s" % file) direction = np.ndarray(1) torsion = np.ndarray((1, 4), dtype=int) step = [] index = (2, 12, -1) f = file.split("/")[-1].split(".") if f[2] == "pos": direction[0] = 1 else: direction[0] = 0 fi = open(file, "r") for line in fi: if re.search(" Scan ", line): t = line.split()[2].split(",") t[0] = t[0][-1] t[-1] = t[-1][0] for i in range(len(t)): torsion[0][i] = int(t[i]) - 1 if re.search("Step", line): try: step = np.array(([int(line.rsplit()[j]) for j in index])) step = step[np.newaxis, :] steps = np.append(steps, step, axis=0) except: pass fi.close() log = Gaussian(file) data = log.parse() # convert angstroms to nanometers positions = np.append(positions, data.atomcoords * 0.1, axis=0) qm_energies = np.append( qm_energies, (convertor(data.scfenergies, "eV", "kJmol-1") - min(convertor(data.scfenergies, "eV", "kJmol-1"))), axis=0, ) for i in range(len(data.scfenergies)): torsions = np.append(torsions, torsion, axis=0) directions = np.append(directions, direction, axis=0) return TorsionScanSet(positions, topology, structure, torsions, directions, steps, qm_energies)
def parse_gauss(logfiles, structure): """ parses Guassian09 torsion-scan log file parameters ---------- logfiles: str of list of str Name of Guassian 09 torsion scan log file structure: charmm psf file returns ------- TorsionScanSet """ topology = md.load_psf(structure) structure = CharmmPsfFile(structure) positions = np.ndarray((0, topology.n_atoms, 3)) qm_energies = np.ndarray(0) torsions = np.ndarray((0, 4), dtype=int) directions = np.ndarray(0, dtype=int) steps = np.ndarray((0, 3), dtype=int) if type(logfiles) != list: logfiles = [logfiles] for file in (logfiles): direction = np.ndarray(1) torsion = np.ndarray((1, 4), dtype=int) step = np.ndarray((0, 3), dtype=int) index = (2, 12, -1) log = Gaussian(file) data = log.parse() # convert angstroms to nanometers positions = np.append(positions, data.atomcoords * 0.1, axis=0) # Only add qm energies for structures that converged (because cclib throws out those coords but not other info) qm_energies = np.append(qm_energies, (convertor( data.scfenergies[:len(data.atomcoords)], "eV", "kJmol-1") - min( convertor(data.scfenergies[:len(data.atomcoords)], "eV", "kJmol-1"))), axis=0) fi = open(file, 'r') for line in fi: if re.search(' Scan ', line): t = line.split()[2].split(',') t[0] = t[0][-1] t[-1] = t[-1][0] for i in range(len(t)): torsion[0][i] = (int(t[i]) - 1) if re.search('^ D ', line): d = line.split()[-1] if d[0] == '-': direction[0] = 0 elif d[0] == '1': direction[0] = 1 if re.search('Step', line): try: point = np.array(([int(line.rsplit()[j]) for j in index])) point = point[np.newaxis, :] step = np.append(step, point, axis=0) except: pass fi.close() # only add scan points from converged structures steps = np.append(steps, step[:len(data.atomcoords)], axis=0) for i in range(len(data.atomcoords)): torsions = np.append(torsions, torsion, axis=0) directions = np.append(directions, direction, axis=0) del log del data return QMDataBase(positions=positions, topology=topology, structure=structure, torsions=torsions, steps=steps, qm_energies=qm_energies, directions=directions)
def read_scan_logfile(logfiles, structure): """ parses Guassian09 torsion-scan log file parameters ---------- logfiles: str of list of str Name of Guassian 09 torsion scan log file structure: charmm psf file returns ------- TorsionScanSet """ topology = md.load_psf(structure) structure = CharmmPsfFile(structure) positions = np.ndarray((0, topology.n_atoms, 3)) qm_energies = np.ndarray(0) torsions = np.ndarray((0, 4), dtype=int) directions = np.ndarray(0, dtype=int) steps = np.ndarray((0, 3), dtype=int) if type(logfiles) != list: logfiles = [logfiles] for file in (logfiles): #print("loading %s" % file) direction = np.ndarray(1) torsion = np.ndarray((1, 4), dtype=int) step = np.ndarray((0, 3), dtype=int) index = (2, 12, -1) # f = file.split('/')[-1].split('.') # if f[2] == 'pos': # direction[0] = 1 # else: # direction[0] = 0 log = Gaussian(file) data = log.parse() # convert angstroms to nanometers positions = np.append(positions, data.atomcoords*0.1, axis=0) # Only add qm energies for structures that converged (because cclib throws out those coords but not other info) qm_energies = np.append(qm_energies, (convertor(data.scfenergies[:len(data.atomcoords)], "eV", "kJmol-1") - min(convertor(data.scfenergies[:len(data.atomcoords)], "eV", "kJmol-1"))), axis=0) fi = open(file, 'r') for line in fi: if re.search(' Scan ', line): t = line.split()[2].split(',') t[0] = t[0][-1] t[-1] = t[-1][0] for i in range(len(t)): torsion[0][i] = (int(t[i]) - 1) if re.search('^ D ', line): d = line.split()[-1] if d[0] == '-': direction[0] = 0 elif d[0] == '1': direction[0] = 1 if re.search('Step', line): try: point = np.array(([int(line.rsplit()[j]) for j in index])) point = point[np.newaxis,:] step = np.append(step, point, axis=0) except: pass fi.close() # only add scan points from converged structures steps = np.append(steps, step[:len(data.atomcoords)], axis=0) for i in range(len(data.atomcoords)): torsions = np.append(torsions, torsion, axis=0) directions = np.append(directions, direction, axis=0) del log del data return TorsionScanSet(positions, topology, structure, torsions, directions, steps, qm_energies)
import os from cclib.parser import Gaussian import logging for arg in sys.argv[1:]: gau_file = str(arg) if os.path.exists(gau_file): newname, ext = os.path.splitext(gau_file) cp_file = '%s-cp.com' % (newname) chk_file = '%s-cp.chk' % (newname) else: print 'File not found.' exit() gau_out = Gaussian(gau_file) gau_out.logger.setLevel(logging.ERROR) gau_data = gau_out.parse() g = open(cp_file,'w') header = '%%chk=%s\n%%mem=1900MB\n%%nproc=1\n# opt=(calcall) b3lyp/cc-pVDZ geom=angle Counterpoise=2\n\nCounterpoise calculation\n\n' % (chk_file) g.write(header) g.write('%i,%i\n' % (gau_data.charge,gau_data.mult)) for num in range(0,gau_data.natom): atm = gau_data.atomnos[num] x, y, z = list(gau_data.atomcoords[-1][num]) g.write('%i %0.5f %0.5f %0.5f 1\n' % (atm, x, y, z)) g.close()
j = 0 for excitation in eStr: if excitation > bestExcitationStr: bestExcitationStr = excitation bestExcitationIdx = j j += 1 # OK, now bestExcitationIdx has the best index exState[smiles] = homos[smiles] + float(eTrans[bestExcitationIdx]) exStr[smiles] = bestExcitationStr i = 0 t = open('hexamer/top_smiles.txt', 'r') for line in t: smiles = line.split(' ')[0].split('_')[0] eff = line.split(' ')[1].rstrip() myfile = Gaussian("gaussian/hex-00/%d.g09" % i) myfile.logger.setLevel(logging.ERROR) data = myfile.parse() homoE = data.moenergies[0][data.homos[0]] excitation = data.etenergies[0] * 0.00012398 lumoE = homoE + excitation eff2 = efficient.efficiency(homoE, excitation, -4.61) print smiles, eff, homos[smiles], exState[smiles], exStr[ smiles], eff2, homoE, lumoE, data.etoscs[0] i += 1